﻿function trace(msg){
  var DebugDiv = document.getElementById('dbgdiv');
  DebugDiv.innerHTML += msg + '<br/>';
}

function getElement(id) { 
  if(document.all) { 
    return document.all[id]; 
  } else if(document.getElementById) { 
    return document.getElementById(id); 
  } else{
    return null;
  }
} 

function toggleSubs(thelink, displayStyle){
  // Get link
  var currentLink = thelink;
  // Get parent LI
  var currentLI = currentLink.parentNode;
  // Get all ULs in the parent LI
  var uls = currentLI.getElementsByTagName('UL');
  // There should only be one, this one:
  var firstUL = uls[0];
  if(displayStyle!=undefined){
    // Set display style
    firstUL.style.display = displayStyle;
    // Hide the <a> that was clicked, show the other one:
    var subLinks = currentLI.getElementsByTagName('a');
    for(t=0; t<= subLinks.length-1; t++){
      testLink = subLinks[t];
      testLinkClass = testLink.className;
      if (testLinkClass=='anone'){
        if (displayStyle=='none'){
          testLink.style.display = 'none';
        }else{
          testLink.style.display = 'inline';
        }
      }else if (testLinkClass=='ablock'){
        if (displayStyle=='block'){
          testLink.style.display = 'none';
        }else{
          testLink.style.display = 'inline';
        }
      }
      if (t == 2) break;
    }
  }else{
    // Try to toggle display style
    if(firstUL.style.display != 'block'){
      firstUL.style.display = 'block';
    }else{
      firstUL.style.display = 'none';
    }
  }
  
}

function showTopSub(nodeNo){
  hideTopSubsExcept(nodeNo);
}

function hideTopSubsExcept(nodeNo){
  exceptDiv = 'dropsubmenudiv' + nodeNo;
  // Get the div that contains drop down menu div:s
  subDivHolder = getElement('dropmenudiv');
  // Get all sub divs
  dropsubmenudivs = subDivHolder.getElementsByTagName('div');
  // iterate...
  for(t=0; t<= dropsubmenudivs.length-1; t++){
    thisDiv = dropsubmenudivs[t];
    divid = thisDiv.id;
    if(exceptDiv == divid){
      thisDiv.style.display = 'block';
    }else{
      thisDiv.style.display = 'none';
    }
  }
  
}

function findme(obj){
  // Debug function
  trace('id ' + obj.id);
  trace('name ' + obj.name);
}

function checkSearchKey(e) {
  var keynum;
  
  if (window.event) {
    keynum = e.keyCode;
  } else if (e.which) {
    keynum = e.which;
  }
  
  if (keynum == 13) {
    searchProduct();
    return false;
  }
  
  return true;
}
var siteRoot="";
function searchProduct() {
  document.location.href=siteRoot+"www/live/product/productsearch.aspx?TreeID=225&searchstring=" + document.getElementById("productSearchstring").value;
}
function fillSearchInput() {
  document.getElementById('productSearchstring').value = getQueryString("searchstring", null);
}

function openTogetherWindow(url) {
    window.open(url, "Together", "width=753, height=400 resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, status=no, menubar=no");
}

function openStartPageLink(url) {
  if(url.indexOf("gateway")>0 || url.indexOf("/www")>=0)
    document.location.href = url;
  else
    document.location.href = "/www/live/"+url;
}

function openFileWin(url) {
  window.open(url.replace('+','|'), 'FileDownload', 'width=500, height=550, resizeable=yes, scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no')
    }
    
    function toggleImg()
    {
    document.getElementById('imgToggler').src=imageList[currentImg][0];
  document.getElementById('imgToggler').alt=imageList[currentImg][1];
  currentImg++;
  if(currentImg==imageList.length)
    currentImg=0;  
}
var currentImg=0;
