
function sameaddress ( cn ) {
   var f = cn.form;

   f.ship_firstname.value = f.bill_firstname.value;
   f.ship_lastname.value = f.bill_lastname.value;
   
   f.ship_phone.value = f.bill_phone.value;
   f.ship_company.value = f.bill_company.value;
   f.ship_address1.value = f.bill_address1.value;
   f.ship_address2.value = f.bill_address2.value;
   f.ship_city.value = f.bill_city.value;
   f.ship_state.options[f.bill_state.selectedIndex].selected = true;
   f.ship_country.options[f.bill_country.selectedIndex].selected = true;
   f.ship_zip.value = f.bill_zip.value;
   
}

//******************************************************************************************************	  
function check_email(e) {
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
				
		for(i=0; i < e.length ;i++){
			if(ok.indexOf(e.charAt(i))<0){ 
			   return (false);
			   }	
		} 
		
		if (document.images) {
			re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
			re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			if (!e.match(re) && e.match(re_two)) {
			   return (-1);		
			   } 
		}
}
						
//******************************************************************************************************			
  function CreateAccountForm ( cn ) {
        var theform = document.NewAccountForm;
		
		updateship =  (theform.ShippingIsBillingAddress.checked == true);
		
		//alert(updateship);
		
        if (theform.firstname.value=="") {
		    theform.firstname.focus();
			alert("Please enter the first name for this account.");
			return false;
		}
		
        if (theform.lastname.value=="") {
		    theform.lastname.focus();
			alert("Please enter the last name for this account.");
			return false;
		}
		
        if (theform.email.value=="") {
		    theform.email.focus();
			alert("Please enter the email for this account.");
			return false;
		}
		
         if(!check_email(theform.email.value)){
            alert("Please enter a valid email address!");
            theform.email.focus(); 
            return false;
            }

        if (theform.passworda.value=="") {
		    theform.passworda.focus();
			alert("Please enter a password for this new account.");
			return false;
		}
		
        if (theform.passwordb.value=="") {
		    theform.passwordb.focus();
			alert("Please enter a confirmation of your password.");
			return false;
		}
		
		if (theform.passworda.value!=theform.passwordb.value) {
		    theform.passworda.focus();
			alert("Please your password and confirmation are not the same. Please try again.");
			return false;
		}
			
        if (theform.bill_firstname.value=="") {
		    theform.bill_firstname.focus();
			alert("Please enter the first name for your billing address.");
			return false;
		}
		
        if (theform.bill_lastname.value=="") {
		    theform.bill_lastname.focus();
			alert("Please enter the last name for your billing address.");
			return false;
		}
		
        if (theform.bill_address1.value=="") {
		    theform.bill_address1.focus();
			alert("Please enter the address for this account.");
			return false;
		}
		
        if (theform.bill_city.value=="") {
		    theform.bill_city.focus();
			alert("Please enter the city for this account.");
			return false;
		}
		
		var con = theform.bill_country.options[theform.bill_country.selectedIndex].value;
		var billstate = theform.bill_state.options[theform.bill_state.selectedIndex].value;
		
			if (billstate=="") {
			    theform.bill_state.focus();
		        alert("Please select the billing address state/province for this account.");
				return false;
			}
		

	        if (theform.bill_zip.value=="") {
			    theform.bill_zip.focus();
				alert("Please enter a zip or postal code for this new account.");
				return false;
			}

		
			var c = theform.bill_country.options[theform.bill_country.selectedIndex].value;
			var p = theform.bill_phone.value;
			p = ReturnPhone ( p )
	
			if (p.length==0) {
			    theform.bill_phone.focus();
				alert("Please enter the phone number for the Bill-To address.");
				return false;
			} else {
			    if (c=="United States" || c=="Canada") {
				    if (p.length < 10) {
					    theform.bill_phone.focus();
				        alert("Please enter a valid 10 digit phone number for the Bill-To address.");
				        return false;
					    }
				} else {
				    if (p.length < 8) {
					    theform.bill_phone.focus();
				        alert("Please enter a valid international phone number for Bill-To address.");
				        return false;
					    }
				   }
			}
		
		
		if (updateship==false) {
		
	        if (theform.ship_firstname.value=="") {
			    theform.ship_firstname.focus();
				alert("Please enter the first name for your shipping address.");
				return false;
			}
			
	        if (theform.ship_lastname.value=="") {
			    theform.ship_lastname.focus();
				alert("Please enter the last name for your shipping address.");
				return false;
			}
			
	        if (theform.ship_address1.value=="") {
			    theform.ship_address1.focus();
				alert("Please enter the shipping address for this account.");
				return false;
			}
			
	        if (theform.ship_city.value=="") {
			    theform.ship_city.focus();
				alert("Please enter the shipping address city for this account.");
				return false;
			}
			
		var shipcon = theform.ship_country.options[theform.ship_country.selectedIndex].value;
		
		var shipstate = theform.ship_state.options[theform.ship_state.selectedIndex].value;
		
			if (shipstate=="") {
			    theform.ship_state.focus();
		        alert("Please select the shipping address state/province for this account.");
				return false;
			}

		        if (theform.ship_zip.value=="") {
				    theform.ship_zip.focus();
					alert("Please enter a shipping address zip code for this new account.");
					return false;
				}

			if (theform.ship_country.selectedIndex==0) {
			    theform.ship_country.focus();
				alert("Please select the shipping address country for this account.");
				return false;
			}
		}
		
			var c = theform.ship_country.options[theform.ship_country.selectedIndex].value;
			var p = theform.ship_phone.value;
			p = ReturnPhone ( p )
	
			if (p.length==0) {
			    theform.ship_phone.focus();
				alert("Please enter the phone number for the Ship-To address.");
				return false;
			} else {
			    if (c=="United States" || c=="Canada") {
				    if (p.length < 10) {
					    theform.ship_phone.focus();
				        alert("Please enter a valid 10 digit phone number for the Ship-To address.");
				        return false;
					    }
				} else {
				    if (p.length < 8) {
					    theform.ship_phone.focus();
				        alert("Please enter a valid international phone number for Ship-To address.");
				        return false;
					    }
				   }
			}
		
    theform.submit();
	return true;
 }
//******************************************************************************************************
function EmailSignForm ( cn ) {

  var f = cn.form;
  var flst = f.TopicID;
  var hasdata = false;
  
  if (f.firstname.value=="") {
      alert("Please enter your first name.");
	  f.firstname.focus();
      return true;
  }
  
  if (f.lastname.value=="") {
      alert("Please enter your last name.");
	  f.lastname.focus();
      return true;
  }
  
  if (f.email.value=="") {
      alert("Please enter your email address.");
	  f.email.focus();
      return true;
  }
  
  if (!isEmail(f.email.value)) {
      alert("Please enter a valid email address.");
	  f.email.focus();
      return true;
  }
  
  // Only validate the phone when a value has been eenter. No value, then no check.
  if (f.phone.value!="") {
		PhoneCode = isValidPhone ( f.phone );
		
		if (PhoneCode!="GOOD") {
		    f.phone.focus();
			
			if (PhoneCode=="length<10") {
			   alert("Please enter a valid phone number.\nThe number you entered contains too few digits. (format 212-123-1234).");
			   return false;
			}
			
			if (PhoneCode=="digit1=0") {
			   alert("Please enter a valid phone number.\nThe number you entered start with 0. (format 212-123-1234).");
			   return false;
			}
			
			if (PhoneCode=="digit0-3=555") {
			   alert("Please enter a valid phone number.\nThe number you entered has a 555 exchange. (format 212-123-1234).");
			   return false;
			}
			
			if (PhoneCode=="digit0-3=000") {
			   alert("Please enter a valid phone number.\nThe number you entered starts with 000. (format 212-123-1234).");
			   return false;
			}
			
			if (PhoneCode=="digit_count<2") {
			   alert("Please enter a valid phone number.\n The number you entered does not contain enough digits (format 212-123-1234).");
			   return false;
			}

			alert("Please enter a valid phone number.\nRequired format 212-123-1234");
			return false;
		}
  }
  
  if (f.address1.value=="") {
      alert("Please enter your street address.");
	  f.address1.focus();
      return true;
  }
  
  if (f.city.value=="") {
      alert("Please enter your street address.");
	  f.city.focus();
      return true;
  }
  
  if (f.state.selectedIndex==0) {
      alert("Please select your state or province.");
	  f.state.focus();
      return true;
  }

  if (f.state.value!="NA") {
	  if (f.zip.value=="") {
	      alert("Please select your zip or postal code.");
		  f.zip.focus();
	      return true;
	  }
  }
  for (var x = 0; x <= flst.length-1; x++) {
      if (flst[x].checked) {
	  hasdata = true;
	  }
   }

  if (!hasdata) {
      alert("Please select at least one email topics before using the save option.");
      return true;
  }
  
  f.submit();
}

//-----
function ReturnPhone (strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;

   if (strString.length == 0) return "";

   var nstr = ""
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length; i++)
      {
      strChar = strString.charAt(i);
	  //alert(strChar+ " " + strValidChars.indexOf(strChar));
      if (strValidChars.indexOf(strChar) != -1){
         nstr = nstr + strChar;
         }
      }
   return nstr;
   }
 //-----------------------------------------------------------------------------------------		
	
