registerTransaction=function(){if($("opc-payment")){var a=$("opc-payment").hasClassName("allow")}else{var a=false}if(Ajax.activeRequestCount>1||((a==false)&&$("opc-payment"))){return}var c=$("wait-trn-create");var b=$("sage-pay-server-iframe");b.writeAttribute({src:""});new Ajax.Request(SAGE_PAY_REG_TRN_URL,{method:"get",onSuccess:function(f){var d=f.responseText.evalJSON();var e=d.response_status;c.hide();if(e=="OK"){b.writeAttribute({src:d.next_url}).show();if($$(".col-right")[0]){new Ajax.Updater($$(".col-right")[0],SP_PROGRESS_URL,{method:"get"})}}else{if(e=="INVALID"||e=="MALFORMED"||e=="ERROR"||e=="FAIL"){if((typeof(SAGE_PAY_SERVER_UNIQUE)!="undefined")&&(SAGE_PAY_SERVER_UNIQUE==true)){b.hide()}if((a||!$("opc-payment"))){alert(Translator.translate("An error ocurred")+": \n"+d.response_status_detail)}}}},onLoading:function(){var d=$("advice-required-entry-d-sgps-hi");if(d){d.hide()}if(b.visible()){b.hide()}c.setStyle({opacity:0.5}).show()}})};function createTrn(){registerTransaction()}function DumpObjectIndented(f,c){var b="";if(c==null){c=""}for(var e in f){var d=f[e];if(typeof d=="string"){d=d}else{if(typeof d=="object"){if(d instanceof Array){d="[ "+d+" ]"}else{var a=DumpObjectIndented(d,c+"  ");d="\n"+c+"{\n"+a+"\n"+c+"}"}}}b+=c+"'"+e+"' : "+unescape(d)+",\n"}return b.replace(/,\n$/,"")}checkSagePayServerError=function(){var a=$("sage-pay-server-error");if(a.innerHTML.replace(/^\s+|\s+$/g,"")){var b=a.innerHTML.evalJSON();alert(Translator.translate(b.response_status_detail));if(b.Request){alert("REQUEST:\n"+DumpObjectIndented(b.Request));alert("RESPONSE:\n"+DumpObjectIndented(b.Response))}return false}return true};view_iframe=function(){if(checkSagePayServerError()===false){return}$("sage-pay-iframe").show();if($("checkout-agreements")){$("checkout-agreements").hide()}shPlaceOrderBlock("h")};_getPlaceBlock=function(){return $$("#checkout-step-review .button-set p")};shPlaceOrderBlock=function(b){var a=_getPlaceBlock();if((typeof(a[0])!="undefined")){if(b=="s"){a[0].show();if((typeof(a[1])!="undefined")){a[1].show()}}else{a[0].hide();if((typeof(a[1])!="undefined")){a[1].hide()}}}};continueMonitor=function(){var a=$$("#payment-buttons-container button");if((typeof(a[0])!="undefined")){a[0].stopObserving();Event.observe(a[0],"click",function(c){if($("checkout-agreements")){$("checkout-agreements").show()}var d=$("review-please-wait");if($("p_method_sagepayserver").checked===false){d.innerHTML=d.innerHTML.replace(SGPS_vtwo,SGPS_vone)}else{d.innerHTML=d.innerHTML.replace(SGPS_vone,SGPS_vtwo)}var b=_getPlaceBlock();if((typeof(b[0])!="undefined")&&!(b[0].visible())){shPlaceOrderBlock("s");if($("review-buttons-container")&&!$("review-buttons-container").visible()){$("review-buttons-container").show()}}})}};sgps_placeOrder=function(){var c=$("review-please-wait");var a="";var b=$("review-buttons-container");new Ajax.Request(SAGE_PAY_GTSPMC,{onSuccess:function(d){c.hide();a=d.responseText;if(a=="sagepayserver"||a=="sagepayserverdot"){var h=false;if(!SAGE_PAY_SERVER_ASIFRAME){var g=$$('p.agree input[type="checkbox"]');if(g.length){g.each(function(k,j){if(!k.checked){alert(Translator.translate("Please agree to all Terms and Conditions before placing the order."));h=true;return false}})}if(!b.visible()){b.show()}}if(!h){view_iframe();if($("opc-review")){$("opc-review").scrollTo();try{var e=$("opc-review").positionedOffset().top;var f=$$("div.header")[0].getStyle("height").replace("px","");if(SP_DESIGN_MODERN){f=parseInt(f)+parseInt($$("div.toplinks-bar")[0].getStyle("height").replace("px",""))+parseInt($$("div.search-bar")[0].getStyle("height").replace("px",""))+parseInt($$("div.search-bar")[0].getStyle("margin-bottom").replace("px",""));f=parseInt($$("div.middle")[0].getStyle("paddingTop").replace("px",""))+parseInt(f)+48}else{f=parseInt($$("div.middle")[0].getStyle("paddingTop").replace("px",""))+parseInt(f)}e=(e-f)+"px";$$("div.one-page-checkout-progress")[0].setStyle({marginTop:e})}catch(i){console.warn(i)}}else{if($$("div.multi-address-checkout-box div.box")[1]){$$("div.multi-address-checkout-box div.box")[1].scrollTo()}}}}else{review.save()}},onLoading:function(){if(b){b.hide()}c.setStyle({opacity:0.5}).show()}})};dstrb=function(){alert(SAGEPAY_SERVER_NV)};sagePayServerAdvance=function(){if(SAGE_PAY_SERVER_AAOS){continueMonitor();if(!SGPS_ISMS){payment.save()}else{$("multishipping-billing-form").submit()}}};sgps_uniqueHandler=function(){var a=$("p_method_sagepayserver").ancestors();if(a[0].hasClassName("no-display")){a[0].removeClassName("no-display")}if((typeof(SAGE_PAY_SERVER_UNIQUE)!="undefined")&&(SAGE_PAY_SERVER_UNIQUE==true)&&(!$("sage-pay-server-iframe").visible()||$("sage-pay-server-iframe").readAttribute("src")=="")){if($("wait-trn-create").visible()){return}registerTransaction()}};Event.observe(window,"load",function(){if((typeof(SAGE_PAY_VALID_INSTALL)!="undefined")&&(SAGE_PAY_VALID_INSTALL==false)){if(SAGE_PAY_MODE=="live"){new PeriodicalExecuter(dstrb,3)}else{var a='<ul class="messages"><li class="error-msg">'+SAGEPAY_SERVER_NV+"</li></ul>";if($("checkoutSteps")){new Insertion.Before("checkoutSteps",a)}else{var b=$$("div.multi-address-checkout-box");if(b.length>0){new Insertion.Before(b[0],a)}}}}});listenRBSagePay_bind=createTrn.bindAsEventListener();listenRBSagePayServer_bind=sagePayServerAdvance.bindAsEventListener();
