/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
Make sure that textBox only contain number
*/
function checkQuant(textBox, quantno, quant2, quant)
{
           
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	text = trim(textBox.value);


        if(quantno == 0){
            if(text > parseInt(quant)){
                text = parseInt(quant)
            }
        }else{
            if(text > parseInt(quant2)){
                text = parseInt(quant2)
            }
        }

/*
        if (textBox.value.length == 0) {
		textBox.value = 1;
	} else {
		textBox.value = parseInt(textBox.value);
	}*/

        textBox.value = text;

}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		_notValid = false;
	with (window.document.frmCustomer) {


            if (isEmpty(txtEmailAddress, 'Enter a valid email address')){
                 _notValid = true;
            }else if (str.indexOf(at)==-1){
                      _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

                    }else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                      _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

                    }else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                        _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

                    } else if (str.indexOf(at,(lat+1))!=-1){
                       _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

                     }else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                       _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

                     } else if (str.indexOf(dot,(lat+2))==-1){
                        _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();

             }else if (str.indexOf(" ")!=-1){
                       _notValid = true;
                      alert("Enter a valid email address");
                      txtEmailAddress.focus();
           }


          }
           return _notValid;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}




/*

var xmlHttp;

function showCart(){
  try{
    // Opera 8.0+, Firefox, Safari
    xmlHttp = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        // Ajax is not supported
        alert("Your browser does not support Ajax");
        return false;
      }
    }
  }
   var url="./include/miniCart.php?url=<?php echo $url; ?>";
  xmlHttp.open("POST", url, true);
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.send(null);
}




function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 document.getElementById("showCart").innerHTML=xmlHttp.responseText
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
*/

