
//email address validation
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

 		 return true					
	}
	
 function ValidateForm(){
	var emailID=document.infofrm.Email
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		return true
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 } 
 
 
 	
 function ValidateForm2(){
	var emailID=document.infofrm2.Email2
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		return true
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 } 
 
 

 
 
  function ValidateForm3(){
	var emailID=document.infofrm3.Email3
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		return true
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 } 
 
 
 
  function ValidateForm4(){
	var emailID=document.corporate_form.email_address
	
	if ((emailID.value==null)||(emailID.value=="")){
		emailID.focus()
		return true
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 } 
 
 
 
 // check a delivery country was selected
 function chkform(prodform) {	
	if (document.forms[prodform].country_id.selectedIndex == 0) { 
		alert('Please choose a delivery area'); 
		return false;
	}
	
   	return true;
  }
  
  
   // check a marketing option was selected
 function chkform2(prodform) {	
	if (document.forms[prodform].marketing.selectedIndex == 0) { 
		alert('Please select how you heard about Hampergifts. Thank you.'); 
		return false;
	}
	
   	return true;
  }
  
 
    // check a delivery option was selected
 function chkform3(prodform) {	
	if (document.forms[prodform].country_id.selectedIndex == 0) { 
		alert('Please select delivery country.'); 
		return false;
	}
	
   	return true;
  }
  
 
 
 
  
//confirm delete on click
    function confirmlink() {
    if (confirm("IMPORTANT: Only click OK to delete AFTER we have delivered your order to this address. Otherwise click CANCEL."))
    {
      return true;
    }
else
      return false;
    }
 
 //checks quantity valid
 function chkNumeric(textObj) {	
	var str = textObj.value;
	for (var i=0;i<str.length; i++) {
	   	var ch = str.charAt(i);
	   	if(ch <"0" || ch >"9"){
			alert("please enter a valid quantity.");
			textObj.focus();
			return false;
	   	}
	}
}

//sets max textarea length
function maxLength(obj,i) {
	if (obj.value.length >= i) {
		obj.value = obj.value.slice(0,i);
	}
}



