var tipologias_vidrio_1=new Array("-")
var valores_tipologias_vidrio_1=new Array("5.7")

var tipologias_vidrio_2=new Array("selecciona","Doble 4-6-4","Doble 4-8-4","Doble 4-9-4","Doble 4-10-4","Doble 4-12-4","Doble 4-14-4","Doble 4-16-4")
var valores_tipologias_vidrio_2=new Array("-","3.3","3.1","3.05","3","2.9","2.75","2.65")

var tipologias_vidrio_3=new Array("selecciona","D. B.E. 4-6-4","D. B.E. 4-8-4","D. B.E. 4-9-4","D. B.E. 4-10-4","D. B.E. 4-12-4","D. B.E. 4-14-4","D. B.E. 4-16-4")
var valores_tipologias_vidrio_3=new Array("-","2.5","2.1","2","1.8","1.7","1.6","1.5")

var tipologias_marco_1=new Array("selecciona","SRPT / normal","RPT/aislante temperatura exterior - Entre 4 y 12 mm","RPT/aislante temperatura exterior - > 12 mm")
var valores_tipologias_marco_1=new Array("-","5.7","4","3.2")

var tipologias_marco_2=new Array("selecciona","de alta densidad","de baja densidad")
var valores_tipologias_marco_2=new Array("-","2.2","2")

var tipologias_marco_3=new Array("selecciona","2 cámaras","3 cámaras","5 cámaras")
var valores_tipologias_marco_3=new Array("-","2.2","1.8","1.3")

var provincias_clima_ORDENADOS=new Array("C","D","D","B","A","C","E","C","C","E","C","A","C","B","B","D","D","B","C","C","D","C","B","D","B","C","D","A","E","D","D","A","D","A","B","D","C","D","C","D","D","B","E","A","B","D","C","B","D","C","D","D")
var provincias_humedad_ORDENADOS=new Array("normal","alta","normal","baja","baja","normal","normal","normal","normal","alta","baja","normal","normal","baja","alta","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","baja","alta","alta","alta","normal","normal","normal","normal","normal","alta","alta","normal","alta","normal","normal","normal","baja","baja","normal","normal","baja","alta","normal","alta","normal")

var provincias_clima=new Array("D","B","A","C","E","C","C","C","E","C","A","C","B","B","D","B","D","C","C","D","B","D","B","C","C","D","A","E","D","D","D","A","A","B","C","D","D","C","D","C","A","D","B","E","B","D","C","B","D","D","D","D")
var provincias_humedad=new Array("normal","baja","baja","normal","normal","normal","normal","normal","alta","baja","normal","normal","baja","alta","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","normal","baja","alta","alta","alta","normal","normal","normal","normal","alta","alta","normal","normal","alta","normal","baja","normal","normal","normal","baja","normal","normal","baja","alta","alta","alta","normal")

// Calculadora energetica -->
function Calculadora(valor){
	
	if(valor == 1) {
		document.getElementById("CalculadoraInicio").style.display = "none";
		document.getElementById("CalculadoraActual").style.display = "block";
		document.getElementById("CalculadoraFutura").style.display = "none";
		document.getElementById("CalculadoraResultado").style.display = "none";
		window.scrollTo(0,0);
	}
	else if(valor == 2) {
		
		var indice_inicial_marco = document.CalculadoraActual.marco.selectedIndex
		var indice_inicial_vidrio = document.CalculadoraActual.vidrio.selectedIndex	
		var marco_inicial = document.CalculadoraActual.marco.options[indice_inicial_marco].value
		var vidrio_inicial = document.CalculadoraActual.vidrio.options[indice_inicial_vidrio].value
		
		if ((vidrio_inicial!="-") && (marco_inicial!="-")) {
			document.getElementById("CalculadoraInicio").style.display = "none";
			document.getElementById("CalculadoraActual").style.display = "none";
			document.getElementById("CalculadoraFutura").style.display = "block";
			document.getElementById("CalculadoraResultado").style.display = "none";
			window.scrollTo(0,0);
		}
		else
			alert("Debe seleccionar todas las opciones.")
	}
	else if(valor == 3) {

		var indice_inicial_marco = document.CalculadoraActual.marco.selectedIndex
		var indice_inicial_vidrio = document.CalculadoraActual.vidrio.selectedIndex	
		var marco_inicial = document.CalculadoraActual.marco.options[indice_inicial_marco].value
		var vidrio_inicial = document.CalculadoraActual.vidrio.options[indice_inicial_vidrio].value
		
		var indice_marco_final = document.CalculadoraFutura.tipologiaMarco.selectedIndex
		var marco_final = document.CalculadoraFutura.tipologiaMarco.options[indice_marco_final].value
		var indice_vidrio_final = document.CalculadoraFutura.tipologiaVidrio.selectedIndex
		var vidrio_final = document.CalculadoraFutura.tipologiaVidrio.options[indice_vidrio_final].value
		if ((marco_final!="-") && (vidrio_final!="-")) {

			document.getElementById("CalculadoraInicio").style.display = "none";
			document.getElementById("CalculadoraActual").style.display = "none";
			document.getElementById("CalculadoraFutura").style.display = "none";
			document.getElementById("CalculadoraResultado").style.display = "block";
			window.scrollTo(0,0);
			
			ahorro = CalculadoraCalcularAhorro(marco_inicial, vidrio_inicial,"1.3","1.7");
			document.getElementById("resultado").innerHTML = ahorro.toFixed(2)+"%";
						
			ahorro = CalculadoraCalcularAhorro(marco_inicial, vidrio_inicial, marco_final, vidrio_final)
			document.getElementById("resultado2").innerHTML = ahorro.toFixed(2)+"%";
		}
		else
			alert("Debe seleccionar todas las opciones.")		
	}
}

function CalculadoraCambiaVidrio(){
    //tomo el valor del select del vidrio
    var tipo
    tipo = document.CalculadoraFutura.tipoVidrio[document.CalculadoraFutura.tipoVidrio.selectedIndex].value
    //miro si está definido
    if (tipo != 0) {
       //si estaba definido, entonces coloco las opciones correspondientes.
       mis_tipologias_vidrio=eval("tipologias_vidrio_" + tipo)
	   mis_valores_tipologias_vidrio=eval("valores_tipologias_vidrio_" + tipo)
       //calculo el numero
       num_tipologias_vidrio = mis_tipologias_vidrio.length
       document.CalculadoraFutura.tipologiaVidrio.length = num_tipologias_vidrio
       //para cada una del array, la introduzco en el select
       for(i=0;i<num_tipologias_vidrio;i++){
          document.CalculadoraFutura.tipologiaVidrio.options[i].value=mis_valores_tipologias_vidrio[i]
          document.CalculadoraFutura.tipologiaVidrio.options[i].text=mis_tipologias_vidrio[i]
       }
    }
	else{
       //si no había  seleccionada, elimino las del select
       document.CalculadoraFutura.tipologiaVidrio.length = 1
       //coloco un guión en la única opción que he dejado
       document.CalculadoraFutura.tipologiaVidrio.options[0].value = "-"
       document.CalculadoraFutura.tipologiaVidrio.options[0].text = "-"
    }
    //marco como seleccionada la opción primera
    document.CalculadoraFutura.tipologiaVidrio.options[0].selected = true
}

function CalculadoraCambiaMarco(){
    var tipo
    tipo = document.CalculadoraFutura.tipoMarco[document.CalculadoraFutura.tipoMarco.selectedIndex].value
    if (tipo != 0) {
       //si estaba definido, entonces coloco las opciones correspondientes.
       mis_tipologias_marco=eval("tipologias_marco_" + tipo)
	   mis_valores_tipologias_marco=eval("valores_tipologias_marco_" + tipo)
       //calculo el numero
       num_tipologias_marco = mis_tipologias_marco.length
       document.CalculadoraFutura.tipologiaMarco.length = num_tipologias_marco
       //para cada una del array, la introduzco en el select
       for(i=0;i<num_tipologias_marco;i++){
          document.CalculadoraFutura.tipologiaMarco.options[i].value=mis_valores_tipologias_marco[i]
          document.CalculadoraFutura.tipologiaMarco.options[i].text=mis_tipologias_marco[i]
       }
    }
	else{
       //si no había  seleccionada, elimino las del select
       document.CalculadoraFutura.tipologiaMarco.length = 1
       //coloco un guión en la única opción que he dejado
       document.CalculadoraFutura.tipologiaMarco.options[0].value = "-"
       document.CalculadoraFutura.tipologiaMarco.options[0].text = "-"
    }
    //marco como seleccionada la opción primera
    document.CalculadoraFutura.tipologiaMarco.options[0].selected = true
}

function CalculadoraCalcularAhorro (marco_inicial, vidrio_inicial, marco_final, vidrio_final) {
	var n_aislamiento_ventana_inicial = (marco_inicial * 0.3) + (vidrio_inicial * 0.7)
	var n_aislamiento_ventana_final = (marco_final * 0.3) + (vidrio_final * 0.7)
	var gasto_energetico = (n_aislamiento_ventana_final / n_aislamiento_ventana_inicial) * 100

	var ahorro_energetico = 100 - gasto_energetico
	return ahorro_energetico;
}
// /Calculadora energetica -->

// Test acustica -->

function TestAcustica(valor) {
	// var ext = false, intern = false;
	var ext = 1000, intern = 1000;

	if(valor == 1) {
		document.getElementById("TestAcusticaInicio").style.display = "none";
		document.getElementById("TestAcusticaCondiciones").style.display = "block";
		window.scrollTo(0,0);
	}
	if(valor == 2) {
		// Variable Condiciones Exteriores
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
		else
			alert("Tiene que seleccionar las condiciones exteriores.");
		// Variable Condiciones Interiores
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_0")) && obj.checked)
			intern = 0;
		else
			alert("Tiene que seleccionar las condiciones interiores.");
	
		
		if((intern!=1000) && (ext!=1000)){

			//Calculo la diferencia entre condiciones externas y aislamiento
			dif = ext - intern;
			//Reducción sugerida
			red_sugerida = dif - 30;

			document.getElementById("TestAcusticaCondiciones").style.display = "none";
			
			// document.getElementById("nivel_1").style.display = "none";
			// document.getElementById("nivel_2").style.display = "none";
			// document.getElementById("nivel_3").style.display = "none";
			// document.getElementById("nivel_4").style.display = "none";
			// document.getElementById("nivel_5").style.display = "none";
			// document.getElementById("nivel_6").style.display = "none";

			if((dif -30) > 0) {
				//Escondo todos los textos
				document.getElementById("TestAcusticaDiagnostico").style.display = "block";
				document.getElementById("TestAcusticaResultadoDiagnostico").innerHTML = dif+"dB";
				document.getElementById("TestAcusticaResultadoDiagnosticoSugerido").innerHTML = red_sugerida+"dB";
				window.scrollTo(0,0);
			}
			else {
				document.getElementById("TestAcusticaDiagnosticoNegativo").style.display = "block";
				window.scrollTo(0,0);
			}		
		}
	}

	if(valor == 3) {
		document.getElementById("TestAcusticaDiagnostico").style.display = "none";
		document.getElementById("TestAcusticaSugerencia").style.display = "block";
		window.scrollTo(0,0);
	}


	if(valor == 4) {
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
			
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_0")) && obj.checked)
			intern = 0;
		
		dif = ext - intern;
	
		document.getElementById("TestAcusticaSugerencia").style.display = "none";
		document.getElementById("TestAcusticaMejoras").style.display = "block";
		
	//Mejoras recomendadas. 
	//Primero, dejo todas como estaban originalmente	
		document.getElementById("caso_1").style.display = "none";
		document.getElementById("caso_2").style.display = "none";
		document.getElementById("caso_3").style.display = "none";
		document.getElementById("caso_4").style.display = "none";
		document.getElementById("consultar_especialista").style.display = "none";
		window.scrollTo(0,0);
		
	//Segundo, en función de la condición interna, se esconden o se muestran las especificadas
		switch(intern){
			case 28: document.getElementById("caso_1").style.display = "block";break;
			case 30: document.getElementById("caso_2").style.display = "block";break;
					 document.getElementById("caso_3").style.display = "block";break;
			case 35: document.getElementById("caso_4").style.display = "block";break;
			default: document.getElementById("consultar_especialista").style.display = "block";break;
		}
	}		
}

function TestAcusticav3(valor) {
	// var ext = false, intern = false;
	var ext = 1000, intern = 1000, persiana = 1000, tipo_ventana = 0, tipo_persiana = 0;

	if(valor == 1) {
		document.getElementById("TestAcusticaInicio").style.display = "none";
		document.getElementById("TestAcusticaCondiciones").style.display = "block";
		window.scrollTo(0,0);
	}
	if(valor == 2) {
		// Variable Condiciones Exteriores
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
		else
			alert("Tiene que seleccionar las condiciones exteriores.");
		// Variable Condiciones Interiores
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_39")) && obj.checked)
			intern = 39;
		else
			alert("Tiene que seleccionar las condiciones interiores.");
		
		// Variable Persianas
		if( (obj = document.getElementById("persiana_1")) && obj.checked)
			persiana = 0;
		else if( (obj = document.getElementById("persiana_2")) && obj.checked)
			persiana = -5;
		else if( (obj = document.getElementById("persiana_3")) && obj.checked)
			persiana = 1;
		else if( (obj = document.getElementById("persiana_4")) && obj.checked)
			persiana = 1;
		else
			alert("Tiene que seleccionar un tipo de persiana.");
		
		if((intern!=1000) && (ext!=1000) && (persiana!=1000)){

			//Calculo la diferencia entre condiciones externas y aislamiento
			dif = ext - intern + persiana;
			//Reducción sugerida
			red_sugerida = dif - 30;

			document.getElementById("TestAcusticaCondiciones").style.display = "none";

			if((dif -30) > 0) {
				//Escondo todos los textos
				document.getElementById("TestAcusticaDiagnostico").style.display = "block";
				document.getElementById("TestAcusticaResultadoDiagnostico").innerHTML = dif+"dB";
				document.getElementById("TestAcusticaResultadoDiagnosticoSugerido").innerHTML = red_sugerida+"dB";
				window.scrollTo(0,0);
			}
			else {
				document.getElementById("TestAcusticaDiagnosticoNegativo").style.display = "block";
				window.scrollTo(0,0);
			}		
		}
	}

	if(valor == 3) {
		
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			tipo_ventana = 1;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			tipo_ventana = 2;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			tipo_ventana = 3;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			tipo_ventana = 4;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			tipo_ventana = 5;
		else if( (obj = document.getElementById("cond_int_39")) && obj.checked)
			tipo_ventana = 6;

		// Variable Persianas
		if( (obj = document.getElementById("persiana_1")) && obj.checked)
			tipo_persiana = 1;
		else if( (obj = document.getElementById("persiana_2")) && obj.checked)
			tipo_persiana = 2;
		else if( (obj = document.getElementById("persiana_3")) && obj.checked)
			tipo_persiana = 3;
		else if( (obj = document.getElementById("persiana_4")) && obj.checked)
			tipo_persiana = 4;
		
		//Consejos. 
		//Primero, dejo todas como estaban originalmente	
			document.getElementById("tipo_ventanas_caso_1").style.display = "none";
			document.getElementById("tipo_ventanas_caso_2").style.display = "none";
			document.getElementById("tipo_persianas_caso_1").style.display = "none";
			window.scrollTo(0,0);

		//Segundo, en función de la condición interna, se esconden o se muestran las especificadas
			switch(tipo_ventana){
				case 1: document.getElementById("tipo_ventanas_caso_1").style.display = "block";break;
				case 2: document.getElementById("tipo_ventanas_caso_1").style.display = "block";break;
				case 3: document.getElementById("tipo_ventanas_caso_1").style.display = "block";break;
				case 4: document.getElementById("tipo_ventanas_caso_1").style.display = "block";break;
				case 5: document.getElementById("tipo_ventanas_caso_2").style.display = "block";break;
				case 6: document.getElementById("tipo_ventanas_caso_2").style.display = "block";break;
			}
			switch(tipo_persiana){
				case 2: document.getElementById("tipo_persianas_caso_1").style.display = "block";break;
			}
		
		document.getElementById("TestAcusticaDiagnostico").style.display = "none";
		document.getElementById("TestAcusticaSugerencia").style.display = "block";
		window.scrollTo(0,0);
	}


	if(valor == 4) {
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
			
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_39")) && obj.checked)
			intern = 39;

		// Variable Persianas
		if( (obj = document.getElementById("persiana_1")) && obj.checked)
			persiana = 0;
		else if( (obj = document.getElementById("persiana_2")) && obj.checked)
			persiana = -5;
		else if( (obj = document.getElementById("persiana_3")) && obj.checked)
			persiana = 1;
		else if( (obj = document.getElementById("persiana_4")) && obj.checked)
			persiana = 1;
		
		//Calculo la diferencia entre condiciones externas y aislamiento
		dif = ext - intern + persiana;
		//Reducción sugerida
		red_sugerida = dif - 30;
		
		document.getElementById("ReduccionSugerida").innerHTML ="Si reduces los "+red_sugerida+"dB que te recomendamos, percibirás una cuarta parte del ruido.";
			
		document.getElementById("TestAcusticaSugerencia").style.display = "none";
		document.getElementById("TestAcusticaMejoras").style.display = "block";
		
	}		
}

function test(valor) {
	// var ext = false, intern = false;
	var ext = 1000, intern = 1000;

	if(valor == 1) {
		document.getElementById("inicio").style.display = "none";
		document.getElementById("formulario").style.display = "block";
	}
	if(valor == 2) {
	//Lectura de los radio input
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
		else
			alert("Tiene que seleccionar las condiciones exteriores.");
	
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_0")) && obj.checked)
			intern = 0;
		else
			alert("Tiene que seleccionar las condiciones interiores.");
	}	
	//Si están seleccionados ambos radio input (es decir, si hemos dado a intern y ext un valor numérico):
	// if(!isNaN(intern) && !isNaN(ext)){
	if((intern!=1000) && (ext!=1000) && valor == 2){
		
		//Calculo la diferencia entre condiciones externas y aislamiento
		dif = ext - intern;
		
		document.getElementById("nivel_1").style.display = "none";
		document.getElementById("nivel_2").style.display = "none";
		document.getElementById("nivel_3").style.display = "none";
		document.getElementById("nivel_4").style.display = "none";
		document.getElementById("nivel_5").style.display = "none";
		document.getElementById("nivel_6").style.display = "none";
		document.getElementById("formulario").style.display = "none";
		
		if((dif -30) > 0) {
			//Escondo todos los textos
			document.getElementById("diagnostico").style.display = "block";
			document.getElementById("resultado_diagnostico").style.display = "block";
			document.getElementById("resultado_diagnostico").innerHTML = "<span class='resaltado_test'>"+dif+"dB</span>";
		}
		else {
			document.getElementById("diagnostico_valor_negativo").style.display = "block";
		}		
	}	

	if(valor == 3) {
		document.getElementById("diagnostico").style.display = "none";
		document.getElementById("resultado_diagnostico").style.display = "none";
		
		//Reducción sugerida
		red_sugerida = dif - 30;
		document.getElementById("sugerimos").style.display = "block";
		document.getElementById("resultado_sugerimos").style.display = "block";
		document.getElementById("resultado_sugerimos").innerHTML = "<span class='resaltado_test'>"+red_sugerida+"dB</span>";				
	}


	if(valor == 4) {
		if( (obj = document.getElementById("cond_ext_20")) && obj.checked)
			ext = 20;
		else if( (obj = document.getElementById("cond_ext_30")) && obj.checked)
			ext = 30;
		else if( (obj = document.getElementById("cond_ext_40")) && obj.checked)
			ext = 40;
		else if( (obj = document.getElementById("cond_ext_50")) && obj.checked)
			ext = 50;
		else if( (obj = document.getElementById("cond_ext_60")) && obj.checked)
			ext = 60;
		else if( (obj = document.getElementById("cond_ext_70")) && obj.checked)
			ext = 70;
		else if( (obj = document.getElementById("cond_ext_80")) && obj.checked)
			ext = 80;
		else if( (obj = document.getElementById("cond_ext_90")) && obj.checked)
			ext = 90;
		else if( (obj = document.getElementById("cond_ext_100")) && obj.checked)
			ext = 100;
			
		if( (obj = document.getElementById("cond_int_25")) && obj.checked)
			intern = 25;
		else if( (obj = document.getElementById("cond_int_28")) && obj.checked)
			intern = 28;
		else if( (obj = document.getElementById("cond_int_30")) && obj.checked)
			intern = 30;
		else if( (obj = document.getElementById("cond_int_31")) && obj.checked)
			intern = 31;
		else if( (obj = document.getElementById("cond_int_35")) && obj.checked)
			intern = 35;
		else if( (obj = document.getElementById("cond_int_0")) && obj.checked)
			intern = 0;
		
		dif = ext - intern;
	
	
		document.getElementById("sugerimos").style.display = "none";	
		document.getElementById("resultado_sugerimos").style.display = "none";
		document.getElementById("resultados").style.display = "block";
		
	//Mejoras recomendadas. 
	//Primero, dejo todas como estaban originalmente	
		document.getElementById("caso_1").style.display = "none";
		document.getElementById("caso_2").style.display = "none";
		document.getElementById("caso_3").style.display = "none";
		document.getElementById("caso_4").style.display = "none";
		document.getElementById("mejoras").style.display = "block";
		document.getElementById("consultar_especialista").style.display = "none";
		
	//Segundo, en función de la condición interna, se esconden o se muestran las especificadas
		switch(intern){
			case 28: document.getElementById("caso_1").style.display = "block";break;
			case 30: document.getElementById("caso_2").style.display = "block";break;
					 document.getElementById("caso_3").style.display = "block";break;
			case 35: document.getElementById("caso_4").style.display = "block";break;
			default: document.getElementById("mejoras").style.display = "none";
					 document.getElementById("consultar_especialista").style.display = "block";break;
		}
	}		
}

// /Test acustica -->


function adaptado_respuestas(valor) {
	if(valor == 2){
		var provincia = document.grupo_1.provincias[document.grupo_1.provincias.selectedIndex].value;
		var clima = provincias_clima[provincia];
		var humedad = provincias_humedad[provincia];
		var resultado_clima = "";
		var resultado_humedad = "";
		
		var nombre_provincia = document.grupo_1.provincias[document.grupo_1.provincias.selectedIndex].text;
        
		document.getElementById("nombres_provincia").innerHTML = "Empresas saludables en "+nombre_provincia+":";

		switch(clima){
			case "A": resultado_clima = "Vives en una provincia con baja necesidad aislamiento."; break;
			case "B": resultado_clima = "Vives en una provincia con baja necesidad aislamiento."; break;
			case "C": resultado_clima = "Vives en una provincia con media necesidad aislamiento."; break;
			case "D": resultado_clima = "Vives en una provincia con alta necesidad aislamiento."; break;
			case "E": resultado_clima = "Vives en una provincia con máxima necesidad aislamiento."; break;
			default: resultado_clima = ""; break;
		}
		switch(humedad){
			case "alta": resultado_humedad = "Es posible que tengas problemas de humedad y condensación en tu provincia. Para evitar este problema te recomendamos que prestes especial atención a la hermeticidad de tus ventanas eligiendo sistemas de apertura abatible."; break;
			default: resultado_humedad = ""; break;
		}
		if (resultado_clima=="")
			document.getElementById("respuestas_clima").style.display = "none";
		else
			document.getElementById("respuestas_clima").innerHTML = resultado_clima;
			
		if (resultado_humedad=="")
			document.getElementById("respuestas_humedad").style.display = "none";
		else
			document.getElementById("respuestas_humedad").innerHTML = resultado_humedad;
	}
	else if(valor == 3){
		var zona = document.grupo_1.zona[document.grupo_1.zona.selectedIndex].value;
		var resultado_zona = "";
		
		switch(zona){
			case "costa": resultado_zona = "En las zonas de costa las ventanas sufren un mayor corrosión y deterioro, por eso es recomendable el uso de materiales resistentes como el PVC."; break;
			case "montaña": resultado_zona = "En las zonas de montaña hay que prestar un especial interés en el aislamiento térmico"; break;
			default: resultado_zona = ""; break;
		}
			if (resultado_zona=="")
				document.getElementById("respuestas_zona").style.display = "none";
			else
				document.getElementById("respuestas_zona").innerHTML = resultado_zona;
	}
	else if(valor == 4){
		var orientacion = document.grupo_1.orientacion[document.grupo_1.orientacion.selectedIndex].value;
		var resultado_orientacion = "";
		
		switch(orientacion){
			case "Fsolar": resultado_orientacion = "Las viviendas con orientación sur deberían tener ventanas con cristales con factor solar de protección."; break;
			case "Aislamiento térmico +": resultado_orientacion = "Las viviendas con orientación norte tienen una máxima necesidad aislamiento."; break;
			default: resultado_orientacion = ""; break;
		}
		if (resultado_orientacion=="")
			document.getElementById("respuestas_orientacion").style.display = "none";
		else
			document.getElementById("respuestas_orientacion").innerHTML = resultado_orientacion;
	}
	else if(valor == 6){
		var zona_residencia = document.grupo_2.zona_residencia[document.grupo_2.zona_residencia.selectedIndex].value;
		var resultado_zona_residencia = "";
		
		switch(zona_residencia){
			case "R1": resultado_zona_residencia = "En una zona como la tuya, la hermeticidad para no permitir entrada de polvo y ruido es muy importante, para lo que te recomendamos sistemas abatibles en tus ventanas."; break;
			case "Seguridad": resultado_zona_residencia = "En zonas aisladas recomendamos el uso de sistemas de seguridad en tus ventanas o puertas, como los mecanismos antirrobos o los herrajes reforzados."; break;
			default: resultado_zona_residencia = ""; break;
		}
		if (resultado_zona_residencia=="")
			document.getElementById("respuestas_zona_residencia").style.display = "none";
		else
			document.getElementById("respuestas_zona_residencia").innerHTML = resultado_zona_residencia;
	}
	else if(valor == 7){
		var tipo_residencia = document.grupo_2.tipo_residencia.selectedIndex;
		var resultado_tipo_residencia ="";
		
		switch(tipo_residencia){
			case 1: resultado_tipo_residencia = "Al vivir en un piso tan alto, tu vivienda se verá afectada por el viento, te aconsejamos que te fijes en la resistencia del sistema de apertura de tus ventanas y puertas."; break;
			case 2: resultado_tipo_residencia = ""; break;
			case 3: resultado_tipo_residencia = "En primeras plantas y pisos bajos recomendamos el uso de sistemas de seguridad en ventanas y puertas, como los mecanismos antirrobos o los herrajes reforzados."; break;
			case 4: resultado_tipo_residencia = "En bungalows, adosados o pareados recomendamos el uso de sistemas de seguridad en ventanas y puertas, como los mecanismos antirrobos o los herrajes reforzados."; break;
			case 5: resultado_tipo_residencia = "En viviendas independientes recomendamos el uso de sistemas de seguridad en ventanas y puertas, como los mecanismos antirrobos o los herrajes reforzados."; break;
			default: resultado_tipo_residencia = ""; break;
		}
		if (resultado_tipo_residencia=="")
			document.getElementById("respuestas_tipo_residencia").style.display = "none";
		else
			document.getElementById("respuestas_tipo_residencia").innerHTML = resultado_tipo_residencia;
	}
}

function devuelve_empresas_provincia (valor_provincia) {
	var url_empresa_ajax=$('#url_plugin_empresa_ajax').val();
	
	var datos = "provincia="+valor_provincia;
	$.ajax({
	       url: url_empresa_ajax+"tabla_empresas.php",
	       beforeSend: function(objeto){
	           //se puede añadir algo para mostrar mientras se recuperand los datos

	       },
	       contentType: "application/x-www-form-urlencoded",
	       data: datos,
	       error: function(objeto, error, error_adicional){
	           alert("Se ha producido un error "+error);
	       },
	       global: true,
	       success: function(data){
	                       $('#cargar_tabla').html(data);
	       },
	       type: "POST"
	});
}

function adaptado (valor) {
	var index_provincia = document.grupo_1.provincias.selectedIndex;
	var provincia = document.grupo_1.provincias[index_provincia].value;
	var index_zona = document.grupo_1.zona.selectedIndex;
	var zona = document.grupo_1.zona[index_zona].value;
	var index_orientacion = document.grupo_1.orientacion.selectedIndex;
	var orientacion = document.grupo_1.orientacion[index_orientacion].value;
	var zona_residencia = document.grupo_2.zona_residencia[document.grupo_2.zona_residencia.selectedIndex].value;
	var tipo_residencia = document.grupo_2.tipo_residencia[document.grupo_2.tipo_residencia.selectedIndex].value;
	
	if(valor == 0){
		document.getElementById("comenzar").style.display = "none";
		document.getElementById("grupo_1").style.display = "block";
		document.getElementById("resumen").style.display = "none";
		document.getElementById("grupo_2").style.display = "none";
		document.getElementById("resultado").style.display = "none";
	}
	
	else if((valor == 9)&&(provincia!="-")&&(zona!="-")&&(orientacion!="-")){
		document.getElementById("comenzar").style.display = "none";
		document.getElementById("grupo_1").style.display = "none";
		document.getElementById("resumen").style.display = "block";
		document.getElementById("grupo_2").style.display = "none";
		document.getElementById("resultado").style.display = "none";
	}
	
	else if(valor == 8){
		document.getElementById("comenzar").style.display = "none";
		document.getElementById("grupo_1").style.display = "none";
		document.getElementById("resumen").style.display = "none";
		document.getElementById("grupo_2").style.display = "block";
		document.getElementById("resultado").style.display = "none";
	}
	else if(valor == 10){
		document.getElementById("ctmodal").style.display = "block";	
		document.getElementById("modal1").style.display = "block";
		document.getElementById("modal2").style.display = "none";	
		
			
	}
	else if(valor == 11){
		document.getElementById("ctmodal").style.display = "block";	
		document.getElementById("modal2").style.display = "block";
		document.getElementById("modal1").style.display = "none";
	}
	else if((valor == 7)&&(tipo_residencia!="-")) {
		document.getElementById("comenzar").style.display = "none";
		document.getElementById("grupo_1").style.display = "none";
		document.getElementById("resumen").style.display = "none";
		document.getElementById("grupo_2").style.display = "none";
		document.getElementById("resultado").style.display = "block";
		document.getElementById("ctmodal").style.display = "none";	
	}
	
	else if((valor == 1)&&(zona_residencia!="-")&&(tipo_residencia!="-")){
		
		document.getElementById("comenzar").style.display = "none";
		document.getElementById("provincias").style.display = "block";
		document.getElementById("zona").style.display = "none";
		document.getElementById("orientacion").style.display = "none";
		document.getElementById("resumen").style.display = "none";
		document.getElementById("zona_residencia").style.display = "none";
		document.getElementById("tipo_residencia").style.display = "none";
		document.getElementById("resultado").style.display = "none";		
	}
	else if((valor == 2)&&(provincia!="-")) {
		document.getElementById("provincias").style.display = "none";
		document.getElementById("zona").style.display = "block";
	}
	else if((valor == 3)&&(zona!="-")) {
		document.getElementById("zona").style.display = "none";
		document.getElementById("orientacion").style.display = "block";
	}
	else if((valor == 4)&&(orientacion!="-")) {

		document.getElementById("orientacion").style.display = "none";
		document.getElementById("resumen").style.display = "block";
	}
	else if(valor == 5) {
		document.getElementById("resumen").style.display = "none";
		document.getElementById("zona_residencia").style.display = "block";
	}
	else if((valor == 6)&&(zona_residencia!="-")) {
		document.getElementById("zona_residencia").style.display = "none";
		document.getElementById("tipo_residencia").style.display = "block";
	}
	else
		alert("Debe seleccionar una opción.")
	
	if (valor == 7) {
		var resultado_ventana ="";
		var resultado_adicional_ventana = "";
		var resultado_herraje = "";
		var resultado_vidrio = "";
		var resultado_adicional_vidrio = "";


		var clima = provincias_clima[provincia];		
		var humedad = provincias_humedad[provincia];
		
		
		var resultado_ventana ="";		
		var resultado_aireador = "";
		var resultado_vidrio_tratamiento = "";
		var resultado_vidrio_composicion = "";
		
		// ventana
		if ((clima == "A") || (clima=="B")) { //Premiline
			resultado_ventana = " Sistema Premiline/Eurodur ";
			tipo_modal=1;
			
			//vidreo tratamiento
			if (orientacion=="norte")
				resultado_vidrio_tratamiento = " sin tratamiento térmico "
			else if ((orientacion=="sur") || (orientacion=="este-oeste"))
				resultado_vidrio_tratamiento = " control solar "
			
			//vidrio composicion
			if (zona_residencia == "Acustico")
				resultado_vidrio_composicion = " 6/10/4 ";
			else if (zona_residencia == "No acustico")
				resultado_vidrio_composicion = " 4/10/4 ";
			
			if (tipo_residencia == "Seguridad")
				resultado_vidrio_composicion += " +4 laminado ";
				
			
		}
		else if (clima == "C") { //Eurodur
			resultado_ventana = " Sistema Eurodur/Eurofutur ";	
			tipo_modal=2;
			
			//vidreo tratamiento
			if (orientacion=="norte")
				if (zona == "montaña")
					resultado_vidrio_tratamiento = " bajo emisivo "
				else if (zona == "interior")
					resultado_vidrio_tratamiento = " bajo emisivo "
				else if (zona == "costa")
					resultado_vidrio_tratamiento = " sin tratamiento térmico "	
			else if ((orientacion=="sur") || (orientacion=="este-oeste"))
				if (zona == "montaña")
					resultado_vidrio_tratamiento = " sin tratamiento térmico "
				else if (zona == "interior")
					resultado_vidrio_tratamiento = " control solar "
				else if (zona == "costa")
					resultado_vidrio_tratamiento = " control solar "
			
			//vidrio composicion
			if (zona_residencia == "Acustico")
				resultado_vidrio_composicion = " 6/12/4 ";
			else if (zona_residencia == "No acustico")
				resultado_vidrio_composicion = " 4/12/4 ";

			if (tipo_residencia == "Seguridad")
				resultado_vidrio_composicion += " +4 laminado ";							
		}
		else if ((clima == "D") || (clima=="E")) { //Eurofutur
			resultado_ventana = " Sistema Eurofutur ";
			tipo_modal=2;
			
			//vidreo tratamiento
			resultado_vidrio_tratamiento = " bajo emisivo ";
			
			//vidrio composicion
			if (zona_residencia == "Acustico")
				resultado_vidrio_composicion = " 6/16/4 ";
			else if (zona_residencia == "No acustico")
				resultado_vidrio_composicion = " 4/16/4 ";
			
			if (tipo_residencia == "Seguridad")
				resultado_vidrio_composicion += " +4 laminado ";
		}
		
		//aireador
		if (humedad == "alta") { // con aireador
			resultado_aireador =" y aireador incorporado ";
		}
		
		
		resultado_texto = "<p>"+resultado_ventana+" de "+resultado_vidrio_composicion+" con un vidrio "+resultado_vidrio_tratamiento+resultado_aireador+"</p><span>&nbsp;</span>";
		document.getElementById("resultados_texto").innerHTML = resultado_texto;
		resultado_texto2 = "<p>"+resultado_ventana+" de "+resultado_vidrio_composicion+" con un vidrio "+resultado_vidrio_tratamiento+resultado_aireador+" con forma de apertura oscilo-batiente</p><span>&nbsp;</span>";
		document.getElementById("resultados_texto2").innerHTML = resultado_texto2;
		
		if (tipo_modal==1) {
			document.getElementById("premiline").style.display = "block";
			document.getElementById("eurofutur").style.display = "none";
		}
		else {
			document.getElementById("premiline").style.display = "none";
			document.getElementById("eurofutur").style.display = "block";
		}
		
		
		
		
		if ((clima == "A") || (clima=="B")) {
			resultado_ventana = "Ventana de PVC corredera - Sistema Premiline";
		}
		else if ((clima == "C") && (humedad == "normal")) {
			resultado_ventana = "Ventana de PVC osciloparalela - Sistema Eurodur.";
			resultado_ventana+= "<br> Puerta de PVC corredera grandes dimensiones - Premidoor.";
			
		}
		else if ((clima == "C") && (humedad == "alta")) {
			resultado_ventana = "Ventana de PVC 3 cámaras - Sistema Eurodur";
		}
		else if ( ((clima == "D") && (humedad == "normal")) || ((clima == "D") && (humedad == "alta") && (zona == "montaña")) || ((clima == "D") && (humedad == "alta") && (orientacion == "Aislamiento térmico +")) ) {
			resultado_ventana = "Ventana de PVC osciloparalela - Sistema EuroFutur";
		}
		else if ( ((clima == "D") && (humedad == "normal")) || ((clima == "D") && (humedad == "alta")) || ((clima == "E") && (humedad == "normal")) || 
		((clima == "E") && (humedad == "alta") && (zona == "montaña")) || ((clima == "E") && (humedad == "alta") && (orientacion == "Aislamiento térmico +")) ) {
			resultado_ventana+= "<br> Ventana de PVC oscilobatiente 5 cámaras - Sistema EuroFutur";
		}
		
		// ventana adicional
		if (((zona_residencia == "R1") && (tipo_residencia == "Seguridad")) ||  (zona_residencia == "R2")) {
			resultado_adicional_ventana = "Además te recomendamos persianas motorizadas en tus puertas y ventanas.";
		}
		else if ((zona == "montaña") && (humedad == "alta")) {
			resultado_adicional_ventana = "Te recomendamos disponer de aireadores.";
			
		}
		
		// herraje
		if ((zona_residencia == "Seguridad") || (tipo_residencia == "Seguridad")) {
			resultado_herraje = "Para una mayor seguridad, incorpora en tus ventanas y puertas herrajes reforzados.";
			resultado_herraje+= "<br> No dudes en incorporar mecanismos antirrobos para tu seguridad.";
		}
		
		// vidrio
		if ((clima == "A") && (humedad == "normal")) {
			resultado_vidrio = "Vidrio doble con cámara 6 mm";
		}
		else if ((clima == "B") && (humedad == "alta")) {
			resultado_vidrio = "Vidrio doble con cámara 12 mm";
		}
		else if (((clima == "C") && (humedad == "alta")) || ((clima == "D") && (humedad == "normal"))) {
			resultado_vidrio = "Vidrio doble BE con cámara 6 mm";
		}
		else if (((clima == "D") && (humedad == "alta")) || ((clima == "E") && (humedad == "normal"))) {
			resultado_vidrio = "Vidrio doble BE con cámara 12 mm";
		}
		
		//vidrio adicional
		if ((zona_residencia == "Seguridad") || (tipo_residencia == "Seguridad")) {
			resultado_adicional_vidrio = "Para mayor seguridad, te recomendamos que los vidrios también sean laminados.";	
		}
		else if (orientacion == "Fsolar") {
			resultado_adicional_vidrio = "Te aconsejamos que los vidrios también tengan filtro solar.";	
		}
		else if (zona_residencia == "R") {
			resultado_adicional_vidrio = "Para evitar el ruido, pon vidrios laminados con tratamiento acústico en tus ventanas.";	
		}
		else if ((zona_residencia == "R2") || ((zona_residencia == "R1") && (tipo_residencia == "Seguridad"))) {
			resultado_adicional_vidrio = "Protégete e instala vidrios con gases nobles.";	
		}
	    
		// document.getElementById("resultado_ventana").style.display = "block";
		// document.getElementById("resultado_ventana").innerHTML = "<span class=''>"+resultado_ventana+"</span>";
		// document.getElementById("resultado_adicional_ventana").style.display = "block";
		// document.getElementById("resultado_adicional_ventana").innerHTML = "<span class=''>"+resultado_adicional_ventana+"</span>";
		// 
		// document.getElementById("resultado_herraje").style.display = "block";
		// document.getElementById("resultado_herraje").innerHTML = "<span class=''>"+resultado_herraje+"</span>";
		// 	
		// document.getElementById("resultado_vidrio").style.display = "block";
		// document.getElementById("resultado_vidrio").innerHTML = "<span class=''>"+resultado_vidrio+"</span>";
		// document.getElementById("resultado_adicional_vidrio").style.display = "block";
		// document.getElementById("resultado_adicional_vidrio").innerHTML = "<span class=''>"+resultado_adicional_vidrio+"</span>";
		
		devuelve_empresas_provincia(provincia);
	}
	
}


