///<reference path="jquery-1.3.2-vsdoc2.js" />
var EVERYTHING;
var siteName;
var dgOnlineFlightsClientID;
var	dgOnlineDepartureFlightsClientID;
var sortedColumnIndx;
var arrowSortPath;
var ArrRemarksLogos = new Array();
var curFullURL;

function formatResult(row)
{	
	if(row.disable == "true")
	{														
		return " ";						 									
	}						
	else
	{										
		return row.name;
	}
}
function formatMatch(row)
{			
	if(row.disable == "true")
	{																
		return row.name; 							
	}						
	else
	{										
		return row.name;
	}
	
}
//Disable all fields except the txtFlightNumber
function SetDisableStateFields(isDisable)
{	
	if(isDisable)								
	{
		$("#AutoAirLineCompany,#autoAirPort,#autoCity,#autoCountry").attr('disabled','disabled');
		$("#AutoAirLineCompany,#autoAirPort,#autoCity,#autoCountry").css("background-color","#C0C0C0");
	}
	else
	{	
		$("#AutoAirLineCompany,#autoAirPort,#autoCity,#autoCountry").removeAttr('disabled');
		$("#AutoAirLineCompany,#autoAirPort,#autoCity,#autoCountry").css("background-color","");
	}						
}

//Reset the fields at the search part
function ClearFilterData()
{
	//Clear text boxes	
	$("#txtFlightNumberAd").val("");
		
	SetDisableStateFields(false);		
	
	$("#autoCity").flushCache()
	$("#autoCity").setOptions({data: AutoCitiesFull});
	
	$("#autoAirPort").flushCache()
	$("#autoAirPort").setOptions({data: AutoAirPortFull});
	
	/*
	$("input.autoCompleteHe").val(AllStrInLang);
	$("input.autoCompleteComboHe").val(AllStrInLang);
	$("input.autoCompleteEn").val(AllStrInLang);
	$("input.autoCompleteComboEn").val(AllStrInLang);
	*/
	
	$("input.autoCompleteHe").val("");	
	$("input.autoCompleteEn").val("");	
	
	//no need
	$("#hdnAirLineCompanyID,#hdnCountryID,#hdnCityID,#hdnAirportID").attr("value", "");	
	
	$("div.ac_results").css("display", "none");
		
}


//Set search type display, and update the hdnIsAdvanced input
function SetSearchType(containerToClose, containerToOpen)
{
	
	
	$("#" + containerToClose).css("display","none");
	$("#" + containerToOpen).css("display","inline");

	if(containerToOpen == "tbdyAdvancedSearchContainer")
	{	
		$("#hdnIsAdvanced").val("True");
	}
	else
	{
		$("#hdnIsAdvanced").val("False");
	}
	
}


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 activeDiv;
	
	if(document.getElementById("divFlightsData") !=null && $.trim($("#divFlightsData").html()).length > 10 )
		activeDiv = "divFlightsData" ;
	 else
		activeDiv = "divDepData";
	
	
	var activeTable = (activeDiv=="divFlightsData") ? dgOnlineFlightsClientID : dgOnlineDepartureFlightsClientID;
	//if(document.all[activeTable]!=null)
	
	if(document.getElementById(activeTable)!=null)
	{
		if(document.all[activeTable].clientHeight<400)
		{
			document.all[activeDiv].style.height = document.all[activeTable].clientHeight;
		}
	}
	else
	{
		if(document.getElementById("divFlightsData")) document.getElementById("divFlightsData").style.height = 0;
		if(document.getElementById("divDepData")) document.getElementById("divDepData").style.height = 0;
	}*/
}

function FireFlightsSearch()
{

	if(event.keyCode==13)
	{
		$("#imgBtnSearch").click();
		/*
		if($("#hdnIsAdvanced").val() != "")
		{	
			$("#imgBtnSearchAd").click();	
		}
		else
		{
			$("#imgBtnSearch").click();
		}
		event.returnValue = false;*/
	}
}


function InitAutoCompleteCityControl()
{
	$("#autoCity").autocomplete(AutoCitiesFull, {
		resultsClass: "ac_results ac_results" + lang,
		minChars: 0,		
		max: 100,		
		mustMatch: true,
		matchContains: false,
		scrollHeight: 220,
		formatItem: function(row, i, max) {
			if(row.disable == "true")
			{								
				return "<span style='color:gray'>" + row.name + "</span>";							
			}						
			else
			{							
				return row.name;
			}
		},
		formatMatch : formatMatch,
		formatResult : formatResult

	});
}
function InitAutoCompleteAirportControl()
{
	$("#autoAirPort").autocomplete(AutoAirPortFull, {
		resultsClass: "ac_results ac_resultsEn",
		minChars: 0,		
		max: 100,
		mustMatch: true,
		matchContains: false,
		scrollHeight: 220,
		formatItem: function(row, i, max) {
			if(row.disable == "true")
			{								
				return "<span style='color:gray'>" + row.name + "</span>";							
			}						
			else
			{							
				return row.name;
			}
		},
		formatMatch : formatMatch,
		formatResult : formatResult
	});
	
}


function InitAutoCompleteControls()
{
	$("#AutoAirLineCompany").autocomplete(AutoAirLineCompanyFull, {
		resultsClass: "ac_results ac_resultsEn",
		minChars: 0,
		width: 220,
		max: 100,		
		mustMatch: true,
		matchContains: false,
		scrollHeight: 220,
		formatItem: function(row, i, max) {
			if(row.disable == "true")
			{								
				return "<span style='color:gray'>" + row.name + "</span>";							
			}						
			else
			{							
				return row.name;
			}
		},
		formatMatch : formatMatch,
		formatResult : formatResult
		});
		
				
		
	$("#autoCountry").autocomplete(AutoCountriesFull, {
		resultsClass: "ac_results ac_results" + lang,
		minChars: 0,		
		max: 100,		
		mustMatch: true,
		matchContains: false,
		scrollHeight: 220,
		formatItem: function(row, i, max) {
			if(row.disable == "true")
			{								
				return "<span style='color:gray'>" + row.name + "</span>";							
			}						
			else
			{							
				return row.name;
			}
		},
		formatMatch : formatMatch,
		formatResult : formatResult
	});
	
	
	InitAutoCompleteCityControl();
	
	InitAutoCompleteAirportControl();
	
}






$(document).ready(function(){
							
					$("input[type='image']").css("vertical-align","middle");
					$("input[type='text']").css("vertical-align","middle");
					
					if($.browser.msie)
					{
						if(lang == "He")
						{
							$("#tab1").attr("width", "100");
						}
						if(lang == "En")
						{
							$("#tab1").attr("width", "100");
						}
					}
					
					
					if($.browser.msie || $.browser.mozilla)
					{
						SetCtrlsMarkFocus();
					}
					
					/*
					$("body").mousedown(function(event) {
						if (event.button == 2) {
							$("div.ac_results").css("display", "none");
						}
					});*/
								
				
				/* yoram - because there is no intellygate
					//---- BIND tooltip to imgBtnSearch
					$("#imgBtnSearch").bind("mouseover", function(){
						$("#IntellyGateSearchToolTip").css('display','inline');
					});										
					
					$("#imgBtnSearch").bind("mouseout", function(){
						$("#IntellyGateSearchToolTip").css('display','none');
					});
					
					$("#imgBtnSearch").bind("focus", function(){
						$("#IntellyGateSearchToolTip").css('display','inline');
					});
					
					$("#imgBtnSearch").bind("blur", function(){
						$("#IntellyGateSearchToolTip").css('display','none');
					});
					
					//---- BIND tooltip to txtFlightNumber
					
					$("#txtFlightNumber").bind("mouseover", function(){
						$("#IntellyGateSearchToolTip").css('display','inline');
					});
					
					$("#txtFlightNumber").bind("mouseout", function(){
						$("#IntellyGateSearchToolTip").css('display','none');
					});
					
					$("#txtFlightNumber").bind("focus", function(){
						$("#IntellyGateSearchToolTip").css('display','inline');
					});
					
					$("#txtFlightNumber").bind("blur", function(){
						$("#IntellyGateSearchToolTip").css('display','none');
					});*/
					
					
					
					
					fixPagerForAccesibillity();	
					
					InitAutoCompleteControls();									
					
				
					
				//---------------------------  Bind Cities --------------
				//fires after COUNTRY blur
				function bindCityRelatedBlur()
				{
				
					/*
					if($("#autoCountry").val() == "")
					{
						$("#autoCountry").val(AllStrInLang);
					}*/
					
					if(	$("#autoCountry").val() != "")  
					{												
						
						//if value of COUNTRY was changed					
						if(		$("#autoCountry").val() != getValueCountry(	$("#hdnCountryID").val() )		) 							
						{	
							// bind cities
							var comboSelectedValueC = getMatchValueCountry();							
							
																					
							FillComboByUrl("#autoCity",comboSelectedValueC+"|CountryID",window.location.href,"");								
														
							
							//bind airports												
							FillComboByUrl("#autoAirPort",comboSelectedValueC+"|CountryForAirportsId",window.location.href,"");																			
							
							
							//$("#autoCity").val(AllStrInLang);
							$("#hdnCityID").val("");	
							
							//$("#autoAirPort").val(AllStrInLang);
							$("#hdnAirportID").val("");							
							
							
							
						}
					}
					else
					{
						if($("#hdnCountryID").val() != "")
						{
							$("#hdnCountryID").val("");	
							
							$("#autoCity").flushCache()
							$("#autoCity").setOptions({data: AutoCitiesFull});

							$("#autoAirPort").flushCache()
							$("#autoAirPort").setOptions({data: AutoAirPortFull});
						}
						
					}
				}
				
				//FIRES EACH LOAD OF PAGE!!
				function bindCityRelated()
				{								
				
					if(	$("#autoCountry").val() != "")
					{												
																																		
							var comboSelectedValueC = getMatchValueCountry();
							
							// bind cities														
							FillComboByUrl("#autoCity",comboSelectedValueC+"|CountryID",window.location.href,"");								
														
							$("#autoCity").val( getValueCity( $("#hdnCityID").val() ) );														
							
							if( $("#autoCity").val() == "" )
							{
								//$("#autoCity").val(AllStrInLang);
								$("#hdnCityID").val("");	
							}
						
							
							//bind airports												
							FillComboByUrl("#autoAirPort",comboSelectedValueC+"|CountryForAirportsId",window.location.href,"");																			
							
							$("#autoAirPort").val( getValueAirport( $("#hdnAirportID").val() ) );														
							
							if( $("#autoAirPort").val() == "" )
							{
								//$("#autoAirPort").val(AllStrInLang);
								$("#hdnAirportID").val("");	
							}	
							
						
					}
					else
					{
						$("#hdnCountryID").val("");	
						
					}
				}
				
				$("#autoCountry").bind("blur", function(){
						bindCityRelatedBlur();													
				});
								
										
				bindCityRelated();
				
					
				//-------------------------Bind Airports ------------------------		
				
				//fires after CITY blur
				function bindAirPortRelatedBlur()
				{	
					
									/*
					if($("#autoCity").val() == "")
					{
						$("#autoCity").val(AllStrInLang);
					}*/
					
					if($("#autoCity").val() != "")
					{
						//if value of CITY was changed					
						if(		$("#autoCity").val() != getValueCity(	$("#hdnCityID").val() )		) 							
						{						
							// bind air ports
							var comboSelectedValueA = getMatchValueCity();								

							var response = FillComboByUrl("#autoAirPort",comboSelectedValueA+"|CityID",window.location.href,"");
							
							//set airports "all"
							//$("#autoAirPort").val(AllStrInLang);
							$("#hdnAirportID").val("");	
							
							//set country
							var arrResponse  = response.split('*');
							var country = arrResponse[1];																								
							$("#autoCountry").val(getValueCountry(country));
							$("#hdnCountryID").val(country);
							
						}
						
					}
					else					
					{						
						//city input was with value and user typed "";
						if($("#hdnCityID").val() != "")
						{
							$("#hdnCityID").val("");	
							
							var comboSelectedValueC = getMatchValueCountry();
							
							if(comboSelectedValueC != "")	//there is country
							{								
								//bind airports												
								FillComboByUrl("#autoAirPort",comboSelectedValueC+"|CountryForAirportsId",window.location.href,"");																			
							
								$("#autoAirPort").val( getValueAirport( $("#hdnAirportID").val() ) );														
							}
							else
							{								
								$("#autoAirPort").flushCache()
								$("#autoAirPort").setOptions({data: AutoAirPortFull});
							}
														
						}						
					}
					
				}
				
				//FIRES EACH LOAD OF PAGE!!
				function bindAirPortRelated()
				{	
					
						/*
					if ($("#hdnCityID").val() == "")
					{
						$("#autoCity").val(AllStrInLang);
					}	*/		
					
					
					if($("#autoCity").val() != "")
					{
						// bind air ports
						var comboSelectedValueA = getMatchValueCity();								

						var response = FillComboByUrl("#autoAirPort",comboSelectedValueA+"|CityID",window.location.href,"");
						
						$("#autoAirPort").val( getValueAirport( $("#hdnAirportID").val() ) );														
							
						if( $("#autoAirPort").val() == "" )
						{
							//$("#autoAirPort").val(AllStrInLang);
							$("#hdnAirportID").val("");	
						}						
					}
					else					
					{
						$("#hdnCityID").val("");
						
													
					}
					
				}
				
				$("#autoCity").bind("blur", function(){						
					bindAirPortRelatedBlur();					
					
				});
								
				bindAirPortRelated();									
				
				//-------------------------   airport blur   ---------------
				
				//set airPort							
				if($("#hdnAirportID").val() != "")
				{
					$("#autoAirPort").val(getValueAirport($("#hdnAirportID").val()));
				}
				else
				{
					//$("#autoAirPort").val(AllStrInLang);
					$("#autoAirPort").val("");
				}
				
				$("#autoAirPort").bind("blur", function(){	
				
					//alert("in auirport blur");
															
					if($("#autoAirPort").val() == "")
					{						
						//$("#autoAirPort").val(AllStrInLang);												
					}
					
					//if( $("#autoAirPort").val() != AllStrInLang)
					if( $("#autoAirPort").val() != "")
					{
						//put value in hidden
						getMatchValueAirPorts();											
						
						var response = GetCountryAndCityRelatedToAirport($("#hdnAirportID").val() + "|AirPortID",window.location.href);
												
						var arrResponse  = response.split('*');
						var country = arrResponse[0];		
						var city	= arrResponse[1];	
						
						
						
						$("#autoCountry").val(getValueCountry(country));
						$("#hdnCountryID").val(country);
						
						$("#autoCity").val(getValueCity(city));
						$("#hdnCityID").val(city);
							
					}
					else
					{
						$("#hdnAirportID").val("");											
					}
					
					
				});
			
				//-----------------------------------------------------
				$("#AutoAirLineCompany").bind("blur", function(){						
																		
					if($("#AutoAirLineCompany").val() == "")
					{
						//$("#AutoAirLineCompany").val(AllStrInLang);
															
					}
					//if( $("#AutoAirLineCompany").val() != AllStrInLang)
					if( $("#AutoAirLineCompany").val() != "")
					{
						getMatchAirLineCompany();
					}
					else
					{					
						$("#hdnAirLineCompanyID").val("");		
					}
					
				});
				
				
				$("#txtFlightNumberAd").bind("blur",function(){
					SetDisableStateFields($(this).val() != "");				
				});
				
				SetDisableStateFields($("#txtFlightNumberAd").val() != "")																			
				
				
				//---------   bind focus event
				
				/*
				$("#AutoAirLineCompany").bind("focus", function(){
						OnFocus("#AutoAirLineCompany");													
				});
				
				
				$("#autoCountry").bind("focus", function(){
						OnFocus("#autoCountry");													
				});								
				
				$("#autoCity").bind("focus", function(){
						OnFocus("#autoCity");													
				});
				
				$("#autoAirPort").bind("focus", function(){
						OnFocus("#autoAirPort");													
				});
				
				
				//bind 
				
				$("#AutoAirLineCompany").bind("keypress", function(){
						OnFocus("#AutoAirLineCompany");													
				});
				
				$("#autoCountry").bind("keypress", function(){
						OnKeyPress("#autoCountry");													
				});								
				
				$("#autoCity").bind("keypress", function(){
						OnFocus("#autoCity");													
				});
				
				$("#autoAirPort").bind("keypress", function(){
						OnFocus("#autoAirPort");													
				});*/
			
			});
			
			
			
			
			
		//----------------------------- end ready -------------------
		
		//suppose to open the autocomplete section in case "All" was in ctrl
		/*
		function OnFocus(clientId)
		{									
			
			if ($(clientId).val()== AllStrInLang)
			{				
				$(clientId).val("");								
			}
		}
		
		function OnKeyPress(clientId)
		{				
			if ($(clientId).val()== AllStrInLang)
			{				
				//alert($(clientId).val());
				$(clientId).val("");				
			}
		}*/
			
		function getMatchAirLineCompany()			
		{
			
			var text = $("#AutoAirLineCompany").val();
			if (text != null && typeof(text) != 'undefined' && 
				AirLineCompanyFull != null && typeof(AirLineCompanyFull) != 'undefined' )
			{
				var pairs = AirLineCompanyFull.split('|');
				for (var i = 0; i < pairs.length; i++) 
				{
					var pair = pairs[i].split(";");
					if (pair[1] == text)
					{
						document.getElementById("hdnAirLineCompanyID").setAttribute("value",pair[0]);						
						return pair[0];
					}
				}				
			}
		}
		function getMatchValueCountry()
		{							
			var text = $("#autoCountry").val();
			
			var res = "";
			
			if (text != null && typeof(text) != 'undefined' && 
				CountriesFull != null && typeof(CountriesFull) != 'undefined' )
			{
				var pairs = CountriesFull.split('|');
				for (var i = 0; i < pairs.length; i++) 
				{
					var pair = pairs[i].split(";");
					if (pair[1] == text)
					{
						document.getElementById("hdnCountryID").setAttribute("value",pair[0]);						
						res = pair[0];
					}
				}				
			}
			
			return res;
		}
		
		function getMatchValueCity()
		{								
			//var text = getSelectedItem("cmbCity").innerText;
			
			
			var text = $("#autoCity").val();

						
			if (text != null && typeof(text) != 'undefined' && 
				CitiesFull != null && typeof(CitiesFull) != 'undefined' )
			{
				var pairs = CitiesFull.split('|');
				for (var i = 0; i < pairs.length; i++) 
				{
					var pair = pairs[i].split(";");
					if (pair[1] == text)
					{					
						document.getElementById("hdnCityID").setAttribute("value",pair[0]);
						return pair[0];
					}
				}				
			}
		}
		
		function getMatchValueAirPorts()
		{							
			//var text = getSelectedItem("cmbAirPorts").innerText;
			var text = $("#autoAirPort").val();			
			if (text != null && typeof(text) != 'undefined' && 
				AirPortsFull != null && typeof(AirPortsFull) != 'undefined' )
			{
				var pairs = AirPortsFull.split('|');
				for (var i = 0; i < pairs.length; i++) 
				{
					var pair = pairs[i].split(";");
					if (pair[1] == text)
					{					
						document.getElementById("hdnAirportID").setAttribute("value",pair[0]);						
					}
				}				
			}
		}
		
		function CreateOption(arrItems, text, disable)
		{		
			arrK = new Array (2);
			arrK["name"] = text;
			arrK["disable"] = disable;
			arrItems.push(arrK);
		}
		
		
		//---------------------------------------------------------
		
		//strAutoFull = AirPortsFull or CitiesFull or 
		function getValueCountry(countryID)		
		{
			var pairs = CountriesFull.split('|');
			for (var i = 0; i < pairs.length; i++) 
			{
				var pair = pairs[i].split(";");
				if (pair[0] == countryID)
				{										
					return pair[1];
				}
			}							
		}
		
		function getValueAirport(airportID)
		{
			var air = "";
			
			var pairs = AirPortsFull.split('|');
			
			for (var i = 0; i < pairs.length; i++) 
			{
				var pair = pairs[i].split(";");
				if (pair[0] == airportID)
				{										
					air = pair[1];
				}
			}		
			
			return air;		
		}
		
		function getValueCity(cityID)
		{
			var res1 = "";
			
			var pairs = CitiesFull.split('|');
			
			for (var i = 0; i < pairs.length; i++) 
			{
				var pair = pairs[i].split(";");
				if (pair[0] == cityID)
				{					
					//document.getElementById("hdnCityID").setAttribute("value",pair[1]);
					res1 = pair[1];
				}
			}			
			
			return res1;	
		}
		
		
		function hide()
		{
			
			for(var i = 0; i < ArrRemarksLogos.length ; i++)
			{
				ArrRemarksLogos[i].addClass("remarks_green_frame");
				ArrRemarksLogos[i].removeClass("remarks_orange_frame");
			}
			window.setTimeout("show()", 1000);
		}
		function show()
		{				
			for(var i = 0; i < ArrRemarksLogos.length ; i++)
			{
				ArrRemarksLogos[i].addClass("remarks_orange_frame");
				ArrRemarksLogos[i].removeClass("remarks_green_frame");					
			}
				
			window.setTimeout("hide()", 700);
		}
		function loadBlinkingSpans(){
			var k = 1;
				
			
			while($("#blink" + k).length)
			{								
				ArrRemarksLogos[ArrRemarksLogos.length] = $("#blink" + k);
				k++;
			}
		}



