

var menuTimer = null;
var menuShown = 0;
var currentMenu = null;
var menus = new Array();
var vc = 0;
var currentProduct = null;
var currentProductTimer = null;
var chartWnd = null;
var paging = false;
var pageTimer = null;
var showingProduct = false;
var overTable = 0;

menus[1] = 'mainmenu_home';
menus[2] = 'mainmenu_products';
menus[3] = 'mainmenu_wheretobuy';
menus[4] = 'mainmenu_sales';
menus[5] = 'mainmenu_support';

function load() {
  if(document.getElementById('catalog_graph')) {
    var el = $('graph_data')?$('graph_data'):$('product_div');
    var cg = $('catalog_graph');
    var xy = Position.cumulativeOffset(el);
    var wh = el.getDimensions();
    var wh2 = cg.getDimensions();
    var offset = $('graph_data')?102:0;

    setElementWidth(el, wh2.width + 20);
    
    document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_up').style.top = xy[1] + "px";
    document.getElementById('autoscroll_up').style.zIndex = 800;
    
    document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
    document.getElementById('autoscroll_down').style.zIndex = 801;
    
    
  }
}

function CreateBookmarkLink() {
  title = "SymCom";
  url = "http://www.symcom.com";
  if (window.sidebar) {
    // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  }
  else if( window.external ) {
    // IE Favorite
    window.external.AddFavorite( url, title);
  }
  else if(window.opera && window.print) {
    // Opera Hotlist
    return true;
  }
}

function mouseoverMainButton(n) {
  if(menuTimer != null) {
    clearTimeout(menuTimer);
  }
  menuTimer = setTimeout('changeSubMenu(' + n + ')', 500);
}

function mouseoutMainButton(n) {
  if(menuTimer != null) {
    clearTimeout(menuTimer);
  }
  menuTimer = setTimeout('changeSubMenu(' + n + ')', 500);
}

function changeSubMenu(n) {
  var i;

  for(i=0;i<5;i++) {
    if(menus[i] != '' && document.getElementById(menus[i])) {
      document.getElementById(menus[i]).style.display = 'none';
    }
  }

  if(n != undefined && menus[n] != '' && document.getElementById(menus[n])) {
    document.getElementById(menus[n]).style.display = 'block';
  }
  menuTimer = null;
  menuShown = 1;
}



/*      CONTACT FUNCTIONS      */

function checkForm(form) {

  if(form.email.value == '') {
    alert('Please enter your email address');
    form.email.focus();
    return false;
  }
  if(!echeck(form.email.value)) {
    alert('The email address you entered is not correct in format');
    form.email.focus();
    return false;
  }
  if(form.state[form.state.selectedIndex].value == '') {
    alert('Please select your location');
    form.state.focus();
    return false;
  }
  if(form.rcpt[form.rcpt.selectedIndex].value == '') {
    alert('Please choose a department');
    form.rcpt.focus();
    return false;
  }
  if(form.comment.value == '') {
    alert('Please enter a question or comment');
    form.comment.focus();
    return false;
  }
  return true;
}

function checkFormTech(form) {

  if(form.email.value == '') {
    alert('Please enter your email address');
    form.email.focus();
    return false;
  }
  if(!echeck(form.email.value)) {
    alert('The email address you entered is not correct in format');
    form.email.focus();
    return false;
  }
  if(form.state[form.state.selectedIndex].value == '') {
    alert('Please select your location');
    form.state.focus();
    return false;
  }
  if(form.rcpt[form.rcpt.selectedIndex].value == '') {
    alert('Please choose a department');
    form.rcpt.focus();
    return false;
  }
  if(form.comment.value == '') {
    alert('Please enter a question or comment');
    form.comment.focus();
    return false;
  }
  if(form.city.value == '') {
    alert('Please enter your city');
    form.city.focus();
    return false;
  }
  return true;
}

function echeck(str) {

  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);

  if(str.indexOf(at) == -1) {
    return false;
  }

  if(str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
    return false;
  }

  if(str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
    return false;
  }

  if(str.indexOf(at,(lat+1)) != -1) {
    return false
  }

  if(str.substring(lat-1,lat) == dot || str.substring(lat+1,lat+2) == dot) {
    return false;
  }

  if(str.indexOf(dot,(lat+2)) == -1) {
    return false;
  }

  if(str.indexOf(" ") != -1) {
    return false;
  }

  return true;
}

function productTableMouseMove(e) {

  if(!document.getElementById('catalog_graph')) return;

  var el = $('graph_data')?$('graph_data'):$('product_div');
  var cg = $('catalog_graph');
  var xy = Position.cumulativeOffset(el);
  var wh = el.getDimensions();
  var wh2 = cg.getDimensions();
  var x = Event.pointerX(e) - xy[0];
  var y = Event.pointerY(e) - xy[1];
  var offset = $('graph_data')?102:0;

  if(x > offset && x < wh.width && y >= 0 && y < 16) {
    if(!showingProduct) {
      stopPaging();
      pageTimer = setTimeout ( "doPage(-1)", 1000);
      document.getElementById('wrapper').style.cursor = 'n-resize';
      
      document.getElementById('autoscroll_up').style.pixelWidth = wh2.width - offset;
      document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=60, FinishOpacity=60, Style=60, StartX=60, StartY=60, FinishX=60, FinishY=60)"; 
      document.getElementById('autoscroll_up').style.opacity = "0.6";
      document.getElementById('autoscroll_down').style.pixelWidth = wh2.width - offset;
      document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
      document.getElementById('autoscroll_down').style.opacity = "0";
      
    }
    else {
      overTable = 1;
      stopPaging();
      
      document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
      document.getElementById('autoscroll_up').style.top = xy[1] + "px";
      setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
      document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
      document.getElementById('autoscroll_up').style.opacity = "0.5";
      
      document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
      document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
      setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
      document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
      document.getElementById('autoscroll_down').style.opacity = "0.5";
      
    }
  }
  else if(x > offset && x < wh.width && y < wh.height && y > wh.height - 16) {
    if(!showingProduct) {
      stopPaging();
      pageTimer = setTimeout ( "doPage(1)", 1000);
      document.getElementById('wrapper').style.cursor = 's-resize';
      
      setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
      document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=60, FinishOpacity=60, Style=60, StartX=60, StartY=60, FinishX=60, FinishY=60)"; 
      document.getElementById('autoscroll_down').style.opacity = "0.6";
      setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
      document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
      document.getElementById('autoscroll_up').style.opacity = "0";
      
    }
    else {
      overTable = 2;
      stopPaging();
      
      document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
      document.getElementById('autoscroll_up').style.top = xy[1] + "px";
      setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
      document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
      document.getElementById('autoscroll_up').style.opacity = "0.5";
      
      document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
      document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
      setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
      document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
      document.getElementById('autoscroll_down').style.opacity = "0.5";
      
    }
  }
  else if(x > 0 && x < wh.width && y < wh.height && y > 0) {
  
    document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_up').style.top = xy[1] + "px";
    setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
    document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
    document.getElementById('autoscroll_up').style.opacity = "0.5";
    
    document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
    setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
    document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
    document.getElementById('autoscroll_down').style.opacity = "0.5";
    
    
    stopPaging();
    document.getElementById('wrapper').style.cursor = 'default';

    overTable = 3;
  }
  else {
    stopPaging();
    
    document.getElementById('wrapper').style.cursor = 'default';
    setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
    document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
    document.getElementById('autoscroll_up').style.opacity = "0";
    setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
    document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
    document.getElementById('autoscroll_down').style.opacity = "0";
    
    overTable = 0;
  }

}

function setElementWidth(obj, w) {
  obj.style.width = w + "px";
}

function checkMousePosition() {
  var el = $('graph_data')?$('graph_data'):$('product_div');
  var cg = $('catalog_graph');
  var xy = Position.cumulativeOffset(el);
  var wh = el.getDimensions();
  var wh2 = cg.getDimensions();
  var offset = $('graph_data')?102:0;
  
  if(overTable == 1) {
    stopPaging();
    pageTimer = setTimeout ( "doPage(-1)", 1000);
    document.getElementById('wrapper').style.cursor = 'n-resize';
    setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
    document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=60, FinishOpacity=60, Style=60, StartX=60, StartY=60, FinishX=60, FinishY=60)"; 
    document.getElementById('autoscroll_up').style.opacity = "0.6";
    setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
    document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
    document.getElementById('autoscroll_down').style.opacity = "0";
  }
  else if(overTable == 2) {
    stopPaging();
    pageTimer = setTimeout ( "doPage(1)", 1000);
    document.getElementById('wrapper').style.cursor = 's-resize';
    setElementWidth(document.getElementById('autoscroll_down'),wh2.width - offset);
    document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=60, FinishOpacity=60, Style=60, StartX=60, StartY=60, FinishX=60, FinishY=60)"; 
    document.getElementById('autoscroll_down').style.opacity = "0.6";
    setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
    document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=0, FinishOpacity=0, Style=0, StartX=0, StartY=0, FinishX=0, FinishY=0)"; 
    document.getElementById('autoscroll_up').style.opacity = "0";
  }
  else if(overTable == 3) {
    document.getElementById('autoscroll_up').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_up').style.top = xy[1] + "px";
    setElementWidth(document.getElementById('autoscroll_up'),wh2.width - offset);
    document.getElementById('autoscroll_up').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
    document.getElementById('autoscroll_up').style.opacity = "0.5";
    
    document.getElementById('autoscroll_down').style.left = xy[0] + offset + "px";
    document.getElementById('autoscroll_down').style.top = xy[1] + wh.height - 16 + "px";
   setElementWidth( document.getElementById('autoscroll_down'),wh2.width - offset);
    document.getElementById('autoscroll_down').style.filter = "Alpha(Opacity=50, FinishOpacity=50, Style=50, StartX=50, StartY=50, FinishX=50, FinishY=50)"; 
    document.getElementById('autoscroll_down').style.opacity = "0.5";
    
    stopPaging();
    document.getElementById('wrapper').style.cursor = 'default';
  }
}

function stopPaging() {
  if(pageTimer) {
    clearTimeout(pageTimer);
  }
}


function doPage(dir) {
  var el =$('graph_data')?$('graph_data'):$('product_div');
  if((dir > 0 && el.scrollTop < el.scrollHeight) || (dir < 0 && el.scrollTop > 0)) {
    el.scrollTop += dir * 20;
    pageTimer = setTimeout ( "doPage('" + dir + "')", 300);
  }
}



function getDim(el){
  for(var lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);
  return {x:lx,y:ly}
}

function showProduct(part) {
  var info = "info_" + part;
  var chart = "chart_" + part;
  var loc;

  if(currentProduct != null) {
    currentProduct.style.display = "none";
    currentProduct = null;
  }

  if(currentProductTimer != null) {
    clearTimeout(currentProductTimer);
    currentProductTimer = null;
  }

  if(part != undefined && document.getElementById(info) && document.getElementById(chart)) {
    loc = getDim(document.getElementById(chart));
    loc.y -= document.getElementById('graph_data').scrollTop;
    document.getElementById(info).style.left = loc.x + 102 + "px";
    document.getElementById(info).style.top = loc.y + 14 + "px";
    document.getElementById(info).style.display = "block";
    document.getElementById(info).style.zIndex = 900;
    currentProduct = document.getElementById(info);
    showingProduct = true;
  }
}

function showProduct2(part) {
  var info = "info_" + part;
  var chart = "chart2_" + part;
  var loc;

  if(currentProduct != null) {
    currentProduct.style.display = "none";
    currentProduct = null;
  }

  if(currentProductTimer != null) {
    clearTimeout(currentProductTimer);
    currentProductTimer = null;
  }

  if(part != undefined && document.getElementById(info) && document.getElementById(chart)) {
    loc = getDim(document.getElementById(chart));
    loc.y -= document.getElementById('products_table').scrollTop;
    document.getElementById(info).style.left = loc.x + 20 + "px";
    document.getElementById(info).style.top = loc.y + 44 + "px";
    document.getElementById(info).style.display = "block";
    document.getElementById(info).style.zIndex = 900;
    currentProduct = document.getElementById(info);
    showingProduct = true;
  }
}

function hideProduct(part) {
  var info = "info_" + part;
  if(part != undefined && document.getElementById(info)) {
    currentProductTimer = setTimeout('document.getElementById("' + info + '").style.display="none"; showingProduct=false; checkMousePosition();', 1000);
  }
}

function openChartWindow(n, c) {
  if(!chartWnd || chartWnd.closed) {
    chartWnd = window.open('/chart.asp?cat='+n, 'chart');
  }

  if(!chartWnd) {
    alert('fail');
  }
  else {
    chartWnd.focus();
  }
}

function viewProduct(part) {
  var loc = window.opener.location.href;
  if(loc.indexOf('#') > 0) {
    loc = loc.substring( 0, loc.indexOf('#') );
  }
  loc = loc + '#' + part;

  window.opener.location.href = loc;
  if(navigator.userAgent.indexOf("Firefox")!=-1) {
    this.close();
  }
  else {
    window.opener.focus();
  }
}


function printEmailAddress(encAddr) {
  var decAddr = decode64(encAddr);
  return decAddr;
}

function printEmailAddressLink(encAddr, class_name) {
  var html;
  if(class_name == undefined) { class_name = 'emaillink'; }
  html = "<span class='" + class_name + "' onClick='document.location=\"mailto:" + printEmailAddress(encAddr) + "\"'>";
  html = html + printEmailAddress(encAddr);
  html = html + "</span>";
  document.write(html);
}

function decode64(inp) {
  var out = ""; //This is the output
  var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
  var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
  var i = 0; //Position counter
  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

  // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
  var base64test = /[^A-Za-z0-9\+\/\=]/g;

  inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

  do { //Here.s the decode loop.

    //Grab 4 bytes of encoded content.
    enc1 = keyStr.indexOf(inp.charAt(i++));
    enc2 = keyStr.indexOf(inp.charAt(i++));
    enc3 = keyStr.indexOf(inp.charAt(i++));
    enc4 = keyStr.indexOf(inp.charAt(i++));

    //Heres the decode part. There.s really only one way to do it.
    chr1 = (enc1 << 2) | (enc2 >> 4);
    chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
    chr3 = ((enc3 & 3) << 6) | enc4;

    //Start to output decoded content
    out = out + String.fromCharCode(chr1);

    if (enc3 != 64) {
      out = out + String.fromCharCode(chr2);
    }
    if (enc4 != 64) {
      out = out + String.fromCharCode(chr3);
    }

    //now clean out the variables used
    chr1 = chr2 = chr3 = "";
    enc1 = enc2 = enc3 = enc4 = "";

  } while (i < inp.length); //finish off the loop

  //Now return the decoded values.
  return out;
}


var retract_timers = new Array();


function dropMenu(obj) {
  if(obj) {
    if(retract_timers[obj] != undefined) {
      clearTimeout(retract_timers[obj]);
    }
    var uls = obj.getElementsByTagName("ul");
    if(uls.length) uls[0].style.display = 'block';
  }
}

function retractMenu(obj) {
  if(obj) {
    var uls = obj.getElementsByTagName("ul");
    if(uls.length) uls[0].style.display = 'none';
  }
}

/*
function retractMenu(obj) {
  if(obj) {
    retract_timers[obj] = setTimeout(function() { retractMenu2(obj); }, 500);
  }
}

function retractMenu2(obj) {
  if(obj) {
    retract_timers[obj] = undefined;
    var uls = obj.getElementsByTagName("ul");
    if(uls.length) uls[0].style.display = 'none';
  }
}

*/


function indexMouseOver(w) {
  if (typeof document.body.style.maxHeight == "undefined") {
    document.getElementById('circle_'+w).style.display='block';
  }
}

function indexMouseOut(w) {
  if (typeof document.body.style.maxHeight == "undefined") {
    document.getElementById('circle_'+w).style.display='none';
  }
}

function display_demo(id) {
  window.open('/files/demos/demo_view.php?id='+id,'demo_view','width=800,height=660');
}











