// additional data and functions

// data structure is ["foreign key", "label"] i'm using non numerical references in case client wants to insert and delete various entries except if references are duplicated.  in that case i take first letter of each word, then next letter of last word until uniqueness is acheived
var dataArray = [
  ["acl","Air Compressor Lubricants"],
  ["acc","Air Compressor Cleaner"],
  ["rac","Reciprocating Air Compressor"],
  ["at","Automotive-Trucking"],
  ["bf","Blower Fluids"],
  ["casc","Centrifugal Air and Steam Compressor"],
  ["cpl","Centrifugal Pump Lubricant"],
  ["ef","Environmentally Friendly"],
  ["beml","Bio-Degradable Environmental Marine Lubricants"],
  ["epl","Extreme Pressure Lubricants"],
  ["fg","Food Grade"],
  ["gl","Gear Lubricants"],
  ["htsl","Heat Transfer Systems Lubricants"],
  ["hs","Hydraulic Systems"],
  ["ngc","Natural Gas Compressors"],
  ["rl","Refrigeration Lubricants"],
  ["rvc","Rotary Vane Compressor"],
  ["sf","Specialty Fluids"],
  ["sg","Synthetic Greases"],
  ["tsbf","Tandem Seal Barrier Fluids"],
  ["vp","Vacuum Pump"]
];

//// data structure is ["id", "label",MSDS on/off, MTD site services data indicator] i'm using non numerical references in case client wants to insert and delete various entries except if references are duplicated.  in that case i take first letter of each word, then next letter of last word until uniqueness is acheived. 
var data_acc = [
  ["BGGFF-Flushing-Fluid","BGGFF Flushing Fluid",1],
  ["Compressor-Cleaner","Compressor Cleaner",1]
];

var data_acl = [
  ["25000-Hour-Lube","25,000 Hour Lube",1],
  ["Breathing-Air-Compressor-Class-D-BAFG-D-100","Breathing Air Compressor Class D BAFG D-100",1],
  ["BGGCL","BGGCL",1],
  ["Food-Grade-FGAC","Food Grade FGAC",1],
  ["Series-D","Series \"D\"",1],
  ["Series-D-plus","Series \"D+\"",1],
  ["Series-G-Glycol-Compressor","Series G Glycol Compressor",1],
  ["Series-GR-PAG-Replacement-Lube","Series \"GR\" PAG Replacement Lube",1],
  ["Series-P","Series \"P\"",1],
  ["Silicone-Screw-Comp","Silicone Screw Comp",1],
  ["Series-SLPIII","Series SLPIII",1],
  ["Series-Specialty-Blend","Series Specialty Blend",1],
  ["Series-SS","Series \"SS\"",1]
];
var data_at = [
  ["ATF-III","ATF III",1],
  ["Auto-Gear","Auto Gear",1],
  ["Wet-Clutch-Hydraulic","Wet Clutch Hydraulic",1],
  ["Workhorse-Full-Syn-MO-SW40","Workhorse Full Syn MO SW40",1]
];
var data_beml = [
  ["Air-Compressors","Air Compressors",1],
  ["Gear-Boxes","Gear Boxes",1],
  ["Grease-Applications","Grease Applications",0],
  ["Hydraulic-Flushing","Hydraulic Flushing",1],
  ["Hydraulic-Systems","Hydraulic Systems",0],
  ["Shark-2-Bio-Degradable-Grease","Shark #2 Bio-Degradable Grease",1],
  ["Wet-Clutch-BG-GHF--68","Wet Clutch, BG&GHF -68",0]
];
var data_bf = [
  ["SBL-220","SBL-220",1]
];
var data_casc = [
  ["Series-SCCL","Series SCCL",1],
  ["Series-STL","Series STL",1]
];
var data_cpl = [
  ["CPL","CPL",1],
  ["Synfluid-X","Synfluid X",1]
];
var data_ef = [
  ["BGGCL","BGGCL",1],
  ["BGGFF-Bio-Green-And-Gold-Flushing-Fluid","BGGFF Bio Green And Gold Flushing Fluid",1],
  ["BGGGF","BGGGF",1],
  ["BGGGR-2-Bio-Green-And-Gold-EP-2-Grease","BGGGR #2 Bio Green And Gold EP 2 Grease",1],
  ["BGGHD","BGGHD",1],
  ["BGGHF","BGGHF",1],
  ["BGGHF-FG","BGGHF FG",1],
  ["BGGHF-MV","BGGHF MV",0],
  ["Shark-2-Shark-Bio-Degradable-Industrial-grease","Shark #2 Shark Bio Degradable Industrial grease",1],
  ["SL-BPC","SL BPC",1]
];
var data_epl = [
  ["EMT-Gear","EMT Gear",1],
  ["Synfluid-X","Synfluid X",1],
  ["SynFluid-X-FG","SynFluid X FG",1]
];
var data_fg = [
  ["Spiral-Freeze--80F-Ball-Rail-Guide-Strip","Spiral Freeze -80F, Ball Rail, Guide Strip",1,"MTD",1,"Spiral-Freeze--55C-Ball-Rail-Guide-Strip","Spiral Freeze -55C, Ball Rail, Guide Strip"],
  ["Arctic-Clear--55","Arctic Clear -55",1],
  ["ATP-FG-Air-Line-Air-Line-Accessory-attatched","ATP FG Air Line, Air Line Accessory attatched",1],
  ["Bio-Degradable-Food-Grade-Hydraulic-BGGHF-FG","Bio-Degradable Food Grade Hydraulic BGGHF FG",1],
  ["BGGGR-2-Bio-Green-And-Gold-EP-2-Grease","BGGGR #2 Bio Green And Gold EP 2 Grease",1],
  ["Blast-Freeze--80F-FG-Low-Temp-Gear-Box","Blast Freeze -80F FG Low Temp Gear Box",1],
  ["Breathing-Air-Compressor-Class-D-BAFG-D-100","Breathing Air Compressor Class D BAFG D-100",1],
  ["Camel-Clear-Silica-Gel-H-1","Camel Clear Silica Gel H-1",1],
  ["Fire-Resistant-Hydraulic-FG","Fire Resistant Hydraulic FG",1],
  ["Hawk-2-FG-Grease","Hawk #2 FG Grease",1],
  ["HTBL-FG-High-Temp-Bearing-Fluid","HTBL FG High Temp Bearing Fluid",1],
  ["HTF-FG","HTF FG",1],
  ["HTF-FG-Heat-Transfer-Fluid-650-F-Auto-Ignition","HTF FG Heat Transfer Fluid 650 F Auto Ignition",0],
  ["Plant-Gear-Boxes-All-Types","Plant Gear Boxes, All Types",1],
  ["PLL-FG-BIO","PLL-FG-BIO",1],
  ["Polar-Bear-Low-Temp","Polar Bear Low Temp",1],
  ["PSL-FG","PSL-FG",1],
  ["Rotary-Screw-Air-Compressors","Rotary Screw Air Compressors",1],
  ["Spray-Pentrant-Bearing-Fluid-PSL-FG","Spray Pentrant & Bearing Fluid PSL-FG",1],
  ["SynFluid-X-FG","SynFluid X FG",1],
  ["Ultra-Pure-380-XT-Oven-Lubricant","Ultra Pure 380 XT - Oven Lubricant",1],
  ["X6100-Anti-microbial-Analysis-Report","X6100 Anti-microbial Analysis Report",0],
  ["Bacoff-Anti-microbial-Statement","Bacoff Anti-microbial Statement",0],
  ["SVAC-FG","Vacuum Pump Fluid",1]
];
var data_gl = [
  ["Ball-Mill-Pulverizes-EMT","Ball Mill Pulverizes EMT",1],
  ["Bevel","Bevel",1],
  ["Helical","Helical",1],
  ["Herringbone","Herringbone",1],
  ["High-Temperature","High Temperature",1],
  ["Low-Temperature-FG","Low Temperature FG",1],
  ["Non-EP-Gear-Fluid","Non EP Gear Fluid",1],
  ["Spiral-Freeze--80F-Ball-Rail-Guide-Strip","Spiral Freeze -80F, Ball Rail, Guide Strip",1],
  ["Spur","Spur",1],
  ["Worm-Gear","Worm Gear",1]
];
var data_htsl = [
  ["Chemical-Processing","Chemical Processing",1],
  ["Closed-Loop-Vented-Heat-Processing","Closed Loop Vented Heat Processing",1],
  ["Die-Casting","Die-Casting",1],
  ["Extrusion","Extrusion",1],
  ["Food-Processing","Food Processing",1],
  ["HTF-32-68-100-Regular","HTF 32, 68, 100 Regular",1],
  ["HTF-DE-Cleaner","HTF DE Cleaner",1],
  ["HTF-FG-32","HTF FG 32",1],
  ["HTF-G-FG","HTF-G-FG",1],
  ["Seal-Compatibility","Seal Compatibility",0],
  ["Plastic-Molding","Plastic Molding",0]
];
var data_hs = [
  ["Environmentally-Friendly-BGGHF","Environmentally Friendly, BGGHF",1],
  ["FRHF","FRHF",1],
  ["FRHF-FG","FRHF FG",1],
  ["High-Temperature-Ultrapure-380-XT","High Temperature Ultrapure 380 XT",1],
  ["Rotary-Vane","Rotary Vane",1],
  ["Rotary-Gear-BG-GGF","Rotary Gear BG&GGF",1],
  ["SL-Parasyn-PS-Series-Hydraulic-Fluids","SL Parasyn-PS Series Hydraulic Fluids",1]
];
var data_ngc = [
  ["NGL","NGL",1],
  ["NGL-SS","NGL SS",1],
  ["Series-G","Series \"G\"",1]
];
var data_rac = [
  ["BAFG-D-100","BAFG-D-100",1],
  ["Series-D","Series \"D\"",1],
  ["Series-P-Recip","Series P Recip",0],
  ["Series-PS-Tank-Mounted","Series PS Tank Mounted",1]
];
var data_rl = [
  ["R717AC","R717AC",1],
  ["RB5","RB5",1],
  ["ABR_-32_-68","ABR_-32_-68",1],
  ["SLII-46FS","SLII-46FS",1]
];
var data_rvc = [
  ["Class-D-BAFG","Class D BAFG",1],
  ["Series-D","Series \"D\"",0],
  ["Series-P","Series \"P\"",0],
  ["Series-Specialty-Blend","Series Specialty Blend",1]
];
var data_sf = [
  ["Centrifugal-Pump-Lubricants","Centrifugal Pump Lubricants",1],
  ["Falcon-Graphite","Falcon Graphite",1],
  ["Fire-Resistant-Concentrate","Fire Resistant Concentrate",1],
  ["Fire-Resistant-Hydraulics","Fire Resistant Hydraulics",0],
  ["Fire-Resistant-Hydraulics-FG","Fire Resistant Hydraulics FG",1],
  ["High-Temperature-Chain-Oils","High Temperature Chain Oils",1],
  ["Polyglycol-Lubricants-Series-GR","Polyglycol Lubricants, Series GR",1],
  ["PSL","PSL",1],
  ["Series-G","Series G",0],
  ["Silicone-Synthetics","Silicone Synthetics",1]
];
var data_sg = [
  ["Arctic-Clear--55","Arctic Clear -55",1],
  ["BGGGR-2-Bio-Green-And-Gold-EP-2-Grease","BGGGR #2 Bio Green And Gold EP 2 Grease",1],
  ["Camel-Clear-Silica-Gel-H-1","Camel Clear Silica Gel H-1",1],
  ["Cougar-Semi-fluid-Grease-Wire-Rope-Lubricant","Cougar Semi-fluid Grease Wire Rope Lubricant",1],
  ["Food-Grade","Food Grade",1],
  ["Hawk-0-3","Hawk #0-3",0],
  ["Hawk-2-FG-Grease","Hawk #2 FG Grease",1],
  ["Polar-Bear-Low-Temp","Polar Bear Low Temp",1],
  ["Shark","Shark",1],
  ["Ultron-Blue","Ultron Blue",1]
];
var data_tsbf = [
  ["Barrier-Fluids-FDA-Supplemental-Data","Barrier Fluids FDA - Supplemental Data",0],
  ["T-Seal","T-Seal",1],
  ["FR-T-Seal","FR T-Seal",1]
];
var data_vp = [
  ["SVAC","Synthetic Vacuum Pump Lubricant",1],
  ["SVAC-FG","Food Grade Vacuum Pump Fluid",1]
];

var data_trinity = [
  ["Series-TSB","Series TSB",1],
  ["Series-D-plus","Series \"D+\"",1],
  ["Series-GR-PAG-Replacement-Lube","Series \"GR\" PAG Replacement Lube",1],
  ["Series-P","Series \"P\"",1],
  ["Series-SLPIII","Series SLPIII",1],
  ["Environmentally-Friendly-BGGHF","Environmentally Friendly, BGGHF",1],
  ["FRHF","FRHF",1],
  ["Workhorse-Full-Syn-MO-SW40","Workhorse Full Syn MO SW40",1],
  ["Consignment","Consignment",1],
  ["trinity","Trinity Industry Special Blend FRHF",1]
];


// functions
var uri = document.location + "";
var uriIndex = uri.indexOf('?');
var queryPart = uri.substring(uriIndex+1,uri.length);
if (uriIndex != "-1") {
  var queryStr = queryPart.split("::");
  var pageType = queryStr[1];
  var indexItem = queryStr[2];
  var companyName = "SLFi";
  var output = "";
  var finaloutput = "";
  var prevCat = false;
  var nextCat = false;
  if(pageType == "category" || pageType == "EuroCategory") {
    var cookieTest = getCookie("slfiCookie");
    // get the label for this category
    for(var j=0;j<dataArray.length;j++) {
      if(indexItem == dataArray[j][0]) {
        categoryTitle = dataArray[j][1];
        if(j > 0) {
          prevCat = dataArray[j - 1][0];
        }
        if(j < dataArray.length - 1) {
          nextCat = dataArray[j + 1][0];
        }
      }
    }

    if(indexItem == "trinity") {
      categoryTitle = "Trinity Industries";
    }
    output += "<b><a href=category.html?::category::" + indexItem + ">" + categoryTitle + "</a></b><br><br>";
    if(pageType == "category") {
      if(prevCat) {
        finaloutput += "<b><a href=category.html?::category::" + prevCat + ">Previous</a></b>&nbsp;&nbsp;|&nbsp;&nbsp;";
      }
      if(nextCat) {
        finaloutput += "<b><a href=category.html?::category::" + nextCat + ">Next</a></b>";
      }
    }
    output += "Below are our product data sheets and MSDS for your reference.  These are PDF documents that require the Adobe Acrobat viewer.  Click on any of the below links to view the document in a new browser window.  If you don't have Adobe Acrobat Viewer, click on the Get Adobe below.<br><br>";
    
    output += "<table border=0 width=100% cellpadding=2 cellspacing=0>";

    // make list of pdf files
    newArray = eval("data_" + indexItem);
    for(var i=0;i<newArray.length;i++) {
      // additional formatting - not implemented yet
      if(i%2){
        tableColor = "white";
      } else {
//        tableColor = "#F2F2F2";
        tableColor = "white";
      }
      var docTitle = companyName + "_" + indexItem + "_" + newArray[i][0];
      var displayTitle = newArray[i][1];
      if(pageType == "EuroCategory" && newArray[i][3]) {
        // check to see if this is a special data sheet from a partner company
        // check for special title
        if(newArray[i][4]) {
          var docTitle = "MTD" + "_" + indexItem + "_" + newArray[i][5];
          var displayTitle = newArray[i][6];
        } else {
          var docTitle = "MTD" + "_" + indexItem + "_" + newArray[i][0];
        }
      }
      output += "<tr><td width=24 class=table bgcolor=" + tableColor + "><img src=/images/pdf.gif width=22 height=24></td><td class=table bgcolor=" + tableColor + ">";
      output += "<a href=products/" + docTitle + ".pdf target=new>" + displayTitle + "</a>";
      if(newArray[i][2] == 1) {
				output += "  | <a href=products/" + docTitle + "_MSDS.pdf target=new>MSDS</a>";
				// Per Mike's request, it is no longer required that the form be filled out before seeing the
				// MSDS sheets.
				
        // if(cookieTest == "msds_success") {
        //           output += "  | <a href=products/" + docTitle + "_MSDS.pdf target=new>MSDS</a>";
        //         } else {
        //           output += "  | <a href=msds.html?::msds::" + indexItem + "::" + i + "::" + docTitle + "_MSDS.pdf>MSDS</a>";
        //         }
      } else {
  			// output += "  | (need MSDS for this)";
      }
			//      output += "<br>" + docTitle + "_MSDS.pdf";
      output += "</td></tr>";
    }
    output += "</table><br>";
    output += finaloutput;
  } else if(pageType == "msds") {
    var productId = queryStr[3];
    var docTitle = queryStr[4];
    tempProductArray = eval("data_" + indexItem);
    tempProductTitle = tempProductArray[productId][1];
    var newQueryStr = "::msds_result::" + indexItem + "::" + productId + "::" + docTitle;
    var newInputField = "<INPUT TYPE=HIDDEN VALUE=\"http://www.slfi.net/msdsthankyou.html?" + newQueryStr + "\" name=\"success\">";
    var productField = "<INPUT TYPE=HIDDEN VALUE=\"" + tempProductTitle + "\" name=\"Requested_MSDS_Title\">";
    
  } else if(pageType == "msds_result") {
    var cookieStr="msds_success";
    var now = new Date();
    // fix the bug in Navigator 2.0, Macintosh
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie("slfiCookie", cookieStr, now, "/");
    var productId = queryStr[3];
    var docTitle = queryStr[4];
    var newLink = "<b><a href=products/" + docTitle + " target=new>Click to get the MSDS Now!</a></b>";
  } else if(pageType == "partlist") {
    indexItem = unescape(indexItem);
    parseArray = indexItem.split(" ");
    if(parseArray) {
      newIndexItem = parseArray.join("_");
    }
    document.write("<script language=\"javascript\" src=\"data/" + newIndexItem + ".js\"></script>");
  }
}

// cookie functions

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}