function getFlights(idOffer)
{
if (idOffer.indexOf("TM")>=0){
	document.getElementById("depFlightPlanWait").style.visibility='visible';
	document.getElementById('flightPlanDetails').innerHTML='';
	document.getElementById('flightsPlan').innerHTML= '';
	
	AjaxMethods.getFlights(idOffer,callback_getFlights);}
}

function callback_getFlights(res)
{	
	document.getElementById("depFlightPlanWait").style.visibility='hidden';

	if (res.value != ''){
	document.getElementById('flightsPlan').innerHTML= res.value;
	document.getElementById('flightPlanDetails').innerHTML= '<table width="80%"><tr><td>'+res.value+'</td></tr></table>';
	}
}




function getDepartureDates(pDateFrom,pDateTo,pDestinationName, pCity, pAccomodation, pNights, pReferer, pAirportNumber, pPromoMsg, pPlan, pSection, pType, pRifTD)
{	

document.getElementById("DEPWAITING").style.visibility='visible';
document.getElementById("DEPWAITING").style.position = 'static';

	var index = document.getElementById('CM_ddlDepartureAirport').selectedIndex
	if (index>=0){
	pAirportCode=document.getElementById('CM_ddlDepartureAirport').value
	pAirportName = document.getElementById('CM_ddlDepartureAirport').options[index].text
		if ((document.getElementById('CM_ddlDepartureAirport').options[document.getElementById('CM_ddlDepartureAirport').selectedIndex].value)==''){
			//document.getElementById("layEstimateAmount").style.visibility='hidden';
			//document.getElementById("layEstimateErrorMessage").style.visibility='hidden';
			
			document.getElementById("ddlDepartureDate").style.visibility='hidden';
		}else
		{
		document.getElementById("ddlDepartureDate").style.visibility='visible';
		AjaxMethods.getDepartureDates(pAirportName,pAirportCode,pDateFrom,pDateTo,pDestinationName, pCity, pAccomodation, pNights, pReferer, pAirportNumber, pPromoMsg, pPlan, pSection, pType, pRifTD, callback_getDepartureDates);
		}
	}else{
	AjaxMethods.getDepartureDates('','',pDateFrom,pDateTo,pDestinationName, pCity, pAccomodation, pNights, pReferer, 0, pPromoMsg, pPlan, pSection, pType, pRifTD, callback_getDepartureDates);
	}
	
}

function callback_getDepartureDates(res)
{
document.getElementById("DEPWAITING").style.visibility='hidden';
document.getElementById("DEPWAITING").style.position = 'absolute';
	return document.getElementById("ddlDepartureDate").innerHTML = res.value
}

function getAvailableRooms(idOffer)
{
document.getElementById("ROOMWAITING").style.visibility='visible';



//document.getElementById("ROOMWAITING").style.position = 'static';
	AjaxMethods.getAvailableRooms(idOffer,callback_getAvailableRooms);
}

function callback_getAvailableRooms(res)
{	
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
	document.getElementById("ROOMWAITING").style.visibility='hidden';
	//document.getElementById("ROOMWAITING").style.position = 'absolute';
		var html = '';
		var header = '<table width="90%" cellspacing="2" cellpadding="0" border="0">';
		header += '<tr>';		
		//aggressivo ma manuele pensava alla bianca in germania e non ha previsto gli apt!
			if (res.value.Tables[0].Rows[0].code=='APT'){
			header += '<td height="34" class="cVacation_dark_text" >Tipologia appartamento</td>'
			//header += '<td class="cVacation_dark_text">N&#186; passeggeri</td>'
			header += '<td class="cVacation_dark_text">N&#186; appartamenti&nbsp;</td>'
			}
			else{
			header += '<td height="34" class="cVacation_dark_text" align="left">Tipologia di camera</td>'

			//header += '<td class="cVacation_dark_text"></td>'
			header += '<td class="cVacation_dark_text" align="left">N&#186; camere&nbsp;&nbsp;&nbsp;</td>'
			}
		header += '</tr>'
		
		for(var i=0; i<res.value.Tables[0].Rows.length; i++) {
			var room = res.value.Tables[0].Rows[i].code +'_'+res.value.Tables[0].Rows[i].guests + '_' + res.value.Tables[0].Rows[i].adults + '_' + res.value.Tables[0].Rows[i].child
			var paramRoom = "'" + room + "'";
			html += '<tr name="row'+room+'" id="row'+room+'">'
			
			if ((i % 2)==0){
			sClass='cVacation_Dark';
			}
			else
			{sClass='cVacation_light_text';}
			var sAction="'ResetRoom'";
			html += '<td class="'+sClass+'" align="left"><input type="hidden" id="supplier' + room +'" name="supplier"' + room +'" value="' + res.value.Tables[0].Rows[i].supplier + '"><input type="hidden" id="MaxChdAge' + room +'" name="MaxChdAge' + room +'" value="' + res.value.Tables[0].Rows[i].chdMaxAge + '">'
			html += '<input type="hidden" name="MinChdAge' + room +'" id="MinChdAge' + room +'" value="' + res.value.Tables[0].Rows[i].chdMinAge + '">'
			
			html += '<INPUT type="checkbox" value="' + res.value.Tables[0].Rows[i].code + '" name="ck' + room +'" id="ck'+room+'" onclick="resetLay('+sAction+');selectNumber(' + paramRoom + ')"><span id="roomTypeDesc'+room+'">' + res.value.Tables[0].Rows[i].type + '</span></td>'
			if (res.value.Tables[0].Rows[i].code == 'APT'){
				html += '<input type="hidden" name="numMaxPaxApt' + room +'" id="numMaxPaxApt' + room +'" value="' + res.value.Tables[0].Rows[i].guests + '">'
			}
			/*if (res.value.Tables[0].Rows[i].code == 'APT'){
				html += '<td class="'+sClass+'">'
				html += '<SELECT NAME="numPaxApt" id="numPaxApt">';
				var numMaxPax;
				numMaxPax=res.value.Tables[0].Rows[i].guests;
				for (j=0;j<numMaxPax;j++){
					html += '<option value="'+(j+1)+'">'+(j+1)+'</option>';
				}
				html += '</SELECT>';
				html += '</td>'
			}*/
	
			html += '<td width="25%" class="'+sClass+'"><span id="lb' + room + '">&nbsp;</span></td></tr>'
			if (res.value.Tables[0].Rows[i].code == 'APT'){
				html += '<tr><td colspan="3" class="'+sClass+'">';
				html += '<table cellpadding="0" cellspacing="0" border="0" name="rowAPT' + room + '" id="rowAPT' + room + '" width="580" style="display:none">'
				html += '<tr class="'+sClass+'">'
				html += '<td align="center" id="lbAPT' + room + '" width="580" >&nbsp;</td></tr></table>'
				}
			
			if (res.value.Tables[0].Rows[i].child > 0) {
			html += '<tr><td colspan="3" class="'+sClass+'">';

				for (j=0;j<res.value.Tables[0].Rows[i].child;j++) {
					html += '<table cellpadding="0" cellspacing="0" border="0" name="rowAge' + room + '" id="rowAge' + room + '" width="580" style="display:none">'
					html += '<tr class="'+sClass+'">'
					html += '<td align="center" id="lbAge' + room + '">&nbsp;</td></tr></table>'
				}
				
			}
			else{
			
			if (res.value.Tables[0].Rows[i].infant>0){
				html += '<tr><td colspan="3" class="'+sClass+'">';
				html += '<table cellpadding="0" cellspacing="0" border="0" name="rowInfant' + room + '" id="rowInfant' + room + '" width="580" style="display:none">'
				html += '<tr class="'+sClass+'">'
				html += '<td align="center" id="lbInfant' + room + '" width="580" >&nbsp;</td></tr></table>'
				}
			}
			html += '</td></tr>';
		}
		html += '</table><br>';	
		html = header + html;
		document.getElementById('roomPanel').innerHTML = html;
		document.getElementById('CM_ImgGoEstimate').style.visibility = 'visible';
		
	}
}



function callback_getDestination(res)
{
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		html[html.length]="<table align=\"left\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" border=\"0\" class=\"vbmenu_option\">"
		html[html.length]="<tr valign=\"top\" ><td nowrap>";
		for(var i=0; i<res.value.Tables[0].Rows.length; i++){
		if (i % 25 == 0 && i>0){
			html[html.length]="</td><td nowrap>";
		}
			html[html.length] = "<li><a href=\"javascript:setDestination('" + res.value.Tables[0].Rows[i].Country + "')\">" + res.value.Tables[0].Rows[i].Country + "</a></li>";
		}
		html[html.length]="</td></tr></table>";
		document.getElementById("display1").innerHTML = html.join("");
	}
}

function getDestination(pDestinationType)
{
	AjaxMethods.getDestination(pDestinationType,callback_getDestination);
}

function getDestinationTOP(pDestinationType)
{
	AjaxMethods.getDestination(pDestinationType,callback_getDestinationTOP);
}

function callback_getDestinationTOP(res)
{
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		html[html.length]="<table align=\"left\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" border=\"0\" class=\"vbmenu_option_best\">"
		html[html.length]="<tr valign=\"top\" ><td nowrap class=\"vbmenu_option_best\">";
		for(var i=0; i<res.value.Tables[0].Rows.length; i++){
		if (i % 15 == 0 && i>0){
			html[html.length]="</td><td nowrap class=\"vbmenu_option_best\">";
		}
			html[html.length] = "<li><a href=\"javascript:setDestination('" + res.value.Tables[0].Rows[i].Country + "')\">" + res.value.Tables[0].Rows[i].Country + "</a></li>";
		}
			
		html[html.length]="</td></tr></table>";
		
		document.getElementById("displayTOP").innerHTML = html.join("");
	}
}

function getDestinationFlight(pDestinationType)
{
	AjaxMethods.getDestination(pDestinationType,callback_getDestinationFlight);
}

function callback_getDestinationFlight(res)
{
	if(res != null && res.value != null && res.value.Tables != 0 && res.value.Tables.length == 1)
	{
		var html = [];
		html[html.length]="<table align=\"left\" cellspacing=\"2\" cellpadding=\"0\" width=\"100%\" border=\"0\" class=\"vbmenu_option\">"
		html[html.length]="<tr valign=\"top\" ><td nowrap>";
		for(var i=0; i<res.value.Tables[0].Rows.length; i++){
		if (i % 15 == 0 && i>0){
			html[html.length]="</td><td nowrap>";
		}
			html[html.length] = "<li><a href=\"javascript:setDestinationFlight('" + res.value.Tables[0].Rows[i].Country + "')\">" + res.value.Tables[0].Rows[i].Country + "</a></li>";
		}
		html[html.length]="</td></tr></table>";
		document.getElementById("display1").innerHTML = html.join("");
	}
}

function getPrices(pAirportName,pAirportCode,pDateFrom,pDateTo,pDestinationName, pCity, pAccomodation, pNights, pReferer, pAirportNumber, pPromoMsg, pPlan, pSection)
{
	AjaxMethods.getPrices(pAirportName,pAirportCode,pDateFrom,pDateTo,pDestinationName, pCity, pAccomodation, pNights, pReferer, pAirportNumber, pPromoMsg, pPlan, pSection, callback_getPrices);
}

function rollOn(layName, tot, section){

for (var i=1; i<=parseInt(tot);i++){
	document.getElementById('lay_AirportName'+i).className=section+'_link_off';
}
document.getElementById(layName).className=section+'_link_on';

}

function callback_getPrices(res)
{
	if(res != null && res.value != null)
	{	
		document.getElementById("cont_risultati").innerHTML = res.value;//html.join("");
	}
}



function getAirportArrive(tabbedName, productType)
{
	document.getElementById("fromCityLS").value=tabbedName;//set quick search

	AjaxMethods.getAirportArrive(tabbedName, 'ITALY_LOCATION', productType, callback_getAirportArriveItaly);


	AjaxMethods.getAirportArrive(tabbedName, 'EUROPE_LOCATION', productType, callback_getAirportArriveEurope);


	AjaxMethods.getAirportArrive(tabbedName, 'WORLD_LOCATION', productType, callback_getAirportArriveWorld);

}

function callback_getAirportArriveItaly(res)
{

	if(res != null && res.value != null)
	{	
		document.getElementById("ITALY_LOCATION").innerHTML = res.value;//html.join("");
	}
}
function callback_getAirportArriveEurope(res)
{
	if(res != null && res.value != null)
	{	
		document.getElementById("EUROPE_LOCATION").innerHTML = res.value;//html.join("");
	}
}
function callback_getAirportArriveWorld(res)
{
	if(res != null && res.value != null)
	{	
		document.getElementById("WORLD_LOCATION").innerHTML = res.value;//html.join("");
	}
}

function rollOnAirportTabbed(homeId,indexSel){

for (var i=0; i<=5;i++){
var cssName;
if (homeId=='Flight'){
cssName='tab_volo'
}else{
cssName='tab_volohotel'
}
	document.getElementById('AirportTabbed'+i).className=cssName+'_off';
	document.getElementById('CentralPane'+homeId+'Destination1__ctl'+i+'_HLAirport').className=cssName+'_off';	
	//alert('CentralPaneFlightDestination1__ctl'+String(parseInt(indexSel)-1)+'_HLAirport')
}
document.getElementById('AirportTabbed'+indexSel).className=cssName+'_on';
document.getElementById('CentralPane'+homeId+'Destination1__ctl'+indexSel+'_HLAirport').className=cssName+'_on';

}


function getOfferDescription(idOffer)
{
	AjaxMethods.getOfferDescription(idOffer,callback_getOfferDescription);
}




function callback_getOfferDescription(res)
{	

	if(res != null && res.value != null)
	{
	
	document.getElementById('dettaglio_text').innerHTML='<span id="flightPlanDetails"></span>'+res.value.replace('<B>OPERATIVO VOLI:</B>','');
	document.getElementById('dettaglio_text').innerHTML=document.getElementById('dettaglio_text').innerHTML.replace('<br><br><br>','')
	document.getElementById('dettaglio_text').innerHTML=document.getElementById('dettaglio_text').innerHTML.replace('<BR><BR><BR>','')
	if (document.getElementById('flightPlan') != null){
	var fp = document.getElementById('flightPlan').innerHTML
	var s = document.getElementById('flightPlan').innerHTML
	if (navigator.appName=='Microsoft Internet Explorer'){
		s = s.substring(0,s.indexOf('<DIV id=flightPlanNotes>'))
	}
	else
	{
		s = s.substring(0,s.indexOf('<div id="flightPlanNotes">'))
	}

	
	var z = '<table width="100%" class="priceDetails_popup"><tr></td><span class="cVacation_flight_plan_header"><img src="../img/utility/flightPlan.gif" align="textTop"></span></td></tr>'
	z += '<tr class="cVacation_Dark"><td>';

	document.getElementById('flightsPlan').innerHTML = z + s + '</td></tr></table>';
	document.getElementById('flightPlan').innerHTML=z + fp + '</td></tr></table>';
	}
	}
}