
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()
{
	rooms = document.getElementById('packagerooms');
	RoomsCount = rooms.options[rooms.selectedIndex].value; 
	
	adultsCount = 0;
	childrensCount = 0;
	infantsCount = 0;
	for (i=1; i<=RoomsCount; i++)
	{
		adults    = document.getElementById('package_nb_adult'+i);
		childrens = document.getElementById('package_children'+i);
		infants   = document.getElementById('package_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 ValidPackForm()
{
	var det_date = new Array;

	if(document.searchPack.date_dep0.value=='yyyy-mm-dd')
	{
		alert(document.getElementById('msg_enter_checkin_date').value);
		document.searchPack.date_dep0.focus();
		return false;
	}			
		
	det_date = document.searchPack.date_dep0.value.split('-');		
	document.searchPack.date_dep.value = det_date[0] + det_date[1] + det_date[2];
	
	// Validar las fechas
	var date_dat = new Array();
	date_dat = document.searchPack.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);
		document.searchPack.date_dep0.focus();
		return false;
	}
	if(((Date1 - Today)/86400000) < 3) 
	{
		alert(document.getElementById('msg_acept_vacations_request').value);
		document.searchPack.date_dep0.focus();
		return false;
	}
	
	return PackageValidPaxesCount();
}

function OpenPackagesRooms(cant)	
{
	for (i=2; i<=6; i++) 
	{ 
		if (i<=cant.value) 
			document.getElementById("packageroom_"+i).style.display = "";
		else
			document.getElementById("packageroom_"+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	(isEmpty2(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	(isEmpty2(departureFlight) || !string_ok2('departure_flight_' + product_code)) 
		{
			alert(document.getElementById('msg_empty_flight_number').value);
			departureFlight.focus();
			return false;
		}		
	}	
	
	document.verifPack.submit();
}

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;
	}
}

function isEmpty2(e) 
{
    if ((e.value == null) || (e.value == ""))
		return true;
}
