
<!--

	var url = 'captcheck.php?code='; 
	var captchaOK = 2; // 2 - not yet checked, 1 - correct, 0 - failed 
	
	function getHTTPObject() 
	{ 
		try { 
		req = new XMLHttpRequest(); 
			} catch (err1) 
			{ 
			try { 
			req = new ActiveXObject("Msxml12.XMLHTTP"); 
			} catch (err2) 
			{ 
			try { 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
				} catch (err3) 
				{ 
			req = false; 
					} 
				} 
			} 
			return req; 
	} 
			
	var http = getHTTPObject(); // We create the HTTP Object 
			
	function handleHttpResponse() { 
		if (http.readyState == 4) { 
			captchaOK = http.responseText; 
			if(captchaOK != 1) { 
				alert('The entered anti-spam code was not correct. Please try again'); 
				document.leads.code.value=''; 
				document.leads.code.style.background = 'Yellow';
				document.leads.code.focus(); 
				return false; 
			} 
			document.leads.code.style.background = 'white';
			document.leads.submit(); 
		} 
	} 
			
	function checkcode(thecode) { 
		http.open("GET", url + escape(thecode), true); 
		http.onreadystatechange = handleHttpResponse; 
		http.send(null); 
	} 
			
	function checkform() { // First the normal form validation 
		//if(document.leads.req.value=='') { 
		//	alert('Please complete the "required" field'); 
		//	document.leads.req.focus(); 
		//	return false; 
		//} 
				
		if(document.leads.code.value=='') { 
			alert('Please enter the anti-spam string from the displayed image'); 
			document.leads.code.value='';
			document.leads.code.style.background = 'Yellow';
			document.leads.code.focus(); 
			return false; 
		} 
		// Now the Ajax CAPTCHA validation 
		checkcode(document.leads.code.value); 
		return false; 
	} 

/*
leads_gender[0]
Please indicate the teens gender

leads_pfirst_name
Please enter the parents first name

leads_plast_name
Please enter the parents last name

leads_email
Please enter a valid email address

leads_home_phone
Please enter your home phone number

leads_cfirst_name
Please enter the teens first name

leads_clast_name
Please enter the teens last name

leads_age
Please select the teens age
*/

//onsubmit="return validateFormOnSubmit(this)" 


function validateFormOnSubmit(theForm) {
var reason = "";

  //alert(checkcode(document.leads.code.value)); 
  //if(!checkcode(document.leads.code.value)) {
  //	return false;  
  //} 

  //reason += validatePhone(theForm.phone);
  //reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.leads_pfirst_name);
  reason += validateEmpty(theForm.leads_plast_name);
  reason += validateEmail(theForm.leads_email);
  reason += validatePhone(theForm.leads_home_phone);
  reason += validatePhone(theForm.leads_cell_phone);
  reason += validateEmpty(theForm.leads_cfirst_name);
  reason += validateEmpty(theForm.leads_clast_name);
  //reason += validateGender(theForm.leads_gender);
  reason += validateAge(theForm.leads_age);

  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
  // Now the Ajax CAPTCHA validation 
  checkcode(document.leads.code.value); 
  return false; 

  //return true;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateAge(fld) {
    var error = "";
	//alert(fld.selectedIndex);
    if (fld.selectedIndex == 0 ) {
        error = "Please select the teens age.\n";
        fld.style.background = 'Yellow';
    } else {
	    fld.style.background = 'White';	
	}
	return error;
}

function validateGender(fld) {
    var error = "";
    //alert(fld);
	if ((fld[0].checked == false) && (fld[1].checked == false)) {
        error = "Please indicate the teens gender.\n";
        document.getElementById("radiogroup").style.background = 'Yellow';
    } else {
	   document.getElementById("radiogroup").style.background = 'White';
	}
	return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    } else {
		fld.style.background = 'White';
	}
    return error;
}

function validateEmpty(fld) {
    var error = "";
 	//alert(fld.name);
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        
		if (fld.name == "leads_pfirst_name") {
			error = "Please enter the parents first name.\n"			
		}		
		if (fld.name == "leads_plast_name") {
			error = "Please enter the parents last name.\n"			
		}
		if (fld.name == "leads_cfirst_name") {
			error = "Please enter the teens first name.\n"			
		}
		if (fld.name == "leads_clast_name") {
			error = "Please enter the teens last name.\n"			
		}
		
    } else {
        fld.style.background = 'White';
    }
    return error;  
}


//-->