
function UpdatePackageTypeAndDuration()
{
	combobox = document.getElementById('typeandduration');
	TypeAndDuration = combobox.options[combobox.selectedIndex].value;
	if (TypeAndDuration.indexOf('-') > -1)
	{
		var listArray = TypeAndDuration.split("-");
		document.getElementById('packagecodtpaq').value = listArray[0];
		document.getElementById('packageduration').value = listArray[1];
	}
	else
	{
		document.getElementById('packagecodtpaq').value = TypeAndDuration;
		document.getElementById('packageduration').value = 0;
	}
}
function PackageValidPaxesCount(elements_suffix)
{
	rooms = document.getElementById('packagerooms'+elements_suffix);
	RoomsCount = rooms.options[rooms.selectedIndex].value; 
	
	adultsCount = 0;
	childrensCount = 0;
	infantsCount = 0;
	for (i=1; i<=RoomsCount; i++)
	{
		adults    = document.getElementById('package_nb_adult'+elements_suffix+i);
		childrens = document.getElementById('package_children'+elements_suffix+i);
		infants   = document.getElementById('package_infants'+elements_suffix+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 ValidPackForm(form, elements_suffix)
{
	if(form.date_dep0.value=='yyyy-mm-dd')
	{
		alert(document.getElementById('msg_enter_checkin_date').value);
		form.date_dep0.focus();
		return false;
	}			
		
	// Validar las fechas
	var date_dat = new Array();
	date_dat = form.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();
	// 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);
		form.date_dep0.focus();
		return false;
	}
	if(((Date1 - Today)/86400000) < 2) 
	{
		alert(document.getElementById('msg_acept_vacations_request').value);
		form.date_dep0.focus();
		return false;
	}
	
	return PackageValidPaxesCount(elements_suffix);
}

function OpenPackagesRooms(cant, elements_suffix)	
{
	for (i=2; i<=6; i++) 
	{ 
		if (i<=cant.value) 
			document.getElementById("packageroom"+elements_suffix+"_"+i).style.display = "";
		else
			document.getElementById("packageroom"+elements_suffix+"_"+i).style.display = "none";			
    }     
}

function SetPackageRequestValues(product_code)
{
	document.getElementById('current_package_product_code').value = product_code;
        if (document.getElementById('arrival_flight_' + product_code))
	{
		arrivalFlight = document.getElementById('arrival_flight_' + product_code);
		if	(isEmpty(arrivalFlight) || !string_ok2('arrival_flight_' + product_code))
		{
			alert(document.getElementById('msg_empty_flight_number').value);
			arrivalFlight.focus();
			return false;
		}
	}

	if (document.getElementById('departure_flight_' + product_code))
	{
		departureFlight = document.getElementById('departure_flight_' + product_code);
		if	(isEmpty(departureFlight) || !string_ok2('departure_flight_' + product_code))
		{
			alert(document.getElementById('msg_empty_flight_number').value);
			departureFlight.focus();
			return false;
		}
	}
        return true;
}

function string_ok2(id)
{
	var re = /^[0-9a-zA-ZÁáÉéÍíÓóÚúÑñ\;\:\,\*\#\+\.\\\[\]\(\)\-\_\/\[\] ]+$/;
	if ((document.getElementById(id).value != null) && (re.test(document.getElementById(id).value))) {
		return true;
	}
	else {
		document.getElementById(id).focus();
		return false;
	}
}
