
﻿
function WbePositionReloader()
{this.posId=null;this.pageId=null;this.Ajax=new WBE_AjaxClass();this.url="VIEW_POSITION_ZONE.wbe";this.GetXmlObjAsStr=function(inXmlNode){if(inXmlNode.xml){return inXmlNode.xml;}else{if(XMLSerializer){return(new XMLSerializer()).serializeToString(inXmlNode);}}}
this.GetXmlNodeChildsAsStr=function(inXmlNode){var sOut='';for(var i=0;i<inXmlNode.childNodes.length;i++){sOut+=this.GetXmlObjAsStr(inXmlNode.childNodes[i]);}
return sOut;}
this.reload=function(){var sResult,xmlObj;if(this.pageId==null){if(window.parent!=undefined&&window.parent.___wbeADMIN!=undefined){this.pageId=window.parent.___wbeADMIN.resourceId;this.Ajax.addPostParameter("show_parent_div",1);}else if(self.___wbeADMIN){this.pageId=self.___wbeADMIN.resourceId;}}
if(this.posId==undefined){alert('No se puede recargar posición. Id de posición no definido.')
return;}
this.Ajax.addPostParameter("position_id",this.posId);if(this.pageId==undefined){alert('No se puede recargar posición. Id página no definido.')
return;}
this.Ajax.addPostParameter("parent_resource_id",this.pageId);if(this.url==undefined){alert('No se puede recargar posición. No se ha definido página destino.')
return;}
sResult=this.Ajax.throwCall(null,false,this.url);if(sResult){window.parent.document.getElementById('WBECP_'+this.posId).innerHTML=sResult;if(window.parent.document.getElementById('change_mode_chk')){if(window.parent.document.getElementById('change_mode_chk').checked){window.parent.document.getElementById('WBECP_'+this.posId).style.border="1px dashed #FF0000";window.parent.document.getElementById('menu-bar-'+this.posId).style.display='block';}}else{if(window.parent.document.getElementById('menu-bar-'+this.posId)){window.parent.document.getElementById('menu-bar-'+this.posId).style.display='none';}}}
this.Ajax.clear();};};function InmediaFormBuilder(iPosition)
{this.posId=iPosition;this.front=1;this.selectedCatIds=new Array();this.selectedParentIds=new Array();this.addSelectedCategory=function(iId){this.selectedCatIds[this.selectedCatIds.length]=iId;}
this.addParentRelation=function(iId){this.selectedParentIds[this.selectedParentIds.length]=iId;}
this.arrayContainsValue=function(a_array,iId){var i;if(a_array==null)return false;for(i=0;i<a_array.length;i++){if(a_array[i]==iId)return true;}
return false;}
this.GetCategoriesByParentId=function(iParentCat){var oAjax=new WBE_AjaxClass();if(iParentCat==null)return null;oAjax.addPostParameter("cat_id",iParentCat);var oXmlDoc=oAjax.throwEventXML('cms_get_child_categories');var sStatus=oAjax.getXMLNodeValue(oXmlDoc,'s');if(sStatus=='0'){return oXmlDoc.getElementsByTagName("c");}else{alert('Error recuperando categorías');return null;}};this.createCategoryCheckBox=function(iParentCatId,sObjectName,bMultiple){var i;var oDiv=document.getElementById(sObjectName);if(oDiv==null)return;var oNodeList=this.GetCategoriesByParentId(iParentCatId);var sOut='';for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var bContains=this.arrayContainsValue(this.selectedCatIds,iValue);var sSelected=(bContains||(!bMultiple&&this.selectedCatIds.length==0&&i==0))?'checked':'';var sType=(bMultiple)?"checkbox":"radio";sOut+="<input class='form_"+sType+"' type='"+sType+"' name='category_"+this.posId+"' value='"+
iValue+"' "+sSelected+"> "+sDesc+"<br/>";}
oDiv.innerHTML=sOut;}
this.fillCategoryCombo=function(iParentCat,sObjectID){var i;var oComboElem=document.getElementById(sObjectID);if(oComboElem==null)return;oComboElem.name="category_"+this.posId;var oNodeList=this.GetCategoriesByParentId(iParentCat);for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var opt=new Option(sDesc,iValue);opt.selected=(this.arrayContainsValue(this.selectedCatIds,iValue));oComboElem.options[oComboElem.length]=opt;}}
this.getContentListByTypeId=function(iCParentId){var oAjax=new WBE_AjaxClass();if(iCParentId==null)return null;oAjax.addPostParameter("ctype_id",iCParentId);var oXmlDoc=oAjax.throwEventXML('cms_get_content_list');var sStatus=oAjax.getXMLNodeValue(oXmlDoc,'s');if(sStatus=='0'){return oXmlDoc.getElementsByTagName("c");}else{alert('Error recuperando contenidos');return null;}}
this.getFrontContentListByTypeIdAndAtt=function(iCParentId,sAttCode){var oAjax=new WBE_AjaxClass();if(iCParentId==null)return null;oAjax.addPostParameter("front",this.front);oAjax.addPostParameter("ctype_id",iCParentId);oAjax.addPostParameter("att_code",sAttCode);var oXmlDoc=oAjax.throwEventXML('cms_get_content_list_byAtt');var sStatus=oAjax.getXMLNodeValue(oXmlDoc,'s');if(sStatus=='0'){return oXmlDoc.getElementsByTagName("c");}else{alert('Error recuperando contenidos');return null;}}
this.getFrontContentListByTypeId=function(iCParentId){var oAjax=new WBE_AjaxClass();if(iCParentId==null)return null;oAjax.addPostParameter("ctype_id",iCParentId);oAjax.addPostParameter("front",this.front);var oXmlDoc=oAjax.throwEventXML('cms_get_content_list');var sStatus=oAjax.getXMLNodeValue(oXmlDoc,'s');if(sStatus=='0'){return oXmlDoc.getElementsByTagName("c");}else{alert('Error recuperando contenidos');return null;}}
this.getContentListByTypeIdAndParents=function(iCParentId,oParentIds){var oAjax=new WBE_AjaxClass();if(iCParentId==null)return null;oAjax.addPostParameter("ctype_id",iCParentId);if(oParentIds){var sIds='';for(var i=0;i<oParentIds.length;i++){if(oParentIds[i]!='')
if(sIds.length>0)sIds+=',';sIds+=oParentIds[i];}
oAjax.addPostParameter("parent_ids",sIds);}
var oXmlDoc=oAjax.throwEventXML('cms_get_content_list');var sStatus=oAjax.getXMLNodeValue(oXmlDoc,'s');if(sStatus=='0'){return oXmlDoc.getElementsByTagName("c");}else{alert('Error recuperando contenidos');return null;}}
this.fillContentParentCombo=function(iContentTypeId,sObjectName){var i;var oComboElem=document.getElementById(sObjectName);if(oComboElem==null)return;oComboElem.name="content_parent_"+this.posId;var oNodeList=this.getContentListByTypeId(iContentTypeId);for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var opt=new Option(sDesc,iValue);opt.selected=(this.arrayContainsValue(this.selectedParentIds,iValue));oComboElem.options[oComboElem.length]=opt;}}
this.fillContentParentComboFrontByAtt=function(iContentTypeId,sAttCode,sObjectName){var i;var oComboElem=document.getElementById(sObjectName);if(oComboElem==null)return;var oNodeList=this.getFrontContentListByTypeIdAndAtt(iContentTypeId,sAttCode);for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var opt=new Option(sDesc,iValue);oComboElem.options[oComboElem.length]=opt;}
for(i=0;i<oComboElem.options.length;i++){var opt=oComboElem.options[i];if(this.arrayContainsValue(this.selectedParentIds,opt.value)){opt.selected=true;break;}}}
this.fillContentParentComboFront=function(iContentTypeId,sObjectName){var i;var oComboElem=document.getElementById(sObjectName);if(oComboElem==null)return;oComboElem.name="content_parent_"+this.posId;var oNodeList=this.getFrontContentListByTypeId(iContentTypeId);for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var opt=new Option(sDesc,iValue);oComboElem.options[oComboElem.length]=opt;}
for(i=0;i<oComboElem.options.length;i++){var opt=oComboElem.options[i];if(this.arrayContainsValue(this.selectedParentIds,opt.value)){opt.selected=true;break;}}}
this.fillContentParentComboWithParents=function(iContentTypeId,sObjectName,oParentIds){var i;var oComboElem=document.getElementById(sObjectName);if(oComboElem==null)return;oComboElem.name="content_parent_"+this.posId;var oNodeList=this.getContentListByTypeIdAndParents(iContentTypeId,oParentIds);for(i=0;i<oNodeList.length;i++){var oNode=oNodeList[i];var iValue=oNode.childNodes[0].firstChild.data;var sDesc=oNode.childNodes[1].firstChild.data;var opt=new Option(sDesc,iValue);opt.selected=(this.arrayContainsValue(this.selectedParentIds,iValue));oComboElem.options[oComboElem.length]=opt;}}
this.getFieldMultipleValues=function(sFieldName){var i,j;var scat_id='';var a_values=new Array();var oElems=document.getElementsByName(sFieldName);if(oElems==null)return scat_id;for(j=0;j<oElems.length;j++){var oElem=oElems[j];if(oElem.options){for(i=0;i<oElem.options.length;i++){if(oElem.options[i].selected){if(!this.arrayContainsValue(a_values,oElem.options[i].value)){a_values[a_values.length]=oElem.options[i].value;if(scat_id!=null&&scat_id!='')scat_id+=',';scat_id+=oElem.options[i].value;}}}}else{if(oElem.checked){if(!this.arrayContainsValue(a_values,oElem.value)){if(scat_id!=null&&scat_id!='')scat_id+=',';scat_id+=oElem.value;}}}}
return scat_id;}}
function WishListManager()
{this.addToWishList=function(sCode,sId){var bOK=false;var oAjax=new WBE_AjaxClass();oAjax.clear();oAjax.addPostParameter('wl_item_id',sId);oAjax.addPostParameter('wl_item_code',sCode);xmlObj=oAjax.throwEventXML('wish_list_add');if(xmlObj){bOK=true;}
if(!bOK)
alert('Se ha producido un error');else{document.location.reload();}};this.removeFromWishList=function(sCode,sId){var bOK=false;var oAjax=new WBE_AjaxClass();oAjax.clear();oAjax.addPostParameter('wl_item_id',sId);oAjax.addPostParameter('wl_item_code',sCode);xmlObj=oAjax.throwEventXML('wish_list_remove');if(xmlObj){bOK=true;}
if(!bOK)
alert('Se ha producido un error');else{document.location.reload();}};this.saveAndNew=function(){var bOK=false;var oAjax=new WBE_AjaxClass();oAjax.clear();xmlObj=oAjax.throwEventXML('wish_list_save_and_new');if(xmlObj){bOK=true;}
if(!bOK)
alert('Se ha producido un error');else{document.location.reload();}};}
var ___WLM=new WishListManager();