/* --------------------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------ COMPONENTE --------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
function JSObj_remember_pwd()
{
	this.posId = 1;
	this.compId = 1;
	this.lngId = 'es';
	this.varname = '';
	this.pageId;
	this.idAtt;	// atributo principal
	this.moreAttsValues; // atributos secundarios
	this.useEvent = 'cms_user_remember_pwd';

	// Envía el recordar contraseña
	this.save = function () {
		var bOK = false;
		var sOkResult, sErrResult;
		var oAjax = new WBE_AjaxClass();
		var oFormValidator = new WBEFormValidator();
		
		if (!oFormValidator.validateForm(document.forms[0], this.posId)) return;

		this.hideOkMsg();
		this.hideNOkMsg();
		this.hideNOkConfirmMsg();
		this.showSavingMsg();
		this.hideForm();

		oAjax.clear();
		oAjax.addPostParameter('pos_id', this.posId);
		if (this.idAtt==null || this.idAtt=='') {
			alert('No hay atributo principal de envío.')
			return;
		}
		obj = document.getElementById(this.idAtt + "_" + this.posId);
		if (obj==null) {
			alert('No existe el campo de atributo principal')
			return;
		}
		oAjax.addPostParameter(this.idAtt + '_val', obj.value);

		// Valores secundarios
		if (this.moreAttsValues!=null && this.moreAttsValues!='') {
			var asAtts = this.moreAttsValues.split(',');
			for (i=0;i<asAtts.length;i++) {
				if (asAtts[i]=='') continue;
				obj = document.getElementById(asAtts[i] + "_" + this.posId);
				if (obj!=null) {
					oAjax.addPostParameter(asAtts[i] + '_value', obj.value);
				}
			}
		}
		
		var result = false;

		var xmlObj = oAjax.throwEventXML(this.useEvent);
		if (xmlObj){
			var status = oAjax.getXMLNodeValue(xmlObj, 's');
			if (status==0)
			{
			 this.showOkMsg();
			 result = true;
			}
			else
			{
			 this.showNOkMsg();
			}
		}
		else{
			this.showNOkMsg();
		}
		
		this.hideSavingMsg();	
		
		if (!result)	
		{
	  	     this.showForm();
		}
	
		return result;
	};


	this.showForm = function () {
		var oDiv = document.getElementById('remember_pwd_form_' + this.posId);
		if (oDiv) oDiv.style.display = '';
	};

	this.hideForm = function () {
		var oDiv = document.getElementById('remember_pwd_form_' + this.posId);
		if (oDiv) oDiv.style.display = 'none';
	};

	this.showOkMsg = function () {
		var oDiv = document.getElementById('message_ok_' + this.posId);
		if (oDiv) oDiv.style.display = '';
	};

	this.hideOkMsg = function () {
		var oDiv = document.getElementById('message_ok_' + this.posId);
		if (oDiv) oDiv.style.display = 'none';
	};

	this.showNOkMsg = function () {
		var oDiv = document.getElementById('message_nok_' + this.posId);
		if (oDiv) oDiv.style.display = '';
	};

	this.hideNOkMsg = function () {
		var oDiv = document.getElementById('message_nok_' + this.posId);
		if (oDiv) oDiv.style.display = 'none';
	};

	this.showNOkConfirmMsg = function () {
		var oDiv = document.getElementById('message_nok_confirm_' + this.posId);
		if (oDiv) oDiv.style.display = '';
	};

	this.hideNOkConfirmMsg = function () {
		var oDiv = document.getElementById('message_nok_confirm_' + this.posId);
		if (oDiv) oDiv.style.display = 'none';
	};

	this.showSavingMsg = function () {
		var oDiv = document.getElementById('message_saving_' + this.posId);
		if (oDiv) oDiv.style.display = '';
	};

	this.hideSavingMsg = function () {
		var oDiv = document.getElementById('message_saving_' + this.posId);
		if (oDiv) oDiv.style.display = 'none';
	};
};

/* --------------------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
/* ------------------------------------------ EDICIÓN DEL COMPONENTE --------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------------------- */
function JSObj_remember_pwd_edit()
{
	this.posId = 1;
	this.compId = 1;
	this.parentPosId = 1;
	this.varName = '';
	this.lngId = 'es';

	this.save = function() {
		this.hideSelectBoxes();
		
		var objConfig = new WBEConfigMgr();
		objConfig.posId = this.posId;
		objConfig.compId = this.compId;
		objConfig.cache_delete_prefix = '|wbe.xsl/remember_pwd.' + this.posId + '|';
	
		objConfig.saveConfig();
		
		var objReloader = new WbePositionReloader();
		objReloader.posId = this.parentPosId;
		objReloader.reload();
		
		this.displaySelectBoxes();
		window.parent.___wbeADMIN.hidePopUp();
	};
/*
	this.saveConfig = function () {
		eval('document.forms[0].codes_' + this.posId).value = this.configCodes;
		this.saveConf();
	};
*/

	// Oculta todos los campos de formulario SELECT por el problema que tiene el IE. (como en el back azul)
	this.hideSelectBoxes = function () {
		for(var i = 0; i < document.forms.length; i++) {
			for(var e = 0; e < document.forms[i].length; e++){
				if(document.forms[i].elements[e].tagName == "SELECT")
					document.forms[i].elements[e].style.visibility="hidden";
			} // for e
		} // for i

	};

	// Muestra todos los campos de formulario SELECT por el problema que tiene el IE. (como en el back azul)
	this.displaySelectBoxes = function () {
		for(var i = 0; i < document.forms.length; i++) {
			for(var e = 0; e < document.forms[i].length; e++){
				if(document.forms[i].elements[e].tagName == "SELECT")
					document.forms[i].elements[e].style.visibility="visible";
			} // for e
		} // for i
	};

};