
function PressEnter(event)
{		
	//debugger
	eK=event.keyCode;
	var buscador=false;
		 		
	if (eK==13)
	{	
	
		if(event.srcElement)
		{
			if(event.srcElement.id=="txtTextoBuscar")
				buscador=true;
		}
		else
		{
			if(event.target.id=="txtTextoBuscar")
				buscador=true;
		}	
		
		if(!buscador)
		{
			if (!Validar())					
				return false
		}
		else
		{
			if(event.srcElement)
			{
				document.getElementById("imgBotonBuscador").click();
			}
			else
			{	
				var inicio = document.getElementById("imgBotonBuscador").attributes["onclick"].nodeValue.indexOf("(");
				var fin = document.getElementById("imgBotonBuscador").attributes["onclick"].nodeValue.indexOf(",");
				var idpais= document.getElementById("imgBotonBuscador").attributes["onclick"].nodeValue.substring((inicio+1),fin);
				Buscar(idpais,1); 
			}
			
			return false;
		}
	}					
	else
	{
		return true				
	}
} 	


function Validar()
{	
	var ok = true;				
	if (eval(document.getElementById("divLogin")))
	{
		if (document.getElementById("divLogin").style.display == "")
		{
			if (eval(document.getElementById("txtUsuario")))
				if (document.getElementById("txtUsuario").value=="")
				{
					alert(mensajes[0]);
					document.getElementById("txtUsuario").focus();
					ok = false;		
				}
								
			if (eval(document.getElementById("txtClave")))
				if (ok && document.getElementById("txtClave").value=="")
				{
					alert(mensajes[1]);
					document.getElementById("txtClave").focus();
					ok = false;			
				}
							
			if (ok)
			{
				dojo.io.bind({
								url: './VerificarLogin.aspx',
								sync: true,
								mimetype: "text/html",
								method: "post",
								content: {usuario: document.getElementById("txtUsuario").value, password: document.getElementById("txtClave").value},
								load: function (type, data) {
									var myObject = eval('(' + data + ')');
									if(myObject.IdPersona>0)
									{
										if(document.getElementById("paginaPopUp").value!="")
											window.open(document.getElementById("paginaPopUp").value + "?idPersona=" + myObject.IdPersona,'Huggies',',toolbar=Yes,location=Yes,scrollbars=auto,status=Yes,resizable=yes, height=' + screen.height + ', width=' + screen.width);
									}
								},
								error: function() {
								}
								});
	
				linkea('LOG');				
			}
		}						    
	}
}

function PedirContrasena()
{					
	var ok=true;
				
	if(document.getElementById("txtUsuario").value=="")
	{
		ok=false;
		alert(mensajes[0]);
		document.getElementById("txtUsuario").focus();
	}				
					
	if(ok)
		linkea('OLV');
}

function linkea(intpaso)
{
	if(document.Form1.__VIEWSTATE)
	{
		document.Form1.__VIEWSTATE.disabled=true;
	}
	if(document.Form1.__EVENTTARGET)
	{
		document.Form1.__EVENTTARGET.disabled=true;
	}
	if(document.Form1.__EVENTARGUMENT)
	{
		document.Form1.__EVENTARGUMENT.disabled=true;
	}	
	document.Form1.intPaso.value=intpaso;			
	document.Form1.submit();			
}

function NavegarEtapa(etapa, idPais, codigoPais)
{
	Navegar("./PlantillaEtapa.aspx", {idEtapa: etapa, idPais: idPais});

	switch(etapa)
	{
	case 1:
		document.Form1.imgEsperandome.src="img/common/topnav/" + codigoPais + "/bt-esperandome-over.gif";
		document.Form1.imgConociendonos.src="img/common/topnav/" + codigoPais + "/bt-conociendonos.gif";
		document.Form1.imgCompartiendo.src="img/common/topnav/" + codigoPais + "/bt-compartiendo.gif";
		document.Form1.imgDescubriendo.src="img/common/topnav/" + codigoPais + "/bt-descubriendo.gif";
		document.Form1.imgIndenpendizandome.src="img/common/topnav/" + codigoPais + "/bt-independizandome.gif";
		break;
	case 2:
		document.Form1.imgConociendonos.src="img/common/topnav/" + codigoPais + "/bt-conociendonos-over.gif";
		document.Form1.imgEsperandome.src="img/common/topnav/" + codigoPais + "/bt-esperandome.gif";
		document.Form1.imgCompartiendo.src="img/common/topnav/" + codigoPais + "/bt-compartiendo.gif";
		document.Form1.imgDescubriendo.src="img/common/topnav/" + codigoPais + "/bt-descubriendo.gif";
		document.Form1.imgIndenpendizandome.src="img/common/topnav/" + codigoPais + "/bt-independizandome.gif";
		break;
	case 3:
		document.Form1.imgCompartiendo.src="img/common/topnav/" + codigoPais + "/bt-compartiendo-over.gif";
		document.Form1.imgEsperandome.src="img/common/topnav/" + codigoPais + "/bt-esperandome.gif";
		document.Form1.imgConociendonos.src="img/common/topnav/" + codigoPais + "/bt-conociendonos.gif";
		document.Form1.imgDescubriendo.src="img/common/topnav/" + codigoPais + "/bt-descubriendo.gif";
		document.Form1.imgIndenpendizandome.src="img/common/topnav/" + codigoPais + "/bt-independizandome.gif";
		break;
	case 4:
		document.Form1.imgDescubriendo.src="img/common/topnav/" + codigoPais + "/bt-descubriendo-over.gif";
		document.Form1.imgEsperandome.src="img/common/topnav/" + codigoPais + "/bt-esperandome.gif";
		document.Form1.imgConociendonos.src="img/common/topnav/" + codigoPais + "/bt-conociendonos.gif";
		document.Form1.imgCompartiendo.src="img/common/topnav/" + codigoPais + "/bt-compartiendo.gif";
		document.Form1.imgIndenpendizandome.src="img/common/topnav/" + codigoPais + "/bt-independizandome.gif";
		break;
	case 5:
		document.Form1.imgDescubriendo.src="img/common/topnav/" + codigoPais + "/bt-descubriendo.gif";
		document.Form1.imgEsperandome.src="img/common/topnav/" + codigoPais + "/bt-esperandome.gif";
		document.Form1.imgConociendonos.src="img/common/topnav/" + codigoPais + "/bt-conociendonos.gif";
		document.Form1.imgCompartiendo.src="img/common/topnav/" + codigoPais + "/bt-compartiendo.gif";
		document.Form1.imgIndenpendizandome.src="img/common/topnav/" + codigoPais + "/bt-independizandome-over.gif";
		break;		
	}
	window.focus();

}



function VisualizarContenido(contenido, idPais)
{
	Navegar("./PlantillaNota.aspx",  {idContenido: contenido, idPais: idPais});
	window.focus();
}



function LinkContenido(contenido, pais)
{
	Navegar("./PlantillaNota.aspx",  {NombreContenido: contenido, CodigoPais: pais, IdContenido: 0, IdPais: 0 });
	window.focus();
}




function ActualizarHtml(data)
{
	document.getElementById("tdCentro").innerHTML = data;

	if(document.getElementById("tdDocumentoHijo1"))
	{
		for(i=1;document.getElementById("tdDocumentoHijo"+i);i++)
		{
			document.getElementById("tdDocumentoHijo"+i).innerHTML = document.getElementById("tdDocumentoHijo"+i).innerHTML.replace("*","");
		}
	}
}


function Buscar(idPais, pagina)
{
	
	var texto = document.Form1.txtTextoBuscar.value;
	texto = trim(texto);
	var ok = true;	
	var aux = new String();	
	
	if(texto.length<3)
	{
		ok=false;
		alert(mensajes[3]);
		document.Form1.txtTextoBuscar.focus();
	}
	/*var arrayPalabras = texto.split(" ");
	for(var i=0; i<arrayPalabras.length; i++)
	{
		aux = trim(arrayPalabras[i]);
		if(aux.length<3)
		{
			ok=false;
			alert(mensajes[3]);
			document.Form1.txtTextoBuscar.focus();
			break;
		}
		if(aux=="and")
		{
			ok=false;	
			alert(mensajes[2]);	
			document.Form1.txtTextoBuscar.focus();
			break;
		}
	}*/
	
	if(ok)
	{
		Navegar("./PlantillaBuscador.aspx", {idPais: idPais, pagina: pagina, texto: texto});
	}
}

function TematicaNavegar(idPais, pagina)
{
		
	var ok = true;
		
	if(document.getElementById("cmbTemas").value=="0")
	{
		ok=false;
		alert(mensajes[4]);
		document.getElementById("cmbTemas").focus();
	}
	
	if(ok)
	{
		Navegar("./PlantillaTematica.aspx", {idPais: idPais, pagina: pagina, idTematica: document.getElementById("cmbTemas").value});
	}
	
}




function AplicacionNavegar(idPais)
{	
	if(document.getElementById("cmbAplicaciones").value!="")
	{
		Navegar(document.getElementById("cmbAplicaciones").value, {idPais: idPais});
	}
}

function NovedadNavegar(idPais)
{	
	Navegar("./PlantillaNovedades.aspx", {idPais: idPais});	
}



function EtapaContenidos(idPais, idEtapa, pagina)
{	
	Navegar("./PlantillaListadoEtapaTematica.aspx", {idPais: idPais, pagina: pagina, idEtapa: idEtapa});
}



function VisualizarCumplemes(ids, idPais)
{	
	Navegar("./PlantillaCumplemes.aspx", {ids: ids, idPais: idPais});	
}



createXhrHistoryTracker = function(url, parametros){
	var request = new dojo.io.Request(url, 'text/html', null, false);
	dojo.lang.mixin(request, {
		data: null,
		sync: true,
		method: "post",
		encoding: "utf-8",
		content: parametros,
		load: function(type, evaldObj){ 
			if(type == "load")
			{
				this.data = evaldObj;
				ActualizarHtml(this.data);
			}
		},
		back: function(){ActualizarHtml(this.data);},
		forward: function(){ActualizarHtml(this.data);},
		error: function() {MensajeError(parametros.idPais, this.data);}
	});
	
	return request;
}

function Navegar(paginaNav, parametros){
	dojo.io.bind(createXhrHistoryTracker(paginaNav, parametros));
	window.scrollTo(0,0);
}


function MensajeError(idPais, data){	
	/*
	dojo.io.bind({
	url: './MensajeError.aspx',
	sync: true,
	mimetype: "text/html",
	method: "post",
	content: {idPais: idPais},
	load: function (type, data) {
		var myObject = eval('(' + data + ')');
		alert(myObject.mensaje);
	},
	error: function() {
		alert('error');
	}
	});
	*/
	alert(mensajes[5]);
	
}

function Continuar()
{
	if(document.getElementById("paginaPopUp").value!="")
		window.open(document.getElementById("paginaPopUp").value.replace("IdPersona","idPersona"),'Huggies',',toolbar=Yes,location=Yes,scrollbars=auto,status=Yes,resizable=yes, height=' + screen.height + ', width=' + screen.width);
		
	document.getElementById('intPaso').value='';
	document.Form1.submit();

}

function EnviarClaves(idPais)
{
	var ok = true;

	if (document.getElementById("txtContactoEMail").value=="")
	{
		alert(mensajes[13]);
		document.getElementById("txtContactoEMail").focus();
		ok = false;	
	}
	
	if(!ValidarMail(document.getElementById("txtContactoEMail").value))
	{
		alert(mensajes[13]);
		document.getElementById("txtContactoEMail").focus();
		ok=false;
	}
	

	if(ok)
	{
		Navegar("./FrmOlvido.aspx",{intPaso: "E", idPais: idPais, EMail: document.getElementById("txtContactoEMail").value});
	}
}