// dem 03/21/08


//for Locator Vehicle
function doquery_make(){
  var theSYElement = document.inputform.VehicleStartYear;
  var theSYIndex = theSYElement.selectedIndex;
  var theSYValue = theSYElement.options[theSYIndex].value;

  var theEYElement = document.inputform.VehicleEndYear;
  var theEYIndex = theEYElement.selectedIndex;
  var theEYValue = theEYElement.options[theEYIndex].value;

  removeAll(document.inputform.VehicleMake);
  removeAll(document.inputform.VehicleModel);
  removeAll(document.inputform.VehicleStyle);
  addToSelect(document.inputform.VehicleMake, "", "");
  addToSelect(document.inputform.VehicleModel, "", "");
  addToSelect(document.inputform.VehicleStyle, "", "");
  addToSelect(document.inputform.VehicleModel, "First select Make", "");
  addToSelect(document.inputform.VehicleStyle, "First select Make", "");

  if (theSYValue == "" && theEYValue == ""){
    addToSelect(document.inputform.VehicleMake, "First select Year(s)", "");
  }
	else{
		//window.open("/temps/delaware/query/doquery_make.cfm?VehicleStartYear=' + theSYValue + '&VehicleEndYear=' + theEYValue", "blank", "width=10,height=10,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,left=1500,top=1500");

		top.hidden.document.location = "/query/doquery_make.cfm?VehicleStartYear=" + theSYValue + "&VehicleEndYear=" + theEYValue;
  }
}



function doquery_model(){
  var theSYElement = document.inputform.VehicleStartYear;
  var theSYIndex = theSYElement.selectedIndex;
  var theSYValue = theSYElement.options[theSYIndex].value;

  var theEYElement = document.inputform.VehicleEndYear;
  var theEYIndex = theEYElement.selectedIndex;
  var theEYValue = theEYElement.options[theEYIndex].value;

  var theElement = document.inputform.VehicleMake;
  var theIndex = theElement.selectedIndex;
  var theValue = theElement.options[theIndex].value;

  removeAll(document.inputform.VehicleModel);
  removeAll(document.inputform.VehicleStyle);
  addToSelect(document.inputform.VehicleModel, "", "");
  addToSelect(document.inputform.VehicleStyle, "", "");
  addToSelect(document.inputform.VehicleStyle, "First select Model", "");
	
  if (theValue == ""){
    addToSelect(document.inputform.VehicleModel, "First select Make", "");
  }
	else{
		top.hidden.document.location = "/query/doquery_model.cfm?VehicleMake=" + theValue + "&VehicleStartYear=" + theSYValue + "&VehicleEndYear=" + theEYValue;
  }
}

function doquery_style(){
  var theSYElement = document.inputform.VehicleStartYear;
  var theSYIndex = theSYElement.selectedIndex;
  var theSYValue = theSYElement.options[theSYIndex].value;

  var theEYElement = document.inputform.VehicleEndYear;
  var theEYIndex = theEYElement.selectedIndex;
  var theEYValue = theEYElement.options[theEYIndex].value;

  var theElement = document.inputform.VehicleModel;
  var theIndex = theElement.selectedIndex;
  var theValue = theElement.options[theIndex].value;

  removeAll(document.inputform.VehicleStyle);
  addToSelect(document.inputform.VehicleStyle, "", "");

  if (theValue == ""){
    addToSelect(document.inputform.VehicleStyle, "First select Model", "");
  }
	else{
		top.hidden.document.location = "/query/doquery_style.cfm?VehicleModel=" + theValue + "&VehicleStartYear=" + theSYValue + "&VehicleEndYear=" + theEYValue;
  }
}



//for Locator Trade vehicle
function doquery_trademake(){
  var theElement = document.inputform.TradeYear;
  var theIndex = theElement.selectedIndex;
  var theValue = theElement.options[theIndex].value;

  removeAll(document.inputform.TradeMake);
  removeAll(document.inputform.TradeModel);
  removeAll(document.inputform.TradeStyle);
  addToSelect(document.inputform.TradeMake, "", "");
  addToSelect(document.inputform.TradeModel, "", "");
  addToSelect(document.inputform.TradeStyle, "", "");
  addToSelect(document.inputform.TradeModel, "First select Make", "");
  addToSelect(document.inputform.TradeStyle, "First select Make", "");

  if (theValue == ""){
    addToSelect(document.inputform.TradeMake, "First select Year", "");
  }
	else{
		parent.hidden.document.location = "/query/doquery_trademake.cfm?VehicleYear=" + theValue;
  }
}

function doquery_trademodel(){
  var theYElement = document.inputform.TradeYear;
  var theYIndex = theYElement.selectedIndex;
  var theYValue = theYElement.options[theYIndex].value;

  var theElement = document.inputform.TradeMake;
  var theIndex = theElement.selectedIndex;
  var theValue = theElement.options[theIndex].value;

  removeAll(document.inputform.TradeModel);
  removeAll(document.inputform.TradeStyle);
  addToSelect(document.inputform.TradeModel, "", "");
  addToSelect(document.inputform.TradeStyle, "", "");
  addToSelect(document.inputform.TradeStyle, "First select Model", "");

  if (theValue == ""){
    addToSelect(document.inputform.TradeModel, "First select Make", "");
  }
	else{
		parent.hidden.document.location = "/query/doquery_trademodel.cfm?VehicleMake=" + theValue + "&VehicleYear=" + theYValue;

  }
}

function doquery_tradestyle(){
  var theYElement = document.inputform.TradeYear;
  var theYIndex = theYElement.selectedIndex;
  var theYValue = theYElement.options[theYIndex].value;

  var theElement = document.inputform.TradeModel;
  var theIndex = theElement.selectedIndex;
  var theValue = theElement.options[theIndex].value;

  removeAll(document.inputform.TradeStyle);
  addToSelect(document.inputform.TradeStyle, "", "");

  if (theValue == ""){
    addToSelect(document.inputform.TradeStyle, "First select Model", "");
  }
	else{
		parent.hidden.document.location = "/query/doquery_tradestyle.cfm?VehicleModel=" + theValue + "&VehicleYear=" + theYValue;
  }
}



// this will remove all the contents of the Select object passed in
function removeAll(formelement){
  var selectLength = formelement.length;
  for (var i = 0; selectLength> i; i++) {
    removelast(formelement);
  }	
}

// will remove the LAST entry in a Select box
function removelast(formelement){
  var thelength = formelement.length;

  formelement.options[thelength - 1].value = "";
  formelement.options[thelength - 1].text = "";
  formelement.length = thelength - 1;	
}

// will add a text/value pair to a Select box if that value
// isn't already in the list
function addToSelect (destSelect, thetext, thevalue){

  var d = new Option(thetext);
  d.value = thevalue;
  d.text = thetext;
	
  destSelect.length ++;
  thelength = destSelect.length;
	
  destSelect.options[thelength - 1] = d;
  return ("1");
}


