//function stopError() {  return true; }
var randomNumber = Math.random();

String.prototype.toCapitalCase = function() {
  var re = /\s/;	var words = this.split(re);	re = /(\S)(\S+)/;
  for (i = words.length - 1; i >= 0; i--) {re.exec(words[i]);	words[i] = RegExp.$1.toUpperCase() + RegExp.$2.toLowerCase();}
  return words.join(' ');
} 

String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, "");}

function number(e)
{
var key, keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true; 
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
   return true;
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function letter(e)
{
var key, keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27))
   return true;
else if ((("abcdefghijklmnopqrstuvwxyz ").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function createXMLHttpRequest() {
  try { return new XMLHttpRequest(); } catch(e) {}
  try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
  alert("XMLHttpRequest not supported");
  return null;
}

var xmlHttpDATES, xmlHttp
function dateUSER()
{
  xmlHttpDATES=createXMLHttpRequest();  
  xmlHttpDATES.onreadystatechange=function(){ if(xmlHttpDATES.readyState != 4){return;} if(xmlHttpDATES.status != 200){ return;} 
   var s=xmlHttpDATES.responseText; return false;
  }
  selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&password="+ document.loginAccount.txtUserPass.value + "&stage=setDateUSER&rand=" + randomNumber;  

  xmlHttpDATES.open("GET",selURL,false);  xmlHttpDATES.setRequestHeader("X-Requested-With", "XMLHttpRequest");  xmlHttpDATES.send(null);  
}

function dateVRMS()
{
  xmlHttpDATES=createXMLHttpRequest();
  xmlHttpDATES.onreadystatechange=function(){ if(xmlHttpDATES.readyState != 4){return;} if(xmlHttpDATES.status != 200){ return;}	  
   var s=xmlHttpDATES.responseText; return false;
  }
 selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&password="+ document.loginAccount.txtUserPass.value + "&stage=setDateVRMS&rand=" + randomNumber;  

 xmlHttpDATES.open("GET",selURL,false); xmlHttpDATES.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xmlHttpDATES.send(null);  
}


function setClosestStore()
{
  xmlHttpStore=createXMLHttpRequest();
  xmlHttpStore.onreadystatechange=function(){ if(xmlHttpStore.readyState != 4){return;} if(xmlHttpStore.status != 200){ return;}
   var s=xmlHttpStore.responseText;
   document.getElementById("selStoreID").value = s;
   document.getElementById("storeNumDiv").innerHTML = "Store #" + s + "&nbsp;&nbsp;";
   document.getElementById("setClosestStoreID").innerHTML = "";
   return false;
  }
  var thisZip = document.manageAccount.txtZipCode.value;
  var thisZip5 = thisZip.substring(0, 5)
 selURL = "myAccount_locateNearestStore.asp?zipcode="+ thisZip5 + "&rand=" + randomNumber;
 xmlHttpStore.open("GET",selURL,false); xmlHttpStore.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xmlHttpStore.send(null);
}


function getBrowser(){
 var browser=navigator.appName;
 var b_version=navigator.appVersion;
 var version=parseFloat(b_version);
}

function hideShowPreloader(which){	
 var loadOBJ = document.getElementById('preloading');
 if(which == "hide"){loadOBJ.style.display = "none";}else{loadOBJ.style.display = "block";}
}

function focusField(x,y,z){ var z=document.getElementById(z); if(z != null){ z.focus(); }}

function selectCheckFocus(x){
 var homePhoneCheck = document.getElementById("checkHomePhoneID"); var lastNameCheck = document.getElementById("checkLastNameID"); var emailCheck = document.getElementById("checkEmailID");
 switch(x)
 {
 case "email":
  homePhoneCheck.checked = false;  lastNameCheck.checked = false;  emailCheck.checked = true;  break;
 case "lastname":
  homePhoneCheck.checked = false;  lastNameCheck.checked = true;  emailCheck.checked = false;  break;
 case "homephone":
  homePhoneCheck.checked = true;  lastNameCheck.checked = false;  emailCheck.checked = false;  break;
 default:
 }
}

//function upperCaseField()
//{
 //document.loginAccount.txtFirstName.value = document.loginAccount.txtFirstName.value.toCapitalCase();
 //document.loginAccount.txtLastName.value = document.loginAccount.txtLastName.value.toCapitalCase();
//}

var patternReg=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|COM|net|NET|org|ORG|edu|EDU|int|INT|mil|MIL|gov|GOV|arpa|biz|aero|name|coop|info|pro|museum|tv|ca))$/;

var jsEmailCreate, jsEmailUpdate
function checkEmail(){
 var thisEmail = document.getElementById('errEmail'); 
 if(patternReg.test(document.loginAccount.txtEmail.value)){ 		
  thisEmail.innerHTML = "";	ajaxFunction("email");		
 } else {
  thisEmail.innerHTML = "Please enter a valid email address.";		
 }
}

function checkLogin(){
 if((document.loginAccount.txtEmail.value != "") && (document.loginAccount.txtUserPass.value != "")){ 
  ajaxFunction("checkLogin");  return false;
 }else{	
  document.getElementById('errLogin').childNodes[0].nodeValue = "Double check Login";  return false;
 }	
}

function checkEmailCreate(){
 var thisEmailMsg = document.getElementById('errLogin'); 
 if(patternReg.test(document.manageAccount.txtEmail.value)){ 		
  ajaxFunction("createEmail");  return false;
 }else{	
  thisEmailMsg.innerHTML = "Please enter a valid email address."; jsEmailCreate = "Email Address\n";  return false;
 }	
}
var jsEmailVerify = "";

function checkEmailVerify(){
 var thisEmailMsg = document.getElementById('eMailMsg'); 
 if(patternReg.test(document.verifyAccount.txtEmail.value)){ return false;
 }else{	
  thisEmailMsg.innerHTML = "Please enter a valid email address."; jsEmailVerify = "Email Address\n";  return false;
 }	
}

function checkEmailGetLogin(){
 var thisEmail = document.getElementById('errEmail'); 
 if(patternReg.test(document.loginAccount.txtEmail.value)){ 	
  ajaxFunction("getLogin"); return false;
 }else{			
  thisEmail.innerHTML = "Please enter a valid email address."; jsEmailCreate = "Email Address\n";  return false;	
 }	
}
var optOutEmail;
function checkEmailOptOut(){

optOutEmail = document.loginAccount.txtEmail.value;

 var thisErrEmail = document.getElementById('errLogin'); 
 var thisbtnSubmitButtonID = document.getElementById('btnSubmitButtonID'); 
//alert("here");
 if(patternReg.test(document.loginAccount.txtEmail.value)){ 	
  //thisbtnSubmitButtonID.disabled = true;
  //hideShowPreloader('show');
  //window.location = "myAccount_optOutVRMS.asp?email="+ optOutEmail + "&rand=" + randomNumber;
  //return false;
  ajaxFunction("OptOut"); return false;
 }else{			
  thisErrEmail.innerHTML = "Please enter a valid email address."; return false;
 }	
}

var jsEmailUpdate;
function checkEmailUpdate()
{
 var thisEmailMsg = document.getElementById('eMailMsg'); 
 var eOne = document.manageAccount.sessionEmailID.value;
 var eTwo = document.manageAccount.txtEmail.value;
 
 if(eOne.toLowerCase() != eTwo.toLowerCase()){
  if(patternReg.test(document.manageAccount.txtEmail.value)){ 
   ajaxFunction("updateEmail");				
  }else{
   thisEmailMsg.innerHTML = "Please enter a valid email address.";	jsEmailUpdate = "Email Address\n";	
  }
 }else{
  jsEmailUpdate = ""; thisEmailMsg.innerHTML = "";	
 }
}

var jsBonusCard;
function checkBonusCard(){
 var thisBonusCard = document.getElementById('bonusSavingsCardMsg');
 var valueTest = document.getElementById("txtBonusSavingsCardID").value;
 if(valueTest.length > 10){
  thisBonusCard.innerHTML = ""; jsBonusCard = "";	
 }else{
  thisBonusCard.innerHTML = "Card Number is not valid"; jsBonusCard = "Bonus Card\n";	
 }
}

var jsMobilePhone = "";
function checkMobilePhone(){
 var thisMobilePhone = document.getElementById('mobilePhoneMsg');
 var valueMobile = document.getElementById("txtMobilePhoneID").value;
 if(valueMobile.length < 10 || valueMobile == "" || valueMobile == null){
  thisMobilePhone.innerHTML = "Mobile Phone Number should be 10 digits"; jsMobilePhone = "Mobile Phone\n";	
 }else{
  thisMobilePhone.innerHTML = ""; jsMobilePhone = "";	
 }
}

var jsHomePhone = "";
function checkHomePhone(){
 var thisHomePhone = document.getElementById('homePhoneMsg');
 var valueHome = document.getElementById("txtHomePhoneID").value;
 if(valueHome.length < 10){
  thisHomePhone.innerHTML = "Home Phone Number should be 10 digits"; jsHomePhone = "Home Phone\n";	
 }else{
  thisHomePhone.innerHTML = ""; jsHomePhone = "";	
 }
}

function checkNewsletterText(x){
 if(x=='n'){
  document.getElementById('noHTML').checked=true;
  document.getElementById('yesHTML').checked=false;
 }
 if(x=='y'){
  document.getElementById('noHTML').checked=false;
  document.getElementById('yesHTML').checked=true;
 }
}

function checkTextMessagesText(){
var valueCheck = document.getElementById("mobileTextID").checked;
 if(valueCheck){
  document.manageAccount.mobileText.checked = false;
 }else{
  document.manageAccount.mobileText.checked = true;
 }
checkTextMessages();
}

function checkTextMessages(){
 var thisMobilePhone = document.getElementById("mobilePhoneMsg");
 var valueTextBox = document.getElementById("mobileTextID").checked;
 var tdOBJ = document.getElementById("mobilePhoneTD");
 if(valueTextBox){tdOBJ.style.color="red";checkMobilePhone();}else{thisMobilePhone.innerHTML="";tdOBJ.style.color="black";}
}

function checkPostalMailText(){
var valueCheck = document.getElementById("postalMailOptionID").checked;
 if(valueCheck){
  document.manageAccount.postalMailOption.checked = false;
 }else{
  document.manageAccount.postalMailOption.checked = true;
 }
checkPostalMail();
}

function checkPostalMail(){
 var valueTextBox = document.getElementById("postalMailOptionID").checked;
 var tdOBJ1 = document.getElementById("address1TD");
 var tdOBJ2 = document.getElementById("cityTD");
 var tdOBJ3 = document.getElementById("stateTD");
 
 if(valueTextBox){
   tdOBJ1.style.color="red"; tdOBJ2.style.color="red"; tdOBJ3.style.color="red";
 }else{
   document.getElementById("chkpostalMailOptionMsg").childNodes[0].nodeValue=" ";   
   document.getElementById("addr1Msg").innerHTML="&nbsp;";
   document.getElementById("cityMsg").innerHTML="&nbsp;";
   document.getElementById("stateMsg").innerHTML="&nbsp;";
   tdOBJ1.style.color="black"; tdOBJ2.style.color="black"; tdOBJ3.style.color="black";
 }
}

function zipStoreCheck(){
 checkFieldLength('manageAccount','txtZipCodeID', 5,'zipCodeMsg'); 
 var zipError = document.getElementById("zipCodeMsg").innerHTML; 
  if(!zipError){
    checkStore("zip");
  }
}

var jsStore;
function checkStore(x){
 var thisStoreDiv = document.getElementById("storeNumDiv");
 var storeDrop = document.getElementById("selStoreID");
 var storeTextID = document.getElementById("setStoreTextID");

  xmlHttpStore=createXMLHttpRequest();
  xmlHttpStore.onreadystatechange=function(){ if(xmlHttpStore.readyState != 4){return;} if(xmlHttpStore.status != 200){ return;}
  var s=xmlHttpStore.responseText;
   if(document.getElementById("selStoreID").value != s){
     storeTextID.innerHTML = "<div align='center' style='width:140px;background-color:white;' onclick='setClosestStore();' class='setNearestStoreLink' id='setClosestStoreID'>Select the closest store</div>";
   }else{
     storeTextID.innerHTML = "";
   }
   return false;
  }
  var thisZip = document.manageAccount.txtZipCode.value;
  var thisZip5 = thisZip.substring(0, 5)
 selURL = "myAccount_locateNearestStore.asp?zipcode="+ thisZip5 + "&rand=" + randomNumber;
 xmlHttpStore.open("GET",selURL,false); xmlHttpStore.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xmlHttpStore.send(null);
  
 
 
 if(storeDrop.options[storeDrop.selectedIndex].value == 0){			
  thisStoreDiv.innerHTML = "Required" + "   "; jsStore = "Select a Store\n";
  storeTextID.innerHTML = "<div align='center'><a href='#' style='width:140px;background-color:white;' onclick='setClosestStore();' id='setClosestStoreID'>Select the closest store</a></div>";
 }else{
  thisStoreDiv.innerHTML = "Store #" + document.getElementById("selStoreID").value + "&nbsp;&nbsp;"; jsStore = "";		
 }
}

var jsFieldLength, jsUserPass, jsFirstName, jsLastName, jsZipCode, errorMessage, jsAddress, jsCity, jsState
function checkFieldLength(myForm, myField, myLength, myErrMsg)
{ 
var thisErrMsg = document.getElementById("" + myErrMsg + "");
 valueTest = eval("document." + myForm + "." + myField + "." + "value;");
 if(valueTest.length >= myLength){
  thisErrMsg.innerHTML = "";
  switch(myField)
  {
    case "txtUserPassID":jsUserPass = ""; break;    
    case "txtFirstNameID":jsFirstName = ""; break;
    case "txtLastNameID": jsLastName = ""; break;	
	case "txtAddress1ID":jsAddress = ""; break;
    case "txtCityID": jsCity = ""; break;
	case "txtStateID": jsState = ""; break;	
    case "txtZipCodeID": jsZipCode = ""; break;
    default:
  }		
}else{	
 thisErrMsg.innerHTML = "You need at least " + myLength + " characters.";		
 switch(myField)
 {
   case "txtUserPassID": jsUserPass = "Password\n"; break;    
   case "txtFirstNameID": jsFirstName = "First Name\n"; break;
   case "txtLastNameID": jsLastName = "Last Name\n"; break;
   case "txtAddress1ID":jsAddress = "Address 1\n"; break;
   case "txtCityID": jsCity = "City\n"; break;
   case "txtStateID": jsState = "State\n"; break;
   case "txtZipCodeID": jsZipCode = "Zip Code\n"; break;
   default:
  }
 }	
}


var ajaxToken = null;
function ajaxFunction(which,a)
{
//alert(which);
 if(which != "email"){ hideShowPreloader('show'); }
  ajaxToken = a;  
   xmlHttp=createXMLHttpRequest();  
   xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){	 	  
   var s=xmlHttp.responseText;	
   //if(s =! null && s =! true && s =! false){
    //alert(optOutEmail);
   if(s =="Not unsubscribed"){
     //window.location = "myAccount_optOutVRMS.asp?email="+ optOutEmail + "&rand=" + randomNumber;
   }
  var thisErrLogin = document.getElementById("errLogin");
  var thisErrEmail = document.getElementById("errEmail");
  var thisEmailMsg = document.getElementById("eMailMsg");
  
 switch(which)
 {
 case "verifyAccount":
  checkUSER(a); break;    
 
 case "email":
  if(s != "undefined"){thisErrEmail.innerHTML = s;}
  if(s != ""){}
 break;   
 
 case "checkLogin":	
  if(s != "Login is incorrect."){ 
   thisErrLogin.innerHTML = ""; 
   thisErrEmail.innerHTML = ""; 
   dateUSER(); 
   //dateVRMS();   
   document.loginAccount.submit(); 		
   return true;
  }else{
   thisErrLogin.innerHTML = s; hideShowPreloader('hide');
   thisSubmitButton.disabled=false;
   thisSubmitButton.value = " Login ";
   return false;
  }			
 break;    

 case "getLogin":	 
 if(s == ""){ 	
  hideShowPreloader('show');
  thisErrLogin.innerHTML = "";
  thisErrEmail.innerHTML = ""; 
  document.loginAccount.submit(); 	
  return true;			
 }else{
  thisSubmitButton.disabled=false;
  hideShowPreloader('hide');
  thisErrEmail.innerHTML = "That email is not registered";
  thisSubmitButton.value = " Email Me My Login ";
  return false;
 } 
break;   

case "OptOut":	
 if(s == ""){ 
  hideShowPreloader('show');
  thisErrLogin.innerHTML = "";
  thisErrEmail.innerHTML = ""; 
  document.loginAccount.submit(); 	
  return true;	
 }else{ 
 window.location = "myAccount_optOutVRMS.asp?email="+ optOutEmail + "&rand=" + randomNumber;
  //thisSubmitButton.disabled=false;
  //hideShowPreloader('hide');
  //thisErrEmail.innerHTML = "That email is not registered";
  //thisSubmitButton.value = " Unsubscribe Me ";
  return false;
 } 
break;  

case "updateEmail":	
  if(s == "Unique"){				
   thisEmailMsg.innerHTML = "";
   jsEmailUpdate = "";
  
  }else{
  
   var currentData = document.manageAccount.txtEmail.value;
    if(document.manageAccount.txtEmail.value != document.manageAccount.sessionEmailID.value){
     thisEmailMsg.innerHTML = currentData + " is already registered.";
     document.manageAccount.txtEmail.value = document.manageAccount.sessionEmailID.value;
     jsEmailUpdate = "\nEmail Address";
	 
    if(currentData != "undefined"){ alert(currentData + " is already registered.");}
	}else{jsEmailUpdate = ""; thisEmailMsg.innerHTML = "";}

  }		
   hideShowPreloader('hide'); 				
 break;   	
 
 case "createEmail":
 alert("createEmail");
  if(s == "Not Found"){
   thisEmailMsg.innerHTML = "";
   thisErrEmail.innerHTML = ""; 
  
   jsEmailCreate = "";	
  }else{
   ref = document.manageAccount.txtEmail.value
    if(ref != ""){
     refUrl = document.manageAccount.refUrlValue.value;
     window.location = "http://" + refUrl + "/pages_referfriend.asp?r=" + ref;
    }
  thisEmailMsg.innerHTML = document.manageAccount.txtEmail.value + " is already registered.";	
  document.manageAccount.txtEmail.value = ""
  document.manageAccount.txtEmail.focus();				
 }
break;    
		  
default:
//default code
}//end switch			
			
  }//request status
 }//ready state
}//onStateChange	  

var thisSubmitButton = document.getElementById('btnSubmitButtonID');
var thisVerifyButton = document.getElementById('VerifyFormID');
   
switch(which)
{
 case "verifyAccount":	

  switch(ajaxToken)
  {
   case "email":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&email="+ document.verifyAccount.txtEmail.value + "&stage=verifyCard-email&rand=" + randomNumber; break;
   case "lastname":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&lastName="+ document.verifyAccount.txtLastName.value + "&stage=verifyCard-lastname&rand=" + randomNumber; break;
   case "homephone":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&homePhone="+ document.verifyAccount.txtHomePhone.value + "&stage=verifyCard-phone&rand=" + randomNumber; break;
  default:
   alert("Verify Error"); return false;
  }

 break;
 case "email":
  selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&stage=lookUpEmail&rand=" + randomNumber; break;    
 case "checkLogin":
  thisSubmitButton.disabled=true;
  thisSubmitButton.value = " Checking Login ";
  document.getElementById('errLogin').childNodes[0].nodeValue = ""; 
  selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&password=" + document.loginAccount.txtUserPass.value + "&stage=loginAccount&rand=" + randomNumber; break;  
 case "getLogin":
  thisSubmitButton.disabled=true;
  thisSubmitButton.value = " Emailing Login ";
  selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&stage=getLogin&rand=" + randomNumber; break;
 case "OptOut":
  thisSubmitButton.disabled=true;
  thisSubmitButton.value = " Unsubscribing Account ";
  selURL = "myAccount_forgotPassDB.asp?email="+ document.loginAccount.txtEmail.value + "&stage=optOut&rand=" + randomNumber; break;
 case "updateEmail":
  selURL = "myAccount_forgotPassDB.asp?email="+ document.manageAccount.txtEmail.value + "&stage=updateEmail&rand=" + randomNumber; break; 
 case "createEmail": 
  thisVerifyButton.disabled=true;
  thisVerifyButton.value = "  Creating Account ";
  selURL = "myAccount_forgotPassDB.asp?email="+ document.manageAccount.txtEmail.value + "&stage=createEmail&rand=" + randomNumber; break;				
 default:
}//end switch	

//alert(selURL);
xmlHttp.open("GET",selURL,true);
xmlHttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlHttp.send(null);   
}  //end ajax


function checkVRMS(x)
{
 xmlHttp2=createXMLHttpRequest(); 
 xmlHttp2.onreadystatechange=function(){if(xmlHttp2.readyState==4){if(xmlHttp2.status==200){
 var s=xmlHttp2.responseText;	
 selURL = "";
 if(s != "Account not found"){
  hideShowPreloader('show');
  
  var thisVerifyButton = document.getElementById('VerifyFormID');
  thisVerifyButton.disabled=true;
  thisVerifyButton.value = "  Creating Account ";
 
  document.getElementById("verifiedValueID").value = "v";
  document.verifyAccount.submit(); 		  
  return true;

 }else{
 hideShowPreloader('hide');
  document.getElementById('errVerify').childNodes[0].nodeValue = s;  return false;
 }		 

  }//request status
 }//ready state
}//onStateChange
 
  switch(x)
 {
  case "email":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&email="+ document.verifyAccount.txtEmail.value + "&stage=email-verifyCard&rand=" + randomNumber;  break;
  case "lastname":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&lastName="+ document.verifyAccount.txtLastName.value + "&stage=lastname-verifyCard&rand=" + randomNumber;  break;
  case "homephone":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&homePhone="+ document.verifyAccount.txtHomePhone.value + "&stage=phone-verifyCard&rand=" + randomNumber;  break;
  default:
   alert("Verify Error");
 }
xmlHttp2.open("GET",selURL,true);
xmlHttp2.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlHttp2.send(null);  
}

function checkUSER(x)
{
  xmlHttp=createXMLHttpRequest(); 
  xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){if(xmlHttp.status==200){	   
  //alert(x); 
  checkVRMS(x);
  return false;
  }//request status 
 }//ready state
}//onStateChange
 
  switch(x)
 {
  case "email":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&email="+ document.verifyAccount.txtEmail.value + "&stage=verifyCard-email&rand=" + randomNumber;  break;
  case "lastname":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&lastName="+ document.verifyAccount.txtLastName.value + "&stage=verifyCard-lastname&rand=" + randomNumber;  break;
  case "homephone":
   selURL = "myAccount_forgotPassDB.asp?cardNum="+ document.verifyAccount.txtBonusSavingsCard.value + "&homePhone="+ document.verifyAccount.txtHomePhone.value + "&stage=verifyCard-phone&rand=" + randomNumber;  break;
  default:
   alert("Verify Error");
 }

xmlHttp.open("GET",selURL,true);
xmlHttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlHttp.send(null);  
}

function checkAccountUpdate(x){
 //if(jsEmailUpdate = "undefined"){ checkEmailUpdate(); }
  checkFieldLength('manageAccount','txtUserPassID', 5,'myPasswordMsg');
  checkFieldLength('manageAccount','txtFirstNameID', 2,'fNameMsg');
  checkFieldLength('manageAccount','txtLastNameID', 2,'lNameMsg');
  checkFieldLength('manageAccount','txtZipCodeID', 5,'zipCodeMsg');
  
  checkBonusCard();
  var mobileCheckBox = document.getElementById("mobileTextID").checked;  
  if(mobileCheckBox){checkTextMessages();}else{jsMobilePhone = "";}checkStore();	  
  
  var validUpdate;
  if(mobileCheckBox){
   validUpdate = jsEmailUpdate + jsUserPass + jsFirstName + jsLastName + jsZipCode + jsBonusCard + jsMobilePhone + jsStore;
  }else{
   validUpdate = jsEmailUpdate + jsUserPass + jsFirstName + jsLastName + jsZipCode + jsBonusCard + jsStore;
  }

  var postalCheckBox = document.getElementById("postalMailOptionID").checked;
  if(postalCheckBox){
   checkFieldLength('manageAccount','txtAddress1ID', 6,'addr1Msg');
   checkFieldLength('manageAccount','txtCityID', 5,'cityMsg');
   checkFieldLength('manageAccount','txtStateID', 2,'stateMsg');
   validUpdate = jsEmailUpdate + jsUserPass + jsFirstName + jsLastName + jsAddress + jsCity + jsState + jsZipCode + jsBonusCard + jsMobilePhone + jsStore;
  }

  var errorMsgHeader = "Please double check\nthe following field(s):\n-------------------------\n";
 if(validUpdate == ""){
   if(x == "yes"){ hideShowPreloader('show'); document.getElementById('UpdateFormID').value = " Updating Account "; document.getElementById('UpdateFormID').disabled = true;return true;}else{hideShowPreloader('hide'); return false;}   
 }else{if(validUpdate != "undefined"){alert(errorMsgHeader + validUpdate);}return false;}
}

function checkAccountCreate(x){
 checkEmailCreate();
 checkFieldLength('manageAccount','txtUserPassID', 5,'myPasswordMsg');
 checkFieldLength('manageAccount','txtFirstNameID', 2,'fNameMsg');
 checkFieldLength('manageAccount','txtLastNameID', 2,'lNameMsg');
 checkFieldLength('manageAccount','txtZipCodeID', 5,'zipCodeMsg');
 checkBonusCard();
 var valueTextBox = document.getElementById("mobileTextID").checked;
 if(valueTextBox){checkTextMessages();}checkStore();		

 var validUpdate;
 if(valueTextBox){
  validUpdate = jsEmailCreate + jsUserPass + jsFirstName + jsLastName + jsZipCode + jsBonusCard + jsMobilePhone + jsStore;
 }else{
  validUpdate = jsEmailCreate + jsUserPass + jsFirstName + jsLastName + jsZipCode + jsBonusCard + jsStore;
 }

 var errorMsgHeader = "Please double check\nthe following field(s):\n-------------------------\n";
 if(validUpdate == ""){if(x == "yes"){return true;}else{return false;}}else{if(validUpdate != "undefined"){alert(errorMsgHeader + validUpdate);}return false;}
}

function verifyAccountCreate(){
 jsEmailVerify = "";
 jsHomePhone = "";
 jsLastNameVerify = "";
 
 document.getElementById('eMailMsg').childNodes[0].nodeValue = "";
 document.getElementById('homePhoneMsg').childNodes[0].nodeValue = "";
 document.getElementById('lNameMsg').childNodes[0].nodeValue = "";
 document.getElementById('bonusSavingsCardMsg').childNodes[0].nodeValue = "";
 document.getElementById('errVerify').childNodes[0].nodeValue = "";

 var t=null;
 var jsVerify;
 checkBonusCard(); 
 var email = document.verifyAccount.verifyToken[0].checked;
 var lastname = document.verifyAccount.verifyToken[1].checked;
 var homephone = document.verifyAccount.verifyToken[2].checked; 
 var checkChecks = email + lastname + homephone;  
 var emailText = document.getElementById("txtEmailID").value;
 var lastnameText = document.getElementById("txtLastNameID").value;
 var homephoneText = document.getElementById("txtHomePhoneID").value; 

 if(email==true){ t = "email"; checkEmailVerify();} 
 if(lastname==true){ t = "lastname"; checkFieldLength('verifyAccount','txtLastNameID', 2,'lNameMsg');} 
 if(homephone==true){ t = "homephone";checkHomePhone();}
 if(!checkChecks){jsVerify="Select Email Address or Last Name or Home Phone";}else{jsVerify = "";}
 //if(document.getElementById('lNameMsg').childNodes[0].nodeValue){jsLastNameVerify = "Last Name";}else{jsLastNameVerify = "";}
 
switch(t)
{
 case "email":
  var validUpdate = jsBonusCard + jsVerify + jsEmailVerify;  break;
 case "lastname":
  var validUpdate = jsBonusCard + jsVerify + jsLastNameVerify;  break;
 case "homephone":
  var validUpdate = jsBonusCard + jsVerify + jsHomePhone;  break;
 default:
  var validUpdate = jsBonusCard + jsVerify;
}
var errorMsgHeader = "Please double check the following field(s):\n----------------------------------------------\n";
 
if(validUpdate){
hideShowPreloader('hide');
alert(errorMsgHeader + validUpdate);
return false;}else{  
  ajaxFunction("verifyAccount",t);
  return false;
 }
}

