// common functions for theGutterGuys.com
// mostly form validation stuff

function submitThis(formID){
	document.forms[formID].submit();
}

function submitThisWithWarning(formID, warning){
	var warn = confirm(warning);
	if(warn){
		document.forms[formID].submit();
	}
}

function valildateEmailAddress(email){
	if(email.indexOf("@") == -1){
		return false;
	}else if(email.indexOf(".") == -1){
		return false;
	}else if(email.length < 7){
		return false;
	}else{
		return true;
	}
}

//form specific functions

function validateUserForm(){
	var tForm = document.franchise_info;
	var defaultError = "Please complete all required fields.\nInvalid ";
	if(tForm.username.value.length < 2){
		alert(defaultError+"User name");
		return false;
	}else if(tForm.password.value.length < 4){
		alert(defaultError+"Password");
		return false;
	}else if(tForm.contactFName.value.length < 2){
		alert(defaultError+"First Name");
		return false;
	}else if(tForm.contactLName.value.length < 2){
		alert(defaultError+"Last Name");
		return false;
	}else if(valildateEmailAddress(tForm.contactEmail.value) == false){
		alert(defaultError+"Email");
		return false;
	}
	return true;
}

function validateAddZipCode(){
	var tForm = document.addZipCode;
	var defaultError = "Please complete all fields";
	if(tForm.zipCode.value.length < 5){
		alert(defaultError);
		return false;
	}else if(tForm.city.value.length < 3){
		alert(defaultError);
		return false;
	}else if(tForm.state.value.length < 2){
		alert(defaultError);
		return false;
	}else{
		return true;
	}
}


function submitOrder(form, target){
	document[form].action = target;
	document[form].submit();		
}

function validateApplication(){
	var form = document.franchise_application;
	var ret = true
	if(form.fname.value.length < 2){
		return appAlert();
	}
	if(form.lname.value.length < 2){
		return appAlert();
	}
	if(form.homeAddress.value.length < 4){
		return appAlert();
	}
	if(form.city.value.length < 2){
		return appAlert();
	}
	if(form.state.value.length < 2){
		return appAlert();
	}
	if(!valildateEmailAddress(form.email.value)){
		return appAlert();
	}
	if(form.homePhone.value.length < 7){
		return appAlert();
	}
	return true;
}

function appAlert(){
	alert("Please fill out all required fields");
	return false;
}

function appAlert2(form, field){
	alert("Please fill out all required fields");
	document[form][field].focus();
	return false;
}

function appAlert3(msg, form, field){
		alert(msg+" is a required field.\nPlease fill out all required fields.");
		document[form][field].focus();
		return false;
}

















