﻿var EVERYTHING;
var siteName;
var dgOnlineFlightsClientID;
var	dgOnlineDepartureFlightsClientID;
var sortedColumnIndx;
var arrowSortPath;
var ArrRemarksLogos = new Array();
var curFullURL;
//Disable all fields except the txtFlightNumber
function SetDeisableStateFields()
{
	var disabledState;
	if(Form1.all["txtFlightNumberAd"].value == "")
		disabledState = false
	else
		disabledState = true
	Form1.all["txtAirlineCompany"].disabled = disabledState;
	Form1.all["txtCountry"].disabled = disabledState;
	Form1.all["txtCity"].disabled = disabledState;
	Form1.all["txtAirport"].disabled = disabledState;
}

//Reset the fields at the search part
function ClearFilterData()
{
	//Clear text boxes
	Form1.all["txtAirlineCompany"].value = EVERYTHING;
	Form1.all["txtCountry"].value = EVERYTHING;
	Form1.all["txtCity"].value = EVERYTHING;
	Form1.all["txtAirport"].value =EVERYTHING;
	Form1.all["txtFlightNumber"].value ='';
	Form1.all["txtFlightNumberAd"].value ='';
	
	//Clear the hiddend that holds the ID
	Form1.all["hdnAirLineCompanyID"].value = "";
	Form1.all["hdnCountryID"].value = "";
	Form1.all["hdnCityID"].value = "";
	Form1.all["hdnAirportID"].value = "";
	SetDeisableStateFields();
}

function OpenSearchPopup(path)
{
	var hdnContainer = event.srcElement.parentElement.previousSibling.children;
	var curKey = hdnContainer[hdnContainer.length-1].value;
	if(!Form1.all["txtFlightNumberAd"].value == "" )
		return;
	var popupXCoordinate = (window.screen.width - 355)/2
	window.open(path + '&siteName=' + siteName + '&curKey=' + curKey + "&openerurl=" + curFullURL,"flightsSearch","width=355,height=280,left=" + popupXCoordinate); 
}

//Set search type display, and update the hdnIsAdvanced input
function SetSearchType(containerToClose, containerToOpen)
{
	containerToClose.style.display = 'none';
	containerToOpen.style.display = 'inline';
	Form1.all["hdnIsAdvanced"].value = (containerToOpen.id==tbdyAdvancedSearchContainer.id)+"";
	
}


function ValidateSearch(source, arguments)
{
	///Validate non advanced search
	if(Form1.all["hdnIsAdvanced"].value.toLowerCase()=="false")
	{	if(Form1.all["txtFlightNumber"].value.length > 0)
		{
			arguments.IsValid=true;
			return;
		}
	}
	else
	{
		
		if(Form1.all["hdnAirLineCompanyID"].value.length > 0)
		{
			arguments.IsValid=true;
			return;
		}
		
		if(Form1.all["hdnCountryID"].value.length > 0)
		{
			arguments.IsValid=true; 
			return;
		}
		if(Form1.all["hdnCityID"].value.length > 0)
		{
			arguments.IsValid=true;
			return;
		}
		if(Form1.all["hdnAirportID"].value.length > 0)
		{
			arguments.IsValid=true;
			return;
		}
		if(Form1.all["txtFlightNumberAd"].value.length > 0)
		{
			arguments.IsValid=true;
			return;
		}
	}
	arguments.IsValid=false;
}


function adjustDiv()
{
	var activeDiv = (document.all["divFlightsData"]!=null && document.all["divFlightsData"].innerHTML!="") ? "divFlightsData" : "divDepData";
	var activeTable = (activeDiv=="divFlightsData") ? dgOnlineFlightsClientID : dgOnlineDepartureFlightsClientID;
	if(document.all[activeTable]!=null)
	{
		if(document.all[activeTable].clientHeight<400)
		{
			document.all[activeDiv].style.height = document.all[activeTable].clientHeight;
		}
	}
	else
	{
		if(document.all["divFlightsData"]) document.all["divFlightsData"].style.height = 0;
		if(document.all["divDepData"]) document.all["divDepData"].style.height = 0;
	}
}

function FireFlightsSearch()
{
	if(event.keyCode==13)
	{
		if(Form1.all["hdnIsAdvanced"].value)
		{	
			document.all["imgBtnSearchAd"].click();	
		}
		else
		{
			document.all["imgBtnSearch"].click();	
		}
		event.returnValue = false;
	}
}

function init()
{
	document.attachEvent("onkeypress", FireFlightsSearch);
	if(document.all["tblArrHeader"])
	{
		tblArrHeader.rows[0].cells[sortedColumnIndx].className = "tisot_sorting";
		tblArrHeader.rows[0].children[sortedColumnIndx].firstChild.firstChild.rows[tblArrHeader.rows[0].children[sortedColumnIndx].firstChild.firstChild.rows.length-1].children[1].firstChild.src = arrowSortPath;
	}
	else
	{
		tblFlightsHeader.rows[0].cells[sortedColumnIndx].className = "tisot_sorting";
		tblFlightsHeader.rows[0].cells[sortedColumnIndx].firstChild.firstChild.rows[tblFlightsHeader.rows[0].children[sortedColumnIndx].firstChild.firstChild.rows.length-1].children[1].firstChild.src = arrowSortPath;
	}
}



