function checkrequired(formulario,lang) {
var pass = true;
if (document.images) {
	for (i=0;i<formulario.length;i++) {
 	var tempobj = formulario.elements[i];
 	if (tempobj.name.substring(0,1)=="r") {
  		if (( (tempobj.type=="text"||tempobj.type=="textarea"||tempobj.type=="password" ) && tempobj.value=='') ||(tempobj.type.toString().charAt(0)=="s" && tempobj.selectedIndex==0))  {
		   //tempobj.style ='background-image: url(../img/fondoinputerror.png)';
		   tempobj.focus();
		   pass = false;
		   break;
	   	} else if (tempobj.type=="radio") {
			// todo
		}
  	}
	}
}

if (!pass) {
	
	shortFieldName=tempobj.id;

	switch(lang) {
		case 'ES': msg = "Por favor, el campo "+shortFieldName+" es obligatorio.";
			break;
		case 'DE': msg = "Bitte, das Feld "+shortFieldName+" ist obligatorisch.";
			break;
		case 'EN': msg = "Please, the field "+shortFieldName+" is mandatory.";
			break;
		case 'FR': msg = "S’il vous plaît, le champ est obligatoire "+shortFieldName+".";
			break;
		case 'IT': msg = "Per favore, il campo "+shortFieldName+" è obbligatoria.";
	}		
	alert(msg);

	return false;
} else {
	

try {


var hoy= new Date();
var llegada=new Date();
var salida=new Date();

llegada.setFullYear(formulario.rtxtLlegada.value.substring(6,4),formulario.rtxtLlegada.value.substring(3,2),formulario.rtxtLlegada.value.substring(0,2));
salida.setFullYear(formulario.rtxtSalida.value.substring(6,4),formulario.rtxtSalida.value.substring(3,2),formulario.rtxtSalida.value.substring(0,2));


if (llegada > salida) {
 alert("Por favor, la fecha de entrada no puede ser posterior a la de salida.");
 formulario.rtxtLlegada.focus();
 return false;
} else if (llegada < salida) {
 alert("Por favor, la fecha de salida no puede ser posterior a la de entrada.");
 formulario.rtxtLlegada.focus();
 return false;
} else if (llegada < hoy) {
 alert("Por favor, la fecha de entrada no puede ser anterior a la fecha actual.");
 formulario.rtxtLlegada.focus();
 return false;
} else if (salida < hoy) {
 alert("Por favor, la fecha de salida no puede ser anterior a la fecha actual.");
 formulario.rtxtSalida.focus();
 return false;
}

} catch(err) {

}

var msg = '';
try {
if (!ValidarDirCorreoElectronico(formulario.rtxtemail.value)) {
			switch(lang) {
			case 'ES': msg = 'Por favor, la dirección de correo electrónico no es válida.';
				break;
			case 'DE': msg = 'Bitte E-Mail-Adresse ist ungültig.';
				break;
			case 'EN': msg = 'Please e-mail address is invalid.';
				break;
			case 'FR': msg = 'S’il vous plaît e-mail est invalide.';
				break;
			case 'IT': msg = 'Vi preghiamo di indirizzo e-mail non è valido.';
			}		
			alert(msg);
			return false;
}	
} catch(err) {

}

return true;
}
}

function ValidarDirCorreoElectronico(email){var caracteres="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.";var i;var valido=true;var pos_arroba=email.indexOf("@");var pos_ultimo_punto=email.lastIndexOf(".");var email_minus = email.toLowerCase();var trozo;if (pos_arroba==-1){return false;}if(email_minus.indexOf("usuario@servidor.es")!=-1){return false;}if(pos_ultimo_punto==-1){return false;}trozo=email.substring(0, pos_arroba);for(i=0;i<trozo.length;i++){if(caracteres.indexOf(trozo.charAt(i))==-1){valido = false;break;}}if(!valido){return false;}valido=true;trozo=email.substring(1+pos_arroba, pos_ultimo_punto);for(i=0;i<trozo.length;i++){if (caracteres.indexOf(trozo.charAt(i)) == -1) {valido = false;break;}}if(!valido){return false;}valido = true;trozo=email.substring(1+pos_ultimo_punto, email.length);if((trozo.length >= 2)&&(trozo.length <= 3)){for(i=0;i<trozo.length;i++){if(caracteres.indexOf(trozo.charAt(i))==-1){valido=false;break;}}if(!valido){return false;}}else{return false;}return true;}

function  validarNewsletter(formulario, msg) {
	if (!ValidarDirCorreoElectronico(formulario.email.value)){
		alert(msg);
		return false;
	} else
		return true;
}


function  validarContacto(formulario,lang) {
	if (checkrequired(formulario,lang)) {
		var msg = '';
		if (!ValidarDirCorreoElectronico(formulario.rtxtemail.value)) {
			switch(lang) {
			case 'ES': msg = 'Por favor, la dirección de correo electrónico no es válida.';
				break;
			case 'DE': msg = 'Bitte E-Mail-Adresse ist ungültig.';
				break;
			case 'EN': msg = 'Please e-mail address is invalid.';
				break;
			case 'FR': msg = 'S’il vous plaît e-mail est invalide.';
				break;
			case 'IT': msg = 'Vi preghiamo di indirizzo e-mail non è valido.';
			}		
			alert(msg);
			return false;
		}
	} else 
		return false;
	
	return true;
}


function AgenciaParticular(valor) {
	if (valor) {
		document.getElementById("dagencia").style.display = "none";
	} else {
		document.getElementById("dagencia").style.display = "";
	}
	
}

function LargaTemporada(valor) {
	if (valor) {
		document.getElementById("dtarifas0").style.display = "none";
		document.getElementById("dtarifas1").style.display = "none";
		document.getElementById("dtarifas2").style.display = "none";
		document.getElementById("dtarifas3").style.display = "none";
		document.getElementById("dtarifas4").style.display = "none";
		document.getElementById("dtarifas5").style.display = "none";
		document.getElementById("dtarifas6").style.display = "none";
	} else {
		document.getElementById("dtarifas0").style.display = "";
		document.getElementById("dtarifas1").style.display = "";
		document.getElementById("dtarifas2").style.display = "";
		document.getElementById("dtarifas3").style.display = "";
		document.getElementById("dtarifas4").style.display = "";
		document.getElementById("dtarifas5").style.display = "";
		document.getElementById("dtarifas6").style.display = "";
	}
	
}

function PrecioxTemporadas() {
	document.falojamientos2.vuelta.value = 1;
	document.falojamientos2.precioxtemporada.checked = true;
	document.falojamientos2.larga_temporada.checked = false;
	document.falojamientos2.submit();
}

function NuevaTemporada(id_vivienda,precio,nombre) {
alert(id_vivienda);
alert(precio);
alert(nombre);
}

function BorrarTemporada(id_vivienda,id_temporada) {
alert(id_vivienda);
alert(id_temporada);

}


function Recomendar(valor) {
	if (valor) {
		document.getElementById("dagencia1").style.display = "none";
		document.getElementById("dagencia2").style.display = "none";
		document.getElementById("dagencia3").style.display = "none";
		document.getElementById("dagencia4").style.display = "none";
	} else {
		document.getElementById("dagencia1").style.display = "";
		document.getElementById("dagencia2").style.display = "";
		document.getElementById("dagencia3").style.display = "";
		document.getElementById("dagencia4").style.display = "";
	}
	
}



function addBookmark() {
if (window.sidebar&&window.sidebar.addPanel)
	window.sidebar.addPanel("AlquilerFuerteventura.com","http://www.alquilerfuerteventura.com","");
else
	window.external.AddFavorite("http://www.alquilerfuerteventura.com","AlquilerFuerteventura.com")
}

function Valora(radio, lang) {

bmarcado = false;

if (radio.length > 0 ) {
	for (i = 0; i < radio.length; i++) {
	 	if (radio[i].checked == true) bmarcado = true;				
	}
} else 
	 bmarcado = radio.checked;

if (!bmarcado) {
	switch(lang) {
		case 'ES': msg = "Por favor, la valoración de uno a cinco es obligatoria.";
			break;
		case 'DE': msg = "Bitte Bewertung von eins bis fünf ist obligatorisch.";
			break;
		case 'EN': msg = "Please valuation of one to five is mandatory.";
			break;
		case 'FR': msg = "S’il vous plaît évaluation de un à cinq est obligatoire.";
			break;
		case 'IT': msg = "Vi preghiamo di valutazione da una a cinque è obbligatoria.";
	}		
	alert(msg);
}

return bmarcado;
}