var irfDivision=""; // Global variable used to identify IRF Division; Used in function writeCurrentModelColumn for IRF Revamp CR
var duplicateErrorMessage="This vehicle is already selected."; //Alert message for duplicate vehicle selection added as part of IRF Revamp CR.
function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=250,left = 492,top = 374');");
}



//MAKE MODEL LIB
//---------------------------------------------------------------------------------------------------------
// constructor for make object

// ie, writeGmMakesMulti(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out GM makes
function writeGmMakesMulti(onlyActive,fieldname,fieldtype) {  
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1) && make.gm==1 ) {
      document.write('<OPTION VALUE="' + make.code + '"  >' + make.name + '</OPTION>\n');
    }
  }
}

// ie, writeGmMakesMultiSelected(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out GM makes
function writeGmMakesMultiSelected(onlyActive,fieldname,fieldtype) {  
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1) && make.gm==1 ) {
      document.write('<OPTION VALUE="' + make.code + '" SELECTED >' + make.name + '</OPTION>\n');
    }
  }
}

// ie, writeGmMakesMulti(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out GM makes
function writeGmMakesSelect(SMSselected) {  
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if (make.gm==1) {
      document.write('<OPTION VALUE="' + make.code + '"' + (make.code == SMSselected)?'SELECTED':'' +  '>' + make.name + '</OPTION>\n');
    }
  }
}


/*

This function writes out GM models.
*/
function writeGmModelsMulti() {
   // if we haven't parsed out all the models for each make, do so
   doModels();

   for (var i = 0; i != makes.length; i++) {
      for (var j = 0; j != makes[i].models.length; j++) {
         if (makes[i].gm == 1 && (makes[i].models[j].active == 1 && makes[i].models[j].brochureAvailable == 1)) {
            document.write('<OPTION VALUE="' + questionID + '%' + makes[i].code + '%' + makes[i].models[j].code + '">' + makes[i].name + ' ' + makes[i].models[j].name + '</OPTION>\n');
         }
      }
   }
}


/*
This function writes out GM models that were selected.
*/
function writeGmModelsMultiSelected() {
   // if we haven't parsed out all the models for each make, do so
   doModels();

   for (var i = 0; i != makes.length; i++) {
      for (var j = 0; j != makes[i].models.length; j++) {
         if (makes[i].gm == 1 && (makes[i].models[j].active == 1 && makes[i].models[j].brochureAvailable == 1)) {
            document.write('<OPTION VALUE="' + questionID + '%' + makes[i].code + '%' + makes[i].models[j].code + '" SELECTED >' + makes[i].name + ' ' + makes[i].models[j].name + '</OPTION>\n');
         }
      }
   }
}


/*
This function sorts an array of objects by the specified property.
*/
function arraySort(arrayName, length, property) {
   for (var i = 0; i < (length - 1); i++) {
      for (var j = i + 1; j < length; j++) {
         if (eval("arrayName[j]." + property) < eval("arrayName[i]." + property)) {
            var temp = arrayName[i];
            arrayName[i] = arrayName[j];
            arrayName[j] = temp;
         }
      }
   }
}


/*
This is the constructor for vehicle object.
*/
function vehicle(makeName, modelName, makeCode, modelCode) {
   this.name = makeName + " " + modelName;
   this.code = makeCode + modelCode;
}


/*
This function creates the checkboxes in the specified number of
columns for the GM Fleet type question for cross divisional makes.
*/
function writeCurrentFleetModelColumn(eligiblemodels,fieldName,numberOfColumns) {
   // if we haven't parsed out all the models for each make, do so
   doModels();

   var vehicles = eligiblemodels.split("~");
   var sortedVehicles = new Array(); // this array will be used to store vehicles, and sorted by make and model names
   var colNumber = 0;
   var vCount = 0; // vehicle count;

   for (i = 0; i < vehicles.length - 1; i++) {
      var codes = vehicles[i].split("%");
      var makeCode = codes[1];
      var modelCode = codes[2];

      // look up vehicle make and model names with corresponding make and model codes
      for (var j = 0; j != makes.length; j++) {
         for (var k = 0; k != makes[j].models.length; k++) {
            if (makes[j].code == makeCode && makes[j].models[k].code == modelCode) {
               // assign to sortedVehicles array
               sortedVehicles[vCount] = new vehicle(makes[j].name, makes[j].models[k].name, makeCode, modelCode);
               
               vCount++;
            }
         }
      }
   }

   // sort the array of objects by the "name" property
   arraySort(sortedVehicles, sortedVehicles.length, "name")

   // display vehicles
   for (i = 0; i < sortedVehicles.length; i++) {
      if (colNumber == 0){
         document.write("<tr>");
      }
      document.write("<td>");
      document.write("<input type='checkbox' name='"
         + fieldName + "' value='"
         + sortedVehicles[i].code + "'>" + "<span id='text'>"
         + sortedVehicles[i].name
         + "</span></input><br />");
      document.write("</td>");
      
      colNumber++;

      if (colNumber == numberOfColumns) {
         colNumber = 0;
         document.write("</tr>");
      }
   }
}


function Make(code, name, gm, active) {
  this.code = code;
  this.name = name;
  this.gm = gm;
  this.active = active;
  this.models = null;
}

// constructor for model object

function Model(code, name, active, brochureAvailable, years) {
  this.code = code;
  this.name = name;
  this.active = active;
  this.brochureAvailable = brochureAvailable;
  this.years = years;  // array of years of available brochures
}

// parse out all the makes into an array of make
// objects, makes[]

var rawMakesSplit = rawMakes.split('~');
var numMakes = rawMakesSplit.length;
var makes = new Array(numMakes);
var makeIndex = new Object();
for (var i = 0; i != numMakes; i++) {
  var fields = rawMakesSplit[i].split('%');
  makes[i] = new Make(fields[0], fields[1], fields[2], fields[3]);

  makeIndex[fields[0]] = makes[i];
}

var rawYearsSplit = rawYears.split('~');
var numYearArrays = rawYearsSplit.length;
var yearArrays = new Array(numYearArrays);
var yearArrayIndex = new Object();
for (var i = 0; i != numYearArrays; i++) {
  var fields = rawYearsSplit[i].split('%');
  yearArrays[i] = fields[2].split(',');

  // create a unique id for each array of years,
  var makeModelID = fields[0] + fields[1];
  yearArrayIndex[makeModelID] = yearArrays[i];
}


// function to parse out all models, called from updateModels(), and
// then only once, presumably to save on not having to do all this
// work if the user never selects anything

var modelsDone = 0;
// when doModels() runs, it only runs once, for after the

function doModels() {

  //if (modelsDone == 0) {
	
    var rawModelsSplit = rawModels.split('*');

    // the number of rawmodels is the number of makes...
    for (var i = 0; i != numMakes; i++) {
      // all the models for this make are separated by ~
      var theseModelsRaw = rawModelsSplit[i].split('~');
      var numThese = theseModelsRaw.length;  // number of models for this make
      var theseModels = new Array(numThese);  // build array of models

      // current array of models gets attached to the .models
      // property of the related make
      makes[i].models = theseModels;

      // create each model object in theseModels, aka makes[i].models
      for (var j = 0; j != numThese; j++) {
        var fields = theseModelsRaw[j].split('%');
		var makeModelID = makes[i].code + fields[0];
        theseModels[j] = new Model(fields[0], fields[1], fields[2], fields.length == 4 ? fields[3] : 0, yearArrayIndex[makeModelID]);
      }
    }
//    modelsDone = 1;
//  }
}

//This is for combo boxes
function updateModelsC(makeList, modelList, onlyActive, onlyBrochureAvailable, useJoint) {
  // if we haven't parsed out all the models for each make, do so
  doModels();
	if (makeList.options[makeList.selectedIndex].value=='' || makeList.selectedIndex==0){
  		modelList.options.length = 0;
  		modelList.options[0] = new Option('Model', '00000');
		return;
	}
  // the currently-selected make, such as "04" for Cadillac
  var makeCode = makeList.options[makeList.selectedIndex].value;

  // make the length of the corresponding model dropdown 0. ie, clear it
  modelList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Model"
  // and have the value 00000 to mean no make or model
  modelList.options[0] = new Option('Model', '00000');

  if (makeCode != '00') {
    // get the array of models associated with this make code,
    // which we conveniently extract from makeIndex[]

    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
      var model = models[i];
      if ((onlyActive  ==  0 || model.active == 1) && (onlyBrochureAvailable == 0 || model.brochureAvailable == 1)) {
        // modelList.options[modelList.length] is a fancy way of saying
	// "the last element of modelList"; that is, we are appending
	// each model to the pulldown pointed to by modelList
		if(modelList.name=="X00950GROUP00951" || modelList.name=="X00950GROUP00953"){ //Full Line removal from Household dropdowns for IRF Revamp
			if(model.code!="999"){ //Full Line removal from Household dropdowns for IRF Revamp
				modelList.options[modelList.length] = new Option(model.name, (useJoint == 1 || make.gm==1 ) ? makeCode + model.code : model.code);
			}
		}
		else
		{
				modelList.options[modelList.length] = new Option(model.name, (useJoint == 1 || make.gm==1 ) ? makeCode + model.code : model.code);
		}
      }
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (modelList.length != 0) {
    modelList.options[0].selected = true;
  }
}


//This is for combo boxes
function updateModelsAdmin(makeList, modelList, onlyActive, onlyBrochureAvailable, useJoint) {

  // if we haven't parsed out all the models for each make, do so
  doModels();

  // the currently-selected make, such as "04" for Cadillac
  var makeCode = makeList.options[makeList.selectedIndex].value;

  // make the length of the corresponding model dropdown 0. ie, clear it
  modelList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Model"
  // and have the value 00000 to mean no make or model
  modelList.options[0] = new Option('Model', '00000');

  if (makeCode != '00') {
    // get the array of models associated with this make code,
    // which we conveniently extract from makeIndex[]
    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
      var model = models[i];
      if ((onlyActive  ==  0 || model.active == 1) && (onlyBrochureAvailable == 0 || model.brochureAvailable == 1)) {
        // modelList.options[modelList.length] is a fancy way of saying
	// "the last element of modelList"; that is, we are appending
	// each model to the pulldown pointed to by modelList
        modelList.options[modelList.length] =
          new Option(model.name, model.code);
      }
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (modelList.length != 0) {
    modelList.options[0].selected = true;
  }
}

//This is for combo boxes
function updateModelsQ(makeCode, modelListName, onlyActive, onlyBrochureAvailable, useJoint) {

  // if we haven't parsed out all the models for each make, do so
  doModels();

 
  // make the length of the corresponding model dropdown 0. ie, clear it
  modelList=document.forms[0].elements[modelListName];
  modelList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Model"
  // and have the value 00000 to mean no make or model
  modelList.options[0] = new Option('Model', '00000');

  if (makeCode != '00') {
    // get the array of models associated with this make code,
    // which we conveniently extract from makeIndex[]
    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
      var model = models[i];
      if ((onlyActive  ==  0 || model.active == 1) && (onlyBrochureAvailable == 0 || model.brochureAvailable == 1)) {
        // modelList.options[modelList.length] is a fancy way of saying
	// "the last element of modelList"; that is, we are appending
	// each model to the pulldown pointed to by modelList
        modelList.options[modelList.length] =
          new Option(model.name, (useJoint == 1 || make.gm==1 ) ? makeCode +  model.code : model.code);
      }
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (modelList.length != 0) {
    modelList.options[0].selected = true;
  }
}



//This is for check boxes
function updateModelsB(makeList, modelList, onlyActive, onlyBrochureAvailable, useJoint) {

  // if we haven't parsed out all the models for each make, do so
  doModels();

  // the currently-selected make, such as "04" for Cadillac
  var makeCode = makeList.options[makeList.selectedIndex].value;

  // make the length of the corresponding model dropdown 0. ie, clear it
  modelList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Model"
  // and have the value 00000 to mean no make or model
  modelList.options[0] = new Option('Model', '00000');

  if (makeCode != '00') {
    // get the array of models associated with this make code,
    // which we conveniently extract from makeIndex[]
    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
      var model = models[i];
      if ((onlyActive  ==  0 || model.active == 1) && (onlyBrochureAvailable == 0 || model.brochureAvailable == 1)) {
        modelList.options[modelList.length] =
          new Option(model.name, useJoint == 1 ? makeCode + '/' + model.code : model.code);
      }
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (modelList.length != 0) {
    modelList.options[0].selected = true;
  }
}


function updateYears(modelList, yearList) {

  // if we haven't parsed out all the models for each make, do so
  doModels();

  // the currently-selected model, such as "03/0202" for Chevy Blazer.
  var modelCode = modelList.options[modelList.selectedIndex].value;

  // make the length of the corresponding year dropdown 0. ie, clear it
  yearList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Year"
  // and have the value 0000 to mean no year
  yearList.options[0] = new Option('Year', '0000');

  if (modelCode != '00000') {
    // get the array of years associated with this make/model code,
    // which we conveniently extract from yearArrayIndex[]
    var years = yearArrayIndex[modelCode];
    for (var i = 0; i != years.length; i++) {
      var year = years[i];
      // yearList.options[yearList.length] is a fancy way of saying
      // "the last element of yearList"; that is, we are appending
      // each model to the pulldown pointed to by yearList
      yearList.options[yearList.length] = new Option(year, year);
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (yearList.length != 0) {
    yearList.options[0].selected = true;
  }
}

// ie, writeMakes(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out every make there is
function writeMakes(onlyActive,fieldname,fieldtype) {
  document.write('<OPTION VALUE="">Make</OPTION>\n');
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1) && onlyActive!=2) {
      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
    }
	else if (onlyActive == 2 && make.gm==0 && make.active == 1) {//Added to filtering out GM Brands from displaying in Other manufacturers dropdown - added for IRF Revamp CR
      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
    }
		 
  }
}

// ie, writeGMMakes(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out GM makes
function writeGmMakes(onlyActive,includeList) {
var incList=includeList.split("~");
  document.write('<OPTION VALUE="">Make</OPTION>\n');
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1) && make.gm==1 ) {
    	if (includeList=='' || includeList=='null' || includeList==null){
		document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');    	
    	}else{
		for (var q=0;q<incList.length;q++){
			if (incList[q]==make.code && irfDivision!=make.code){
			      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
			}
		}
	}
    }
  }
}
//added to remove the GM vehcile from the other manufacture question.
function writeMakesNonGM(onlyActive,fieldname,fieldtype) {
  document.write('<OPTION VALUE="">Make</OPTION>\n');
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
	if(make.code!='05'){
	if (make.gm== 0)  {		
      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
    }}
  }
}

// Return the make name as string
function getMakeName(smscode) {
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if (make.code==smscode){
    	return make.name;
    }
}
return '';
}


// called once, at the location of each brochure models pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown

function writeNulls(count) {
  document.write('<OPTION VALUE="00000">Model</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="00000">______</OPTION>\n');
  }
}

// used by the "what other makes/models interest you?" pulldowns.
// consider modifying this for use in the year pulldown for brochures
function writeYears() {
  document.write('<OPTION VALUE="0000">Year</OPTION>');
//	var cYear=new Date().getYear();
  for (var i = 2007 ; i != 1969; i--) {
    document.write('<OPTION VALUE="' + i + '">' + i + '</OPTION>');
  }
}


// called once, at the location of each current models pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
// NOTE that here we have just 0000 for an empty model, whereas
// writeNulls has 00000
function writeCurrentModelNulls(count) {
  document.write('<OPTION VALUE="00000">Model</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="00000">______</OPTION>\n');
  }
}


// called once, at the location of each current models pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
// NOTE that here we have just 00000 for an empty model, whereas
// writeNulls has 00000
function writeCurrentModel(SMSMakeCode,fieldName) {

  // if we haven't parsed out all the models for each make, do so
  doModels();

  // the currently-selected make, such as "04" for Cadillac
  var makeCode = SMSMakeCode;

  if (makeCode != '00') {
    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
	var model = models[i];
	if (models[i].active==1){
		document.write("<input type=\"checkbox\" name=\""+fieldName+"\" value=\""+model.code+"\">"+"<span id=\"text\">"+model.name+"</span></input><br />");
	}

    }
  }

  }

function writeCurrentModelColumn(SMSMakeCode,fieldName,numberOfColumns) {
   // if we haven't parsed out all the models for each make, do so
      doModels();

   // the currently-selected make, such as "04" for Cadillac
  var makeCode = SMSMakeCode;
irfDivision=makeCode;
   if (makeCode != '00') {
      var models = makeIndex[makeCode].models;
      var colNumber=0;
      
	  
	  for (var i = 0; i != models.length; i++) {
         var model = models[i];
			if (model.active==1 && model.code=='999'){//IRF Revanmp Release2.9 full line vehicle in first line.
				document.write("<input type=\"checkbox\" name=\""+fieldName+"\" value=\""+SMSMakeCode+model.code+"\">"+"<span id=\"text\">"+model.name+"</span></input><br />");
			}

	  }

   	  for (var i = 0; i != models.length; i++) {
         var model = models[i];
         if (model.active==1 && model.code!='999'){//IRF Revanmp Release2.9 full line vehicle removal from existing model
            if (colNumber==0){
               document.write("<tr>");
            }
            document.write("<td nowrap>");
            document.write("<input type=\"checkbox\" name=\""+fieldName+"\" value=\""+SMSMakeCode+model.code+"\">"+"<span id=\"text\">"+model.name+"</span></input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />");
            document.write("</td>");	
            colNumber++
            if (colNumber==4){
               colNumber=0;
               document.write("</tr>");
            }
         }
      }

   }
}

function writeCurrentModelColumnBlue(SMSMakeCode,fieldName,numberOfColumns) {
	// if we haven't parsed out all the models for each make, do so
	doModels();

	var makeCode = SMSMakeCode;
irfDivision=makeCode;
   if (makeCode != '00') {
      var models = makeIndex[makeCode].models;
      var colNumber=0;
      
	  
	  for (var i = 0; i != models.length; i++) {
         var model = models[i];
			if (model.active==1 && model.code=='999'){//IRF Revanmp Release2.9 full line vehicle in first line.
				document.write("<input type=\"checkbox\" name=\""+fieldName+"\" value=\""+SMSMakeCode+model.code+"\">"+"<span id=\"text\">"+model.name+"</span></input><br />");
			}

	  }

   	  for (var i = 0; i != models.length; i++) {
         var model = models[i];
         if (model.active==1 && model.code!='999'){//IRF Revanmp Release2.9 full line vehicle removal from existing model
            if (colNumber==0){
               document.write("<tr>");
            }
            document.write("<td nowrap>");
            document.write("<input type=\"checkbox\" name=\""+fieldName+"\" value=\""+SMSMakeCode+model.code+"\">"+"<span id=\"text\">"+model.name+"</span></input>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />");
            document.write("</td>");	
            colNumber++
            if (colNumber==4){
               colNumber=0;
               document.write("</tr>");
            }
         }
      }

   }
}








// called once, at the location of each years pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
function writeYearNulls(count) {
  document.write('<OPTION VALUE="0000">Year</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="0000">____</OPTION>\n');
  }
}


// used to write options 1..10 and 15 for the question
// "how many more years will you own/drive this vehicle?"
// Not currently asked in current application
function writeMoreYears() {
  for (var i = 1; i != 11; i++) {
    document.write('<OPTION VALUE="' + i + '">' + i + '</OPTION>');
  }
  document.write('<OPTION VALUE="15">&gt;10</OPTION>');
}





//This is for combo boxes
function updateModelsCSpanish(makeList, modelList, onlyActive, onlyBrochureAvailable, useJoint) {

  // if we haven't parsed out all the models for each make, do so
  doModels();
	if (makeList.options[makeList.selectedIndex].value=='' || makeList.selectedIndex==0){
  		modelList.options.length = 0;
  		modelList.options[0] = new Option('Modelo', '00000');
		return;
	}
  // the currently-selected make, such as "04" for Cadillac
  var makeCode = makeList.options[makeList.selectedIndex].value;

  // make the length of the corresponding model dropdown 0. ie, clear it
  modelList.options.length = 0;

  // set the first element of the corresponding model dropdown to say "Model"
  // and have the value 00000 to mean no make or model
  modelList.options[0] = new Option('Modelo', '00000');

  if (makeCode != '00') {
    // get the array of models associated with this make code,
    // which we conveniently extract from makeIndex[]
    var models = makeIndex[makeCode].models;
    for (var i = 0; i != models.length; i++) {
      var model = models[i];
      if ((onlyActive  ==  0 || model.active == 1) && (onlyBrochureAvailable == 0 || model.brochureAvailable == 1)) {
        // modelList.options[modelList.length] is a fancy way of saying
	// "the last element of modelList"; that is, we are appending
	// each model to the pulldown pointed to by modelList
        modelList.options[modelList.length] =
          new Option(model.name, (useJoint == 1 || make.gm==1 ) ? makeCode + model.code : model.code);
      }
    }
  }
  // ensure that the 0th element of the dropdown list is selected,
  if (modelList.length != 0) {
    modelList.options[0].selected = true;
  }
}





// ie, writeMakes(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out every make there is
function writeMakesSpanish(onlyActive,fieldname,fieldtype) {
  document.write('<OPTION VALUE="">Marca</OPTION>\n');
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1)) {
      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
    }
  }
}

// ie, writeGMMakes(0)
// used by the select dropdowns for what other models users are interested in;
// Writes out GM makes
function writeGmMakesSpanish(onlyActive,includeList) {
var incList=includeList.split("~");
  document.write('<OPTION VALUE="">Marca</OPTION>\n');
  for (var i = 0; i != makes.length; i++) {
    var make = makes[i];
    if ((onlyActive == 0 || make.active == 1) && make.gm==1 ) {
    	if (includeList=='' || includeList=='null' || includeList==null){
		document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');    	
    	}else{
		for (var q=0;q<incList.length;q++){
			if (incList[q]==make.code){
			      document.write('<OPTION VALUE="' + make.code + '">' + make.name + '</OPTION>\n');
			}
		}
	}
    }
  }
}



// called once, at the location of each brochure models pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
function writeNullsSpanish(count) {
  document.write('<OPTION VALUE="00000">Modelo</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="00000">____________</OPTION>\n');
  }
}

// called once, at the location of each current models pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
// NOTE that here we have just 0000 for an empty model, whereas
// writeNulls has 00000
function writeCurrentModelNullsSpanish(count) {
  document.write('<OPTION VALUE="00000">Modelo</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="00000">____________</OPTION>\n');
  }
}




// called once, at the location of each years pulldown, to create
// the requisite number of empty options, presumably to keep the pulldown
function writeYearNullsSpanish(count) {
  document.write('<OPTION VALUE="0000">A&ntilde;o</OPTION>\n');
  for (var i = 0; i != count; i++) {
    document.write('<OPTION VALUE="0000">____</OPTION>\n');
  }
}

// used by the "what other makes/models interest you?" pulldowns.
// consider modifying this for use in the year pulldown for brochures
function writeYearsSpanish(varT) {
  document.write('<OPTION VALUE="0000">A&ntilde;o</OPTION>');
	//var cYear=new Date().getYear();
  for (var i = 2007 ; i != 1969; i--) {
    document.write('<OPTION VALUE="' + i + '">' + i + '</OPTION>');
  }
}


function  checkModels(modelDropdown){ // Avoid duplicate selection for Divisonal GM model dropdowns
	if(modelDropdown.selectedIndex==0)
		return;
	var currentValInDropdown=modelDropdown.value;
	var currentSelIndex=modelDropdown.selectedIndex;
	switch(modelDropdown.name)
		{
			case "XMMGM001model0":
				if(currentValInDropdown==document.forms[0].XMMGM001model1.value || currentValInDropdown==document.forms[0].XMMGM001model2.value)
				{
					alert(duplicateErrorMessage);
					modelDropdown.options[0].selected=true;
					//modelDropdown.options[currentSelIndex].selected=true;
					modelDropdown.focus();
				}
				break;
			case "XMMGM001model1":
				if(currentValInDropdown==document.forms[0].XMMGM001model0.value || currentValInDropdown==document.forms[0].XMMGM001model2.value)
				{
					alert(duplicateErrorMessage);
					modelDropdown.options[0].selected=true;
					//modelDropdown.options[currentSelIndex].selected=true;
					modelDropdown.focus();
				}
				break;
			case "XMMGM001model2":
				if(currentValInDropdown==document.forms[0].XMMGM001model0.value || currentValInDropdown==document.forms[0].XMMGM001model1.value)
				{
					alert(duplicateErrorMessage);
					modelDropdown.options[0].selected=true;
					//modelDropdown.options[currentSelIndex].selected=true;
					modelDropdown.focus();
				}
				break;
		}
}