
function showLayer(divName)
{
   document.getElementById(divName).style.visibility = "visible";
}
function hideLayer(divName)
{
   document.getElementById(divName).style.visibility = "hidden";
}


function validateForm() {
var cForm = document.contactForm;
var isValid = true;
//var errMsg="Incomplete Form:\n\nPlease fix the following fields and noted problems:\n\n";

	
	// did they choose a Subject?
	if(cForm.config_name.options[cForm.config_name.selectedIndex].value == "")
	{	
		//errMsg += "\n- Subject: not selected";
		isValid = false;
		showLayer("configNameErr");
		showLayer("errNote");
	}
	else {hideLayer("configNameErr")}
	
	// are they a merchant, if "Yes" did they enter a Merchant ID?
	if(cForm.existing_merchant[0].checked && cForm.merchant_id.value == "")
	{
		   //errMsg += "\n- Merchant ID: empty";
		   isValid = false;
		   showLayer("merchantIdErr");
		   showLayer("errNote");
	}
	else {hideLayer("merchantIdErr")}
	
	// did they enter their first name?
	if(cForm.fname.value == "")
	{
		//errMsg += "\n- First Name: empty";
		isValid = false;
		showLayer("fnameErr");
		showLayer("errNote");
	}
	else {hideLayer("fnameErr")}
	
	// did they enter their last name?
	if(cForm.lname.value == "")
	{
		//errMsg += "\n- Last Name: empty";
		isValid = false;
		showLayer("lnameErr");
		showLayer("errNote");
	}
	else {hideLayer("lnameErr")}

    // is their email correct
		var str = document.contactForm.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1 || str == "") {
		   //errMsg += "\n- Email: empty or invalid";
           isValid = false;
		   showLayer("emailErr");
		   showLayer("errNote");
		}
		else
		{
			hideLayer("emailErr")
		}
		
	   // is the phone field blank?
	   if(cForm.phone.value == "" || cForm.phone.value == "xxx-xxx-xxxx (ext)")
		{
			//errMsg += "\n- Phone: empty";
			isValid = false;
			showLayer("phoneErr");
			showLayer("errNote");
		}
		else {hideLayer("phoneErr")}
		
	   // did they choose a State or Province?
		if(cForm.state_prov.options[cForm.state_prov.selectedIndex].value == "")
		{	
			//errMsg += "\n- State/Province: not selected";
			isValid = false;
			showLayer("stateProvErr");
			showLayer("errNote");
		}
		else {hideLayer("stateProvErr")}
		
		// are they a merchant, if "Yes" did they enter a Merchant ID?
		if(cForm.reply_by[0].checked && cForm.callback_time.value == "")
		{
			   //errMsg += "\n- Best time to call: empty";
			   isValid = false;
			   showLayer("callbackTimeErr");
			   showLayer("errNote");
	    }
		else {hideLayer("callbackTimeErr")}

	   // is the phone field blank?
	   if(cForm.message.value == "")
		{
			//errMsg += "\n- Message: empty";
			isValid = false;
			showLayer("messageErr");
			showLayer("errNote");
		}
		else {hideLayer("messageErr")}

        // show the alert
		if(isValid == false)
		{
		document.location.href="#errorMessage"
		}
		//alert(errMsg);
		return isValid;
}
