var siteurl = 'http://www.aramcoffee.com/index.php';var wait=""; var para=""; var delall =""; var frmcheckout = false; var loadcomplete = false; $(document).ready(function () { loadcomplete = true; StoreRequest('mo=showcart','1stshowcart'); }); function StoreRequest(url,p,postform) { if(loadcomplete){ _StoreRequest(url,p,postform); }else{ //dialogStore("prompt", "dialogWait"); } } function _StoreRequest(requesturl, para, postform) { if(postform){postpara = createQuery(postform);}else{postpara="";} if(para!="1stshowcart"){ wait = true; dialogStore("WaitModal", "dialogWait"); }else{ wait = false; para= "showcart"; } $.ajax({ type: "POST", url: siteurl + "?store_ajax=true&" + requesturl, data: postpara, success: function(response){ alertContents(response,para); }, error: function(){ dialogStore("prompt", "dialogError"); } }); } function alertContents(response,para){ if(wait==true){ dialogStore("close", "dialogWait"); wait = false; } if (para=="showcart"){ cart_scroll(); $('#butshowcart').hide(); $('#div'+para).html(response); if($('#divnewbody').css("display")=="block"){ StoreRequest("mo=checkout","checkout"); } }else if(para=="addcart") { $('.popupWrapper').slideDown(); // for ravaknegar //dialogStore("prompt", response); }else if(para=="delcart") { dialogStore("prompt", response); }else if(para=="checkout") { $('#divbody').hide(); $('#divnewbody').show(); $('#divnewbody').html(response); }else if(para=="submitcheckout") { if(response=="dialogError"){ dialogStore("prompt", response); $('#divbody').show(); $('#divnewbody').hide(); }else{ $('#divnewbody').html(response); StoreRequest('mo=showcart','submitcheckoutok'); } }else if(para=="submitcheckoutcard") { if(response=="dialogError"){ dialogStore("prompt", response); $('#divbody').show(); $('#divnewbody').hide(); }else{ if(response.substring(0,8) == '//script'){ eval(response); }else{ $('#divnewbody').html(response); } } }else if(para=="submitcheckoutok") { $('#butshowcart').hide(); $('#divshowcart').html(response); }else if(para=="") { $('#divnewbody').show(); $('#divnewbody').html(response); } if((para=="addcart" || para=="delcart") && !wait){ StoreRequest("mo=showcart","showcart"); } } function dialogStore(type, divid){ //if($.browser.msie){ // $("body").css("overflow-x", "hidden"); // $("body").css("overflow-y", "scroll"); //} var w = $('#'+divid).attr("width"); var h = $('#'+divid).attr("height"); if(!w){w='300';} if(!h){h='150';} if(type=="close"){ $('#'+divid).dialog("close"); }else if(type=="WaitModal"){ $('#'+divid).dialog({modal: true,closeOnEscape: false, width: w, height: h}); return false; }else if(type=="prompt"){ $('#'+divid).dialog({modal: true, width: w, height: h, buttons: { "OK": function() { $(this).dialog("close"); } }}); return false; } } function StoreDelete(divid,pid){ //if($.browser.msie){ // $("body").css("overflow-x", "hidden"); // $("body").css("overflow-y", "scroll"); //} var re = false; var w = $('#'+divid).attr("width"); var h = $('#'+divid).attr("height"); if(!w){w='300';} if(!h){h='150';} $('#'+divid).dialog({ resizable: false, width:w, height:h, modal: true, buttons: { "Delete": function() { StoreRequest('mo=delcart&pid=' + pid,'delcart',frmcheckout); $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } } }); } function createQuery(form){ var elements = form.elements; var pairs = new Array(); for (var i = 0; i < elements.length; i++) { if ((name = elements[i].name) && (value = elements[i].value)) pairs.push(name + "=" + encodeURIComponent(value)); } return pairs.join("&"); } function cart_scroll(){ var e = $('#cart_scroll'); if(e.length!=1) e = $('#cart_sidebar_scroll'); $('body,html').animate({ scrollTop: e.position().top - 100 }, 500 ); // for ravaknegar }