function pplCheckOutClicked()
{
    if (typeof logCustomEvent != 'undefined')
        logCustomEvent(140,'N/A','N/A','N/A');
    lockProcessPaymentPress(true);
	var myAjax = new Ajax.Request(
		currentURL+'&action=checkout&gbr=' + Math.random().toString().substr(3),
		{
			method: 'get',
			onSuccess: function(oHttp)
			{
			    lockProcessPaymentPress(false);
				var tokenURL = oHttp.responseText
				if(0==tokenURL.toLowerCase().lastIndexOf("https://")) //OK token
					document.location.href = tokenURL;
				else
					showPPLErrors();			
			},
			
			onFailure: function(oHttp){showPPLErrors();}
		}
	);
}
function setQueryPlan(planValue)
{
	currentURL = currentURL.replace(/(&|\?)qplan=[0-9]{0,4}/g,'');
	currentURL = currentURL+'&qplan='+planValue;
}
function lockProcessPaymentPress(isLock)
{
    // lock the submit button from being pressed and validate all other controls
    if (typeof $('btnProcess').onclick != 'undefined')
        if (isLock)
            $('btnProcess').onclick = '';
        else
            $('btnProcess').onclick = 'processPayment();';
}
function checkRadio()
{
	var pr = $i('Paypal');
	
	if(pr == null) return;
	
	if(pr.checked) pplCheckOutClicked();
}

function startEndProcess(start) {
    if (start) {
        $('btnProcess').addClassName("g_hidden");
        //Replaced for bug 4773
		//hide('btnProcess');
		$('imgProcess').style.display = "inline"
	}
	else {
	    hide('imgProcess');
	    //Replaced for bug 4773
	    //$('btnProcess').style.display = "inline";
	    $('btnProcess').removeClassName("g_hidden");
	}
	var objAgree = $('agree');
	if(null!=objAgree && undefined!=objAgree)
		objAgree.disabled = start;
}


function processPaymentOk(pplValues)
{
	var payVals = $H(pplValues).toQueryString();
	var myAjax = new Ajax.Request(
		currentURL+'&action=directpay&'+payVals+'&gbr=' + Math.random().toString().substr(3),
		{
			method: 'get',
			onSuccess: function(oHttp)
			{
				var tranURL = oHttp.responseText;
				if(0==tranURL.toLowerCase().lastIndexOf("http")) //OK token
					document.location.href = tranURL;
				else
				{
					if (oHttp.responseText == 'isOnce') {
						if (typeof logCustomEvent != 'undefined')
							logCustomEvent(141,'N/A','N/A','N/A');
						show('pplFirstError');
						startEndProcess(false); }
					else {
						if (typeof logCustomEvent != 'undefined')
							logCustomEvent(142,'N/A','N/A','N/A');
							showPPLErrors(); }
				    
					if($('isAddressShown').value != 1)
					{
						$('isAddressShown').value = 1;
						show('addressDiv');
						checkCreatePayValues();
						show('billingErrorCap');
						hide('errorsCap');
					}
					
				}
			},
			onFailure: function(oHttp){showPPLErrors();}
		}
	);	
}
function processPaymentCPS()
{
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		processPaymentOk(pplValues);
	}
}	
function processPaymentCPSNew(bMissingData)
{
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.ISCPS = 1;
		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 21;
				
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp)
					{
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');	
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else
						{
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){


						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			
			processPaymentOk(pplValues);
		}
	}
}	
function processPaymentCPSBundle(bMissingData)
{
	var buy_gs = $('buy_gs');
	
	if(buy_gs !=  null)
	{
		if(buy_gs.checked)
		{
			currentURL = currentURLGS;
			processPayment(bMissingData);
			return;
		}
	}
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.ISCPS = 1;
		pplValues.ISBUNDLE = 1;
		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 22;
				
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp)
					{
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');	
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else
						{
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){


						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			
			processPaymentOk(pplValues);
		}
	}
}	
function processPaymentGsSubscribe(bMissingData)
{
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.IS_GS_SUBSCRIPTION = 1;

		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 24;
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp) {
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else {
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){

						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			processPaymentOk(pplValues);
		}
	}
}

function processPaymentChatSubscribe(bMissingData)
{
	
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.IS_CHAT_SUBSCRIPTION = 1;

		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 25;
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp) {
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else {
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){

						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			processPaymentOk(pplValues);
		}
	}
}
function processPaymentUpdate()
{
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		processPaymentOk(pplValues);
	}
}
function processPaymentUpgrade()
{
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		processPaymentOk(pplValues);
	}
}
function processPaymentSubChoose(bMissingData)
{
	
	var rbplangs = $i('rbplangs');
	var rbplanchat = $i('rbplanchat');
	
	if(rbplangs !=  null)
	{
		if(rbplangs.checked || (rbplanchat !=  null && rbplanchat.checked))
		{
			currentURL = currentURLGS;
			processPayment(bMissingData);
			return;
		}
	}
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.IS_GS_SUBSCRIPTION = 1;

		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 24;
				
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp)
					{
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');	
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else
						{
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){


						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			
			processPaymentOk(pplValues);
		}
	}
}
	
function processPaymentCPSTotal(bMissingData)
{
	var buy_gs = $('buy_gs');
	
	if(buy_gs !=  null)
	{
		if(buy_gs.checked)
		{
			currentURL = currentURLGS;
			processPayment(bMissingData);
			return;
		}
	}
	startEndProcess(true);
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		pplValues.ISCPS = 1;
		pplValues.ISBUNDLE = 1;
		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 23;
				var cpsid = $F('cpsid_span');
				
				if(cpsid == null || cpsid == '' || cpsid == 0)
					startEndProcess(false);
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype+'&cpsid='+ cpsid,
					onSuccess: function(oHttp)
					{
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');	
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else
						{
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){


						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			
			processPaymentOk(pplValues);
		}
	}
}	
function processPayment(bMissingData)
{
	startEndProcess(true);
	clearErrors();
	var pplValues = checkCreatePayValues();
	if(null==pplValues)
		startEndProcess(false);
	else
	{
		
		var hdn_f5_plan = $i('hdn_f5_plan');
		var hdn_an_plan = $i('hdn_an_plan');
		var hdn_net_plan = $i('hdn_net_plan');
		var hdn_netcars_plan = $i('hdn_netcars_plan');


		if(hdn_net_plan != null)
		{
			itype = hdn_net_plan.value;
			if(typeof logEvent != 'undefined')
			{
			/*
			5450	LP - Purchase First GS option (Group  / net)
			5451	LP - Purchase Second GS option (Group  / net)
			5452	LP - Purchase Chat (Group  / net)
			*/
				var evt = 5452;
				
				switch(itype)
				{
					case '0': //gs
					{
						evt = 5451;
						break;
					}
					case '1': //chat
					{
						evt = 5452;
						break;
					}
					case '2': //gs1
					{
						evt = 5450;
						break;
					}					
				}
				logEvent(evt);		
			}
		}	
		if(hdn_netcars_plan != null)
		{
			itype = hdn_netcars_plan.value;
			if(typeof logEvent != 'undefined')
			{
			/*
			5450	LP - Purchase First GS option (Group  / net)
			5451	LP - Purchase Second GS option (Group  / net)
			5452	LP - Purchase Chat (Group  / net)
			*/
				var evt = 5452;
				
				switch(itype)
				{
					case '0': //gs
					{
						evt = 5596;
						break;
					}
					case '1': //chat
					{
						evt = 5597;
						break;
					}
					case '2': //gs1
					{
						evt = 5598;
						break;
					}
					case '3': //gs2
					{
						evt = 5595;
						break;
					}					
				}
				logEvent(evt);		
			}
		}	
				
		if(hdn_f5_plan != null)
		{
			itype = hdn_f5_plan.value;
			if(typeof logEvent != 'undefined')
			{
			/*
			5450	LP - Purchase First GS option (Group  /lpgetsolution5.aspx)
			5451	LP - Purchase Second GS option (Group  /lpgetsolution5.aspx)
			5452	LP - Purchase Chat (Group  /lpgetsolution5.aspx)
			*/
				var evt = 5452;
				
				switch(itype)
				{
					case '0': //gs
					{
						evt = 5451;
						break;
					}
					case '1': //chat
					{
						evt = 5452;
						break;
					}
					case '2': //gs1
					{
						evt = 5450;
						break;
					}
				}
				logEvent(evt);		
			}
		}	
		if(hdn_an_plan != null)
		{
			itype = hdn_an_plan.value;
			if(typeof logEvent != 'undefined')
			{
			/*
			5566	LP - Purchase Cheap GS option		(Ask New)
			5504	LP - Purchase Expensive GS option	(Ask New)
			5565	LP - Purchase Chat					(Ask New)
			*/
				var evt = 5452;
				
				switch(itype)
				{
					case '0': //gs - expensive
					{
						evt = 5504;
						break;
					}
					case '1': //chat
					{
						evt = 5565;
						break;
					}
					case '2': //gs1 - cheap
					{
						evt =  5566;
						break;
					}
				}
				logEvent(evt);		
			}
		}			
		if(typeof bMissingData != 'undefined' && bMissingData)
		{
				var itype = 0;
				var rbplangs_b = $i('rbplangs');
				var hdnplan_b = $i('hdnplangs');
				var rbplangs_a = $i('rbplangs_new');
				var hdnplan_a = $i('hdnplangs_new');
				var rbLocal = $i('rbLocal');
				var rvNational = $i('rvNational');
			
				if(rbplangs_b != null)
				{
					itype = rbplangs_b.checked ? rbplangs_b.value : $F('rbplanchat');
					
					if(typeof logEvent != 'undefined')
					{
					/*
					5454	LP - Purchase GS - /lpgetsolution3_B.aspx
					5455	LP - Purchase Chat - /lpgetsolution3_B.aspx
					*/
						var evt = 5455;
						
						switch(itype)
						{
							case '0': //gs
							{
								evt = 5454;
								break;
							}
							case '1': //chat
							{
								evt = 5455;
								break;
							}
						}
						logEvent(evt);		
					}
				}
				else if(hdnplan_b != null)
				{
					itype = hdnplan_b.value;
					if(typeof logEvent != 'undefined')
					{
					/*
					5454	LP - Purchase GS - /lpgetsolution3_B.aspx
					*/
						var evt = 5454;
						logEvent(evt);		
					}
				}
				else if(rbplangs_a != null)
				{
					var rbplangs1_a = $i('rbplangs1_new');
					itype = rbplangs_a.checked ? rbplangs_a.value : (rbplangs1_a.checked ? rbplangs1_a.value : $F('rbplanchat_new'));
					
					if(typeof logEvent != 'undefined')
					{
					/*
					5450	LP - Purchase First GS option (Group  /lpgetsolution3_A.aspx)
					5451	LP - Purchase Second GS option (Group  /lpgetsolution3_A.aspx)
					5452	LP - Purchase Chat (Group  /lpgetsolution3_A.aspx)
					*/
						var evt = 5452;
						
						switch(itype)
						{
							case '0': //gs
							{
								evt = 5451;
								break;
							}
							case '1': //chat
							{
								evt = 5452;
								break;
							}
							case '2': //gs1
							{
								evt = 5450;
								break;
							}
						}
						logEvent(evt);		
					}
				}
				else if(hdnplan_a != null)
				{
					itype = hdnplan_a.value;
					if(typeof logEvent != 'undefined')
					{
					/*
					5451	LP - Purchase GS (Group  /lpgetsolution3_A.aspx)
					*/
						var evt = 5451;
						logEvent(evt);		
					}
				}
				var myAjax = new Ajax.Request(
				'/pplLogin.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					postBody: 'email='+$F('email')+'&pass='+ $F('pass')+'&type='+ itype,
					onSuccess: function(oHttp)
					{
						//alert(oHttp.responseText);
						
						var res = oHttp.responseText;
						var iend = res.lastIndexOf('}');
						res = res.substring(0, iend+1);
						res = res.replace(/\n\r/gi,' ').replace(/\n/gi,' ').replace(/\r/gi,' ');
						
						if(res != "" && res != "{}")
						{
							var resultMap =  eval('(' + res + ')');	
							var returncode = parseInt(resultMap.code);
							if(returncode == 1)//success
							{
								hide('passrow');
								hide('emailtip');
								hide('forgotpass');
								hide('iagree');
								$('email').disabled = true;
								processPaymentOk(pplValues);
							}
							else if(returncode == 2)//need password
							{
								show('passrow');
								hide('emailtip');
								show('forgotpass');
								hide('iagree');
								startEndProcess(false);
							}
							else if(returncode == 3)//bad password?
							{
								hide('passtip');
								makeError('pass', 'password does not match', '');
								showErrors('password does not match');
							}							
						
						}
						else
						{
							showErrors('user/message check failed');
						}
					},
					onFailure: function(oHttp){


						showErrors('ajax failed');
					
					}
				}
			);		
		
		}
		else
		{
			
			processPaymentOk(pplValues);
		}

	}	
}

function sendPass()
{
	startEndProcess(true);
	var eml = $F('email').trim();
	
	if(null != eml && eml.length > 2)
	{
		var myAjax = new Ajax.Request(
				'/ForgotPassword.aspx?gbr=' + Math.random().toString().substr(3),
				{
					method: 'post',
					onSuccess: function(oHttp)
					{
						$('forgotpass').innerHTML = 'Password sent.';
						startEndProcess(false);
					},
					postBody: 'it_email='+$F('email'),
					onFailure: function(oHttp){
						startEndProcess(false);
					}					
					/*
					method: 'post',
					onSuccess: function(oHttp)
					{
						$('forgotpass').innerHTML = 'Password sent.';
						startEndProcess(false);
					},
					postBody: 'it_email='+$F('email'),
					onFailure: function(oHttp){
						startEndProcess(false);
					}
					*/
				}
			);
	}
}
function processContinue()
{
	var objAgree = $('agree');
	if(null!=objAgree && undefined!=objAgree)
		$('btnProcess').disabled = !(objAgree.checked);
	
	if($('btnProcess').disabled)
	{
		$('btnProcess').className = "g_buttondis";
	}
	else
	{
		$('btnProcess').className = "g_button";
	}
}

function checkCCValidity(ccType, ccNumber, ccMonth, ccYear)
{
	var retVal = true;
	var cardObj = eval(ccType)
	var errors = "";
	cardObj.setCardNumber(ccNumber);
	cardObj.setExpiryDate(ccYear, ccMonth);
	if(!cardObj.isCardNumber())
		errors = makeError("ccNumber", "Please check the credit card number. The card number you have entered is invalid", errors);
	if(!cardObj.isExpiryDate())
	{
		makeError('ccMonthDiv', '', errors);
		errors = makeError('ccYearDiv', 'Your Card Expiry Date is wrong!', errors);
	}	
	return errors;
}

function makeError(ctrl, error, errors)
{
	$(ctrl).style.border = "solid thin red";
	return errors+"* "+error+" <br /> ";
}
function checkCreatePayValues()
{
	var retVal = true;
	var pplValues = new Object();
	pplValues.FIRSTNAME = $F('firstName');
	if ($$('input:checked[type="radio"][name="rprplan"]') !== null)
	pplValues.RPRPLAN = $$('input:checked[type="radio"][name="rprplan"]').pluck('value');
	
	var errors="";
	if(0==pplValues.FIRSTNAME.trim().length)
	{
		retVal=false;
		errors = makeError('firstName', 'Please fill in your First Name', errors);
	}
	pplValues.LASTNAME = $F('lastName');
	if(0==pplValues.LASTNAME.trim().length)
	{
		retVal=false;
		errors = makeError('lastName', 'Please fill in your Last Name', errors);
	}
	var ccTypes = document.getElementsByName("cctype");
	pplValues.CREDITCARDTYPE = "";
	for(var i=0;i<ccTypes.length;++i)
	{
		if(ccTypes[i].checked)
			pplValues.CREDITCARDTYPE = ccTypes[i].id;
	}		
	if (pplValues.CREDITCARDTYPE == "")
	{
		//Try to detect card type according to the number
		pplValues.CREDITCARDTYPE = DetectCardType();
	}
	if("" == pplValues.CREDITCARDTYPE || 'Paypal' == pplValues.CREDITCARDTYPE)
	{
		retVal=false;
		errors = makeError('cardTypes', 'Please select a Credit Card Type', errors);
	}
	
	pplValues.ACCT = $F('ccNumber');
	if(0==pplValues.ACCT.trim().length)
	{
		retVal=false;
		errors = makeError('ccNumber', 'Please enter the Credit Card Number', errors);
	}
	pplValues.CVV2=$F('cardSC');
	if(0==pplValues.CVV2.trim().length)
	{
		retVal=false;
		errors = makeError('cardSC', 'Please enter the Credit Card Security Code', errors);
	}
	else
	{
		var cvv = pplValues.CVV2.trim();
		if(isNaN(cvv) || cvv.length<3 || cvv.length>4)
		{
			retVal=false;
			errors = makeError('cardSC', 'Please enter the 3 or 4 digit security code on the signature strip of your credit card', errors);
		}
	}
	var ccMOnth = $F('ccMonth');
	if("0"==ccMOnth)
	{
		retVal=false;
		errors = makeError('ccMonthDiv', 'Please enter the Credit Card Expiration Month', errors);
	}
	var ccYear = $F('ccYear');
	if("0"==ccYear)
	{
		retVal=false;
		errors = makeError('ccYearDiv', 'Please enter the Credit Card Expiration Year', errors);
	}
	
	if(retVal)
	{
		var cardErrors = checkCCValidity(pplValues.CREDITCARDTYPE, pplValues.ACCT, ccMOnth, ccYear);
		if(0<cardErrors.length)
		{
			retVal = false;
			errors+=cardErrors;
		}
	}

	if($F('isAddressShown')!='0')
	{
		if ($('address1')!== null)
		pplValues.STREET = $F('address1');
		if(0==pplValues.STREET.trim().length)
		{
			retVal=false;
			errors = makeError('address1', 'Please fill in the Billing Address', errors);
		}
		pplValues.CITY = $F('city');
		if(0==pplValues.CITY.trim().length)
		{
			retVal=false;
			errors = makeError('city', 'Please fill in the Billing City', errors);
		}
		
		pplValues.COUNTRYCODE = $F("country");
		if("0"==pplValues.COUNTRYCODE)
		{
			retVal=false;
			errors = makeError('countryDiv', 'Please fill in the Billing Country', errors);
		}
			
		if("US"==pplValues.COUNTRYCODE)
		{	
			pplValues.STATE = $F('state_us');		
			if("0"==pplValues.STATE)
			{
				retVal=false;
				errors = makeError('stateDiv', 'Please fill in the Billing State', errors);
			}
		}
		else
			pplValues.STATE = $F('state_input');	
		
		pplValues.ZIP = $F('postalCode');
		if(0==pplValues.ZIP.trim().length)
		{
			retVal=false;
			errors = makeError('postalCode', 'Please fill in the Billing Postal Code', errors);
		}
	
	}	
	
	pplValues.EMAIL=$F('email').trim();
	if(0==pplValues.EMAIL.length)
	{
		retVal=false;
		errors = makeError('email', 'Please enter your Email Address so we can send you the billing information', errors);
	}
	else if (!(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test(pplValues.EMAIL)))
	{
		retVal=false;
		errors = makeError('email', 'Your Billing Email Syntax is incorrect', errors);
	}
	
	if ($('otherShip') !== null)
	if($('otherShip').checked)
	{
		pplValues.SHIPTONAME = pplValues.FIRSTNAME + ' ' + pplValues.LASTNAME;
		pplValues.SHIPTOSTREET = $F('ship_address1');
		if(0==pplValues.SHIPTOSTREET.trim().length)
		{
			retVal=false;
			errors = makeError('ship_address1', 'Please fill in the Shipping Address', errors);
		}
		pplValues.SHIPTOSTREET2 = $F('ship_address2');
		pplValues.SHIPTOCITY = $F('ship_city');
		if(0==pplValues.SHIPTOCITY.trim().length)
		{
			retVal=false;
			errors = makeError('ship_city', 'Please fill in the Shipping City', errors);
		}
		
		pplValues.SHIPTOCOUNTRYCODE = $F("ship_country");
		if("0"==pplValues.SHIPTOCOUNTRYCODE)
		{
			retVal=false;
			errors = makeError('ship_countryDiv', 'Please fill in the Shipping Country', errors);
		}
		
		if("US"==pplValues.SHIPTOCOUNTRYCODE)
		{	
			pplValues.SHIPTOSTATE = $F('ship_state_us');		
			if("0"==pplValues.SHIPTOSTATE)
			{
				retVal=false;
				errors = makeError('ship_stateDiv', 'Please fill in the Shipping State', errors);
			}
		}
		else
			pplValues.SHIPTOSTATE = $F('ship_state_input');
		
		pplValues.SHIPTOZIP = $F('ship_postalCode');
		if(0==pplValues.SHIPTOZIP.trim().length)
		{
			retVal=false;
			errors = makeError('ship_postalCode', 'Please fill in the Shipping Postal Code', errors);
		}
	}
	if(retVal)
	{
		pplValues.EXPDATE = ccMOnth+ccYear;
		if($('address2')!=null)
		{
			pplValues.STREET2 = $F('address2');
		}
		pplValues.AMT = $('totalSale').innerHTML;
		//pplValues.PHONENUM = $F('phone');
		return pplValues;
	}
	else
	{
	    if (typeof logCustomEvent != 'undefined')
            logCustomEvent(143,'N/A','N/A','N/A');
		showErrors(errors);
		return null;		
	}
	
}

var errorCtrls = ['firstName', 'lastName', 'cardTypes', 'ccNumber', 'cardSC', 'ccMonthDiv', 'ccYearDiv', 'address1', 'city', 'stateDiv', 'countryDiv', 'postalCode', 'email', 'ship_address1', 'ship_city', 'ship_stateDiv', 'ship_countryDiv', 'ship_postalCode'];

function showPPLErrors()
{
	show('pplErrors');
	startEndProcess(false);
}

function showErrors(errors)
{
	hide('required');
	$('errors').innerHTML = errors;
	show('errors', 'errorsCap');
	startEndProcess(false);
}

function clearErrors()
{
	hide('billingErrorCap', 'errors', 'errorsCap', 'pplErrors','pplFirstError');
	show('required');
	errorCtrls.each(
		function(ctrl)
		{
			var obj = $(ctrl);
			if(obj==null) //some controls can be not rendered
				return;
				
			var objCtrl = obj.style;
			if("DIV" == obj.nodeName)
			{
				objCtrl.border = "none";
			}
			else
			{	
				objCtrl.border = 'solid 2px #808080';	
				objCtrl.borderBottom = objCtrl.borderRight = 'solid 1px #D4D0C8';	
			}	
		}
	);
}

function doStateCheck()
{
	if("US"==$F('country'))
	{
		show('state_us');
		hide('state_input')
	}
	else
	{
		hide('state_us')
		show('state_input');
	}
}

function doShipStateCheck()
{
	if("US"==$F('ship_country'))
	{
		show('ship_state_us');
		hide('ship_state_input')
	}
	else
	{
		hide('ship_state_us')
		show('ship_state_input');
	}
}

function checkSA()
{
	var f = $i('mainform');
	if(f != null)
	{
		if(f.rb_ship_same != null)
		{
			if(f.rb_ship_same[0].checked)
				hide('shipping_address_section');
			else
				show('shipping_address_section');
		}
	}
}

function DetectCardType()
{
	var cardnumber = $F('ccNumber');
	var headdigit = '';
	
	headdigit = cardnumber.substring(0, 2);
	if(headdigit == '51' 
		|| headdigit == '52'
		|| headdigit == '53'
		|| headdigit == '54'
		|| headdigit == '55')
	{
		return 'MasterCard';
	}
	
	headdigit = cardnumber.substring(0, 1);
	if(headdigit == '4' )
	{
		return 'Visa';
	}

	headdigit = cardnumber.substring(0, 2);
	if(headdigit == '34' || headdigit == '37')
	{
		return 'Amex';
	}

	headdigit = cardnumber.substring(0, 4);
	if(headdigit == '6011')
	{
		return 'Discover';
	}
	
	return "";
}

function show_why()
{
	if($('pqp_price_popup') != null)
	{
		doModal(); 
		ShowCenteredAlertDIV1('pqp_price_popup');
	}
}