/* 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';
      }
   }
}

//Envio de datos segun el tipo de form seleccionado
function checkformNV()
{
   var form = document.getElementById("buscadorNieve")
   if (!form) form = document.getElementById("minibuscador");
   var error = 'seleccione destino';
   var errorDates = '';
   formId = form.id;
   //comprobaciones del form de hotel

   if (form.codzge3.value == '') {
      alert(error);
      return '';
   }
   errorDates = validateDateNV(formId);
   if (errorDates != '')
   {
      alert(errorDates);
      return '';
   }
   errorDades = validaAduNV(formId);
   if (errorDates != '') {
      alert(errorDates);
      return '';
   }
   form.fecini.value = form.fecha_orig3.value;
   form.fecfin.value = form.fecha_dest3.value;
   form.distri.value = referdistri('NV');
   form.codtou.value = 'EPL#HTB#ROD';
   form.filtra.value = 'impbas##[*]codral##[*]codsca##[*]codzge##[*]codtou##[*]tipcam##';
   form.codtse.value = 'HT';
   form.conpgr.value = 'HT';
   form.tipser.value = 'NV';
   form.nomzge.value = form.codzge3.value;
   form.target = '_parent';
   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 validateDateNV(formId) {
   var form = document.getElementById(formId);
   if (form.fecha_orig3.value == '' || form.fecha_dest3.value == '') {
      return 'Fecha no válida. Compruebe las fechas';
   }
   return '';
}

function validaAduNV(formId) {
   var form = document.getElementById(formId);
   if (form.numadu_1_NV.value == 0) {
      return 'El número de adultos no puede ser 0. Compruebe en numero de adultos';
   }
   return '';
}

  function seleccionarZona(codzge, nombre) {
        var form = document.getElementById('buscadorNieve');
        $('#inputArbolNV').attr('value', nombre)
        form.codzge.value = codzge;
        arbNV.ocultarArbol();
    };
