///<reference path="jquery-1.3.2-vsdoc2.js" />




$(document).ready(function(){
				fixPagerForAccesibillity();
				
				
				$("span.Days").css("margin-right","7px");						
				$("span.Days").css("margin-left","1px");						
				
				if($.browser.msie || $.browser.mozilla)
				{
					SetCtrlsMarkFocus();
				}	
								
				
				$('table.FlightsGridMain').attr("rules","none");
				$('table.FlightsGridMainScroll').attr("rules","none");
				
				$("#AutoAirLineCompany").autocomplete(AutoAirLineCompanyFull, {
					resultsClass: "ac_results ac_resultsEn",
					minChars: 0,
					
					max: 100,

					mustMatch: true,
					matchContains: false,
					scrollHeight: 220
				});
				$("#autoCountry").autocomplete(AutoCountriesFull, {
					resultsClass: "ac_results ac_results" + lang,
					minChars: 0,					
					max: 100,
					mustMatch: true,
					matchContains: false,
					scrollHeight: 220
				});
				$("#autoCity").autocomplete(AutoCitiesFull, {
					resultsClass: "ac_results ac_results" + lang,
					minChars: 0,
					
					max: 100,

					mustMatch: true,
					matchContains: false,
					scrollHeight: 220
		
				});
				$("#autoAirPort").autocomplete(AutoAirPortFull, {
					resultsClass: "ac_results ac_resultsEn",
					minChars: 0,					
					max: 100,
					mustMatch: true,
					matchContains: false,
					scrollHeight: 220
				});
								
				if (AutoFestivalFull != "")
				{
				
					$("#AutoFestival").autocomplete(AutoFestivalFull, {
						resultsClass: "ac_results ac_results" + lang,
						minChars: 0,
						
						max: 100,

						mustMatch: true,
						matchContains: false,
						scrollHeight: 220
					});
				}
				
				//-----------------------------------------------

				
				//---------------------------  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
					{
						//in case there was value in input of country and user typed ""
						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() != "")
					// &&
					//	$("#autoCountry").val() != AllStrInLang )
					{												
																																		
							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").bind("blur", function(){	
					
					
															
					if($("#autoAirPort").val() == "")
					{						
						//$("#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() != "")
					{
						getMatchAirLineCompany();
					}
					else
					{					
						$("#hdnAirLineCompanyID").val("");		
					}
										
				});
				
				$("#AutoFestival").bind("blur", function(){						
				
					if($("#AutoFestival").val() == "")
					{
						//$("#AutoFestival").val(AllStrInLang);
															
					}
					if( $("#AutoFestival").val() != "")
					{
						var fest = getMatchFestival();
						
						if(fest != "")
						{
							$("#txtFromDate").val("");
							$("#txtToDate").val("");							
						}
					}
					else
					{					
						$("#hdnFestivalID").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");													
				});
				
				$("#AutoFestival").bind("focus", function(){
						OnFocus("#AutoFestival");													
				});*/
				
				
											
			
			});
			
			
		//----------------------------- end ready -------------------	
		
		//suppose to open the autocomplete section in case "All" was in ctrl
		/*
		function OnFocus(clientId)
		{									
			if ($(clientId).val()== AllStrInLang)
			{				
				$(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 ( $.trim(pair[1]) == $.trim(text) )
					{
						document.getElementById('hdnAirLineCompanyID').setAttribute("value",pair[0]);						
						return pair[0];
					}
				}				
			}
		}
		function getMatchValueCountry()
		{										
			//var text = getSelectedItem("cmbCountry").innerText;
			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 ( $.trim(pair[1]) == $.trim(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 getMatchFestival()
		{
			var text = $("#AutoFestival").val();			
						
			if (text != null && typeof(text) != 'undefined' && 
				FestivalFull != null && typeof(FestivalFull) != 'undefined' )
			{				
				var pairs = FestivalFull.split(';');
				for (var i = 0; i < pairs.length; i++) 
				{					
					var pair = pairs[i].split("|");
										
					if (pair[0] == text)
					{	
										
						document.getElementById('hdnFestivalID').setAttribute("value",pair[1] + "|" + pair[2] + "|" + pair[3]);												
					}
				}				
			}
		}
		
		//---------------------------------------------------------
		
		//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 ClearFilterData()
		{	//Clear text boxes		
			
			
			$("#autoCity").flushCache()
			$("#autoCity").setOptions({data: AutoCitiesFull});
			
			$("#autoAirPort").flushCache()
			$("#autoAirPort").setOptions({data: AutoAirPortFull});
			
			
			$("#txtFromDate").val("");
			$("#txtToDate").val("");
						
			$("input:checkbox").attr('checked','true');
			
			/*
			$("input.autoCompleteHe").val(AllStrInLang);
			$("input.autoCompleteComboHe").val(AllStrInLang);
			$("input.autoCompleteEn").val(AllStrInLang);
			$("input.autoCompleteComboEn").val(AllStrInLang);*/
			
			$("input.autoCompleteHe").val("");			
			$("input.autoCompleteEn").val("");			
			
			$("#hdnAirLineCompanyID,#hdnCountryID,#hdnCityID,#hdnAirportID,#hdnFestivalID").attr("value", "");
			
			$("div.ac_results").css("display", "none");
			
			$("#lblNoData").text("");
			$("#spnSearchDesc").text("");
			
		}
		
		function CreateOption(arrItems, text, value)
		{		
			arrItems.push(text);
		}
		
		
		
		//-------------------------------------------
		
		
		

		
		

