//Java Script Core - AJVTEST
var FPglobal = {
   loginOp : new ajaxObject("/cgi-bin/JSMDIRECT?LOGIN",handleLogin),
   logoutOp : new ajaxObject("/cgi-bin/JSMDIRECT?LOGOUT",handleLogout),
   GetGlobalDtlsOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_VCHS",handleGetGlobalDtls),
   GetGlobalDtlsOp_ID : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_DTLS",handleGetGlobalDtls_ID),
   GetGlobalDtlsOp_Expiry : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_STS",handleGetGlobalDtls_Expiry),
   GetGlobalDtlsOp_Authorized : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_STS",handleGetGlobalDtls_Authorized),
   GetEmailOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_DTLS",handleGetEmail),
   GetMbrDtlsOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_DTLS",handleGetMbrDtls),
   GetMbrStsOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_STS",handleGetMbrSts),
   GetMbrVchsOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_VCHS",handleGetMbrVchs),
   GetMbrVchsOp_A : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_VCHS",handleGetMbrVchs_A),
   GetMbrVchsOp_U : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_VCHS",handleGetMbrVchs_U),
   GetMbrVchsOp_N : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_VCHS",handleGetMbrVchs_N),
   GenTempCardOp : new ajaxObject("/cgi-bin/JSMDIRECT?GEN_TEMP_CARD",handleGenTempCard),
   SetMbrDtlsOp_J : new ajaxObject("/cgi-bin/JSMDIRECT?SET_MBR_DTLS",handleSetMbrDtls_J),
   SetMbrDtlsOp_E : new ajaxObject("/cgi-bin/JSMDIRECT?SET_MBR_DTLS",handleSetMbrDtls_E),
   SetMbrDtlsOp_R : new ajaxObject("/cgi-bin/JSMDIRECT?SET_MBR_DTLS",handleSetMbrDtls_R),
   ChkMbrRegOp : new ajaxObject("/cgi-bin/JSMDIRECT?CHK_MBR_REG",handleChkMbrReg),
   CcPayReqOp_J : new ajaxObject("/cgi-bin/JSMDIRECT?CC_PAY_REQ",handleCcPayReq_J),
   CcPayReqOp_L : new ajaxObject("/cgi-bin/JSMDIRECT?CC_PAY_REQ",handleCcPayReq_L),
   CcPayReqOp_R : new ajaxObject("/cgi-bin/JSMDIRECT?CC_PAY_REQ",handleCcPayReq_R),
   GetMbrPrfOp : new ajaxObject("/cgi-bin/JSMDIRECT?GET_MBR_PRF",handleGetMbrPrf),
   SetMbrPrfOp : new ajaxObject("/cgi-bin/JSMDIRECT?SET_MBR_PRF",handleSetMbrPrf),
   ChkPswdOp : new ajaxObject("/cgi-bin/JSMDIRECT?LOST_PASSWORD_CHK",handleChkPswd),
   RstPswdOp : new ajaxObject("/cgi-bin/JSMDIRECT?RESET_PASSWORD",handleRstPswd),
   resultsTag : null,
   responseData : null
};

function init() { 
   FPglobal.resultsTag = document.getElementById('responseData');
}

function sendLoginRequest() {
   var requestData = {};
   var requestString = null;
   
   //Check for saving password option and set cookie
   if (document.loginform.rememberme.checked) { 
   		setCookie('username',document.getElementById('username').value,365);
		setCookie('password',document.getElementById('password').value,365);
   }
   
   FPglobal.resultsTag = document.getElementById('responseLoginData');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.USER_VALUE = document.getElementById('username').value;
   requestData.PASSWORD = document.getElementById('password').value;
   requestString = JSON.stringify(requestData);
   
   InitializeTimer_Login()

   FPglobal.loginOp.send(requestString, "POST");
   
   return;
}

function sendLogoutRequest() {
   var requestData = {};
   var requestString = null;
      
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);
   
   InitializeTimer_Logout()

   FPglobal.logoutOp.send(requestString, "POST");
   
   return;
}

function sendGetGlobalDtlsRequest() {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "A";
   requestString = JSON.stringify(requestData);
   
   InitializeTimer_GlbDetails()

   FPglobal.GetGlobalDtlsOp.send(requestString, "POST");
   
   return;
}

// Get the Member ID
function sendGetGlobalDtlsRequest_ID() {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "A";
   requestString = JSON.stringify(requestData);

   FPglobal.GetGlobalDtlsOp_ID.send(requestString, "POST");
   
   return;
}

// Check thier expiry
function CheckExpiry() {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GetGlobalDtlsOp_Expiry.send(requestString, "POST");
   
   return;
}

function CheckAuthorized(token) {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = token;
   requestString = JSON.stringify(requestData);

   FPglobal.GetGlobalDtlsOp_Authorized.send(requestString, "POST");
   
   return;
}

function GetEmail() {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GetEmailOp.send(requestString, "POST");
   
   return;
}

function sendGetMbrDtlsRequest() {
   var requestData = {};
   var requestString = null;
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrDtlsOp.send(requestString, "POST");
   
   return;
}

function sendGetMbrStsRequest() {
   var requestData = {};
   var requestString = null;
   
   //FPglobal.resultsTag = document.getElementById('responseGetMbrStsData');
   //FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrStsOp.send(requestString, "POST");
   
   return;
}

function sendGetMbrVchsRequest() {
   var requestData = {};
   var requestString = null;
   
   //FPglobal.resultsTag = document.getElementById('display_table');
   //FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "A";
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrVchsOp.send(requestString, "POST");
   
   return;
}

function sendGetMbrVchsRequest_A() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('display_table');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "A";
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrVchsOp_A.send(requestString, "POST");
   
   return;
}

function sendGetMbrVchsRequest_U() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('display_table');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "U";
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrVchsOp_U.send(requestString, "POST");
   
   return;
}

function sendGetMbrVchsRequest_N() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('display_table');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "N";
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrVchsOp_N.send(requestString, "POST");
   
   return;
}

function checkSetMbrDtls_J() {
	responsebox = document.getElementById('responseSetMbrDtls');
    responsebox.innerHTML = '';
	if (document.getElementById('passwd').value == document.getElementById('rpassword').value) {
		sendSetMbrDtlsRequest_J();
	} else {
		document.getElementById('rpassword').focus();
		responsebox.innerHTML = 'Passwords do not match. Please re-type the password.';
		toggleLoader('loadergif','off');
	}
}

function checkSetMbrDtls_E() {
	responsebox = document.getElementById('responseSetMbrDtls');
    responsebox.innerHTML = '';
	if (document.getElementById('passwd').value == document.getElementById('rpassword').value) {
		sendSetMbrDtlsRequest_E();
	} else {
		document.getElementById('rpassword').focus();
		responsebox.innerHTML = 'Passwords do not match. Please re-type the password.';
		toggleLoader('loadergif','off');
	}
}

function checkSetMbrDtls_R() {
	responsebox = document.getElementById('responseSetMbrDtls');
    responsebox.innerHTML = '';
	
	if (document.getElementById('user_value').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Username!");
		document.getElementById('user_value').focus();
		return;
    }
	if (document.getElementById('passwd').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Password!");
		document.getElementById('passwd').focus();
		return;
    }
	if (document.getElementById('rpassword').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please repeat the Password!");
		document.getElementById('rpassword').focus();
		return;
    }
	if (document.getElementById('passwd').value != document.getElementById('rpassword').value) {
		toggleLoader('loadergif','off');
		alert("Passwords do not match. Please re-type the password.");
		document.getElementById('passwd').focus();
		return;
	}
	if (document.getElementById('email').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter an Email!");
		document.getElementById('email').focus();
		return;
    }
	sendSetMbrDtlsRequest_R();
}

function sendSetMbrDtlsRequest_J() {
   var requestData = {};
   var requestString = null;
   var dob_day = null;
   var dob_month = null;
   var dob_year = null;
   var dob_full = null;
   
   FPglobal.resultsTag = document.getElementById('responseSetMbrDtls');
   FPglobal.resultsTag.innerHTML = '';
   
   // Form checking
   if (document.getElementById('firstname').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Firstname!");
		document.getElementById('firstname').focus();
		return;
   }
   if (document.getElementById('surname').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Surname!");
		document.getElementById('surname').focus();
		return;
   }
   if ((document.getElementById('dob_day').value == "") && (document.getElementById('dob_month').value == "") && (document.getElementById('dob_year').value == "")) {
	   // Ignore
   } else {
	   if ((document.getElementById('dob_day').value == "") || (document.getElementById('dob_month').value == "") || (document.getElementById('dob_year').value == "")) {
			toggleLoader('loadergif','off');
			alert("To enter your Date of Birth you must complete all fields (DD MM YYYY).");
			document.getElementById('dob_month').focus();
			return;
	   }
   }
   if (document.getElementById('email').value != "") {
	   if (echeck(document.getElementById('email').value)==false){
			document.getElementById('email').value = "";
			alert("Please enter a valid email address!");
			document.getElementById('email').focus()
			return false
       }
   }
   if (document.getElementById('street_address').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Street Address!");
		document.getElementById('street_address').focus();
		return;
   }
   if (document.getElementById('suburb').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Suburb!");
		document.getElementById('suburb').focus();
		return;
   }
   if (document.getElementById('state').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a State!");
		document.getElementById('state').focus();
		return;
   }
   if (document.getElementById('postcode').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Postcode!");
		document.getElementById('postcode').focus();
		return;
   }
   if (isNaN(document.getElementById('postcode').value)) {
	    toggleLoader('loadergif','off');
   		alert("Postcodes must be numbers only");
		document.getElementById('postcode').value = "";
		document.getElementById('postcode').focus();
		return;
   }
   if ((document.getElementById('email').value == "") && (document.myform.have_email.checked == false)) {
	   	toggleLoader('loadergif','off');
   		alert("Please enter an Email or tick the box indicating you do not have an Email.");
		document.getElementById('email').focus();
		return;
   }
   if ((document.getElementById('email').value == "") && (document.getElementById('user_value').value != "")) {
	   	toggleLoader('loadergif','off');
   		alert("You must enter an Email to register for online access! Either enter an Email or remove the Username you have entered.");
		document.getElementById('email').focus();
		return;
   }
   if ((document.getElementById('user_value').value != "") && (document.getElementById('passwd').value == "")) {
	   	toggleLoader('loadergif','off');
   		alert("You must enter a password!");
		document.getElementById('passwd').focus();
		return;
   }
   
   requestData.REQUEST_TYPE = "J";
   requestData.TITLE = document.getElementById('title').value;
   requestData.FIRSTNAME = document.getElementById('firstname').value;
   requestData.SURNAME = document.getElementById('surname').value;
   requestData.SEX = document.getElementById('sex').value;
   
   if (document.getElementById('dob_day').value == "") { dob_day = "00"; } else { dob_day = document.getElementById('dob_day').value; }
   if (document.getElementById('dob_month').value == "") { dob_month = "00"; } else { dob_month = document.getElementById('dob_month').value; }
   if (document.getElementById('dob_year').value == "") { dob_year = "0000"; } else { dob_year = document.getElementById('dob_year').value; }
   dob_full = dob_year + dob_month + dob_day;
   requestData.DATE_OF_BIRTH = dob_full;
   
   //requestData.EMAIL = document.getElementById('email').value;
   if (document.myform.have_email.checked) { requestData.EMAIL = ""; } else { requestData.EMAIL = document.getElementById('email').value; }
   requestData.MOBILE_PHONE = document.getElementById('mobile_phone').value;
   requestData.HOME_PHONE_NUMBER = document.getElementById('home_phone').value;
   requestData.STREET_ADDRESS = document.getElementById('street_address').value;
   requestData.SUBURB = document.getElementById('suburb').value;
   requestData.STATE = document.getElementById('state').value;
   requestData.POSTCODE = document.getElementById('postcode').value;
   
   requestData.PASSWORD = document.getElementById('passwd').value;
   if (document.myform.have_email.checked) { requestData.USER_VALUE = ""; } else { requestData.USER_VALUE = document.getElementById('user_value').value; }
   
   if (document.myform.unsubscribe_newsletter.checked) { requestData.UNSUBSCRIBE_NEWSLETTER = "Y"; } else { requestData.UNSUBSCRIBE_NEWSLETTER = "N"; }
   if (document.myform.unsubscribe_promo.checked) { requestData.UNSUBSCRIBE_PROMO_EMAIL = "Y"; } else { requestData.UNSUBSCRIBE_PROMO_EMAIL = "N"; }
   
   requestString = JSON.stringify(requestData);
   
   FPglobal.SetMbrDtlsOp_J.send(requestString, "POST");
   
   return;
}

function sendSetMbrDtlsRequest_R() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseSetMbrDtls');
   FPglobal.resultsTag.innerHTML = '';
   
   // Form checking
   if (document.getElementById('user_value').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Username!");
		document.getElementById('user_value').focus();
		return;
   }
   if (document.getElementById('passwd').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Password!");
		document.getElementById('passwd').focus();
		return;
   }
   
   requestData.REQUEST_TYPE = "R";
   requestData.SESSION_TOKEN = document.getElementById('sessionToken2').value;
   requestData.PASSWORD = document.getElementById('passwd').value;
   requestData.EMAIL = document.getElementById('email').value;
   requestData.USER_VALUE = document.getElementById('user_value').value;
   
   requestString = JSON.stringify(requestData);
   
   FPglobal.SetMbrDtlsOp_R.send(requestString, "POST");
   
   return;
}

function sendSetMbrDtlsRequest_E() {
	
   var requestData = {};
   var requestString = null;
   var dob_day = null;
   var dob_month = null;
   var dob_year = null;
   var dob_full = null;
   
   FPglobal.resultsTag = document.getElementById('responseSetMbrDtls');
   FPglobal.resultsTag.innerHTML = '';
   
   // Form checking
   if (document.getElementById('firstname').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Firstname!");
		document.getElementById('firstname').focus();
		return;
   }
   if (document.getElementById('surname').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Surname!");
		document.getElementById('surname').focus();
		return;
   }
   if ((document.getElementById('dob_day').value == "") && (document.getElementById('dob_month').value == "") && (document.getElementById('dob_year').value == "")) {
	   // Ignore
   } else {
	   if ((document.getElementById('dob_day').value == "") || (document.getElementById('dob_month').value == "") || (document.getElementById('dob_year').value == "")) {
			toggleLoader('loadergif','off');
			alert("To enter your Date of Birth you must complete all fields (DD MM YYYY).");
			document.getElementById('dob_month').focus();
			return;
	   }
   }
   if (document.getElementById('street_address').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Street Address!");
		document.getElementById('street_address').focus();
		return;
   }
   if (document.getElementById('suburb').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Suburb!");
		document.getElementById('suburb').focus();
		return;
   }
   if (document.getElementById('state').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a State!");
		document.getElementById('state').focus();
		return;
   }
   if (document.getElementById('postcode').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Postcode!");
		document.getElementById('postcode').focus();
		return;
   }
      
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "E";
   requestData.TITLE = document.getElementById('title').value;
   requestData.FIRSTNAME = document.getElementById('firstname').value;
   requestData.SURNAME = document.getElementById('surname').value;
   requestData.SEX = document.getElementById('sex').value;
   
   if (document.getElementById('dob_day').value == "") { dob_day = "00"; } else { dob_day = document.getElementById('dob_day').value; }
   if (document.getElementById('dob_month').value == "") { dob_month = "00"; } else { dob_month = document.getElementById('dob_month').value; }
   if (document.getElementById('dob_year').value == "") { dob_year = "0000"; } else { dob_year = document.getElementById('dob_year').value; }
   
   dob_full = dob_year + dob_month + dob_day;
   requestData.DATE_OF_BIRTH = dob_full;
   
   requestData.EMAIL = document.getElementById('email').value;
   requestData.MOBILE_PHONE = document.getElementById('mobile_phone').value;
   requestData.HOME_PHONE_NUMBER = document.getElementById('home_phone').value;
   requestData.STREET_ADDRESS = document.getElementById('street_address').value;
   requestData.SUBURB = document.getElementById('suburb').value;
   requestData.STATE = document.getElementById('state').value;
   requestData.POSTCODE = document.getElementById('postcode').value;
   
   if (document.myform.unsubscribe_newsletter.checked) { requestData.UNSUBSCRIBE_NEWSLETTER = "Y"; } else { requestData.UNSUBSCRIBE_NEWSLETTER = "N"; }
   if (document.myform.unsubscribe_promo.checked) { requestData.UNSUBSCRIBE_PROMO_EMAIL = "Y"; } else { requestData.UNSUBSCRIBE_PROMO_EMAIL = "N"; }
   
   if (document.getElementById('current_password').value != "") { requestData.CURRENT_PASSWORD = document.getElementById('current_password').value; requestData.PASSWORD = document.getElementById('passwd').value; }
   
   requestString = JSON.stringify(requestData);
   
   FPglobal.SetMbrDtlsOp_E.send(requestString, "POST");
   
   return;
}

function sendCcPayReqRequest_J() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('requestCcPayReqData2');
   FPglobal.resultsTag.innerHTML = '';
   
   if (isNaN(document.getElementById('card_number').value)) {
		toggleLoader('loadergif','off');
   		alert("Card numbers must be numbers only!");
		document.getElementById('card_number').focus();
		return;
   }
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken2').value;
   requestData.REQUEST_TYPE = "J";
   requestData.CARD_NAME = document.getElementById('card_name').value;
   requestData.CARD_NUMBER = document.getElementById('card_number').value;
   requestData.CARD_CCV = document.getElementById('card_ccv').value;
   //////////////////
   card_month = document.getElementById('card_month').value;
   card_year = document.getElementById('card_year').value;
   requestData.CARD_EXPIRY = card_month + card_year;
   //////////////////
   requestString = JSON.stringify(requestData);
   
   FPglobal.CcPayReqOp_J.send(requestString, "POST");
   
   return;
}

function sendCcPayReqRequest_L() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseGenTempCardData');
   
   if (document.getElementById('card_name').value == "") {
		toggleLoader('loadergif','off');
   		alert("You must enter a credit card name to continue!");
		document.getElementById('card_name').focus();
		return;
   }
   if (document.getElementById('card_number').value == "") {
		toggleLoader('loadergif','off');
   		alert("You must enter a credit card number to continue!");
		document.getElementById('card_number').focus();
		return;
   }
   if (isNaN(document.getElementById('card_number').value)) {
		toggleLoader('loadergif','off');
   		alert("Card numbers must be numbers only!");
		document.getElementById('card_number').focus();
		return;
   }
   if (document.getElementById('card_ccv').value == "") {
		toggleLoader('loadergif','off');
   		alert("You must enter a credit card ccv to continue!");
		document.getElementById('card_ccv').focus();
		return;
   }
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "L";
   requestData.CARD_NAME = document.getElementById('card_name').value;
   requestData.CARD_NUMBER = document.getElementById('card_number').value;
   requestData.CARD_CCV = document.getElementById('card_ccv').value;
   //////////////////
   card_month = document.getElementById('card_month').value;
   card_year = document.getElementById('card_year').value;
   requestData.CARD_EXPIRY = card_month + card_year;
   //////////////////
   requestString = JSON.stringify(requestData);
   
   FPglobal.CcPayReqOp_L.send(requestString, "POST");
   
   return;
}

function sendCcPayReqRequest_R() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('requestCcPayReqData');
   
   if (isNaN(document.getElementById('card_number').value)) {
		toggleLoader('loadergif','off');
   		alert("Card numbers must be numbers only!");
		document.getElementById('card_number').focus();
		return;
   }
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestData.REQUEST_TYPE = "R";
   requestData.CARD_NAME = document.getElementById('card_name').value;
   requestData.CARD_NUMBER = document.getElementById('card_number').value;
   requestData.CARD_CCV = document.getElementById('card_ccv').value;
   //////////////////
   card_month = document.getElementById('card_month').value;
   card_year = document.getElementById('card_year').value;
   requestData.CARD_EXPIRY = card_month + card_year;
   //////////////////
   requestString = JSON.stringify(requestData);
   
   FPglobal.CcPayReqOp_R.send(requestString, "POST");
   
   return;
}

function sendGenTempCardRequest() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseGenTempCardData');
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GenTempCardOp.send(requestString, "POST");
   
   return;
}

function sendChkMbrRegRequest() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseChkMbrRegData');
   FPglobal.resultsTag.innerHTML = '';
   
   if (document.getElementById('member_id').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Member ID!");
		document.getElementById('member_id').focus();
		return;
   }
   if (isNaN(document.getElementById('member_id').value)) {
	    toggleLoader('loadergif','off');
   		alert("Member IDs must be numbers only");
		document.getElementById('member_id').value = "";
		document.getElementById('member_id').focus();
		return;
   }
   if (document.getElementById('surname').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Surname!");
		document.getElementById('surname').focus();
		return;
   }
   
   requestData.MEMBER_NUMBER = document.getElementById('member_id').value;
   requestData.SURNAME = document.getElementById('surname').value;
   requestString = JSON.stringify(requestData);
   
   FPglobal.ChkMbrRegOp.send(requestString, "POST");
   
   return;
}

function sendGetMbrPrfRequest() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseGetMbrPrfData');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   requestString = JSON.stringify(requestData);

   FPglobal.GetMbrPrfOp.send(requestString, "POST");
   
   return;
}

function sendSetMbrPrfRequest() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseSetMbrPrfData');
   FPglobal.resultsTag.innerHTML = '';
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken').value;
   if (document.getElementById('size_balcony').checked == true) { requestData.SIZE_BALACONY = "Y"; } else { requestData.SIZE_BALACONY = "N"; }
   if (document.getElementById('size_courtyard').checked == true) { requestData.SIZE_COURTYARD = "Y"; } else { requestData.SIZE_COURTYARD = "N"; }
   if (document.getElementById('size_borders').checked == true) { requestData.SIZE_BORDERS = "Y"; } else { requestData.SIZE_BORDERS = "N"; }
   if (document.getElementById('size_small').checked == true) { requestData.SIZE_SMALL = "Y"; } else { requestData.SIZE_SMALL = "N"; }
   if (document.getElementById('size_medium').checked == true) { requestData.SIZE_MEDIUM = "Y"; } else { requestData.SIZE_MEDIUM = "N"; }
   if (document.getElementById('size_large').checked == true) { requestData.SIZE_LARGE = "Y"; } else { requestData.SIZE_LARGE = "N"; }
   if (document.getElementById('size_other').checked == true) { requestData.SIZE_OTHER = "Y"; } else { requestData.SIZE_OTHER = "N"; }
   if (document.getElementById('feature_lawn').checked == true) { requestData.FEATURE_LAWN = "Y"; } else { requestData.FEATURE_LAWN = "N"; }
   if (document.getElementById('feature_deck').checked == true) { requestData.FEATURE_DECK = "Y"; } else { requestData.FEATURE_DECK = "N"; }
   if (document.getElementById('feature_wtr_sys').checked == true) { requestData.FEATURE_WTR_SYS = "Y"; } else { requestData.FEATURE_WTR_SYS = "N"; }
   if (document.getElementById('feature_veg').checked == true) { requestData.FEATURE_VEG = "Y"; } else { requestData.FEATURE_VEG = "N"; }
   if (document.getElementById('feature_water').checked == true) { requestData.FEATURE_WATER = "Y"; } else { requestData.FEATURE_WATER = "N"; }
   if (document.getElementById('feature_pets').checked == true) { requestData.FEATURE_PETS = "Y"; } else { requestData.FEATURE_PETS = "N"; }
   if (document.getElementById('feature_yng_kids').checked == true) { requestData.FEATURE_YNG_KIDS = "Y"; } else { requestData.FEATURE_YNG_KIDS = "N"; }
   if (document.getElementById('feature_old_kids').checked == true) { requestData.FEATURE_OLD_KIDS = "Y"; } else { requestData.FEATURE_OLD_KIDS = "N"; }
   requestData.AVG_TIME_SUMMER = document.getElementById('avg_time_summer').value;
   requestData.AVG_TIME_AUTUMN = document.getElementById('avg_time_autumn').value;
   requestData.AVG_TIME_WINTER = document.getElementById('avg_time_winter').value;
   requestData.AVG_TIME_SPRING = document.getElementById('avg_time_spring').value;
   if (document.getElementById('use_gardener').checked == true) { requestData.USE_GARDENER = "Y"; } else { requestData.USE_GARDENER = "N"; }
   if (document.getElementById('gardener_lawn').checked == true) { requestData.GARDENER_LAWN = "Y"; } else { requestData.GARDENER_LAWN = "N"; }
   if (document.getElementById('gardener_weeds').checked == true) { requestData.GARDENER_WEEDS = "Y"; } else { requestData.GARDENER_WEEDS = "N"; }
   if (document.getElementById('gardener_landscaping').checked == true) { requestData.GARDEN_LANDSCAPING = "Y"; } else { requestData.GARDEN_LANDSCAPING = "N"; }
   requestData.RADIO_1 = document.getElementById('radio_1').value;
   requestData.RADIO_2 = document.getElementById('radio_2').value;
   requestData.RADIO_3 = document.getElementById('radio_3').value;
   requestData.RADIO_4 = document.getElementById('radio_4').value;
   requestData.NEWSPAPER_1 = document.getElementById('newspaper_1').value;
   requestData.NEWSPAPER_2 = document.getElementById('newspaper_2').value;
   requestData.NEWSPAPER_3 = document.getElementById('newspaper_3').value;
   requestData.NEWSPAPER_4 = document.getElementById('newspaper_4').value;
   requestData.MAGAZINE_1 = document.getElementById('magazine_1').value;
   requestData.MAGAZINE_2 = document.getElementById('magazine_2').value;
   requestData.MAGAZINE_3 = document.getElementById('magazine_3').value;
   requestData.MAGAZINE_4 = document.getElementById('magazine_4').value;
   if (document.getElementById('purchase_via_gl').checked == true) { requestData.PURCHASE_VIA_GL = "Y"; } else { requestData.PURCHASE_VIA_GL = "N"; }
   requestData.PURCHASE_FREQUENCY = document.getElementById('purchase_frequency').value;
   requestData.WHERE_ELSE_SHOP = document.getElementById('where_else_shop').value;
   requestData.PRODUCT_SUGGESTIONS = document.getElementById('other_product_suggestions').value;
   
   requestString = JSON.stringify(requestData);
   
   FPglobal.SetMbrPrfOp.send(requestString, "POST");
   return;
}

function sendForgotPassword() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseForgotPassword');
   FPglobal.resultsTag.innerHTML = '';
   
      if (document.getElementById('member_id').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a Member ID!");
		document.getElementById('member_id').focus();
		return;
   }
   if (isNaN(document.getElementById('member_id').value)) {
	    toggleLoader('loadergif','off');
   		alert("Member IDs must be numbers only");
		document.getElementById('member_id').value = "";
		document.getElementById('member_id').focus();
		return;
   }
   if (document.getElementById('email').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter your Email!");
		document.getElementById('email').focus();
		return;
   }
   
   requestData.MEMBER_NUMBER = document.getElementById('member_id').value;
   requestData.EMAIL = document.getElementById('email').value;
   requestString = JSON.stringify(requestData);
   
   FPglobal.ChkPswdOp.send(requestString, "POST");
   
   return;
}

function sendResetPassword() {
   var requestData = {};
   var requestString = null;
   
   FPglobal.resultsTag = document.getElementById('responseResetPassword');
   FPglobal.resultsTag.innerHTML = '';
   
   if (document.getElementById('passwd').value == "") {
	   	toggleLoader('loadergif','off');
   		alert("Please enter a new Password!");
		document.getElementById('passwd').focus();
		return;
   }
   if (document.getElementById('passwd').value != document.getElementById('rpassword').value) {
		toggleLoader('loadergif','off');
		alert("Passwords do not match. Please re-type the password.");
		document.getElementById('rpassword').focus();
		return;
   }
   
   requestData.SESSION_TOKEN = document.getElementById('sessionToken2').value;
   requestData.PASSWORD = document.getElementById('passwd').value;
   requestString = JSON.stringify(requestData);
   
   FPglobal.RstPswdOp.send(requestString, "POST");
   
   return;
}

function handleReponse(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
         FPglobal.resultsTag.innerHTML = 'Success - <br/><pre>' + responseText + '</pre>';
		 FPglobal.responseData = null;
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

// Login timer
var loginattempt = 1
var logoutattempt = 1
var glbdetailsattempt = 1
var secs
var timerID_Login = null
var timerID_Logout = null
var timerID_GlbDetails = null
var timerRunning = false
var delay = 1000

function InitializeTimer_Login()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    Timer_Login()
}

function InitializeTimer_Logout()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    Timer_Logout()
}

function InitializeTimer_GlbDetails()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    Timer_GlbDetails()
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID_Login)
		clearTimeout(timerID_Logout)
		clearTimeout(timerID_GlbDetails)
    timerRunning = false
}

function Timer_Login()
{
    if (secs==0)
    {
        StopTheClock()
		
        //alert("Attempt #" + loginattempt + "\n\nDue to a large amount of traffic we are experiencing difficulties.")
		loginattempt = loginattempt + 1
		if (loginattempt < 4) {
			sendLoginRequest()
		} else {
			StopTheClock()
			window.location.href = "index.php?pg=timeout";
		}
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID_Login = self.setTimeout("Timer_Login()", delay)
    }
}

function Timer_Logout()
{
    if (secs==0)
    {
        StopTheClock()
		
        //alert("Attempt #" + loginattempt + "\n\nDue to a large amount of traffic we are experiencing difficulties.")
		logoutattempt = logoutattempt + 1
		if (logoutattempt < 3) {
			sendLogoutRequest()
		} else {
			StopTheClock()
			window.location.href = "logout.php";
		}
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID_Logout = self.setTimeout("Timer_Logout()", delay)
    }
}

function Timer_GlbDetails()
{
    if (secs==0)
    {
        StopTheClock()
		
        //alert("Attempt #" + loginattempt + "\n\nDue to a large amount of traffic we are experiencing difficulties.")
		glbdetailsattempt = glbdetailsattempt + 1
		if (glbdetailsattempt < 4) {
			sendGetGlobalDtlsRequest()
		} else {
			StopTheClock()
			window.location.href = "index.php?pg=timeout";
		}
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID_GlbDetails = self.setTimeout("Timer_GlbDetails()", delay)
    }
}

function handleLogin(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			token = FPglobal.responseData.SESSION_TOKEN;
			
			spansessionToken = document.getElementById('sessionToken');
			spansessionToken.value = token;
			
			StopTheClock()
			
			RemoveMemberCookies();
			CheckAuthorized(token);
			
		} else {
			
			StopTheClock()
			
			// Set as default response
			FPglobal.resultsTag.innerHTML = '<br>Incorrect username or password.'+FPglobal.responseData.MESSAGES[0].MESSAGE;
			toggleLoader('loginloader','off');
			
			if (FPglobal.responseData.MESSAGES[0].MESSAGE == "DISABLED") {
				FPglobal.resultsTag.innerHTML = '<br>This account has been disabled, usually because of too many login attempts. Please contact us for assistance.';
				toggleLoader('loginloader','off');
			}
			if (FPglobal.responseData.MESSAGES[0].MESSAGE == "INVALID") {
				FPglobal.resultsTag.innerHTML = '<br>Incorrect username or password.';
				toggleLoader('loginloader','off');
			}
		}
		
		FPglobal.responseData = null;
		FPglobal.loginOp.abort();
		
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
		 toggleLoader('loginloader','off');
		 FPglobal.loginOp.abort();
      }
   } else {
      FPglobal.resultsTag.innerHTML = responseText;
	  FPglobal.responseData = null;
	  toggleLoader('loginloader','off');
	  FPglobal.loginOp.abort();
   }
   
   return;
}

function handleLogout(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 RemoveMemberCookies();
		 StopTheClock()
		 window.location.href = "logout.php";
		 FPglobal.responseData = null;
		 FPglobal.logoutOp.abort();
      } else {
		 StopTheClock()
		 RemoveMemberCookies();
		 FPglobal.responseData = null;
         window.location.href = "logout.php";
		 FPglobal.logoutOp.abort();
      }
   } else {
	  StopTheClock()
	  RemoveMemberCookies();
	  FPglobal.responseData = null;
      window.location.href = "logout.php";
	  FPglobal.logoutOp.abort();
   }
   
   return;
}

function RemoveMemberCookies() {
	setCookie('GlbDetails','',1);
	setCookie('GlbFirstname','',1);
	setCookie('GlbBalance','',1);
	setCookie('GlbToSpend','',1);
	setCookie('GlbCurrentSpend','',1);
	setCookie('GlbStatsToSpend','',1);
	deletecookie('GlbDetails');
	deletecookie('GlbFirstname');
	deletecookie('GlbBalance');
	deletecookie('GlbToSpend');
	deletecookie('GlbCurrentSpend');
	deletecookie('GlbStatsToSpend');
}

function handleGetGlobalDtls(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 		 
		 CurrentPoints = FPglobal.responseData.POINTS_BALANCE;
		 if (CurrentPoints.charAt(0) == "." ) { CurrentPoints = "0"+CurrentPoints; } //Check current spend is a whole number
		 
		 GlbDetails_txt = "<div style='float:left;'><p class='name'><em>" + FPglobal.responseData.FIRSTNAME + "</em></p><p>You have <strong>" + CurrentPoints + "</strong> points.</p></div><div style='float:right;margin-right:20px;'><p class='name'>Member ID</p>";
		 
		 spanGlbDetails = document.getElementById('tmp_mbr_dtls');
		 spanGlbDetails.value = GlbDetails_txt;
		 
		 StopTheClock()
		 
	     setCookie('GlbDetails',GlbDetails_txt,1);
		 
		 sendGetGlobalDtlsRequest_ID();
		 
		 FPglobal.responseData = null;
		 FPglobal.GetGlobalDtlsOp.abort();
		 
      } else {
		 StopTheClock()
		 setCookie('GlbDetails','',1);
		 deletecookie('GlbDetails');
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
		 FPglobal.GetGlobalDtlsOp.abort();
      }
   } else {
	  setCookie('GlbDetails','',1);
	  deletecookie('GlbDetails');
	  
	  GlbDetails_txt = "<p class='name'>Failed to load member data.</p>";
	  spanGlbDetails = document.getElementById('responseGlbDetails');
	  spanGlbDetails.innerHTML = GlbDetails_txt;
	  
	  FPglobal.responseData = null;
	  FPglobal.GetGlobalDtlsOp.abort();
   }
   
   return;
}

function handleGetGlobalDtls_ID(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 spanGlbDetails = document.getElementById('tmp_mbr_dtls').value;
		 GlbDetails_txt = spanGlbDetails + "<p id='responseGlbmember_number'><strong>" + FPglobal.responseData.MEMBER_NUMBER + "</strong></p></div>";
		 
		 responseGlbDetails = document.getElementById('responseGlbDetails');
		 responseGlbDetails.innerHTML = GlbDetails_txt;
		 
		 setCookie('GlbDetails',GlbDetails_txt,1);
		 
		 FPglobal.responseData = null;
		 
      } else {
		 setCookie('GlbDetails','',1);
		 deletecookie('GlbDetails');
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
		 FPglobal.responseData = null;
      }
	  
	  FPglobal.responseData = null;
	  
   } else {
	   setCookie('GlbDetails','',1);
	   deletecookie('GlbDetails');
	   FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	   FPglobal.responseData = null;
   }
   
   return;
}

function handleGetGlobalDtls_Expiry(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 var currentTime = new Date();
		 var month = currentTime.getMonth() + 1;
		 var day = currentTime.getDate();
		 var year = currentTime.getFullYear();
		 
		 month = month.toString();
		 if (month.length <= 1) { month = "0"+month; }
		 day = day.toString();
		 if (day.length <= 1) { day = "0"+day; }
		 
		 var thisdate = year + month + day;
		 var expired;

		 if ( ((thisdate - FPglobal.responseData.EXPIRY) > 0) || (FPglobal.responseData.MEMBERSHIP_STATUS == "E") ) { 
			window.location.href = "index.php?pg=renew&subpg=18&expiry="+FPglobal.responseData.EXPIRY+"&firstname="+FPglobal.responseData.FIRSTNAME;
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetGlobalDtls_Authorized(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 membership_status = FPglobal.responseData.MEMBERSHIP_STATUS;
		 
		 switch (membership_status) {
			case "C":
				window.location.href = "login.php?val=" + document.getElementById('sessionToken').value;
				break;
			case "E":
				window.location.href = "login.php?val=" + document.getElementById('sessionToken').value;
				break;
			default:
				window.location.href = "index.php?pg=unauthorized";	
				break;
		}
		
		FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetEmail(responseText, responseStatus) {
   if (responseStatus == 200) {  
      if (responseText != '{}') {
        FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.EMAIL == "") {
			document.getElementById('email_table').style.display = 'block';
			document.getElementById('email_table').style.visibility = 'visible';
		}
		
		document.getElementById('email_address').value = FPglobal.responseData.EMAIL;
		
		FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrDtls(responseText, responseStatus) {

   var varDOB = null;
   
   if (responseStatus == 200) {  
      if (responseText != '{}') {
		  
         FPglobal.responseData = JSON.parse(responseText);
		 
		 setSelectedIndex(document.getElementById('title'), FPglobal.responseData.TITLE);
		 document.getElementById('firstname').value = FPglobal.responseData.FIRSTNAME;
		 document.getElementById('surname').value = FPglobal.responseData.SURNAME;
		 setSelectedIndex(document.getElementById('sex'), FPglobal.responseData.SEX);
		 
		 varDOB = FPglobal.responseData.DATE_OF_BIRTH;
		 if (varDOB != "00000000") {
			 setSelectedIndex(document.getElementById('dob_day'), varDOB.charAt(6)+varDOB.charAt(7));
			 setSelectedIndex(document.getElementById('dob_month'), varDOB.charAt(4)+varDOB.charAt(5));
			 setSelectedIndex(document.getElementById('dob_year'), varDOB.charAt(0)+varDOB.charAt(1)+varDOB.charAt(2)+varDOB.charAt(3));
		 }
		 
		 document.getElementById('email').value = FPglobal.responseData.EMAIL;
		 document.getElementById('mobile_phone').value = FPglobal.responseData.MOBILE_PHONE;
		 document.getElementById('home_phone').value = FPglobal.responseData.HOME_PHONE_NUMBER;
		 document.getElementById('street_address').value = FPglobal.responseData.STREET_ADDRESS;
		 document.getElementById('suburb').value = FPglobal.responseData.SUBURB;
		 document.getElementById('state').value = FPglobal.responseData.STATE;
		 document.getElementById('postcode').value = FPglobal.responseData.POSTCODE;
		 
		 if (FPglobal.responseData.UNSUBSCRIBE_NEWSLETTER == "Y") { document.getElementById('unsubscribe_newsletter').checked = true; }
		 if (FPglobal.responseData.UNSUBSCRIBE_PROMO_EMAIL == "Y") { document.getElementById('unsubscribe_promo').checked = true; }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleSetMbrDtls_J(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			window.location.href = "index.php?pg=join2&subpg=10&val=" + FPglobal.responseData.SESSION_TOKEN + "&member_number=" + FPglobal.responseData.MEMBER_NUMBER + "&email=" + document.getElementById('email').value + "&firstname=" + document.getElementById('firstname').value + "&user_value=" + document.getElementById('user_value').value + "&pwd=" + document.getElementById('passwd').value;
		} else { 
			if (FPglobal.responseData.MESSAGES[0].MESSAGE == "USERNAME IN USE") {
				alert('The username you selected has been taken. Please enter a different username.');
				document.getElementById('user_value').focus();
				toggleLoader('loadergif','off');
			} else {
				FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
				toggleLoader('loadergif','off');
			}
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
         FPglobal.responseData = null;
		 toggleLoader('loadergif','off');
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
	  FPglobal.responseData = null;
	  toggleLoader('loadergif','off');
   }
   
   return;
}

function handleSetMbrDtls_R(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			window.location.href = "send_register.php?pg=register3&subpg=16&firstname=" + FPglobal.responseData.FIRSTNAME + "&email=" + FPglobal.responseData.EMAIL + "&user_value=" + document.getElementById('user_value').value + "&pwd=" + document.getElementById('passwd').value;
			//window.location.href = "index.php?pg=register3&subpg=16";
		} else { 
			if (FPglobal.responseData.MESSAGES[0].MESSAGE == "USERNAME IN USE") {
				alert('The username you selected has been taken. Please enter a different username.');
				document.getElementById('user_value').focus();
				toggleLoader('loadergif','off');
			} else {
				FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
				toggleLoader('loadergif','off');
			}
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
         FPglobal.responseData = null;
		 toggleLoader('loadergif','off');
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'There was a problem registering your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
	  FPglobal.responseData = null;
	  toggleLoader('loadergif','off');
   }
   
   return;
}

function handleSetMbrDtls_E(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			window.location.href = "index.php?pg=my_details&subpg=5";
		} else { 
			FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>'+FPglobal.responseData.MESSAGES[0].MESSAGE;
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
         FPglobal.responseData = null;
		 toggleLoader('loadergif','off');
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
	  FPglobal.responseData = null;
	  toggleLoader('loadergif','off');
   }
   
   return;
}

function handleGetMbrSts(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 spanFirstname = document.getElementById('responseFirstname');
		 spanFirstname.innerHTML = FPglobal.responseData.FIRSTNAME;
		 spanCurrentSpend = document.getElementById('responseCurrentSpend');
		 CurrentSpend = FPglobal.responseData.CURRENT_SPEND;
		 if (CurrentSpend.charAt(0) == "." ) { CurrentSpend = "0"+CurrentSpend; } //Check current spend is a whole number
		 spanCurrentSpend.innerHTML = CurrentSpend;
		 spanToSpend = document.getElementById('responseToSpend');
		 spendamount = 110 - parseFloat(FPglobal.responseData.CURRENT_SPEND);
		 if (spendamount > 0) {
			spendamount_txt = '$' + spendamount;
		 } else {
		 	spendamount_txt = '$0.00';
		 }
		 spanToSpend.innerHTML = spendamount_txt;
		 
		 if (spendamount_txt = "$0.00") {
			fill_container = document.getElementById('responseStatusMsg');
			fill_container.innerHTML = ". Your membership will be automatically renewed free of charge.";
		 }
		 
		 // Set these as cookies after 1st call
		 setCookie('GlbFirstname',FPglobal.responseData.FIRSTNAME,1);
		 setCookie('GlbCurrentSpend',CurrentSpend,1);
		 setCookie('GlbStatsToSpend',spendamount_txt,1);
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleChkMbrReg(responseText, responseStatus) {
	
   if (responseStatus == 200) {
	   
      if (responseText != '{}') {
        FPglobal.responseData = JSON.parse(responseText);
		
		if (FPglobal.responseData.MESSAGES[0].MESSAGE == "OK") {
			window.location.href = "index.php?pg=register2&subpg=11&val=" + FPglobal.responseData.SESSION_TOKEN + "&email=" + FPglobal.responseData.EMAIL;
		} else {
			switch (FPglobal.responseData.MESSAGES[0].MESSAGE) {
				case "INVALID MEMBER NUMBER":
					FPglobal.resultsTag.innerHTML = 'The member number you have entered do not exist.';
					break;
				case "ALREADY REGISTERED":
					FPglobal.resultsTag.innerHTML = 'The member details you have entered are already registered.';
					break;
				case "SURNAME DOES NOT MATCH":
					FPglobal.resultsTag.innerHTML = 'The surname you have entered does not match the member number.';
					break;
				default:
					FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
			}
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
	
}

function handleCcPayReq_J(responseText, responseStatus) {

   if (responseStatus == 200) {
	   
      if (responseText != '{}') {
        FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			window.location.href = "send_join.php?pg=join3&subpg=15&firstname=" + document.getElementById('firstname').value + "&email=" + document.getElementById('email').value + "&member_number=" + FPglobal.responseData.MEMBER_NUMBER + "&user_value=" + document.getElementById('user_value').value + "&pwd=" + document.getElementById('pwd').value;
		} else {
			switch (FPglobal.responseData.MESSAGES[0].MESSAGE) {
				case "GATEWAY ERROR":
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
				case "FSP ERROR":
					switch (FPglobal.responseData.MESSAGES[2].MESSAGE) {
						case "CUST CONTACT THEIR BANK":
							switch (FPglobal.responseData.MESSAGES[1].MESSAGE) {
								case "01":
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "05":
									FPglobal.resultsTag.innerHTML = 'Failed security check, eg. CVN (Card Verification Number) on back of card was entered incorrectly. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "56":
									FPglobal.resultsTag.innerHTML = 'The card issuer has no record of this card. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								default:
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
							}
							break;
						case "RETRY TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'The transaction has not been processed and should be retried.';
							break;
						case "INSUFFICIENT FUNDS":
							FPglobal.resultsTag.innerHTML = 'The account has insufficient funds to complete the transaction. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY AMOUNT EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your account/card withdrawal limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY TRANS EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your withdrawal frequency limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD INVALID":
							FPglobal.resultsTag.innerHTML = 'The Bank that issued this card is not supported.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID CARD NUMBER" || "CARD NO INVALID"):
							FPglobal.resultsTag.innerHTML = 'An invalid card number was specified. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "EXPIRED CARD":
							FPglobal.resultsTag.innerHTML = 'This card has expired. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD EXPIRED":
							FPglobal.resultsTag.innerHTML = 'A past date was set for card expiry date. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "NO CHQ/SAV ACCOUNT":
							FPglobal.resultsTag.innerHTML = 'Savings/Cheque accounts are not applicable here. Please try a credit card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID TRANSACTION" || "TRANSACTION NOT ALLOWED"):
							FPglobal.resultsTag.innerHTML = 'The card issuer has indicated that this transaction is not permitted to the cardholder.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "TRAN NOT ALLOWED":
							FPglobal.resultsTag.innerHTML = 'The Card Issuer has indicated that there are restrictions placed on this card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("DECLINED SYSTEM ERROR" || "BANK NOT AVAILABLE"):
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DUPLICATE TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'This is a duplicate transmission. It has already been sent.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Server busy":
							FPglobal.resultsTag.innerHTML = 'The server is currently busy. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Timout":
							FPglobal.resultsTag.innerHTML = 'A timeout occurred between our server and your bank. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Initialised":
							FPglobal.resultsTag.innerHTML = 'Your transaction did not process. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "In Progress":
							FPglobal.resultsTag.innerHTML = 'Your transaction is being processed. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Card unsupported":
							FPglobal.resultsTag.innerHTML = 'The card is not supported. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("Validation failure" || "Unable to process Could not validate transaction"):
							FPglobal.resultsTag.innerHTML = 'The transaction was not processed. Please try again, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						default:
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[2].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
					}
					break;
				default:
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[0].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
			}
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleCcPayReq_L(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			sendGenTempCardRequest();
		} else {
			switch (FPglobal.responseData.MESSAGES[0].MESSAGE) {
				case "GATEWAY ERROR":
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
				case "FSP ERROR":
					switch (FPglobal.responseData.MESSAGES[2].MESSAGE) {
						case "CUST CONTACT THEIR BANK":
							switch (FPglobal.responseData.MESSAGES[1].MESSAGE) {
								case "01":
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "05":
									FPglobal.resultsTag.innerHTML = 'Failed security check, eg. CVN (Card Verification Number) on back of card was entered incorrectly. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "56":
									FPglobal.resultsTag.innerHTML = 'The card issuer has no record of this card. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								default:
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
							}
							break;
						case "RETRY TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'The transaction has not been processed and should be retried.';
							break;
						case "INSUFFICIENT FUNDS":
							FPglobal.resultsTag.innerHTML = 'The account has insufficient funds to complete the transaction. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY AMOUNT EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your account/card withdrawal limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY TRANS EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your withdrawal frequency limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD INVALID":
							FPglobal.resultsTag.innerHTML = 'The Bank that issued this card is not supported.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID CARD NUMBER" || "CARD NO INVALID"):
							FPglobal.resultsTag.innerHTML = 'An invalid card number was specified. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "EXPIRED CARD":
							FPglobal.resultsTag.innerHTML = 'This card has expired. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD EXPIRED":
							FPglobal.resultsTag.innerHTML = 'A past date was set for card expiry date. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "NO CHQ/SAV ACCOUNT":
							FPglobal.resultsTag.innerHTML = 'Savings/Cheque accounts are not applicable here. Please try a credit card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID TRANSACTION" || "TRANSACTION NOT ALLOWED"):
							FPglobal.resultsTag.innerHTML = 'The card issuer has indicated that this transaction is not permitted to the cardholder.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "TRAN NOT ALLOWED":
							FPglobal.resultsTag.innerHTML = 'The Card Issuer has indicated that there are restrictions placed on this card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("DECLINED SYSTEM ERROR" || "BANK NOT AVAILABLE"):
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DUPLICATE TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'This is a duplicate transmission. It has already been sent.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Server busy":
							FPglobal.resultsTag.innerHTML = 'The server is currently busy. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Timout":
							FPglobal.resultsTag.innerHTML = 'A timeout occurred between our server and your bank. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Initialised":
							FPglobal.resultsTag.innerHTML = 'Your transaction did not process. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "In Progress":
							FPglobal.resultsTag.innerHTML = 'Your transaction is being processed. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Card unsupported":
							FPglobal.resultsTag.innerHTML = 'The card is not supported. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("Validation failure" || "Unable to process Could not validate transaction"):
							FPglobal.resultsTag.innerHTML = 'The transaction was not processed. Please try again, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						default:
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[2].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
					}
					break;
				default:
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[0].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
			}
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleCcPayReq_R(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		
		if (FPglobal.responseData.STATUS == "OK") {
			//window.location.href = "index.php?pg=content&subpg=19";
			window.location.href = "send_renew.php?pg=content&subpg=19&firstname=" + document.getElementById('firstname').value + "&email=" + document.getElementById('email_address').value;
		} else {
			switch (FPglobal.responseData.MESSAGES[0].MESSAGE) {
				case "GATEWAY ERROR":
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
				case "FSP ERROR":
					switch (FPglobal.responseData.MESSAGES[2].MESSAGE) {
						case "CUST CONTACT THEIR BANK":
							switch (FPglobal.responseData.MESSAGES[1].MESSAGE) {
								case "01":
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "05":
									FPglobal.resultsTag.innerHTML = 'Failed security check, eg. CVN (Card Verification Number) on back of card was entered incorrectly. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								case "56":
									FPglobal.resultsTag.innerHTML = 'The card issuer has no record of this card. Check the number and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
								default:
									FPglobal.resultsTag.innerHTML = 'There is a problem with the card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
									break;
							}
							break;
						case "RETRY TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'The transaction has not been processed and should be retried.';
							break;
						case "INSUFFICIENT FUNDS":
							FPglobal.resultsTag.innerHTML = 'The account has insufficient funds to complete the transaction. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY AMOUNT EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your account/card withdrawal limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DAILY TRANS EXCEEDED":
							FPglobal.resultsTag.innerHTML = 'The transaction will exceed your withdrawal frequency limit. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD INVALID":
							FPglobal.resultsTag.innerHTML = 'The Bank that issued this card is not supported.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID CARD NUMBER" || "CARD NO INVALID"):
							FPglobal.resultsTag.innerHTML = 'An invalid card number was specified. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "EXPIRED CARD":
							FPglobal.resultsTag.innerHTML = 'This card has expired. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "CARD EXPIRED":
							FPglobal.resultsTag.innerHTML = 'A past date was set for card expiry date. Check data and try again.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "NO CHQ/SAV ACCOUNT":
							FPglobal.resultsTag.innerHTML = 'Savings/Cheque accounts are not applicable here. Please try a credit card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("INVALID TRANSACTION" || "TRANSACTION NOT ALLOWED"):
							FPglobal.resultsTag.innerHTML = 'The card issuer has indicated that this transaction is not permitted to the cardholder.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "TRAN NOT ALLOWED":
							FPglobal.resultsTag.innerHTML = 'The Card Issuer has indicated that there are restrictions placed on this card. Please contact your bank, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("DECLINED SYSTEM ERROR" || "BANK NOT AVAILABLE"):
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "DUPLICATE TRANSACTION":
							FPglobal.resultsTag.innerHTML = 'This is a duplicate transmission. It has already been sent.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Server busy":
							FPglobal.resultsTag.innerHTML = 'The server is currently busy. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Timout":
							FPglobal.resultsTag.innerHTML = 'A timeout occurred between our server and your bank. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Initialised":
							FPglobal.resultsTag.innerHTML = 'Your transaction did not process. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "In Progress":
							FPglobal.resultsTag.innerHTML = 'Your transaction is being processed. Please try again later, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case "Card unsupported":
							FPglobal.resultsTag.innerHTML = 'The card is not supported. Please try a different card, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						case ("Validation failure" || "Unable to process Could not validate transaction"):
							FPglobal.resultsTag.innerHTML = 'The transaction was not processed. Please try again, or alternatively <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
						default:
							FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[2].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
							break;
					}
					break;
				default:
					FPglobal.resultsTag.innerHTML = 'There was a problem connecting to the bank ('+FPglobal.responseData.MESSAGES[0].MESSAGE+').<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
			}
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGenTempCard(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			imgTempCard = FPglobal.responseData.CARD_LINK;
			imgTempCard = "'" + imgTempCard + "'";
			FPglobal.resultsTag.innerHTML = "";
			FPglobal.resultsTag.innerHTML = '<p class="title">TEMPORARY CARD</p><p>&nbsp;</p><p>You have successfully ordered a replacement card.</p><p>&nbsp;</p><p>Your new Garden Lover&#39;s Club card will be mailed to the address that you have registered, please allow ten working days.</p><p>&nbsp;</p><p>While you wait for a new card to arrive, please feel free to print a temporary card using the button below.</p><p>&nbsp;</p><p><input type="button" class="button" value="Generate Temp Card" onclick="OpenTempCard('+imgTempCard+')" /></p><p>&nbsp;</p><iframe src='+imgTempCard+' name="TempCard" id="TempCard" frameborder="0" height="500" width="100%" allowtransparency="true"></iframe>';
		} else { 
			FPglobal.resultsTag.innerHTML = 'There was a problem generating a temp card.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'There was a problem generating a temp card.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'There was a problem generating a temp card.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrVchs(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 var spanFirstname = "";
		 var spanBalance = "";
		 var CurrentBalance = "";
		 var spanToSpend = "";
		 		 
		 spanFirstname = document.getElementById('responseFirstname');
		 spanFirstname.innerHTML = FPglobal.responseData.FIRSTNAME;
		 spanBalance = document.getElementById('responseBalance');
		 CurrentBalance = FPglobal.responseData.POINTS_BALANCE;
		 if (CurrentBalance.charAt(0) == "." ) { CurrentBalance = "0"+CurrentBalance; } //Check current spend is a whole number
		 spanBalance.innerHTML = CurrentBalance;
		 ToSpend = '$' + (100 - parseFloat(FPglobal.responseData.POINTS_BALANCE));
		 spanToSpend = document.getElementById('responseToSpend');
		 spanToSpend.innerHTML = ToSpend;
		 
		 // Set these as cookies after 1st call
		 setCookie('GlbFirstname',FPglobal.responseData.FIRSTNAME,1);
		 setCookie('GlbBalance',CurrentBalance,1);
		 setCookie('GlbToSpend',ToSpend,1);
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrVchs_A(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.VOUCHERS == null) {
			 FPglobal.resultsTag.innerHTML = "There are <strong>no</strong> vouchers on record.";
		 } else {
			 FPglobal.resultsTag.innerHTML = "<p>Here is a list of your current vouchers:</p><p>&nbsp;</p>";
			 
			 headings = ["Voucher","Issued At","Date Issued","Redeemed At","Expiry Date","Status","Value"];
			 
			 var tableObj, tHeadObj, tBodyObj, oRow, oHcell, oCell;
			 tableObj = document.createElement('table'); tableObj.border = "1"; tableObj.className = "vouchers";
			 tHeadObj = document.createElement('thead');
			 tBodyObj = document.createElement('tbody');
			 
			 // Set Header
			 oRow = document.createElement('tr');
			 for (var i = 0; i < headings.length; i++) {
				 oHcell = document.createElement('th');
				 oHcell.innerHTML = headings[i];
				 oRow.appendChild(oHcell);
			 }
			 tHeadObj.appendChild(oRow);
			 tableObj.appendChild(tHeadObj);
			 
			 // Set Body
			 for (var i = 0; i < 10; i++) {
				 oRow = document.createElement('tr'); if ((i % 2) != 0) {oRow.style.backgroundColor = "#fdf5e5";};
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].NUMBER; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].ISSUED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].DATE_ISSUED; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].REDEEMED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].EXPIRY_DATE; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VCH_STATUS; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VALUE; oCell.style.textAlign = "right"; oRow.appendChild(oCell);
				 tBodyObj.appendChild(oRow);
			 }
			   
			 tableObj.appendChild(tBodyObj);
			   
			 //Append Table
			 FPglobal.resultsTag.appendChild(tableObj);
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrVchs_U(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.VOUCHERS == null) {
			 FPglobal.resultsTag.innerHTML = "There are <strong>no</strong> unused vouchers on record.";
		 } else {
			 FPglobal.resultsTag.innerHTML = "<p>Here is a list of your unused vouchers:</p><p>&nbsp;</p>";
			 
			 headings = ["Voucher","Issued At","Date Issued","Redeemed At","Expiry Date","Status","Value"];
			 
			 var tableObj, tHeadObj, tBodyObj, oRow, oHcell, oCell;
			 tableObj = document.createElement('table'); tableObj.border = "1"; tableObj.className = "vouchers";
			 tHeadObj = document.createElement('thead');
			 tBodyObj = document.createElement('tbody');
			 
			 // Set Header
			 oRow = document.createElement('tr');
			 for (var i = 0; i < headings.length; i++) {
				 oHcell = document.createElement('th');
				 oHcell.innerHTML = headings[i];
				 oRow.appendChild(oHcell);
			 }
			 tHeadObj.appendChild(oRow);
			 tableObj.appendChild(tHeadObj);
			 
			 // Set Body
			 for (var i = 0; i < 10; i++) {
				 oRow = document.createElement('tr'); if ((i % 2) != 0) {oRow.style.backgroundColor = "#fdf5e5";};
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].NUMBER; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].ISSUED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].DATE_ISSUED; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].REDEEMED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].EXPIRY_DATE; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VCH_STATUS; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VALUE; oCell.style.textAlign = "right"; oRow.appendChild(oCell);
				 tBodyObj.appendChild(oRow);
			 }
			   
			 tableObj.appendChild(tBodyObj);
			   
			 //Append Table
			 FPglobal.resultsTag.appendChild(tableObj);
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrVchs_N(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.VOUCHERS == null) {
			 FPglobal.resultsTag.innerHTML = "There are <strong>no</strong> expired/unused vouchers on record.";
		 } else {
			 FPglobal.resultsTag.innerHTML = "<p>Here is a list of your expired/unused vouchers:</p><p>&nbsp;</p>";
			 
			 headings = ["Voucher","Issued At","Date Issued","Redeemed At","Expiry Date","Status","Value"];
			 
			 var tableObj, tHeadObj, tBodyObj, oRow, oHcell, oCell;
			 tableObj = document.createElement('table'); tableObj.border = "1"; tableObj.className = "vouchers";
			 tHeadObj = document.createElement('thead');
			 tBodyObj = document.createElement('tbody');
			 
			 // Set Header
			 oRow = document.createElement('tr');
			 for (var i = 0; i < headings.length; i++) {
				 oHcell = document.createElement('th');
				 oHcell.innerHTML = headings[i];
				 oRow.appendChild(oHcell);
			 }
			 tHeadObj.appendChild(oRow);
			 tableObj.appendChild(tHeadObj);
			 
			 // Set Body
			 for (var i = 0; i < 10; i++) {
				 oRow = document.createElement('tr'); if ((i % 2) != 0) {oRow.style.backgroundColor = "#fdf5e5";};
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].NUMBER; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].ISSUED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].DATE_ISSUED; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].REDEEMED_AT; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].EXPIRY_DATE; oCell.style.textAlign = "center"; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VCH_STATUS; oRow.appendChild(oCell);
				 oCell = document.createElement('td'); oCell.innerHTML = FPglobal.responseData.VOUCHERS[i].VALUE; oCell.style.textAlign = "right"; oRow.appendChild(oCell);
				 tBodyObj.appendChild(oRow);
			 }
			   
			 tableObj.appendChild(tBodyObj);
			   
			 //Append Table
			 FPglobal.resultsTag.appendChild(tableObj);
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleGetMbrPrf(responseText, responseStatus) {

   var varDOB = null;
   
   if (responseStatus == 200) {  
      if (responseText != '{}') {
		  
         FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.SIZE_BALACONY == "Y") { document.getElementById('size_balcony').checked = true; }
		 if (FPglobal.responseData.SIZE_COURTYARD == "Y") { document.getElementById('size_courtyard').checked = true; }
		 if (FPglobal.responseData.SIZE_BORDERS == "Y") { document.getElementById('size_borders').checked = true; }
		 if (FPglobal.responseData.SIZE_SMALL == "Y") { document.getElementById('size_small').checked = true; }
		 if (FPglobal.responseData.SIZE_MEDIUM == "Y") { document.getElementById('size_medium').checked = true; }
		 if (FPglobal.responseData.SIZE_LARGE == "Y") { document.getElementById('size_large').checked = true; }
		 if (FPglobal.responseData.SIZE_OTHER == "Y") { document.getElementById('size_other').checked = true; }
		 
		 if (FPglobal.responseData.FEATURE_LAWN == "Y") { document.getElementById('feature_lawn').checked = true; }
		 if (FPglobal.responseData.FEATURE_DECK == "Y") { document.getElementById('feature_deck').checked = true; }
		 if (FPglobal.responseData.FEATURE_WTR_SYS == "Y") { document.getElementById('feature_wtr_sys').checked = true; }
		 if (FPglobal.responseData.FEATURE_VEG == "Y") { document.getElementById('feature_veg').checked = true; }
		 if (FPglobal.responseData.FEATURE_WATER == "Y") { document.getElementById('feature_water').checked = true; }
		 if (FPglobal.responseData.FEATURE_PETS == "Y") { document.getElementById('feature_pets').checked = true; }
		 if (FPglobal.responseData.FEATURE_YNG_KIDS == "Y") { document.getElementById('feature_yng_kids').checked = true; }
		 if (FPglobal.responseData.FEATURE_OLD_KIDS == "Y") { document.getElementById('feature_old_kids').checked = true; }
		 
		 setSelectedIndex(document.getElementById('avg_time_summer'), FPglobal.responseData.AVG_TIME_SUMMER);
		 setSelectedIndex(document.getElementById('avg_time_autumn'), FPglobal.responseData.AVG_TIME_AUTUMN);
		 setSelectedIndex(document.getElementById('avg_time_winter'), FPglobal.responseData.AVG_TIME_WINTER);
		 setSelectedIndex(document.getElementById('avg_time_spring'), FPglobal.responseData.AVG_TIME_SPRING);
		 
		 if (FPglobal.responseData.USE_GARDENER == "Y") { setCheckedValue(document.forms['myform'].elements['use_gardener'], 'Y'); }
		 if (FPglobal.responseData.USE_GARDENER == "N") { setCheckedValue(document.forms['myform'].elements['use_gardener'], 'N'); }
		 
		 if (FPglobal.responseData.GARDENER_LAWN == "Y") { document.getElementById('gardener_lawn').checked = true; }
		 if (FPglobal.responseData.GARDENER_WEEDS == "Y") { document.getElementById('gardener_weeds').checked = true; }
		 if (FPglobal.responseData.GARDEN_LANDSCAPING == "Y") { document.getElementById('gardener_landscaping').checked = true; }
		 
		 if (FPglobal.responseData.FEATURE_PETS == "Y") { document.getElementById('feature_pets').checked = true; }
		 if (FPglobal.responseData.FEATURE_YNG_KIDS == "Y") { document.getElementById('feature_yng_kids').checked = true; }
		 if (FPglobal.responseData.FEATURE_OLD_KIDS == "Y") { document.getElementById('feature_old_kids').checked = true; }
		 
		 setSelectedIndex(document.getElementById('radio_1'), FPglobal.responseData.RADIO_1);
		 setSelectedIndex(document.getElementById('radio_2'), FPglobal.responseData.RADIO_2);
		 setSelectedIndex(document.getElementById('radio_3'), FPglobal.responseData.RADIO_3);	 
		 document.getElementById('radio_4').value = FPglobal.responseData.RADIO_4;
		 
		 setSelectedIndex(document.getElementById('newspaper_1'), FPglobal.responseData.NEWSPAPER_1);
		 setSelectedIndex(document.getElementById('newspaper_2'), FPglobal.responseData.NEWSPAPER_2);
		 setSelectedIndex(document.getElementById('newspaper_3'), FPglobal.responseData.NEWSPAPER_3);	 
		 document.getElementById('newspaper_4').value = FPglobal.responseData.NEWSPAPER_4;
		 
		 setSelectedIndex(document.getElementById('magazine_1'), FPglobal.responseData.MAGAZINE_1);
		 setSelectedIndex(document.getElementById('magazine_2'), FPglobal.responseData.MAGAZINE_2);
		 setSelectedIndex(document.getElementById('magazine_3'), FPglobal.responseData.MAGAZINE_3);	 
		 document.getElementById('magazine_4').value = FPglobal.responseData.MAGAZINE_4;
		 
		 if (FPglobal.responseData.PURCHASE_VIA_GL == "Y") { setCheckedValue(document.forms['myform'].elements['purchase_via_gl'], 'Y'); }
		 if (FPglobal.responseData.PURCHASE_VIA_GL == "N") { setCheckedValue(document.forms['myform'].elements['purchase_via_gl'], 'N'); }
		 
		 setSelectedIndex(document.getElementById('purchase_frequency'), FPglobal.responseData.PURCHASE_FREQUENCY);
		 
		 document.getElementById('where_else_shop').value = FPglobal.responseData.WHERE_ELSE_SHOP;
		 document.getElementById('other_product_suggestions').value = FPglobal.responseData.PRODUCT_SUGGESTIONS;
		 
		 FPglobal.responseData = null;
			 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleSetMbrPrf(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
         FPglobal.responseData = JSON.parse(responseText);

		if (FPglobal.responseData.STATUS == "OK") {
			window.location.href = "index.php?pg=survey&subpg=14";
		} else { 
			FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
			toggleLoader('loadergif','off');
		}
		
		FPglobal.responseData = null;
		
      } else {
         FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
         FPglobal.responseData = null;
		 toggleLoader('loadergif','off');
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'There was a problem updating your details.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
	  FPglobal.responseData = null;
	  toggleLoader('loadergif','off');
   }
   
   return;
}

function handleChkPswd(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
		 FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.MESSAGES[0].MESSAGE == "OK") {
			 window.location.href = "send_password.php?token=" + FPglobal.responseData.SESSION_TOKEN + "&email=" + document.getElementById('email').value;
		 } else {
			switch (FPglobal.responseData.MESSAGES[0].MESSAGE) {
				case "MEMBER NUMBER OR EMAIL INVALID OR BLANK":
					FPglobal.resultsTag.innerHTML = 'The member number or email you have entered are invalid.';
					break;
				case "Member_NUMBER or EMAIL invalid":
					FPglobal.resultsTag.innerHTML = 'The member number or email you have entered are invalid.';
					break;
				default:
					FPglobal.resultsTag.innerHTML = 'This page is currently experiencing technical difficulties.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
					break;
			}
			toggleLoader('loadergif','off');
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

function handleRstPswd(responseText, responseStatus) {

   if (responseStatus == 200) {  
      if (responseText != '{}') {
		 FPglobal.responseData = JSON.parse(responseText);
		 
		 if (FPglobal.responseData.MESSAGES[0].MESSAGE == "OK") {
			FPglobal.resultsTag.innerHTML = "Your password has been updated.";
			toggleLoader('loadergif','off');
		 } else {
			if (FPglobal.responseData.MESSAGES[0].MESSAGE == "cannot reset password") {
				FPglobal.resultsTag.innerHTML = 'Cannot reset password.';
			} else {
				FPglobal.resultsTag.innerHTML = 'There was a problem resetting your password.<br>Please <a href="index.php?pg=contact&subpg=9">contact us</a> for assistance.';
			}
			toggleLoader('loadergif','off');
		 }
		 
		 FPglobal.responseData = null;
		 
      } else {
         FPglobal.resultsTag.innerHTML = 'No Data Returned';
         FPglobal.responseData = null;
      }
   } else {
      FPglobal.resultsTag.innerHTML = 'Recieving Error - ' + responseText;
	  FPglobal.responseData = null;
   }
   
   return;
}

// functions not part of Ajax Transaction Examples

function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function showOperation(operation) {
   // First Hide All Operations pairs expect for login and logout
   document.getElementById('getmbrdtls').style.display = 'none'; document.getElementById('getmbrdtls').style.visibility = 'hidden';
   document.getElementById('getmbrsts').style.display = 'none'; document.getElementById('getmbrsts').style.visibility = 'hidden';
   document.getElementById('getmbrprf').style.display = 'none'; document.getElementById('getmbrprf').style.visibility = 'hidden';
   document.getElementById('getmbrvchs').style.display = 'none'; document.getElementById('getmbrvchs').style.visibility = 'hidden';
   document.getElementById('gentempcard').style.display = 'none'; document.getElementById('gentempcard').style.visibility = 'hidden'; 
   document.getElementById('setmbrdtls').style.display = 'none'; document.getElementById('setmbrdtls').style.visibility = 'hidden';
   document.getElementById('chkmbrreg').style.display = 'none'; document.getElementById('chkmbrreg').style.visibility = 'hidden';
   document.getElementById('ccpayreq').style.display = 'none'; document.getElementById('ccpayreq').style.visibility = 'hidden';
   document.getElementById('setmbrprf').style.display = 'none'; document.getElementById('setmbrprf').style.visibility = 'hidden';
   
   //Now Show selected Operation
   document.getElementById(operation).style.display = 'block'; document.getElementById(operation).style.visibility = 'visible';         
}

function checkLogin() {
	if (document.getElementById('sessionToken').value == "") {
		document.getElementById('loggedin').style.display = 'none';
		document.getElementById('loggedin').style.visibility = 'hidden';
		document.getElementById('loggedout').style.display = 'block';
		document.getElementById('loggedout').style.visibility = 'visible';
	} else {
		document.getElementById('loggedin').style.display = 'block';
		document.getElementById('loggedin').style.visibility = 'visible';
		document.getElementById('loggedout').style.display = 'none';
		document.getElementById('loggedout').style.visibility = 'hidden';
	}
	checkCookie_username();
	checkCookie_password();
	checkCookie_GlbDetails();
}

function toggleLoader(id,type) {
	if (type == "on") {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

function toggleVouchers(id) {
	switch (id) {
		case "table_A":
			document.getElementById('table_A').style.display = 'block';
			document.getElementById('table_U').style.display = 'none';
			document.getElementById('table_N').style.display = 'none';
			break;
		case "table_U":
			document.getElementById('table_A').style.display = 'none';
			document.getElementById('table_U').style.display = 'block';
			document.getElementById('table_N').style.display = 'none';
			break
		case "table_N":
			document.getElementById('table_A').style.display = 'none';
			document.getElementById('table_U').style.display = 'none';
			document.getElementById('table_N').style.display = 'block';
			break
	}
}

function toggleVoucherBG(type) {
	if (type == "on") {
		scrollTo(0,0);
		document.body.style.overflow="hidden";
		document.getElementById('vouchers_bg').style.display = 'block';
	} else {
		document.body.style.overflow="auto";
		document.getElementById('vouchers_bg').style.display = 'none';
	}
	
}

function printvouchers(){
	var DocumentContainer = document.getElementById('display_table');
	var WindowObject = window.open("", "VoucherData","width=700,height=400,top=20,left=20,toolbars=no,scrollbars=no,status=no,resizable=no");
	WindowObject.document.write(DocumentContainer.innerHTML);
	WindowObject.document.close();
	WindowObject.focus();
	WindowObject.print();
	WindowObject.close();
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		toggleLoader('loginloader','on');sendLoginRequest();
		return false
	} else {
		return true
	}
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1) {
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		  return unescape(document.cookie.substring(c_start,c_end));
	  }
	}
	return "";
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function checkCookie_username() {
	username=getCookie('username');
	if (username!=null && username!="") {
	  document.getElementById('username').value = username;
	}
}

function checkCookie_password() {
	password=getCookie('password');
	if (password!=null && password!="") {
	  document.getElementById('password').value = password;
	}
}

function checkCookie_GlbDetails() {
	GlbDetails=getCookie('GlbDetails');
	if (GlbDetails!=null && GlbDetails!="") {
	  globaldetails = document.getElementById('responseGlbDetails');
	  globaldetails.innerHTML = GlbDetails;
	} else {
	  sendGetGlobalDtlsRequest();	
	}
}

// Form Validation
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	 if (str.indexOf(" ")!=-1){
		return false
	 }				
}

function checkDate(DOBDay, DOBMonth, DOBYear) {
	var x = document.forms[1].elements;
	var day = parseInt(DOBDay);
	var month = parseInt(DOBMonth);
	var year = parseInt(DOBYear);

	if (!day || !month || !year)
		return false;

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1])
		return false;

	monthLength[1] = 28;

	var now = new Date();
	now = now.getTime(); //NN3

	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();

	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);

	return true;
}

function CheckContactForm() {
	if (document.getElementById('frm_name').value == "") {
		alert("Please enter a name!");
		document.getElementById('frm_name').focus();
		return false;
	}
	if (document.getElementById('frm_email').value == "") {
		alert("Please enter an email!");
		document.getElementById('frm_email').focus();
		return false;
	}
	if (echeck(document.getElementById('frm_email').value)==false){
		document.getElementById('frm_email').value = "";
		alert("Please enter a valid email address!");
		document.getElementById('frm_email').focus()
		return false
	}
	return true;
	toggleLoader('loadergif','on');
}

function DisableUserDetails() {
	if (document.myform.have_email.checked) {
		document.getElementById('user_value').value="";
		document.getElementById('email').value="";
		document.getElementById('passwd').value="";
		document.getElementById('rpassword').value="";
		
		document.getElementById('email').disabled=true;
		document.getElementById('user_value').disabled=true;
		document.getElementById('passwd').disabled=true;
		document.getElementById('rpassword').disabled=true;
		
		document.getElementById('email').style.backgroundColor = '#dddddd';
		document.getElementById('user_value').style.backgroundColor = '#dddddd';
		document.getElementById('passwd').style.backgroundColor = '#dddddd';
		document.getElementById('rpassword').style.backgroundColor = '#dddddd';
	} else {
		document.getElementById('email').disabled=false;
		document.getElementById('user_value').disabled=false;
		document.getElementById('passwd').disabled=false;
		document.getElementById('rpassword').disabled=false;
		
		document.getElementById('email').style.backgroundColor = '#ffffff';
		document.getElementById('user_value').style.backgroundColor = '#ffffff';
		document.getElementById('passwd').style.backgroundColor = '#ffffff';
		document.getElementById('rpassword').style.backgroundColor = '#ffffff';
	}
}

function OpenTempCard(URL) {
	window.location = URL;	
}

/*******************************************************************
* JavaScript/CSS Font Size Changer (Persistent Between Pages)
* (c) DB Design, All rights are reserved
* http://phpscriptindex.com, phpsales@gmail.com
********************************************************************
* Script will allow user to visually change font size. Font size 
* will persist thru page change using a cookie.
********************************************************************
* Directions: Change fontElementId var to the element id you wish to
* allow users to change font sizes. 
********************************************************************
* Tip: Next span element inside normal div to inherit parent style
* but enable use to change font size.
*******************************************************************
* FireFox 2.0.0.3 Tested
* MS IE 7 Tested
* Netscape 8.1.2 Tested
* Opera 9.1 Tested
******************************************************************/

var fontElementId = "block"; //CHANGE ME TO YOUR ELEMENT ID

//DO NOT MODIFY BELOW

/* Module Change Font (string) */
function changeFont(fontClass){
	var element = document.getElementById(fontElementId);
	element.className = fontClass;
	setCookie("fontSize", fontClass, 5);
}		

/* Module Set Default Font Size (void) */
function setDefaultFontSize(){
	var fontSize = getCookie("fontSize")
	if(fontSize){
		var element = document.getElementById(fontElementId);
		element.className = fontSize;
	}
}

/* Module Set Cookie (string, string, int) -- http://www.w3schools.com/js/js_cookies.asp */
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
/* Module Get Cookie (string) -- http://www.w3schools.com/js/js_cookies.asp */
function getCookie(c_name){
	if(document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return false;
}

function deletecookie(name) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() - 1);
	document.cookie = name += "=; expires=" + expdate.toGMTString();
}

function removeSpaces(string) {
 return string.split(' ').join('');
}
