//<!--
// This function will validate a form
function validateQuote(theform)
{
  pass = 1; //assume everything is ok
  msg = "The following problems where found in trying to submit this form:\n\n";

  //make sure required fields are not empty
  if (isEmpty(theform.business.value)) {
    msg = msg + "- Business Name cannot be empty\n";
    pass = 0;
  }
 
   //make sure required fields are not empty
  if (isEmpty(theform.contactname.value)) {
    msg = msg + "- Contact Name cannot be empty\n";
    pass = 0;
  }
 
   //make sure required fields are not empty
  if (isEmpty(theform.address1.value)) {
    msg = msg + "- Primary Address cannot be empty\n";
    pass = 0;
  }
  
   //make sure required fields are not empty
  if (isEmpty(theform.city.value)) {
    msg = msg + "- City cannot be empty\n";
    pass = 0;
  }
  
   //make sure required fields are not empty
  if (isEmpty(theform.zipcode.value)) {
    msg = msg + "- Zipcode Name cannot be empty\n";
    pass = 0;
  }
  
   //validate the email address
  if (!(isEmail(theform.email.value))) {
    msg = msg + "- Please enter a valid email address\n";
    pass = 0;
  }

	//Business Operations
	if (isEmpty(theform.numemployees.value) || !(isNum(theform.numemployees.value))) {
		msg = msg + "- Number of Employees must be a valid number\n";
		pass = 0;
	}
	if (isEmpty(theform.yearsinbusiness.value) || !(isNum(theform.yearsinbusiness.value))) {
		msg = msg + "- Years in Business must be a valid number\n";
		pass = 0;
	}
	if (isEmpty(theform.annualsales.value)) {
		msg = msg + "- Annual Sales cannot be empty\n";
		pass = 0;
	}
	if (isEmpty(theform.numlocations.value) || !(isNum(theform.numlocations.value))) {
		msg = msg + "- Number of Locations must be a valid number\n";
		pass = 0;
	}
	if (!(theform.ownvehicles[0].checked || theform.ownvehicles[1].checked)) {
		msg = msg + "- Does your business own vehicles must be answered\n";
		pass = 0;
	}
	if (isEmpty(theform.contentcost.value) || !(isNum(theform.contentcost.value))) {
		msg = msg + "- Building Content Cost must be a valid number\n";
		pass = 0;
	}
	if (!(theform.ownbuilding[0].checked || theform.ownbuilding[1].checked)) {
		msg = msg + "- Does your own the building you occupy must be answered\n";
		pass = 0;
	}
	if (!theform.element_9_1.checked && !theform.element_9_2.checked && !theform.element_9_3.checked && !theform.element_9_4.checked && !theform.element_9_5.checked && !theform.element_9_6.checked) {
		msg = msg + "- Please select at least one policy type\n";
		pass = 0;
	}
	if (isEmpty(theform.businessdescription.value)) {
		msg = msg + "- Business Description cannot be empty\n";
		pass = 0;
	}

	if (theform.quotereason.value == '-1') {
		msg = msg + "- Please choose Why Are You Requesting A Quote\n";
		pass = 0;
	}

	if (theform.timeframe.value == '-1') {
		msg = msg + "- Please choose When Will You Be Ready To Buy\n";
		pass = 0;
	}
	
  if (pass == 1) {
    return true;
  } else {
    alert(msg);
    return false;
  }
}

// validators ------------------------------------------------------------------
	
function isEmpty (s) {
	var p = /\S+/;
	return !p.test(s);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphaNum(string) {
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isExecutable (s) {
	var p = /\.(bat|com|dll|exe|vbs)$/i;
	return p.test(s);
}

function isImage (s) {
	var p = /\.(gif|jpg)$/i;
	return p.test(s);
}

function isUrl (s) {
	var p = /^(http|https|ftp):\/\/\S+\.[^\.\s]{2,4}(\/\S*)?$/i;
	return p.test(s);
}

//-->