// Funcion resaltar para las tablas

function resalta(linea, color)
{

    if (color == '' || typeof(linea.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var celdas = linea.getElementsByTagName('td');
    }
    else if (typeof(linea.cells) != 'undefined') {
        var celdas = linea.cells;
    }
    else {
        return false;
    }

    var i  = celdas.length;
    for (var c = 0; c < i; c++) {
        celdas[c].style.backgroundColor = color;
    }

    return true;
	
} // Fin de 'resalta()' 



function anularBotonDerecho() {
	if (event.button==2) {
	 alert('Botón derecho deshabilitado');
	}
}

   

function printit(){  
if (NS) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);
WebBrowser1.outerHTML = "";  
}
}

function email_valido(txt){
// Expresion regular de la leche
        var b=/^[^@ $]+@([^@. $]+\.[^@. $]+)+$/;
		if (!(b.test(txt))){ 
			alert("Email no válido.");
			return false;
		}else{
            return true;
		};
}


function fecha_valida(txt,alerta){
	var Fecha= new String(txt);	// Crea una cadena auxiliar para para fecha
	var RealFecha= new Date();	// Fecha de hoy
	// txt Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length));
	// txt Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")));
	// txt Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")));

	// Valido el año
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
        alert('Año no válido en '+ alerta);
		return false;
	};
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		alert('Mes no válido en' + alerta);
		return false;
	};
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
		alert('Día no válido en' + alerta);
		return false;
	};
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
			alert('Día no válido en' + alerta);
			return false;
		};
	};
	
  //Fecha correcta
  return true;
}



function validar_form(){
	// verificamos el nombre
	if (document.nform.nombre.value==""){
		alert("El campo Nombre no debe estar vacío");
		return false;
	};
    // verificamos el apellido
	if (document.nform.apellidos.value==""){
		alert("El campo Apellidos no debe estar vacío");
		return false;
	};
	
    // verificamos la dirección
	if (document.nform.direccion.value==""){
		alert("El campo Dirección no debe estar vacío");
		return false;
	};
    // verificamos la población
	if (document.nform.poblacion.value==""){
		alert("El campo Población no debe estar vacío");
		return false;
	};
    // verificamos el CP
	if (document.nform.codigop.value==""){
		alert("El campo Código Postal no debe estar vacío");
		return false;
	}else{
		if (isNaN(document.nform.codigop.value)){
			alert("El campo Código Postal debe ser numérico");
			return false;
		};// verificamos la provincia
	};
	// Verificamos la provincia
	if (document.nform.provincia.value==""){
		alert("El campo Provincia no debe estar vacío");
		return false;
	};

    // verificamos el teléfono
	if (document.nform.movil.value!=""){
		if (isNaN(document.nform.movil.value)){
			alert("El campo Móvil debe ser numérico");
			return false;
		};
	}	
	else{
		alert("El campo Móvil no debe estar vacío");
		return false;
	};
   
    // verificamos el email
	if (document.nform.email.value!=""){
		if (!email_valido(document.nform.email.value)){
			alert("La dirección e-mail no es válido");
			return false;
		}
	};
	
	// Comprobamos el login
	if (document.nform.login.value!=""){
		if ((document.nform.login.value.length)<6){
			alert("El campo login debe tener 6 caracteres mínimo");
			return false;
		};
	}else{
		alert("El campo Login no debe estar vacío");
		return false;
	}	

	// Comprobamos el password
	if (document.nform.password.value!=""){
		if ((document.nform.password.value.length)<6){
			alert("El campo Password debe tener 6 caracteres mínimo");
			return false;
		}else{
			if ((document.nform.password.value)!=(document.nform.cpassword.value)){
				alert("Los campos Password no coinciden,vuelva a introducirlos");
				return false;
			}
		}
	}else{
		alert("El campo Password no debe estar vacío");
		return false;
	}	

	return true;
};

function enviar_form(nform){
	if (validar_form(nform)){
		document.nform.submit();
	}

};

// Código para ejecutar
document.onmousedown=anularBotonDerecho;
