// JavaScript Document
<!--

function get_reason_value(fm)
{
	var rad = fm.reason;
for (var i=0; i < rad.length; i++)
   {
   if (rad[i].checked)
      {
      	return rad[i].value;
      }
   }
}

function get_referral_value(fm)
{
var rad = fm.referral;
for (var i=0; i < rad.length; i++)
   {
   if (rad[i].checked)
      {
      	return rad[i].value;
      }
   }
}
function checkEmail(email) {
var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
return (filter.test(email)) ;
}


function mailing_validate(doc)
{
	var message = "The form has the following errors:\n"
	var errors = false;
	var form = doc.getElementById("contactme_form")
	if(form.username.value !="")
	{
		errors = true;
		message +="Are you human? you triggered a spam trap. If you are using some kind of auto fill in, pleaswe fill the form in by hand\n"
	}
	if(!checkEmail(form.email.value))
	{
		errors = true;
		message +="Your email adress needs to be in the form name@example.com\n"
	}
	if(form.name.value = "")
	{
		errors = true;
		message +="Please add your name\n"
	}

	//resopnd to failure by printing error and return false
	if(errors)
	{
    	window.alert (message);
		return false;
	}
	else
		return true;
	
}

function  validate_and_submit(doc)
{
	if(mailing_validate(doc))
	{
		var form = doc.getElementById("contactme_form");
		var form_holder = doc.getElementById("form_holder");
		
		//deal with radios and "other"
		var res = get_reason_value(form);
		var ref = get_referral_value(form);
		var other_res =" ";
		var other_ref=" ";
		if (res == "Other")
			other_res = form.reasonother.value;
		if (ref == "Other")
			other_ref = form.referralother.value;
		var av = form.additional_info.value;
	//build output
		var st = "<form id='contactme_form' action='contactme.php' method='post'><div class='form_description'> <p class='black'>"
		+" <strong class='instructions'>Please verify your information and click Send.</strong></p></div> "
		+"<label class='info_verify'>Name: </label> "
		+form.contact_name.value 
		+"<br/><br/><label class='info_verify'>Phone: </label>"
		+form.areacode.value+" - "+form.prefix.value+" - "+form.suffix.value
		+"<br/><br/><label class='info_verify'>Email: </label>"
		+form.email.value
		+"<br/><label class='info_verify'>Interest: </label><br/>"
		+res
		+"<br/>"
		+other_res
		+"<br/><label class='info_verify'>Refferal: </label><br/>"
		+ref
		+"<br/>"
		+other_ref
		+"<br/><label class='info_verify'>Additional Information: </label><br/>"
		+av
		
		+"<input type='hidden' name='contact_name' value='"+form.contact_name.value+"'>"
		+"<input type='hidden' name='email' value='"+form.email.value+"'>"
		+"<input type='hidden' name='prefix' value='"+form.prefix.value+"'>"
		+"<input type='hidden' name='suffix' value='"+form.suffix.value+"'>"
		+"<input type='hidden' name='areacode' value='"+form.areacode.value+"'>"
	
		+"<input type='hidden' name='reason' value='"+res+"'>"
		+"<input type='hidden' name='reasonother' value='"+other_res+"'>"
		+"<input type='hidden' name='referral' value='"+ref+"'>"
		+"<input type='hidden' name='refferalother' value='"+other_ref+"'>"
		+"<input type='hidden' name='additional_info' value='"+av+"'>"
		+"<input type='hidden' name='js_loaded' value='1'>"
		
		
     +"<p class='instructions'>Please click the 'Send' button only once. Depending upon the speed of your internet connection, it may take a few second to process your submission.</p>"
	 +"<input type='submit' value='Send' ><input type='button' value='Go Back' onclick='revert_form()'></form><br/><br/>";
	 form_holder.innerHTML = st;
	 window.scroll(0,0);
	}
	
}


function revert_form(){
window.location.reload();
}

-->
