function verFormacion() {
	location.href = "ctl_servlet?_f=120";
}

function verServicios() {
	location.href = "ctl_servlet?_f=130";
}

function verBuscador() {
	location.href = "ctl_servlet?_f=160";
}

function volver() {
	history.back();
}

function mostrarCapaError() {
	document.getElementById("capaErrores").style.visibility = "visible";
}

function ocultarCapaError() {
	document.getElementById("capaErrores").style.visibility = "hidden";
}

function ponerError(mensaje, element) {

	// pintar elemento
	//element.style.color = '#F00';
	//element.style.backgroundColor = '#FF0';
	
	// poner mensaje
	document.getElementById("capaErrores").innerHTML+=mensaje;
}

function quitarErrores(form)
{
	// campos
	for (i = 0; i < form.elements.length; i++)
	{
		element = form.elements[i];
		//element.style.color = '#000';
		//element.style.backgroundColor = '#FFF';
	}
	
	// capa
	window.document.getElementById("capaErrores").innerHTML = "";
	window.document.getElementById("capaMensaje").innerHTML = "";
}

function validarMail(element) {
	var mailCorrecto = false;
	
	
	if (element.value != '') {
		var mail = element.value;
		
		if (mail.indexOf("@") != -1) {
			mailCorrecto = true;
		
		} else {
			mailCorrecto = false;
			ponerError('Por favor, introduzca una direcci&oacute;n de correo v&aacute;lida.<br />', element);
			mostrarCapaError();
		}
		
	} else {
		mailCorrecto = false;
		ponerError('Por favor, introduzca una direcci&oacute;n de correo.<br />', element);
		mostrarCapaError();
	}
	return mailCorrecto;
}

function validarMensaje(element) {
	var mensajeCorrecto = false;
	
	
	if (element.value != '') {
		mensajeCorrecto = true;
	
	} else {
		mensajeCorrecto = false;
		ponerError('Por favor, introduzca un mensaje.<br />', element);
		mostrarCapaError();
	}
	return mensajeCorrecto;
}


//
function abrirReminder() {

    //alert('reminder');

    var width = 525;
    var height = 500;
    
    var X = getWidth() / 2;
    var Y = getHeight() / 2;

    var top = getTop(Y, height);
    var left = getTop(X, width);

    var mail = document.getElementById("pmail").value;
    
    var destino = 'ctl_servlet?_f=20000&txtMail=' + mail;
      
    var vtnPass = window.open(destino, 'Password' , 'width=' + width + ', height=' + height + ', toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no, titlebar=no, top=' + top + ', left=' + left);

    vtnPass.focus();

}

//
function getWidth() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return(document.body.clientWidth);
    
    } else {
        return window.outerWidth;
    }
} 

//
function getHeight() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return(document.body.clientHeight);
    
    } else {
        return window.outerHeight;
    }
}

//
function getTop(Y, height) {
    var top = 0;

    if (navigator.userAgent.indexOf("MSIE") > 0) {
        top = window.screenTop + (Y - (height / 2));
    
    } else {
        top = window.screen.top + (Y - (height / 2));
    }
    
    return top;
}

//
function getLeft(X, width) {
    var left = 0;

    if (navigator.userAgent.indexOf("MSIE") > 0) {
        left = window.screenLeft + (X - (width / 2));
    
    } else {
        left = window.screen.left + (X - (width / 2));
    }
    
    return left;
}

function mail() {
    
    // llama a ajax
    validarMail();
    
    // sin este alert no funciona el pop-up en la 1era ejecucion
    alert('Comprobando e-mail introducido...');
   
    
    if (mailok != '0') {
    
        //alert('valor: ' + window.document.getElementById("mail_estado").value);
        
         // EXISTE
        if (window.document.getElementById("mail_estado").value == '1') {
        
            document.getElementById("mail_ico").src=document.getElementById("mail_ico_cancel").src; 
            //alert("Dirección de correo ya utilizada.");
            
            abrirReminder();

        // NO VALIDO
        } else if (window.document.getElementById("mail_estado").value == '0') {
            document.getElementById("mail_ico").src=document.getElementById("mail_ico_cancel").src;
            //alert('Direccion no valida');
        
        // NUEVO
        } else if (window.document.getElementById("mail_estado").value == '2') {
            document.getElementById("mail_ico").src=document.getElementById("mail_ico_ok").src;
            //alert("Mail nuevo");
        
        // OTRO
        } else {
            //alert("otro");
        }
    }
}

// 2 - ok
// 1- existe
// 0 - no existe
function validarMail()
{
    //alert('validarMail()');
    
    disableButton();
    
    var mail = document.getElementById("pmail").value;
    
    // MAIL VACIO O NO VALIDO
    if (mail == "" || !emailCheck(mail)) {
        //alert('no valido');
    
        document.getElementById("mail_estado").value="0";
        
        document.getElementById("mail_ico").src=document.getElementById("mail_ico_cancel").src;
        
        enableButton();
        
        mailok = "0";
        
        return;
        
        
        
    } else {
    
        //alert('traerDatos()');
        
        mailok = "1";
        
        // si continua aqui es un mail valido
        traerDatos('mail_test', mail);
    
    }
    // traer datos escribe en mail_estado
    
    //alert(window.document.getElementById("mail_estado").value);
}
