function UpdateDestinationCode()
{
	var CodSV	= document.getElementById("hotelcodsv").options[document.getElementById("hotelcodsv").selectedIndex].value;
	 
	if (CodSV != 0 && CodSV.length > 3)
	{
		document.getElementById("dest_dep1").value = CodSV.substr(0,3);
	}
	else 
	{
		document.getElementById("dest_dep1").value = CodSV;
	}
}

function ValidPaxesCount()
{
	hotelrooms = document.getElementById('selectedrooms');
	RoomsCount = hotelrooms.options[hotelrooms.selectedIndex].value; 
	
	adultsCount = 0;
	childrensCount = 0;
	infantsCount = 0;
	for (i=1; i<=RoomsCount; i++)
	{
		adults    = document.getElementById('nb_adult'+i);
		childrens = document.getElementById('children'+i);
		infants   = document.getElementById('infants'+i);
		adultsCount += parseInt(adults.options[adults.selectedIndex].value);		
		childrensCount += parseInt(childrens.options[childrens.selectedIndex].value);
		infantsCount += parseInt(infants.options[infants.selectedIndex].value);
		adults = parseInt(adults.options[adults.selectedIndex].value);		
		childrens = parseInt(childrens.options[childrens.selectedIndex].value);
		infants = parseInt(infants.options[infants.selectedIndex].value);
		
		totalNonAdults = childrens + infants;
		if (totalNonAdults >2)
		{
			alert(document.getElementById('msg_allowed_childrens_per_room').value);
			return false;
		}
		if ((adults == 3) && ((totalNonAdults == 2) || (totalNonAdults == 1)))
		{
			alert(document.getElementById('msg_allowed_pax_per_room').value);
			return false;
		}
		
	}
	paxesCount = adultsCount + childrensCount + infantsCount;
	if (paxesCount>12)
	{
		alert(document.getElementById('msg_allowed_total_pax').value); 
		return false;
	}
	return true;
}

function ValidHotelForm()
{ 
	var det_date = new Array;	

        if(document.getElementById('dest_dep1'))
        {
            if(document.getElementById('dest_dep1').value==0)
            {
                    alert(document.getElementById('msg_select_destination').value);
                    document.getElementById('dest_dep1').focus();
                    return false;
            }
        }
	
	if ((document.getElementById('date_dep0').value=='') || (document.getElementById('date_dep0').value=='yyyy-mm-dd'))
	{
		alert(document.getElementById('msg_enter_checkin_date').value);
		document.getElementById('date_dep0').focus();
		return false;
	}			
	if ((document.getElementById('date_dep1').value=='') || (document.getElementById('date_dep1').value=='yyyy-mm-dd'))
	{
		alert(document.getElementById('msg_enter_checkout_date').value);
		document.getElementById('date_dep1').focus();
		return false;
	}	


	det_date = document.getElementById('date_dep0').value.split('-');		
	det_date1 = document.getElementById('date_dep1').value.split('-');		
	document.getElementById('date_dep').value = det_date[0] + det_date[1] + det_date[2];
	// Validar las fechas
	var date_dat = new Array();
	date_dat = document.getElementById('date_dep0').value.split('-');
	var current1 = new Date(date_dat[0], date_dat[1]-1, date_dat[2]); // a new instance	
	//fixDate(current1);

	Date1 = current1.getTime();
	// Validar las fechas
	date_dat = document.getElementById('date_dep1').value.split('-');
	var current2 = new Date(date_dat[0], date_dat[1]-1, date_dat[2]); // a new instance	
	//fixDate(current2);
	Date2 = current2.getTime();
	document.getElementById('duration').value = (Date2 - Date1)/86400000;
	
	// Today
	var current3 = new Date(); // a new instance	
//	fixDate(current3);
	var current4 = new Date(current3.getFullYear(), current3.getMonth(), current3.getDate())
	Today = current4.getTime();


	if(Date1 <= Today)
	{		
		alert(document.getElementById('msg_checkin_after_today').value);
		document.getElementById('date_dep0').focus();
		return false;
	}
	if(((Date1 - Today)/86400000) < 3) 
	{
		alert(document.getElementById('msg_acept_hotels_request').value);
		document.getElementById('date_dep0').focus();
		return false;
	}
	if(Date1 >= Date2)
	{
		alert(document.getElementById('msg_checkout_after_checkin').value);
		document.getElementById('date_dep1').focus();
		return false;
	}
	return ValidPaxesCount();
}

function OpenRooms(cant, resizeBestDeals)	
{
	for (i=2; i<=6; i++) 
	{ 
		if (i<=cant.value) 
			document.getElementById("room_"+i).style.display = "";
		else
			document.getElementById("room_"+i).style.display = "none";			
    } 
}