
function ValidarFormularioAlquiler(oFormulario){

 var oElemento;
 // El valor de iEstado se obtiene de hacer una operación AND entre todos los estados de los distintos campos
 var iEstado;
 var i;
 var control=false
 var control2=false
 var controlTitulo=""

 sListadoCampos = "";

 iEstado = true;

 for(i=0;i<oFormulario.elements.length;i++){
  sTipo = oFormulario.elements[i].type;

  // A la hora de evaluar iEstado es importante el orden. Si iEstado es falso y se escribe:
  // iEstado = iEstado && ValidarInput(oFormulario.elements[i]);
  // entonces no se vuelve a evaluar la segunda expresión (una operación && donde el primero es falso => falso)

  if(sTipo=="text" || sTipo=="password"){
   iEstado = ValidarInput(oFormulario.elements[i]) && iEstado;
  }

  if(sTipo=="checkbox"){
   iEstado = ValidarCheckBox(oFormulario.elements[i]) && iEstado;
  }

  if(sTipo=="radio"){
	var sClase = oFormulario.elements[i].className;
	var sTitulo = TratarCadena(oFormulario.elements[i].title);
	var sRequerido = sClase.split("_")[0];
	if(sRequerido == "si"){
		control2=true
	   if(control==false && oFormulario.elements[i].checked==true){
		control= true
	   }
  	}

  }

  if(sTipo=="textarea"){
   iEstado = ValidarTextArea(oFormulario.elements[i]) && iEstado;
  }

  if(sTipo=="select-one"){
   iEstado = validarCombo(oFormulario.elements[i]) && iEstado;
  }

 }

 if(control==false && control2==true){
	 iEstado = false
	 sListadoCampos = sListadoCampos + "\n          - " + sTitulo;
	 }

  if (!iEstado) {
  	window.alert(sMensaje+sListadoCampos);
  }
 return iEstado;

}



function atras(){
	var oForm = document.getElementById('alquilerform');
	oForm.onsubmit=function() {return true;};
}

function imprimir(){
	window.print();
}

function abrirIdaVuelta(){
	var capa
	capa = document.getElementById("idaVuelta")
	capa.style.display="block";

	document.getElementById("fechaOrigen2").className = document.getElementById("fechaOrigen2").className.replace("no_","si_")
	document.getElementById("horaOrigen2").className = document.getElementById("horaOrigen2").className.replace("no_","si_")
	document.getElementById("tipoVOrigen2").className = document.getElementById("tipoVOrigen2").className.replace("no_","si_")
	document.getElementById("lugarOrigen2").className = document.getElementById("lugarOrigen2").className.replace("no_","si_")
	document.getElementById("calleOrigen2").className = document.getElementById("calleOrigen2").className.replace("no_","si_")
	document.getElementById("pisoOrigen2").className = document.getElementById("pisoOrigen2").className.replace("no_","si_")

	//document.getElementById("fechaDestino2").className = document.getElementById("fechaDestino2").className.replace("no_","si_")
	//document.getElementById("horaDestino2").className = document.getElementById("horaDestino2").className.replace("no_","si_")
	//document.getElementById("tipoVDestino2").className = document.getElementById("tipoVDestino2").className.replace("no_","si_")
	document.getElementById("lugarDestino2").className = document.getElementById("lugarDestino2").className.replace("no_","si_")
	document.getElementById("calleDestino2").className = document.getElementById("calleDestino2").className.replace("no_","si_")
	document.getElementById("pisoDestino2").className = document.getElementById("pisoDestino2").className.replace("no_","si_")

}

function cerrarIdaVuelta(){
	var capa
	capa = document.getElementById("idaVuelta")
	capa.style.display="none";

	document.getElementById("fechaOrigen2").className = document.getElementById("fechaOrigen2").className.replace("si_","no_")
	document.getElementById("horaOrigen2").className = document.getElementById("horaOrigen2").className.replace("si_","no_")
	document.getElementById("tipoVOrigen2").className = document.getElementById("tipoVOrigen2").className.replace("si_","no_")
	document.getElementById("lugarOrigen2").className = document.getElementById("lugarOrigen2").className.replace("si_","no_")
	document.getElementById("calleOrigen2").className = document.getElementById("calleOrigen2").className.replace("si_","no_")
	document.getElementById("pisoOrigen2").className = document.getElementById("pisoOrigen2").className.replace("si_","no_")

	//document.getElementById("fechaDestino2").className = document.getElementById("fechaDestino2").className.replace("si_","no_")
	//document.getElementById("horaDestino2").className = document.getElementById("horaDestino2").className.replace("si_","no_")
	//document.getElementById("tipoVDestino2").className = document.getElementById("tipoVDestino2").className.replace("si_","no_")
	document.getElementById("lugarDestino2").className = document.getElementById("lugarDestino2").className.replace("si_","no_")
	document.getElementById("calleDestino2").className = document.getElementById("calleDestino2").className.replace("si_","no_")
	document.getElementById("pisoDestino2").className = document.getElementById("pisoDestino2").className.replace("si_","no_")

}

function cambiarMapa(combo,idioma){
	var capa
	capa = document.getElementById("ImgMapa")
	if(combo.value==28){
		capa.src = "img/"+ idioma + "/aplicaciones/madrid.gif"
	}else{
		capa.src = "img/"+ idioma + "/aplicaciones/barcelona.gif"
	}

	capa = document.getElementById("txtMapa")
	if(combo.value==28){
		capa.innerHTML = "Madrid"
	}else{
		capa.innerHTML = "Barcelona"
	}
}

function cambiarRegimen(radio,idioma,txt){
	var capa
	capa = document.getElementById("ImgRegimen")
	if(radio.value==1){
		capa.src = "img/"+ idioma + "/aplicaciones/porHoras.gif"
	}else{
		capa.src = "img/"+ idioma + "/aplicaciones/porTraslados.gif"
	}

	var capa
	capa = document.getElementById("txtRegimen")
	capa.innerHTML = txt
}


//Modifica la apariencia del alquiler de la página de inicio
function  cambiaApariencia(oItem){

	// Quito la imagen de fondo de las llaves
	document.getElementById("a_alquilerinicio").style.backgroundImage = 'url(../../img/css/aplicaciones/fondoAlquilerInicioSelect.jpg)';

	//Añado las imágenes correspondientes
	var idCapaR = document.getElementById("divregimen");
	var idCapaP = document.getElementById("divprovincia");

	switch (oItem.value){
		// Por horas
		case "1":
			if(document.getElementById("img1")){
				document.getElementById("img1").src="img/es/aplicaciones/porHoras.gif";
				document.getElementById("img1").alt="Régimen por horas";
			}else{
				idCapaR.innerHTML = idCapaR.innerHTML + "<img src='img/es/aplicaciones/porHoras.gif' alt='Régimen por horas' id='img1'/>";
			}
			idCapaR.style.display="block";
		break;
		// Por traslados
		case "2":
			if(document.getElementById("img1")){
				document.getElementById("img1").src="img/es/aplicaciones/porTraslados.gif";
				document.getElementById("img1").alt="Régimen por traslados";
			}else{
				idCapaR.innerHTML = idCapaR.innerHTML+"<img src='img/es/aplicaciones/porTraslados.gif' alt='Régimen por traslados' id='img1'/>";
			}
			idCapaR.style.display="block";
		break;
		// Madrid
		case "28":
			if(document.getElementById("img2")){
				document.getElementById("img2").src="img/es/aplicaciones/madrid.gif";
				document.getElementById("img2").alt="Madrid";
			}else{
				idCapaP.innerHTML = idCapaP.innerHTML+"<img src='img/es/aplicaciones/madrid.gif' alt='Madrid' id='img2'/>";
			}
			idCapaP.style.display="block";
		break;
		// Barcelona
		case "8":
			if(document.getElementById("img2")){
				document.getElementById("img2").src="img/es/aplicaciones/barcelona.gif";
				document.getElementById("img2").alt="Barcelona";
			}else{
				idCapaP.innerHTML = idCapaP.innerHTML+"<img src='img/es/aplicaciones/barcelona.gif' alt='Barcelona' id='img2'/>";
			}
			idCapaP.style.display="block";
		break;
	}
}
