if (navigator.appName == 'Netscape') 
{
	window.captureEvents(Event.KEYPRESS);
	window.onKeyPress = getEnterKey;
}
		
function getEnterKey(keyStroke)
{

	// when user presses 'Enter' key 
	isNetscape=(document.layers);
	keyCode = (isNetscape) ? keyStroke.which : event.keyCode;
			
	if(keyCode==13)
	{
				
		if(isNetscape)
		{
					
			if(document.frmaddressverification.valtextarea.value != "inside")
			{
						
			return validations('addressprocess.asp');
			}
					
		}
		else
		{
			//check if textbox value is 'outside' if so call validation function
			if(document.frmaddressverification.valtextarea.value != "inside")
			{
						
				return validations('addressprocess.asp');
			}
			else//check if textbox value is 'inside' if so do nothing
			{
				return false;
			}
		}
	}
	document.frmaddressverification.valtextarea.value = "inside"
}
		
		
function changeval()
{
	if (document.frmaddressverification.valtextarea.value == "outside")
	{
		document.frmaddressverification.valtextarea.value = "inside";
	}
	else
	{
		document.frmaddressverification.valtextarea.value = "outside";
	}
}




function integersonly(field)
{
		
  var valid="0123456789"
		
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
				  
}




// validation for first or last name . used for city also
function stringvalidatename(field)
{
		
  var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'."
		
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
				  
}
	
	
function stringvalidatestate(field)
{
	
  var valid="0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	
  for (var i=0; i<field.length; i++) 
  {
		if (valid.indexOf(field.charAt(i)) < 0) 
		{
			//alert('invalid characters');
			return false;
		}
  }
			  
}



	function stringvalidatecity(field)
	{
		
	  var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		
	  for (var i=0; i<field.length; i++) 
	  {
			if (valid.indexOf(field.charAt(i)) < 0) 
			{
				//alert('invalid characters');
				return false;
			}
	  }
				  
	}
	
	
	function submitpage(strAction,cboname)
	{
		
		// the cboname parameter is used to find which combo raised the onchange event
		
		if (cboname == "cboCountry")
		{
			if (document.frmaddressverification.cboCountry.value != "0")
			 {
		
				document.frmaddressverification.action = strAction;
		
				document.frmaddressverification.submit();
			}
		}
		if (cboname == "cboShipCountry")
		{
			if (document.frmaddressverification.cboShipCountry.value != "0")
			 {
		
				document.frmaddressverification.action = strAction;
		
				document.frmaddressverification.submit();
			}
		}
	}
	
	function validations(strAction)
	{
		if (document.frmaddressverification.cboPrefix.value == "None")
		{
		   
		   alert("Please select the prefix");
		   document.frmaddressverification.cboPrefix.focus();		   
		   return false;
		}
		if (trim(document.frmaddressverification.txtfirstname.value) == "")
		{
		   
		   alert("Please enter the firstname");
		   document.frmaddressverification.txtfirstname.focus();		   
		   return false;
		}
		
		var ret = stringvalidatename(trim(document.frmaddressverification.txtfirstname.value))
		if (ret==false)
			{
				alert("Please don't include any numbers/special characters other than '. in first name.");
				document.frmaddressverification.txtfirstname.focus();
				return false;
			}
		
		
		if (trim(document.frmaddressverification.txtLastname.value) == "")
		{
		   
		   alert("Please enter the lastname");
		   document.frmaddressverification.txtLastname.focus();		   
		   return false;
		}
		var ret1 = stringvalidatename(trim(document.frmaddressverification.txtLastname.value))
		if (ret1==false)
			{
				alert("Please don't include any numbers/special characters other than '. in last name.");
				document.frmaddressverification.txtLastname.focus();
				return false;
			}
		
		
		 if (document.frmaddressverification.cboPrimaryBusiness.value == "0")
		 {
		 	alert("Please select primary business type.");
			document.frmaddressverification.cboPrimaryBusiness.focus();
			return false;
		 }
		 else if(document.frmaddressverification.cboPrimaryBusiness[document.frmaddressverification.cboPrimaryBusiness.selectedIndex].value == "17")
		 {
			//check to see if primary businsess type is 'OTHERS --> CODE 17'
			if (trim(document.frmaddressverification.txtBTypeOther.value) == "")
			{
				alert("Please specify primary business type.");
				document.frmaddressverification.txtBTypeOther.focus();
				return false;
			}
		 }
		
		if (trim(document.frmaddressverification.txtAddress1.value) == "")
		{
		 	alert("Please enter your address.");
			document.frmaddressverification.txtAddress1.focus();
			return false;
		}
		
		if (trim(document.frmaddressverification.txtCity.value) == "")
		{
		 	alert("Please enter your city.");
			document.frmaddressverification.txtCity.focus();
			return false;
		}
  
		
		var ret1b = stringvalidatecity(trim(document.frmaddressverification.txtCity.value))
		if (ret1b==false)
		{
			alert("Only alphabets and spaces allowed in city field.");
			document.frmaddressverification.txtCity.focus();
			return false;
		}
		
		if (document.frmaddressverification.cboCountry.value == "0")
		{
		 	alert("Please select country.");
			document.frmaddressverification.cboCountry.focus();
			return false;
		}
		else if(document.frmaddressverification.cboCountry[document.frmaddressverification.cboCountry.selectedIndex].value != "253")
		{
			//check to see if country is Non-US --> if so force user to enter state manually
			if (trim(document.frmaddressverification.txtStateOther.value) == "")
			{
				alert("Please specify state/province.");
				document.frmaddressverification.txtStateOther.focus();
				return false;
			}
	
			var retb = stringvalidatestate(trim(document.frmaddressverification.txtStateOther.value))
			if (retb==false)
			{
					alert("Only alphanumeric characters allowed in state/province field.");
					document.frmaddressverification.txtStateOther.focus();
					return false;
			}
	
		}
		
		
		if (document.frmaddressverification.cboState.value == "0")
		{
		 	alert("Please select state.");
			document.frmaddressverification.cboState.focus();
			return false;
		}
  
  
		if(trim(document.frmaddressverification.txtPostcode.value) == "")
		{
			alert("Please enter your post code.");
			document.frmaddressverification.txtPostcode.focus();
			return false;
		} 
		
		// Zip code
		var strZipCode = trim(document.frmaddressverification.txtPostcode.value);
		if(strZipCode.length>0)			        
		{
					         
			
			             
				
				//checks for the integer validation if any string value is present in it
			    var ret2=integersonly(strZipCode);
			    if (ret2==false)
			    {
			    	alert("Please enter only numbers in Zip code")
			        document.frmaddressverification.txtPostcode.focus();
			        return false;
			    }
				//checks for the existence of zip code for atleast five digits
				if(strZipCode.length < 5)
				{
					alert("Zip code should be atleast 5 digits");
					document.frmaddressverification.txtPostcode.focus();
					return false;
				}	   
			                  
			    if(strZipCode <= 0)
				{
					alert("Zip code should not have all digit zero");
				    document.frmaddressverification.txtPostcode.focus();
				    return false;
				}        		                        
					                 
			}
		
		
		
		if(trim(document.frmaddressverification.txtCountryCode.value) == "")
		{
			alert("Please enter your country code.");
			document.frmaddressverification.txtCountryCode.focus();
			return false;
		} 
		var ret3cc=integersonly(trim(document.frmaddressverification.txtCountryCode.value));
		if (ret3cc==false)
		{
				alert("Please enter only numbers in country code")
			    document.frmaddressverification.txtCountryCode.focus();
			    return false;
		}
		
		if(document.frmaddressverification.txtCountryCode.value <= 0)
		{
				alert("Country Code should not have all digit zero");
			    document.frmaddressverification.txtCountryCode.focus();
			    return false;
		}
		//
		if(trim(document.frmaddressverification.txtPhone.value) == "")
		{
			alert("Please enter your phonenumber.");
			document.frmaddressverification.txtPhone.focus();
			return false;
		} 
		
		var ret3=integersonly(trim(document.frmaddressverification.txtPhone.value));
		if (ret3==false)
		{
				alert("Please enter only numbers in phonenumber")
			    document.frmaddressverification.txtPhone.focus();
			    return false;
		}
		
		if(document.frmaddressverification.txtPhone.value <= 0)
		{
				alert("Phone number should not have all digit zero");
			    document.frmaddressverification.txtPhone.focus();
			    return false;
		}
		
		
		if(trim(document.frmaddressverification.txtExtension.value) != "")
		{
			
			var ret3ex=integersonly(trim(document.frmaddressverification.txtExtension.value));
			if (ret3ex==false)
			{
					alert("Please enter only numbers in extension number")
				    document.frmaddressverification.txtExtension.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtExtension.value <= 0)
			{
					alert("Extension number should not have all digit zero");
				    document.frmaddressverification.txtExtension.focus();
				    return false;
			}
		
		}
		/////////////////////////////////////////
		
		
		
		
		if(trim(document.frmaddressverification.txtFaxCountryCode.value) != "")
		{
			var retfaxcc=integersonly(trim(document.frmaddressverification.txtFaxCountryCode.value));
			if (retfaxcc==false)
			{
					alert("Please enter only numbers in country code")
				    document.frmaddressverification.txtFaxCountryCode.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtFaxCountryCode.value <= 0)
			{
					alert("Country Code should not have all digit zero");
				    document.frmaddressverification.txtFaxCountryCode.focus();
				    return false;
			}
			if(trim(document.frmaddressverification.txtFax.value) == "")
			{
				alert("Please enter your faxnumber.");
				document.frmaddressverification.txtFax.focus();
				return false;
			} 
		} 
		
		if(trim(document.frmaddressverification.txtFax.value) != "")
		{
			 var ret3A=integersonly(trim(document.frmaddressverification.txtFax.value));
			 if (ret3A==false)
			 {
						alert("Please enter only numbers in Fax")
					    document.frmaddressverification.txtFax.focus();
					    return false;
			 }
			 
			 if(document.frmaddressverification.txtFax.value <= 0)
			 {
						alert("Country Code should not have all digit zero");
					    document.frmaddressverification.txtFax.focus();
					    return false;
			 }
			 
			if(trim(document.frmaddressverification.txtFaxCountryCode.value) == "")
			{
				alert("Please enter your country code.");
				document.frmaddressverification.txtFaxCountryCode.focus();
				return false;
			} 
		} 
		
		if(trim(document.frmaddressverification.txtFaxExtension.value) != "")
		{
			
			var ret3ex=integersonly(trim(document.frmaddressverification.txtFaxExtension.value));
			if (ret3ex==false)
			{
					alert("Please enter only numbers in extension number")
				    document.frmaddressverification.txtFaxExtension.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtFaxExtension.value <= 0)
			{
					alert("Extension number should not have all digit zero");
				    document.frmaddressverification.txtFaxExtension.focus();
				    return false;
			}
			
			if(trim(document.frmaddressverification.txtFax.value) == "")
			{
				alert("Please enter your faxnumber.");
				document.frmaddressverification.txtFax.focus();
				return false;
			} 
			if(trim(document.frmaddressverification.txtFaxCountryCode.value) == "")
			{
				alert("Please enter your country code.");
				document.frmaddressverification.txtFaxCountryCode.focus();
				return false;
			} 
		
		}
		
		///////////////////////
		
		
		
		
		if(trim(document.frmaddressverification.txtEmail.value) == "")
		{
			alert("Please enter your email address.");
			document.frmaddressverification.txtEmail.focus();
			return false;
		} 
		
		
		var fieldname="Email";
		var fieldvalue=trim(document.frmaddressverification.txtEmail.value)
		var specialcharset="`~!|\#$%^&*():;{}[]'?/<>,+=";
	
		var ret4 = validemail(fieldvalue,fieldname, specialcharset)
		if (ret4 == "false")
		{
			document.frmaddressverification.txtEmail.focus();
			return false;
		}
		
		
		//validations for shipping address
		
		
		if (document.frmaddressverification.cboShipPrefix.value == "None")
		{
		   
		   alert("Please select the ship prefix");
		   document.frmaddressverification.cboShipPrefix.focus();		   
		   return false;
		}
		
		if (trim(document.frmaddressverification.txtShipToName.value) == "")
		{
		 	alert("Please enter your ship to name.");
			document.frmaddressverification.txtShipToName.focus();
			return false;
		}
		
		
		var retship = stringvalidatename(trim(document.frmaddressverification.txtShipToName.value))
		if (retship==false)
		{
				alert("Please don't include any special characters other than '. in ship to name.");
				document.frmaddressverification.txtShipToName.focus();
				return false;
		}
		
		
		/*if(document.frmaddressverification.cboShipToType[document.frmaddressverification.cboShipToType.selectedIndex].value == "6")
		{
			//check to see if ship to type is 'OTHERS --> CODE 6'
			if (trim(document.frmaddressverification.txtSTypeOther.value) == "")
			{
				alert("Please specify ship to type.");
				document.frmaddressverification.txtSTypeOther.focus();
				return false;
			}
		}*/
  
  
		
		if (trim(document.frmaddressverification.txtShipAddress1.value) == "")
		{
		 	alert("Please enter your shipping address.");
			document.frmaddressverification.txtShipAddress1.focus();
			return false;
		}
		
		if (trim(document.frmaddressverification.txtShipCity.value) == "")
		{
		 	alert("Please enter your shipping city.");
			document.frmaddressverification.txtShipCity.focus();
			return false;
		}
		
		
		if (document.frmaddressverification.cboShipCountry.value == "0")
		{
		 	alert("Please select ship to country.");
			document.frmaddressverification.cboShipCountry.focus();
			return false;
		}
		if (document.frmaddressverification.cboShipState.value == "0")
		{
		 	alert("Please select ship state.");
			document.frmaddressverification.cboShipState.focus();
			return false;
		}
		else if(document.frmaddressverification.cboShipCountry[document.frmaddressverification.cboShipCountry.selectedIndex].value != "253")
		{
			//check to see if country is Non-US --> if so force user to enter state manually
			if (trim(document.frmaddressverification.txtShipStateOther.value) == "")
			{
				alert("Please specify state/province.");
				document.frmaddressverification.txtShipStateOther.focus();
				return false;
			}
	
			var retb = stringvalidatestate(trim(document.frmaddressverification.txtShipStateOther.value))
			if (retb==false)
			{
					alert("Only alphanumeric characters allowed in state/province field.");
					document.frmaddressverification.txtShipStateOther.focus();
					return false;
			}
	
		}
		
		if(trim(document.frmaddressverification.txtShipPostCode.value) == "")
		{
			alert("Please enter your ship post code.");
			document.frmaddressverification.txtShipPostCode.focus();
			return false;
		} 
		
			
	    // shipping Zip code
		var strZipCode1 = trim(document.frmaddressverification.txtShipPostCode.value);
		if(strZipCode1.length>0)			        
		{
				
			//checks for the integer validation if any string value is present in it
			var ret2=integersonly(strZipCode1);
			if (ret2==false)
			{
				alert("Please enter only numbers in Zip code")
			    document.frmaddressverification.txtShipPostCode.focus();
			    return false;
			}
					
					
			//checks for the existence of zip code for atleast three digits
			if(strZipCode1.length < 5)
			{
				alert("Zip code should be atleast 5 digits");
			    document.frmaddressverification.txtShipPostCode.focus();
			    return false;
			}	 
			    
			                 
			if(strZipCode1 <= 0)
			{
				alert("Zip code should not have all digit zero");
			    document.frmaddressverification.txtShipPostCode.focus();
			    return false;
			}
				             		                        
					                 
		}
		//////////////////////////////////
		
		if(trim(document.frmaddressverification.txtShipCountryCode.value) == "")
		{
			alert("Please enter your shipping country code.");
			document.frmaddressverification.txtShipCountryCode.focus();
			return false;
		} 
		var ret3cc=integersonly(trim(document.frmaddressverification.txtShipCountryCode.value));
		if (ret3cc==false)
		{
				alert("Please enter only numbers in shipping country code")
			    document.frmaddressverification.txtShipCountryCode.focus();
			    return false;
		}
		
		if(document.frmaddressverification.txtShipCountryCode.value <= 0)
		{
				alert("Shipping Country Code should not have all digit zero");
			    document.frmaddressverification.txtShipCountryCode.focus();
			    return false;
		}
		
		
		if(trim(document.frmaddressverification.txtShipPhone.value) == "")
		{
			alert("Please enter your ship phonenumber.");
			document.frmaddressverification.txtShipPhone.focus();
			return false;
		} 
		
		var ret3=integersonly(trim(document.frmaddressverification.txtShipPhone.value));
		if (ret3==false)
		{
				alert("Please enter only numbers in ship phonenumber")
			    document.frmaddressverification.txtShipPhone.focus();
			    return false;
		}
		if(document.frmaddressverification.txtShipPhone.value <= 0)
		{
				alert("Phone number should not have all digit zero");
			    document.frmaddressverification.txtShipPhone.focus();
			    return false;
		}
		
		
		if(trim(document.frmaddressverification.txtShipExtension.value) != "")
		{
			
			var ret3ex=integersonly(trim(document.frmaddressverification.txtShipExtension.value));
			if (ret3ex==false)
			{
					alert("Please enter only numbers in extension number")
				    document.frmaddressverification.txtShipExtension.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtShipExtension.value <= 0)
			{
					alert("Extension number should not have all digit zero");
				    document.frmaddressverification.txtShipExtension.focus();
				    return false;
			}
		
		}
		
		
		if(trim(document.frmaddressverification.txtShipFaxCountryCode.value) != "")
		{
			var retfaxshipcc=integersonly(trim(document.frmaddressverification.txtShipFaxCountryCode.value));
			if (retfaxshipcc==false)
			{
					alert("Please enter only numbers in country code")
				    document.frmaddressverification.txtShipFaxCountryCode.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtShipFaxCountryCode.value <= 0)
			{
					alert("Country Code should not have all digit zero");
				    document.frmaddressverification.txtShipFaxCountryCode.focus();
				    return false;
			}
			if(trim(document.frmaddressverification.txtShipFax.value) == "")
			{
					alert("Please enter your shipping Fax number")
				    document.frmaddressverification.txtShipFax.focus();
				    return false;
		    }
		} 
		
		
		
		if(trim(document.frmaddressverification.txtShipFax.value) != "")
		{
		  
			var ret3Aship=integersonly(trim(document.frmaddressverification.txtShipFax.value));
			if (ret3Aship==false)
			{
					alert("Please enter only numbers in Fax")
					document.frmaddressverification.txtShipFax.focus();
					return false;
			}
			if(document.frmaddressverification.txtShipFax.value <= 0)
			{
		 			alert("Shipping Fax should not have all digit zero");
				    document.frmaddressverification.txtShipFax.focus();
				    return false;
			}
			if(trim(document.frmaddressverification.txtShipFaxCountryCode.value) == "")
			{
					alert("Please enter your shipping country code")
					document.frmaddressverification.txtShipFaxCountryCode.focus();
					return false;
			}
		} 
		
		
		if(trim(document.frmaddressverification.txtShipFaxExtension.value) != "")
		{
			
			var ret3ex=integersonly(trim(document.frmaddressverification.txtShipFaxExtension.value));
			if (ret3ex==false)
			{
					alert("Please enter only numbers in extension number")
				    document.frmaddressverification.txtShipFaxExtension.focus();
				    return false;
			}
		
			if(document.frmaddressverification.txtShipFaxExtension.value <= 0)
			{
					alert("Extension number should not have all digit zero");
				    document.frmaddressverification.txtShipFaxExtension.focus();
				    return false;
			}
			
			if(trim(document.frmaddressverification.txtShipFax.value) == "")
			{
				alert("Please enter your faxnumber.");
				document.frmaddressverification.txtShipFax.focus();
				return false;
			} 
			if(trim(document.frmaddressverification.txtShipFaxCountryCode.value) == "")
			{
				alert("Please enter your country code.");
				document.frmaddressverification.txtShipFaxCountryCode.focus();
				return false;
			} 
		
		}
		///////////////////////////////////////////
		if(trim(document.frmaddressverification.txtShipEmail.value) == "")
		{
			alert("Please enter your email address.");
			document.frmaddressverification.txtShipEmail.focus();
			return false;
		} 
		
		
		var fieldnameship="Email";
		var fieldvalueship=trim(document.frmaddressverification.txtShipEmail.value)
		var specialcharsetship="`~!|\#$%^&*():;{}[]'?/<>,+=";
	
		var ret4ship = validemail(fieldvalueship,fieldnameship, specialcharsetship)
		if (ret4ship == "false")
		{
			document.frmaddressverification.txtShipEmail.focus();
			return false;
		}
		
		
		if (trim(document.frmaddressverification.txtComments.value).length > 200)
		{
			alert("Please enter comments less than 200 characters.");
			document.frmaddressverification.txtComments.focus();
			return false;
		}
		
		if(document.frmaddressverification.cboPrimaryBusiness[document.frmaddressverification.cboPrimaryBusiness.selectedIndex].value != "17")
		{
			//check to see if primary businsess type is not 'OTHERS --> CODE 17'
			document.frmaddressverification.txtBTypeOther.value = "";	
		}
  
		if(document.frmaddressverification.cboShipToType[document.frmaddressverification.cboShipToType.selectedIndex].value != "6")
		{
			//check to see if ShipToType is not 'OTHERS --> CODE 6'
			document.frmaddressverification.txtSTypeOther.value = "";	
		}
  
		if(document.frmaddressverification.cboCountry[document.frmaddressverification.cboCountry.selectedIndex].value == "253")
		{
			//check to see if country is  'US --> CODE 253' if so, clear
			document.frmaddressverification.txtStateOther.value = "";	
		}
		if(document.frmaddressverification.cboShipCountry[document.frmaddressverification.cboShipCountry.selectedIndex].value == "253")
		{
			//check to see if country is  'US --> CODE 253' if so, clear
			document.frmaddressverification.txtShipStateOther.value = "";	
		}
		
		document.frmaddressverification.action = strAction;
		
		document.frmaddressverification.submit();
	}
	
	
	//function to trim preceding and following spaces for text fields
	function trim(str)
	{
		temp=" ";
			var countspcatfrnt=-1;
			var len;
			i=0;
			len=str.length;
			while(temp==" ")
			{
				temp=str.substring(i,i+1);
				countspcatfrnt+=1;//counting front spaces
				i+=1;	
			}
			temp=" ";
			var countspcatrear=-1;
			var trimvalue=""
			i=0;
			while(temp==" ")
			{
				temp=str.substring(((len-i)-1),(len-i));
				countspcatrear+=1;//counting rear spaces
				i++;
			}
			i=0;
			for(i=countspcatfrnt; i<=(len-countspcatrear-1); i++)
				trimvalue=trimvalue + str.substring(i,i+1);
					
			return trimvalue;
	}
	  
//----------------------------------------------------------------
//=======TRIM==========END==============
//------------------------
