/**
 * prelaunch_checkform.js
 *
 * This file is copyrighted; you cannot redistribute it and/or
 * modify it under any circumstance.
 *
 * @version 1.0.0
 * @copyright Copyright: 2009 Harun & Josh
 * @author Josh Beistle <josh@usprofitsearch.com>
 */



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 CheckForm(fname, lname, email, phone, u, c, cr) {
	
	document.getElementById('submit_btn').disabled = true;
	var datetime = new Date();
	// This will record a lead and unique visitorid after the form is submitted
	var url = 'prelaunch_record_lead.php';
	var args = '?fname=' + escape(fname);
		args += '&lname=' + escape(lname);
		args += '&email=' + escape(email);
		args += '&phone=' + escape(phone);
		args += '&username=' + escape(document.getElementById('username').value);
		args += '&password=' + escape(document.getElementById('password').value);
		args += '&sponsor_username=' + u;
		args += '&sponsor_campaign=' + c;
		args += '&cr=' + cr;
		args += '&cl=' + document.cookie.length;
		args += '&cd=' + screen.colorDepth;
		args += '&je=' + navigator.javaEnabled();
		args += '&lang=' + escape(navigator.language);
		args += '&pf=' + escape(navigator.platform);
		args += '&res=' + escape(screen.width+ 'x' +screen.height);
		args += '&sl=' + escape(navigator.systemLanguage); // ie only
		args += '&tzoff=' + datetime.getTimezoneOffset();
		args += '&page=' + escape(window.location.href);
		args += '&rand=' + Math.random();
		
		document.getElementById('custom_http_referer').value = window.location.href;
		document.getElementById('subscriber_name').value = fname+' '+lname;
		document.getElementById('subscriber_email').value = email;
		document.getElementById('custom_Phone').value = phone;
		document.getElementById('custom_username').value = document.getElementById('username').value;
		document.getElementById('custom_afflink').value = 'http://www.800moneymaker.com/?id='+document.getElementById('username').value;
		//alert(url+args);
	try {
		http.open('GET',  url+args);
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = CheckFormResponseText;
		http.send(null);
	}
	catch(e){}
	finally{}
}


function CheckFormResponseText() {
	try {
		document.getElementById('fname').style.backgroundColor= "";
		document.getElementById('lname').style.backgroundColor= "";
		document.getElementById('email').style.backgroundColor= "";
		document.getElementById('phone').style.backgroundColor= "";
		document.getElementById('username').style.backgroundColor= "";
		document.getElementById('password').style.backgroundColor= "";
		
		if ((http.readyState == 4) && (http.status == 200)) {
			document.getElementById('submit_btn').disabled = false;
			var response = http.responseText;
			if (response == 'fname') {
				alert('First Name is required\n(must consist of A-Z, spaces, 2-25 characters only)');
				document.getElementById('fname').style.backgroundColor= "#FF0000";
				document.getElementById('fname').focus();
				return false;
			}
			if (response == 'lname') {
				alert('Last Name is required\n(must consist of A-Z, spaces, 2-25 characters only)');
				document.getElementById('lname').style.backgroundColor= "#FF0000";
				document.getElementById('lname').focus();
				return false;
			}
			if (response == 'bademail') {
				alert('An account with that email already exists.\nPlease use a different Email Address');
				document.getElementById('email').style.backgroundColor= "#FF0000";
				document.getElementById('email').focus();
				return false;
			}
			if (response == 'email') {
				alert('Email is required');
				document.getElementById('email').style.backgroundColor= "#FF0000";
				document.getElementById('email').focus();
				return false;
			}
			if (response == 'phone') {
				alert('Please Enter A Valid Phone Number To See The Power Of This System!');
				document.getElementById('phone').style.backgroundColor= "#FF0000";
				document.getElementById('phone').value = "???-???-????";
				document.getElementById('phone').focus();
				return false;
			}
			if (response == 'badusername') {
				alert('That username is already taken');
				document.getElementById('username').style.backgroundColor= "#FF0000";
				document.getElementById('username').focus();
				return false;
			}
			if (response == 'username') {
				alert('Username must be 4-16 characters in length.\nAlpha-numerical only');
				document.getElementById('username').style.backgroundColor= "#FF0000";
				document.getElementById('username').focus();
				return false;
			}
			if (response == 'password') {
				alert('Please define a password for your membership account');
				document.getElementById('password').style.backgroundColor= "#FF0000";
				document.getElementById('password').focus();
				return false;
			}
			if (response == 'badphone') {
					alert('Please Enter A Valid Phone Number To See The Power Of This System!');
					document.getElementById('phone').style.backgroundColor= "#FF0000";
					document.getElementById('phone').value = "???-???-????";
					document.getElementById('phone').focus();
					return false;
			}
			if (response == 'wait') {
				alert('Whoa buddy! You just created a membership account.\nWait a few minutes before you signup another account');
				return false;
			}
			if (response == 'ban') {
				alert('Error: Please contact Josh immediately! (602) 686-7218');
				return false;
			}
			if (response == 'good') {
				document.form1.submit();
			}
		}
	}
	catch(e){alert(e);}
	finally{}
}

// This will record a unique pageview using body onload
function RPV(affid, campaign)
{
	var datetime = new Date();
	var image_url = new Image();
	var queries = "?cl=" + document.cookie.length;
	queries += "&affid=" + affid;
	queries += "&campaign=" + campaign;
	queries += "&cd=" + screen.colorDepth;
	queries += "&je=" + navigator.javaEnabled();
	queries += "&lang=" + escape(navigator.language);
	queries += "&pf=" + escape(navigator.platform);
	queries += "&res=" + escape(screen.width+ 'x' +screen.height);
	queries += "&sl=" + escape(navigator.systemLanguage);
	queries += "&tzoff=" + datetime.getTimezoneOffset();
	image_url.src='prelaunch_record_pageview.php'+queries;
	//alert(image_url.src);

}
