//Global Variables //

					var num=0;
					var interval = null;
					var mkIndex=0;
//End//
					function doLists(make,model)  {
					model = model.toUpperCase();
					make = make.toUpperCase();
					num++;
						if (num < 100)  {
							if (typeof get_makes == 'function' && typeof get_range =='function' && typeof _model=='object' && typeof make_v=='object' && typeof make_d=='object')  {
								get_makes(make);
								if (document.qSearch && document.qSearch.make && typeof document.qSearch.make.selectedIndex == 'number')  {
									mkIndex = document.qSearch.make.selectedIndex;
								}
								get_range(_model[mkIndex], model);
								clearInterval(interval);
							}
						}
						else {
							clearInterval(interval);
						}
					}

function getcookieField(FLDval)
{
	var ourcookie = "user";
	var allcookies = document.cookie;
	var FIELD = null;

	if (allcookies != "")
	{

		var start = allcookies.indexOf(ourcookie + "=");
		if (start != -1)
		{
			start += ourcookie.length + 1;
			var end = allcookies.indexOf(";",start);
			if (end == -1) end = allcookies.length;
			var usercookie = allcookies.substring(start,end);
			var celements = usercookie.split('&')
			for (cnt=0;cnt<celements.length;cnt++)
			{
				celements[cnt] = celements[cnt].split('=');
				if (celements [cnt][0] == FLDval)
				FIELD = unescape(celements[cnt][1]);
			}
		}
	}
	return FIELD;
}

function get_makes(req_make)	{
	var dropDown;
	selectedIndex = 0;
	
	if(document.getElementsByName("make")){
		dropDown  = document.getElementsByName("make")[0];
	}

	if (dropDown)  {
			dropDown.length = 0;

			for(index=0; index<make_d.length; index++)	{

				dropDown[index] = new Option(make_d[index],make_v[index]);

				if (make_d[index]=="Make" || make_d[index]=="MAKE")  {
					dropDown[index] = new Option(make_d[index],"");
				  }

				if (make_d[index]=="ANY MAKE")  {
					dropDown[index] = new Option(make_d[index],"ANY");
				  }


				if(make_v[index].toUpperCase() == req_make){
					selectedIndex = index;

				}
			  }
			dropDown.options[selectedIndex].selected = true;
		}
		select_make(req_make);
}

function get_range(ranges,req_model)	{

	selectedIndex = 0;
	var dropDown;
	
	if(document.getElementsByName("model")){
		dropDown = document.getElementsByName("model")[0];
	}

	if (dropDown)  {

		dropDown.length = 0;

		for(index=0; index<ranges.length; index++)	{

			dropDown[index] = new Option(ranges[index],ranges[index]);

			if (ranges[index]=="Model" || ranges[index]=="MODEL")  {
				dropDown[index] = new Option(ranges[index],"");
			  }

			  if (ranges[index]=="ANY MODEL")  {
				dropDown[index] = new Option(ranges[index],"ANY");
			  }

			if(ranges[index].toUpperCase() == req_model){
				selectedIndex = index;
			}
			else if (ranges[index].toUpperCase() == "ANY MODEL" && req_model == "ANY")  {
				selectedIndex = index;
			}
		}
		dropDown.options[selectedIndex].selected = true;
	}
}

function select_make(req_make)  {
	var dropDown;

	if (req_make == null)  {
		req_make="";
	}
	
	if(document.getElementsByName("make")){
		dropDown = document.getElementsByName("make")[0];
	}

	if (dropDown)  {
		for (x=0; x<dropDown.length; x++)  {
			mk=dropDown.options[x].value;
			if ( mk.toUpperCase()==req_make)  {
				if (dropDown.options[x].selected==false)   {
					dropDown.options[x].selected=true;
				}
			}
		}
	}
}


function postCheck(){
				var users_postcode = getcookieField("PC");
				if (users_postcode && users_postcode != '') {
				document.qSearch.postcode.value= users_postcode.replace('+', ' ');
				}
	}
	
		
function aV(){	
	var make = document.qSearch.make.value;
	var model = document.qSearch.model.value;
	var min_pr = document.qSearch.min_pr.value;
	var max_pr = document.qSearch.max_pr.value;
	var postcode = document.qSearch.postcode.value;
	if (document.qSearch.nU[0].checked)
	{
	parent.location="http://atsearch.autotrader.co.uk/WWW/cars_search.asp?nU=0&make=" + make + "&model=" + model + "&min_pr=" + min_pr + "&max_pr=" + max_pr + "&postcode=" + postcode + "&miles=40&max_records=50&modelexact=1";	
        }
	
	if (document.qSearch.nU[1].checked)
	{
	    parent.location="http://ncs.autotrader.co.uk/ncs/NewCarSearchController?nU=1&make=" + make + "&model=" + model + "&min_pr=" + min_pr + "&max_pr=" + max_pr + "&postcode=" + postcode + "&distance=40&max_records=50&modelexact=1";	
        }
        }
        

function openWindow() 
	{
	wiwwindow=window.open("","wiw","toolbar=no,location=no,directories=no,margin=0,status=no,menubar=no,scrollbars=yes,resizable=no,width=630,height=470");
	wiwwindow.focus();
	}

  
