var http = createRequestObject();
function createRequestObject() {
	var xmlhttp;
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch(e) {
		try { 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(f) {
			xmlhttp=null;
		}
	}
	if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
		xmlhttp=new XMLHttpRequest();
	}
	return  xmlhttp;
}

function ValidateForm(num) {
	
	var name_field = String('name'+num);
	var phone_field = String('phone'+num);
	var email_field = String('email'+num);
	
	var name = document.getElementById(name_field).value;
	var phone = document.getElementById(phone_field).value;
	var email = document.getElementById(email_field).value;
	
	var datetime = new Date();
	
	var url = 'formCurl.php';
	var args = '?name=' + escape(name); 
		args += '&email=' + escape(email); 
		args += '&phone=' + escape(phone);
		args += '&rand=' + Math.random();
	try {
		http.open('GET',  url+args);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = handleResponseText;
		http.send(null);
	} catch(e){}
	finally{}
	
	function handleResponseText()
	{
		try {
			if ((http.readyState == 4) && (http.status == 200)) {
				var response = http.responseText;
				if (response == 'name') {
					alert('A Name is required\n(must consist of A-Z, spaces, 2-25 characters only)');
					document.getElementById(name_field).style.backgroundColor= "#FF0000";
					document.getElementById(name_field).focus();
					return false;
				} else {
					document.getElementById(name_field).style.backgroundColor= "";
				}
				if (response == 'phone') {
					alert('Please Enter A Valid Phone Number To See The Power Of This System!');
					document.getElementById(phone_field).style.backgroundColor= "#FF0000";
					document.getElementById(phone_field).value = "???-???-????";
					document.getElementById(phone_field).focus();
					return false;
				} else {
					document.getElementById(phone_field).style.backgroundColor= "";
				}
				if (response == 'badphone') {
					alert('Please Enter A Valid Phone Number To See The Power Of This System!');
					document.getElementById(phone_field).style.backgroundColor= "#FF0000";
					document.getElementById(phone_field).value = "???-???-????";
					document.getElementById(phone_field).focus();
					return false;
				} else {
					document.getElementById(phone_field).style.backgroundColor= "";
				}
				if (response == 'email') {
					alert('A valid Email is required');
					document.getElementById(email_field).style.backgroundColor= "#FF0000";
					document.getElementById(email_field).focus();
					return false;
				} else {
					document.getElementById(email_field).style.backgroundColor= "";
				}
				if (response == 'ban') {
					alert('Please limit registrations to one per household.\nProspects should be enrolling themselves from their own computer.\nIf you have questions regarding this policy please create a support ticket in the help desk.');
				}
				if (response == 'good')
				{
					document.getElementById('form'+num).submit();
				}
			}
		}
		catch(e){alert(e);}
		finally{}
	}
}
