
// Checks the E-MAIL field.
function isEmail(mailfield){   
	// Return false if e-mail field is blank.   
	if (mailfield == ""){      
		return false;       
	}   
	// Return false if e-mail field does not contain a '@' and '.' .   
	if (mailfield.indexOf ('@',0) == -1 || mailfield.indexOf ('.',0) == -1){       
		return false;      
	}   
	else {      
		return true;      
	}   
}
//Check for a valid phone number
function ForceNumber(FieldValue)
{
	if (FieldValue == "")	{
		return false;
	}
	var strField = new String(FieldValue);
	for (var i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && strField.charAt(i) != '-' && strField.charAt(i) != '(' && strField.charAt(i) != ')' && strField.charAt(i) != '.') {
			return false;
		}
	return true;
}

//form validation.
//takes form object as an input
function ValidateInput(form) {
	var LB = "\n"; 
	var msghdr = "Please fill out your:" + LB + LB;
	var msg= "";

	var F_Name = form.first_name.value;
	var L_Name = form.last_name.value;
	var Address_1 = form.address_1.value;
	var City = form.city.value;
	//var State = form.state.value;
	//var Zip = form.zipcode.value;
	var Country = form.country.selectedIndex;
	var W_Phone = form.work_phone.value;
	var Email = form.email.value;
	
	if(form.state.selectedIndex == 1) {
		if( form.province.value == "") { msg += "Province field" + LB; }
		}

	if (!F_Name){
		msg += "First Name" + LB;
	} if (!L_Name){
		msg += "Last Name" + LB;
	} if (!Address_1){
		msg += "Address1" + LB;
	} if (!City){
		msg += "City" + LB;
	} if (Country == 0){
		msg += "Country" + LB;
	} if (!W_Phone){
		msg += "Valid Work Telephone" + LB;
	} if (!isEmail(Email)) {
	          msg += "Valid E-mail Address" + LB;
	} if (msg.length > 0){
	   alert(msghdr + msg);
		return false;
	} else {

	// If the state field is set to anything other then international, then clear out the province value
	if(form.state.selectedIndex != 1) { form.province.value = ""; }

	   return true;
	}
}

//form validation.
//takes form object as an input
function ValidateHomeInput(form) {
	var LB = "\n"; 
	var msghdr = "Please fill out your:" + LB + LB;
	var msg= "";

	var F_Name = form.first_name.value;
	var Email = form.email.value;
	
	if (!F_Name){
		msg += "First Name" + LB;
	} if (!isEmail(Email)) {
		msg += "Valid E-mail Address" + LB;
	   	alert(msghdr + msg);
		return false;
	} else {
	   return true;
	}
}

//clears email field
function changeVal() {
   if (document.email_list.email.value == "Enter E-mail Address")
		document.email_list.email.value = ""; 
} 
function changeValName() {
   if (document.email_list.first_name.value == "Enter Your Name")
		document.email_list.first_name.value = ""; 
}
