var defText = [2];
defText[0] = "Enter Item Number or Keyword";
defText[1] = "Description";
defText[2] = "0";
var tabDivId = [5];
var tabDivzIndex = [5];
tabDivId[0] = "hmetab";
tabDivId[1] = "prdtab";
tabDivId[2] = "rprtab";
tabDivId[3] = "fldtab";
tabDivId[4] = "engtab";
tabDivzIndex[0] = 97;
tabDivzIndex[1] = 96;
tabDivzIndex[2] = 95;
tabDivzIndex[3] = 94;
tabDivzIndex[4] = 93;
var showTimeoutId = 0;
var hideTimeoutId = 0;
var evt;
var fcall;
var recCnt;
var accCount = 0;
var is_ie6 = document.all && 
             (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);

function ie6iframe (divid,state) {
   var thediv = document.getElementById(divid);
   var sizestyle;
   if (divid.indexOf("family") == 0) {
      sizestyle = "WIDTH: 220px; HEIGHT: 160px; ";
   }
   else if (divid.indexOf("tablines") != -1) {
      sizestyle = "WIDTH: 200px; HEIGHT: 180px; ";
   }
   else {
      sizestyle = "WIDTH: 100%; HEIGHT: 100%; ";
   }
   if (thediv.innerHTML.indexOf("<IFRAME") == -1) {
      var html = 
          "<IFRAME STYLE=\"DISPLAY: block; Z-INDEX: -1; FILTER: mask(); " +
          "POSITION: absolute; TOP: -1px; LEFT: -1px; " + sizestyle +
          "BACKGROUND-COLOR: #ffffff\"></IFRAME>";
      thediv.innerHTML += html;
   }
}
function displayDflt (obj, idx) {
   if (obj.value == "") {
      obj.value = defText[idx];
   }
}
function clearDflt (obj, idx) {
   if (obj.value == defText[idx]) {
      obj.value = "";
   }
}
function displayAll (theForm) {
   displayDflt(theForm.searchbox,0);
}
function clearAll (theForm) {
   clearDflt(theForm.searchbox,0);
}
function toggleDiv (divid) {
   var thestyle;
   if (document.getElementById) {
      thestyle = document.getElementById(divid).style;
      thestyle.display = (thestyle.display == "block") ? "none" : "block";
   }
}
function hideAllDivisions () {
   var divname;
   var i;
   for (i = 1; i < 5; i++) {
      divname = tabDivId[i] + 'lines';
      if (document.getElementById(divname)) {
         document.getElementById(divname).style.display = 'none';
      }
   }
}
function hideAllAlpha () {
   var divname;
   var i;
   for (i = 'a'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
       divname = String.fromCharCode(i) + "index";
       if (document.getElementById(divname)) {
          document.getElementById(divname).style.display = 'none';
       }
   }
}
function hideAllFamilies () {
   var divname;
   var i;
   for (i = 1; i < 50; i++) {
      divname = 'family' + i;
      if (document.getElementById(divname)) {
         document.getElementById(divname).style.display = 'none';
      } else {
         break;
      }
   }
}   
function changeDiv (divid,state) {
   hideAllDivisions();
   hideAllAlpha();
   hideAllFamilies();
   if (document.getElementById && document.getElementById(divid)) {
      if (is_ie6) {
         ie6iframe(divid,state);
      }
      var d = document.getElementById(divid);
      d.style.display = state;
   }
   if (state == 'none') {
      hideTimeoutId = 0;
   } else {
      showTimeoutId = 0;
   }
}
function showDivDelay (divid) {
   fcall = "changeDiv('" + divid + "','block')";
   if (showTimeoutId !== 0) {
     clearTimeout(showTimeoutId);
   }
   if (hideTimeoutId !== 0) {
     clearTimeout(hideTimeoutId);
   }
   showTimeoutId = setTimeout(fcall,300);
   /*document.getElementById(divid).style.visibility = 'visible';
   document.getElementById(divid).style.display = 'block';*/
}
function hideDivDelay (divid) {
   fcall = "changeDiv('" + divid + "','none')";
   if (showTimeoutId !== 0) {
     clearTimeout(showTimeoutId);
   }
   if (hideTimeoutId !== 0) {
     clearTimeout(hideTimeoutId);
   }
   hideTimeoutId = setTimeout(fcall,300);
   /*document.getElementById(divid).style.visibility = 'hidden';
   document.getElementById(divid).style.display = 'none';*/
}
function toggleDivNP (divid,evt) {
   if (!evt) { evt = window.event; }
   toggleDiv(divid);
   evt.cancelBubble = true;
   if (evt.stopPropagation) { evt.stopPropagation(); }
}
function divTabToFront (divid) {
   var i;
   if (document.getElementById) {
      // Set all tabs back to default z-index
      for (i = 0; i < 5; i++) {
         document.getElementById(tabDivId[i]).style.zIndex = tabDivzIndex[i];
      }
      // Bring selected div to front
      document.getElementById(divid).style.zIndex = 98;
   }
}
function alphaImageOn (divid) {
   if (document.getElementById) {
      if (divid == "abut") {
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index_a_white.jpg')";
      } 
      else if (divid == "zbut") {
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index_z_white.jpg')";
      }
      else {    
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index3_white.jpg')";
      }
   }
}
function alphaImageOff (divid) {
   if (document.getElementById) {
      if (divid == "abut") {
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index_a.jpg')";
      } 
      else if (divid == "zbut") {
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index_z.jpg')";
      }
      else {    
         document.getElementById(divid).style.backgroundImage="url('/images/template/tab_index3.jpg')";
      }
   }
}
function moveToCursor (evt,divid) {
   if (!evt) { evt = window.event; }
   if (document.getElementById) {
      if (evt.pageX || evt.pageY) {
         document.getElementById(divid).style.left = evt.pageX + 2;
         document.getElementById(divid).style.top = evt.pageY - 2;
      }
      else if (evt.clientX || evt.clientY) {
         document.getElementById(divid).style.left = evt.clientX +
                                                    (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
         document.getElementById(divid).style.top = evt.clientY + 
                                                    (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
      }
   }
}
function moveToCursorY (evt,divid) {
   if (!evt) { evt = window.event; }
   if (document.getElementById) {
      if (evt.pageY) {
         document.getElementById(divid).style.top = evt.pageY - 8;
      } else if (evt.clientY) {
         document.getElementById(divid).style.top = evt.clientY + 
              (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 8;
      }
   }
}
function setBackground (divid) {
   if (document.getElementById) {
      document.getElementById(divid).style.backgroundColor="#E8E8E8";
   } 
}
function clearBackground (divid) {
   if (document.getElementById) {
      document.getElementById(divid).style.backgroundColor="#FFFFFF";
   } 
}
function lessSeriesText (divid) {
   if (document.getElementById) {
      document.getElementById(divid + '_parent').style.zIndex = 1;
      document.getElementById(divid).className = "seriestxt serless";
      document.getElementById(divid + '_mlnk').style.display='block';
      document.getElementById(divid + '_llnk').style.display='none';
   }
}
function hideAllSeriesText () {
   var i;
   var divid;
   for (i = 1; i <= recCnt; i++) {
      divid = 'seriestext' + i;
      if (document.getElementById(divid)) {
         lessSeriesText(divid);
      }
   }
}
function moreSeriesText (divid) {
   hideAllSeriesText();
   if (document.getElementById) {
      document.getElementById(divid + '_parent').style.zIndex = 2;
      document.getElementById(divid).className = "seriestxt sermore";
      document.getElementById(divid + '_mlnk').style.display='none';
      document.getElementById(divid + '_llnk').style.display='block';
   }
}

// Function gup taken from http://www.netlobo.com/url_query_string_javascript.html
function gup( name ){  
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
   var regexS = "[\\?&]"+name+"=([^&#]*)";
   var regex = new RegExp( regexS );  
   var results = regex.exec( window.location.href );
   if( results == null )    
      return "";
   else    
      return results[1];
}

function addToCart (qty,theform,partnum) {
   if (isNaN(parseInt(qty)) || parseInt(qty) < 1) {
      alert("Please enter a positive number before clicking add to cart");
      return false;
   }
   theform.pnum.value = partnum;
   theform.addqty.value = qty;  
   // Insure we redirect to same content position in browse window
   //alert(theform.redirURL.value + " " + theform.redirURL.value.indexOf("scrollx"));
   if (theform.redirURL.value.indexOf("scrollx") == -1 && theform.redirURL.value.indexOf("scrolly") == -1) {
      if (theform.redirURL.value.indexOf("?") == -1) {
         theform.redirURL.value = theform.redirURL.value + "?scrollx=" + document.body.scrollLeft + "&scrolly=" + document.body.scrollTop;
      } else {
         theform.redirURL.value = theform.redirURL.value + "&scrollx=" + document.body.scrollLeft + "&scrolly=" + document.body.scrollTop;
      }
   }
   if (theform.tabid && theform.redirURL.value.indexOf("tabid") == -1) theform.redirURL.value = theform.redirURL.value + "&tabid=" + theform.tabid.value;   
   return true;
}   
function resetScrollPosition() {
   var hidx, hidy;
   hidx = gup("scrollx");
   hidy = gup("scrolly");
   if (hidx != '' && hidy != '') {
      window.scrollTo(hidx, hidy);
   }
}

var tabDtlId = [10];
tabDtlId[0] = "ovr";
tabDtlId[1] = "spc";
tabDtlId[2] = "doc";
tabDtlId[3] = "acc";
tabDtlId[4] = "rep";
tabDtlId[5] = "war";
tabDtlId[6] = "tar";
tabDtlId[7] = "opt";
tabDtlId[8] = "lin";
tabDtlId[9] = "sub";
function deactivateAll () {
   var i;
   for (i = 0; i < 10; i++) {
      if (document.getElementById(tabDtlId[i] + "tab") && document.getElementById(tabDtlId[i] + "div")) {
         document.getElementById(tabDtlId[i] + "tab").className = "tab dtl small bold";
         document.getElementById(tabDtlId[i] + "div").style.display = "none";
      }
   }
}   
function makeActive (tabid) {
   if (document.getElementById) {
      deactivateAll();
      document.getElementById(tabid + "tab").className = "tab dtlactive small bold";
      document.getElementById(tabid + "div").style.display = "block";
      document.forms["itemdtlform"].tabid.value = tabid;
   }
}

function selectAccessory (qty, checked) {
   if (checked) {
      accCount = (+accCount) + (+qty);
   } else {
      accCount = accCount - qty;
   } 
}
function addAccessories (theform,partnum) {
   if (accCount <= 0) {
      alert('Please select one or more accessories before adding to cart.');
      return false;
   } else {
      return addToCart(accCount,theform,partnum);
   }
}
function addSubstitute (theform,partnum) {
   if (accCount <= 0) {
      alert('Please select a substitute before adding to cart.');
      return false;
   } else {
      return addToCart(accCount,theform,partnum);
   }
}

