/*funciones para manejar una capa dado su nombre*/

/*****************************************************************
  function para mostrar una capa dado su nombre.  
*****************************************************************/
function verCapa(nombre){
  document.getElementById(nombre).style.visibility="visible";
  document.getElementById(nombre).style.display="block";
}//Fin function

/*****************************************************************
  function para ocultar una capa dado su nombre.  
*****************************************************************/
function noverCapa(nombre){
  document.getElementById(nombre).style.visibility="hidden";
  document.getElementById(nombre).style.display="none";
}//Fin function

/*****************************************************************
  function para ocultar capas dado su nombre.  
*****************************************************************/
function noverCapaDoble(nombre1,nombre2){
  document.getElementById(nombre1).style.visibility="hidden";
  document.getElementById(nombre1).style.display="none";
  document.getElementById(nombre2).style.visibility="hidden";
  document.getElementById(nombre2).style.display="none";
}//Fin function

/*****************************************************************
  function para  ver capas dado su nombre.  
*****************************************************************/
function verCapaDoble(nombre1,nombre2){
  document.getElementById(nombre1).style.visibility="visible";
  document.getElementById(nombre1).style.display="block";
  document.getElementById(nombre2).style.visibility="visible";
  document.getElementById(nombre2).style.display="block";
}//Fin function

/*funcion para validar el buscador de la home*/
function validarBuscador(busqueda)
{
var todo_ok = 0;
    if(busqueda == "detalle")
    {
    	if(document.buscador.edad1.value == "" || document.buscador.edad2.value == "")
        {
			alert("Los campos de la edad deben ir rellenos");
			todo_ok = 1;
        }
        if(document.buscador.edad1.value*1 > document.buscador.edad2.value*1)
        {
			alert("La edad del segundo campo debe ser superior a la del primero");
			todo_ok = 1;
        }
        document.buscador.paisEnviado.value = document.buscador.paisEnviado.options[document.buscador.paisEnviado.selectedIndex].value;
		if(document.buscador.paisEnviado.value == 0)
		{
			alert("Debes seleccionar un país");
			todo_ok = 1;
		}
	    if(todo_ok == 1)
		{
			alert("Comprueba todos los campos y vuelve a intentarlo");
		}
		else
		{
			document.buscador.submit();
		}
    }
    if(busqueda == "email")
    {
	    var addressPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	    if (! addressPattern.test(document.buscador.email.value)) 
	    {
	            alert("Comprueba el campo email");
	             document.buscador.email.focus();
	    }else{
				document.buscador.tipoBusqueda.value="email";
	            document.buscador.submit();
	    }
    }
    if(busqueda == "nick")
    {
        if(document.buscador.nick.value == "")
        {
            alert("Tienes que introducir algún nick");
        }
        else
        {
			document.buscador.tipoBusqueda.value="nick";
            document.buscador.submit();
        }
    }
}

//solo permite escribir digitos
function onlyDigits(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true; //Tecla de retroceso (para borrar)
    patron = /\d/; // Solo acepta numeros
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

//permite escribir letras y numeros, pero no simbolos raros
function onlyDigitsKeys(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron = /\w/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

//permite escribir letras mayusculas y minusculas, espacios y puntos
function onlyKeys(e) {
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla==8) return true;
    patron =/[A-Za-z ]/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

/* Elimina espacios en blanco */
function trim(palabra){
  for(var i=0; i<palabra.length; i++){
    if(palabra.charAt(i)==' '){
          palabra=palabra.replace(' ','');
          i=i-1;
    }
  }
 return palabra;
}


/* Función para agregar a favoritos */
function favoritos(){
if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
var url="http://www.cadaovejaconsupareja.es/";
var titulo="Cada oveja con su pareja - Contactos gratis";
window.external.AddFavorite(url,titulo);
}
else {
if(navigator.appName == "Netscape") 
alert ("Presione Crtl+D para agregar este sitio en sus Favoritos");
}
}

function validarRegistro()
{
	var todo_ok = 0;
	
	textoAlert = "Revisa los campos: ";
	if (document.getElementById("disponibilidadNick").innerHTML.indexOf("[No disponible]") != -1)
	{
		textoAlert += "'Nickname repetido', ";
		todo_ok = 1;
	}
	if(document.registro.nickname.value == "")
	{
		textoAlert += "'Nickname', ";
		todo_ok = 1;
	}
	if(document.registro.password.value == "")
	{
		textoAlert +="'Password', ";
		todo_ok = 1;
	}
	
	var addressPattern =  /^[^\s\n]+\@[a-zA-Z0-9][a-zA-Z0-9\-\.]*\.[a-zA-Z]{2,4}$/;
  	if (! addressPattern.test(document.registro.email.value)) 
	 {
		textoAlert +="'Email', ";
 		document.registro.email.focus();
 		todo_ok = 1;
	}
	if(document.registro.descripcion.value == "")
	{
		textoAlert +="'Descripcion', ";
		todo_ok = 1;
	}
	if(document.registro.foto.value == "")
	{
		textoAlert +="'Foto', ";
		todo_ok = 1;
	}
	if (document.registro.foto.value.length>0) {
    Foto=document.registro.foto.value.toLowerCase();
    Extension=Foto.substr(Foto.length -4, Foto.length);
	    if (Extension != ".jpg" && Extension != ".gif") {
	      textoAlert +="Debes elegir una foto con formato JPG o GIF";
	      todo_ok = 1;
	    }
	}
	if (!document.registro.condiciones.checked)
	{
		textoAlert +="'Condiciones de uso', ";
		todo_ok = 1;
	}

	// Hay que coger los textos de las localidades, porque no queremos pasar el value
	document.registro.paisEnviado.value = document.registro.pais.options[document.registro.pais.selectedIndex].text;
	if(document.registro.paisEnviado.value == "Elige tu País")
	{
		textoAlert +="'País', ";
		todo_ok = 1;
	}
	else
	{
		document.registro.provinciaEnviada.value = document.registro.provincia.options[document.registro.provincia.selectedIndex].text;
		if(document.registro.provinciaEnviada.value == "Elige tu provincia")
		{
			textoAlert +="'Provincia', ";
			todo_ok = 1;
		}
		else
		{
			document.registro.localidadEnviada.value = document.registro.localidad.options[document.registro.localidad.selectedIndex].text;
			if(document.registro.localidadEnviada.value == "Elige tu localidad")
			{
				textoAlert +="'Localidad', ";
				todo_ok = 1;
			}
		}
	}
	
	
	if(document.registro.zona.value == "")
	{
		textoAlert +="'Zona', ";
		todo_ok = 1;
	}
	if(document.registro.textoCaptcha.value == "")
	{
		textoAlert += "'Imagen con números', ";
		todo_ok = 1;
	}
	
	if(todo_ok == 1)
	{
		textoAlert += "Comprueba todos los campos y vuelve a intentarlo";
		alert(textoAlert);
	}
	else
	{
		document.getElementById("registro").style.display="none";
		document.getElementById("hidepage").style.display="block";
		document.registro.submit();
	}
}

/*función para contar los caracteres que quedan en un campo de texto*/
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

/*funcion para actualizar la imagen del Captcha*/
function actualizaCaptcha()
  {
    	var obj=document.getElementById("imgCaptcha");
    	if (!obj) 
		{
			obj=document.registro.imgCaptcha;
		}
    	if (obj)
		{
      		obj.src= "captcha.php?" + Math.random()  ;
    	}
  }
  
function validarRegistrarse()
{
	var todo_ok = 0;
	if(document.login.nickname.value == "")
	{
		alert("Debes rellenar el campo 'Nickname'");
		todo_ok = 1;
	}
	if(document.login.password.value == "")
	{
		alert("Debes rellenar el campo 'Password'");
		todo_ok = 1;
	}
	/*if(todo_ok == 0 && document.login.nickname.value.length < 4)
	{
		alert("El campo 'Nickname debe llevar al menos 4 caracteres'");
		todo_ok = 1;
	}
	if(todo_ok == 0 && document.login.password.value.length < 6)
	{
		alert("El campo 'Password' debe llevar al menos 6 caracteres");
		todo_ok = 1;
	}*/
	if(todo_ok == 1)
	{
		alert("Comprueba todos los campos y vuelve a intentarlo");
	}
	else
	{
		document.login.submit();
	}
}

function validarIA()
{
	//var addressPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
    //if (! addressPattern.test(document.invitaramigo.email.value)) 
      //{
           // alert("Comprueba el campo email");
             //document.invitaramigo.email.focus();
      //}else{
			//document.invitaramigo.tipoBusqueda="email";
            document.invitaramigo.submit();
      //}
}

function validarOlvido()
{
	var addressPattern =  /^[^\s\n]+\@[a-zA-Z0-9][a-zA-Z0-9\-\.]*\.[a-zA-Z]{2,4}$/;
  	if (! addressPattern.test(document.olvidoPass.email.value)) 
	 {
		alert("Has escrito mal tu dirección de correo en el campo 'Email'");
 		document.olvidoPass.email.focus();
	}
	else
	{
		document.olvidoPass.submit();
	}
}

function validarMsn()
{
	var addressPattern =  /^[^\s\n]+\@[a-zA-Z0-9][a-zA-Z0-9\-\.]*\.[a-zA-Z]{2,4}$/;
  	if (! addressPattern.test(document.buscarContactosMSN.username.value)) 
	 {
		alert("Has escrito mal tu dirección de correo en el campo 'Email'");
 		document.buscarContactosMSN.username.focus();
	}
	else if (document.buscarContactosMSN.password.value == "")
	{
		alert("Debes escribir tu password");
	}
	else
	{
		document.buscarContactosMSN.submit();
	}
}

function getSelectedCheckboxValue(buttonGroup) 
{   
   var listado = '';
   var i = 0;
   alert (document.listadoContactosMSN.listaEmails[0].value);
   var tamanhoMails = document.listadoContactosMSN.listaEmails.length;
   for (i = 0; i<tamanhoMails;i++)
   {
   		if (document.listadoContactosMSN.listaEmails[i].checked)
		{
			listado = listado + ',' + document.listadoContactosMSN.listaEmails[i].value;
		}
   }   
   document.listadoContactosMSN.listadoEMails.value=listado;
}

function cambiaColor(idCelda)
{
	if(idCelda == "td_detalle")
	{
		document.getElementById(idCelda).className='fondocelda1';
		document.getElementById('td_nick').className='fondocelda2';
		document.getElementById('td_email').className='fondocelda2';
	}
	if(idCelda == "td_nick")
	{
		document.getElementById(idCelda).className='fondocelda1';
		document.getElementById('td_detalle').className='fondocelda2';
		document.getElementById('td_email').className='fondocelda2';
	}
	if(idCelda == "td_email")
	{
		document.getElementById(idCelda).className='fondocelda1';
		document.getElementById('td_nick').className='fondocelda2';
		document.getElementById('td_detalle').className='fondocelda2';
	}
}

/*colores Vuelos Baratos*/
document.writeln("<style type=\"text/css\">\n");
document.writeln(".rumbo_descripcion00 {\n");
document.writeln("color: #010062;\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 6.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("}\n");
document.writeln(".rumbo_select00 {\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 6.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("}\n");
document.writeln(".rumbo_480x250 {\n");
document.writeln("color: black;\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 6.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("text-decoration: none;\n");
document.writeln("}\n");
document.writeln("a.rumbo_480x250:visited {\n");
document.writeln("color: #000000;\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 6.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("text-decoration: none;\n");
document.writeln("}\n");
document.writeln("a.rumbo_480x250:hover {\n");
document.writeln("color: #000000;\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 6.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("text-decoration: underline;\n");
document.writeln("}\n");
document.writeln(".rumbo_480x250_titulo {\n");
document.writeln("color: #2e659d;\n");
document.writeln("font-family: Verdana, Arial, Helvetica, sans-serif;\n");
document.writeln("font-size: 9.5pt;\n");
document.writeln("font-style: normal;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-weight : bold;\n");
document.writeln("}\n");
document.writeln(".rumbo_480x250_fondo {\n");
document.writeln("background-color : #ffffff;\n");
document.writeln("}\n");
document.writeln("<\/style>");

document.writeln("<style type=\"text/css\">\n");
document.writeln(".rumbo_cd9iv_titulo_caja {\n");
document.writeln("color : #ffffff;\n");
document.writeln("font-family : Verdana;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-style : normal;\n");
document.writeln("font-weight : bold;\n");
document.writeln("font-size : 8pt;\n");
document.writeln("text-decoration : none;\n");
document.writeln("text-align : center;\n");
document.writeln("}\n");
document.writeln(".rumbo_cd9iv_enlace {\n");
document.writeln("color : #000180;\n");
document.writeln("font-family : Verdana;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-style : normal;\n");
document.writeln("font-weight : normal;\n");
document.writeln("font-size : 8pt;\n");
document.writeln("text-decoration : none;\n");
document.writeln("}\n");
document.writeln("a.rumbo_cd9iv_enlace:link {\n");
document.writeln("color : #000180;\n");
document.writeln("font-family : Verdana;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-style : normal;\n");
document.writeln("font-weight : normal;\n");
document.writeln("font-size : 8pt;\n");
document.writeln("text-decoration : none;\n");
document.writeln("}\n");
document.writeln("a.rumbo_cd9iv_enlace:visited {\n");
document.writeln("color : #000180;\n");
document.writeln("font-family : Verdana;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-style : normal;\n");
document.writeln("font-weight : normal;\n");
document.writeln("font-size : 8pt;\n");
document.writeln("text-decoration : none;\n");
document.writeln("}\n");
document.writeln("a.rumbo_cd9iv_enlace:hover {\n");
document.writeln("color : #ff4400;\n");
document.writeln("font-family : Verdana;\n");
document.writeln("line-height : normal;\n");
document.writeln("font-style : normal;\n");
document.writeln("font-weight : normal;\n");
document.writeln("font-size : 8pt;\n");
document.writeln("text-decoration : underline;\n");
document.writeln("}\n");
document.writeln(".rumbo_cd9iv_tabla {\n");
document.writeln("border-collapse : collapse;\n");
document.writeln("border : 1px solid #316ac5;\n");
document.writeln("}\n");
document.writeln("<\/style>");

document.writeln("\n");
document.writeln("<style type=\"text/css\">\n");
document.writeln(".rmbescdhl12_titulo_caja {\n");
document.writeln("color: #ffffff;\n");
document.writeln("font-family: Verdana;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-style: normal;\n");
document.writeln("font-weight: bold;\n");
document.writeln("font-size: 8pt;\n");
document.writeln("text-decoration: none;\n");
document.writeln("text-align: center;\n");
document.writeln("}\n");
document.writeln(".rmbescdhl12_enlace {\n");
document.writeln("color: #000180;\n");
document.writeln("font-family: Verdana;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-style: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("font-size: 8pt;\n");
document.writeln("text-decoration: none;\n");
document.writeln("}\n");
document.writeln("a.rmbescdhl12_enlace:link {\n");
document.writeln("color: #000180;\n");
document.writeln("font-family: Verdana;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-style: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("font-size: 8pt;\n");
document.writeln("text-decoration: none;\n");
document.writeln("}\n");
document.writeln("a.rmbescdhl12_enlace:visited {\n");
document.writeln("color: #000180;\n");
document.writeln("font-family: Verdana;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-style: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("font-size: 8pt;\n");
document.writeln("text-decoration: none;\n");
document.writeln("}\n");
document.writeln("a.rmbescdhl12_enlace:hover {\n");
document.writeln("color: #ff4400;\n");
document.writeln("font-family: Verdana;\n");
document.writeln("line-height: normal;\n");
document.writeln("font-style: normal;\n");
document.writeln("font-weight: normal;\n");
document.writeln("font-size: 8pt;\n");
document.writeln("text-decoration: underline;\n");
document.writeln("}\n");
document.writeln(".rmbescdhl12_tabla {\n");
document.writeln("border-collapse: collapse;\n");
document.writeln("border: 1px solid #316ac5;\n");
document.writeln("}\n");
document.writeln("<\/style>\n");
document.writeln("");