<!--
function isblank(s)
{
for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;;
        }
return true;
}

//check validity of email address
function validEmail(email) {
        invalidChars = " /:,;"
        if (email == "") {
                return false
        }
        for (i=0; i<invalidChars.length; i++) {
                badChar=invalidChars.charAt(i)
                if (email.indexOf(badChar,0) != -1) {
                        return false
                }
        }
        atPos = email.indexOf("@",1)
        if (atPos == -1) {
                return false
        }
        if (email.indexOf("@",atPos+1) != -1) {
                return false
        }
        periodPos = email.indexOf(".",atPos)
        if (periodPos == -1) {
                return false
        }
        if (periodPos+3 > email.length) {
                return false
        }
        return true
}

//truncate field name
function replaceString(oldS,newS,fullS) {
	for (var i=0; i<fullS.length; i++) {      
		if (fullS.substring(i,i+oldS.length) == oldS){
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
		}
	}   
return fullS;
}

//direct email to correct address
function emailDirect(){
	var f = document.forms[0];
	if (f.x_category.selectedIndex == 1) {
		f.x_template_key.value = "contact_sameday";
		f.x_subject.value = "Contact: Same Day Services";
	} else if (f.x_category.selectedIndex == 2) {
		f.x_template_key.value = "contact_overnight";
		f.x_subject.value = "Contact: Overnight Services";
	} else if (f.x_category.selectedIndex == 3) {
		f.x_template_key.value = "contact_minimum";
		f.x_subject.value = "Contact: Minimum Usage";
	} else if (f.x_category.selectedIndex == 4) {
		f.x_template_key.value = "contact_supplies";
		f.x_subject.value = "Contact: Order Supplies";
	} else if (f.x_category.selectedIndex == 5) {
		f.x_template_key.value = "contact_account";
		f.x_subject.value = "Contact: Open an Account";
	} else if (f.x_category.selectedIndex == 6) {
		f.x_template_key.value = "contact_routed";
		f.x_subject.value = "Contact: Routed Services";
	} else if (f.x_category.selectedIndex == 7) {
		f.x_template_key.value = "contact_warehousing";
		f.x_subject.value = "Contact: Warehousing and Facilities Management Services";
	} else if (f.x_category.selectedIndex == 8) {
		f.x_template_key.value = "contact_technology";
		f.x_subject.value = "Contact: Technology - General";
	} else if (f.x_category.selectedIndex == 9) {
		f.x_template_key.value = "contact_tracking";
		f.x_subject.value = "Contact: FXTrak Web Order Entry and Tracking";
	} else if (f.x_category.selectedIndex == 10) {
		f.x_template_key.value = "contact_insurance";
		f.x_subject.value = "Contact: Insurance Coverage";
	} else if (f.x_category.selectedIndex == 11) {
		f.x_template_key.value = "contact_job";
		f.x_subject.value = "Contact: Apply for a Job";
	} else if (f.x_category.selectedIndex == 12) {
		f.x_template_key.value = "contact_username_password";
		f.x_subject.value = "Contact: Setup User Name and Password";
	} else if (f.x_category.selectedIndex == 13) {
		f.x_template_key.value = "contact_federal";
		f.x_subject.value = "Contact: Federal Services";
	}	
}

//called from the onSubmit() event handler.
function verify(f) {
	var msg = "";
	var no_category = "";
	var empty_fields = "";
	var bad_email = "";

	if (f.x_category.selectedIndex == 0) {
		empty_fields += "\nsubject"
	}

	for(var i=0; i < f.length; i++) {
			var e = f.elements[i];
			
		if ((e.type=="text") && !e.optional) {
			if ((e.value == null) || (e.value == "") || isblank(e.value)){				
				var fieldName = replaceString("x_","",e.name);
				var finalName = replaceString("b_","billing ",fieldName);
				empty_fields += "\n" + finalName;
			}
		}
	}

	if ((f.x_email.value == null) || (f.x_email.value == "") || isblank(f.x_email.value)){
	} else {
		if (!validEmail(f.x_email.value)) {
			bad_email = "invalid email address"
		}
	}

	if (empty_fields) {	
		msg = "Please complete all required fields:\n";
		msg += empty_fields;
	}

	if (bad_email) {
		msg += "\n" + bad_email;
	}		

	if (msg) {
		alert(msg);
		return(false);
	}

emailDirect();
return(true);
}
//-->