function runMailer()
{
	var EmailAddress= window.document.form1.email.value;
	var TestEmail   = window.document.form1.confirm_email.value;

	if (EmailAddress != TestEmail)
	{
		alert("The confirm email address you entered does not match the email address you entered. We want to be certain we can contact you. So please re-enter your email address and re-confirm it. Thank you.");
		window.document.getElementById("confirm_email").value = "";		
		window.document.getElementById("email").value = "";		
		window.document.getElementById("email").focus();
		return;
	}

	
	var aFields = new Array("company_name", "first_name", "last_name", "phone", "title", "address", "business_description");
	for (var i = 0; i < aFields.length; i++)
	{
		var o = document.getElementById(aFields[i]);
		if (o)
		  if (typeof(o) != "undefined")
		  {
		     var v = o.value;
		     if (v)
			if (typeof(v) != "undefined")
			  if (v.length > 0)
			  	continue;
          }			  	

		alert("Fields marked with an asterisk (*) are required. Please complete the form and resubmit.");
		o.focus();
		return;
	}


	var o = document.getElementById("AwareOfUsHow");
	if (document.getElementById("AwareOfUs_A").checked)
		o.value = "From someone within my company";
			
	if (document.getElementById("AwareOfUs_B").checked)
		o.value = "From one of our vendors";

	if (document.getElementById("AwareOfUs_C").checked)
		o.value = "Sent to me by a friend";

	if (document.getElementById("AwareOfUs_D").checked)
		o.value = "Web search";

	if (document.getElementById("AwareOfUs_E").checked)
		o.value = "From your website";

	if (document.getElementById("AwareOfUs_F").checked)
		o.value = "Other - " + document.getElementById("AwareOfUs_Other").value;

	
	var s =	document.getElementById("phone").value;
	if (s.charAt(3) == "-")
		if (s.charAt(7) == "-")
		  if ("0123456789".indexOf(s.charAt(0)) >= 0)
		    if ("0123456789".indexOf(s.charAt(1)) >= 0)
		      if ("0123456789".indexOf(s.charAt(2)) >= 0)
		        if ("0123456789".indexOf(s.charAt(4)) >= 0)
			  if ("0123456789".indexOf(s.charAt(5)) >= 0)
	  		    if ("0123456789".indexOf(s.charAt(6)) >= 0)
		              if ("0123456789".indexOf(s.charAt(8)) >= 0)
		  		if ("0123456789".indexOf(s.charAt(9)) >= 0)
				  if ("0123456789".indexOf(s.charAt(10)) >= 0)
		  		    if ("0123456789".indexOf(s.charAt(11)) >= 0)
				    {	
					window.document.form1.action = "contact_form_mailer.asp";
					window.document.form1.submit();	
					return;
				    }

	alert("Fields marked with an asterisk (*) are required. Please complete the form and resubmit.");
	document.getElementById("phone").focus();
	return;

}

function GetCaretPos(obj) 
{
    if (obj.setSelectionRange) 
	return obj.selectionEnd;

    var i = obj.value.length + 1;
    if (obj.createTextRange)
    {
        var theCaret = document.selection.createRange().duplicate();
        while ( theCaret.parentElement() == obj && theCaret.move("character",1) == 1 ) 
            --i;
    }
    if (i > 0) 
        i--;

    return i;       
}

function PhoneMask(o)
{
   var c = String.fromCharCode(event.keyCode); 
   if (!document.selection)
       return ("0123456789-".indexOf(c) >= 0) ;	

    var i = GetCaretPos(o);
    if ((i==3)||(i==7)) return (c=="-");
    return ("0123456789".indexOf(c) >= 0) ;
}
