fC = new Array()
thisFranchise = null
thisYear = null
thisModelFamily = null
yIndex = 0
mIndex = 0

function Franchise (p_code, p_desc, p_seq) {
  this.f_code = p_code
  this.f_desc = p_desc
  this.f_seq = p_seq
  this.f_default = false
  this.f_mY = new Array()
}

function mY (p_code, p_desc, p_parent, p_seq) {
  this.y_code = p_code
  this.y_desc = p_desc
  this.y_seq = p_seq
  this.y_parent = p_parent
  this.y_mF = new Array()  
}

function mF (p_code, p_desc, p_parent, p_seq, p_pdf, p_chart) {
  this.m_code = p_code
  this.m_desc = p_desc
  this.m_seq = p_seq
  this.m_parent = p_parent
  this.m_pdf = p_pdf
  this.m_chart = p_chart
}

function fillFranchiseList(franchiseCode) {

 	i = 0
	thisFranchise = null
  	for (fIndex in fC)
  	{
		if (franchiseCode == fC[fIndex].f_code) {
			thisFranchise = fC[fIndex]
			break
		}

    	i++
  	}
		
	fillYearList(thisFranchise);
}

function changeYear() {
  	thisYear = thisFranchise.f_mY[document.vehiclecombo.YEAR.selectedIndex]
	fillModelFamilyList(thisYear)	
}

function changeFamily() {

var vehname, chartname, myear;
thisYear = thisFranchise.f_mY[document.vehiclecombo.YEAR.selectedIndex];
myear = thisYear.y_code;

thisModelFamily = thisYear.y_mF[document.vehiclecombo.FAMILY.selectedIndex];
	
chartname = thisModelFamily.m_chart;
vehname = thisModelFamily.m_code;

	if (chartname == "NO_CHART") {
		//now check for vehicle. if vehicle has no value, this means current vehicle selected in drop down has no specific chart
		if (vehicle == "") {
		//do nothing
		} else {
		//means we are switching to a generic-chart vehicle from a specific-chart vehicle
		document.location="/crossbrand/warranty/?brand=" + brand + "&modelyear=" + myear + "&nameplate=" + vehname;
		} 
  	} else {
	document.location="/crossbrand/warranty/?brand=" + brand + "&vehicle=" + chartname + "&modelyear=" + myear + "&nameplate=" + vehname;
	}

}

function fillYearList(p_franchise) {
  k = 0
  yIndex = 0

  document.vehiclecombo.YEAR.options.length = 1
  document.vehiclecombo.YEAR.options.selectedIndex = 0
  thisYear = null

  for (yInd in p_franchise.f_mY)  
  {  

    theYear = p_franchise.f_mY[yInd]
    yCode = theYear.y_code

    if (yCode == modelyear) {
      yIndex = k
    }
    document.vehiclecombo.YEAR.options[k] = new Option(theYear.y_desc, theYear.y_code)
    k++
  }

  document.vehiclecombo.YEAR.selectedIndex = yIndex 
  thisYear = p_franchise.f_mY[yIndex ]
  
  //reset yIndex and modelyear
  yIndex = 0
  modelyear = ""  

  fillModelFamilyList(thisYear);

  
}

function fillModelFamilyList(p_year) {
  k = 0
  mIndex = 0

  document.vehiclecombo.FAMILY.options.length = 1
  document.vehiclecombo.FAMILY.options.selectedIndex = 0
  thisModelFamily = null

  for (mInd in p_year.y_mF)  
  {  

    theModelFamily = p_year.y_mF[mInd]
    mCode = theModelFamily.m_code
    if (mCode == nameplate) {
      mIndex = k
    }
    document.vehiclecombo.FAMILY.options[k] = new Option(theModelFamily.m_desc, theModelFamily.m_code)
	
    k++
  }

  document.vehiclecombo.FAMILY.selectedIndex = mIndex
  thisModelFamily = p_year.y_mF[mIndex]
  
  //reset mIndex and nameplate
  mIndex = 0
  nameplate = ""    

}


function openIt( argApp, launchUrl ) {
var winWidth = 790, winHeight = 452;

if( window.screen)
winHeight = ( window.screen.availHeight - 130 );
var options = "resizable,scrollbars,toolbar,"
options += "width=" + winWidth + ",height=" + winHeight;
if( window.screen ) {
var xPos = ( screen.availWidth - winWidth ) / 2;
var yPos = ( ( screen.availHeight - winHeight ) / 2 ) - 40;
options += ",left=" + xPos + ",screenX=" + xPos;
options += ",top=" + yPos + ",screenY=" + yPos;
}

warrantyWindow = window.open( launchUrl, "warrantypdf", options );
return warrantyWindow;

}

function downloadBooklet(arg_formObj) {
  var pdfname;
  thisYear = thisFranchise.f_mY[document.vehiclecombo.YEAR.selectedIndex];
  thisModelFamily = thisYear.y_mF[document.vehiclecombo.FAMILY.selectedIndex];
  pdfname = thisModelFamily.m_pdf;
  
  url = "pdf/" + pdfname + ".pdf";
  openIt('warrantypdf', url);

}

