function validateFields() {

var frmEl = document.getElementById('cForm');

var posName = document.getElementById('scompany_name');

var posEmail = document.getElementById('semail');

var posUName = document.getElementById('suser_name');

var posFName = document.getElementById('sfirst_name');

var posLName = document.getElementById('slast_name');

var posSubdomain = document.getElementById('ssubdomain');

var posPhone = document.getElementById('sphone');

var posPass = document.getElementById('spassword');

var posPassConfirmation = document.getElementById('spassword-confirmation');

//var posTerms = document.getElementById('sterms_agree');

var posPlans = document.getElementById('splan_name');

var posSubdompar = document.getElementById('ssubdomainpar');

var whiteSpace = /^[\s]+$/;

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

var subdomainRegex = /^[a-zA-Z0-9]+-?[a-zA-Z0-9]+$/i;



	if ( posFName.value == '' || posLName.value == ''){

		alert('Your have not entered your name.');

		if (posFName.value == '')	{posFName.focus();}

		else {posLName.focus();}

	}

	else if ( posEmail.value == '') {

		alert('You have not typed in an email for us to respond.  Please type someting in for our response.');

		posEmail.focus();

	}

	else if(!filter.test(posEmail.value)){

		alert('Please enter a valid email address');

		posEmail.select();

		posEmail.focus();

	}

	else if ( posUName.value.length < 6){

    alert('Your username must be at least 6 characters long.');

    posUName.select();

		posUName.focus();

	}

	else if ( posPass.value.length < 6){

    alert('Your password must be at least 6 characters long.');

    posPass.select();

		posPass.focus();

	}

	else if (posPass.value!=posPassConfirmation.value){

    alert('Your password and confirmation does not match.  Please re-enter your passwords to match.');

    posPass.value="";

    posPassConfirmation.value="";

		posPass.focus();

	}

	else if (posSubdomain.value==''){

    alert('Your subdomain for your account is empty. Please type something in. We recommend your company name.');

    posSubdomain.focus();

	}

	else if (!subdomainRegex.test(posSubdomain.value)) {

		alert('subdomain can only contain a-Z, 0-9 and -\'s');

		posSubdomain.focus();

	}

	else if (posSubdomain.value.toLowerCase()=='www'||posSubdomain.value.toLowerCase()=='http'||posSubdomain.value.toLowerCase()=='https'){

    alert('Your subdomain for your account must not be the prefixs/accounts named "www", "http" nor "https"');

    posSubdomain.focus();

	}

	//else if (!posTerms.checked){

	//	alert('To signup for an account, you must agree to our terms of service.  Please review the terms.');

	//}

	else {return true;}

	return false;

}

function validateFields2() {

var frmEl = document.getElementById('cForm');

var posFName = document.getElementById('bfirst_name');

var posLName = document.getElementById('blast_name');

var posAddress = document.getElementById('baddress');

var posCity = document.getElementById('bcity');

var posZip = document.getElementById('bzip');

var posCC_num = document.getElementById('bcc_num');

var posCVV2 = document.getElementById('bcvv2');

var posTerms = document.getElementById('sterms_agree');

var whiteSpace = /^[\s]+$/;

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

var subdomainRegex = /^[a-zA-Z0-9]+-?[a-zA-Z0-9]+$/i;

var ccNumbRegex = /^[0-9]{16}$/i;



	if ( posFName.value == '' || posLName.value == ''){

		alert('Your have not entered your name.');

		if (posFName.value == '')	{posFName.focus();}

		else {posLName.focus();}

	}

	else if ( posAddress.value == '') {

		alert('You have not typed in a billing address.');

		posAddress.focus();

	}


	else if (posCity.value==''){

    alert('You have not typed in a billing city');

    posCity.focus();

	}
	
	else if (posZip.value==''){

    alert('You have not typed in a billing zip code or mailing code');

    posZip.focus();

	}

	else if (!ccNumbRegex.test(posCC_num.value)) {

		alert('You have entered an invalid credit card number.  Please verify this and make changes as needed.');

		posCC_num.focus();

	}

    else if (posCVV2.value==''){

    alert('You have not typed in a billing credit card validation number (CVV2 number)');

    posCVV2.focus();

	}
	else if (!posTerms.checked){

		alert('To signup for an account, you must agree to our terms of service.  Please review the terms.');

	}

	else {return true;}

	return false;

}


function sendPosFreeEmail (posName, posEmail, posFName, posLName, posSubdomain, posPhone, posPass, posPassConfirmation, posUName, posSubdompar, posPlan)

{

	var page = "scripts/xmlHttpRequest.php?contact=true&xml=true";

    

	showContactTimer(); // quickly begin the load bar

	document.getElementById('emailSuccess').style.display = 'none'; // hide the success bar (incase this is a multi-email



	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.

	var str1 = posName;

	str1 = str1.replace(/&/g,"**am**");

	str1 = str1.replace(/=/g,"**eq**");

	str1 = str1.replace(/\+/g,"**pl**");

	var str2 = posEmail;

	str2 = str2.replace(/&/g,"**am**");

	str2 = str2.replace(/=/g,"**eq**");

	str2 = str2.replace(/\+/g,"**pl**");

	var str3 = posFName;

	str3 = str3.replace(/&/g,"**am**");

	str3 = str3.replace(/=/g,"**eq**");

	str3 = str3.replace(/\+/g,"**pl**");

	var str5 = posLName;

	str5 = str5.replace(/&/g,"**am**");

	str5 = str5.replace(/=/g,"**eq**");

	str5 = str5.replace(/\+/g,"**pl**");

	var str4 = posSubdomain;

	str4 = str4.replace(/&/g,"**am**");

	str4 = str4.replace(/=/g,"**eq**");

	str4 = str4.replace(/\+/g,"**pl**");

	var str6 = posPhone;

	str6 = str6.replace(/&/g,"**am**");

	str6 = str6.replace(/=/g,"**eq**");

	str6 = str6.replace(/\+/g,"**pl**");

	var str7 = posPass;

	str7 = str7.replace(/&/g,"**am**");

	str7 = str7.replace(/=/g,"**eq**");

	str7 = str7.replace(/\+/g,"**pl**");

	var str8 = posPassConfirmation;

	str8 = str8.replace(/&/g,"**am**");

	str8 = str8.replace(/=/g,"**eq**");

	str8 = str8.replace(/\+/g,"**pl**");

	var str9 = posUName;

	str9 = str9.replace(/&/g,"**am**");

	str9 = str9.replace(/=/g,"**eq**");

	str9 = str9.replace(/\+/g,"**pl**");

	var str10 = posPlan;

    var str11 = posSubdompar;

    

	var stuff = "posName="+str1+"&posEmail="+str2+"&posFName="+str3+"&posLName="+str5+"&posSubdomain="+str4+"&posPhone="+str6;

	stuff += "&posPass="+str7+"&posPassConfirmation="+str8+"&posUName="+str9+"&posPlan="+str10+"&posSubdompar="+str11;

    

    loadXMLPosDoc(page,stuff)

}



function sendPosEmail (free) {

var frmEl = document.getElementById('cForm');

var posName = document.getElementById('scompany_name');

var posEmail = document.getElementById('semail');

var posUName = document.getElementById('suser_name');

var posFName = document.getElementById('sfirst_name');

var posLName = document.getElementById('slast_name');

var posSubdomain = document.getElementById('ssubdomain');

var posPhone = document.getElementById('sphone');

var posPass = document.getElementById('spassword');

var posPassConfirmation = document.getElementById('spassword-confirmation');

var posPlans = document.getElementById('splan_name');

var posSubdompar = document.getElementById('ssubdomainpar');



	var page = "scripts/xmlHttpRequest.php?contact=true&xml=true";

    

    if (free == false){

    	showContactTimer(); // quickly begin the load bar

    	document.getElementById('emailSuccess').style.display = 'none'; // hide the success bar (incase this is a multi-email

	}

    

	// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.

	var str1 = posName.value;

	str1 = str1.replace(/&/g,"**am**");

	str1 = str1.replace(/=/g,"**eq**");

	str1 = str1.replace(/\+/g,"**pl**");

	var str2 = posEmail.value;

	str2 = str2.replace(/&/g,"**am**");

	str2 = str2.replace(/=/g,"**eq**");

	str2 = str2.replace(/\+/g,"**pl**");

	var str3 = posFName.value;

	str3 = str3.replace(/&/g,"**am**");

	str3 = str3.replace(/=/g,"**eq**");

	str3 = str3.replace(/\+/g,"**pl**");

	var str5 = posLName.value;

	str5 = str5.replace(/&/g,"**am**");

	str5 = str5.replace(/=/g,"**eq**");

	str5 = str5.replace(/\+/g,"**pl**");

	var str4 = posSubdomain.value;

	str4 = str4.replace(/&/g,"**am**");

	str4 = str4.replace(/=/g,"**eq**");

	str4 = str4.replace(/\+/g,"**pl**");

	var str6 = posPhone.value;

	str6 = str6.replace(/&/g,"**am**");

	str6 = str6.replace(/=/g,"**eq**");

	str6 = str6.replace(/\+/g,"**pl**");

	var str7 = posPass.value;

	str7 = str7.replace(/&/g,"**am**");

	str7 = str7.replace(/=/g,"**eq**");

	str7 = str7.replace(/\+/g,"**pl**");

	var str8 = posPassConfirmation.value;

	str8 = str8.replace(/&/g,"**am**");

	str8 = str8.replace(/=/g,"**eq**");

	str8 = str8.replace(/\+/g,"**pl**");

	var str9 = posUName.value;

	str9 = str9.replace(/&/g,"**am**");

	str9 = str9.replace(/=/g,"**eq**");

	str9 = str9.replace(/\+/g,"**pl**");

	var str10 =  posSubdompar.options[posSubdompar.selectedIndex].value;

	str10 = str10.replace(/&/g,"**am**");

	str10 = str10.replace(/=/g,"**eq**");

	str10 = str10.replace(/\+/g,"**pl**");

	

	var stuff = "posName="+str1+"&posEmail="+str2+"&posFName="+str3+"&posLName="+str5+"&posSubdomain="+str4+"&posPhone="+str6;

	stuff += "&posPass="+str7+"&posPassConfirmation="+str8+"&posUName="+str9+"&posPlan="+posPlans.value+"&posSubdompar="+str10;

    

    if (free == false){

        loadXMLPosDoc(page,stuff)

    } else {

        window.location = "validate.php?"+stuff;

    }

}

function showContactTimer () {

	var loader = document.getElementById('loadBar');

	loader.style.display = 'block';

	sentTimer = setTimeout("hideContactTimer()",6000);

}



function hideContactTimer (validate) {

	var loader = document.getElementById('loadBar');

	var success = document.getElementById('emailSuccess');

	//var fieldArea = document.getElementById('contactFormArea');

	//var inputs = fieldArea.getElementsByTagName('input');

	//var inputsLen = inputs.length;

	//var tAreas = fieldArea.getElementsByTagName('textarea');

	//var tAreasLen = tAreas.length;

	// Hide the load bar alas! Done Loading

	

	

	loader.style.display = "none";

	success.style.display = "block";

	success.innerHTML = '<strong style="color:green;">'+grabPosXML("confirmation")+'</strong>';

	// Now Hijack the form elements

    if ( validate != '' ){

    	document.getElementById('scompany_name').value='';

    	document.getElementById('semail').value='';

    	document.getElementById('suser_name').value='';

    	document.getElementById('sfirst_name').value='';

    	document.getElementById('slast_name').value=''

    	document.getElementById('ssubdomain').value='';

    	document.getElementById('sphone').value='';

    	document.getElementById('spassword').value='';

    	document.getElementById('spassword-confirmation').value='';

   }

}






/*
 * 
 * We need to check a few things...
 * 
 * All fields are correct
 * The subdomain is NOT in use
 * 
 * 
 * 
 */
function validateFields_stepone(){
	

	var sub = document.getElementById('ssubdomain').value;
	var subpar = document.getElementById('ssubdomainpar');
	var subdomainpar  = subpar.options[subpar.selectedIndex].value;
	

	
	AJAX_call('http://perfectshare.net/signupTEST.php?ajax_type=domain_check',
	'post',
	'subdomain='+sub+'&subpar='+subdomainpar,
	function(o){
		var response = o.responseText || "0";
		if(response=='0'){//bad
			
			alert('The subdomain is already in use');
	    }else if(response=='2'){//bad - blank
		
		    alert('You must select a subdomain');
		
		}else{//good
			
			var frmEl = document.getElementById('cForm');

			var posName = document.getElementById('scompany_name');
			
			var posEmail = document.getElementById('semail');
			
			var posUName = document.getElementById('suser_name');
			
			var posFName = document.getElementById('sfirst_name');
			
			var posLName = document.getElementById('slast_name');
			
			var posSubdomain = document.getElementById('ssubdomain');
			
			var posPhone = document.getElementById('sphone');
			
			var posPass = document.getElementById('spassword');
			
			var posPassConfirmation = document.getElementById('spassword-confirmation');
			
			//var posTerms = document.getElementById('sterms_agree');
			
			var posPlans = document.getElementById('splan_name');
			
			var posSubdompar = subdomainpar;
			
			var whiteSpace = /^[\s]+$/;
			
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			
			var subdomainRegex = /^[a-zA-Z0-9]+-?[a-zA-Z0-9]+$/i;
			
			
			
			if ( posFName.value == '' || posLName.value == ''){
		
				alert('Your have not entered your name.');
		
				if (posFName.value == '')	{posFName.focus();}
		
				else {posLName.focus();}
		
			}
		
			else if ( posEmail.value == '') {
		
				alert('You have not typed in an email for us to respond.  Please type someting in for our response.');
		
				posEmail.focus();
		
			}
		
			else if(!filter.test(posEmail.value)){
		
				alert('Please enter a valid email address');
		
				posEmail.select();
		
				posEmail.focus();
		
			}
		
			else if ( posUName.value.length < 6){
		
		    alert('Your username must be at least 6 characters long.');
		
		    posUName.select();
		
				posUName.focus();
		
			}
		
			else if ( posPass.value.length < 6){
		
		    alert('Your password must be at least 6 characters long.');
		
		    posPass.select();
		
				posPass.focus();
		
			}
		
			else if (posPass.value!=posPassConfirmation.value){
		
		    alert('Your password and confirmation does not match.  Please re-enter your passwords to match.');
		
		    posPass.value="";
		
		    posPassConfirmation.value="";
		
				posPass.focus();
		
			}
		
			else if (posSubdomain.value==''){
		
		    alert('Your subdomain for your account is empty. Please type something in. We recommend your company name.');
		
		    posSubdomain.focus();
		
			}
		
			else if (!subdomainRegex.test(posSubdomain.value)) {
		
				alert('subdomain can only contain a-Z, 0-9 and -\'s');
		
				posSubdomain.focus();
		
			}
		
			else if (posSubdomain.value.toLowerCase()=='www'||posSubdomain.value.toLowerCase()=='http'||posSubdomain.value.toLowerCase()=='https'){
		
		    alert('Your subdomain for your account must not be the prefixs/accounts named "www", "http" nor "https"');
		
		    posSubdomain.focus();
		
			}
		
			else {
				
			
				createPP_prepops();
				var pars = "ssubdomain="+sub+"&ssubdomain_par="+subdomainpar;
				pars+="&scompany_name="+posName.value+"&sfirst_name="+posFName.value+"&slast_name="+posLName.value+"&sphone="+posPhone.value;
				pars+="&suser_name="+posUName.value+"&spassword="+posPass.value+"&splan_name="+posPlans.value+"&semail="+posEmail.value;
	            pars+="&order_id="+document.getElementById('custom').value;
			
				
				var ajax_call_order = AJAX_call('http://perfectshare.net/signupTEST.php?ajax_type=set_order',
				'post',
				pars,
				function(obj){
					var response = obj.responseText || "0";
					if(response=='0'){//bad
						
						alert('There was an error in your request.');
						
					}else{//good
					   
						document.cForm.submit();
					}
					
				});
				
		    }
		
			//return false;

			
			
		}
	});
	
	
	
}



function AJAX_call(url,meth,vars,succ){
	

    

    var req=new Ajax.Request(url,
  	{
		parameters:vars,
	    method:meth,
	    onSuccess: function(o){
	        succ(o);
	    },
	    onFailure: function(){
			 alert('Something went wrong...'); 
	    }
		
  	});

}


/* function creates PayPal prepop vars for form submission */
function createPP_prepops(){
	
	var posEmail = document.getElementById('semail');
	var posFName = document.getElementById('sfirst_name');
	var posLName = document.getElementById('slast_name');
	var posPhone = document.getElementById('sphone');
	
	var ppEmail = document.getElementById('ppEmail');
	var ppFName = document.getElementById('ppFName');
	var ppLName = document.getElementById('ppLName');
	var ppPhoneA = document.getElementById('ppPhoneA');
	var ppPhoneB = document.getElementById('ppPhoneB');
	var ppPhoneC = document.getElementById('ppPhoneC');
	var ppPhoneHome = document.getElementById('H_PhoneNumber');
	
	ppEmail.value = posEmail.value;
	ppFName.value = posFName.value;
	ppLName.value = posLName.value;
	ppPhoneHome.value = posPhone.value;
	var t_phone = new Array();
	t_phone = createNakedPhone(posPhone.value);
	
	if(t_phone[0]!=''){
		
		ppPhoneA.value = t_phone[0];
		ppPhoneB.value = t_phone[1];
		ppPhoneC.value = t_phone[2];
		
	}
	
}

/*only for US numbers*/
function createNakedPhone(numb){
	
	
	numb = new String(numb);
	var temp_numb = numb.replace(/[^0-9]/g, '');
	//temp_numb = temp_numb.replace(/\)/,'');
	//temp_numb = temp_numb.replace(/-/,'');
	//temp_numb = temp_numb.replace(/ /,'');

	var phone_numb=new Array();
	
	if(temp_numb.length==10){
		
		phone_numb[0] = temp_numb.substr(0,3);
		phone_numb[1] = temp_numb.substr(3,3);
		phone_numb[2] = temp_numb.substr(6,4);
		
	}
	
	return phone_numb;
	
}


/*

function ajaxContact() {

var frmEl = document.getElementById('cForm');

addEvent(frmEl, 'submit', validateFields, false);

frmEl.onsubmit = function() { return false; }

}*/

//addEvent('load',ajaxContact, false);