// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function rellenarCombos() {

 	var prod = document.getElementById("productoS").value;

	switch (prod){
		case "1":/*VENTA/ALQUILER*/
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearSelect();
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(1);
				}
				break;

		case "2":/*VENTA*/
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(2);
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(2);
				}	
				break;		

		case "3":/*ALQUILER*/
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(1);
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(3);
				}
				break;		

		case "4":/*ALQUILER*/ 
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(1);
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(4);
				}
				break;		

		case "5": /*ALQUILER*/
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(1);/*Sólo alquiler*/
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(5);
				}
				break;		

		case "6": /*VENTA*/
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(2);/*Sólo venta*/
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(6);
				}	
				break;
					
		case "7":/*VENTA*/ 
				div = document.getElementById("ventaAlquiler");
				removeAllChild(div);
				crearElemento(2);
				/*USOS*/
				div = document.getElementById("uso");
				if (div != null) {
					removeAllChild(div);
					crearComboUsos(4);
				}
				break;		
		}
}

function ocultarUsos() {

 	
	venta = document.getElementById("ventaAlquilerS").value;

	switch (venta){
		case "1":/*VENTA/ALQUILER*/
				div = document.getElementById("uso");
				removeAllChild(div);
				crearComboUsos(1);
				break;

		case "2":/*VENTA*/
				div = document.getElementById("uso");
				removeAllChild(div);
				break;		
		}
}
	
function removeAllChild(object){
	while(object.hasChildNodes()){
		object.removeChild(object.firstChild);
	}
}
	
function crearElemento(valor){
	p = document.createElement("p");
	p.setAttribute("class","solo");		
	if (valor == 1) {
		sTexto = "** Este producto sólo esta disponible para alquiler.";
	}
	else{
		sTexto = "** Este producto sólo esta disponible para venta.";
	}

	p.innerHTML = sTexto;
	div = document.getElementById("ventaAlquiler");
	div.appendChild(p);
	
	hidden= document.createElement("input");
	hidden.setAttribute("name","ventaAlquiler");
	hidden.setAttribute("id","ventaAlquilerS");
	hidden.setAttribute("onChange","javascript:ocultarUsos();")
	hidden.setAttribute("type","hidden");	
	hidden.setAttribute("value",valor);	
	div.appendChild(hidden);
	
}

function crearSelect(){
	div = document.getElementById("ventaAlquiler");
	
	/*CREO EL LABEL*/
	label = document.createElement("label");
	label.setAttribute("for", "ventaAlquiler");
	sTexto="Desea alquiler o venta";
	label.innerHTML = sTexto;
	div.appendChild(label);
	
	/*CREO EL SELECT*/
	select = document.createElement("select");
	select.setAttribute("name", "ventaAlquiler");
	select.setAttribute("id","ventaAlquilerS");
	select.setAttribute("onChange","javascript:ocultarUsos();")
	option = document.createElement("option");
	option.setAttribute("value", 1);
	option.innerHTML="Alquiler";
	select.appendChild(option);
		
	option = document.createElement("option");
	option.setAttribute("value", 2);
	option.innerHTML="Venta";
	select.appendChild(option);
	
	div.appendChild(select);
	
}

function crearComboUsos(valor){
	
	switch (valor){
		case 1:	
				div = document.getElementById("uso");
				
				/*CREO EL LABEL*/
				label = document.createElement("label");
				label.setAttribute("for", "uso");
				label.innerHTML="Seleccione el tipo de uso al que se destinará";
				div.appendChild(label);
				
				select = document.createElement("select");
				select.setAttribute("name", "uso");				
				
				/*CREO LOS OPTIONS PARA EL SELECT*/
				option = document.createElement("option");
				option.setAttribute("value", 1);
				option.innerHTML="Inauguraciones";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 2);
				option.innerHTML="Ferias/Congresos";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 3);
				option.innerHTML="Bodas/Fiestas";
				select.appendChild(option);

				option = document.createElement("option");
				option.setAttribute("value", 4);
				option.innerHTML="Conciertos";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 5);
				option.innerHTML="Pasarelas";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 6);
				option.innerHTML="Almacenamiento Industrial";
				select.appendChild(option);

				div.appendChild(select);
				break;
		case 6:
				div = document.getElementById("uso");
				
				/*CREO EL LABEL*/
				label = document.createElement("label");
				label.setAttribute("for", "uso");
				label.innerHTML="Seleccione el tipo de uso al que se destinará";
				div.appendChild(label);
				
				select = document.createElement("select");
				select.setAttribute("name", "uso");				
				
				/*CREO LOS OPTIONS PARA EL SELECT*/
				option = document.createElement("option");
				option.setAttribute("value", 1);
				option.innerHTML="Saunas";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 2);
				option.innerHTML="Cortinas divisorias";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 3);
				option.innerHTML="Equipamiento deportivo";
				select.appendChild(option);

				option = document.createElement("option");
				option.setAttribute("value", 4);
				option.innerHTML="Gradas telescópicas";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 5);
				option.innerHTML="Pavimento";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 6);
				option.innerHTML="Juegos infantiles";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 7);
				option.innerHTML="Redes";
				select.appendChild(option);
				
				option = document.createElement("option");
				option.setAttribute("value", 8);
				option.innerHTML="Tuneles telescópicos";
				select.appendChild(option);

				div.appendChild(select);
				break;		
	}
	
}
function gestionarInputsTres(objeto){
	if(objeto.checked){
		if (objeto.name=="metros"){
			document.getElementById("ancho").disabled=false;
			document.getElementById("largo").disabled=false;	
		}
		else if (objeto.name=="asistentes"){
			document.getElementById("numeroAsistentes").disabled=false;
			document.getElementById("asistentesSentados").disabled=false;
			document.getElementById("asistentesPie").disabled=false;						
		}
		else if (objeto.name == "escenario"){
			document.getElementById("metrosEscenario").disabled=false;
			document.getElementById("personasEscenario").disabled=false;	
		}
		else if (objeto.name == "cordon"){
			document.getElementById("metrosCordon").disabled=false;
		}
		else if (objeto.name == "banderas"){
			document.getElementById("numeroBanderas").disabled=false;
		}
		else if (objeto.name == "velumTecho"){
			document.getElementById("velumTechoColor").disabled=false;
		}
		else if (objeto.name == "velumLateral"){
			document.getElementById("velumLateralColor").disabled=false;
		}
		else if (objeto.name == "laterales_lona"){
			document.getElementById("numeroVentanas").disabled=false;
		}						
		else if (objeto.name == "sillas") {
						
			document.getElementById("sillasMadera").disabled = false;
			document.getElementById("sillasResinaBlanca").disabled = false;
			document.getElementById("sillasCeremonia").disabled = false;
				
			}		
	}else{
		if (objeto.name=="metros"){
			document.getElementById("ancho").disabled=true;
			document.getElementById("largo").disabled=true;	
		}
		else if (objeto.name=="asistentes"){
			document.getElementById("numeroAsistentes").disabled=true;
			document.getElementById("asistentesSentados").disabled=true;
			document.getElementById("asistentesPie").disabled=true;						
		}
		else if (objeto.name == "escenario"){
			document.getElementById("metrosEscenario").disabled=true;
			document.getElementById("personasEscenario").disabled=true;				
			}
		else if (objeto.name == "cordon"){
			document.getElementById("metrosCordon").disabled=true;
		}
		else if (objeto.name == "banderas"){
			document.getElementById("numeroBanderas").disabled=true;
		}
		else if (objeto.name == "velumTecho"){
			document.getElementById("velumTechoColor").disabled=true;
		}
		else if (objeto.name == "velumLateral"){
			document.getElementById("velumLateralColor").disabled=true;
		}
		else if (objeto.name == "laterales_lona"){
			document.getElementById("numeroVentanas").disabled=true;
		}			
		else if (objeto.name == "sillas") {
						
			document.getElementById("sillasMadera").disabled = true;
			document.getElementById("sillasResinaBlanca").disabled = true;
			document.getElementById("sillasCeremonia").disabled = true;
				
			}						
	}
}
function gestionarInputs(objeto){
	if(objeto.checked){
		//recogo el valor
		valor =	objeto.name;
		//obtengo el nombre -> tanto stands como metros que son las varialbes con las que trabajo tienen 6 silabas
		nombre = valor.substring(0, 6)
		//obtengo el numero de carpa a la que pertenece el stand
		numero = valor.substring(7);
		
		if (nombre == "stands"){
			numeroStand ="numeroStands";
			medidasStand = "medidasStands";
			document.getElementById(numeroStand).disabled=false;
			document.getElementById(medidasStand).disabled=false;	
		}
		/*else if (nombre == "metros"){
			ancho ="ancho-"+numero+"_norequerido_numero";
			largo = "largo-"+numero+"_norequerido_numero";
			document.getElementById(ancho).disabled=false;
			document.getElementById(largo).disabled=false;	
		}*/

	}else{
		//recogo el valor
		valor =	objeto.name;
		nombre = valor.substring(0, 6)
		numero = valor.substring(7);
		
		if (nombre == "stands"){
			numeroStand ="numeroStands";
			medidasStand = "medidasStands";
			document.getElementById(numeroStand).disabled=true;
			document.getElementById(medidasStand).disabled=true;	
		}/*
		else if (nombre == "metros"){
			ancho ="ancho-"+numero+"_norequerido_numero";
			largo = "largo-"+numero+"_norequerido_numero";
			document.getElementById(ancho).disabled=true;
			document.getElementById(largo).disabled=true;	
		}*/

	}
}
function gestionarInputs(objeto){
	if (objeto.checked) {
		if (objeto.name == "carpa") {
			document.getElementById("tarima").disabled = false;
			document.getElementById("moqueta").disabled = false;
			document.getElementById("iluminacion").disabled = false;
			document.getElementById("velumTecho").disabled = false;
			document.getElementById("velumLateral").disabled = false;
		}
		else 
			if (objeto.name == "metros") {
				document.getElementById("ancho").disabled = false;
				document.getElementById("largo").disabled = false;
			}
			else 
				if (objeto.name == "asistentes") {
					document.getElementById("numeroAsistentes").disabled = false;
					document.getElementById("asistentesSentados").disabled = false;
					document.getElementById("asistentesPie").disabled = false;
				}
				else 
					if (objeto.name == "sillas") {
						
						document.getElementById("lazos").disabled = false
						
						document.getElementById("sillasMadera").disabled = false;
						document.getElementById("sillasResinaBlanca").disabled = false;
						document.getElementById("sillasCeremonia").disabled = false;
						
						document.getElementById("fundaMadera").disabled = false;
						document.getElementById("fundaResinaBlanca").disabled = false;
						document.getElementById("fundaCeremonia").disabled = false;
						
						document.getElementById("colorFundaMadera").disabled = false;
						document.getElementById("colorFundaResinaBlanca").disabled = false;
						document.getElementById("colorFundaCeremonia").disabled = false;
					}
					else 
						if (objeto.name == "mesas") {
							document.getElementById("mesasRedondas").disabled = false;
							document.getElementById("mesasRectangulares").disabled = false;
						}
						else 
							if (objeto.name == "escenario") {
								document.getElementById("metrosEscenario").disabled = false;
								document.getElementById("modulosEscenario").disabled = false;
								document.getElementById("alturaEscenario").disabled = false;
							}
							else 
								if (objeto.name == "jaimas") {
									document.getElementById("jaimas44").disabled = false;
									document.getElementById("jaimas55").disabled = false;
								}
									else 
										if (objeto.name == "stands") {
											document.getElementById("numeroStands").disabled = false;
											document.getElementById("medidasStands").disabled = false;
										}
										else {
											document.getElementById("numeroStands").disabled = false;
											document.getElementById("medidasStands").disabled = false;
										}
	}
	else {
		if (objeto.name == "carpa") {
			document.getElementById("tarima").disabled = true;
			document.getElementById("moqueta").disabled = true;
			document.getElementById("iluminacion").disabled = true;
			document.getElementById("velumTecho").disabled = true;
			document.getElementById("velumLateral").disabled = true;
		}
		else if (objeto.name == "metros") {
				document.getElementById("ancho").disabled = true;
				document.getElementById("largo").disabled = true;
			}
			else if (objeto.name == "asistentes") {
					document.getElementById("numeroAsistentes").disabled = true;
					document.getElementById("asistentesSentados").disabled = true;
					document.getElementById("asistentesPie").disabled = true;
				}
				else if (objeto.name == "sillas") {
						
						document.getElementById("lazos").disabled = true
						
						document.getElementById("sillasMadera").disabled = true;
						document.getElementById("sillasResinaBlanca").disabled = true;
						document.getElementById("sillasCeremonia").disabled = true;
						
						document.getElementById("fundaMadera").disabled = true;
						document.getElementById("fundaResinaBlanca").disabled = true;
						document.getElementById("fundaCeremonia").disabled = true;
						
						document.getElementById("colorFundaMadera").disabled = true;
						document.getElementById("colorFundaResinaBlanca").disabled = true;
						document.getElementById("colorFundaCeremonia").disabled = true;
					}
					else if (objeto.name == "mesas") {
							document.getElementById("mesasRedondas").disabled = true;
							document.getElementById("mesasRectangulares").disabled = true;
						}
						else if (objeto.name == "escenario") {
								document.getElementById("metrosEscenario").disabled = true;
								document.getElementById("modulosEscenario").disabled = true;
								document.getElementById("alturaEscenario").disabled = true;
							}
							
							else if (objeto.name == "jaimas") {
									document.getElementById("jaimas44").disabled = true;
									document.getElementById("jaimas55").disabled = true;
								}
									else if (objeto.name == "stands") {
											document.getElementById("numeroStands").disabled = true;
											document.getElementById("medidasStands").disabled = true;
										}
										else {
											document.getElementById("numeroStands").disabled = true;
											document.getElementById("medidasStands").disabled = true;
										}
	}
}	

function gestionarInputsDos(objeto, indice){	
	if (objeto.checked) {
		document.getElementById("numeroStands" + indice).disabled=false;
		document.getElementById("medidasStands"+ indice).disabled=false;}
	else{
	document.getElementById("numeroStands"+ indice).disabled=true;
	document.getElementById("medidasStands"+ indice).disabled=true;		
	}
		
	}	
	
function gestionarInputsCuatro(objeto){	
	if (objeto.checked) {
			document.getElementById("alto").disabled = false;
			document.getElementById("largo").disabled = false;
			document.getElementById("ancho").disabled = false;
		}
	else {
			document.getElementById("alto").disabled = true;
			document.getElementById("ancho").disabled = true;
			document.getElementById("largo").disabled = true;
	}
		
	}	