var DutyCalculationProductInterface=Class.create();
DutyCalculationProductInterface.prototype={initialize:function(a){this.acceptorId=a.acceptor;this.listenerId=a.listen;this.url=a.url;this.containerId=a.containerId;this.itemsFieldId=a.itemsField?a.itemsField:"";this.countryField=a.countryField?a.countryField:"dtc_country_to";this.url_param=a.url_param?a.url_param:"subcategory";this.is_sub=a.issub?a.issub:false;this.ajaxLoadingEffect=null;(trigger=a.start_on_load?a.start_on_load:false)?Event.observe(document,"dom:loaded",this.setCatchers.bindAsEventListener(this)):
this.setCatchers()},setCatchers:function(){Event.observe($(this.listenerId),"change",this.onChangeSelect.bindAsEventListener(this))},onChangeSelect:function(){if($(this.listenerId).value==0){$(this.acceptorId).disabled="disabled";$(this.acceptorId).value=0}else{if(this.ajaxLoadingEffect!=null)if(Prototype.Browser.IE){this.ajaxLoadingEffect.removeLoadingEffect();this.ajaxLoadingEffect=null}this.ajaxLoadingEffect=new AjaxLoadingEffect({containerId:this.containerId});this.ajaxLoadingEffect.setLoadingEffect();
productCategoryPattern=/dtc_product_category([0-9])*$/;if(this.listenerId.match(productCategoryPattern)){postfix=this.listenerId.substr(20);$("dtc_product_item"+postfix).value="";$("dtc_product_item"+postfix).disabled="disabled"}new Ajax.Request(this.url+this.url_param+"/"+this.acceptorId+"/"+$(this.listenerId).value+"/"+$(this.countryField).value+"/",{onSuccess:this.successLoading.bind(this)})}},successLoading:function(a){responceText=a.responseText;Element.replace($(this.acceptorId),responceText);
this.is_sub||new DutyCalculationProductInterface({acceptor:this.itemsFieldId,listen:this.acceptorId,url:this.url,containerId:this.containerId,issub:true,url_param:"items"});this.ajaxLoadingEffect!=null&&this.ajaxLoadingEffect.removeLoadingEffect()}};var DutyCalculationCountriesInterface=Class.create();
DutyCalculationCountriesInterface.prototype={initialize:function(a){this.sekoAdAllow=false;this.countryToFieldId=a.import_to_field;this.countryFromFieldId=a.import_from_field;this.url=a.url;this.ajaxLoadingEffect=null;this.containerId=a.containerId;this.categoryFieldId=a.categoryField;this.subCategoryFieldId=a.subCategoryField;this.itemsFieldId=a.itemsField;this.hCurrencies=a.countryCurrencies;this.currencyField=a.currencyField;(a.already_loaded?a.already_loaded:false)?this.setCatchers():Event.observe(document,
"dom:loaded",this.setCatchers.bind(this))},setCatchers:function(){this.bfx=this.onChangeSelect.bind(this);Event.observe($(this.countryToFieldId),"change",this.bfx);Event.observe($(this.countryFromFieldId),"change",this._showhideGetQuoteBtn.bind(this));Event.observe($("dtc_shipping_cost"),"change",this._checkShippingCostValue.bind(this));Event.observe($("dtc_shipping_cost_currency"),"change",this._checkShippingCostValue.bind(this));this._showhideGetQuoteBtn()},onChangeSelect:function(){if($(this.categoryFieldId)==
null)Event.stopObserving($(this.countryToFieldId),"change",this.bfx);else{if($(this.countryToFieldId).value==0){$(this.categoryFieldId).disabled="disabled";this.disabledInputs()}else{this.ajaxLoadingEffect!=null&&Prototype.Browser.IE&&this.ajaxLoadingEffect.removeLoadingEffect();this.ajaxLoadingEffect=new AjaxLoadingEffect({containerId:this.containerId});this.disabledInputs();this.ajaxLoadingEffect.setLoadingEffect();new Ajax.Request(this.url+"country_to/"+this.categoryFieldId+"/"+$(this.countryToFieldId).value+
"/",{onSuccess:this.successLoading.bind(this)})}this._showhideGetQuoteBtn()}},_checkShippingCostValue:function(){var a=aAllCurrencies[$("dtc_shipping_cost_currency").value]?aAllCurrencies[$("dtc_shipping_cost_currency").value]:0;this.sekoAdAllow&&a&&parseFloat($("dtc_shipping_cost").value)/a>=500?$("get_seko").show():$("get_seko").hide()},_showhideGetQuoteBtn:function(){var a=$(this.countryFromFieldId).value;if(a==objAllCountries.USA&&BboxCountries[$(this.countryToFieldId).value]){$("shipping_cost_error")&&
$("shipping_cost_error").hide();$("insurance_cost_error")&&$("insurance_cost_error").hide();$("get_shipping_estimate_btn")&&$("get_shipping_estimate_btn").show()}else{$("shipping_cost_error")&&$("shipping_cost_error").show();$("insurance_cost_error")&&$("insurance_cost_error").show();$("get_shipping_estimate_btn")&&$("get_shipping_estimate_btn").hide()}if((a==objAllCountries.CHN||a==objAllCountries.HKG||a==objAllCountries.IND||a==objAllCountries.ARE||a==objAllCountries.THA)&&$(this.countryToFieldId).value==
objAllCountries.GBR){this.sekoAdAllow=true;this._checkShippingCostValue(null)}else this.sekoAdAllow=false},_setDefaultCurrency:function(){if($(this.countryFromFieldId).value&&$(this.currencyField))$(this.currencyField).value=this.hCurrencies.get($(this.countryFromFieldId).value)},successLoading:function(a){$(this.categoryFieldId).disabled="";a=a.responseText;Element.replace($(this.categoryFieldId),a);new DutyCalculationProductInterface({acceptor:this.subCategoryFieldId,listen:this.categoryFieldId,
url:this.url,containerId:this.containerId,itemsField:this.itemsFieldId,countryField:this.countryToFieldId});this.ajaxLoadingEffect!=null&&this.ajaxLoadingEffect.removeLoadingEffect()},disabledInputs:function(){$(this.subCategoryFieldId).disabled="disabled";$(this.itemsFieldId).disabled="disabled";$(this.categoryFieldId).value="";$(this.subCategoryFieldId).value="";$(this.itemsFieldId).value=""}};var DutyAddProduct=Class.create();
DutyAddProduct.prototype={initialize:function(a){this.url=a.url;this.maxProduct=a.maxProducts;this.containerId=a.containerId;this.categoryFieldId=a.categoryField;this.subCategoryFieldId=a.subCategoryField;this.itemsFieldId=a.itemsField;this.countryFieldId=a.countryFieldId;this.countryFromField=a.importFromFieldId;this.currencyFieldId=a.currencyFieldId;this.lastBlockId=a.lastBlockId;this.addButtonId=a.addButtonId;this.etalonBlock=a.etalonBlockId;this.productNamesHash=new Hash;this.lastIndex=a.lastIndex?
a.lastIndex:1;this.lastBlockId=this.etalonBlock;this.beforeBlock=a.before_block;this.hCurrency=a.currenciesList;Event.observe(document,"dom:loaded",this.setCathers.bindAsEventListener(this))},setCathers:function(){$(this.addButtonId).onclick=function(){return false};Event.observe($(this.addButtonId),"click",this.createNewProductForm.bind(this));for(var a=$$('a[rel="delete_product"]'),c=0;c<a.length;c++){a[c].onclick=function(){return false};Event.observe(a[c],"click",this.deleteProduct.bindAsEventListener(this))}},
createNewProductForm:function(){var a=$(this.etalonBlock),c=document.createElement("div");c.className=a.className;a=a.innerHTML;Insertion.Before($(this.beforeBlock),c);c.style.display="none";c.innerHTML=a;var b=c.getElementsByTagName("input");this.lastIndex++;for(a=0;a<b.length;a++)b[a].id=b[a].name=b[a].id+this.lastIndex;b=c.getElementsByTagName("select");for(a=0;a<b.length;a++){if(b[a].id==this.subCategoryFieldId||b[a].id==this.itemsFieldId)b[a].disabled="disabled";b[a].id=b[a].name=b[a].id+this.lastIndex;
$(b[a].id).selectedIndex=""}new DutyCalculationCountriesInterface({import_to_field:this.countryFieldId,import_from_field:this.countryFromField,url:this.url,containerId:this.containerId+this.lastIndex,categoryField:this.categoryFieldId+this.lastIndex,subCategoryField:this.subCategoryFieldId+this.lastIndex,itemsField:this.itemsFieldId+this.lastIndex,currencyField:this.currencyFieldId+this.lastIndex,countryCurrencies:this.hCurrency,already_loaded:true});$(this.currencyFieldId+this.lastIndex).value=this.hCurrency.get($(this.countryFromField).value)?
this.hCurrency.get($(this.countryFromField).value):defaultCurrencyId;$("dtc_product_name"+this.lastIndex).value=exampleBrandName;$("dtc_product_value"+this.lastIndex).value="";$(this.countryFieldId).value&&new DutyCalculationProductInterface({acceptor:this.subCategoryFieldId+this.lastIndex,listen:this.categoryFieldId+this.lastIndex,url:this.url,containerId:this.containerId+this.lastIndex,itemsField:this.itemsFieldId+this.lastIndex});b=c.getElementsByTagName("label");for(a=0;a<b.length;a++){var e=
b[a].getAttribute("for");e!=null&&typeof e!="undefined"&&b[a].setAttribute("for",e+this.lastIndex)}c.id=this.etalonBlock+this.lastIndex;this.productNamesHash.set(this.lastIndex,this.etalonBlock+this.lastIndex);c.style.display="";$(this.etalonBlock).getElementsByClassName("HeadLine")[0].style.display="";$(this.etalonBlock+this.lastIndex).getElementsByClassName("HeadLine")[0].style.display="";$("topSeparLine").hide();this.setKeysToInput(this.getAllProductObjectsId());this.getAllProductObjectsId().length==
this.maxProduct-1&&$(this.addButtonId).hide();a=c.getElementsByTagName("span");for(b=0;b<a.length;b++)a[b].className=="IcoForm InfIco"&&objTooltips.setCatcher(a[b]);a=Element.down($(c.id),'img[alt="Close"]').up("a");a.show();if(a){a.onclick=function(){return false};Event.observe(a,"click",this.deleteProduct.bindAsEventListener(this))}if(Prototype.Browser.IE){c=c.getElementsByTagName("a");for(a=0;a<c.length;a++)c[a].rel=="showWindow"&&new WindowModal(c[a])}else{c=c.down('a[rel="showWindow"]');new WindowModal(c)}this._setProductEnumeration()},
_setBBoxValueChangeCatcher:function(){return true},deleteProduct:function(a){a=Event.findElement(a,"a").up(2);var c=a.id;Element.remove(a);if(c!=this.etalonBlock)var b=c.sub(this.etalonBlock,"",1);this.productNamesHash.unset(b);this.setKeysToInput(this.getAllProductObjectsId());this.getAllProductObjectsId().length<this.maxProduct-1&&$(this.addButtonId).show();if(this.getAllProductObjectsId().length==0){$(this.etalonBlock).down('div[class="HeadLine"]').hide();$("topSeparLine").show()}this._setProductEnumeration()},
getAllProductObjectsId:function(){return this.productNamesHash.keys()},setKeysToInput:function(a){var c="";for(i=0;i<a.length;i++){if(c!="")c+=",";c+=a[i]}$("product_keys").value=c},_setProductEnumeration:function(){Prototype.Browser.IE?this._setProductEnumerationIE():this._setNums($$('span[class="productNumber"]'))},_setProductEnumerationIE:function(){for(var a=document.getElementsByTagName("span"),c=[],b=0;b<a.length;b++)if(a[b].className=="productNumber")c[c.length]=a[b];this._setNums(c)},_setNums:function(a){for(var c=
0;c<a.length;c++)a[c].innerHTML=c+1},_createBBoxFields:function(){}};var SelectBoxEnabling=Class.create();SelectBoxEnabling.prototype={initialize:function(a){this.formName=a.formName;Event.observe(document,"dom:loaded",this.enableSelects.bindAsEventListener(this))},enableSelects:function(){for(var a=$(this.formName).getElementsByTagName("select"),c=0;c<a.length;c++)if(a[c].options.length>1)a[c].disabled=""}};
function showBBoxPopup(){$("bbox_estimate").getElementsBySelector('p[class="bbox_cnt"]');$("hiddens_container").innerHTML="";$("hiddens_container").style.fontSize="1.2em";var a=[],c=$$("div.GreyBox");for(i=0;i<c.length;i++)if(c[i].id.match(/product_block/,""))a[a.length]=c[i];c=false;for(var b="",e="",f=0;f<a.length;f++){var d=a[f].id.replace(/product_block/,""),h=d!=""?d:"1",g="dtc_product_category"+d,j="dtc_product_category_sub"+d,k="dtc_product_item"+d,m="dtc_product_value"+d,l="dtc_value_currency"+
d;d=_checkforErrors(g,j,k,m,l);if(!d.length&&!c){_appendHiddenFields(g,j,k,m,l,h);if(a.length>1)b+="<i>Item No. "+parseInt(f+1)+"</i><br />";b+='<span class="bbox_info"><strong>Product Name</strong>: '+$(g).options[$(g).selectedIndex].text;b+="<br /><strong>Product subcategory</strong>: "+$(j).options[$(j).selectedIndex].text;b+="<br /><strong>Product</strong>: "+$(k).options[$(k).selectedIndex].text;b+="<br /><strong>Product value</strong>: "+$(m).value+" "+$(l).options[$(l).selectedIndex].text;
b+="<br /></span>"}else{c||(c=true);if(d.length){h="";if(a.length>1)h=" for Item No. "+parseInt(f+1);for(g=0;g<d.length;g++)e+='<span class="ErrorTextPopup">'+d[g]+h+"</span><br />";e+="<br />"}}}if(c)b=e;Insertion.Bottom($("hiddens_container"),b);_createPopupLayer("bboxPopup",c)}
function _checkforErrors(a,c,b,e,f){var d=[];$(a).value||(d[d.length]="Please select Product Category");$(c).value||(d[d.length]="Please select Product subcategory");$(b).value||(d[d.length]="Please select product");val=parseFloat($(e).value);if(isNaN(val))d[d.length]="Please provide Product Value";$(f).value||(d[d.length]="Please select currency of the product value");return d}
function _appendHiddenFields(a,c,b,e,f,d){Element.append("hiddens_container","input",{type:"hidden",name:"package_1_item_category_"+d,id:"package_1_item_category_"+d,value:$(a).value},"");Element.append($("hiddens_container"),"input",{type:"hidden",name:"package_1_item_subcategory_"+d,id:"package_1_item_subcategory_"+d,value:$(c).value},"");Element.append($("hiddens_container"),"input",{type:"hidden",name:"package_1_item_product_"+d,id:"package_1_item_product_"+d,value:$(b).value},"");Element.append($("hiddens_container"),
"input",{type:"hidden",name:"package_1_item_price_"+d,id:"package_1_item_price_"+d,value:$(e).value},"");Element.append($("hiddens_container"),"input",{type:"hidden",name:"package_1_item_currency_"+d,id:"package_1_item_currency_"+d,value:$(f).value},"")}
function _createPopupLayer(a,c){var b=$("overlay");if(!b){b=document.createElement("div");b.id="overlay";document.getElementsByTagName("body")[0].appendChild(b)}b.style.display="block";var e=$("window");if(!e){e=document.createElement("div");e.id="window";document.getElementsByTagName("body")[0].appendChild(e)}e.style.display="block";e.className="done";b=document.createElement("div");b.id="lbContent";e.appendChild(b);var f=Utils.getViewportWidth();e=Utils.getViewportHeight();f=parseInt(f/2);parseInt(e/
2);e=document.createElement("div");e.id="win-form";e.style.visibility="visible";e.style.left=f-170+"px";e.style.top="100px";b.appendChild(e);b=document.createElement("div");b.className="inner";e.appendChild(b);if($("popup-invalid-inputs")&&$("bbox-add-inputs"))if(c){$("popup-invalid-inputs").show();$("bbox-add-inputs").hide()}else{$("popup-valid-inputs").show();$("bbox-add-inputs").show()}if(Prototype.Browser.IE)b.innerHTML=$(a).innerHTML;else b.appendChild($(a).down(0))}
function getUrlParamsForSekoSynergy(){var a="?",c=[],b=$$("div.GreyBox");for(i=0;i<b.length;i++)if(b[i].id.match(/product_block/,""))c[c.length]=b[i];for(b=0;b<c.length;b++){var e=c[b].id.replace(/product_block/,""),f="dtc_product_category_sub"+e,d="dtc_product_item"+e,h="dtc_product_value"+e,g="dtc_value_currency"+e;a+="category"+b+"="+$("dtc_product_category"+e).value+"&";a+="sub"+b+"="+$(f).value+"&";a+="item"+b+"="+$(d).value+"&";a+="value"+b+"="+$(h).value+"&";a+="currency"+b+"="+$(g).value+
"&";product_descr=$("dtc_product_name"+e).value==exampleBrandName?"":$("dtc_product_name"+e).value;a+="description"+b+"="+product_descr+"&"}a+="prod_count="+c.length;a+="&from="+$("dtc_country_from").value;a+="&to="+$("dtc_country_to").value;a+="&shipping_cost="+$("dtc_shipping_cost").value;a+="&shipping_currency="+$("dtc_shipping_cost_currency").value;return a}
function _destroyPopupLayer(a){$(a).innerHTML=$("win-form").down("div.inner").innerHTML;$("overlay").style.display="";Element.remove($("window").down(0));$("window").className="loading";$("window").style.display="";if($("popup-invalid-inputs")&&$("bbox-add-inputs")){$("popup-invalid-inputs").hide();$("popup-valid-inputs").hide()}};
