// JavaScript formularios /source/include/forms.asp

var colorFallo="#fbc311";
var colorNormal="#FFFFFF";


	function ValidationException(codigo,mensaje,campo){
		this.codigo=(codigo==undefined)?0:codigo;
		this.mensaje=(mensaje==undefined)?null:mensaje;
		this.campo=(campo==undefined)?null:campo;
	}

	
	function validarElementos(elementos){
		for(var idx=0;idx<elementos.length;idx++){
			var vacio=elementos[idx].getAttribute("empty");
			if( ((vacio=="false") && (elementos[idx].value=="")) || elementos[idx].style.backgroundColor=="rgb(251, 195, 17)"){
				throw new ValidationException(1,"Needed: ",elementos[idx])
			}
		}
	}
	
	function validarFormulario(form){
		var ok;
		try{
			validarElementos(form.elements);
			ok=true;
		}catch(ex){
			//alert(ex.mensaje+" "+ ex.campo.name);
			ex.campo.style.backgroundColor=colorFallo;	
			ex.campo.focus();
			ok=false;
		}
		
		if (form.agree.checked == false && ok==true)	{
			form.agree.focus();	
			ok=false;
		}
		
		if(ok==true) loading();
		return ok;
	}
	
	function validarFormularioBook(form){
		var ok;
		try{
			validarElementos(form.elements);
			ok=true;
		}catch(ex){
			//alert(ex.mensaje+" "+ ex.campo.name);
			ex.campo.style.backgroundColor=colorFallo;	
			ex.campo.focus();
			ok=false;
		}
		
		if (form.agree.checked == false && ok==true)	{
			form.agree.focus();	
			ok=false;
		}
	
		if(ok==true) window.print();
		
		return ok;
	}

function validarEmail(email){
	//alert(email.value);
	if (!isEmail(email.value)) {
			email.style.backgroundColor=colorFallo;	
		//	email.focus();	
		}
	else{
		email.style.backgroundColor=colorNormal;
	}
}

function validarTexto(e) {
	if (e.value.length < 3){
    	e.style.backgroundColor=colorFallo;	
		//e.focus();	
 	} 
	else {
    	e.style.backgroundColor=colorNormal;
  	}
}

function validarCaptcha(e) {
	if (e.value.length < 5){
    	e.style.backgroundColor=colorFallo;	
		//e.focus();	
 	} 
	else {
    	e.style.backgroundColor=colorNormal;
  	}
}

function validarFecha(e) {
	if (e.value.length != 10){
    	e.style.backgroundColor=colorFallo;	
	//	e.focus();	
 	} 
	else {
    	e.style.backgroundColor=colorNormal;
  	}
}

function validarNumero(e) {
	if (e.value.length < 1){
    	e.style.backgroundColor=colorFallo;	
		//e.focus();	
 	} 
	else {
    	e.style.backgroundColor=colorNormal;
  	}
	/*if (isNaN(e.value) == true){
    	e.style.backgroundColor=colorFallo;	
		e.focus();	
 	} 
	else {
    	e.style.backgroundColor=colorNormal;
  	}*/
}



function copyInquilino(){
	document.getElementById("nombre1").value=document.getElementById("titular").value;	
	document.getElementById("pasaporte1").value=document.getElementById("cif").value;	
	document.getElementById("direccion1").value=document.getElementById("direccion").value;	
	document.getElementById("pais1").value=document.getElementById("pais").value;
	document.getElementById("telefono1").value=document.getElementById("telefono").value;
	document.getElementById("telefonoSeg1").value=document.getElementById("telefonoSeg").value;
	document.getElementById("correo1").value=document.getElementById("correo").value;
}




