

// if want to disblay text boxes with load gif - not so recomanded if user is realy fast he can cach it while loading and auto complete doesnt show there for hide it while loading ajax see below
//document.searchForm.CodeLoad.className = "ac_loading";
//document.searchForm.CityLocation.className = "ac_loading";
//document.searchForm.RegAreaLocation.className = "ac_loading";


function findCity2(li) {
if( li == null ) 
{
	//document.getElementById("CityLocation2").value = "";// not found clear user value
	return; //alert("No match, city was not found !"); 	
}
// if coming from an AJAX call, let's use the CityId as the value	
if( !!li.extra ) 
	{
		var sValue = li.extra[0]; 	
	}
// otherwise, let's just display the value in the text box	
else 
	{	var sValue = li.selectValue; 	
		
	}
	//alert("findCity: " + sValue);
	LoadRegArea2(sValue);
}

//function formatItem(row) {	return row[0] + " (id: " + row[1] + ")";}
/*
function lookupLocal(){	
	var oSuggest = $("#CityLocation")[0].autocompleter; 	
	oSuggest.findValue();	
	
	return false;
}
*/
function selectCity2(li) {	findCity2(li); }

////////////////////////////////////////////////////////////////////////////////
function findRegArea2(li) {
if( li == null ) 
{
	//document.getElementById("RegAreaLocation2").value = "";// not found clear user value
	return; //alert("No match, RegArea was not found !"); 	
}
// if coming from an AJAX call, let's use the CityId as the value	
if( !!li.extra ) 
	{
		var sValue = li.extra[0]; 	
	}
// otherwise, let's just display the value in the text box	
else 
	{	var sValue = li.selectValue; 	
		
	}
	//alert("findRegArea: " + sValue);
	
}

function selectRegArea2(li) {	findRegArea2(li); }
//////////////////////////////////////////////////////////////////////////////////





$(document).ready(function() {

	LoadCities2();
	
	LoadRegArea2('');
});



// getCities.asp
function LoadCities2()
{
	$.get("/JS_AUTOCOM/getCities.asp", function(data){
  		//alert("Data Loaded: " + data);
   		$("#CityLocation2").autocompleteArray(		data.split(","),		{
													   delay:10,
													   minChars:1,
													   matchSubset:1,
													   cacheLength:1,
													   onItemSelect:selectCity2,
													   onFindValue:findCity2,
													   autoFill:false,
													   selectFirst:true
													   }	//maxItemsToShow:100  
		);
		$("#CityLoad2").css("display","none");
		document.searchForm2.CityLocation2.style.display = "block";
		//document.getElementById('CityLoad2').style.display = "none";
	});
}
///////////////////////////////////////////////////////////////////////////////////////
// will be also called on findCity()
function LoadRegArea2(city_)
{
	//if (city_!="")
	//{
		// prevent caching ! caching - cuases duplication values and bugs !
		var oSuggest = $("#RegAreaLocation2")[0].autocompleter; 
		if (oSuggest)
		{
			oSuggest.flushCache();
			document.searchForm2.RegAreaLocation2.value="";
		}
	//}
	
	document.searchForm2.RegAreaLocation2.style.display = "none";
	document.getElementById('RegAreaLoad2').style.display = "block";
	$.get("/JS_AUTOCOM/getRegArea.asp?city="+city_, function(data){
  		//alert("Data Loaded: " + data);
   		$("#RegAreaLocation2").autocompleteArray(		data.split(","),		{
													   delay:10,
													   minChars:1,
													   matchSubset:1,
													   cacheLength:1,
													   autoFill:false,
													   onItemSelect:selectRegArea2,
													   onFindValue:findRegArea2,
													   selectFirst:true
													   }	//maxItemsToShow:100  
		);
		document.searchForm2.RegAreaLocation2.style.display = "block";
		document.getElementById('RegAreaLoad2').style.display = "none";
	});
}




function checkCity2() // enter "" if not in list
{
	//alert('checkCity');
	$("#CityLocation2")[0].autocompleter.findValue();
	// becuase findValue() is an event use this setTimeout to wait for sure for
	//document.getElementById("CityLocation").value
	
	// if user deleted value or chose no mach value - load again regions...
	setTimeout(function(){ if (document.searchForm2.CityLocation2.value == "")
	{
		// prevent caching ! caching - cuases duplication values and bugs !
		$("#RegAreaLocation2")[0].autocompleter.flushCache();
		LoadRegArea2(''); // TO LOAD ALL REGION AGAIN IF USER HAS DELETED THE WANTED CITY AND WANTS TO GET ALL REGIONS & AREAS
	}},200);
			
}
/////////////////////////////////////////////////////////////////////////
function checkRegArea2() // enter "" if not in list
{
	//alert('checkRegArea'); 
	$("#RegAreaLocation2")[0].autocompleter.findValue();	
		
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////