DD_roundies.addRule('div.login', '10px', true);
DD_roundies.addRule('div.ppal_dcha', '10px', true);
DD_roundies.addRule('div.cuatroPax', '10px', true);
DD_roundies.addRule('div.ppal_dcha_inicio', '0 0 10px 10px', true);
DD_roundies.addRule('div.contenedor', '0 0 10px 10px', true);
DD_roundies.addRule('a.liborder', '0 0 10px 10px', true);
DD_roundies.addRule('div.hotel_search', '10px', true);
DD_roundies.addRule('div.hotel_search_vacacional', '10px', true);
DD_roundies.addRule('div.hotel_search_rural', '10px', true);
DD_roundies.addRule('div.aviso', '10px', true);
DD_roundies.addRule('div.footer', '10px', true);
DD_roundies.addRule('div.errores', '10px', true);
DD_roundies.addRule('div.precarga', '10px', true);

$(function() {

	$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['es']));

	
	$("#fecha1").datepicker({
		firstDay: 1,
		minDate: '+0D', 
		showOn: 'both',
		buttonImage: './imgs/interface/forms/calendario.gif',
		buttonImageOnly: true,
		changeMonth: true
		});
	$("#fecha2").datepicker({
		firstDay: 1,
	    beforeShow: customRange,
 
		showOn: 'both',
		buttonImage: './imgs/interface/forms/calendario.gif',
		buttonImageOnly: true,
		changeMonth: true
		});
});

function customRange(input) {
	
		var day = $('#fecha1').datepicker('getDate');
		day.setDate(day.getDate()+1);
		
    return {
	    minDate: (
	    		day
			)
        };  
}

function validaLogin(frmLogin)
{
	var valor = document.frmLogin.login.value;
	
	if (valor == '') {
		alert("Debe indicar el login.");
		return false;
	}
	
	var valor = document.frmLogin.password.value;
	
	if (valor == '') {
		alert("Debe indicar el password.");
		return false;
	}
}

function resetear(f){
	//document.f.provincia.options[document.f.provincia.selectedIndex].value = "0";
	//document.f.provincia.options[document.f.provincia.selectedIndex].text = "--------------- Select ---------------";
	
	document.getElementById('pais').selectedIndex = "0";
	document.getElementById('provincia').selectedIndex = "0";
	
	
	document.f.fpoblacion.value = "";
	document.f.fnomhotel.value = "";
	
	document.getElementById('fcategoria').selectedIndex = 0;
	
	document.getElementById('regimen').selectedIndex = 0;
	
	document.f.fecha1.value = "";
	document.f.fecha2.value = "";
	
	document.getElementById('habitac1').selectedIndex = 0;
	document.getElementById('adultos1').selectedIndex = 0;
	document.getElementById('ninos1').selectedIndex = 0;
	document.getElementById('edadn11').selectedIndex = 0;
	document.getElementById('edadn21').selectedIndex = 0;
	document.getElementById('edadn12').selectedIndex = 0;
	document.getElementById('edadn22').selectedIndex = 0;
	document.getElementById('edadn13').selectedIndex = 0;
	document.getElementById('edadn23').selectedIndex = 0;
}

function validaEstancias(f){
	
	var f1 = document.f.fecha1.value;
	if(f1 == ''){
			alert("Fecha de salida incorrecta");
			return false;
		}
	
	var f2 = document.f.fecha2.value;
	if(f2 == ''){
			alert("Fecha de regreso incorrecta");
			return false;
		}
	//******************************************************************************* Comprobar Provincia
	var indice = document.f.pais.selectedIndex
	var valor = document.f.pais.options[indice].value
	var textoPais = document.f.pais.options[indice].text
	
	if (textoPais == "--------------- Select ---------------") {
		alert("Seleccione un PAIS");
		return false;
	}else{
		var indice = document.f.provincia.selectedIndex
		var valor = document.f.provincia.options[indice].value
		var textoProv = document.f.provincia.options[indice].text

		if (textoProv == "--------------- Select ---------------") {
			alert("Seleccione una PROVINCIA");
			return false;
		}
	}		
	
	//******************************************************************************* Comprobamos numero de noches
	var noches = document.f.nNoches.value;
	if(noches <= 0){
		alert("Fecha Incorrecta");
		return false;
	}
	
	//****************************************************************************** Comprobamos paxes
	var indice1_1 = document.f.pax1_1.selectedIndex
	var pax1_1 = document.f.pax1_1.options[indice1_1].value
	
	var indice1_2 = document.f.pax1_2.selectedIndex
	var pax1_2 = document.f.pax1_2.options[indice1_2].value
	
	var indice2_1 = document.f.pax2_1.selectedIndex
	var pax2_1 = document.f.pax2_1.options[indice2_1].value
	
	var indice3_1 = document.f.pax3_1.selectedIndex
	var pax3_1 = document.f.pax3_1.options[indice3_1].value
	
	var indice2_2 = document.f.pax2_2.selectedIndex
	var pax2_2 = document.f.pax2_2.options[indice2_2].value
	
	//** Sin niños
	var indice1_0 = document.f.pax1_0.selectedIndex
	var indice2_0 = document.f.pax2_0.selectedIndex
	var indice3_0 = document.f.pax3_0.selectedIndex
	var indice4_0 = document.f.pax4_0.selectedIndex
	//**
	
	var sum = indice1_1 + indice1_2 + indice2_1 + indice3_1 + indice2_2 + indice1_0 + indice2_0 + indice3_0 + indice4_0
	if(sum == 0){
		alert('Debe elegir la ocupación');
		return false;
	}
}

function calculaNoches(f){
		var fecha1 = document.f.fecha1.value
		var fecha2 = document.f.fecha2.value

		var Dia = fecha1.substr(0, 2);
		var Mes = fecha1.substr(3, 2);
		var Any = fecha1.substr(6, 4);

		var Dia2 = fecha2.substr(0, 2);
		var Mes2 = fecha2.substr(3, 2);
		var Any2 = fecha2.substr(6, 4);

		var noches = Math.max( Math.round( (new Date(Any2,Mes2-1,Dia2) - new Date(Any,Mes-1,Dia)) / 86400000 ) , 0 );
		
		if(noches <= 0){
			//alert("Fecha Incorrecta");
			//return false;
		}

		f.nNoches.value = noches;
}

function llenarCombosPaises(){
	window.location="inicio.php?codpais="+document.f.pais.options[document.f.pais.selectedIndex].value+"&nompais="+document.f.pais.options[document.f.pais.selectedIndex].text;
}

function llenarCombosProvincias(){
	window.location="inicio.php?codpais="+document.f.pais.options[document.f.pais.selectedIndex].value+"&nompais="+document.f.pais.options[document.f.pais.selectedIndex].text+"&codprovincia="+document.f.provincia.options[document.f.provincia.selectedIndex].value+"&nomprovincia="+document.f.provincia.options[document.f.provincia.selectedIndex].text;
}

function edades(f){
	var indice1_1 = document.f.pax1_1.selectedIndex
	var pax1_1 = document.f.pax1_1.options[indice1_1].value
	
	var indice1_2 = document.f.pax1_2.selectedIndex
	var pax1_2 = document.f.pax1_2.options[indice1_2].value
	
	var indice2_1 = document.f.pax2_1.selectedIndex
	var pax2_1 = document.f.pax2_1.options[indice2_1].value
	
	var indice3_1 = document.f.pax3_1.selectedIndex
	var pax3_1 = document.f.pax3_1.options[indice3_1].value
	
	var indice2_2 = document.f.pax2_2.selectedIndex
	var pax2_2 = document.f.pax2_2.options[indice2_2].value
	
	//** Sin niños
	var indice1_0 = document.f.pax1_0.selectedIndex
	var indice2_0 = document.f.pax2_0.selectedIndex
	var indice3_0 = document.f.pax3_0.selectedIndex
	var indice4_0 = document.f.pax4_0.selectedIndex
	//**
	
	var sum = indice1_1 + indice1_2 + indice2_1 + indice3_1 + indice2_2 + indice1_0 + indice2_0 + indice3_0 + indice4_0
	if(sum > 3){
		alert('Máximo 3 habitaciones');
		document.f.pax1_0.selectedIndex = 0;
		document.f.pax2_0.selectedIndex = 0;
		document.f.pax3_0.selectedIndex = 0;
		document.f.pax4_0.selectedIndex = 0;
		document.f.pax1_1.selectedIndex = 0;
		document.f.pax1_2.selectedIndex = 0;
		document.f.pax2_1.selectedIndex = 0;
		document.f.pax3_1.selectedIndex = 0;
		document.f.pax2_2.selectedIndex = 0;
	}
	
	//*********************************************** pax1_1
	if (pax1_1 > 0){
		$(document).ready(function(){
			$('#pax1_1_edad').show();
		  });
	}else{
		$(document).ready(function(){
			$('#pax1_1_edad').hide();
		  });
	}
	
	//*********************************************** pax1_2
	if (pax1_2 > 0){
		$(document).ready(function(){
			$('#pax1_2_edad').show();
		  });
	}else{
		$(document).ready(function(){
			$('#pax1_2_edad').hide();
		  });
	}
	
	//*********************************************** pax2_1
	if (pax2_1 > 0){
		$(document).ready(function(){
			$('#pax2_1_edad').show();
		  });
	}else{
		$(document).ready(function(){
			$('#pax2_1_edad').hide();
		  });
	}
	
	//*********************************************** pax3_1
	if (pax3_1 > 0){
		$(document).ready(function(){
			$('#pax3_1_edad').show();
		  });		
	}else{
		$(document).ready(function(){
			$('#pax3_1_edad').hide();
		  });
	}
	
	//*********************************************** pax2_2
	if (pax2_2 > 0){
		$(document).ready(function(){
			$('#pax2_2_edad').show();
		  });		
	}else{
		$(document).ready(function(){
			$('#pax2_2_edad').hide();
		  });
	}
}

var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function finMes(nMes, nAno){
 return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0);
}

 function padNmb(nStr, nLen, sChr){
  var sRes = String(nStr);
  for (var i = 0; i < nLen - String(nStr).length; i++)
   sRes = sChr + sRes;
  return sRes;
 }

 function makeDateFormat(nDay, nMonth, nYear){
  var sRes;
  sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0");
  return sRes;
 }
 
function incDate(sFec0){
 var nDia = parseInt(sFec0.substr(0, 2), 10);
 var nMes = parseInt(sFec0.substr(3, 2), 10);
 var nAno = parseInt(sFec0.substr(6, 4), 10);
 nDia += 1;
 if (nDia > finMes(nMes, nAno)){
  nDia = 1;
  nMes += 1;
  if (nMes == 13){
   nMes = 1;
   nAno += 1;
  }
 }
 return makeDateFormat(nDia, nMes, nAno);
}

function decDate(sFec0){
 var nDia = Number(sFec0.substr(0, 2));
 var nMes = Number(sFec0.substr(3, 2));
 var nAno = Number(sFec0.substr(6, 4));
 nDia -= 1;
 if (nDia == 0){
  nMes -= 1;
  if (nMes == 0){
   nMes = 12;
   nAno -= 1;
  }
  nDia = finMes(nMes, nAno);
 }
 return makeDateFormat(nDia, nMes, nAno);
}

function addToDate(sFec0, sInc){
 var nInc = Math.abs(parseInt(sInc));
 var sRes = sFec0;
 if (parseInt(sInc) >= 0)
  for (var i = 0; i < nInc; i++) sRes = incDate(sRes);
 else
  for (var i = 0; i < nInc; i++) sRes = decDate(sRes);
 return sRes;
}

function recalcF1(){
 with (document.f){
  fecha2.value = addToDate(fecha1.value, nNoches.value);
 }
}
