function updateQuantity(c,e){var d="0.00";if(IsNumeric(document.getElementById(c).value)==false||document.getElementById(c).value==0){if(document.getElementById(c).value<=0){$.prompt("Quantity should be greater than zero")}else{$.prompt("Quantity should be numeric")}$("#"+c).val("1");var b=document.getElementById(c).value;var a="/shopping/updateQuantity";$.ajax({type:"GET",url:a,data:"itemId="+e+"&newQty="+b,success:function(n){var l=n;if(n!=null){$("#totalOrder_Amt").val(n);if(($("#certificateExist").val()!="")&&($("#certificateExist").val()=="1")){var f=$("#certificateAmount").val();n=n-f;d=l-n;n=roundNumber(n,2)}if(n<0){var k=-(n);k=roundNumber(k,2);$("#giftCertificateRemainingAmount").val(k);d=l;n="0.00"}else{$("#giftCertificateRemainingAmount").val("0.00")}d=roundNumber(d,2);$("#giftAppliedAmount").val(d);$("#giftcertificatetd").html("Gift Certificate ($"+$("#certificateAmount").val()+")");$("#equaltoid").html("=");$("#appliedtd").html("-$"+d);var j=c.replace("txtquan","");var h=document.getElementById("txtprice"+j).value*document.getElementById(c).value;var g=roundNumber(h,2);$("#orderTotalAfterCertificateDiscount").val(n);document.getElementById("tdtotprice"+j).innerHTML="$"+g;document.getElementById("tdNetAmt").innerHTML="$"+n;var m="/shopping/updateExistingSession";$.ajax({type:"GET",url:m,data:"giftAppliedAmount="+d,success:function(o){}})}}});document.getElementById(c).focus()}else{var b=document.getElementById(c).value;var a="/shopping/updateQuantity";$.ajax({type:"GET",url:a,data:"itemId="+e+"&newQty="+b,success:function(n){var l=n;if(n!=null){$("#totalOrder_Amt").val(n);if(($("#certificateExist").val()!="")&&($("#certificateExist").val()=="1")){var f=$("#certificateAmount").val();n=n-f;d=l-n;n=roundNumber(n,2)}if(n<0){var k=-(n);k=roundNumber(k,2);$("#giftCertificateRemainingAmount").val(k);d=l;n="0.00"}else{$("#giftCertificateRemainingAmount").val("0.00")}d=roundNumber(d,2);$("#giftAppliedAmount").val(d);$("#giftcertificatetd").html("Gift Certificate ($"+$("#certificateAmount").val()+")");$("#equaltoid").html("=");$("#appliedtd").html("-$"+d);var j=c.replace("txtquan","");var h=document.getElementById("txtprice"+j).value*document.getElementById(c).value;var g=roundNumber(h,2);$("#orderTotalAfterCertificateDiscount").val(n);document.getElementById("tdtotprice"+j).innerHTML="$"+g;document.getElementById("tdNetAmt").innerHTML="$"+n;var m="/shopping/updateExistingSession";$.ajax({type:"GET",url:m,data:"giftAppliedAmount="+d,success:function(o){}})}}})}}function delItem(a){$.prompt("Are you sure you want to delete\n this Item from the Cart?",{callback:confirmdelItem,buttons:{Yes:a,No:"0"}})}function confirmdelItem(b,a,c){if(b!="0"){$.ajax({url:"/shopping/cart/removeItem/"+b,type:"GET",success:function(e){var f=$("#dkp-cart-item-counts").val();var l="0.00";f=f-1;$("#dkp-cart-item-counts").val(f);if(f!=0){$("#dkp-cart-item-"+b).remove();$("#totalOrder_Amt").val(e);if(($("#certificateExist").val()!="")&&($("#certificateExist").val()=="1")){var k=$("#certificateAmount").val();var j=e-k;var m=j;var d="0.00";if(j<0){l=e;j="0.00"}if(m>=0){l=k}e=e-k;e=roundNumber(e,2);if(e<0){var g=-(e);g=roundNumber(g,2);$("#giftCertificateRemainingAmount").val(g);e="0.00"}else{$("#giftCertificateRemainingAmount").val("0.00")}}$("#giftAppliedAmount").val(l);$("#giftcertificatetd").html("Gift Certificate ($"+k+")");$("#equaltoid").html("=");$("#appliedtd").html("-$"+roundNumber(l,2));$("#orderTotalAfterCertificateDiscount").val(e);document.getElementById("tdNetAmt").innerHTML="$"+e;var h=getCartItems();getCartCountItems()}else{window.location.href="/shopping/cart/"}}})}}function editItem(e,d,b,a,c){window.location.href="/design/"+e.replace(" ","+")+"/"+d+"/"+b+"/"+a+"/"+c}function IsNumeric(c){var a="0123456789";var d;var b=true;if(c.length==0){return false}for(i=0;i<c.length&&b==true;i++){d=c.charAt(i);if(a.indexOf(d)==-1){b=false}}return b}function continueshop(a){if(a!=""){window.location.href="/home/?pid="+a}else{window.location.href="/home"}}function mycallbackform(b,a,c){if(b=="Success"){$.prompt.close();window.location.href="/shopping/cart/billing-shipping"}}function checkout(g,r,m,l,j,f){var a=$("#dkp-cart-item-initialcounts").val();var h=0;var b=0;for(var e=1;e<=a;e++){if($("#tdShopping-1")){if($("#selectProductShop"+e).val()==""||$("#selectColorShop"+e).val()==""||$("#selectSizeShop"+e).val()==""){h=1;break}}}for(var e=1;e<=a;e++){if($("#tdShopping-1")){if($("#txtSpecialItem"+e).val()=="0"){b=1}}}if(h==1||b==0){if(b==0){$.prompt("Please purchase atleast one item before checkout.")}else{$.prompt("Please complete the Product customization for all the Items")}}else{if(($("#certificateExist").val()!="")&&($("#certificateExist").val()=="1")){var c=$("#orderTotalAfterCertificateDiscount").val();var k=$("#giftCertificateRemainingAmount").val();var q=$("#totalOrder_Amt").val();var o=$("#giftAppliedAmount").val();var n=$("#certificateAmount").val();var p=$("#giftCertificateId").val();if(k>0){k=roundNumber(k,2);var d="You have $"+k+" remaining on your Gift Certificate! You can SHOP MORE to use the remaining balance or continue to checkout and place your order (your remaining gift certificate balance will be forfeited).";$.prompt(d,{buttons:{"Shop More":"1","Continue to Checkout":"2"},callback:function(t,s,u){if((t!=0)&&(t!=undefined)&&(t=="1")){location.href="/home/"}else{if(t=="2"){$.ajax({type:"POST",url:"/shopping/createGiFtCertificateSessionForOrder",data:"orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o,success:function(v){if(g=="s"){if(l!==""){if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}}else{if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/"}}}else{if(l!==""){if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}}else{if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping/"}}}}})}else{if(t==undefined){}}}}})}else{$.ajax({type:"POST",url:"/shopping/createGiFtCertificateSessionForOrder",data:"orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o,success:function(s){if(g=="s"){if(l!==""){if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}}else{if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/"}}}else{if(l!==""){if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&orderTotal="+c+"&giftRemainingAmount="+k+"&totalOrderAmount="+q+"&giftAppliedAmount="+o+"&certificateAmount="+n+"&giftCertificateId="+p}}else{if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping/"}}}}})}}else{$.ajax({type:"GET",url:"/shopping/checkCouponCode",data:"CouponCode="+$("#txtCouponCode").val(),success:function(s){$("#tdvalidate").html("");if(s=="1"){if(g=="s"){if(l!==""){if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&nid=1"}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&nid=1"}}else{if(f!=""){window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="https://www.donkeyts.com/shopping/cart/billing-shipping/"}}}else{if(l!==""){if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&pid="+f+"&nid=1"}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping?id="+m+"&id1="+l+"&cid="+j+"&nid=1"}}else{if(f!=""){window.location.href="http://"+r+"/shopping/cart/billing-shipping/?pid="+f}else{window.location.href="http://"+r+"/shopping/cart/billing-shipping/"}}}}else{if(s=="min error"){$.prompt("Minimum purchase amount to use this coupon not reached! Do you still want to continue?",{callback:mycallbackform,buttons:{Continue:"Success",Cancel:"Failure"}})}else{$.prompt(s)}}}})}}}function roundNumber(e,d){var j;d=Number(d);if(d<1){j=(Math.round(e)).toString()}else{var f=e.toString();if(f.lastIndexOf(".")==-1){f+="."}var c=f.lastIndexOf(".")+d;var b=Number(f.substring(c,c+1));var a=Number(f.substring(c+1,c+2));if(a>=5){if(b==9&&c>0){while(c>0&&(b==9||isNaN(b))){if(b!="."){c-=1;b=Number(f.substring(c,c+1))}else{c-=1}}}b+=1}if(b==10){f=f.substring(0,f.lastIndexOf("."));var k=Number(f)+1;j=k.toString()+"."}else{j=f.substring(0,c)+b.toString()}}if(j.lastIndexOf(".")==-1){j+="."}var h=(j.substring(j.lastIndexOf(".")+1)).length;for(var g=0;g<d-h;g++){j+="0"}return j}function loadPopUp(h){var f=$("#totalOrder_Amt").val();var e=$("#dkp-cart-item-initialcounts").val();var g=0;var b=0;for(var c=1;c<=e;c++){if($("#tdShopping-1")){if($("#selectProductShop"+c).val()==""||$("#selectColorShop"+c).val()==""||$("#selectSizeShop"+c).val()==""){g=1;break}}}for(var c=1;c<=e;c++){if($("#tdShopping-1")){if($("#txtSpecialItem"+c).val()=="0"){b=1}}}if(g==1||b==0){if(b==0){$.prompt("Please purchase atleast one item before checkout.")}else{$.prompt("Please complete the Product customization for all the Items")}}else{if($("#txtCouponCode").val()!=""){try{loaded=$("#hid_loaded1").val();var a='Click ok to use a gift certificate or cancel to return to the shopping cart page and use your coupon code. <input type="hidden" id="userid" name="userid" value="'+h+'" /><input type="hidden" id="couponCd" name="couponCd" value="'+$("#txtCouponCode").val()+'" />';$.prompt(a,{buttons:{Ok:"1",Cancel:false},callback:function(l,j,o){if((l!=0)&&(l!=undefined)){var k=o.userid;if(k&&loaded==1){$("#txtCouponCode").val("");k=k+"&totalAmt="+f;tb_show(null,k,false)}return false}else{if(l==undefined){}else{var n=o.couponCd;$("#txtCouponCode").val(n)}}}})}catch(d){return false}}else{try{loaded=$("#hid_loaded1").val();if(h&&loaded==1){$("#txtCouponCode").val("");h=h+"&totalAmt="+f;tb_show(null,h,false)}}catch(d){return false}}}}function removePopUp(){$("#txtCouponCode").attr("disabled","");tb_remove()}function getCertificateDetails(){var a=$("#giftcertificate_num").val();var b=$("#total_amt").val();var c="0.00";if(a!=""){$.ajax({type:"POST",url:"/shopping/getCertificateDetails",data:"certificateNumber="+a,success:function(h){if(h=="Not Found"){$("#errmsg").html("Gift certificate number is not valid. Please provide correct gift certificate number or <a href='/learn/contact-us/?subject=5'>contact us</a> for this.")}else{$("#errmsg").html("");var g=h.split(",");var f=b-g[1];var e=f;var d="0.00";if(f<0){c=b;d=d-(f);d=roundNumber(d,2);$("#giftCertificateRemainingAmount").val(d);f="0.00"}if(e>=0){c=g[1]}$.ajax({type:"POST",url:"/shopping/createSessionForGiFtCertificate",data:"remainingAmount="+d+"&certificateId="+g[0]+"&totalAmount="+b+"&certificateAmount="+g[1]+"&giftAppliedAmount="+c,success:function(j){f=roundNumber(f,2);$("#txtCouponCode").val("");$("#cerificateId").css("display","none");$("#cerificateDeleteId").css("display","block");$("#tdNetAmt").html("$"+f);$("#certificateExist").val("1");$("#certificateAmount").val(g[1]);$("#giftAppliedAmount").val(c);$("#orderTotalAfterCertificateDiscount").val(f);$("#giftcertificatetd").css("display","");$("#giftcertificatetd").html("Gift Certificate ($"+g[1]+")");$("#equaltoid").css("display","");$("#appliedtd").css("display","");$("#equaltoid").html("=");$("#appliedtd").html("-$"+roundNumber(c,2));$("#coupontexttr").css("display","none");$("#coupontr").css("display","none");$("#couponCodeErr").css("display","none");location.reload()}})}}})}else{alert("Please enter gift certificate number first");return false}}function deleteCertificate(){$.prompt("Are you sure you want to cancel gift certificate discount?",{callback:confirmDelete,buttons:{Yes:"hi",No:"0"}})}function confirmDelete(b,a,c){if((b!=0)&&(b!=undefined)){$.ajax({type:"POST",url:"/shopping/removeSessionForGiFtCertificate",success:function(d){$("#coupontr").css("display","");$("#coupontexttr").css("display","");$("#certificateExist").val("");$("#certificateAmount").val("");$("#giftCertificateId").val("");$("#tdNetAmt").html("$"+$("#totalOrder_Amt").val());$("#orderTotalAfterCertificateDiscount").val($("#totalOrder_Amt").val());$("#cerificateId").css("display","block");$("#cerificateDeleteId").css("display","none");$("#txtCouponCode").css("background-color","");$("#txtCouponCode").attr("disabled","");$("#giftCertificateRemainingAmount").val("");$("#giftAppliedAmount").val("");$("#giftcertificatetd").html("");$("#giftcertificatetd").css("display","none");$("#equaltoid").css("display","none");$("#appliedtd").css("display","none");$("#txtCouponCode").val($("#cccode").val());$("#couponCodeErr").css("display","");location.reload()}})}}function searchKeyPress(a){if(window.event){a=window.event}if(a.keyCode==13){getCertificateDetails()}};
