// Global variables
  xMousePos = 0; // Horizontal position of the mouse on the screen
  yMousePos = 0; // Vertical position of the mouse on the screen
  xMousePosMax = 0; // Width of the page
  yMousePosMax = 0; // Height of the page

  function captureMousePosition(e)
  {
    if (document.layers)
    {
      xMousePos = e.pageX;
      yMousePos = e.pageY;
      xMousePosMax = window.innerWidth+window.pageXOffset;
      yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    else if (document.all)
    {
      xMousePos = window.event.x+document.body.scrollLeft;
      yMousePos = window.event.y+document.body.scrollTop;
      xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
      yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    }
    else if (document.getElementById)
    {
      xMousePos = e.pageX;
      yMousePos = e.pageY;
      xMousePosMax = window.innerWidth+window.pageXOffset;
      yMousePosMax = window.innerHeight+window.pageYOffset;
    }
  }

  if (document.layers)
  {
    // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
  }
  else if (document.all)
  {
    // Internet Explorer
    document.onmousemove = captureMousePosition;
  }
  else if (document.getElementById)
  {
    // Netcsape 6
    document.onmousemove = captureMousePosition;
  }

  function pausecomp(Amount)
  {
    d = new Date() //today's date
    while (1)
    {
      mill=new Date() // Date Now
      diff = mill-d //difference in milliseconds
      if( diff > Amount ) {break;}
    }
  }

  function getAbsoluteLeft(o)
  {
    oLeft = o.offsetLeft
    while(o.offsetParent!=null)
    {
      oParent = o.offsetParent
      oLeft += oParent.offsetLeft
      o = oParent
    }
    return oLeft
  }

  function getAbsoluteTop(o)
  {
    oTop = o.offsetTop
    while(o.offsetParent!=null)
    {
      oParent = o.offsetParent
      oTop += oParent.offsetTop
      o = oParent
    }
    return oTop
  }

  var MenuFlag = 0;
  var MenuCloseDelay = 200;

  function setMenuFlagOn()
  {
    MenuFlag = 1;
  }

  function setMenuFlagOff()
  {
    MenuFlag = 0
  }

  function showMenu(o,html)
  {
    document.getElementById('CategoryMenuP').innerHTML = html

    var menu = document.getElementById('CategoryMenu');
    menu.style.left = getAbsoluteLeft(o) ;
    if(document.layers) {
      //netscape
       menu.style.top = getAbsoluteTop(o) + 15;
   } else if(document.all) {
     // IE
      menu.style.top = getAbsoluteTop(o) + 18;
   } else if (document.getElementById) {
      //ff
       menu.style.top = getAbsoluteTop(o) + 15;
   }

    //menu.style.top = getAbsoluteTop(o) + 18;
    menu.style.visibility = 'visible';

    setMenuFlagOn();
    window.setTimeout('checkMenu()', MenuCloseDelay);
  }

  function hideMenu()
  {
    var menu = document.getElementById('CategoryMenu')

    menu.style.visibility = 'hidden';

    setMenuFlagOff();
  }

  function checkMenu()
  {
    var menu = document.getElementById('CategoryMenu')

    if(MenuFlag == 0)
    {
      menu.style.visibility = 'hidden';
    }
    else
    {
      window.setTimeout('checkMenu()', MenuCloseDelay);
    }
  }


  //MessageBox.Begin

  function showLevelHelp(level)
  {
    switch(level)
    {
      case 1:
        showMessageBox('<b>Entry Level</b><br>Basic features offering value');
        break
      case 2:
        showMessageBox('<b>Entry Level*</b><br>Enhanced specification/features offering value');
        break
      case 3:
        showMessageBox('<b>Mid Range</b><br>Specification offering good performance/features');
        break
      case 4:
        showMessageBox('<b>Mid Range*</b><br>Enhanced specification offering good performance/features');
        break
      case 5:
        showMessageBox('<b>High End</b><br>Designed to offer high performance/features');
        break
      case 6:
        showMessageBox('<b>High End*</b><br>Enhanced specification offering the highest performance/features');
        break
    }
  }

  function showStockMessage(inStock){
    if (inStock){
      showMessageBox('This item is in stock and ready for shipping.<br>Feel free to place your order,<br>if there are any stock issues<br>we will contact you immediately.');
    } else {
      showMessageBox('Item is currently out of stock<br>1 - 2 days leadtime<br>Any orders placed will be on back order<br>and we will ship on a <b>first come first served</b> basis.<br>We will contact you should there be further delays.');
    }
  }

  function showMessageBox(html)
  {
    document.getElementById('MessageBoxP').innerHTML = html
    document.getElementById('MessageBox').style.visibility = 'visible';
    moveMessageBox()
  }

  function moveMessageBox()
  {
    if (document.getElementById('MessageBox').style.visibility == 'visible')
    {
      var msg = document.getElementById('MessageBox')
      msg.style.left = xMousePos
      msg.style.top = yMousePos + 15

      while((parseInt(msg.style.left.replace('px','')) + parseInt(msg.offsetWidth)) > xMousePosMax)
      {
        msg.style.left = parseInt(msg.style.left) - 1;
      }
      while((parseInt(msg.style.top.replace('px','')) + parseInt(msg.offsetHeight)) > yMousePosMax)
      {
        msg.style.top = parseInt(msg.style.top) - 1;
      }

      window.setTimeout('moveMessageBox()', 10);
    }
  }

  function hideMessageBox()
  {
    document.getElementById('MessageBox').style.visibility = 'hidden';
  }

  //MessageBox.End

  function popUp(url)
  {
    sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
    self.name = "mainWin";
  }

  var cookies = document.cookie;

  function getCookie(name)
  { // use: getCookie("name");
    var index = cookies.indexOf(name + "=");
    if (index == -1) return null;
    index = cookies.indexOf("=", index) + 1;
    var endstr = cookies.indexOf(";", index);
    if (endstr == -1) endstr = cookies.length;
    return unescape(cookies.substring(index, endstr));
  }

  var today = new Date();
  var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

  function setCookie(name, value)
  { // use: setCookie("name", value);
    if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
    cookies = document.cookie; // update cookies
  }

  function checkElementById(Id)
  {
    var x = eval(document.getElementById(Id));
    if(x)
    {
      return true;
    }
    else
    {
      return false;
    }
  }

  function SetProductImageTabs(tab1, tab2, tab3, tab4)
  {
    if(checkElementById('tab1'))
    {
      if(tab1)
      {
        document.getElementById('tab1').src = '/images/zbar_v1o.png';
      }
      else
      {
        document.getElementById('tab1').src = '/images/zbar_v1.png';
      }
    }

    if(checkElementById('tab2'))
    {
      if(tab2)
      {
        document.getElementById('tab2').src = '/images/zbar_v2o.png';
      }
      else
      {
        document.getElementById('tab2').src = '/images/zbar_v2.png';
      }
    }

    if(checkElementById('tab3'))
    {
      if(tab3)
      {
        document.getElementById('tab3').src = '/images/zbar_v3o.png';
      }
      else
      {
        document.getElementById('tab3').src = '/images/zbar_v3.png';
      }
    }

    if(checkElementById('tab4'))
    {
      if(tab4)
      {
        document.getElementById('tab4').src = '/images/zbar_v4o.png';
      }
      else
      {
        document.getElementById('tab4').src = '/images/zbar_v4.png';
      }
    }

  }

  function preloadImage(url)
  {
    var img = new Image();
    img.src = url;
  }


  function showhide(obj, link)
  {
    if(obj.style.visibility != "visible")
    {
      show(obj);
      link.innerHTML = 'Hide category overview';
    }
    else
    {
      hide(obj);
      link.innerHTML = 'Show category overview';
    }
  }

  function show(obj)
  {
    obj.style.visibility="visible";
    obj.style.display="";
  }

  function hide(obj)
  {
    obj.style.visibility="hidden";
    obj.style.display="none";
  }


  function showhidecategoryoverview(obj, img)
  {
    if(obj.style.visibility != "visible")
    {
      show(obj);
      //img.src='/images/plstco2.png';
      document[img].src='/images/plstco2.png';
    }
    else
    {
      hide(obj);
      //img.src='/images/plstco1.png';
      document[img].src='/images/plstco1.png';
    }
  }

  function showhidemenu(obj, img, ckey)
  {
    if(obj.style.visibility != "visible")
    {
      showmenu(obj, img, ckey);
    }
    else
    {
      hidemenu(obj, img, ckey);
    }
  }

  function showmenu(obj, img, ckey)
  {
    obj.style.visibility="visible";
    obj.style.display="";
    //try{
    //document[img].src='/images/nav_bar_u.png';
    document.getElementById(img).src='/images/nav_bar_u.png';
    //} catch(e)
    //{
    //  alert('S image name = '+img+ '\n' + e)
    //}
    setCookie(ckey, "visible")
  }

  function hidemenu(obj, img, ckey)
  {
    obj.style.visibility="hidden";
    obj.style.display="none";
    //try{
    //document[img].src='/images/nav_bar_d.png';
    document.getElementById(img).src='/images/nav_bar_d.png';
    //} catch(e) {
    //  alert('H image name = '+img + '\n' + e)
    //}
    setCookie(ckey, 'hidden')
  }

  function validate_search()
  {
    if (document.search.criteria.value.length < 3)
    {
      alert("Your criteria needs to be greater than two characters!");
      document.search.criteria.focus();
      return false;
    }
    return invalid_chars_check(document.search.criteria);
    return true;
  }
  // Array of invaild characters
  var arr_invalid_chars = new Array("!", "\"", "£", "$", "%", "^", "&", "*", "(", ")", "=", "+", "{", "}",
                    ";", ":", "@", "\'", "|", "\\", "\`", "¬", "#", "~", "<", ">", "/", "?",
                    ",", ".");
  // Check a field for invalid characters
  function invalid_chars_check(obj)
  {
    // Make a string that holds the invalid characters
    var str_invalid_chars = new String();
    for (i = 0; i < arr_invalid_chars.length; i++)
    {
      if (i < arr_invalid_chars.length) str_invalid_chars += arr_invalid_chars[i] + " ";
      else str_invalid_chars += arr_invalid_chars[i];
    }
    for (i = 0; i < arr_invalid_chars.length; i++)
    {
      var where = obj.value.indexOf(arr_invalid_chars[i]);
      if (where != -1 && obj.value)
      {
        alert("Your criteria must contain valid characters, the following are NOT valid:\n\n" + str_invalid_chars);
        obj.value = "";
        obj.focus();
        return false;
      }
    }
    return true;
  }

  function return_remaining_chars(obj, max_length)
  {
    var remaining = max_length - obj.value.length;
    if (remaining > 0) return remaining;
    else return 0;
  }

  function check_remaining_chars()
  {
    var obj_q = document.kb.question;
    var obj_a = document.kb.answer;
    var obj_q_r = document.kb.question_remaining;
    var obj_a_r = document.kb.answer_remaining;
    if (obj_q) obj_q_r.value = return_remaining_chars(obj_q, 1000);
    if (obj_a) obj_a_r.value = return_remaining_chars(obj_a, 8000);
  }



    function OpenNewsWindow(url, width, height)
    {
      window.open(url, "_blank", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=" + width + ",height=" + height)
    }