function morganiza(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function emailCheck (emailStr) {
/* Verificar si el email tiene el formato user@dominio. */
var emailPat=/^(.+)@(.+)$/; 

/* Verificar la existencia de caracteres. ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; 

/* Verifica los caracteres que son válidos en una dirección de email */
var validChars="\[^\\s" + specialChars + "\]"; 

var quotedUser="(\"[^\"]*\")"; 

/* Verifica si la dirección de email está representada con una dirección IP Válida */ 


var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;


/* Verificar caracteres inválidos */ 

var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");


var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
/*alert("Email address seems incorrect (check @ and .'s)");*/
return false
}
var user=matchArray[1]
var domain=matchArray[2]

// Si el user "user" es valido 
if (user.match(userPat)==null) {
// Si no
/*alert("El nombre de usuario no es válido.");*/
return false
}

/* Si la dirección IP es válida */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
/*alert("IP de destino inválida");*/
return false
}
}
return true
}

var domainArray=domain.match(domainPat)
if (domainArray==null) {
/*alert("El dominio parece no ser válido.");*/
return false
}

var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) { 

/*alert("La dicrección debe tener 3 letras si es .'com' o 2 si en de algún pais.");*/
return false
}

if (len<2) {
var errStr="La dirección es erronea"
/*alert(errStr);*/
return false
}

// La dirección de email ingresada es Válida
return true;
}
// End -->

function buscador(){
if (document.getElementById("kbsq").value == "")
{ alert("Introduzca al menos un criterio"); document.getElementById("kbsq").focus(); return false; }
document.getElementById("fbsq").submit();
}

function logea(){
/*var mail=emailCheck(document.getElementById("usu").value);
if (mail == false)
{ alert("Debe introducir un e-mail correcto de usuario"); document.getElementById("usu").focus(); return false; }
*/
if (document.getElementById("usu").value == "")
{ alert("Debe introducir su CIF o NIF"); document.getElementById("usu").focus(); return false; }
if (document.getElementById("pass").value == "")
{ alert("Debe introducir su contrase\u00F1a"); document.getElementById("pass").focus(); return false; }
document.getElementById("facceso").submit();
}

function logeab(){
var mail=emailCheck(document.getElementById("usur").value);
if (mail == false)
{ alert("Debe introducir un e-mail correcto de usuario"); document.getElementById("usur").focus(); return false; }
confirm('Recibira un e-mail con una contrase\u00F1a nueva que podra modificar una vez se conecte');
document.getElementById("faccesor").submit();
}

function Validar(){

if (document.getElementById("Nombre").value == "")
{ alert("Debe proporcionarnos su Nombre"); document.getElementById("Nombre").focus(); return false; }

var mail=emailCheck(document.getElementById("email").value);
if (mail == false)
{ alert("Debe introducir un e-mail correcto"); document.getElementById("email").focus(); return false; }

if (document.getElementById("Privacidad").checked == false)
{ alert("Debe aceptar la politica de privacidad"); document.getElementById("Privacidad").focus(); return false; }

document.getElementById("form1").submit();
}



function RegValidar(){

if (document.getElementById("Nombre").value == "")
{ alert("Debe proporcionarnos su Nombre"); document.getElementById("Nombre").focus(); return false; }

if (document.getElementById("Apellidos").value == "")
{ alert("Debe proporcionarnos sus Apellidos"); document.getElementById("Apellidos").focus(); return false; }

var mail=emailCheck(document.getElementById("email").value);
if (mail == false)
{ alert("Debe introducir un e-mail correcto"); document.getElementById("email").focus(); return false; }

if (document.getElementById("Telefono").value == "")
{ alert("Debe proporcionarnos un telefono de contacto"); document.getElementById("Telefono").focus(); return false; }

if (document.getElementById("Contrasena").value == "")
{ alert("Debe especificar una contrase\u00F1a"); document.getElementById("Contrasena").focus(); return false; }

if (document.getElementById("Contrasenab").value == "")
{ alert("Debe escribir de nuevo la contrase\u00F1a"); document.getElementById("Contrasenab").focus(); return false; }

if (document.getElementById("Contrasena").value == document.getElementById("Contrasenab").value)
{} else
{ alert("Debe escribir la misma contrase\u00F1a"); document.getElementById("Contrasenab").focus(); return false; }


if (document.getElementById("Privacidad").checked == false)
{ alert("Debe aceptar la politica de privacidad"); document.getElementById("Privacidad").focus(); return false; }

document.getElementById("registro").submit();
}


function Validaract(){

if (document.getElementById("nombre").value == "")
{ alert("Es obligatorio escribir su Nombre"); document.getElementById("nombre").focus(); return false; }

if (document.getElementById("apellidos").value == "")
{ alert("Es obligatorio escribir sus apellidos"); document.getElementById("apellidos").focus(); return false; }

var mail=emailCheck(document.getElementById("correo").value);
if (mail == false)
{ alert("Debe introducir un e-mail correcto"); document.getElementById("correo").focus(); return false; }

if (document.getElementById("tlfa").value == "")
{ alert("Es obligatorio un tlf de contacto"); document.getElementById("tlfa").focus(); return false; }

alert("Datos de cliente modificados");
document.getElementById("editusu").submit();
}

function Validaractb(){

if (document.getElementById("npass").value == "")
{ alert("Debe especificar su contrase\u00F1a"); document.getElementById("npass").focus(); return false; }

if (document.getElementById("npassb").value == "")
{ alert("Debe escribir la nueva contrase\u00F1a"); document.getElementById("npassb").focus(); return false; }


document.getElementById("editusub").submit();
}

function Validaractd(){
/*
if (document.getElementById("npass").value == "")
{ alert("Debe especificar su contrase\u00F1a"); document.getElementById("npass").focus(); return false; }

if (document.getElementById("npassb").value == "")
{ alert("Debe escribir la nueva contrase\u00F1a"); document.getElementById("npassb").focus(); return false; }
*/
document.getElementById("deditusu").submit();
}
function Validaractdn(){
/*
if (document.getElementById("npass").value == "")
{ alert("Debe especificar su contrase\u00F1a"); document.getElementById("npass").focus(); return false; }

if (document.getElementById("npassb").value == "")
{ alert("Debe escribir la nueva contrase\u00F1a"); document.getElementById("npassb").focus(); return false; }
*/
if (document.getElementById("dirrn").value == "")
{ alert("Debe especificar la direccion"); document.getElementById("dirrn").focus(); return false; }
if (document.getElementById("cpn").value == "")
{ alert("Debe especificar el codigo postal"); document.getElementById("cpn").focus(); return false; }
if (document.getElementById("pobn").value == "")
{ alert("Debe especificar la poblacion"); document.getElementById("pobn").focus(); return false; }

document.getElementById("deditusun").submit();
}
function Validaractdd(f){
/*
if (document.getElementById("npass").value == "")
{ alert("Debe especificar su contrase\u00F1a"); document.getElementById("npass").focus(); return false; }

if (document.getElementById("npassb").value == "")
{ alert("Debe escribir la nueva contrase\u00F1a"); document.getElementById("npassb").focus(); return false; }
*/
document.getElementById("deditusu"+f).submit();
}

function Validarcon(){

if (document.getElementById("asunto").value == "")
{ alert("Debe escribir un asunto de la consulta"); document.getElementById("asunto").focus(); return false; }

if (document.getElementById("consulta").value == "")
{ alert("Debe explicar el motivo de su consulta"); document.getElementById("consulta").focus(); return false; }

document.getElementById("rconusu").submit();
}

function quehacer(id) {
if (document.getElementById(id).style.display=="block") {
hide(id);
} else {
show(id);
}
}

function show(id) {

document.getElementById(id).style.display = "block";
document.getElementById(id).style.visibility = "visible";
}

function hide(id) {

document.getElementById(id).style.display = "none";
document.getElementById(id).style.visibility = "hidden";


}

