function isEmail(campo) {
    invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";

    var email = campo.value;

    // Check for null
    if (email == "") {
        return true;
    }

    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
           return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
 		    
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
  		  
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {    		
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }

    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }

    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }

    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
}

function imgOver(){
  document.SC.src = "../imagenes/bot-news-leermas-h.gif";
}

function imgOut(){
  document.SC.src= "../imagenes/bot-news-leermas.gif";
}

function avanzarPag(avanc){
		var p_inicio = document.getElementById("inic").value;
		var p_fin = document.getElementById("fin").value;
		var p_pagina = document.getElementById("pag").value;

    $.post('php/notListado.php',{inicio:p_inicio,
								 fin:p_fin,
								 pagina:p_pagina,
                 avance: avanc.id}, function(data){
			$('.listnoticias').html(data);			
	
		});
}

function loc2(t1,t2)
{

	if(document.formRegistro.T1.value=="")
	{
		alert("Por favor, introduzca un usuario.");
		document.formRegistro.T1.focus();
	}
	else if(document.formRegistro.T2.value=="")
	{
		alert("Por favor, introduzca el correo de contacto.");
		document.formRegistro.T2.focus();
	}
	else
	{
		document.formRegistro.action='http://www.cruzroja.es/sercuidador/AltaRegistroSerCuidador';
		document.formRegistro.submit();
	}
}

function validarMail()
{
 
     if (document.getElementById("p_nombre").value == "" )
     {
	    alert("Debes introducir TU NOMBRE");
	    document.getElementById("p_nombre").focus();
        return false;
      }
     
     if (document.getElementById("p_mail").value == ""){
    	 alert("Por favor, introduzca su dirección de correo");
    	 document.getElementById("p_mail").focus();
    	 return false;
     }
     
     if (document.getElementById("p_mail").value != ""){
		if (!isEmail(document.getElementById("p_mail")))
		{
			alert("Por favor introduzca un correo electrónico válido");
		    document.getElementById("p_mail").value = "";
			document.getElementById("p_mail").focus();
			return false;
		}
     }
     
     if (document.getElementById("p_asunto").value == "" )
     {
	    alert("Debes introducir un asunto para tu correo");
	    document.getElementById("p_asunto").focus();
        return false;
      }
      
      if (document.getElementById("p_texto").value =="" )
     {
	    alert("Debes dejarnos algún mensaje");
	    document.getElementById("p_texto").focus();
        return false;
      }
      
  return true;
}

function enviarMail(){
	if (validarMail()){
		$.post('php/enviarMail.php',
				{nom:document.getElementById('p_nombre').value,
				correo:document.getElementById('p_mail').value,
				txt:document.getElementById('p_texto').value},
	            function(data){
				$("#contenedorContacto").hide("slow");
				$("#contenedorContConf").show("slow");
		 });	
	}
}



function buscador(){
	var texto = document.getElementById('textSearch').value;
	var pag = document.getElementById('pagina').value;
	IniciaBuscador(texto,pag,0);
}

