function valForm(f) {
	var why = "";
	why += isEmpty("Contact Name", f.Client_Info_Contact_Name.value);
	why += isEmpty("Contact Firm", f.Client_Info_Company_Name.value);
	why += isEmpty("Contact Street", f.Client_Info_Street_Address1.value);
	why += isEmpty("Contact City", f.Client_Info_City.value);
	why += isEmpty("Contact State", f.Client_Info_State.value);
	why += isEmpty("Contact Zip", f.Client_Info_Zip_Code.value);
	why += checkPhone("Contact Phone", f.Client_Info_Phone.value);
	why += checkPhone("Contact Fax", f.Client_Info_Fax.value);
	why += checkEmail("Contact Email", f.Client_Info_Email.value);
	why += isEmpty("Property Street", f.Property_Information_Street_Address.value);
	why += isEmpty("Property City", f.Property_Information_City.value);
	why += isEmpty("Owner", f.Participant_Info_Owner1_Name.value);

    if (why != "") {
       alert("Application could not be submitted for the following reasons:\n\n" + why + "\nPlease make the corrections and try again.");
       return false;
    }
	
	if (f.cRem.checked) {
		SetCookie("CRem", f.cRem.checked)
		SetCookie("CName", f.Client_Info_Contact_Name.value)
		SetCookie('CFirm', f.Client_Info_Company_Name.value)
		SetCookie('CStreet', f.Client_Info_Street_Address1.value)
		SetCookie('CCity', f.Client_Info_City.value)
		SetCookie('CState', f.Client_Info_State.value)
		SetCookie('CZip', f.Client_Info_Zip_Code.value)
		SetCookie('CTel', f.Client_Info_Phone.value)
		SetCookie('CFax', f.Client_Info_Fax.value)
		SetCookie('CEmail', f.Client_Info_Email.value)
	} else {
		DeleteCookie("CRem")
		DeleteCookie("CName")
		DeleteCookie('CFirm')
		DeleteCookie('CStreet')
		DeleteCookie('CCity')
		DeleteCookie('CState')
		DeleteCookie('CZip')
		DeleteCookie('CTel')
		DeleteCookie('CFax')
		DeleteCookie('CEmail')
	}
	return true;
}

function LoadVal(f){
	f.cRem.checked = GetCookie("CRem");
	if (f.cRem.checked){
		f.Client_Info_Contact_Name.value = GetCookie("CName")
		f.Client_Info_Company_Name.value = GetCookie('CFirm')
		f.Client_Info_Street_Address1.value = GetCookie('CStreet')
		f.Client_Info_City.value = GetCookie('CCity')
		f.Client_Info_State.value = GetCookie('CState')
		f.Client_Info_Zip_Code.value = GetCookie('CZip')
		f.Client_Info_Phone.value = GetCookie('CTel')
		f.Client_Info_Fax.value = GetCookie('CFax')
		f.Client_Info_Email.value = GetCookie('CEmail')
	}
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCookieVal (j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break; 
	}
	return null;
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = new Date()
	expires.setTime (expires.getTime() + 90*(24 * 60 * 60 * 1000)); // dead in 3 months	
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
	  var exp = new Date();
	  exp.setTime (exp.getTime() - 1);
	  var cval = GetCookie (name);
	  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function isEmpty(name, strng) {
	var error = "";
	if (strng.length == 0) {
			error = "-  " + name + " is not entered.\n";
	}
	return error;	  
}
    
function checkPhone (name, strng, type) {
	var error = "";
	if (strng != "") {
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	   	if (isNaN(parseInt(stripped))) 
			error = "-  " + name + " number is invalid.";
   		if (!(stripped.length == 10))
			error = "-  " + name + " number is the wrong length. Make sure you included an area code.\n";
    }
	if ((name == "Contact Phone" || name == "Contact Fax") && strng == "")
   		error = "-  " + name + " number is not entered.\n";
	return error;
}

function checkEmail (name, strng) {
	var error="";
	if (strng != "") {
		var emailFilter=/^.+@.+\..{2,3}$/;
    	if (!(emailFilter.test(strng))) { 
       		error = "-  " + name + " address is invalid.\n";
    	} else {
    		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    		if (strng.match(illegalChars)) 
       			error = "-  " + name + " address contains illegal characters.\n";
    	}
    }
	if (name == "Contact Email" && strng == "")
   		error = "-  " + name + " address is not entered.\n";
	return error;    
}
