/**
 * Name: index_default.js
 * Version: 1.0
 *
 * Created By: Colorado Correctional Industries [USA]
 *             http://www.coloradoci.com
 *             Arkansas Valley Correctional Facility (AVCF)
 *
 * Web Master: Sandy Gray (sandra.gray@doc.state.co.us)
 *
 * Project: index_default [VBScript/UEStudioProjects]
 * Programmer: WEB1
 * Revision: 23
 *
 * Edited Date: 5/25/2010 10:09:52 AM
 */

var index_default = {};

/**
 * THE DOCROOT WILL BE REMOVED ONCE THIS SITE IS DONE.
 */
var docRoot;
(function() {
  var root = location.protocol + "//" + location.host + "/";
  if (location.toString().match(/intranet/i)) root = root + "" + location.pathname.split(/\//)[0]+"/";
  if (location.toString().match(/172\.22\.40\.30/i)) root = root + "" + location.pathname.split(/\//)[0]+"/";
  if (location.toString().match(/172\.22\.40\.29/i)) root = root + "/";
  docRoot = root;
  //docRoot = "http://coloradoci2/";
  if (location.toString().match(/coloradoci\.com/i)) {
    docRoot = "http://www.coloradoci.com/";
  } else if(location.toString().match(/cijvp\.com/i)) {
    docRoot = "http://www.cijvp.com/";
  }
})();

/**
 * This javascript page here deals with the navigational system of the site as well as the header.
 * This page also displays the images that display on the main page.
 */
var msie = navigator.userAgent.match(/msie/i);
var opera = navigator.userAgent.match(/opera/i);
var safari = navigator.userAgent.match(/safari/i);
var firefox = navigator.userAgent.match(/firefox/i);
var netscape = navigator.userAgent.match(/navigator/i);
var N_states = "AL,AK,AZ,AR,CA,CO,CT,DE,DC,FL,GA,ID,IL,IN,IA,KS,KY,LA,ME,MD,MA,MI,MN,MS,MO,MT,NE,NV,NH,NJ,NM,NY,NC,ND,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VT,VA,WA,WV,WI,WY".split(",");

index_default.ordering_error = false;
index_default.ordering_error_message = "<div align=center><strong style='color:red'><u>ATTENTION: OUR EMAIL SYSTEM IS DOWN!</u></strong></div><div style=text-indent:10><strong>Our online ordering system, and all other online forms are not available at this time. Please contact Sylvia Hernandez to place an order at 303-370-2170.<strong></div>";
/**
 * FUNCTION FOR ALL OF THE PDFS TO OPEN UP IN A STANDARD WINDOW.
 */
index_default.popUpPDFWin = function( links, name ) {
  var N_data = [];
  N_data.push("<html>");
  N_data.push("  <head><title>" + name + "</title></head>");
  N_data.push("  <frameset>");
  N_data.push("     <frame src='" + links + "' frameborder='no' />");
  N_data.push("  </frameset>");
  N_data.push("</html>");

  var greenPDF = window.open("", "", "width=850,height=550,status=no,resizable=yes,menubar=no,toolbar=no,alwaysRaised=yes,addressbar=no");
  greenPDF.document.write(N_data.join(""));
  greenPDF.document.close();
};

//This is to cancel the timeout on the home page when we open the videos.
var swfTimeOut1, swfTimeOut2
var stopProccessingFlash = false;
index_default.popUpSWFWin = function( links, name ){
  var N_data = [];
  N_data.push("<html>");
  N_data.push("  <head><title>"+name+"</title></head>");
  N_data.push("  <frameset>");
  N_data.push("     <frame src='"+links+"' frameborder='no' />");
  N_data.push("  </frameset>");
  N_data.push("</html>");

  //This is to cancel the timeout on the home page when we open the videos
  if(location.pathname.match(/^\/(index.html)?$/i)){
    if(obj('swf_header'))  obj('swf_header').Playing = false;
    if(obj('swf_playing')) obj('swf_playing').Playing = false;
    clearTimeout(swfTimeOut1);
    clearTimeout(swfTimeOut2);
    if(obj('flash')) obj('flash').innerHTML = "<img src='bin-swf/hotBack.jpg'>";
    if(obj('flashHeader')) obj('flashHeader').innerHTML = "";
    if(obj('header')) obj('header').style.backgroundImage = "url('"+docRoot+"/images/flag3.jpg')";
    stopProccessingFlash = true;
  }

  var movieStage = window.open("", "", "width=640,height=476,status=no,resizable=yes,menubar=no,toolbar=no,alwaysRaised=yes,addressbar=no");
  movieStage.document.write(N_data.join(""));
  movieStage.document.close();

};
//temp popup panel only the size changes from popUpSWFWin
index_default.popUp3DWin = function( links, name ) {
  var N_data = [];
  N_data.push("<html>");
  N_data.push("  <head><title>"+name+"</title></head>");
  N_data.push("  <frameset>");
  N_data.push("     <frame src='"+links+"' frameborder='no' />");
  N_data.push("  </frameset>");
  N_data.push("</html>");

  var movieStage = window.open(docRoot+"/bin-htm/flashLoader.html?"+links, "", "width=515,height=515,status=no,resizable=yes,menubar=no,toolbar=no,alwaysRaised=yes,addressbar=no,");
};

var currentPage;

index_default.initMain = function(v) {
  LocationLoger();

  if(index_default.ordering_error && obj("messages")) {
    obj("messages").innerHTML += ordering_error_message;
  }

  //document.body.disabled = true;
	currentPage = v;
  if (v =="mainPage") index_default.rightNav();
  index_default.loadMainMenu();
  index_default.headerInfo();
  index_default.footerInfo();
  index_default.initCache();
};

index_default.initCache = function() {
  //document.body.disabled = false;
  var query = document.location.search.substring(1);
  Cache.initiate(index_default.prepData);
};

index_default.loadMainMenu = function() {
  if(!window.Menu){
    index_default.include(docRoot + "bin-js/Menu.js");
    if (!window.Menu) return false;
  }
  Menu.load("navBar");
};

//////////
// OBJ FUNCTION FOR ALL PAGES.
/////////////
obj = function() {return document.getElementById(arguments[0])};

//////////////
// This script here is the main navigational system and header bar for the entire site.
/////////////

index_default.headerInfo = function(initType) {

	var headInfo = "<table id=headerTable cellpadding=0 cellspacing=0 width=800 height=75 style=\"background:url('"+docRoot+"images/flag3.jpg');\">";

  headInfo += " <tr>";
  headInfo += "  <td valign=top  width=100 height=60 style='Z-index:10;' onclick=\"index_default.checkAdmin(event)\"></td>";
  headInfo += "  <td width=410 valign='center' align=center id='mainMessage' style=z-index:2; class=forthheaderB></td>";
  headInfo += "  <td align=center width=290 valign=top>";
  headInfo += "   <div width=290 align='right' style=padding-right:25px;padding-top:5>";
  headInfo += "    <span>";
  headInfo += "     <span class=smallLinks onclick=document.location='"+docRoot+"index.html' onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">HOME &nbsp;</span>";
  if (!initType) {
    headInfo += "     &nbsp;<span class=smallLinks onclick=\"index_default.login()\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">LOGIN</span>";
  }
  headInfo += "     &nbsp;<span id='span_viewcart' class=smallLinks onclick=\"index_default.goToCart()\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">VIEW CART</span>";
  if (!initType) {
    headInfo += "     &nbsp;<span class=smallLinks onclick=document.location='"+docRoot+"administrator/programs/customer/login_customer.html' onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">YOUR ACCOUNT</span>";
  }

  headInfo += "    </span>";
  headInfo += "   </div>";
  headInfo += "   <div class=darkfifthheader style='padding-top:2px;padding-bottom:3; cursor: pointer' onclick=\"location='"+docRoot+"bin-htm/custServ.html?intro'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">Customer Service 1-800-685-7891</div>";
  if (msie) {
    headInfo += "   <div width=290 style=padding-left:10;>";
  } else {
    headInfo += "   <div width=290 align='right' style=padding-right:25px;padding-top:5;>";
  }
  if(!initType) {
    headInfo += "     <input type=text id=search value='' style='border:solid 1px lightgray' title='search for product: name, one-word description...' />";
    headInfo += "     <span id='span_search' class=fifthheaderB style='cursor:pointer;width:60px;padding:10 0 2 0;' onclick='index_default.searchFor()' onmouseover=\"this.style.color='#c8b24d';\" onmouseout=\"this.style.color='#0f3e5b';\">";
    headInfo += "      Search";
    headInfo += "     </span>";
  }
  headInfo += "   </div>";
  headInfo += "  </td>";
  headInfo += " </tr>";
  headInfo += "</table>";

  obj("header").innerHTML = headInfo;
  if(!initType) {
    obj("search").onkeyup = function(e) {
      if (!e) try{e=event;}catch(e){};
      //e = e || event;
      var keyPressed = e.which || window.event.keyCode;

      if (keyPressed == 13) {
        index_default.searchFor();
      } else if (obj("search").value.match(/debug/i)) {
        index_default.include(docRoot + "bin-js/Cache.debug.js");
      }
    }
  }
}

// Search for products...
index_default.searchFor = function(returndata) {
  Cache.data.general.search = obj("search").value;

  var c = document.createElement("form");
  c.method = "POST";
  c.action = docRoot + "bin-php/search.php";

  var a = document.createElement("input");
  a.type = "hidden";
  a.name = "search";
  a.value = obj("search").value;
  c.appendChild(a);
  document.body.appendChild(c);

  setTimeout(function(){c.submit();}, 1000);
};

index_default.insertBodyWrapper = function() {
  var N_html = [];
  N_html.push("<table width='800' align='center' bgcolor='#ffffff' border='0' cellpadding='0' cellspacing='0'>");
  N_html.push(" <!-- These are the two rows that need to be inserted for the display of the header and navigational system. -->");
  N_html.push(" <tr><td id='header' width='100%'>&nbsp;</td></tr>");
  N_html.push(" <tr><td><div id='navBar' style='position: relative; height: 20px'></div></td></tr>");
  N_html.push(" <tr><td bgcolor='#e9e9e9' height='2'></td></tr>");
  N_html.push(" <tr><td height='10'></td></tr>");
  N_html.push("</table>");
  var headObj = document.createElement("div");
  headObj.innerHTML = N_html.join("");
  var bodyFirstChild = document.body.firstChild;
  document.body.insertBefore(headObj, bodyFirstChild);

  var N_html = [];
  N_html.push("<table width='800' align='center' bgcolor='#ffffff' border='0' cellpadding='0' cellspacing='0'>");
  N_html.push(" <tr><td id='footer' align='center' colspan='2'>&nbsp;</td>");
  N_html.push("</table><br><br><br><br><br><br><br><br><br><br>");
  var headObj = document.createElement("div");
  headObj.innerHTML = N_html.join("");
  document.body.appendChild(headObj);
};



index_default.rightNav = function() {
  var rightNavT = " <br><table width=150 cellpadding=0 cellspacing=0 border=0 >";
  //rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>QUICK SHOPPER</th><tr>";
  var shopNowProds;
  shopNowProds = "Desks|../catalogs/bin-html/onlineProds.html?desks;all,Seating/Chairs|../catalogs/bin-html/onlineProds.html?seating;office,Files & Storage|../catalogs/bin-html/onlineProds.html?filing/Storage;all,Tables|../catalogs/bin-html/onlineProds.html?tables;computer,DOC BDUs|../catalogs/bin-html/onlineProds.html?apparel;DOC BDUs,Flags|../catalogs/bin-html/onlineProds.html?apparel;flags,Lounge Chairs|../catalogs/bin-html/onlineProds.html?seating;lounge,Dormitory Products|../manufacturers/furniture/dormitory.html?dormitory;all,Printer Cartridges|../bin-htm/greenInk.html?intro,Accessories|../catalogs/bin-html/accessories.html?5259;Single Pedestal Desks";

   //shopNowProds = "Air Filtration|filters/index.html?filterProds,Apparel|apparel/index.html?all,DOC BDUs|apparel/index.html?bdu,Dormitory Furniture|furniture/index.html?dormFurn,File Systems|files/index.html?fileProds,Lounge Furniture|furniture/index.html?laungeProds,Office Furniture|furniture/index.html?officeProds,Plastic Bags|bags/index.html?bagProds,Seating|seating/index.html?seatingProds,Hon/Allsteel|honFiling/index.html?honProds";
  var tmp = shopNowProds.split(",");
  for (var i = 0;i < tmp.length; ++i){
    var tmpName = tmp[i].split("|");
    if (tmpName[0] == "Modular Office Systems") {
      rightNavT += " <tr><td class=sideBarLinkSmall onclick=\"document.location='"+docRoot+"manufacturers/"+tmpName[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpName[0]+"</td></tr>";
    } else {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+"manufacturers/"+tmpName[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpName[0]+"</td></tr>";
    }
  }
  rightNavT += "</table>";


//  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
//  rightNavT += " <tr><td style='height:5px'></td><tr>";
//  rightNavT += " <tr><th class=sideBarBlocks>QUICK SHIP</th><tr>";
//  var quickShip = {};
//  quickShip = ",";
//  var tmpQS = quickShip.split(",");
//  for (var i=0;i < tmpQS.length;++i){
//    var tmpNameQS = tmpQS[i].split("|");
//    rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+"manufacturers/"+tmpNameQS[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameQS[0]+"</td></tr>";
//  }
//  rightNavT += "</table>";

  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>CUSTOMER SERVICE</th><tr>";

  wareHouse = "Customer Services|/bin-htm/custServ.html?intro,New Customer|ordering/bin-php/application.php,Service Request|bin-php/cust_serv_form.php";
  var tmpWH = wareHouse.split(",");
  for (var i = 0;i < tmpWH.length; ++i){
    var tmpNameWH = tmpWH[i].split("|");
    if (tmpNameWH[0] == "Contact Customer Service") {
      rightNavT += " <tr><td class=sideBarLinkSmall onclick=\"location='"+docRoot+tmpNameWH[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameWH[0]+"</td></tr>";
    } else {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"location='"+docRoot+tmpNameWH[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameWH[0]+"</td></tr>";
    }
  }
  rightNavT += "</table>";

  /**
   * Videos paths will have to be fixed to link right.
   */


  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>CUSTOM PROJECTS</th><tr>";
  var highLights = {};
  highLights = "Modular Office Plans|serviceproviders/mosprojects/index.html,Furniture Drawings|serviceproviders/furnitureProjects/index.html?intro,Completed Projects|bin-htm/comProjects.html?intro_album";
  var tmpHL = highLights.split(",");
  for (var i = 0;i < tmpHL.length; ++i){
    var tmpNameHL = tmpHL[i].split("|");
    rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+""+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
  }
  rightNavT += "</table>";

  //DENVER SALES LINKS
  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks nowrap>DENVER SHOWROOM</th><tr>";
  var highLights = {};
  highLights = "About Denver Showroom|manufacturers/show/index.html?intro,Quick Ship|manufacturers/show/index.html?qs;all;office%20chairs,In-Stock|manufacturers/show/index.html?ss%7Cin;seating;office%20chairs,Sales Specials|manufacturers/show/index.html?ss%7Css;seating;office%20chairs";
  var tmpHL = highLights.split(",");
  for (var i = 0;i < tmpHL.length; ++i){
    var tmpNameHL = tmpHL[i].split("|");
    if(tmpNameHL[0].length > 20) {
      rightNavT += " <tr><td class=sideBarLinks style='letter-spacing: -0.05em;' onclick=\"document.location='"+docRoot+""+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    } else {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+""+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\" >"+tmpNameHL[0]+"</td></tr>";
    }
  }
  rightNavT += "</table>";
  /**
   * PERSONNEL
   */
  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>NEWS & VIDEOS</th><tr>";
  var highLights = {};
  highLights = "Newsletter|bin-htm/newsletters.html,Video Collection|movies/webMovies/flashdvd.swf,S.W.I.F.T. Videos|movies/swiftFLV/flashdvd.swf,NCIA Video|movies/pie/flashdvd.swf";
  var tmpHL = highLights.split(",");
  for (var i = 0;i < tmpHL.length; ++i){
    var tmpNameHL = tmpHL[i].split("|");
    if (tmpNameHL[0] == "Newsletter") {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+"/"+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    } else if (tmpNameHL[0] == "Video Collection") {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"index_default.popUpSWFWin('"+docRoot+"/"+tmpNameHL[1]+"', 'CCi Movies')\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    } else if (tmpNameHL[0] == "S.W.I.F.T. Videos") {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"index_default.popUpSWFWin('"+docRoot+"/"+tmpNameHL[1]+"', 'SWIFT Movies')\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
      } else if (tmpNameHL[0] == "NCIA Video") {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"index_default.popUpSWFWin('"+docRoot+"/"+tmpNameHL[1]+"', 'NCIA Movies')\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    } else {
      rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+""+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    }
  }
  rightNavT += "</table>";
  /**
   * PROGRAMS
   */
  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>PROGRAMS</th><tr>";
  var highLights = {};
  highLights = "Dog Program|serviceproviders/puppy/index.html?intro,Wild Horse Program|serviceproviders/whip/index.html?intro";
  var tmpHL = highLights.split(",");
  for (var i = 0;i < tmpHL.length; ++i){
    var tmpNameHL = tmpHL[i].split("|");
    rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+""+tmpNameHL[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpNameHL[0]+"</td></tr>";
    if (tmpNameHL[0] == "Dog Program") {
      rightNavT += " <tr><td style=text-indent:5 class=sideBarLinkSmall onclick=location='serviceproviders/puppy/index.html?contact' onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">(719) 269-4650</td></tr>";
    } else if (tmpNameHL[0] == "Wild Horse Program") {
      rightNavT += " <tr><td style=text-indent:5 class=sideBarLinkSmall onclick=location='serviceproviders/whip/index.html?contact' onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">(719) 269-5305</td></tr>";
    }
  }
  rightNavT += "</table>";

  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  rightNavT += " <tr><th class=sideBarBlocks>STATE AWARDS</th><tr>";
  rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+"bin-htm/stateAgreement.html?mos'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">State Awards</td></tr>";
  rightNavT += "</table>";
  rightNavT += " <table width=150 cellpadding=0 cellspacing=0 border=0 >";
  rightNavT += " <tr><td style='height:5px'></td><tr>";
  //rightNavT += " <tr><th class=sideBarBlocks>Video Visits</th><tr>";
  //rightNavT += " <tr><td class=sideBarLinks onclick=\"document.location='"+docRoot+"serviceproviders/videovisits/index.html?products'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">Video Visits</td></tr>";
  rightNavT += "</table>";

  obj("navTableR").innerHTML = rightNavT;
};

index_default.footerInfo = function() {
  var footerTmp = "Home|index.html,About Us|bin-htm/generalinfo.html?intro,CCi Mission|bin-htm/generalinfo.html?mission,Contact Us|bin-htm/contactus.html,State Awards|bin-htm/stateAgreement.html?mos";
  var tmp = footerTmp.split(",");
  var footer = "<table width=100% cellpadding=0 cellspacing=0 border=0>";
  footer += " <tr><td style='height:5px' bgcolor=#E9E9E9></td><tr>";
  footer += " <tr><td style='height:5px' ></td><tr>";
  footer += " <tr><td align=center>";
  for (var i = 0; i < tmp.length; i++) {
    var tmpName = tmp[i].split("|");
    footer += " &nbsp;<span style'font:normal 10pt wingdings'>|</span>&nbsp;<u><span class=sideBarLinks onclick=\"document.location='"+docRoot+""+tmpName[1]+"'\" onmouseover=\"this.style.color='#c8b24d'\" onmouseout=\"this.style.color='#0f3e5b'\">"+tmpName[0]+"</span></u>&nbsp;";
  }
  footer += " </td<tr>";
  footer += "</table>";
  obj("footer").innerHTML = footer;
};

index_default.contactDisplayID = "";
index_default.getContactInfo = function(_id, _specificMatch, _department, _title, _name, _facility, _search){
  var args = { action: 'getContactInfo' };

  if(_specificMatch){
    args.specificMatch = _specificMatch;
  }
  if(_department){
    args.department = _department;
  }
  if(_title){
    args.title = _title;
  }
  if(_name){
    args.name = _name;
  }
  if(_facility){
    args.facility = _facility;
  }
  if(_search){
    args.search = _search;
  }

  if((!_department && !_title && !_name && !_facility && !_search && !_specificMatch) || !_id){
    return false;
  }

  index_default.contactDisplayID = _id;
  index_default.HTTP("POST", docRoot+"bin-cgi/directory.cgi", args, index_default.displayContact);
};

index_default.displayContact = function(dbinfo){
  if(!dbinfo){
    alert("No Contacts Match the given Criteria.");
    return false;
  }

  dbinfo = dbinfo.split("\n");

  var html = ["<div width='100%' style='ext-align:center;'>"];
  var currentDepartment = '', currentTitle = '';
  for(var i = 0; i < dbinfo.length; i++){
    var record = dbinfo[i].split("~");
    var userInfo = record[5].split("^");

    if(currentDepartment != record[1]){
      currentDepartment = record[1];
      html.push("<div style='font: bold 14pt georgia;color:#396e8e; width: 100%; text-align: center; border-bottom: 3px solid #999999;'>"+record[1]+"</div>");
    }
    if(currentTitle != record[3]){
      currentTitle = record[3];

      html.push("<div style='font: bold 12pt georgia; width: 100%; border-bottom: solid 1px #cccccc;'>"+record[3]+"</div>");
    }

    html.push("<div style='font: normal 8pt gothic; margin-left: 10px;'>");
    img = (userInfo[12]) ? docRoot+"images/staffImages/"+decodeURIComponent(userInfo[12])+".jpg" : "";

    html.push("<table><tr>");
    if(img){
      html.push("  <td><img src='"+img+"' style='' /></td>");
    }
    html.push("<td>");
    html.push("  <div style='font: bold 10pt gothic; text-decoration: underline; margin-bottom: 4px;"+(img ? 'float:clear;': '')+"'>"+userInfo[1]+" "+userInfo[2]+" "+userInfo[3]+"</div>");

    if(userInfo[11]){
      html.push("  <a href='mailto:"+userInfo[11]+"' style='margin-bottom: 4px;'>"+userInfo[11]+"</a>");
    }
    html.push("  <div style='font: normal 8pt gothic; margin-bottom: 4px;'>"+userInfo[4]+"<br>"+userInfo[5]+", "+userInfo[6]+" "+userInfo[7]+"</div>");

    if(userInfo[8]){
      html.push("  <div style='font: normal 8pt gothic;'>Phone: "+userInfo[8]+"</div>");
    }
    if(userInfo[9]){
      html.push("  <div style='font: normal 8pt gothic;'>Phone (cell): "+userInfo[9]+"</div>");
    }
    if(userInfo[10]){
      html.push("  <div style='font: normal 8pt gothic;'>FAX: "+userInfo[10]+"</div>");
    }
    html.push("</td></tr></table>");
    html.push("</div><br>");
  }
  html.push("</div>");

  if(obj(index_default.contactDisplayID)){
    obj(index_default.contactDisplayID).innerHTML = html.join("");
  }
};

index_default.faqID = '';
index_default.getFAQ = function(_id, cat, _search){
  var args = {action: 'getFAQ', category: '', search: ''};

  if(!_id || !cat && !_search){
    return false
  }
  index_default.faqID = _id;

  if(cat){
    args.category = cat;
  }
  if(_search){
    args.search = _search;
  }

  index_default.HTTP("POST", docRoot+"bin-cgi/faq.cgi", args, index_default.displayFAQ);
};

index_default.displayFAQ = function(dbinfo){
  if(!dbinfo || dbinfo.match(/^failure/)){
    if(dbinfo.match(/^failure/)){
      alert(dbinfo.split(":")[1]);
    } else {
      alert("Problem with Database.");
    }
    return false;
  }

  dbinfo = dbinfo.split("\n");

  //var html = ["<div style='position:relative;'><div id='div_faq_answer_area' style='z-index: 11; position:absolute; width:300px; height:300px; top: 15; left:30; background-color:white; border:ridge 6px #0f3e5b; display: none;'></div>"];
  var html = ["<div style=''>"];
  var cnt = 1;
  for(var i = 0; i < dbinfo.length; i++){
    var record      = dbinfo[i].split("~");
    var answerID    = "td_"+record[1]+"_answer_"+cnt;
    var questionID  = "td_"+record[1]+"_question_number_"+cnt;
    var questionID1 = "td_"+record[1]+"_question_q_"+cnt;

    if(record[4] && record[5]){
//      html.push("    <div style='margin-top:10px;>");
//      html.push("      <div width='100%' style='' onmouseover=\"obj('div_faq_answer_area').innerHTML = '"+record[5].replace(/\'|\"/g, "&rsquo;")+"'; obj('div_faq_answer_area').style.display = '';\"   onmouseout=\"obj('div_faq_answer_area').style.display = 'none';\"  >");
//      html.push("        "+record[4]);
//      html.push("      </div>");
//      html.push("    </div>");

      html.push("    <table width=600 style='border-collapse:collapse;border-color: #CCCCCC;cursor:pointer;' cellpadding='3' order=1 onclick=\"obj('"+answerID+"').style.display = (obj('"+answerID+"').style.display == 'none') ? '' : 'none';obj('"+questionID1+"').style.fontWeight = (obj('"+questionID1+"').style.fontWeight == 'normal' ? 'bold' : 'normal');\"  onmouseover=\"obj('"+questionID+"').style.display = '';\" onmouseout=\"obj('"+questionID+"').style.display = 'none';\" >");
      html.push("      <tr>");
      html.push("        <td align='right' width='50px' height='30px' rowspan=2 valign=top><span id='"+questionID+"' style='display:none;font: normal 10pt verdana; color: #c8b24d;width:20px;'><span style='font: bold 11pt verdana;'>?</span>&nbsp;</span>"+cnt+"&nbsp;</td>");
      html.push("        <td id='"+questionID1+"' style='cursor: pointer; font: normal 10pt verdana; color: #0f3e5b;' valign='top'>"+record[4]+"</td>");
      html.push("      </tr>");
      html.push("      <tr>");
      html.push("        <td id='"+answerID+"' style='display: none; font: normal 8pt verdana;' >"+record[5]+"</td>");
      html.push("      </tr>");
      html.push("    </table><hr width='100%' style='color:#dddddd;height:1px;' />");
      cnt++;
    }
  }
  html.push("</div>");

  if(index_default.faqID && obj(index_default.faqID)){
    obj(index_default.faqID).innerHTML = html.join("");
    obj(index_default.faqID).style.display = '';
  }
};

index_default.goToCart = function() {
  var ordertype = "";
  if (Cache.data.CART.ordertype) ordertype = "_" + Cache.data.CART.ordertype;
  if (Cache.data.general.blankorder)  ordertype = "_blank";
  Cache.data.CART.checkout = false;

  Cache.checkForChanges(function(){
    document.location = docRoot+"ordering/shoppingcart" + ordertype + ".html";
  });
};

index_default.checkAdmin = function( e ) {
  if (!e) try{e=event;}catch(e){};
  parent.location = docRoot + "index.html";
  if (e.altKey && e.ctrlKey) {
    parent.document.location = docRoot + "administrator/index.html";
  }
};

index_default.login = function() {
  document.location = docRoot + "ordering/login_order.html";
};

function randomizeArray(array){
  if(!typeof(array).toString().match(/array|object/i)){
    return null;
  }
  if(array.length == 1){
    return array;
  }

  var out = [];
	var i = 0;
	var A_done = {};
	while (i < array.length){
		var count = Math.floor(Math.random() * array.length);
		while(A_done[count]){
			count++;
			if(count >= array.length) count = 0;
		}
		A_done[count] = 1;
		out[i] = array[count];
		i++;
	}
	return out;
}

A_GET = {};
(GET = function() {
  if (location.search) {
    var N_query = document.location.search.substring(1).split("&");
    for (var i in N_query) {
      N_query[i] = N_query[i].toString().replace(/\+/g, "%20");
      N_query[i] = decodeURIComponent(N_query[i]);
      var s = N_query[i].search(/\=/);
      var key_ = N_query[i].substring(0, s);
      A_GET[key_] = N_query[i].substring(s+1);
    }
  }
})();
//###########################################################################
//###########################################################################
//###########################################################################

index_default.prepData = function() {
  if (!Cache.data || (Cache.data && !Cache.data.CART)) {
    Cache.data = {
      general: {
        registerinfo: "||||||||||||||||||||||||||||||||||||||"
      },
      CART: {
        products: {}
      },
      A_fabricSamples: {},
      A_fabricSamplesUserData: {
        name: "",
        business: "",
        address1: "",
        address2: "",
        city: "",
        state: "",
        zip: "",
        phone: "",
        fax: "",
        email: ""
      }
    }
  }

  if (Cache.data.general.search && obj("search")) {
    obj("search").value = Cache.data.general.search;
  }

  if (window.shoppingcart) {
    shoppingcart.initiate();
  }
  if (window.amc) {
    amc.initiate();
  }
};

/**
 * Instead of loading every possible javascript module you may need,
 * just load then as you need them!
 *
 * Example of use:
 *  index_default.include("../bin-data/DOC_Facilities.js");
 *  if (!window.DOC_Facilities) return false;
 */
index_default.include = function(js) {
  if (!index_default.include.callers) {
    index_default.include.callers = {};
  }
  if (index_default.include.callers[js]) {
    return true;
  }
  index_default.include.callers[js] = index_default.include.caller;

  var O_script = document.createElement("script");
  var runCaller = function() {
    // MSIE - onreadystatechange
    if (O_script.readyState && O_script.readyState != "loaded") return;
    // Re-run the caller's function.
    index_default.include.callers[js]();
  };

  // Create [loaded] triggers to the <script> element.
  if (document.addEventListener) {
    O_script.addEventListener("load", runCaller, false);
  } else {
    O_script.attachEvent("onreadystatechange", runCaller);
  }

  O_script.setAttribute("src", js);
  document.body.appendChild(O_script);
  //setTimeout(function(){document.body.appendChild(O_script);}, 1000)
};

/**
 * index_default.HTTP
 * Send an HTTP POST/GET request to the specified URL, using the names and
 * values of the properties of the values object as the body of the request.
 * Parse the server's response according to its content type and pass
 * the resulting value to the callback function.
 * If an HTTP error occurs, a null is returned to the callback.
 *
 * EXAMPLE:
 *   index_default.HTTP("GET", "test.txt", returnFunction);
 *
 *   var values = {};
 *     values.productno1 = 11111;
 *     values.productno2 = 22222;
 *     values.productno3 = 33333;
 *   index_default.HTTP("POST", "post.php", values, returnFunction);
 *
 *   function returnFunction(data) { alert(data); };
 */
index_default.HTTP = function( method, URL, values, callback ) {
  method = method.toUpperCase();
  if (method == "GET") {
    callback = values;
  }

  var request;
  try { request = new XMLHttpRequest(); }catch(e){};
  try { request = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){};
  try { request = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){};

  request.onreadystatechange = function() {
    if (request.readyState==1){
      if (obj("productDisplay")) {
        obj("productDisplay").innerHTML= "<div style='text-align:center;font:bold 12pt Arial;padding-top:100'>[ PLEASE STAND BY LOADING PAGE... ]</div>";
      }
    }
    if(request.readyState == 4){
      //alert(request.statusText);
    }
    if (request.readyState == 4 && request.status == 200) {
      if (callback) {
        callback(request.responseText, URL, request.responseXML);
      }
    }
  }
  request.open(method, URL);

  var send = null;
  if (method == "POST") {
    // The header tells the server how to interpret the body of the request.
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    // Encode the properties of the values object and send them as
    // the body of the request.
    var pairs = [];
    for (var name in values) {
      //alert(name+":"+values[name]);
      var value = values[name].toString();
      var pair = encodeURIComponent(name).replace(/%20/g, "+") + "=" +
        encodeURIComponent(value).replace(/%20/g, "+");
      pairs.push(pair);
    }

    send = pairs.join("&");
  }
  request.send(send);
};

index_default.debug = function ( str, folder ) {
  var A_POST = {
    action: "debug",
    str: str,
    folder: folder};
  index_default.HTTP("POST", "bin-php/generalpurpose.php", A_POST);
};

//#######################################################################
/**
 * Name: Cache.js
 * DETAIL:
 */
var Cache = {
  userid: "",
  JSON: "",
  data: {},
  cookie: {
    jar: {}
  }
};

Cache.initiate = function( incommingText ) {

  if (!Cache.initiate.tried) Cache.initiate.tried = false;

  // Initiating Cache through [index_default.initCache()].
  if (incommingText instanceof Function) {
    Cache.initiate.callback = incommingText;
    incommingText = "";
  }

  if (!navigator.cookieEnabled) {
    alert("Browser [cookies] need to be turned on!");
    return false;
  }

  // Initiating Cache through [index_default.initCache()].
  if (!incommingText && !Cache.initiate.tried) {
    Cache.userid = readCookie("Cache_userid");
    if (!Cache.userid){
      Cache.userid = new Date().getTime();
      writeCookie("Cache_userid", Cache.userid);
    }

    var values = {
      action: "getcache",
      userid: Cache.userid
    };
    //alert("Cache_userid => "+readCookie('Cache_userid')+"\nCache.userid  => "+Cache.userid);

    Cache.HTTP(values, Cache.initiate);
    Cache.initiate.tried = true;
    return;
  }

  // Previous use of this function sent out for possible stored Cache data.
  Cache.JSON = incommingText;

  try {
    eval("Cache.data =" + Cache.JSON);
  } catch(e){
    //alert("Cache.initiate->eval(Cache.JSON)\n"+Cache.JSON)
  }

  //setInterval("Cache.checkForChanges();", 250);
  if (Cache.initiate.callback) {
    Cache.initiate.callback();
  }
};

Cache.HTTP = function(A_data, callback ) {
  var request = null;
  try { request = new XMLHttpRequest(); } catch(e) {};
  try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
  try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};

  if (callback) {
    request.onreadystatechange = function() {
      if ((request.readyState == 4) && (request.status == 200)) {
        callback(request.responseText);
      }
    }
  }

  request.open("POST", docRoot + "bin-cgi/cache.cgi");
  request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  var pairs = [];
  for (var name in A_data) {
    var pair = encodeURIComponent(name).replace(/%20/g, "+") + "=" +
      encodeURIComponent(A_data[name]).replace(/%20/g, "+");
    pairs.push(pair);
  }

  request.send(pairs.join("&"));
};

Cache.checkForChanges = function(_callback) {
  if(!_callback){
    _callback = function(){};
  }

  //status = "sciquest: "+document.cookie+":"+(new Date());
  var newJSON = "Cache.data=" + Cache.toJSON(Cache.data);
  var oldJSON = Cache.JSON;

	if (Cache.userid != readCookie("Cache_userid")) {
	  //alert(Cache.userid+" <==> "+readCookie("Cache_userid"));
    writeCookie("Cache_userid", Cache.userid);
  }

  if (newJSON != oldJSON) {
    var values = {
      action: "setcache",
      userid: Cache.userid,
      JSON: newJSON
    };
    Cache.HTTP(values, _callback);
  } else {
    _callback();
  }

  //status = "Cache.data="+Cache.toJSON(Cache.data);;
  Cache.JSON = newJSON;
};

Cache.toJSON = function(O_) {
  var str = "";
  var firstitem = true;

  if (O_ == null || O_ == undefined) return str+O_;

  if (typeof O_ == "number" || typeof O_ == "boolean") {
    str += O_;
  } else if (typeof O_ == "string") {
    O_ = O_.replace(/\\/g, "\\\\");
    O_ = O_.replace(/"/g, "&quot;");
    O_ = O_.replace(/["']/g, "\\$&");
    O_ = O_.replace(/\n/g, "\\n");
    O_ = O_.replace(/\r/g, "\\r");
    str += "\""+O_+"\"";
  } else if (O_.constructor == Array) {
    str += "[";
    for (var i = 0; i < O_.length; i++) {
      if (!firstitem) str += ", ";
      str += arguments.callee(O_[i]);
      firstitem = false;
    }
    str += "]";
  } else if (typeof O_ == "object") {
    str += "{";
    for (var p in O_) {
      if (!firstitem) str += ", ";
      str += "\""+p+"\": "+arguments.callee(O_[p]);
      firstitem = false;
    }
    str += "}";
  }

  return str;
};


//############################
//Colorado Ci Cookies System
//Date: 03/30/11
//Version: 1.0
//Programer: Chewy
//############################

//This function will read a cookie by the name of of the argument name.  It will
//return '' if there is no cookie OR if there is no value in the cookie.
function readCookie(name){
  //Set Default values and append '=' to the end of the name
  var cookieValue = "";
  var search = name + "=";

  //if there are any cookies period
  if(document.cookie.length > 0){
    //find the cookie we are looking for in the cookie string. will return -1 if it does find the cookie
    offset = document.cookie.indexOf(search);

    //if the cookie we are looking for exists
    if (offset != -1){
      //use substring to get the name=value pair we are looking for.
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;

      //set the cookie value to the value part of the name=value pair in the cookie string.
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
};

// Example:
// writeCookie("myCookie", "my name", 24, '/catalogs');
// Stores the string "my name" in the cookie "myCookie" which expires after 15 minutes (900 seconds).
function writeCookie(name, value, hours, _path){
  //make sure that we have the necessary info to write a cookie
  if(!name){ return false; }

  //Begin Cookie Value with name=value pair.
  var cookieValue = name + "=" + escape(value);

  //If no Hours were passed set the default hours to (4320) [180 Days]
  if(!hours){ hours = (180 * 24); }

  //Create Date object then set new time in milliseconds based on the hours either passed to this function or the default.
  var newTime = new Date();
  newTime.setTime(new Date().getTime() + (hours * 60 * 60 * 1000));

  //Set cookie expires time.  This is acutaly been obsolete since 2006 but because Microsoft is a little late catching up we still have to do it this way.
  cookieValue += "; expires=" + newTime.toGMTString() + ";";

  //Set path values defualt is root unless a value was passed to this function to change it.
  cookieValue += ("path=" + (_path ? _path : '/'));

  //write the actual cookie and return the value.
  document.cookie = cookieValue;
  return value;
};

//
//This function tells the browser to delete the cookie next time it runs its
//routine to delete cookies.  untill then it sets the value of the cookie to
//'ImoutOfHere'
function clearCookie(name){
  //get three days worth of milliseconds
  var threedays = 3 * 24 * 60 * 1000;

  //get a new date object and set the date to reflect three days ago.
  var expDate = new Date();
  expDate.setTime(expDate.getTime() - threedays);

  //rewrite the cookie with date reflecting three days ago and for all intents and purposes the cookie has been deleted.
  document.cookie = name + "=ImoutOfHere; expires=" + expDate.toGMTString();
};

//
//This function checks to see if a cookie of name [name] exists and if it does
//it returns that value otherwise it writes in the default value it was passed
//and returns that. Either way after this function has run a cookie of the name
//[name] will exist.
function checkCookie(name, value){
  //make sure that the value is set atleast to the empty string if it is undefined
  if(!value) value = "";

  //if there is not already a value then create the cookie with the default value passed to the function
  if (!readCookie(name)){
    writeCookie(name, value);
  }

  //return either the existing value in the cookie or the defualt sent to the function.
  return readCookie(name);
};

// The location logger checks the page that we are on and sends it to a cgi
// script with a userid(tmp or otherwise). It then gets loged in the
// /bin-data/logs/locationLogger.txt text file.  That file can then be reported
// on later for monthly stats.
function LocationLoger(){
  index_default.HTTP("POST", docRoot+"bin-cgi/locationlog.cgi", {});
};


//See Mars/Web-Work/JavaScript-PHP-Perl/JavaScript/JSON for copies of the json files with documentation.
//This section is a copy of the json.js with the json_parse.js function replacing the JSON.parse function because the JSON.parse function used eval.
//Basic usage is JSON.parse(String) will create a JSON obj out of a properly formated string containing a JSON obj.
//And JSON.stringify(Obj) will return a properly formated string that can be parsed back into a JSON obj using JSON.parse.
var JSON;
if (!JSON) {JSON = {};}
(function () {
"use strict";
function f(n) {return n < 10 ? '0' + n : n;}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta = {'\b': '\\b','\t': '\\t','\n': '\\n','\f': '\\f','\r': '\\r','"' : '\\"','\\': '\\\\'},rep;
function quote(string) {escapable.lastIndex = 0;return escapable.test(string) ? '"' + string.replace(escapable, function (a) {var c = meta[a];return typeof c === 'string' ? c :'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);}) + '"' : '"' + string + '"';}
function str(key, holder) {
var i,k,v,length,mind = gap,partial,value = holder[key];
if (value && typeof value === 'object' && typeof value.toJSON === 'function') {value = value.toJSON(key);}
if (typeof rep === 'function') {value = rep.call(holder, key, value);}
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if (!value) {return 'null';}
gap += indent;partial = [];
if (Object.prototype.toString.apply(value) === '[object Array]') {length = value.length;for (i = 0; i < length; i += 1) {partial[i] = str(i, value) || 'null';}v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';gap = mind;return v;}
if (rep && typeof rep === 'object') {length = rep.length;for (i = 0; i < length; i += 1) {k = rep[i];if (typeof k === 'string') {v = str(k, value);if (v) {partial.push(quote(k) + (gap ? ': ' : ':') + v);}}}
} else {for (k in value) {if (Object.prototype.hasOwnProperty.call(value, k)) {v = str(k, value);if (v) {partial.push(quote(k) + (gap ? ': ' : ':') + v);}}}}
v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';gap = mind;return v;
}}
if (typeof JSON.stringify !== 'function') {JSON.stringify = function (value, replacer, space) {var i;gap = '';indent = '';
if (typeof space === 'number') {for (i = 0; i < space; i += 1) {indent += ' ';}} else if (typeof space === 'string') {indent = space;}rep = replacer;
if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {throw new Error('JSON.stringify');}
return str('', {'': value});};}
if (typeof JSON.parse !== 'function') {JSON.parse = (function () {"use strict";
var at, ch, escapee = {'"': '"','\\': '\\','/': '/',b: '\b',f: '\f',n: '\n',r: '\r',t: '\t'},text,error = function (m) {throw new Error(m);},
next = function (c) {if (c && c !== ch) {error("Expected '" + c + "' instead of '" + ch + "'");}ch = text.charAt(at);at += 1;return ch;},
number = function () {var number,string = '';
if (ch === '-') {string = '-';next('-');}
while (ch >= '0' && ch <= '9') {string += ch;next();}
if (ch === '.') {string += '.';while (next() && ch >= '0' && ch <= '9') {string += ch;}}
if (ch === 'e' || ch === 'E') {string += ch; next();if (ch === '-' || ch === '+') { string += ch; next();}while (ch >= '0' && ch <= '9') { string += ch; next();}}
number = +string;
if (!isFinite(number)) {error("Bad number");} else {return number;}
},
string = function () {
var hex,i,string = '',uffff;
if (ch === '"') {while (next()) {if (ch === '"') {next();return string;} else if (ch === '\\') {next();if (ch === 'u') {uffff = 0;for (i = 0; i < 4; i += 1) {hex = parseInt(next(), 16);if (!isFinite(hex)) {break;}uffff = uffff * 16 + hex;}string += String.fromCharCode(uffff);} else if (typeof escapee[ch] === 'string') {string += escapee[ch];} else {break;}} else {string += ch;}}}
error("Bad string");
},
white = function () {
while (ch && ch <= ' ') {
next();
}
},
word = function () {
switch (ch) {
case 't':
next('t');
next('r');
next('u');
next('e');
return true;
case 'f':
next('f');
next('a');
next('l');
next('s');
next('e');
return false;
case 'n':
next('n');
next('u');
next('l');
next('l');
return null;
}
error("Unexpected '" + ch + "'");
},
value,
array = function () {
var array = [];
if (ch === '[') {
next('[');
white();
if (ch === ']') {
next(']');
return array;
}
while (ch) {
array.push(value());
white();
if (ch === ']') {
next(']');
return array;
}
next(',');
white();
}
}
error("Bad array");
},
object = function () {
var key,
object = {};
if (ch === '{') {
next('{');
white();
if (ch === '}') {
next('}');
return object;
}
while (ch) {
key = string();
white();
next(':');
if (Object.hasOwnProperty.call(object, key)) {
error('Duplicate key "' + key + '"');
}
object[key] = value();
white();
if (ch === '}') {
next('}');
return object;
}
next(',');
white();
}
}
error("Bad object");
};
value = function () {
white();
switch (ch) {
case '{':
return object();
case '[':
return array();
case '"':
return string();
case '-':
return number();
default:
return ch >= '0' && ch <= '9' ? number() : word();
}
};
return function (source, reviver) {
var result;
text = source;
at = 0;
ch = ' ';
result = value();
white();
if (ch) {
error("Syntax error");
}
return typeof reviver === 'function' ? (function walk(holder, key) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}({'': result}, '')) : result;
};
}());
}
}());
