<!-- Hide code from non Javascript Browsers
var inputVin = "";

/** 
 * Main function, called by HTML.
 */
function decodeVIN() 
{
  //set and clear the variables
  divId = "";
  vehId = "";
  bodyId = "";
  engineId = "";
  plantId = "";
  yearId = "";
  seqId = "";

  division = "Undefined";
  lineSeries = "Undefined";
  bodyStyle = "Undefined";
  engineType = "Undefined";
  plant = "Undefined";
  year = "Undefined";
  sequence = "Undefined";
  message = "";
  scriptVersion = "1.0";

  //get vin value from screen
  inputVin = document.GMCVINDecoder.vin.value;
  
  //check vin to make sure it looks like a vin
  if (inputVin == "") 
  {
      alert("Please enter your VIN Code");
      return false;
  }
  if (inputVin.length > 14 || inputVin.length < 13) 
  {
      alert("Your VIN is not the correct length\nThe value should be either 13 or 14 characters long.");
      return false;
  }
  //uppercase vin to be consistant
  Vin = inputVin.toUpperCase();

  //1N19G9J100001
  //chop out the relevant bits
  if(Vin.length == 13)
  {
    divId = Vin.charAt(0);
    vehId = Vin.charAt(1);   
    bodyId = Vin.substr(2,2);
    engineId = Vin.charAt(4);
    yearId = Vin.charAt(5);
    plantId = Vin.charAt(6);
    seqId= Vin.substr(7,6);
  }
  
  if(Vin.length == 14)
  {
    divId = Vin.charAt(0);
    vehId = Vin.charAt(1);   
    bodyId = Vin.substring(2,4);
    engineId = Vin.charAt(5);
    yearId = Vin.charAt(6);
    plantId = Vin.charAt(7);
    seqId = Vin.substr(8,6);
  }

  //get the year
  year = getYear(yearId);

  //check that the year is in range
  if (year == "Undefined")
  {
    alert("Your VIN is outside the date range for the this decoder.");
    return false;
  }
  
  // get division
  division = getDivision(divId);

  // Engine Type
  engineType = getEngineType(engineId);

  //Vehicle series
  lineSeries = getLineSeries(vehId);

  //Body style
  bodyStyle = getBodyStyle(bodyId);

  //Production line convert to value
  plant = getPlant(plantId);

  //Sequence absolute convert
  sequence = getSequence(seqId);

  mailto = "mailto:loki@astradyne.co.uk?subject=Chevrolet\%20VIN\%20Decoder\%20Error";

  //Set out answer window
  message = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
  message += "<html>\n<head>\n";
  message += "<title>VIN Decoded</title>\n";
  message += "<link type=\"text/css\" rel=\"stylesheet\" href=\"http://www.astradyne.co.uk/loki/camaro/scripts/stylesheet.css\" title=\"BBB\">\n";
  message += "</head>\n<\head>\n<body>\n";
  message += "<h2>VIN Decoded</h2>\n";
  message += "<p>The VIN code <b>" + Vin + "</b> breaks down as:</p>\n";
  message += ("<p><b>Divison</b>: " + division + "<br/>\n");
  message += ("<b>Car line & Series</b>: " + lineSeries + "<br/>\n");
  message += ("<b>Basic Body Style</b>: " + bodyStyle + "<br/>\n");
  message += ("<b>Engine Type</b>: " + engineType + "<br/>\n");
  message += ("<b>Model Year</b>: " + year + "<br/>\n");
  message += ("<b>Assembly Plant</b>: " + plant + "<br/>\n");
  message += ("<b>Sequential Number</b>: " + sequence + "<p/>\n");
  message += ("This should work for most Chevys between '72 and '80, however<br/>\n");
  message += ("I cannot guarantee that it is 100\% correct. If your VIN works out different<br/>\n");
  message += ("to what your car actually is, hit the \'Error\' button<p/>\n"); 
  message += ("<form name=\"mailError\" action=\""+mailto+"\" method=\"post\" enctype=\"text/plain\">\n");
  message += ("<input type=\"hidden\" name=\"inputVin\" value=\""+inputVin+"\">\n");
  message += ("<input type=\"hidden\" name=\"division\" value=\""+division+"\">\n");
  message += ("<input type=\"hidden\" name=\"lineSeries\" value=\""+lineSeries+"\">\n");
  message += ("<input type=\"hidden\" name=\"bodyStyle\" value=\""+bodyStyle+"\">\n");
  message += ("<input type=\"hidden\" name=\"engineType\" value=\""+engineType+"\">\n");
  message += ("<input type=\"hidden\" name=\"year\" value=\""+year+"\">\n");
  message += ("<input type=\"hidden\" name=\"plant\" value=\""+plant+"\">\n");
  message += ("<input type=\"hidden\" name=\"sequence\" value=\""+sequence+"\">\n");
  message += ("<input type=\"hidden\" name=\"scriptVersion\" value=\""+scriptVersion+"\">\n");
  message += ("<input type=\"submit\" name=\"error\" value=\"Error\">&nbsp;");
  message += ("<input type=\"button\" value=\"Close\" name=\"close\" onclick=\"window.close()\"></form><p>\n");
  message += ("</body>\n</html>");

  //prepare a new window for the search result
  resultWindow = window.open("","_blank","status=yes, width=500, height=400", true);
  resultWindow.document.write(message);
}

/**
 * Get the year from the id
 * @param yearId
 * @return year
 */
function getYear(yearId)
{
  year = "Undefined";
  if (yearId == "2") year = "1972";
  if (yearId == "3") year = "1973";
  if (yearId == "4") year = "1974";
  if (yearId == "5") year = "1975";
  if (yearId == "6") year = "1976";
  if (yearId == "7") year = "1977";
  if (yearId == "8") year = "1978";
  if (yearId == "9") year = "1979";
  if (yearId == "0") year = "1980";
  return year;
}

/**
 * Get the plant name.
 * Needs work, not sorted by division
 * @param plantId single character
 * @return string plant name
 */
function getPlant(plantId)
{
  plant = "Undefined";
  //Production line convert to value
  if (plantId == "A") plant = "GMAD - Lakewood";
  if (plantId == "B") plant = "GMAD - Baltimore";
  if (plantId == "C") plant = "GMAD - Southgate";
  if (plantId == "D") plant = "GMAD - Doraville";
  if (plantId == "E") plant = "Linden";
  if (plantId == "F") plant = "Chevrolet - Flint";
  if (plantId == "G") plant = "Framingham";
  if (plantId == "H") plant = "Buick - Flint";
  if (plantId == "J") plant = "GMAD - Janesville";
  if (plantId == "K") plant = "GMAD - Leeds or Kosai";
  if (plantId == "L") plant = "GMAD - Van Nuys";
  if (plantId == "M") plant = "Lansing (Buick)";
  if (plantId == "N") plant = "Chevrolet - Norwood";
  if (plantId == "P") plant = "Pontiac (Pontiac)";
  if (plantId == "Q") plant = "Detroit";
  if (plantId == "R") plant = "GMAD - Arlington";
  if (plantId == "S") plant = "Chevrolet St. Louis/Ramos Arizpe";
  if (plantId == "T") plant = "GMAD - Tarrytown";
  if (plantId == "U") plant = "Chevrolet - Lordstown/Hamtramck";
  if (plantId == "V") plant = "G.M. Truck - Pontiac";
  if (plantId == "W") plant = "Chevrolet - Willowtown";
  if (plantId == "X") plant = "Fairfax";
  if (plantId == "Y") plant = "GMAD - Wilmington";
  if (plantId == "Z") plant = "GMAD - Fremont";
  if (plantId == "1") plant = "GM of Canada - Oshawa #1/Wentzville";
  if (plantId == "2") plant = "GM of Canada - St. Therese/Moraine (T&B)";
  if (plantId == "3") plant = "St. Eustache/Detroit (T&B)";
  if (plantId == "4") plant = "Orion/Scarborough";
  if (plantId == "5") plant = "Bowling Green/London";
  if (plantId == "6") plant = "Oklahoma";
  if (plantId == "7") plant = "Lordstown";
  if (plantId == "8") plant = "Shreveport/Fujisawa (Japan)";
  if (plantId == "9") plant = "Detroit (Cadillac)/Oshawa #2";
  if (plantId == "0") plant = "GM Truck Pontiac";

  return plant;
}

/**
 * Get the division from the id
 * Not really used...
 * @param divId
 * @return year
 */
function getDivision(divId)
{
  division = "Undefined";
  switch(divId)
  {
    case "1":
    {
      division = "Chevrolet";
      break;
    }
    case "2":
    {
      division = "Pontiac";
      break;
    }
    case "3":
    {
      division = "Oldsmobile";
      break;
    }
    case "4":
    {
      division = "Buick";
      break;
    }
    case "5":
    {
      division = "GM Overseas";
      break;
    }
    case "6":
    {
      division = "Cadillac";
      break;
    }
    case "7":
    {
      division = "CM of Canada";
      break;
    }
    case "9":
    {
      division = "GM Overseas";
      break;
    }
    case "C":
    {
      division = "Chevy Truck";
      break;
    }
    case "T":
    {
      division = "GMC Truck";
      break;
    }
    default:
    {
      break;
    }
  }
  return division;
}

/**
 * Get the line series from the id
 * Not really used...
 * @param vehId
 * @return lineSeries
 */
function getLineSeries(vehId)
{
  lineSeries = "Undefined";
  if (vehId == "C") lineSeries = "Deluxe (Chevelle/El Camino)";
  if (vehId == "D") lineSeries = "Malibu/El Camino";
  if (vehId == "E") lineSeries = "Chevelle Laguna";
  if (vehId == "G") lineSeries = "Malibu Estate";
  if (vehId == "H") lineSeries = "Monte Carlo/Laguna Estate";
  if (vehId == "K") lineSeries = "Bel Air";
  if (vehId == "L") lineSeries = "Impala";
  if (vehId == "N") lineSeries = "Caprice Classic/Caprice Estate";
  if (vehId == "Q") lineSeries = "Camaro";
  if (vehId == "S") lineSeries = "Camaro Berlinetta/Type LT";
  if (vehId == "V") lineSeries = "Vega";
  if (vehId == "X") lineSeries = "Nova";
  if (vehId == "Y") lineSeries = "Nova Custom";
  if (vehId == "Z") lineSeries = "Corvette";
  return lineSeries;
}

/**
 * Get the sequence from the id
 * Not really used...
 * @param seqId
 * @return sequence
 */
function getSequence(seqId)
{
  sequence = seqId;
  return sequence;
}

/**
 * Get the engine type from the id
 * Not really used...
 * @param engineId
 * @return the engine type
 */
function getEngineType(engineId)
{
  engineType = "";
  switch(engineId)
  {
    case "A":
    {
      engineType=(yearId=="0")?"231 cu. in. L6":"L13 140 cu. in., 1 bbl. carb.";
      break;
    }
    case "B":
    {
      engineType = "L11 140 cu. in., 2 bbl. carb.";
      break;
    }
    case "D":
    {
      engineType = "L22 250 cu. in. L6, 1 bbl. carb.";
      break;
    }
    case "F":
    {
      engineType = "L14 307 cu. in. V8, 2 bbl. carb.";
      break;
    }
    case "H":
    {
      engineType=(yearId=="0")?"L48 350 cu. in. V8, 4 bbl. carb.":"L65 350 cu. in. V8, 2 bbl. carb.";
      break;
    }
    case "J":
    {
      engineType = "267 cu. in. V8";
      break;
    }
    case "K":
    {
      engineType=(yearId=="0")?"229 cu. in. V6":"L48 350 cu. in. V8, 4 bbl. carb.";
      break;
    }
    case "R":
    {
      engineType = "LF6 400 cu. in. V8, 2 bbl. carb.";
      break;
    }
    case "Q":
    case "U":
    case "G":
    {
      engineType = "305 cu. in. V8, 2 bbl. carb.";
      break;
    }
    case "T":
    {
      engineType = "Z28/L82 350 cu. in. V8, 4 bbl. carb.";
      break;
    }
    case "V":
    {
      engineType = "350 cu. in. V8, 2 bbl. carb.";
      break;
    }
    case "L":
    {
      engineType = "L48 350 cu. in. V8, 4 bbl. carb.";
      break;
    }
    case "Y":
    case "X":
    {
      engineType = "LS4 454 cu. in. V8, 4 bbl. carb.";
      break;
    }
    default:
    {
      engineType = engineId;
      break;
    }
  }
  return engineType;
}

/**
 * Get the bodyStyle from the id
 * @param bodyId
 * @return the bodyStyle
 */
function getBodyStyle(bodyId)
{
  bodyStyle = "Undefined";
  // body Id
  if (bodyId == "39") bodyStyle = "Sport Sedan";
  if (bodyId == "47") bodyStyle = "Coupe";
  if (bodyId == "57") bodyStyle = "Sport Coupe (Monte Carlo)";
  if (bodyId == "Z03") bodyStyle = "Landau Coupe (Monte Carlo)";
  if (bodyId == "Z76") bodyStyle = "S Coupe (Monte Carlo)";
  if (bodyId == "67") bodyStyle = "Convertible (Corvette)";
  if (bodyId == "69") bodyStyle = "4-Door Sedan (Nova)";
  if (bodyId == "29") bodyStyle = "4-Door Sedan (Chevelle)";
  if (bodyId == "37") bodyStyle = "Sport Coupe (Chevelle/Corvette)";
  if (bodyId == "35") bodyStyle = "2-Seat Wagon (Chevelle)";
  if (bodyId == "AQ4") bodyStyle = "3-Seat Wagon (Chevelle)";
  if (bodyId == "45") bodyStyle = "3-Seat Wagon";
  if (bodyId == "87") bodyStyle = "Sport Coupe (Camaro)";
  if (bodyId == "17") bodyStyle = "Hatchback Coupe (Nova)";
  if (bodyId == "27") bodyStyle = "Coupe (Nova)";
  if (bodyId == "05") bodyStyle = "Panel Express (Vega)";
  if (bodyId == "11") bodyStyle = "Panel Express (Vega)";
  if (bodyId == "15") bodyStyle = "Kammback Wagon (Vega)";
  if (bodyId == "77") bodyStyle = "Hatchback Coupe (Vega)";
  if (bodyId == "80") bodyStyle = "El Camino";
  return bodyStyle;
}

-->

