// All functions were moved off individual pages because of
// issues with w3c compliance.  Their parse tree does not permit
// '&' anywhere on a page!
var good = "contact_table_optional_label";
var bad = "contact_table_required_label";
function load(page, path){
	var fileNameOnly = 
	    path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
	if(path.lastIndexOf("/") == (path.length-1)){
		fileNameOnly = "index";
	}
	if(fileNameOnly == "contact" ||
	   fileNameOnly == "index"
	){
		eval("load_" + fileNameOnly + "(page)");
	}
}
function load_index(obj){
	obj.getElementById("language_options").style.visibility="visible";
	verify_name(obj.getElementById("name"));
	verify_street(obj.getElementById("street"));
	verify_city(obj.getElementById("city"));
	verify_state(obj.getElementById("state"));
	verify_zip(obj.getElementById("zip"));
	verify_phone(obj.getElementById("phone"));
	verify_email(obj.getElementById("email"));

}
function load_contact(obj){
	verify_name(obj.getElementById("name"));
	verify_email(obj.getElementById("email"));
	obj.forms.contact.name.focus();
}
function verify_name(obj){
	if(obj.value.length > 0){
		obj.className=good;
	}else{
		obj.className=bad;
	}
}
function verify_street(obj){
	if(obj.value.length > 0){
		obj.className=good;
	}else{
		obj.className=bad;
	}
}
function verify_city(obj){
	if(obj.value.length > 0){
		obj.className=good;
	}else{
		obj.className=bad;
	}
}
function verify_state(obj){
	if(obj.value.toLowerCase() == "ga" ||
	   obj.value.toLowerCase() == "georgia"){
		obj.className=good;
	}else{
		obj.className=bad;
		alert("Auto Insurance Atlanta services the Metro Atlanta area!" +
		      "\\nPlease contact us if you do not live in Georgia.");
	}
}
function verify_zip(obj){
	if(obj.value.length >= 5){
		obj.className=good;
	}else{
		obj.className=bad;
	}
}
function verify_phone(obj){
	//Thanx to Joseph K. Myers
	//http://webdeveloper.earthweb.com/ (...)
	//repository/javascripts/2003/07/216981/val.html
	var phone = obj.value;
	var a = phone.replace(/\D+/g, '-');
	a = a.match(/(\d+-?)*(\d{3}-?){2}\d{4}/g);
	if(a != null && a.length ? 0 : 2){
		obj.className=bad;
	}else{
		obj.className=good;
	}
}
function verify_email(obj){
	//Thanx to Joseph K. Myers
	//http://webdeveloper.earthweb.com/ (...)
	//repository/javascripts/2003/07/216981/val.html
	var email = obj.value;
	var a = email.match(/\S+@([-\w]+\.)+\w+/g);
	if(a != null && a.length ? 0 : 6){
		obj.className=bad;
	}else{
		obj.className=good;
	}
}
function check_comments(obj){
	if(obj.value == "Please enter your comments here!\r\n"){
		obj.value='';
	}
	if(obj.value == "Please enter your comments here!\n"){
		obj.value='';
	}
	return true;
}
function check_comments_again(obj){
	if(obj.value == ""){
		obj.value='Please enter your comments here!\n';
	}
	return true;
}
function submit_contact(name,email,form){
	if(name.className==bad){
		alert("You didn\'t enter your name!");
		return false;
	}
	if(email.className==bad){
		alert("You didn\'t enter your e-mail!");
		return false;
	}
	form.submit();
}
function submit_quote(page, form){
	if(page.getElementById("name").className==bad){
		alert("You did not enter your name!");
	}else if(page.getElementById("street").className==bad){
		alert("You did not enter your street!");
	}else if(page.getElementById("city").className==bad){
		alert("You did not enter your city!");
	}else if(page.getElementById("state").className==bad){
		alert("You did not enter your state!");
	}else if(page.getElementById("zip").className==bad){
		alert("You did not enter your zip!");
	}else if(page.getElementById("phone").className==bad){
		alert("You did not enter your phone!");
	}else if(page.getElementById("email").className==bad){
		alert("You did not enter your E-mail!");
	}else{
		form.submit();
		return true;
		//alert("functionality finishing...");
	}
	return false;
}
function toggle_visibility(obj){
	if(obj.style.visibility == "visible"){
		obj.style.visibility = "hidden";
	}else{
		obj.style.visibility = "visible";
	}
}
