//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 get_makes(req_make) {
 var dropDown;
 selectedIndex = 0;
 if (document.qSearch && document.qSearch.make)  {
  dropDown = document.qSearch.make;
 }
 else if(document.search && document.search.make)  {
  dropDown=document.search.make;
 }
 else if (document.forms[0] && document.forms[0].make)  {
  dropDown = document.forms[0].make;
 }
 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]=="")  {
     dropDown[index] = new Option(make_d[index],"");
      }
    if (make_d[index]=="ANY MAKE")  {
     dropDown[index] = new Option(make_d[index],"");
      }

    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.qSearch && document.qSearch.model)  {
  dropDown = document.qSearch.model;
 }
 else if(document.search && document.search.model)  {
  dropDown=document.search.model;
 }
 else if (document.forms[0] && document.forms[0].model)  {
  dropDown = document.forms[0].model;
 }
 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.qSearch && document.qSearch.make)  {
  dropDown = document.qSearch.make;
 }
 else if(document.search && document.search.make)  {
  dropDown=document.search.make;
 }
 else if (document.forms[0] && document.forms[0].make)  {
  dropDown = document.forms[0].make;
 }
 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 check(){
    if (document.qSearch.postcode.value == '') {
			alert("You must enter a Postcode");
			return false;
    }else if (document.qSearch.make.value == '') {
			alert("You must chose a Make");
			return false;
		}else document.qSearch.submit();
}

function checkgarage(){
    if (document.qSearch.postcode.value == '') {
			alert("You must enter a Postcode");
			return false;
		}else document.qSearch.submit();
}

function checknewpage(){
  document.qSearch.submit();
}

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();
}
function make(m){
	document.makesearch.make.value=m;
	document.makesearch.submit();
}
function model(m){
	document.modelsearch.model.value=m;
	document.modelsearch.submit();
}
function page(p){
	document.oSearch.page.value=p;
	document.oSearch.submit();
}
