﻿function ___mostrar_capa(nombreCapa, numero_capas, nombrePestanya){
	for(i=1;i<numero_capas+1;i++){
		if (document.getElementById('capa'+i) != null)
			document.getElementById('capa'+i).style.display="none";
		if (document.getElementById('p'+i) != null)
			document.getElementById('p'+i).className="";
	}
	document.getElementById(nombreCapa).style.display="inline";
	document.getElementById(nombrePestanya).className='current';
}

// Para guardar categorias
function __modifyMerchant (obj) 
{
}

// Para guardar categorias
function __saveMerchant (obj) 
{
	obj.save();
/*	
	window.scroll(0, 0);
	obj.uploadFiles();

	if (obj.isAllUploaded()) {

		var oAjax = new WBE_AjaxClass();
		obj.getParams(oAjax);

		var oValidator = new WBEFormValidator();
		if(!oValidator.validateForm(document.forms[0], obj.posId))return false;

		// categories
		var scat_id = document.forms[0].category_ids.value;
		var i;
		if (scat_id == null || scat_id=='') {
			scat_id='';
			for (i=0;i<document.forms[0].category_ids.length;i++) {
				if (document.forms[0].category_ids[i].checked) {
					if (scat_id!=null && scat_id!="") scat_id+=",";
					scat_id +=document.forms[0].category_ids[i].value;
				}
			}
		}
		oAjax.addPostParameter("category_ids", scat_id);
		
		// categories
		obj.useEvent = "cms_content_save_merchant";
		xmlObj = oAjax.throwEventXML(obj.useEvent);
		
		document.getElementById('form_' + obj.posId).style.display = 'none';
		document.getElementById('form_ok_' + obj.posId).style.display = '';
	}
*/
}


function changedisplay(sIdName){
	var elem = document.getElementById(sIdName);
	if(elem != null){
		if(elem.style.display == 'none'){
			document.getElementById(sIdName).style.display = 'block';
		}else{
			document.getElementById(sIdName).style.display = 'none';
		}
	}
}

function displayblock(sIdName){
	var elem = document.getElementById(sIdName);
	if(elem != null){
		document.getElementById(sIdName).style.display = 'block';
	}
}

function load(sIdName){
	var sId = sIdName.split(';');
	var i;
	//alert(sIdName);
	//alert(sId.length);
	//alert(iContador);
	for(i=0;i<sId.length;i++)
	{
		//alert('sId[' + i + '] = ' + sId[i]);
		displayblock('menu'+sId[i]);
	}
}

function __saveUser(obJS) {
	var oObj;
	
	var sL1 = eval("document.forms[0].user_login_" + obJS.posId + ".value");
	var sL2 = eval("document.forms[0].user_login2_" + obJS.posId + ".value");
	var sP1 = eval("document.forms[0].user_password_" + obJS.posId + ".value");
	var sP2 = eval("document.forms[0].user_password2_" + obJS.posId + ".value");

	var oElement = eval("document.forms[0].user_login_" + obJS.posId);
	if (obJS.checkDuplicateLogin(oElement)==false){
		return;
	}
	
	if (!document.forms[0].condiciones.checked) {
		alert("Debes aceptar las condiciones de contratación.");
		return;
	}
	if (sL1!=sL2) {
		oObj = eval("document.forms[0].user_login2_" + obJS.posId);
		alert('No coinciden los emails');
		oObj.value='';
		oObj.select();
		return;
	}
	if (sP1!=sP2) {
		oObj = eval("document.forms[0].user_password2_" + obJS.posId);
		alert('La contraseña no coincide');
		oObj.value='';
		oObj.select();
		return;
	}

	//salvo sin hacer el dologin
	obJS.save();
	
	//hago el dologin y redirecciono
	var oAjax = new WBE_AjaxClass();
	var oXmlDoc;
	oAjax.clear();
	oAjax.addPostParameter("txt_login", obJS.getValue2('user_login', false));
	oAjax.addPostParameter("txt_password", obJS.getValue2('user_password', false));
	oXmlDoc = oAjax.throwEventXML("user_login");
	if (!oXmlDoc) {	alert('Error al intentar entrar.'); return;	}
	var sStatus = oAjax.getXMLNodeValue(oXmlDoc, 's');
	if (sStatus!=0) {
		var sErrorMessage = oAjax.getXMLNodeValue(oXmlDoc, 'm');
		alert(sErrorMessage);
		return;
	} else {
		window.location.href = 'inscripcion_ok.html';
	}
}

function __isFormValue(sName) {
	return (sName.indexOf('_171_')>0 || 
		sName.indexOf('_174_')>0 ||
		sName.indexOf('_175_')>0 ||
		sName.indexOf('_177_')>0 ||
		sName.indexOf('_179_')>0 ||
		sName.indexOf('_178_')>0 ||
		sName.indexOf('_180_')>0);
		

}

//Script efecto del menu superior
if ((document.all) && (document.getElementById)) {
	function MenuListElementHoverFix() {
		var _this	= this;
		
		if (typeof(Array.prototype.push) == 'undefined') {
			// IE < 5.5 does not support push/pop
			function push() {
				var j = this.length;
				for (var i = 0; i < push.arguments.length; ++i) {
					this[j] = push.arguments[i];
					j++;
				}
			}
			function pop() {
				var i = this[this.length - 1];
				this.length--;
				return i;
			}
			Array.prototype.push	= push;
			Array.prototype.pop		= pop;
		}
		
		this.className				= 'hover';	// change the class name to use here if you are not happy with it
		this.classNameSuffix		= ' ' + this.className;
		this.removeClassNameRegExp	= new RegExp("\\b ?" + this.className + "\\b");
		this.hoverElementStack		= new Array();
		
		this.onmouseover	= function() {
			if (!_this.isHover(this)) {
				if (this.getAttribute('is_hover_class_removing') != 'true') {
					this.className	+= _this.classNameSuffix;
				}
				this.setAttribute('is_hover', 'true');
			}
		}
		this.isHover	= function(element) {
			return (element.getAttribute('is_hover') == 'true');
		}
		this.checkNonHoverState	= function(element) {
			if (!_this.isHover(element)) {
				element.className	= element.className.replace(_this.removeClassNameRegExp, '');
			}
			element.removeAttribute('is_hover_class_removing');
		}
		this.checkLastNonHoverState	= function() {
			var hoverElement	= null;
			if (_this.hoverElementStack.length > 0) {
				hoverElement	= _this.hoverElementStack.pop();
			}
			for (var i = _this.hoverElementStack.length - 1; i >= 0; i--) {
				// we need to apply the "non-hover" class to the children first - else the result is mixed in the IE
				var o = _this.hoverElementStack[i];
				while (o != null) {
					o	= o.offsetParent;
					if (o == hoverElement) {
						_this.checkNonHoverState(_this.hoverElementStack[i]);
						break;
					}
				}
			}
			if (hoverElement != null) {
				_this.checkNonHoverState(hoverElement);
			}
		}
		this.onmouseout		= function() {
			// all this mess to not change the class immediately (which would cause flickering in the IE)
			this.setAttribute('is_hover', 'false');
			if (this.getAttribute('is_hover_class_removing') != 'true') {
				this.setAttribute('is_hover_class_removing', 'true');
				_this.hoverElementStack.push(this);
				window.setTimeout(_this.checkLastNonHoverState, 100);
			}
		}
		this.fixElement		= function(elementRoot) {
			for (var i=0; i < elementRoot.childNodes.length; i++) {
				var node = elementRoot.childNodes[i];
				if (node.nodeName == "LI") {
					node.onmouseover	= this.onmouseover;
					node.onmouseout		= this.onmouseout;
				}
				this.fixElement(node);
			}
		};
		this.findElement	= function(elementRoot) {
			for (var i=0; i< elementRoot.childNodes.length; i++) {
				var node = elementRoot.childNodes[i];
				if (node.nodeName == "UL") {
					if ((node.id != '') && ((node.id.indexOf("menu") >= 0) || (node.id.indexOf("nav") >= 0))) {
						this.fixElement(node);
						continue;	// do not iterate through children of already fixed element
					}
				}
				this.findElement(node);
			}
		};
		this.fix			= function() {
			var node = document.body;
			if (node) {
				_this.findElement(node);
			}
		}
		this.addOnLoad		= function() {
			if (window.attachEvent) {
				window.attachEvent("onload", this.fix);
			} else {
				window.onload	= this.fix;
			}
		}
	}
	(new MenuListElementHoverFix()).addOnLoad();
}


function __cleanMerchantDataForm(obJS, oObj) {
	document.getElementById('datos_empresa_form').style.display = 
		(oObj.selectedIndex == 0) ? '' : 'none';
/*
	var i;
	if (oObj.selectedIndex == 0) {
		document.getElementById('datos_empresa_form').style.display = '';
		for (i=0; i<document.forms[0].elements.length; i++) {
			var sName = document.forms[0].elements[i].name;
			if (__isFormValue(sName)) {
				document.forms[0].elements[i].value = '';
				document.forms[0].elements[i].delAttribute("required");
			}
		}
	} else {
		document.getElementById('datos_empresa_form').style.display = 'none';
		document.forms[0].elements[i].name.indexOf("att_")
		for (i=0; i<document.forms[0].elements.length; i++) {
			var sName = document.forms[0].elements[i].name;
			if (__isFormValue(sName)) {
				document.forms[0].elements[i].value = '';
				document.forms[0].elements[i].setAttribute("required",1);
			}
		}
	}
*/
	//obJS.user_role = (oObj.selectedIndex == 0) ? null : 4;	// Rol de asociado.
}

function __changeCountry(oCountryElem, sProvTextId, sSelected, sProvinceSelId) {
	var oGeo = new WBEGeoInfo();
	var sProvId = oCountryElem.getAttribute("target");
	var oSel = document.getElementById(sProvId);
	var oField = eval("document.forms[0]." + sProvTextId);
	__selectArray(oCountryElem.options, sSelected); // Necesario para IE
	oGeo.changeGEOElement(oCountryElem, null, sSelected);
	if (sSelected!='ES') {
		oSel.style.display = 'none';
		oField.style.display = '';
		oGeo.clearSelect(oSel);
		oField.value = (sProvinceSelId!=null) ? sProvinceSelId : '';
	} else {
		oSel.style.display = '';
		oField.style.display = 'none';
		__selectArray(oSel.options, sProvinceSelId);
		__changeProvince(oSel, sProvTextId)
	}
}

function __changeProvince(oProvinceSel, sProvTextId) {
	var oField = eval("document.forms[0]." + sProvTextId);
	oField.value = (oProvinceSel.options != null && oProvinceSel.selectedIndex>=0)
		? oProvinceSel[oProvinceSel.selectedIndex].value
		: '';
}

function __selectArray(oArray, sValue) {
	var i;
	if (sValue==null) return;
	for (i=0;i<oArray.length;i++)
		if (oArray[i].value == sValue) oArray[i].selected=true;
}

function __EditM() {
	var oElem = document.getElementById('form_enlace_pag');
	if (oElem==null) return;
	var iId = oElem.getAttribute("pid");
	var iCid = oElem.getAttribute("cpid");
	var sURL = oElem.getAttribute("url");
	var sCRes = oElem.getAttribute("cres");
	var sBackP = oElem.getAttribute("bpar");
	oElem.innerHTML = 
		"<a href='" + sURL + "?ver_id=" + iId + 
			"&content_type_id=" + iCid + "&back_link=" + sCRes + 
			"&back_params=" + sBackP+ "'>Editar los datos de mi empresa</a>";
}

function recordar() 
{
 var texto1 = document.getElementById('email');
 if (texto1.value != '')
 {
  document.location.href = 'recordatorio_correcto.html?event=usr_remember_password&user_login=' + texto1.value;
 }
}

function UrlHistoryBack(page,querystring){
	if(page=='')
	{
		history.back();
	}
	else
	{
		if(querystring == '')
			location.href=page;
		else
			location.href=page + '?' + querystring;
	}
}

var divIdToPutFirst = null ;
function PutDivInFirstPlace()
{
	var divMove = document.getElementById(divIdToPutFirst);
	var parentDiv = document.getElementById('generales_fecemd');
	if(divMove && parentDiv)
	{
		parentDiv.insertBefore(divMove, parentDiv.childNodes[1]);
	}
}

function UserMainLogin(obj) {
	obj.doOkReload = function() {
		var oAjax = new WBE_AjaxClass();
		oAjax.clear();
		oXmlDoc = oAjax.throwEventXML("fedemc_get_rof_code");
		if (!oXmlDoc) return;
		var sProfCode = oAjax.getXMLNodeValue(oXmlDoc, 'p_code');
		if (sProfCode!=null && sProfCode!='') {
			document.location.href = 'http://net.fecemd.org/8/' + sProfCode + '/0/0/0/0/0/0/0/0/0/';
		} else {
			if (this.url_ok) window.location.href = this.url_ok;	
			else window.location.reload();
		}
	};
	obj.doLogin();
}