//Global Variables //
     var num=0;
     var interval = null;
     var mkIndex=0;
//End//
     function doLists(fMake,fModel)  {
     fModel = fModel.toUpperCase();
     fMake = fMake.toUpperCase();
     num++;
      if (num < 100)  {
       if (typeof get_makes == 'function' && typeof get_range =='function' && typeof listmodel=='object' && typeof makes=='object')  {
        get_makes(fMake);
        if (document.adform && document.adform.fMake && typeof document.adform.fMake.selectedIndex == 'number')  {
         mkIndex = document.adform.fMake.selectedIndex;
        }
        get_range(listmodel[mkIndex], fModel);
        clearInterval(interval);
       }
      }
      else {
       clearInterval(interval);
      }
     }
	 
function get_makes(req_make) {
 var dropDown;
 selectedIndex = 0;
 if (document.adform && document.adform.fMake)  {
  dropDown = document.adform.fMake;
 }
 else if(document.search && document.search.fMake)  {
  dropDown=document.search.fMake;
 }
 else if (document.forms[0] && document.forms[0].fMake)  {
  dropDown = document.forms[0].fMake;
 }
 if (dropDown)  {
   dropDown.length = 0;
   for(index=0; index<makes.length; index++) {
    dropDown[index] = new Option(makes[index],makes[index]/*,make_v[index]*/);
    if (makes[index]=="Make" || makes[index]=="MAKE")  {
     dropDown[index] = new Option(makes[index],"");
      }
    if (makes[index]=="ANY MAKE")  {
     dropDown[index] = new Option(makes[index],"ANY");
      }

if(makes[index].toUpperCase() == req_make){
     selectedIndex = 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.adform && document.adform.fModel)  {
  dropDown = document.adform.fModel;
 }
 else if(document.search && document.search.fModel)  {
  dropDown=document.search.fModel;
 }
 else if (document.forms[0] && document.forms[0].fModel)  {
  dropDown = document.forms[0].fModel;
 }
 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.adform && document.adform.fMake)  {
  dropDown = document.adform.fMake;
 }
 else if(document.search && document.search.fMake)  {
  dropDown=document.search.fMake;
 }
 else if (document.forms[0] && document.forms[0].fMake)  {
  dropDown = document.forms[0].fMake;
 }
 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.adform.postcode.value= users_postcode.replace('+', ' ');
    }
 }
*/ 
  
/*<!--Ensures only one search parameter is sent when the form is submitted - toggles between county/region - If one option is selected the other is de-selected. This script is used when the county and region options are given to the user as a result of the postcode not being found-->*/
  var arr_county = new Array("jfCounty", "fCounty");
  var arr_region = new Array("jfRegion", "fRegion");
  var arr_meta_loc = new Array(arr_county, arr_region);

  function toggle_loc_search() {
    for (var i = 0; i < arr_meta_loc.length ; i++)
      for (var j = 1; j < arr_meta_loc[i].length; j++)
        document.getElementById(arr_meta_loc[i][j]).disabled = !document.getElementById(arr_meta_loc[i][0]).checked;
  }

  function toggle_loc_search_onfocus(id) {
    document.getElementById(id).checked = true;
    toggle_loc_search();
  }
   
/*<!--popup window functions-->*/	
function showDetailPop(url,windowname){
	windowname=window.open(url,windowname,"toolbar=no,location=no,directories=no,margin=0,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600"); 
	windowname.focus();
}

/*
function showDetails(url) {
popWin =window.open("http://" + url,"","width=500,height=400,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,left=0,top=0,screenX=0,screenY=0");
}
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();
 }*/