// Cross browser function to return key code from a javascript event 
function eventKeyCode(event) {
  return event.charCode? event.charCode : event.keyCode;
}

// Numbers only function for phone number fields
function NumbersOnly(e){
  var unicode = eventKeyCode(e);
  if (unicode!=8 && unicode!=9 && unicode!=177 && unicode!=13 && unicode!=27 && unicode!=28 
	    && unicode!=29 && unicode!=30 && unicode!=31 && unicode!=32 && unicode!=1 && unicode!=5 
	    && unicode!=6 && unicode!=7) { //if the key isn't the backspace, tab, enter, delete, escape or directional arrows
	
      if (unicode<48 || unicode>57) //if not a number
        return false //disable key press
  }
}


function submitform(){
	frmsignup.submit();
}



<!-- ############################# Trim function ###################-->
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


function checkSignup(frmObj,action){
	var firstname = Trim(frmObj.firstname.value);
	var lastname = frmObj.lastname.value;
	var password = frmObj.password.value;
	var rpassword = frmObj.rpassword.value;
	var email = Trim(frmObj.email.value);
	var address1 = Trim(frmObj.address1.value);
	var city = frmObj.city.value;
	var state = frmObj.state.value;
	var zip = Trim(frmObj.zip.value);
	
	if(email==''){
		alert('Please Enter Email');
		frmObj.email.focus();
		return false;
	}
	if (email!=''){
			var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
			if(!email.match(emailExp))
			{
				alert("Please Enter Valid Email Address.\n");
				document.frmSignup.email.focus();
				return false;
			}	
			
	}
		if(password==''){
		alert('Please Enter Password');
		frmObj.password.focus();
		return false;
	}
	
	if (password.length < 6 ){
		alert("Password should be atleast 6 Characters Long");
		frmObj.password.focus();
		return false;
	}
	//return false;				
	if(rpassword==''){
		alert('Please Enter Re-Password');
		frmObj.rpassword.focus();
		return false;
	}
		
	if(password!=rpassword){
		alert('Password and Re-Password should be same');
		frmObj.password.focus();
		return false;
	}
	if(firstname==''){
		alert('Please Enter First Name ');
		frmObj.firstname.focus();
		return false;
	}
	
	if(lastname==''){
		alert('Please Enter Last Name');
		frmObj.lastname.focus();
		return false;
	}	
	
	if(address1==''){
		alert('Please Enter Address 1');
		frmObj.address1.focus();
		return false;
	}
	
	if (Trim(frmObj.city.value)==''){
			alert("Please Enter City Name");
			frmObj.city.focus();
			return false;
	}
	if (Trim(frmObj.state.value)==''){
			alert("Please Select State");
			frmObj.state.focus();
			return false;
	}

	if (Trim(frmObj.zip.value)==''){
		alert("Please Enter Zip Code");
		frmObj.zip.focus();
		return false;
	}
	if (zip.length < 5 ){
			alert("Zip Code should be 5 Digit Long");
			frmSignup.zip.focus();
			return false;
	}
	if (isNaN(frmObj.zip.value)){
					alert("Please Enter Zip as Numeric");
					frmObj.zip.focus();
					return false;
	}

	return true;
	
}

function checkSignin(frmObj){
	
	var username = Trim(frmObj.username.value);
	var password = frmObj.password.value;
	if(username==''){
		alert('Please Enter Username');
		frmObj.username.focus();
		return false;
	}

	if(password==''){
		alert('Please Enter Password');
		frmObj.password.focus();
		return false;
	}
	
	frmObj.add.value="Submit";
}

function checkSpecialChar(field, name){
	var iChars = "!@#$%^&*()+=-[]\\\;./{}|\":<>?";
		 for (var i = 0; i < field.length; i++) {
  			if (iChars.indexOf(field.charAt(i)) != -1) {
  				alert (name+"has special characters. \nThese are not allowed.\n Please remove them and try again.");
				return 1;
  			}
		}//for
		return 0;	
}

/******************** Validation for signup *****************************/

//ajax functionality of unique value 
function getProducts(value,name){
	var docObj = null;
	if (typeof window.ActiveXObject != 'undefined'){
		docObj = new ActiveXObject("Microsoft.XMLHTTP"); 
	}else{ 
		docObj = new XMLHttpRequest();
	}
	var url = "getproduct.php?categoryId="+value;
	docObj.open("GET", url,false);
	docObj.send(null);
	var Res = docObj.responseText;
	var a=document.getElementById('ProdDisp');
	var b=document.getElementById('Header');
	
	a.innerHTML = '';
	a.innerHTML += Res;
	b.innerHTML = '';
	b.innerHTML += name;

}

function showfields(){
	var chkreason = document.frminternet.reason.value;
	if(chkreason=='other'){
		document.getElementById('lblexplain').style.display='table-cell';
		document.getElementById('txtexplain').style.display='table-cell';
	}else{
		document.getElementById('lblexplain').style.display='none';
		document.getElementById('txtexplain').style.display='none';
	}
}

function hidefields(){
		document.getElementById('lblexplain').style.display='none';
		document.getElementById('txtexplain').style.display='none';
}

function NewWindowAlert(mypage,myname,w,h,scroll){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
		var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable=no'+',';
		settings +='status=no';
		win=window.open(mypage,myname,settings);
		if(parseInt(navigator.appVersion) >= 4){
			win.window.focus();
		}
} 

function NewWindow(mypage,myname,w,h,scroll){
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
		var settings ='height='+h+',';
		settings +='width='+w+',';
		settings +='top='+wint+',';
		settings +='left='+winl+',';
		settings +='scrollbars='+scroll+',';
		settings +='resizable=no'+',';
		settings +='status=yes';
		win=window.open(mypage,myname,settings);
		if(parseInt(navigator.appVersion) >= 4){
			win.window.focus();
		}
} 
function addAddons(pid){
NewWindow('getAddons.php?productId='+pid,'Addons','400','450','Yes');	
}
function editAddons(pid){
NewWindow('editAddons.php?cId='+pid,'Addons','400','450','Yes');	
}
function chkQty(frmObj){
	if (Trim(frmObj.ProductQty.value) == ''	|| parseInt(Trim(frmObj.ProductQty.value)) == parseInt(0)){
		alert("Product Quantity cannot be zero");
		frmObj.ProductQty.focus();
		return false;
	}
	return true;
}
function calctotal(frmObj,val){
	var tot = frmObj.tot.value;
	var tax = frmObj.tax.value;
	var gtot = frmObj.gtot.value;
	var gtotd = frmObj.gtotd.value;
	
	switch(val){
		case '0':
				frmObj.txtd.value = '$0.00';
				frmObj.txtgtot.value = '$'+gtot;
			break;
		case '2':
				frmObj.txtd.value = '$2.00';
				frmObj.txtgtot.value = '$'+gtotd;
			break;
	}
}