
   function city_window(win_name, URL, lt, tp) 
   { msgWindow=window.open(URL,win_name,'toolbar=yes,width=1024,height=768,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,menubar=yes'+',left='+lt+',top='+tp) }





	function ClearList(OptionList, TitleName){
		OptionList.length = 0;
			OptionList.options[0] = new Option(TitleName, '', true, true);

		// added by cwl to ensure consistent widths of pull-down menus
		OptionList.options[1] = new Option ('-------------------------','');
	}
	function LoadModels(model_field, Index, selectedModel)
	{
		var ModelSelected = false;
		var tmp = '';
		var xtmp = 0;

			//alert(Index);
			if (Index > 0)
			{       var CurrentModelNames = ModelNames[Index].split('||');
					var CurrentModel_IDs = Model_IDs[Index].split('||');
					for (var i=0; i<CurrentModelNames.length; i++){
							model_field.options[i] = new Option(CurrentModelNames[i], CurrentModel_IDs[i], false, false);
							//tmp += CurrentModel_IDs[i] + ' = ' + selectedModel + '/';

							if(CurrentModel_IDs[i] == selectedModel){
							    xtmp = i;
								//model_field.options[i].selected = true;
								//ModelSelected = true;
								//alert(CurrentModel_IDs[i] + ' = ' + selectedModel);
							}
					}

					//if(!ModelSelected)
					//model_field.options[1].selected = true;
					//model_field.options[xtmp+3].selected = true;
					//alert(xtmp);
			}

			//var ModelSelected = false;
			//alert(tmp);
			//alert('Done');


		// added by cwl to ensure consistent widths of pull-down menus
		model_field.options[i] = new Option ('----------------','');
		model_field.options[xtmp].selected = true;


	}
	// not done yet.
	function LoadCitys(city_field, CIndex, PIndex, selectedCity)
	{
		var xtmp = 0;

			if ((PIndex >= 0) && ( CIndex > 0) )
			{
			 if (CityNames[CIndex - 1 + '_' + PIndex]) {
			var CurrentCityNames = CityNames[CIndex - 1 + '_' + PIndex ].split('||');
					var CurrentCityValue = CityValues[CIndex - 1 + '_' + PIndex ].split('||');
					for (var i=0; i<CurrentCityNames.length; i++){
							city_field.options[i] = new Option(CurrentCityNames[i], CurrentCityValue[i], false, false);

							if(CurrentCityValue[i] == selectedCity){
							    xtmp = i;
								//model_field.options[i].selected = true;
								//ModelSelected = true;
								//alert(CurrentModel_IDs[i] + ' = ' + selectedModel);
							}
					}

			 } else {
			var i = 0;
					city_field.options[i] = new Option('', '', false, false);
			i++;
			 }
				 //city_field.options[0].selected = true;
				 city_field.options[xtmp].selected = true;


		}
		city_field.options[i] = new Option ('----------------','');
	}











	function LoadTypes(Index)
	{       // ClearList(document.search.segmentlist, '-- Make --');

	    city_field = document.search.city_id;
	    make_field = document.search.make_id;
	    model_field = document.search.model_id;

			if (Index > 0)
			{       var CurrentSegments = Segments[Index - 1].split('||');
					for (var i=0; i<CurrentSegments.length; i++)
							document.search.segmentlist.options[i+1] = new Option(CurrentSegments[i], CurrentSegments[i], false, false);
					document.search.segmentlist.options[0].selected = true;
			}
	}

	function ChangeModels(make_field, model_field, CalledFromOnLoad, selectedModel)
	{       // Clear both of the lists first then add the options if valid Make has been selected. -GDC

			// cwl added to trap when user chooses the last item in the list (the equal signs)
		if (make_field.selectedIndex == (make_field.length - 1)){
			// reset to first make_id in the list
			make_field.selectedIndex = 1;
		}

		if (model_field.selectedIndex == (model_field.length - 1)) {
			// reset to first make_id in the list
			model_field.selectedIndex = 0;
		}

		var CurrIndex = model_field.selectedIndex;
		ClearList(model_field, 'Any Model');

		LoadModels(model_field, make_field.selectedIndex, selectedModel);

		//if (CalledFromOnLoad == 1){
		//	model_field.selectedIndex = CurrIndex;
		//} else {
		//	model_field.selectedIndex = 0;
		//}
	}


	function ChangeCitys(make_field, model_field, city_field, CalledFromOnLoad, selectedCity)
	{       // Clear both of the lists first then add the options if valid Make has been selected. -GDC

			// cwl added to trap when user chooses the last item in the list (the equal signs)
		if (make_field.selectedIndex == (make_field.length - 1)) {
			// reset to first make_id in the list
			make_field.selectedIndex = 1;
		}

		if (model_field.selectedIndex == (model_field.length - 1)) {
			// reset to first make_id in the list
			model_field.selectedIndex = 0;
		}

			ClearList(city_field, '-- Select City --');

			LoadCitys(city_field, make_field.selectedIndex, model_field.selectedIndex, selectedCity);

			if (CalledFromOnLoad == 1){
			var CurrIndex =city_field.selectedIndex;
			city_field.selectedIndex = CurrIndex;
			}

		if (city_field.selectedIndex == (city_field.length - 1)) {
			// reset to first make_id in the list
			city_field.selectedIndex = 0;
		}

	}
	
	/* These next functions were imported to use in the drop-down search suggestion boxes. */
	
	function getObj(objID)
{
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Left(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//Added to enable animation of DIVs	

var currentMovements = new Array();

function toNumber(myStr){
	newString = '';
	myStr = String(myStr);
	valids = "0123456789";
	for(nn=0;nn<myStr.length;nn++){
		if(valids.indexOf(myStr.substr(nn,1))>-1) newString += String(myStr.substr(nn,1));
		//if(Number()!==false) 
	}
	//alert(myStr + "\n" + newString);
	return Number(newString);
}

function start_moving(myDiv,givenSpeed,initW,finalW,initH,finalH){
	if(currentMovements[myDiv]){
		//alert('Called on ' + myDiv + "\r" + currentMovements[myDiv]['timeout']);
		delete currentMovements[myDiv];
	}
	//clearTimeout(currentMovements[myDiv]['timeout']);
	initW = toNumber(initW);
	initH = toNumber(initH);
	finalW = toNumber(finalW);
	finalH = toNumber(finalH);
	currentMovements[myDiv] = new Array();
	currentMovements[myDiv]['initial_width'] = initW;
	currentMovements[myDiv]['final_width'] = finalW;
	currentMovements[myDiv]['initial_height'] = initH;
	currentMovements[myDiv]['final_height'] = finalH;
	currentMovements[myDiv]['speed'] = givenSpeed;
	currentMovements[myDiv]['num'] = 0;
	//alert(currentMovements);
	currentMovements[myDiv]['timeout'] = setTimeout('keep_moving(\'' + myDiv + '\')',currentMovements[myDiv]['speed']);
}
function keep_moving(myDiv){
	//clearTimeout(currentMovements[myDiv]['timeout']);
	//alert('Attempting ' + myDiv + "\r" + currentMovements[myDiv]['num']);
	if(document.getElementById(myDiv)){
	currentMovements[myDiv]['num'] = Math.round(currentMovements[myDiv]['num']*100)/100 + 1/24;
	
	if (currentMovements[myDiv]['num']<1) {
		if(Math.abs(currentMovements[myDiv]['final_width']-currentMovements[myDiv]['initial_width'])>1){
			document.getElementById(myDiv).style.width = (Number(currentMovements[myDiv]['initial_width']) + Number(Math.round((currentMovements[myDiv]['final_width']-currentMovements[myDiv]['initial_width'])*(1/2-Math.cos(currentMovements[myDiv]['num']*3.14159265389793)/2))));
		} else {
			document.getElementById(myDiv).style.width = currentMovements[myDiv]['final_width'];
		}
		//if(currentMovements[myDiv]['final_height']-currentMovements[myDiv]['initial_height']<0) alert(myDiv + (Number(currentMovements[myDiv]['initial_height']) + Math.round((currentMovements[myDiv]['final_height']-currentMovements[myDiv]['initial_height'])*(1/2-Math.cos(currentMovements[myDiv]['num']*3.14159265389793)/2))));
		//alert("I -> " + currentMovements[myDiv]['initial_height'] + "\nD -> " + currentMovements[myDiv]['final_height'] + "\nR -> " + (currentMovements[myDiv]['final_height'] - currentMovements[myDiv]['initial_height']));
		if(Math.abs(currentMovements[myDiv]['final_height']-currentMovements[myDiv]['initial_height'])>1){
			//alert(Number(currentMovements[myDiv]['initial_height']) + Number(Math.round((currentMovements[myDiv]['final_height']-currentMovements[myDiv]['initial_height'])*(1/2-Math.cos(currentMovements[myDiv]['num']*3.14159265389793)/2))));
			document.getElementById(myDiv).style.height = (Number(currentMovements[myDiv]['initial_height']) + Number(Math.round((currentMovements[myDiv]['final_height']-currentMovements[myDiv]['initial_height'])*(1/2-Math.cos(currentMovements[myDiv]['num']*3.14159265389793)/2))));
		} else {
			//alert('no' + "\n" + get_height(myDiv) + "\n" + currentMovements[myDiv]['final_height']);
			document.getElementById(myDiv).style.height = currentMovements[myDiv]['final_height'];
		}
		
		 
	} else {
		currentMovements[myDiv]['num'] = 0;
		clearTimeout(currentMovements[myDiv]['timeout']);
		currentMovements[myDiv]['initial_width'] = currentMovements[myDiv]['final_width'];
		currentMovements[myDiv]['initial_height'] = currentMovements[myDiv]['final_height'];
		currentMovements[myDiv]['speed'] = 10000000000;
		document.getElementById(myDiv).style.width = currentMovements[myDiv]['final_width'];
		document.getElementById(myDiv).style.height = currentMovements[myDiv]['final_height'];
	}
	
	document.getElementById(myDiv).style.display = '';
	currentMovements[myDiv]['timeout'] = setTimeout('keep_moving(\'' + myDiv + '\')',currentMovements[myDiv]['speed']);
	} else {
		
	document.getElementById(myDiv).style.display = '';
	delete currentMovements[myDiv];
	clearTimeout(currentMovements[myDiv]['timeout']);
	}
}
function get_width(id){
	return toNumber(document.getElementById(id).style.width);
}
function get_height(id){
	return toNumber(document.getElementById(id).style.height);
}

/* Added to work with Prototype.js */

function ajaxGet(url, section){
	//$(section).innerHTML = '<img src="images/indicator_mozilla_blu.gif" />';
	new Ajax.Request(url,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "";
      $(section).innerHTML = response;
	  return false;
    },
    onFailure: function(){ $(section).innerHTML = '';
	return false; }
  });
}

function find_countries(make_id){
	start_moving('make_chosen',10,get_width('make_chosen'),get_width('make_chosen'),get_height('make_chosen'),0);
	start_moving('countries_listing',1,get_width('countries_listing'),460,get_height('countries_listing'),get_height('countries_listing'));
	start_moving('cities_listing',1,get_width('cities_listing'),0,get_height('cities_listing'),get_height('cities_listing'));
	$('cities_listing').innerHTML = '';
	$('make_listing').style.backgroundImage = 'url(images/map_loading.jpg)';
	$('make_listing').innerHTML = '';
	new Ajax.Request('ajax_model_list.php?make_id=' + make_id,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "";
	  start_moving('make_chosen',10,get_width('make_chosen'),get_width('make_chosen'),get_height('make_chosen'),200);
	  $('make_listing').style.backgroundImage = 'url(images/map_all.jpg)';
	  $('make_listing').innerHTML = '<img src="images/map_all.jpg" width="460" height="211" border=0 usemap="#Map" name="Image101" id="Image101">';
      $('countries_listing').innerHTML = response;
	  //alert(response);
	  return false;
    },
    onFailure: function(){ $('make_listing').style.backgroundImage = 'url(images/map_all.jpg)';
	//alert('bad');
	return false; }
  });
}
function find_cities(model_id){
	start_moving('countries_listing',1,get_width('countries_listing'),460,get_height('countries_listing'),get_height('countries_listing'));
	start_moving('cities_listing',1,get_width('cities_listing'),0,get_height('cities_listing'),get_height('cities_listing'));
	$('cities_listing').innerHTML = '';
	new Ajax.Request('ajax_city_list.php?model_id=' + model_id,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "";
	  start_moving('countries_listing',10,get_width('countries_listing'),230,get_height('countries_listing'),get_height('countries_listing'));
	  start_moving('cities_listing',10,get_width('cities_listing'),230,get_height('cities_listing'),get_height('cities_listing'));
      $('cities_listing').innerHTML = response;
	  //alert(response);
	  return false;
    },
    onFailure: function(){
	//alert('bad');
	return false; }
  });
}

/* Added to work with the drop-down suggestion box for the search bars */

//document.write('<div id="sb" style="z-index:99;position:absolute;width:300px;border:1px solid black;background-color:white;display:none;top:0px;left:0px;"></div>');
var currentObj = new Object();
var sugs = 0;
function startsuggest(givenObj){
	currentObj = givenObj;
	clearTimeout(sugs);
	sugs = setTimeout("suggest(false);",30);
}
function suggest(givenObj){
	if(!givenObj){
		givenObj = currentObj;
	} else {
		currentObj = givenObj;
	}
	if(givenObj.value!=""){
	getObj('sb').innerHTML = '';
	getObj('sb').style.top = Top(givenObj)+givenObj.offsetHeight;	
	getObj('sb').style.left = Left(givenObj)+0;
	ajaxGet('ajax_suggest.php?q=' + givenObj.value,'sb');
	eva = setTimeout('evaluate_fill()',300);
	}
}
function evaluate_fill(){
	getObj('sb').style.display = (getObj('sb').innerHTML != "")?'':'none';
}
function stopsuggesting(){
	getObj('sb').style.top = 0;
	getObj('sb').style.left = 0;
	getObj('sb').style.display = 'none';
	//getObj('sb').innerHTML = '';
}
function stopsuggesting_countdown(){
	stopsug = setTimeout('stopsuggesting()',500);
}












// ------ D R O P   L I S T   F U N C T I O N S  ----------- 



/* 
    S A M P L E : 
    UpdateDropList(document.myform.main_id, document.myform.sub_id,'<?=$sub_selected_id?>',SubNames,SubIDs);
*/

function ClearDropList(OptionList) {
    OptionList.length = 1;
}

function LoadDropList(Index,sub_select, selected_value,NameArray,ValueArray,MainIndex) {
	if (Index > 0){	
	        
	    // get data from array
	    if(MainIndex == null){
	        var CurrentName = NameArray[Index - 1].split('||');
		var CurrentValue = ValueArray[Index - 1].split('||');
	        //alert("NULL - " + MainIndex + CurrentName); 
	    }else{
	        var CurrentName = NameArray[Index - 1][MainIndex-1].split('||');
	        var CurrentValue = ValueArray[Index - 1][MainIndex-1].split('||');
	        //alert("NOT NULL - " + Index + ":" + MainIndex +"="+ CurrentName); 
	    }

	    // load the data into the "sub" drop down box
	    for (var i=0; i<CurrentName.length; i++){
	       sub_select.options[i+1] = new Option(CurrentName[i], CurrentValue[i], false, false);
	       
	       //split
	       	value_splited = selected_value.split("|");
                for(var x=0;x<value_splited.length;x++){
	           if(CurrentValue[i] == value_splited[x]) {  sub_select.options[i+1].selected = true;  break;}
	           //if(CurrentValue[i] == selected_value) {  sub_select.options[i+1].selected = true;  }
	        }
	    }
	}
	MainIndex = null;
}

function UpdateDropList(main_select, sub_select,selected_value,NameArray,ValueArray,MainIndex) {
	MainIndex = parseInt(MainIndex);
	if(isNaN(MainIndex)) MainIndex = null;

	//var CurrSub = sub_select.selectedIndex;
	//if(MainIndex==null) CurrSub = 0;
	//alert("First Alert - " + MainIndex + ' -> '+CurrSub); 
	
	
	ClearDropList(sub_select);
	LoadDropList(main_select.selectedIndex, sub_select,selected_value,NameArray,ValueArray,MainIndex);
}


//-----------  E N D   D R O P   L I S T   F U N C T I O N  ----------




