﻿function ___mostrar_capa(nombreCapa, numero_capas){
	
	for(i=1;i<numero_capas+1;i++){
		if (document.getElementById('question_'+i) != null)
			document.getElementById('question_'+i).style.display="none";
		
	}

	document.getElementById(nombreCapa).style.display="";

}
		 
function actualizaDireccionEnvio()
					{
						var sede=document.getElementById('sedeDeEnvioDeCorreo').value;									
						if(sede=="Picanya (Valencia)")
						{		
							document.getElementById('direccionDeEnvioDeCorreo').value="picanya@apila.es, info@apila.es";							
//document.getElementById('direccionDeEnvioDeCorreo').value="sbadal@demini.com"							
						}
						else if(sede=="Quart de Poblet (Valencia)")
						{									
							document.getElementById('direccionDeEnvioDeCorreo').value="quart@apila.es, info@apila.es";										
//document.getElementById('direccionDeEnvioDeCorreo').value="vgimeno@demini.com"						
						}
						else if(sede=="Zaragoza")
						{															
							document.getElementById('direccionDeEnvioDeCorreo').value="cogullada@apila.es, info@apila.es";
							//document.getElementById('direccionDeEnvioDeCorreo').value="ediaz@demini.com"													
						}
					}

function comprobarComo()
					{
						var como=document.getElementById('comoConocido').value;									
						var elemento = document.getElementById("otrosOculto");
						if(como=="Otros")
						{		
							document.getElementById('otrosOculto').value="Introduzca cómo nos ha conocido";

							elemento.style.visibility = 'visible';
						} else {
							elemento.style.visibility = 'hidden';
						}					
					}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
   /* IN - num:            the number to be formatted
           decimalNum:     the number of decimals after the digit
           bolLeadingZero: true / false to use leading zero
           bolParens:      true / false to use parenthesis for - num

      RETVAL - formatted number
   */
   {
       var tmpNum = num;

       // Return the right number of decimal places
       tmpNum *= Math.pow(10,decimalNum);
       tmpNum = Math.floor(tmpNum);
       tmpNum /= Math.pow(10,decimalNum);

       var tmpStr = new String(tmpNum);

       // See if we need to hack off a leading zero or not
       if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
           if (num > 0)
               tmpStr = tmpStr.substring(1,tmpStr.length);
           else
               // Take out the minus sign out (start at 2)
               tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


       // See if we need to put parenthesis around the number
       if (bolParens && num < 0)
           tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";


       return tmpStr;
   }



function validarEntero(valor){ 
      //intento convertir a entero. 
     //si era un entero no le afecta, si no lo era lo intenta convertir 
     valor = parseInt(valor) 

      //Compruebo si es un valor numerico 
      if (isNaN(valor)) { 
            //entonces (no es numero) devuelvo el valor cadena vacia 
            return false
      }else{ 
            //En caso contrario (Si era un numero) devuelvo el valor 
            return valor 
      } 
} 



function calcula(){



if (validarEntero(document.forms[0].unidades.value)){
  var indice = document.forms[0].tamano.selectedIndex ;
  var caja= document.forms[0].tamano.options[indice].value;
  var uds = validarEntero(document.forms[0].unidades.value);

document.forms[0].acumulado.value = document.forms[0].acumulado.value+uds+' '+document.forms[0].tamano.options[indice].text+'\n';

document.forms[0].m2h.value = FormatNumber(((document.forms[0].m2h.value)*1 + ((caja*uds)/2.80)*1)*1,2,false,true);
rangoO(document.forms[0].m2h.value);
return true;
}

else{
alert ('Debe introducir un numero');
document.forms[0].unidades.focus();
return false;
}
}

function rangoO(varx){

	var result;
	
	
	if (varx<4){
		result="de 2 a 4";		
	}
	
	if (varx>=4 && varx<7){
		result="de 4 a 7";			
	}
	
	if (varx>=7 && varx<12){	
		result="de 7 a 12";		
	}
	
	if (varx>=12 && varx<16){
		result="de 12 a 16";		
	}
	
	if (varx>=16){	
		result="de 16 a 20";	
	}
	
	document.forms[0].m2.value=result + '  m2	';

}




function calcula2(){

var tam_c =  document.forms[0].tamano_c.value;
var num_h =  document.forms[0].numero_h.value;


	if (num_h!='0' || tam_c!='0'){
		
		if (num_h!='0'){
			rangoM(num_h);
		}
		else{
			rangoM(tam_c);
		}
	
	}

}

function rangoM(varx){
	var result;
	switch (varx){
		case '1':{result="de 2 a 4";break}
		case '2':{result="de 4 a 7";break}
		case '3':{result="de 7 a 12";break}
		case '4':{result="de 12 a 16";break}
		case '5':{result="de 16 a 20";break}
		
	}
	document.forms[0].m2_h.value=result + '  m2	';
}


function checkPrivacidad ()
{ 
	chkP= document.getElementById('blue');
	if( chkP.checked == true ){
			document.getElementById('btn_submit_ok').style.display = 'inline';
			document.getElementById('btn_submit_inicial').style.display = 'none';
	} else {
			document.getElementById('btn_submit_ok').style.display = 'none';
			document.getElementById('btn_submit_inicial').style.display = 'inline';
	}
}