var currentCardSet=null,selectedCard=-1,GCMDebug=false,userCards=[],currentEditingIndex=-1,summaryMsgShown=false,createAnotherMsgShown=false;var hashParams;function validateStartDate(g,c){var e=g.split("/"),f,h,a=new Date();try{f=e[1]+"/"+e[0]+"/"+e[2];h=new Date(f)}catch(b){return false}return(h>a)}function load(){hashParams="";selectedCard=-1;if(gup("action")=="edit"){getGCParams()}else{if(window.location.hash!=""){hashParams=$.deparam.fragment();getGCParams()}else{boolCardsInBasket()}}}function getGCParams(){var a=[];if(gup("action")=="edit"){a.push("ordinalPos="+gup("ordinalpos"))}else{a.push("ordinalPos="+hashParams.ordinalpos)}jQueryCallWrapperREST("CharityGiftCardMultiple.aspx/getGiftCardInfo",a,getGCParams_Succeeded,Ajax_Error,null)}function getGCParams_Succeeded(b,a){var c=JSON.parse(b.d);if(c.cardType=="print"){$("#lstCardType").val("1")}else{$("#lstCardType").val("2")}configureInterface($("#lstCardType").val());$("#lstCategories").val(c.category);if(c.category>3){c.category=3}changeCategory($("#lstCategories")[0],c.category);if(c.amount=="10"||c.amount=="20"||c.amount=="50"||c.amount=="100"){$("#lstAmount").val(c.amount)}else{$("#lstAmount").val("other")}changeAmount();selectedCard=c.imageNumber;selectCard(c.imageNumber);$("#RecipientName").val(c.recipientName);$("#RecipientEmail").val(c.recipientEmail);$("#RecipientEmail2").val(c.recipientEmail);$("#CardMessage").val(c.GCMessage);$("#SenderName").val(c.senderName);$("#SenderEmail").val(c.senderEmail);if(c.GCDelayedSend=="true"){$("#radSendCardLater").trigger("click");$("#DPSendDate").val(c.GCDelayedDate)}else{$("#radSendCardNow").attr("checked","checked")}getCardsFromBasket()}function Ajax_Error(a){alert("Error: "+a.responseText)}function initPage(){getCategories();$("#lstCardType").focus();$("#divDelaySendControls").hide();$("#radSendCardNow").click(function(){$("#divDelaySendControls").hide("slow");$("#DPSendDate").val("");$("#DPSendDate").addClass("ignore")});$("#radSendCardLater").click(function(){$("#divDelaySendControls").show("slow");$("#DPSendDate").removeClass("ignore")});$.datepicker.setDefaults($.extend({showMonthAfterYear:false,showOn:"both",buttonImage:"/image/cal.gif",buttonImageOnly:true,changeMonth:true,changeYear:true,dateFormat:"dd/mm/yy"},$.datepicker.regional[""]));if(pageLanguage==2){$.getScript("/jquery/ui.datepicker-fr.js",function(a,b){$("#DPSendDate").datepicker($.datepicker.regional.fr)})}else{$("#DPSendDate").datepicker({dateFormat:"dd/mm/yy"})}if(false==GCMDebug){$("#divGCContainer").hide();$("#divRecipientInfo").hide()}$("#aSaveCard").bind("click",saveCurrentCard);jQuery.validator.addMethod("DateGTToday",validateStartDate,"Please choose a date that is later than today's date");$("#form1").validate({debug:false,onsubmit:false,ignore:".ignore",rules:{RecipientName:"required",RecipientEmail:{required:true,email:true},RecipientEmail2:{equalTo:"#RecipientEmail"},CardMessage:"required",SenderName:"required",SenderEmail:{required:true,email:true},txtOtherAmount:{required:true,number:true},DPSendDate:{required:true,DateGTToday:true}},messages:{RecipientName:"Please enter the recipient's name",RecipientEmail:{required:"Please enter the recipient's email address",email:"Your email address must be in the proper format (ex. name@domain.com)"},RecipientEmail2:{equalTo:"Must match email above."},CardMessage:"Please enter a message to the recipient",SenderName:"Please enter your name",SenderEmail:{required:"Please enter your email address",email:"Your email address must be in the proper format (ex. name@domain.com)"},txtOtherAmount:{required:"Please enter an amount above",number:"Please enter a valid amount above"}},errorPlacement:function(a,b){a.appendTo(b.parent("td"))},highlight:function(b,a){$(b).siblings("img").remove();$(b).addClass("fieldInvalid")},unhighlight:function(b,a){$(b).removeClass("fieldInvalid")},success:function(a){}});$("#lstCardType").trigger("onchange")}function unloadPage(){currentCardSet=null;userCards=null}function changeCategory(c,b){var a=c.options[b].value;getCards(a);optionsSelected()}function getCardDeliveryType(){var a=$("#lstCardType").val();return a}function optionsSelected(){if(($("#lstCardType").val()!=-1&&$("#lstCategories").val()!=-1&&$("#lstAmount").val()!=-1)){if($("#divGCContainer").is(":visible")==false){$("#divGCContainer").show("slow")}}}function configureInterface(a){if(a==1){$(".emailOnlyField input:text").addClass("ignore");$(".emailOnlyField").hide()}else{if(a==2){$(".emailOnlyField input:text").not("#DPSendDate").removeClass("ignore");$(".emailOnlyField").show()}}optionsSelected()}function getCategories(){var a=[];a.push("language="+pageLanguage);a.push("categoryType=1");jQueryCallWrapperREST("CharityGiftCardMultiple.aspx/getCategories",a,getCategories_Succeeded,Ajax_Error,null)}function getCategories_Succeeded(a,d){var b=a.d,e;e=$("#lstCategories")[0];e.options[0]=new Option("Choose an Occasion","-1");for(var c=0;c<b.length;c++){e.options[c+1]=new Option(b[c].CategoryDescription,b[c].CategoryID)}}function getCards(b){var a=[];a.push("categoryID="+b);jQueryCallWrapperREST("CharityGiftCardMultiple.aspx/getCards",a,getCards_Succeeded,Ajax_Error,null)}function getCards_Succeeded(c,b){var a=c.d,d;if(a!=null){d=$("#lstAmount").val();if(d=="other"){d=""}displayCards((currentCardSet=a),d)}else{alert("Could not get cards")}}function displayCards(e,c){var a=new Array(),d=null;if(e==null){return}selectedCard=-1;for(var b=0;b<e.length;b++){d=e[b].CardID;cardDesc=e[b].Description;a.push('<div class="GCContainer">');a.push(createLabel(d,c));a.push(createButton(d));a.push("</div>")}$("#divGCArea").html(a.join(""))}function createLink(c,b,a,d){return"/GiftCards/GiftCardImage.aspx?gcID="+c+"&gcIS="+b+"&amt="+a+"&lang="+d}function createLabel(c,a){var b=createLink(c,1,a,pageLanguage);return'<label for="gcButton'+c+'" style="background-image: url('+b+');"></label>'}function createButton(a){return'<input id="gcButton'+a+'" name="gcButton'+a+'" type="button" value="SELECT THIS CARD" onclick="javascript:selectCard('+a+')">'}function changeAmount(){var a=$("#lstAmount").val();if(a=="other"){a=""}displayOtherAmount();displayCards(currentCardSet,a);optionsSelected()}function displayOtherAmount(){var a=$("#lstAmount").val();if(a=="other"){$("#divOtherAmount").show("slow");$("#txtOtherAmount").removeClass("ignore")}else{$("#divOtherAmount").hide("slow");$("#txtOtherAmount").addClass("ignore")}}function highlightCard(a){if(selectedCard!=-1){$("#gcButton"+selectedCard).show().parent().css("border","none").css("-moz-border-radius","0px").css("-webkit-border-radius","0px")}$("#gcButton"+a).hide().parent().css("border","solid 3px #FCB131").css("-moz-border-radius","5px").css("-webkit-border-radius","5px")}function selectCard(a){highlightCard(a);selectedCard=a;if($("#divRecipientInfo").is(":visible")==false){$("#divRecipientInfo").show("slow",function(){$("#RecipientName").focus()})}}function getCardCategory(a){var b=[];b.push("cardID="+a);jQueryCallWrapperREST("CharityGiftCardMultiple.aspx/getCardCategory",b,getCardCategory_Succeeded,Ajax_Error,null)}function getCardCategory_Succeeded(d,b){var a=d.d,f,c;f=$("#lstCategories")[0];c=0;for(var e=0;e<f.options.length;e++){if(f.options[e].value==a){c=e;break}}f.options[c].selected=true;changeCategory(f,f.selectedIndex)}function Ajax_Error(a){alert("Error: "+a.responseText)}function validate(){var a=$("#form1").valid();if(!a){alert("form not valid")}}function resetFormForNewCard(){$("#RecipientName").val("");$("#RecipientEmail").val("");$("#RecipientEmail2").val("")}function updateUserCardTotal(){var a=0,b=0;for(a=0;a<userCards.length;a++){b=b+parseInt(userCards[a].CardAmount,10)}$("#spanUserCardTotalCount").html(userCards.length);$("#spanUserCardTotalAmount").text(b)}function createUserCardListItem(c,e){var b="",d="",a="";a='&nbsp;|&nbsp;<a href="javascript:void(0);" onclick="removeUserCard('+c+');">Delete</a>';b='<span style="font-weight:bold;float:left;font-size:10pt;">'+(c+1)+". $"+e.CardAmount+(e.CardDeliveryType==1?" Print":" Email")+" card for "+e.RecipientName+'</span><span style="float:right;font-weight:bold;margin-right:10px;">(<a href="javascript:void(0);" onclick="editUserCard('+c+')">Change</a>&nbsp;|&nbsp;<a href="javascript:void(0);" onclick="viewCard('+c+');">View</a>'+(e.SavedToBasket==true?"":a)+")</span>";d=$('<div id="divUserCard'+c+'" style="margin:10px;width:640px;padding:5px;height:20px;"></div>').html(b);if(c%2==0){d.addClass("even")}return d}function addToUserCardList(c){var a=(userCards.push(c))-1,b;b=createUserCardListItem(a,c);$("#divUserCards").prepend(b)}function updateUserCardList(){var a,b;$("#divUserCards").html("");for(a=0;a<userCards.length;a++){b=createUserCardListItem(a,userCards[a]);$("#divUserCards").prepend(b)}}function removeUserCard(a){userCards.splice(a,1);updateUserCardList();updateUserCardTotal()}function createCardHelper(a){$("#tableRecipient input:text").each(function(){a[this.id]=jQuery.trim(this.value)});a.CardMessage=jQuery.trim($("#CardMessage").val());amount=jQuery.trim($("#lstAmount").val());if(amount=="other"){a.CardAmount=jQuery.trim($("#txtOtherAmount").val()).replace(/[,$ ]/g,"");a.OtherAmount=true}else{a.CardAmount=amount;a.OtherAmount=false}a.CardID=selectedCard;a.CategoryID=$("#lstCategories").val();a.CardDeliveryType=$("#lstCardType").val();return a}function createCard(){var a;a=createCardHelper({});addToUserCardList(a);updateUserCardTotal()}function viewCard(b){var a=userCards[b];setPreviewData(a);showPreview()}function setPreviewData(a){var b="";$("#spanRecipientName").text(a.RecipientName);b=a.CardMessage.replace(/\n/g,"<br/>");b=b.replace(/\r\n/g,"<br/>");$("#cardMsg").html($("<p></p>").html(b));$("#spanSenderName").text(a.SenderName);$("#imgCardPreview").attr("src","/GiftCards/GiftCardImage.aspx?gcID="+a.CardID+"&gcIS=1&amt="+a.CardAmount+"&lang="+pageLanguage)}function showPreview(){var a=$("#divCardPreview");a.dialog({bgiframe:true,height:600,width:700,modal:true,autoOpen:false,close:function(b,c){}});a.dialog("open")}function closePreview(){$("#divCardPreview").dialog("close")}function presetDeliveryMethod(a){$("#lstCardType option[value='"+a+"']").attr("selected","selected")}function presetOccasion(a){$("#lstCategories option[value='"+a+"']").attr("selected","selected")}function presetAmount(a){if(a.OtherAmount==true){$("#lstAmount option[value='other']").attr("selected","selected");$("#txtOtherAmount").val(a.CardAmount)}else{$("#lstAmount option[value='"+a.CardAmount+"']").attr("selected","selected")}}function indicateCardReadyForEdit(){$("#RecipientName").focus()}function editUserCard(b){var a=userCards[b];currentEditingIndex=b;presetDeliveryMethod(a.CardDeliveryType);$("#lstCardType").trigger("onchange");presetOccasion(a.CategoryID);$("#lstCategories").trigger("onchange");presetAmount(a);$("#lstAmount").trigger("onchange");setTimeout(function(){selectCard(a.CardID)},1000);$("#RecipientName").val(a.RecipientName);$("#CardMessage").val(a.CardMessage);$("#SenderName").val(a.SenderName);if(a.CardDeliveryType==2){$("#RecipientEmail").val(a.RecipientEmail);$("#RecipientEmail2").val(a.RecipientEmail2);$("#SenderEmail").val(a.SenderEmail);if(a.DPSendDate!=""&&a.DPSendDate!="01/01/0001"){$("#DPSendDate").val(a.DPSendDate);$("#radSendCardLater").trigger("click")}else{$("#radSendCardNow").trigger("click")}}indicateCardReadyForEdit();$("#aSaveCard").unbind("click",saveCurrentCard);$("#aSaveCard").text("Save Changes");$("#aSaveCard").bind("click",saveUserCardChanges);if($("#pCreateAnotherCard").is(":visible")==true){$("#pCreateAnotherCard").fadeOut("normal",function(){$("#pSaveCard").fadeIn("normal")})}}function saveUserCardChanges(){var c=$("#form1").valid();if(selectedCard==-1){alert("Please select a card by clicking on it");return}if(!c){return}var b=userCards[currentEditingIndex],a=null;a=createCardHelper(b);a.CardModified=true;userCards[currentEditingIndex]=a;updateUserCardList();updateUserCardTotal();showSavedMessage();setTimeout(function(){$("#aSaveCard").unbind("click",saveUserCardChanges);$("#aSaveCard").text("I'm done with this Gift Card");$("#aSaveCard").bind("click",saveCurrentCard)},500)}function createAnotherCard(){resetFormForNewCard();$("#RecipientName").focus();if(createAnotherMsgShown==false){$("#pCreateAnotherCard").fadeOut("normal",function(){$("#pCreateAnotherMsg").fadeIn("normal")});setTimeout(function(){$("#pCreateAnotherMsg").fadeOut("slow",function(){$("#pSaveCard").fadeIn("normal")})},3500);createAnotherMsgShown=true}else{$("#pCreateAnotherCard").fadeOut("normal",function(){$("#pSaveCard").fadeIn("normal")})}}function previewCurrent(){var a,b;b=$("#form1").valid();if(selectedCard==-1){alert("Please select a card by clicking on it");return}if(!b){return}a=createCardHelper({});setPreviewData(a);showPreview()}function saveCurrentCard(){var a=$("#form1").valid();if(selectedCard==-1){alert("Please select a card by clicking on it");return}if(!a){return}if($("#divCreatedCards").is(":visible")==false){$("#divCreatedCards").show("slow");$("#pFinishedBottom").show()}createCard();showSavedMessage()}function showSavedMessage(){if(true==summaryMsgShown){$("#pSaveCard").fadeOut("normal",function(){$("#pCreateAnotherCard").fadeIn("normal")});return}$("#pSaveCard").fadeOut("normal",function(){$("#pSavedMsg").fadeIn("normal")});setTimeout(function(){$("#pSavedMsg").fadeOut("slow",function(){$("#pCreateAnotherCard").fadeIn("normal")})},2000);summaryMsgShown=true}function submitCards(){var a={};a.cards=userCards;a.languageCode=pageLanguage;jQueryCallWrapperDTO("/GiftCards/CharityGiftCardMultiple.aspx/processCards",a,submitCards_Success,Ajax_Error,null)}function submitCards_Success(b,a){var c=b.d;if(c!=null&&c[0]!=null){alert(c[0])}else{if(currentEditingIndex<0){currentEditingIndex=0}window.location.hash="#ordinalpos="+currentEditingIndex;window.location.href="/GivingBasket.aspx"}}function getCardsFromBasket(){var a=[];jQueryCallWrapper("CharityGiftCardMultiple.aspx/getCardsFromBasket",a,getCardsFromBasket_Succeeded,Ajax_Error,null)}function getCardsFromBasket_Succeeded(b,a){var c=b.d;if(c!=null&&c.length>0){userCards=c;updateUserCardList();$("#divGCContainer").show();$("#divRecipientInfo").show();$("#divCreatedCards").show();summaryMsgShown=true;createAnotherMsgShown=true;currentEditingIndex=c.length-1}if(gup("action")=="edit"){editUserCard(gup("ordinalpos"))}else{if(hashParams.ordinalpos!=""){editUserCard(hashParams.ordinalpos)}}$("#pFinishedBottom").show()}function boolCardsInBasket(){var a=[];jQueryCallWrapper("CharityGiftCardMultiple.aspx/getCardsFromBasket",a,boolCardsInBasket__Succeeded,Ajax_Error,null)}function boolCardsInBasket__Succeeded(b,a){var c=b.d;if(c!=null){if(c.length>0){userCards=c;updateUserCardList();currentEditingIndex=c.length-1}}}$(document).ready(function(){initPage()});
