﻿var sBlankInput = "Please enter a valid Player Rewards card number.";
var sErrorInUse = "Sorry, this account number is already in use. Please call customer service at 866-462-9493.";
var sErrorInvalid = "Sorry, this account number is invalid. Please call customer service at 866-462-9493.";
var sEmailExisting = "This email address is already existing in our Rewards database. Do you already have a card number? If so, <a href=javascript:; onclick=showExistingAccountMode()>click here</a> to enter your Rewards Card # and link to your GC.com account";
var sErrorNonExistingAPI = "Sorry, this account link can not be made. Please ensure all information is accurate and the Card Number is correct. If you are still having trouble, please call customer service at 866-462-9493.";
var sErrorGeneric = "Sorry, an error has occurred, and as a result this card cannot be added to your account.";
var sErrorInvalidZip = "Sorry! This program is not yet available in your area. If you believe this is an error, please confirm your address is correct or call customer service at 866-462-9493.";
var valObj;
/******** ADD NEW CARD *********/
function addNewCard(sCardNo,sEmail,sUserId) {
var bSuccess = false;
try { 
// validate
var bIsExisting = true;
$("#divAddButton_saving").show();
$("#spnAddBtn").hide();
var sZip = $('.txtZip').val();
if (sZip == "" || sZip == null)
sZip = $('#hdnUserZip').val(); 
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateCardNo",
data: "{'sLoyaltyNo':'" + sCardNo + "', 'sZip':'" + sZip + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
addNewCard_callback(msg.d, sCardNo, sUserId);
}
});
var n = 0;
}
catch(err) {
bSuccess = false;
showErrorModalPopup(sErrorGeneric);
}
return bSuccess;
}
function addNewCard_callback(valObj, sCardNo, sUserId) {
try {
if (valObj.IsValidNo) {
if (valObj.IsExistingSM || valObj.IsExistingApi) {
showErrorModalPopup(sErrorInUse);
$("#divAddButton_saving").hide();
$("#spnAddBtn").show();
}
else if (!valObj.IsAcceptableFirstDigit) {
showErrorModalPopup(sErrorInvalid);
}
else {
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/addNewCard",
data: "{'sNewLoyaltyNo':'" + sCardNo + "','sUserId':'" + sUserId + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
if (msg.d) {
showConfirmation('divConfirmation');
}
else {
showErrorModalPopup(sErrorInvalid);
}
$("#divAddButton_saving").hide();
$("#divAddNewCard").hide();
$("#spnAddBtn").show();
}
});
}
}
else {
showErrorModalPopup(sErrorInvalid);
$("#divAddButton_saving").hide();
$("#spnAddBtn").show(); 
}
}
catch (err) {
bSuccess = false;
showErrorModalPopup(sErrorGeneric);
$("#divAddButton_saving").hide();
$("#spnAddBtn").show(); 
}
}
function validateCardNo(sLoyaltyNo, bIsAddCard) {
var bIsExisting = true;
$("#divProcessingExisting").show();
$(".btnLinkExisting").hide();
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateCardNo",
data: "{'sLoyaltyNo':'" + sLoyaltyNo + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
valObj = msg.d;
showResult(bIsAddCard);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
});
var n = 0;
return validationObj;
}
/******** SIGNUP - CREATE NEW ACCT *********/
function validateNewAccount() {
if (newAccountCheck()) {
$("#divProcessing").show();
try {
var sZip = $('.txtZip').val();
if (sZip == "" || sZip == null)
sZip = $('#hdnUserZip').val();
var sEmail = $('.txtEmail').val();
if (sEmail == "" || sEmail == null)
sEmail = $('#hdnUserEmail').val();
if (sZip != "" && sEmail != "") {
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateNewAccount",
data: "{'sZip':'" + sZip + "', 'sEmail':'" + sEmail + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
validateNewAccount_callback(msg.d);
}
});
}
else {
alert("You must enter a valid Zip Code and Email Address.");
$("#divProcessing").hide();
}
}
catch (err) {
}
}
}
function validateNewAccount_callback(valObj) {
if (!valObj.IsValidZip) {
showErrorModalPopup(sErrorInvalidZip);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
else if (valObj.IsExistingApi) {
showErrorModalPopup(sEmailExisting);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
else {
createNewAccountLocal();
}
}
/******** SIGNUP - LINK EXISTING ACCT *********/
function validateExistingCardNoLocal() {
var sCardNo = $('.txtExistingAcctNo').val()
$("#spnCardNo").html('');
if (!isTCChecked()) {
return false;
}
if (!isHearAboutSelected()) {
return false;
}
if (isBlank(sCardNo)) {
return false;
}
try {
var bExistingSMAcct;
var bIsValid;
$("#spnCardNo").html(sCardNo);
// validate
validateExistingCardNo(sCardNo);
}
catch (err) {
bRtn = false;
}
return false;
}
function validateExistingCardNo(sCardNo) {
try {
var bIsExisting = true;
$("#divProcessingExisting").show();
$(".btnLinkExisting").hide();
var sZip = $('.txtZip').val();
if (sZip == "" || sZip == null)
sZip = $('#hdnUserZip').val(); 
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateCardNo",
data: "{'sLoyaltyNo':'" + sCardNo + "', 'sZip':'" + sZip + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
validateExistingCardNo_callback(msg.d, sCardNo);
}
});
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
}
function validateExistingCardNo_callback(valObj, sCardNo) {
try {
if (!valObj.IsValidZip) {
showErrorModalPopup(sErrorInvalidZip);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
else if (!valObj.IsValidNo) {
showErrorModalPopup(sErrorInvalid);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
else if (valObj.IsExistingSM) {
showErrorModalPopup(sErrorInUse);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
else if (!valObj.IsAcceptableFirstDigit) {
showErrorModalPopup(sErrorInvalid);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show();
}
// else if (sCardNo.substring(0, 1) == "2" && !valObj.IsExistingApi) {
// showErrorModalPopup(sErrorNonExistingAPI);
// }
else { // submit the form
existingFormSubmitLocal();
}
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
} 
}
/******** CREATE NEW ACCT - RECEIPT **********/
function createNewLoyaltyAccountAjax() {
try {
if (!isTCChecked()) {
return false;
} 
var bValidPwd = true;
var hdnPs = $("#hdnPs").val();
if ($("#hdnIsSMNewAccount").val() == "True") {
var bValidPwd = validatePwd();
if (bValidPwd)
createAccount();
}
if (bValidPwd) {
var sUserId = $("#hdnUserId").val();
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/createNewLoyaltyAccount",
data: "{'sUserId':'" + sUserId + "', 'hdnPs':'" + hdnPs + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg2) {
window.location = "/MyAccount/LoyaltyConfirmation.aspx";
}
});
} else {
alert("Please remember to enter your password above!");
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
return false;
}
return false;
}
/******** LINK EXISTING ACCT - RECEIPT **********/
function linkExistingLoyaltyAccountAjaxLocal() {
linkExistingLoyaltyAccountAjax($('.txtExistingAcctNo').val(), $('#hdnUserId').val(), $('#hdnPs').val());
return false;
}
function linkExistingLoyaltyAccountAjax(sLoyaltyNo,sUserId,hdnPs) {
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
var bSuccess = false;
if (!isTCChecked()) {
return false;
} 
var bValidPwd = true;
try {
if ($("#hdnIsSMNewAccount").val() == "True") {
var bValidPwd = validatePwd();
}
if (!bValidPwd) {
alert("Please remember to enter your password above!");
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
else {
validateExistingCardNoReceipt(sLoyaltyNo,sUserId,hdnPs)
}
}
catch(err) {
showErrorModalPopup(sErrorGeneric);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
return bSuccess;
}
function validateExistingCardNoReceipt(sCardNo,sUserId,hdnPs) {
try {
var bIsExisting = true;
$("#divProcessingExisting").show();
$(".btnLinkExisting").hide();
var sZip = null;
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateCardNo",
data: "{'sLoyaltyNo':'" + sCardNo + "', 'sZip':'" + sZip + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
validateExistingCardNoReceipt_callback(msg.d, sCardNo,sUserId,hdnPs);
}
});
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
}
function validateExistingCardNoReceipt_callback(valObj, sCardNo,sUserId,hdnPs) {
try {
if (!valObj.IsValidNo) {
showErrorModalPopup(sErrorInvalid);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
else if (valObj.IsExistingSM) {
showErrorModalPopup(sErrorInUse);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
}
// else if (sCardNo.substring(0, 1) == "2" && !valObj.IsExistingApi) {
// showErrorModalPopup(sErrorNonExistingAPI);
// } 
else { // create the account
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/linkExistingLoyaltyAccount",
data: "{'sLoyaltyNo':'" + sCardNo + "','sUserId':'" + sUserId + "', 'hdnPs':'" + hdnPs + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg2) {
createAccount(); 
window.location = "/MyAccount/LoyaltyConfirmation.aspx";
}
});
}
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divProcessingExisting").hide();
$(".btnLinkExisting").show(); 
} 
}
/******** ZIP CHECK *********/
function showZipModal() {
tb_show(null, "#TB_inline?height=300&width=450&inlineId=activation_popup&modal=true", null);
}
function checkZip() {
$("#divProcessing").show();
try {
var sZip = $(".txtZipCode").val();
if (sZip != "") {
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/isValidZip",
data: "{'sZip':'" + sZip + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
checkZip_callback(msg.d);
}
});
}
else {
alert("You must enter a valid zip code");
$("#divProcessing").hide();
}
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
}
}
function checkZip_callback(valObj) {
if (valObj.IsValid) {
var sRedirect = valObj.Redirect;
if ($('.txtZipCode').val() != "") {
sRedirect += "&zip=" + $('.txtZipCode').val();
}
window.location = sRedirect;
}
else {
window.location = "/GC---Player-Rewards-Not-Available-g25245t0.gc";
}
}
/******** EMAIL ADD *********/
function addEmail() {
$("#divProcessing").show();
$(".btnSubmit").hide();
try {
var sEmail = $("#txtEmail").val();
if (sEmail != "") {
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/enterLoyaltyEmail",
data: "{'sEmail':'" + sEmail + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
addEmail_callback(msg.d);
}
});
}
else {
alert("You must enter a valid email address!");
$("#divProcessing").hide();
$(".btnSubmit").show();
}
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
}
}
function addEmail_callback(valObj) {
if (valObj) {
$("#divConfirmation").show();
$("#divProcessing").hide();
$("#divSorryForm").hide();
}
}
/******** SPO - EXISTING ACCT *********/
function validateCardNoSPO(sLoyaltyNo) {
if (sLoyaltyNo != "") {
$("#divSpoProcessing").show();
try {
var bExistingSMAcct;
var bIsValid;
$("#spnCardNo").html(sLoyaltyNo);
var sZip = null;
// validate
$.ajax({
type: "POST",
url: "/Ajax/Loyalty/LoyaltyUtility.asmx/validateCardNo",
data: "{'sLoyaltyNo':'" + sLoyaltyNo + "', 'sZip':'" + sZip + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
validateCardNoSPO_callback(msg.d, sLoyaltyNo);
$("#divSpoProcessing").hide();
}
});
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divSpoProcessing").hide();
$('.loyaltyNo').val("");
}
}
}
function validateCardNoSPO_callback(valObj, sCardNo) {
try {
if (!valObj.IsValidNo) {
showErrorModalPopup(sErrorInvalid);
$("#divSpoProcessing").hide();
$('.loyaltyNo').val("");
}
else if (valObj.IsExistingSM || valObj.IsExistingApi) {
showErrorModalPopup(sErrorInUse);
$("#divSpoProcessing").hide();
$('.loyaltyNo').val(""); 
}
// else if (sCardNo.substring(0, 1) == "2" && !valObj.IsExistingApi) {
// showErrorModalPopup(sErrorNonExistingAPI);
// $("#divSpoProcessing").hide();
// $('.loyaltyNo').val("");
// }
}
catch (err) {
showErrorModalPopup(sErrorGeneric);
$("#divSpoProcessing").hide();
} 
}
/******** ENTER HANDLING *********/
function isEnterKey(event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) 
return true;
else
return false;
}
function handleExistingAcctValidate(event) {
if (isEnterKey(event)) {
if (validateExistingCardNoLocal()) {
return false;
}
else {
return false;
}
}
else {
return true;
}
}
function handleExistingAcctValidateReceipt(event) {
if (isEnterKey(event)) {
linkExistingLoyaltyAccountAjaxLocal();
return false;
}
else {
return true;
}
}
function handleEnterAddNewCard(event) {
if (isEnterKey(event)) {
addNewCardLocal();
return false;
}
else {
return true;
}
}
function handleEnterNewAccount(event) {
if (isEnterKey(event)) {
showZipModal();
return false;
}
else {
return true;
}
}
function handleEnterZip(event) {
if (isEnterKey(event)) {
checkZip();
return false;
}
else {
return true;
}
}
// OTHER
function onSuccess(res) {
validationObj = res;
bKeepLooping = false;
}
function parseInfo(data) {
$('#info').html(data.name + ', ' + data.email);
}
function isTCChecked() {
if (!$('#chkTerms').attr('checked')) {
alert("You must agree to the Terms And Conditions.");
return false;
}
else {
return true;
}
}
function isHearAboutSelected() {
if ($('.selHearAbout').val() == "") {
alert("Please tell us how you heard about Player Rewards.");
return false;
}
else {
return true;
}
}
function newAccountCheck() {
if (!isTCChecked()) {
return false;
}
else if (!isHearAboutSelected()) {
return false;
}
else {
return true;
}
}
function isBlank(sLoyaltyNo) {
if (sLoyaltyNo.replace(/^\s+|\s+$/g, '') == "") {
showErrorModalPopup(sBlankInput);
return true;
}
else {
return false;
}
}
function showErrorModalPopup(sMsg) {
if ($('#spnCardNo').html() == "") {
$('.divCardNo').hide();
}
else {
$('.divCardNo').show();
}
$("#spnErrorMsg").html(sMsg);
tb_show(null, "#TB_inline?height=300&width=450&inlineId=activation_popup&modal=true", null);
}
function showConfirmation(sDiv) {
$("#" + sDiv).show();
}
function showProcessing(sElementShow, sElementHide) {
$("#" + sElementShow + "").show();
$("#" + sElementHide + "").hide();
}
function validatePwd(isExistingLoyaltyAccount) {
jQuery.validator.messages.required = "* required";
var validator = $("#aspnetForm").validate({
rules: {
ctl00$CenterContent$ctl02$password: "required",
ctl00$CenterContent$ctl02$confirmpassword: "required"
},
messages: {
ctl00$CenterContent$ctl02$password: "required",
ctl00$CenterContent$ctl02$confirmpassword: "required"
}
});
if ($("#aspnetForm").valid()) {
return true;
}
else {
return false;
}
}
function getLastNameByClientId(sClientID) {
return $("#" + sClientID + "").val();
}
function popPrintCard() {
window.open("/MyAccount/LoyaltyPrintCard.aspx", "Print", "width=700,height=600");
}
function showExistingAccountMode() {
tb_remove();
$('.box_create_new').hide();
$('.box_player_rewards').show();
}
/* landing page stuff */
function existingRewardsAccountClick() {
if ($('.txtCardNo').val().length == 9) {
location.href = "/MyAccount/account.aspx?isloyalty=1&cardno=" + $('.txtCardNo').val();
}
else {
$('.spnInvalidCard').show();
}
}
function getNewAccountURL() {
var sUrl = "/myaccount/account.aspx?isloyalty=1&isnew=1";
var sZip = gup('zip');
if (sZip != undefined && sZip != "") {
sUrl += "&zip=" + sZip;
}
location.href = sUrl;
}
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function showCardNo() {
setTimeout('$(".divCardNo").show()', 1000);
}
