var intTimeoutLength = 2000; var floatUnitCost = 99; //Price of the EDE2 Book function fnCalcSubtotal () { floatSubTotal = (Number($('#idNumBook').val() * Number(floatUnitCost))).toFixed(2); $('.clsAmount').html(floatSubTotal); } //Check if a named parameter is set function isSetURLParameter(name) { return (new RegExp('[?|&]' + name + '(?:[=|&|#|;|]|$)','i').exec(location.search) !== null) } //Get the value of a named parameter function getURLParameter(name) { return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)','i').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null; } $(document).ready(function() { /* =================================================================================== */ /* make sure the first item from purchase options selected on page load / refresh. */ //$("form.purchase-method input[type=radio]:first").click(); $("#guest-i").click(); //$("#guest-i").attr("checked","checked"); //If we passed the "p" parameter go to that page. if (isSetURLParameter('p')) { var intPage = getURLParameter('p'); switch (intPage) { case '2': fnNavigate("Overview", "PurchaseOptions"); break; case '3': fnNavigate("Overview", "ContactInfo"); break; default: break; } }; fnCalcSubtotal(); /* =================================================================================== */ /* re-position (center) dialog (pop-up window) when browser window is resized. */ $(window).resize(function() { $("#dialog").dialog("option", "position", "top"); }); /* =================================================================================== */ /* in step 1 of 2 for buying book, add/remove class to selected radio input parent label. (sets background color) */ $("form.purchase-method input[type=radio]").change(function() { $(this).parents("label").siblings().removeClass("sel").end().addClass("sel"); }); /* =================================================================================== */ /* if radio input ___ or ____ selected a nd form submitted, display the following. */ $("form.purchase-method").submit(function() { // check which radio input has been selected. var curRadio = $(this).find(".radio:checked"); ////////////////////////////////////////////////// if(curRadio.val()=="guest") { fnNavigate("PurchaseOptions", "ContactInfo"); } else { var button = $(this).find("button"); // add class "disabled" to form button. button.addClass("disabled"); // change button value to new chars. button.html("Please Wait "); // The initial message var msgStr = "This window will now close"; var strPostLoginMode; // switch on value switch(curRadio.val()) { case "sign-in": msgStr += " — You are being re-directed to the sign-in page."; strPostLoginMode = "purchaseAfterSignIn"; break; case "register": msgStr += " — You are being re-directed to the account registration page."; strPostLoginMode = "purchaseAfterReg"; break; } // Do the AJAX! $.post( "/includes/__EDE2Class/ajax/ajaxPublic.php?mode="+strPostLoginMode+"&intBookAmt="+$('#idNumBook').val()+"&intLocation="+$('#region').val()+"&bookLang="+$("#idBookLang").val() , {} , function(res) { switch(curRadio.val()) { case "sign-in": to = setTimeout(function() { window.parent.location.href="/index.php?fuseaction=public.login"; }, intTimeoutLength); break; case "register": to = setTimeout(function() { window.parent.location.href="/index.php?fuseaction=public.create-html5"; }, intTimeoutLength); break; } } ); $(".message").remove(); // avoid duplicates. // call function to display re-direct message. $(this).append(showMessage(msgStr, true)); // hide message immediately and re-display nicely. (fade in) $(this).find(".message").hide().fadeIn(); } return false; }); /* =================================================================================== */ $("form.contact-information").submit(function() { // validate the form // first name if($.trim($("#fname-i").attr("value"))=="" || $("#fname-i").attr("value")==objInputDefaults["fname-i"]) { $("#fname-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your first name."); return false; } // last name if($.trim($("#lname-i").attr("value"))=="" || $("#lname-i").attr("value")==objInputDefaults["lname-i"]) { $("#lname-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your last name."); return false; } // phone if($.trim($("#phone-i").attr("value"))==""){ $("#phone-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your phone number."); return false; } // email if($.trim($("#email-address-i").attr("value"))==""){ $("#email-address-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your email address."); return false; } // email if(!validateEmail($("#email-address-i").attr("value"))) { $("#email-address-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter a valid email address."); return false; } // country if($.trim($("#region").attr("value"))==""){ $("#region").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please select your location."); return false; } // canada province if( // canada $.trim($("#region").attr("value"))=="1" // no province selected && $.trim($("#canadian-provinces").attr("value"))=="" ){ $("#canadian-provinces").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please select your province."); return false; } // us if( // us $.trim($("#region").attr("value"))=="2" // no province selected && $.trim($("#us-state").attr("value"))=="" ){ $("#us-state").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your state."); return false; } // country other if($.trim($("#region").attr("value"))=="3") { if($.trim($("#international-other-country").attr("value"))=="") { $("#international-other-country").addClass("attention"); $("#idReqFieldsWarning").show(); alert("You've chosen International / Other as your country, please specify your country."); return false; } else if($.trim($("#international-other-state-province").attr("value"))=="") { $("#international-other-state-province").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your state or province."); return false; } } // street address if($.trim($("#street-i").attr("value"))==""){ $("#street-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your street address."); return false; } // city if($.trim($("#city-i").attr("value"))==""){ $("#city-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter your city."); return false; } // postal code if($.trim($("#postal-code-i").attr("value"))==""){ $("#postal-code-i").addClass("attention"); alert("Please enter your postal code."); return false; } if($.trim($("#num-copies").attr("value"))=="10+"){ return false; } // ----------------------------------------------------------------------------- // // Do the AJAX! $.post( "/includes/__EDE2Class/ajax/ajaxPublic.php?mode=fudgeAccount" , $("form.contact-information").serializeArray() , function(res) { // obj = $.parseJSON(res); // var strStoreURL = obj.store_url; if(obj.res==1) { to = setTimeout(function() { window.parent.location.href=strStoreURL; }, intTimeoutLength); } else { if(obj.res==-3) { $("#email-address-i").addClass("attention"); $("#idReqFieldsWarning").show(); alert("Please enter a valid email address."); } else if(obj.res==-2) { alert("Please fill out all fields."); } else if(obj.res==-4) { alert("Sorry, this email has already been used and has an account associated with it, either click 'Back' below and select 'Sign-in' as your purchase option or enter another email address."); } else { alert("There was an error processing your transaction, please try again."); } return false; } // ----------------------------------------------------------------------------- // // var from = "ContactInfo"; var to = "Redir"; // switch off from $("#id"+from).hide(); $("#id"+from+"Nav").hide(); $("#id"+from+"Header").hide(); $("#idBody").removeClass(objBodyClasses[from]); $("#id"+to+"Header").show(); $("#idBody").addClass("alert"); $("#idBody").addClass("re-direct"); $("#button-close").hide(); } ); return false; }); // Dialog $('#dialog').dialog({ autoOpen: true, width: 1000, position: "top", modal: true, closeOnEscape: true, draggable: false, resizable: false, dialogClass: "ede-book", close: function() { if($(document.body).hasClass("thank-you")) { parent.location.href='/index.php?fuseaction='+top.getURLParameter('fuseaction'); } else { parent.location.reload(true); } } }); // Dialog Link $('#dialog_link').click(function() { $('#dialog').dialog('open'); return false; }); $("#button-close").click(function() { $("#dialog").dialog("close"); $("iframe").parent().children("iframe.ede-book").remove(); //window.parent.closeIFrame(); }); // ------------------------ Guest Contact Info Input Fields -------------------------- // $("form.contact-information select").blur(function() { if($(this).value!="0") { $(this).removeClass("attention"); } }); $("form.contact-information input").blur(function() { var id = $(this).attr("id"); if( // is blank $.trim($(this).attr("value"))=="" // is default || (objInputDefaults[id] && $(this).attr("value")==objInputDefaults[id]) ) { if(objInputDefaults[id]) { $(this).attr("value",objInputDefaults[id]); } else { $(this).attr("value",""); } } else { $(this).removeClass("attention"); } }); // What happens when you change the region/location drop-down? $("#region").change(function() { // Regardless of selected option... $(this).parent().siblings().hide(); // hide all before showing anything. $(this).parent().parent().addClass("active"); switch($(this).attr("value")) { // No selection case "": // removes the "highlight" / background color. $(this).parent().parent().removeClass("active"); // postal code $("label[for=postal-code-i]").text("Postal Code"); break; // Canada case "1": // canadian provinces $("#canadian-provinces").parent().show(); // postal code $("label[for=postal-code-i]").text("Postal Code"); break; // US case "2": // us states $("#us-state").parent().show(); // zip code $("label[for=postal-code-i]").text("Zip Code"); break; // Other case "3": // internation, show other country and state or province $("#international-other-country").parent().show(); $("#international-other-state-province").parent().show(); // postal code $("label[for=postal-code-i]").text("Postal Code"); break; } }); $("#num-copies").change(function(){ if($(this).attr("value")=="10+") { $("#msg-more-books").show(); $(".more-books").addClass("active"); $(this).siblings(".msg").show(); $("#idContactInfo button[type=submit]").addClass("disabled"); $("#idContactInfo button[type=submit]").attr("disabled",""); } else { $(this).siblings(".msg").hide(); $(".more-books").removeClass("active"); $("#idContactInfo button[type=submit]").removeClass("disabled"); $("#idContactInfo button[type=submit]").removeAttr("disabled"); } }); $(".defaulted-input").focus(function() { var id = $(this).attr("id"); if($.trim($(this).attr("value"))==objInputDefaults[id]) { $(this).attr("value",""); } }); // ------------------------------------ NAVIGATION BUTTONS --------------------------- // $("#idOverviewBtn").click(function() { fnNavigate("PurchaseOptions", "Overview"); }); $("#idBuyBookBtn").click(function() { $('.popup-alert').toggle(); fnCalcSubtotal(); if (Number($('.error').val()) < 10) { $('#idBookWarning').hide(); } }); $("#idPurchaseOptionsBackBtn").click(function() { fnNavigate("PurchaseOptions", "Overview"); }); $("#idContactInfoOverviewBtn").click(function() { fnNavigate("ContactInfo", "Overview"); }); $("body.contact-information a.back").live("click",function(){ fnNavigate("ContactInfo", "PurchaseOptions"); }); $("#idPurchaseOptionsProcBtn").click(function() { }); /* =================================================================================== */ /* this function displays a message when ____ action is performed. */ function showMessage(value, loading_icon) { /* make sure user has passed a value to function, if not, display this one. */ if (value == null) {value = "Default Message.";} // generate markup for display. var output = '
'; /* check if the second parameter was passed a boolean value of true, if yes, append html markup required to display "loading" .gif - */ if (loading_icon !== true) { // do nothing. } else { // add markup for "loading" .gif - output += ''; } output += '

'; output += value; output += '

'; output += '
'; return output; } }); var objInputDefaults = { "fname-i": "First" , "lname-i": "Last" }; var objBodyClasses = { "Overview": "overview" , "PurchaseOptions": "purchase-options" , "ContactInfo": "contact-information" }; function fnNavigate(from, to) { //console.log("fnNavigate("+from+", "+to+");"); // switch off from $("#id"+from).hide(); $("#id"+from+"Nav").hide(); $("#id"+from+"Header").hide(); $("#idBody").removeClass(objBodyClasses[from]); // switch on to $("#id"+to).show(); $("#id"+to+"Nav").show(); $("#id"+to+"Header").show(); $("#idBody").addClass(objBodyClasses[to]); } function fnValidateOrder(newVal) { if (newVal < 10) { $('#idBookWarning').hide(); $('#idCheckout').removeClass('disabled'); } else { $('#idBookWarning').show(); $('#idCheckout').addClass('disabled'); } if (newVal < 1 && newVal !='') { newVal = 1; } if(newVal > 0 && newVal <=10) { $('#idNumBook').val(Number(newVal)); fnCalcSubtotal(); } } function validateEmail(email) { var re = /\S+@\S+\.\S+/; return re.test(email); } $('.add').live("click", function () { var intBooks = Number($('#idNumBook').val()) + 1; fnValidateOrder(intBooks); }); $('#idNumBook').live("keyup",function() { this.value = this.value.replace(/[^0-9\.]/g,''); fnValidateOrder(this.value); }); $('.rem').live("click", function () { var intBooks = Number($('#idNumBook').val()) - 1; fnValidateOrder(intBooks); }); $('#idCheckout').live("click",function () { if(!$('#idCheckout').hasClass('disabled')) { $('#num-copies').val( $('#idNumBook').val() ); $('#book-lang').val( $("#idBookLang").val() ) localStorage["intPurchased"] = $('#idNumBook').val(); localStorage["bookLanguage"] = $("#idBookLang").val(); fnNavigate("Overview", "PurchaseOptions"); } }); $('#idCancel').live("click", function(){ $('#idNumBook').val(1); $('.popup-alert').toggle(); })