var departing_date_selected = false;

function ChangeReturnDate() {
	var myform = document.AIR_ENTRY_FORM
	var selectedMonth
	var IsShortMonth
	var btnRetDate = false

	selectedMonth = myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value.charAt(4) + myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value.charAt(5)
	IsShortMonth = (selectedMonth == "02" || selectedMonth == "04" || selectedMonth == "06" || selectedMonth == "09" || selectedMonth == "11")

	if(myform.TRIP_TYPE[1].checked)
		btnRetDate = true

	if(btnRetDate && departing_date_selected){
		if(myform.B_MONTH.selectedIndex > myform.E_MONTH.selectedIndex || myform.B_MONTH.options[myform.B_MONTH.selectedIndex].value == "XX")
		myform.E_MONTH.selectedIndex = myform.B_MONTH.selectedIndex

		if((myform.B_DAY.selectedIndex >= myform.E_DAY.selectedIndex || myform.E_DAY.options[myform.E_DAY.selectedIndex].value == "XX")&&(myform.E_MONTH.selectedIndex == myform.B_MONTH.selectedIndex)){
			if(((myform.B_DAY.options[myform.B_DAY.selectedIndex].value > 29) && (IsShortMonth))||(myform.B_DAY.options[myform.B_DAY.selectedIndex].value == 31)||((myform.B_DAY.options[myform.B_DAY.selectedIndex].value > 27) && (myform.B_MONTH.selectedIndex == 6))){
				myform.E_MONTH.selectedIndex = myform.B_MONTH.selectedIndex + 1
				myform.E_DAY.selectedIndex = 0
			} else	myform.E_DAY.selectedIndex = myform.B_DAY.selectedIndex + 1
		}
	}
	departing_date_selected = false
}

function ReturnFlight(){
	document.AIR_ENTRY_FORM.TRIP_TYPE[1].checked = true
	ChangeReturnDate()
}


function OnewayTrip(){
	var lengthMonth = document.AIR_ENTRY_FORM.E_MONTH.length
	var lengthDay = document.AIR_ENTRY_FORM.E_DAY.length
	if(!(document.AIR_ENTRY_FORM.E_MONTH.selectedIndex == lengthMonth - 1 && document.AIR_ENTRY_FORM.E_DAY.selectedIndex == lengthDay - 1 )){
		return_month_index = document.AIR_ENTRY_FORM.E_MONTH.selectedIndex
		return_day_index = document.AIR_ENTRY_FORM.E_DAY.selectedIndex
	}
	document.getElementById('retornobox').className="hideSubM"; 
}


function ReturnTrip(){
	if(return_month_index == -1){
		for(n = 0;n < document.AIR_ENTRY_FORM.E_MONTH.length;n ++){
			if(document.AIR_ENTRY_FORM.E_MONTH.options[n].selected)
			return_month_index = n
		}
		for(n = 0;n < document.AIR_ENTRY_FORM.E_DAY.length;n ++){
			if(document.AIR_ENTRY_FORM.E_DAY.options[n].selected)
			return_day_index = n
		}
	}
	document.AIR_ENTRY_FORM.E_MONTH.options[return_month_index].selected = true
	document.AIR_ENTRY_FORM.E_DAY.options[return_day_index].selected = true
	document.getElementById('retornobox').className="showSubM";
}


function submit_form() {
	var la_nueva=window.open('','THE_NEW','resizable=yes,toolbar=yes,scrollbars=yes,width=800,height=450');
	document.AIR_ENTRY_FORM.target='THE_NEW';
	document.AIR_ENTRY_FORM.action='/modules/cnt/fnd/tripflow_previa.php';
	document.AIR_ENTRY_FORM.submit();
	/*
	document.AIR_ENTRY_FORM.action='http://sales.flypluna.com/cgi-bin/tripflow/tripflow.cgi';
    	*/
	document.AIR_ENTRY_FORM.submit();	
}


// Función para Sajax
function Des_Dropdown(org) {
	
	var the_url = "/AjaxApps/Get_Des_Dropdown.php";
	var miObjeto = new Object();
	miObjeto['org'] = org;

	new Ajax.Request(the_url, {
		method: 'POST',
		parameters: miObjeto,
		onComplete: Display_Des_Dropdown
	});
	
	
}

// Función para Sajax
function Display_Des_Dropdown(new_data) {
	$("des").innerHTML = new_data.responseText;
}

function showOffers(oft_id){
	//var url='/modules/oft/fnd/ofertas.php?oft_id='+oft_id;
	var url='/ofertas/frontend.php?oid='+oft_id;
	var oft_window=window.open(url,'','resizable=yes,toolbar=yes,scrollbars=yes,width=900,height=630');
}

