/* Behavior for Markley */

window.onload = function() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	contactSend();

}


/* -- checker function - checks to see if variables in each function exist -- */

function checkVars(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;

	for(i=0; i<x.length; i++) {
		
		if(!eval(x[i])) {
		pass = false; 
		checkerInvalid[checkerInvalid.length] = x[i];
		}
		
	}
	
	return pass;

}


/* Code to let IE see the Product dropdown menu */

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


/* Code to validate the contact form */

function valContactForm() {
	
	if(!checkVars('document.contactform.Name, document.contactform.Company, document.contactform.Phone, document.contactform.Email')) {
		return;
	}
	
	var name_value = document.contactform.Name.value;
	var comp_value = document.contactform.Company.value;
	var phone_value = document.contactform.Phone.value;
	var email_value = document.contactform.Email.value;
	var errormsg = '';


	if (name_value == '') {
		errormsg = errormsg + '-You must input your name\n';
	}
	
	if (comp_value == '') {
		errormsg = errormsg + '-You must input the company name\n';
	}
	
	if (phone_value == '') {
		errormsg = errormsg + '-You must input your phone number\n';
	}
	
	if (email_value == '') {
		errormsg = errormsg + '-You must input your e-mail address\n';
	}
	
	if (errormsg != '') {
		alert('The following errors were found:\n'+errormsg);
		return false;
	}
	
	else { 
		return true; 
	}

}


/* Code to run validation when the contact form is sumbitted */

function contactSend() {
	
	if(!checkVars('document.getElementById("contactform")')) {
		return;
	}
	
	var form_name = document.getElementById("contactform");
	
	form_name.onsubmit = function() {
		return valContactForm();
		//alert("just work, man");
	}
	
}

