/* funciones para el buscador de escapadas de la home*/

/*Pinta las filas de habitaciones para los minibuscadores*/
function showHabitacionMini(valor, tipo) {
   if (valor == '3') {
      pintaHabitacionMini('block', 'block', 'block', 'block', '40px', tipo);
   } else if (valor == '2') {
      pintaHabitacionMini('block', 'block', 'none', 'block', '20px', tipo);
   } else {
      pintaHabitacionMini('block', 'none', 'none', 'none', '0px', tipo);
   }
}

function pintaHabitacionMini(valor1, valor2, valor3, valor4, valor5, tipo) {
   document.getElementById('hab1_' + tipo).style.display = valor1;
   if (document.getElementById('c_hab1_' + tipo)) document.getElementById('c_hab1_' + tipo).style.display = valor1;
   if (document.getElementById('separacion-hab1_' + tipo)) document.getElementById('separacion-hab1_' + tipo).style.display = valor1;
   document.getElementById('edanin1_' + tipo).style.display = valor1;
   document.getElementById('hab2_' + tipo).style.display = valor2;
   if (document.getElementById('c_hab2_' + tipo)) document.getElementById('c_hab2_' + tipo).style.display = valor2;
   if (document.getElementById('separacion-hab2_' + tipo)) document.getElementById('separacion-hab2_' + tipo).style.display = valor2;
   document.getElementById('edanin2_' + tipo).style.display = valor2;
   document.getElementById('hab3_' + tipo).style.display = valor3;
   if (document.getElementById('c_hab3_' + tipo)) document.getElementById('c_hab3_' + tipo).style.display = valor3;
   if (document.getElementById('separacion-hab3_' + tipo)) document.getElementById('separacion-hab3_' + tipo).style.display = valor3;
   document.getElementById('edanin3_' + tipo).style.display = valor3;
   /*document.getElementById('alto').style.display = valor4;
             document.getElementById('alto').style.height = valor5;	*/
}

function mostrarSelNinMini(idvalor, tipo) {
   maxhab = 3;
   var idnin = idvalor.split('_');
   var nnin = document.getElementById('numnin_' + idnin[1] + '_' + tipo).selectedIndex;
   if (nnin > 0) {
      document.getElementById('edanin' + idnin[1] + '_' + tipo).style.display = 'block';
      document.getElementById('txteda' + idnin[1] + '_' + tipo).style.display = 'block';
   } else {
      document.getElementById('edanin' + idnin[1] + '_' + tipo).style.display = 'none';
      document.getElementById('txteda' + idnin[1] + '_' + tipo).style.display = 'none';
   }
   for (var i = 0; i < nnin; i++) {
      var str1 = 'edad_' + idnin[1] + i + '_' + tipo;
      var str2 = 'seled_' + idnin[1] + i + '_' + tipo;
      document.getElementById(str1).style.display = 'block';
      document.getElementById(str2).style.display = 'block';
   }
   for (var i = nnin; i < maxhab; i++) {
      var str3 = 'edad_' + idnin[1] + i + '_' + tipo;
      var str4 = 'seled_' + idnin[1] + i + '_' + tipo;
      if (document.getElementById(str3)) {
         document.getElementById(str3).style.display = 'none';
         document.getElementById(str4).style.display = 'none';
      }
   }
}


function  cambiaTipoBuscador_new(Tipo)
{
	if (Tipo=='PRO') /* por provincias */
	{					
		document.getElementById('cal_ida2').style.visibility='visible';
		document.getElementById('cal_vta2').style.visibility='visible';
		// Atencion jQery
		$('#buscadorext').find('input, select').each(function(){
			$(this).removeAttr('disabled');
			$(this).css( "background", "#fff" );
		});	
		
		document.getElementById('botonbuscarTIP').style.display='none';	
		document.getElementById('botonbuscarPRO').style.display='block';				
	
	}	
	else /* por tipos*/
	{
		document.getElementById('cal_ida2').style.visibility='hidden';
		document.getElementById('cal_vta2').style.visibility='hidden';
		// Atencion jQery
		$('#buscadorext').find('input, select').each(function(){
			$(this).attr('disabled','disabled');
			$(this).css( "background", "#cccccc" );
		});
		
		document.getElementById('botonbuscarTIP').style.display='block';	
		document.getElementById('botonbuscarPRO').style.display='none';
		
	}	
}

function carga(valor){
	if(valor ==0){
		document.getElementById("codzge2").style.display = 'none';
		document.getElementById("codcam2").style.display = 'block';
		
		
	}
	else{
		document.getElementById("codzge2").style.display = 'block';
		document.getElementById("codcam2").style.display = 'none';
	
	}
}

/* 
* Funcion del combo de SYTHomeContentESC
* Ensenya las escapadas de una provincia
*/
function showCampaign_new(coddes, codcam){
	var select = document.getElementById("codcam2");
	if(select.value !='Seleccione >>'){
		var form = document.getElementById("campaignSearcher");
		if (coddes) form.coddes.value = coddes;
		if (codcam && codcam != 'undefined') form.codcam.value = codcam.value;
		form.submit();
	}
	else{alert("Por favor, seleccione un tipo de escapada!!");}
}

//Envio de datos segun el tipo de form seleccionado
function checkformES()
{
   var form = document.getElementById("buscadorEscapadas")
   if (!form) form = document.getElementById("minibuscador");
   var error = 'seleccione destino';
   var errorDates = '';
   formId = form.id;
   //comprobaciones del form de hotel

   if (form.codzge2.value == '') {
      alert(error);
      return '';
   }
   errorDates = validateDateES(formId);
   if (errorDates != '')
   {
      alert(errorDates);
      return '';
   }
   errorDades = validaAduES(formId);
   if (errorDates != '') {
      alert(errorDates);
      return '';
   }
   form.fecini.value = form.fecha_orig2.value;
   form.fecfin.value = form.fecha_dest2.value;

   form.codzge.value = form.codzge2.value;
   form.distri.value = referdistri('ES');
   form.codtou.value = 'EPL';
   /*var cat = document.getElementById('selsca').value;
                   if (cat > 0){
                      form.filtra.value='impbas##[*]codral##[*]codsca#=#' + cat + '[*]codzge##[*]codtou##';
                   } else {*/
   form.filtra.value = 'impbas##[*]codral##[*]codsca##[*]codzge##[*]codtou##[*]tipcam##';

   if (form.codzge2.value == '') {
      var codzge = document.getElementById("sel_codzge");
      if (codzge) form.codzge.value = codzge2.value;
   }
   form.codtse.value = 'HT';
   form.conpgr.value = 'HT';
   form.tipser.value = 'ES';
   form.target = '_parent';


   form.action = 'forward.do';
 

   form.submit();
}
/* VALIDATE */
/*proceso que devuelve el numero de ocupantes segun tipo de habitacion*/
function getNumOcupacion(valor)
{
   if (valor == 'single')
      return '1';
   else if (valor == 'double')
      return '2';
   else if (valor == 'double_nin')
      return '2';
   else  if (valor == 'triple')
      return '3';
   else  if (valor == 'cuadruple')
      return '4';
   else return '0';
}

function validateDateES(formId) {
   var form = document.getElementById(formId);
   if (form.fecha_orig2.value == '' || form.fecha_dest2.value == '') {
      return 'Fecha no válida. Compruebe las fechas';
   }
   return '';
}

function validaAduES(formId) {
   var form = document.getElementById(formId);
   if (form.numadu_1_ES.value == 0) {
      return 'El número de adultos no puede ser 0. Compruebe en numero de adultos';
   }
   return '';
}
