var pb_modules=Class.create({});var ProductList=Class.create({print:function(){var a=$("productListContainer");var b=$("productType");new Ajax.Request(system.getLibraryPath()+"catalog/_product_list.php",{method:"post",parameters:{command:"printProductList",style:system.getCurrentStyle(),productType:b.value},onSuccess:function(c){a.innerHTML=c.responseText;system.getMessageManager().hideMessage()}})}});var productList=new ProductList();var TagInputManager=Class.create({getKey:function(a){a=(window.event)?event:a;return(a.keyCode)?a.keyCode:a.charCode}});var tagInputManager=new TagInputManager();var TagManager=Class.create({addTagString:function(b){var a=$("createTagForm").serialize(true);a.command="addTagString";a.style=system.getCurrentStyle();new Ajax.Request(system.getLibraryPath()+"catalog/_tag_manager.php",{method:"post",parameters:a,onSuccess:function(c){if(c.responseText=="OK"){tagManager.reloadTagList();$(b).value="";$(b).focus()}}})},reloadTagList:function(){new Ajax.Request(system.getLibraryPath()+"catalog/_tag_manager.php",{method:"post",parameters:{command:"reloadTagList",style:system.getCurrentStyle()},onSuccess:function(a){$("tagListContainer").innerHTML=a.responseText}})},deleteSelected:function(){var a=$("tagList");if(a.value){new Ajax.Request(system.getLibraryPath()+"catalog/_tag_manager.php",{method:"post",parameters:{command:"deleteSelected",style:system.getCurrentStyle(),tagId:a.value},onSuccess:function(b){tagManager.reloadTagList()}})}},checkDeleteButton:function(){var b=$("tagList");if(b.value){var a=$("deleteTagButton");a.disabled=false}else{a.disabled=true}}});var tagManager=new TagManager();var ItemManager=Class.create({addAndCreateTag:function(a,b){new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"addAndCreateTag",style:system.getCurrentStyle(),tagName:$(a).value,itemId:b},onSuccess:function(c){if(c.responseText=="OK"){itemManager.reloadTagList()}}})},addTag:function(a,b){new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"addTag",style:system.getCurrentStyle(),tagId:$(a).value,itemId:b},onSuccess:function(c){if(c.responseText=="OK"){itemManager.reloadTagList()}}})},removeTag:function(){new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"removeTag",style:system.getCurrentStyle(),tagId:$("tagList").value},onSuccess:function(a){if(a.responseText=="OK"){itemManager.reloadTagList()}}})},reloadTagList:function(){var a=$("products").value;if(a){new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"reloadTagList",style:system.getCurrentStyle(),itemId:a},onSuccess:function(b){$("tagListContainer").innerHTML=b.responseText}})}},loadTypeList:function(){var a=$("productTypeListContainer");new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"printProductTypeList",style:system.getCurrentStyle()},onSuccess:function(b){a.innerHTML=b.responseText}})},loadProductList:function(b,d){var a=$("productListContainer");var c=$("productType");if(!b){b=c.value}new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"printProductList",style:system.getCurrentStyle(),typeId:b,itemId:d},onSuccess:function(e){a.innerHTML=e.responseText;itemManager.loadProduct();system.getMessageManager().hideMessage()}})},loadProduct:function(){var a=$("productContainer");var b=$("products");new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"loadProduct",style:system.getCurrentStyle(),productId:b.value},onSuccess:function(c){a.innerHTML=c.responseText;system.evalAllScripts("productContainer")}})},addProduct:function(){var a=$("productType").value;if(a){parent.pb.core.activityMonitor.addTask(new pb_core_Task("adding_product",pb.core.localizedString.get("Adding Product")));new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"addProduct",style:system.getCurrentStyle(),typeId:a},onSuccess:function(b){if(b.responseText!="OK"){system.getMessageManager().showMessage(b.responseText,{color:"red"})}else{itemManager.loadProductList(a)}},onComplete:function(){parent.pb.core.activityMonitor.endTask("adding_product")}})}},removeSelected:function(){var b=$("products").value;var a=$("productType").value;if(b){parent.pb.core.activityMonitor.addTask(new pb_core_Task("removing_product",pb.core.localizedString.get("Removing Product")));new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"removeProduct",itemId:b},onSuccess:function(c){if(c.responseText!="OK"){system.getMessageManager().showMessage(c.responseText,{color:"red"})}else{itemManager.loadProductList(a);itemManager.redrawTrash()}},onComplete:function(){parent.pb.core.activityMonitor.endTask("removing_product")}})}},duplicateSelected:function(){var b=$("products").value;var a=$("productType").value;if(b){parent.pb.core.activityMonitor.addTask(new pb_core_Task("duplicating_product",pb.core.localizedString.get("Duplicating Product")));new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"duplicate",itemId:b},onSuccess:function(c){if(c.responseText!="OK"){system.getMessageManager().showMessage(c.responseText,{color:"red"})}else{itemManager.loadProductList(a);itemManager.redrawTrash()}},onComplete:function(){parent.pb.core.activityMonitor.endTask("duplicating_product")}})}},saveChanges:function(c,a){var b=$(c).serialize(true);b.command="saveProduct";b.style=system.getCurrentStyle();parent.pb.core.activityMonitor.addTask(new pb_core_Task("saving_product",pb.core.localizedString.get("Saving Product Changes")));new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:b,onSuccess:function(d){if(d.responseText=="OK"){itemManager.loadProductList(a,$(c).itemId.value);system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(d.responseText,{color:"red"})}},onComplete:function(){parent.pb.core.activityMonitor.endTask("saving_product")}})},redrawTrash:function(){new Ajax.Request(system.getLibraryPath()+"catalog/_item_manager.php",{method:"post",parameters:{command:"redrawTrash",style:system.getCurrentStyle()},onSuccess:function(a){$("trashContainer").innerHTML=a.responseText}})}});var itemManager=new ItemManager();var ProductTypeManager=Class.create({loadFieldsAsList:function(a,b){parent.pb.core.activityMonitor.addTask(new pb_core_Task("show_fields",pb.core.localizedString.get("Show Fields"),false));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"showFields",style:system.getCurrentStyle(),typeId:a},onSuccess:function(c){$(b).innerHTML=c.responseText;system.getMessageManager().hideMessage();parent.pb.core.activityMonitor.endTask("show_fields")}})},createProductType:function(b){var a=$(b).serialize(true);a.command="createProductType";parent.pb.core.activityMonitor.addTask(new pb_core_Task("create_type",pb.core.localizedString.get("Create Type")));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:a,onSuccess:function(c){parent.pb.core.activityMonitor.endTask("create_type");if(c.responseText=="OK"){new Page(system.getLibraryPath()+"catalog/_product_type_manager.php",{command:"printPage",style:system.getLibraryPath()},"pageContainer");system.getPopUp().close()}}})},saveProductType:function(b){var a=$(b).serialize(true);a.command="saveProductType";parent.pb.core.activityMonitor.addTask(new pb_core_Task("save_type",pb.core.localizedString.get("Save type")));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:a,onSuccess:function(c){parent.pb.core.activityMonitor.endTask("save_type");if(c.responseText=="OK"){new Page(system.getLibraryPath()+"catalog/_product_type_manager.php",{command:"printPage",style:system.getLibraryPath()},"pageContainer");system.getPopUp().close()}}})},printAddFieldForm:function(a){system.getPopUp().setContent("Loading form...");system.getPopUp().setContentWithURL("_product_type_manager.php",{command:"printAddFieldForm",style:system.getCurrentStyle(),typeId:a});system.getPopUp().open();system.getMessageManager().hideMessage()},printEditFieldForm:function(a){system.getPopUp().setContent("Loading form...");system.getPopUp().setContentWithURL("_product_type_manager.php",{command:"printEditFieldForm",style:system.getCurrentStyle(),fieldId:a});system.getPopUp().open();system.getMessageManager().hideMessage()},addField:function(c,a){var b=$(c).serialize(true);b.command="addField";new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:b,onSuccess:function(d){if(d.responseText=="OK"){productTypeManager.loadFieldsAsList(a,"fieldListContainer");system.getMessageManager().hideMessage();system.getPopUp().close()}else{system.getMessageManager().showMessage(d.responseText,{color:"red"})}}})},editField:function(c,a){var b=$(c).serialize(true);b.command="editField";new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:b,onSuccess:function(d){if(d.responseText=="OK"){productTypeManager.loadFieldsAsList(a,"fieldListContainer");system.getMessageManager().hideMessage();system.getPopUp().close()}else{system.getMessageManager().showMessage(d.responseText,{color:"red"})}}})},deleteField:function(a,b,c){parent.pb.core.activityMonitor.addTask(new pb_core_Task("delete_field",pb.core.localizedString.get("Deleting Field")));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"deleteField",fieldId:a,fieldName:c},onSuccess:function(d){parent.pb.core.activityMonitor.endTask("delete_field");if(d.responseText=="OK"){productTypeManager.loadFieldsAsList(b,"fieldListContainer");system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(d.responseText,{color:"red"})}}})},moveFieldUp:function(a,b){parent.pb.core.activityMonitor.addTask(new pb_core_Task("moving_up",pb.core.localizedString.get("Moving Field Up")));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"moveFieldUp",fieldId:a},onSuccess:function(c){parent.pb.core.activityMonitor.endTask("moving_up");if(c.responseText=="OK"){productTypeManager.loadFieldsAsList(b,"fieldListContainer");system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(c.responseText,{color:"red"})}}})},moveFieldDown:function(a,b){parent.pb.core.activityMonitor.addTask(new pb_core_Task("moving_down",pb.core.localizedString.get("Moving Field Down")));new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"moveFieldDown",fieldId:a},onSuccess:function(c){parent.pb.core.activityMonitor.endTask("moving_down");if(c.responseText=="OK"){productTypeManager.loadFieldsAsList(b,"fieldListContainer");system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(c.responseText,{color:"red"})}}})},loadFieldTypes:function(b,c){var a=$(b).value;new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"loadFieldTypes",style:system.getCurrentStyle(),fieldDestination:a},onSuccess:function(d){$(c).innerHTML=d.responseText;productTypeManager.loadValidValuesHelp("fieldType","allowedValuesMessageContainer")}})},loadValidValuesHelp:function(b,a){value=$(b).value;new Ajax.Request(system.getLibraryPath()+"catalog/_product_type_manager.php",{method:"post",parameters:{command:"loadValidValuesHelp",style:system.getCurrentStyle(),type:value},onSuccess:function(c){$(a).innerHTML=c.responseText}})}});var productTypeManager=new ProductTypeManager();var DesignModule=Class.create({openDesigner:function(b,a,c){window.open(b,a,"toolbar=0")}});var designModule=new DesignModule();var WebsiteBasicCSS=Class.create({loadWebsite:function(c){var b="websitePropertiesContainer";var a=$(b);if(a!=0){new Ajax.Request(system.getLibraryPath()+"design/_basicCSSActions.php",{method:"post",parameters:{command:"loadWebsite",style:system.getCurrentStyle(),siteId:c},onSuccess:function(d){a.innerHTML=d.responseText;system.evalAllScripts(b)}})}else{a.innerHTML=""}}});var websiteBasicCSS=new WebsiteBasicCSS();var TemplateChooser=Class.create({loadWebsite:function(c){var b=system.getLibraryPath()+"design/_templateChooser.php";var a={command:"loadWebsite",style:system.getCurrentStyle(),siteId:c};system.getActionManager().executeAndPutResultIntoContainer(b,a,"websiteTemplateContainer",true)},setPublicationPointSite:function(b,d,a){var c="unlinkPublicationPointSite";if(a){c="linkPublicationPointSite"}new Ajax.Request(system.getLibraryPath()+"design/_templateChooser.php",{method:"post",parameters:{command:c,style:system.getCurrentStyle(),file:b,siteId:d},onSuccess:function(e){if(e.responseText){templateChooser.loadWebsite(d)}}})},saveTemplate:function(c,b,a){new Ajax.Request(system.getLibraryPath()+"design/_templateChooser.php",{method:"post",parameters:{command:"saveTemplate",style:system.getCurrentStyle(),siteId:c,filePath:b,templateName:a},onSuccess:function(d){if(d.responseText=="OK"){templateChooser.loadWebsite(c)}}})}});var templateChooser=new TemplateChooser();var BasicCSSEditor=Class.create({init:function(a){if(!hudWindowManager.getHUDWindow("cssEditorHud")){hudWindowManager.addHUDWindow("cssEditorHud",a,"350px","310px");viewportPlacer.place("cssEditorHud","right","bottom");hudWindowManager.getHUDWindow("cssEditorHud").hide()}},showEditor:function(c,b){var a=hudWindowManager.getHUDWindow("cssEditorHud");a.show();a.setContentWithURL(system.getLibraryPath()+"design/_basicCSSActions.php",{command:"showEditor",style:system.getCurrentStyle(),siteId:c,content:b})},setManageStyle:function(c,a){var b=false;if(a==1){b=true}new Ajax.Request(system.getLibraryPath()+"design/_basicCSSActions.php",{method:"post",parameters:{command:"setManageStyle",style:system.getCurrentStyle(),siteId:c,manage:b},onSuccess:function(d){if(d.responseText=="OK"){websiteBasicCSS.loadWebsite(c)}else{alert(d.responseText)}}})}});var basicCSSEditor=new BasicCSSEditor();var PageContainer=Class.create({topResizer:null,middleResizer:null,bottomResizer:null,loadWebSite:function(a,b){new Ajax.Request(system.getLibraryPath()+"design/_pageContainer.php",{method:"post",parameters:{command:"loadWebSite",style:system.getCurrentStyle(),siteId:b},onSuccess:function(c){$(a).innerHTML=c.responseText;system.evalAllScripts(a)}})},setManageStyle:function(c,a){var b=false;if(a==1){b=true}new Ajax.Request(system.getLibraryPath()+"design/_pageContainer.php",{method:"post",parameters:{command:"setManageStyle",style:system.getCurrentStyle(),siteId:c,manage:b},onSuccess:function(d){$("pageContainerEditor").innerHTML=d.responseText;system.evalAllScripts("pageContainerEditor")}})}});var pageContainer=new PageContainer();var PageDesignerModule=Class.create({loadSectionList:function(a){new Ajax.Request(system.getLibraryPath()+"design/_pageDesigner.php",{method:"post",parameters:{command:"loadSectionList",style:system.getCurrentStyle(),siteId:a},onSuccess:function(b){$("sectionContainer").innerHTML=b.responseText;system.evalAllScripts("sectionContainer")}})},loadPageList:function(a){new Ajax.Request(system.getLibraryPath()+"design/_pageDesigner.php",{method:"post",parameters:{command:"loadPageList",style:system.getCurrentStyle(),sectionId:a},onSuccess:function(b){$("pageListContainer").innerHTML=b.responseText;pageDesigner.loadPage(0);system.evalAllScripts("pageListContainer")}})},loadPage:function(a){new Ajax.Request(system.getLibraryPath()+"design/_pageDesigner.php",{method:"post",parameters:{command:"loadPage",style:system.getCurrentStyle(),pageId:a},onSuccess:function(b){$("pageDesignerContainer").innerHTML=b.responseText;system.evalAllScripts("pageDesignerContainer")}})},openDesigner:function(b,a,c){}});var pageDesignerModule=new PageDesignerModule();var WebsiteDesigner=Class.create({loadWebsite:function(a){new Ajax.Request(system.getLibraryPath()+"design/_websiteDesigner.php",{method:"post",parameters:{command:"loadWebsite",style:system.getCurrentStyle(),siteId:a},onSuccess:function(b){$("websiteContainer").innerHTML=b.responseText;system.evalAllScripts("websiteContainer")}})},saveContainerProperties:function(b,c){var a=$(c).serialize(true);a.command="saveContainerProperties";a.style=system.getCurrentStyle();a.siteId=b;new Ajax.Request(system.getLibraryPath()+"design/_websiteDesigner.php",{method:"post",parameters:a,onSuccess:function(d){if(d.responseText!="OK"){alert(d.responseText)}}})}});var websiteDesigner=new WebsiteDesigner();var ConfigurationManager=Class.create({saveData:function(c,b,a){new Ajax.Request(system.getLibraryPath()+"ecommerce/_general_configuration.php",{method:"post",parameters:c,onSuccess:function(d){if(d.responseText=="OK"){b.innerHTML="";a.hide()}else{b.innerHTML=d.responseText}}})},saveFiscalData:function(){var c=$("fiscalDataForm").serialize(true);var b=$("fiscalDataResultContainer");var a=$("fiscalDataWarning");c.command="saveFiscalData";c.style=system.getCurrentStyle();this.saveData(c,b,a)},notifyFiscalDataChange:function(){var a=$("fiscalDataWarning");a.show()},savePostalAddress:function(){var c=$("postalAddressForm").serialize(true);var b=$("postalAddressResultContainer");var a=$("postalAddressWarning");c.command="savePostalAddress";c.style=system.getCurrentStyle();this.saveData(c,b,a)},notifyPostalAddressChange:function(){var a=$("postalAddressWarning");a.show()},saveContactData:function(){var c=$("contactDataForm").serialize(true);var b=$("contactDataResultContainer");var a=$("contactDataWarning");c.command="saveContactData";c.style=system.getCurrentStyle();this.saveData(c,b,a)},notifyContactDataChange:function(){var a=$("contactDataWarning");a.show()},saveGeneralConfig:function(){var c=$("moduleConfigForm").serialize(true);var b=$("moduleConfigResultContainer");var a=$("moduleConfigWarning");c.command="saveGeneralConfig";c.style=system.getCurrentStyle();this.saveData(c,b,a)},notifyGeneralConfigChange:function(){var a=$("moduleConfigWarning");a.show()},saveWebPageConfig:function(){var c=$("moduleWebsiteConfigForm").serialize(true);var b=$("moduleWebsiteConfigResultContainer");var a=$("moduleWebsiteConfigWarning");c.command="saveWebsiteConfig";c.style=system.getCurrentStyle();this.saveData(c,b,a)},notifyWebPageConfigChanged:function(){var a=$("moduleWebsiteConfigWarning");a.show()}});var configManager=new ConfigurationManager();var PubPointChooser=Class.create({loadWebsite:function(c){var b=system.getLibraryPath()+"settings/_publish_points.php";var a={command:"loadWebsite",style:system.getCurrentStyle(),siteId:c};system.getActionManager().executeAndPutResultIntoContainer(b,a,"websiteTemplateContainer",true)},setPublicationPointSite:function(b,d,a){var c="unlinkPublicationPointSite";if(a){c="linkPublicationPointSite"}new Ajax.Request(system.getLibraryPath()+"settings/_publish_points.php",{method:"post",parameters:{command:c,style:system.getCurrentStyle(),file:b,siteId:d},onSuccess:function(e){if(e.responseText){pubPointChooser.loadWebsite(d)}}})},saveTemplate:function(c,b,a){new Ajax.Request(system.getLibraryPath()+"settings/_publish_points.php",{method:"post",parameters:{command:"saveTemplate",style:system.getCurrentStyle(),filePath:b,templateName:a},onSuccess:function(d){if(d.responseText=="OK"){pubPointChooser.loadWebsite(c)}}})}});var pubPointChooser=new PubPointChooser();var TemplateChooser=Class.create({loadWebsite:function(c){var b=system.getLibraryPath()+"settings/_design.php";var a={command:"loadWebsite",style:system.getCurrentStyle(),siteId:c};system.getActionManager().executeAndPutResultIntoContainer(b,a,"websiteTemplateContainer",true)},saveTemplate:function(c,b,a){new Ajax.Request(system.getLibraryPath()+"settings/_design.php",{method:"post",parameters:{command:"saveTemplate",style:system.getCurrentStyle(),filePath:b,templateName:a,siteId:c},onSuccess:function(d){if(d.responseText=="OK"){templateChooser.loadWebsite(c)}}})}});var Backup=Class.create({makeBackup:function(){parent.pb.core.activityMonitor.addTask(new pb_core_Task("making_backup",pb.core.localizedString.get("Making Backup")));new Ajax.Request(system.getLibraryPath()+"settings/_backup.php",{method:"post",parameters:{command:"makeBackup"},onSuccess:function(b){parent.pb.core.activityMonitor.endTask("making_backup");if(b.responseText!="ERROR"){var a=system.getDownloaderUrl()+"?file="+b.responseText+"&path=backups";window.location.href=a}else{$("backupErrorField").appear()}}})}});var FriendlyUrl=Class.create({reloadContainer:function(){var a=$("friendlyUrlContainer");if(a){parent.pb.core.activityMonitor.addTask(new pb_core_Task("reloading_friendly_url",pb.core.localizedString.get("Reloading friendly URL list")));new Ajax.Request(system.getLibraryPath()+"settings/_friendly_url.php",{method:"post",parameters:{command:"printFriendlyUrlList"},onSuccess:function(b){parent.pb.core.activityMonitor.endTask("reloading_friendly_url");a.innerHTML=b.responseText}})}},addName:function(){var c=$("newFriendlyURL").value;var b=$("pageToUse").value;var a=$("friendlyUrlContainer");if(a){parent.pb.core.activityMonitor.addTask(new pb_core_Task("adding_friendly_url",pb.core.localizedString.get("Adding new friendly URL")));new Ajax.Request(system.getLibraryPath()+"settings/_friendly_url.php",{method:"post",parameters:{command:"addUrl",urlName:c,pageId:b},onSuccess:function(d){parent.pb.core.activityMonitor.endTask("adding_friendly_url");a.innerHTML=d.responseText}})}},removeName:function(b){var a=$("friendlyUrlContainer");if(a){parent.pb.core.activityMonitor.addTask(new pb_core_Task("removing_friendly_url",pb.core.localizedString.get("Adding new friendly URL")));new Ajax.Request(system.getLibraryPath()+"settings/_friendly_url.php",{method:"post",parameters:{command:"removeUrl",urlName:b},onSuccess:function(c){parent.pb.core.activityMonitor.endTask("removing_friendly_url");a.innerHTML=c.responseText}})}}});var templateChooser=new TemplateChooser();var backup=new Backup();var friendlyUrl=new FriendlyUrl();var TemplateMaker=Class.create({actionFile:"",composerActionFile:"",initialize:function(){document.observe("ws:css_changed",function(a){if(a.memo.fieldId=="spaceGenerator"){$("backgroundImage").style.width=$("spaceGenerator").style.width;$("backgroundImage").style.height=$("spaceGenerator").style.height;$("templateContent").style.width=$("spaceGenerator").style.width;$("templateContent").style.width=$("spaceGenerator").style.width}})},create:function(){var a=$("createTemplateForm").serialize(true);a.command="doCreateTemplate";new Ajax.Request(this.getActionFile(),{method:"post",parameters:a,onSuccess:function(b){if(b.responseText=="OK"){system.getPopUp().close();new Page(templateMaker.getActionFile(),{command:"printPage",style:system.getCurrentStyle},"pageContainer");system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(b.responseText,{color:"red"})}}})},edit:function(a){var b=$("editTemplateForm").serialize(true);b.command="doEditTemplate";b.templateId=a;new Ajax.Request(this.getActionFile(),{method:"post",parameters:b,onSuccess:function(c){if(c.responseText=="OK"){system.getPopUp().close();new Page(templateMaker.getActionFile(),{command:"printPage",style:system.getCurrentStyle},"pageContainer");system.getMessageManager().hideMessage()}else{system.getMessageManager().showMessage(c.responseText,{color:"red"})}}})},changeStyle:function(a){var b=hudWindowManager.getHUDWindow("editBlock");if(!b){hudWindowManager.addHUDWindow("editBlock",localizedString.get("Properties"),"400px","","350px");b=hudWindowManager.getHUDWindow("editBlock");b.setPosition("fixed");b.setLeftPos("860px");b.setTopPos("100px")}b.show();b.setContentWithURL(system.getLibraryPath()+"templatemaker/_template_composer.php",{command:"changeStyle",style:system.getCurrentStyle(),templateId:a})},saveTemplateProperties:function(a){var b=$("templatePropertiesForm").serialize(true);b.command="saveTemplateProperties";b.templateId=a;new Ajax.Request(this.getTemplateComposerFile(),{method:"post",parameters:b,onSuccess:function(c){if(c.responseText=="OK"){templateMaker.reloadTemplateContainer(a)}else{alert(c.responseText)}}})},reloadTemplateContainer:function(b,a){var c={command:"reloadTemplateContainer",style:system.getCurrentStyle(),templateId:b};new Ajax.Request(this.getTemplateComposerFile(),{method:"post",parameters:c,onSuccess:function(d){$("templateEditorContainer").innerHTML=d.responseText;system.evalAllScripts("templateEditorContainer");if(a){blockEditor.selectLastBlock()}}})},getActionFile:function(){if(this.actionFile==""){this.actionFile=system.getLibraryPath()+"templatemaker/_index.php"}return this.actionFile},getTemplateComposerFile:function(){if(this.composerActionFile==""){this.composerActionFile=system.getLibraryPath()+"templatemaker/_template_composer.php"}return this.composerActionFile}});var templateMaker=new TemplateMaker();var BlockEditor=Class.create({actionFile:"",currentBlockId:0,prevMouseX:0,prevMouseY:0,selectedBlock:null,lastBlockId:null,getSelectedBlock:function(){return this.selectedBlock},addBlock:function(a){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"createNewBlock",templateId:a},onSuccess:function(b){if(b.responseText=="OK"){templateMaker.reloadTemplateContainer(a,true)}}})},startDrag:function(b,a){this.currentBlockId=a;this.prevMouseX=b.pageX;this.prevMouseY=b.pageY;this.selectedBlock=$("template_block_"+a)},drag:function(e,c){if(this.currentBlockId!=0){var f=$("template_block_"+c);var d=f.positionedOffset().left;var b=f.positionedOffset().top;var a=this.prevMouseX-e.pageX;var g=this.prevMouseY-e.pageY;this.prevMouseX=e.pageX;this.prevMouseY=e.pageY;d=(d-a)+"px";b=(b-g)+"px";f.setStyle({left:d,top:b})}},stopDrag:function(b,a){this.updateResizer(b,a);var d=$("template_block_"+a);if(d){var e=d.positionedOffset().left;var c=d.positionedOffset().top;new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"saveBlockPosition",blockId:a,posX:e,posY:c},onSuccess:function(f){if(f.responseText!="OK"){alert(f.responseText)}}})}this.currentBlockId=0},updateResizer:function(d,f){var h=$("template_block_"+f);var g=$("template_block_resize_"+f);if(h&&g){var c=h.positionedOffset().left;var b=h.positionedOffset().top;var e=parseInt(h.style.width);var i=parseInt(h.style.height);var a=e+c-16;var j=i+b-16;g.style.left=(a)+"px";g.style.top=(j)+"px"}this.currentBlockId=0},updateBlockSize:function(e,b){var g=$("template_block_"+b);var d=$("template_block_resize_"+b);if(g&&d){var h=g.positionedOffset().left;var f=g.positionedOffset().top;var c=d.positionedOffset().left;var a=d.positionedOffset().top;g.style.width=(c-h+16)+"px";g.style.height=(a-f+16)+"px";this.updateResizer(e,b)}this.currentBlockId=0},updateSize:function(c,e){var g=$("template_block_"+e);var f=$("template_block_resize_"+e);if(g&&f){var b=g.positionedOffset().left;var a=g.positionedOffset().top;var j=f.positionedOffset().left;var i=f.positionedOffset().top;var d=j-b+16;var h=i-a+16;this.updateResizer(c,e);new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"saveBlockSize",blockId:e,width:d,height:h},onSuccess:function(k){if(k.responseText!="OK"){alert(k.responseText)}}})}this.currentBlockId=0},changeRowOrder:function(c,a){var b=$("template_block_roworder_"+c);b.innerHTML=a;var d=new Object();d.command="saveBlockChanges";d.blockId=c;d.rowOrder=a;new Ajax.Request(this.getActionFile(),{method:"post",parameters:d,onSuccess:function(e){if(e.responseText=="OK"){}else{system.getMessageManager().showMessage(e.responseText,{color:"red"})}}})},editBlock:function(a){var b=hudWindowManager.getHUDWindow("editBlock");if(!b){hudWindowManager.addHUDWindow("editBlock",localizedString.get("Properties"),"450px","","350px");b=hudWindowManager.getHUDWindow("editBlock");b.setPosition("fixed");b.setLeftPos("860px");b.setTopPos("100px")}b.show();b.setContentWithURL(this.getActionFile(),{command:"editBlockForm",style:system.getCurrentStyle(),blockId:a})},saveBlockChanges:function(a,b){var c=$("editBlockForm").serialize(true);c.command="saveBlockChanges";c.blockId=a;new Ajax.Request(this.getActionFile(),{method:"post",parameters:c,onSuccess:function(d){if(d.responseText=="OK"){system.getPopUp().close();system.getMessageManager().hideMessage();templateMaker.reloadTemplateContainer(b)}else{system.getMessageManager().showMessage(d.responseText,{color:"red"})}}})},deleteBlock:function(a,b){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"deleteBlock",style:system.getCurrentStyle(),blockId:a},onSuccess:function(c){if(c.responseText=="OK"){system.getPopUp().close();system.getMessageManager().hideMessage();templateMaker.reloadTemplateContainer(b)}else{system.getMessageManager().showMessage(c.responseText,{color:"red"})}}})},getActionFile:function(){if(this.actionFile==""){this.actionFile=system.getLibraryPath()+"templatemaker/_template_composer.php"}return this.actionFile},registerClickEvent:function(a,c){$(a).observe("click",function(d){blockEditor.select(a);d.stop()});var b=new Object();b.cssId=c;pb.core.itemInfoManager.add("template_block",b,a);this.lastBlockId=a},clearSelection:function(){if(this.propertiesRequest){this.propertiesRequest.abort()}var a=hudWindowManager.getHUDWindow("info");if(a){a.showNothingSelected()}if(resizerManager.getResizer(this.currentResizer)){resizerManager.removeResizer(this.currentResizer)}if(resizerManager.getResizer(this.selectedBlockId)){resizerManager.removeResizer(this.selectedBlockId)}this.selectedBlockId=null},select:function(a){if(this.selectedBlockId==a){return}this.clearSelection();if(!a){return}this.selectedBlockId=a;this.loadResizer(a);this.editBlock(a.substr(15))},selectLastBlock:function(){if(this.lastBlockId){this.select(this.lastBlockId)}},loadResizer:function(a){var d=resizerManager.getResizer(a);if(!d&&$(a)){resizerManager.addResizer(a);var d=resizerManager.getResizer(a);d.minWidth=1;d.minHeight=1;d.showHandles();var c=pb.core.itemInfoManager.get("template_block",a);var b=a.substr(15);d.endDragCallback=function(){blockEditor.updateSize(null,b);document.fire("ws:css_changed",{fieldId:a,cssId:c.cssId})};d.resizeCallback=function(){document.fire("ws:css_changed",{fieldId:a,cssId:c.cssId})};if($(a).style.display=="none"){d.hideHandles()}}},adjustFields:function(){var b=$("backgroundImage");var c=parseInt(b.style.width)||0;var n=parseInt(b.style.height)||0;c=c;n=n;var a=b.select(".templateBlock");for(var g=0;g<a.length;g++){var l=parseInt(a[g].style.top)||0;var f=parseInt(a[g].style.left)||0;var m=parseInt(a[g].style.width)||0;var j=parseInt(a[g].style.height)||0;if(l<0){l=0}if(f<0){f=0}if((f+m)>c){f=c-m;if(f<0){f=0;m=c-f}}if((l+j)>n){l=n-j;if(l<0){l=0;j=n-l}}a[g].style.left=f+"px";a[g].style.top=l+"px";a[g].style.width=m+"px";a[g].style.height=j+"px";var k="template_block_";var e=new String(a[g].id);var d=e.substring(k.length);this.updateResizer(null,d);new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"saveBlockPosition",blockId:d,posX:f,posY:l,width:m,height:j},onSuccess:function(h){if(h.responseText!="OK"){alert(h.responseText)}}});this.currentBlockId=0}}});var blockEditor=new BlockEditor();var SiteLayoutEditor=new Class.create({reloadURLList:function(){new Ajax.Request(system.getLibraryPath()+"web/_siteLayout.php",{method:"post",parameters:{command:"reloadURLList",style:system.getCurrentStyle()},onSuccess:function(a){$("websiteList").innerHTML=a.responseText}})},saveSiteConfig:function(){var a=$("sitePreferences").serialize(true);a.command="saveSiteConfig";a.style=system.getCurrentStyle();new Ajax.Request(system.getLibraryPath()+"web/_siteLayout.php",{method:"post",parameters:a,onSuccess:function(b){if(b.responseText=="OK"){web.getLayoutEditor().reloadURLList()}else{system.getMessageManager().show(b.responseText,{color:"red"})}}})}});var ACLPageSelector=new Class.create({actionFile:"",getTypeWithTableName:function(a){switch(a){case"web_site":return"site";case"web_section":return"section";case"web_page":return"page"}},addUser:function(b,d){var a=$("denyUserList").value;var c=this.getTypeWithTableName(b);if(a){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"addUser",tableName:b,id:d,userId:a},onSuccess:function(e){web.getACLPageSelector().showACL(c,d)}})}},removeUser:function(b,d){var a=$("grantUserList").value;var c=this.getTypeWithTableName(b);if(a){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"removeUser",tableName:b,id:d,userId:a},onSuccess:function(e){web.getACLPageSelector().showACL(c,d)}})}},addGroup:function(a,d){var c=$("denyGroupList").value;var b=this.getTypeWithTableName(a);if(c){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"addGroup",tableName:a,id:d,groupId:c},onSuccess:function(e){web.getACLPageSelector().showACL(b,d)}})}},removeGroup:function(a,d){var c=$("grantGroupList").value;var b=this.getTypeWithTableName(a);if(c){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"removeGroup",tableName:a,id:d,groupId:c},onSuccess:function(e){web.getACLPageSelector().showACL(b,d)}})}},changeAccessType:function(c,d){var b=$("access_type").value;var a=this.getActionFile();new Ajax.Request(a,{method:"post",parameters:{command:"changeAccessType",newType:b,itemType:c,id:d},onSuccess:function(e){new Ajax.Request(a,{method:"post",parameters:{command:"printACL",style:system.getCurrentStyle(),type:c,id:d},onSuccess:function(f){$("aclContainer").innerHTML=f.responseText;switch(c){case"site":web.getACLPageSelector().reloadSiteList();break;case"section":web.getACLPageSelector().reloadSectionList();break;case"page":web.getACLPageSelector().reloadPageList();break}}})}})},showACL:function(a,b){new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"printACL",style:system.getCurrentStyle(),type:a,id:b},onSuccess:function(c){$("aclContainer").innerHTML=c.responseText}})},reloadSiteList:function(){var b="ACLPageSelectorSiteContainer";var a="ACLPageSelectorSectionContainer";var c="ACLPageSelectorPageContainer";new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"loadSiteList"},onSuccess:function(d){$(b).innerHTML=d.responseText;$(a).innerHTML='<select id="ACLPageSelectorSection" size="7" onchange="" style="width:100%;"></select>';$(c).innerHTML='<select id="ACLPageSelectorPage" size="7" onchange="" style="width:100%;"></select>'}})},reloadSectionList:function(){var a="ACLPageSelectorSectionContainer";var b="ACLPageSelectorPageContainer";var c=$("ACLPageSelectorSite").value;new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"loadSectionList",siteId:c},onSuccess:function(d){$(a).innerHTML=d.responseText;$(b).innerHTML='<select id="ACLPageSelectorPage" size="7" onchange="" style="width:100%;"></select>'}})},reloadPageList:function(){var a=$("ACLPageSelectorSection").value;new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"loadPageList",sectionId:a},onSuccess:function(b){$("ACLPageSelectorPageContainer").innerHTML=b.responseText}})},onSiteSelected:function(){var a="ACLPageSelectorSectionContainer";var b="ACLPageSelectorPageContainer";var c=$("ACLPageSelectorSite").value;new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"loadSectionList",siteId:c},onSuccess:function(d){$(a).innerHTML=d.responseText;$(b).innerHTML='<select id="ACLPageSelectorPage" size="7" onchange="" style="width:100%;"></select>';web.getACLPageSelector().showACL("site",c)}})},onSectionSelected:function(){var a=$("ACLPageSelectorSection").value;new Ajax.Request(this.getActionFile(),{method:"post",parameters:{command:"loadPageList",sectionId:a},onSuccess:function(b){$("ACLPageSelectorPageContainer").innerHTML=b.responseText;web.getACLPageSelector().showACL("section",a)}})},onPageSelected:function(){var a=$("ACLPageSelectorPage").value;this.showACL("page",a)},getActionFile:function(){if(this.actionFile==""){this.actionFile=system.getLibraryPath()+"web/_accessControl.php"}return this.actionFile}});var WebModule=new Class.create({ACLPageSelector:null,layoutEditor:null,initialize:function(){this.ACLPageSelector=new ACLPageSelector();this.layoutEditor=new SiteLayoutEditor()},getACLPageSelector:function(){return this.ACLPageSelector},getLayoutEditor:function(){return this.layoutEditor}});var web=new WebModule();
