//Navigation Menu

currentMenuItem = "";
menuItemNormal = "";

function setCurrentMenuItem(item, normal) {
  if(currentMenuItem != MM_findObj(item)) {
    currentMenuItem.src = menuItemNormal;
    currentMenuItem = MM_findObj(item);
    menuItemNormal = normal;
  }
}

function toggleList(id) {
  list = document.getElementById(id);
  if (list.style.display == "none") {
    list.style.display = "";
  } else {
    list.style.display = "none";
  }
}

//Bookmark Page

function bookmarkIt() { 
  var bookmarktitle = document.title;
  var bookmarkurl = document.location;
  var netscape
  var macintosh
  netscape="Attention Netscape Users. To Bookmark this page please click the page you would like to bookmark and press CTRL+D. If you would like to add this page to your Netscape Sidebar, please click OK on the next window which appears.";
  macintosh="Attention Macintosh User. To Bookmark this page please click the page you would like to bookmark and press CTRL+D.";

  if (window.sidebar&&window.sidebar.addPanel) { 
    alert(netscape);
    window.sidebar.addPanel(bookmarktitle, bookmarkurl,""); 
  } else if (isMac) {
    alert(macintosh);
  } else if (document.all) {
    window.external.AddFavorite(bookmarkurl, bookmarktitle);
  } else if (window.opera && window.print) {
    return true;
  }
}

//Print Page

function printIt() { 
  var macprint;
  macprint = "Attention Macintosh User. Unfortunately this functionality is not available on the Macintosh OS. Please click the page you would like to print a select print from your browser menu.";

  if (isMac) { 
    alert(macprint);
  } else {
  self.print()
  }
}

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) {
    if(x!=currentMenuItem)
      x.src=x.oSrc;
  }
}

//Rollover Effects

function MM_preloadImages() {
  var d=document;
  if(d.images){
    if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0) {
      d.MM_p[j]=new Image;
      d.MM_p[j++].src=a[i];
    }
  }
}

function MM_findObj(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n);
    return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr = new Array;
  for(i=0;i<(a.length-2);i+=3) {
    if ((x=MM_findObj(a[i]))!=null) {
      document.MM_sr[j++]=x;
      if(x!=currentMenuItem) {
        if(!x.oSrc) x.oSrc=x.src;
        x.src=a[i+2];
      }
    }
  }
}

//Open Browser Window

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

isIE = isIE4 = isIE5 = isIE6 = isIE7 = isNS = isNS4 = isNS6 = isNS7 = isNS8 = isGecko = isOpera = isBlazer = isFlash5 = isFlashMX = false;

// Browser Detection
if (navigator.userAgent.indexOf('Gecko') > 0) isGecko = true;
if (navigator.appName.indexOf('Netscape') == 0) isNS = true;
if (navigator.appName.indexOf('Microsoft') == 0) isIE = true;
if (navigator.appName.indexOf('Opera') == 0) isOpera = true;
if (navigator.appName.indexOf('Blazer') == 0) isBlazer = true;
isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) ||
         (window.navigator.appVersion.indexOf("Linux") != -1) ||
         (window.navigator.appVersion.indexOf("SunOS") != -1) ||
         (window.navigator.appVersion.indexOf("IRIX") != -1) ||
         (window.navigator.appVersion.indexOf("HP-UX") != -1);
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
isWindows = navigator.userAgent.indexOf("Windows 95") != -1 ||
            navigator.userAgent.indexOf("Windows 98") != -1 ||
            navigator.userAgent.indexOf("Windows NT") != -1;
isMacIE = (isMac && isIE);

// Browser Versions
if (isNS) {
  v = parseInt(navigator.appVersion);
  if(v == 4) {
    isNS4 = true;
  } else if(v == 5) {
    p = navigator.userAgent.lastIndexOf('/');
    v = parseInt(navigator.userAgent.substr(p+1));
    eval("isNS" + v + " = true");
  }
}

if (isIE) {
  v = parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+5));
  eval("isIE" + v + " = true");
}

if (isOpera) {
  v = parseInt(navigator.appVersion);
}

// Flash Version
if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]  && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
  if (navigator.plugins && navigator.plugins["Shockwave Flash"] && (versionIndex = navigator.plugins["Shockwave Flash"].description.indexOf(".")) != - 1) {
    var versionString = navigator.plugins["Shockwave Flash"].description.substring(versionIndex-1, versionIndex);
    versionIndex = parseInt( versionString );
    if ( versionIndex >= 5 ) {
      isFlash5 = true;
    }
    if ( versionIndex >= 6 ) {
      isFlashMX = true;
    }
  }
} else if (isIE && isWindows) {
  document.write('<script language="VBScript">\n');
  document.write('on error resume next\n');
  document.write('isFlash5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
  document.write('isFlashMX = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
  document.write('</script>\n');
}

//Random Quote Generator
var theImages = new Array()

theImages[0] = '/images/quote_1.gif'
theImages[1] = '/images/quote_2.gif'
theImages[2] = '/images/quote_3.gif'
theImages[3] = '/images/quote_4.gif'

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
  document.write('<img src="'+theImages[whichImage]+'">');
}

//expire in 30 days
expire = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 30);

if (document.location.toString().indexOf('browser_detect.php') < 1) {
  //Check for compliant browser:
  cleared = false;
  param = '';
  // Allow IE 5+, Netscape 6+, Opera 7+, and Mozilla/Gecko based browsers
  if ((isIE && v >= 5) || (isNS && v > 4) || isGecko || (isOpera && v > 6)) {
    cleared = true;
  }
  if (isBlazer) // Clear the Treo browser, but don't enable Flash:
    cleared = true;

  if (!cleared && getCookie('ignoreBrowserCheck') != 1) {
    document.location = '/browser_detect.php' + param;
  }
/*
  if (getCookie('flash') == null && location.toString().indexOf('cookiecheck=1') < 1) {
    if (isFlashMX) {// || isFlash5) {
      setFlashCookie(true);
    } else {
      setFlashCookie(false);
    }
  }
*/
}


function ignoreDetect() {
  setCookie('ignoreBrowserCheck', 1, expire);
}

function setCookie(name, value, expires) {
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    "; path=/";
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
    end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name) {
  if (getCookie(name))
    document.cookie = name + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function toggleFlash(enable) {
  if (getCookie('flash') == null &&
    location.toString().indexOf('cookiecheck=1') > 0) {
    alert('Cookies are required to disable the Flash interface.');
  } else
    setFlashCookie(enable);
  return false;
}

function setFlashCookie(enable) {
    if (typeof(encodeURIComponent) == 'function')
      loc = encodeURIComponent(document.location);
    else
      loc = escape(document.location);
    if (enable) {
      location.replace("/cookie.php?flash=1&cookiecheck=1&loc=" + loc);
    } else {
      location.replace("/cookie.php?flash=0&cookiecheck=1&loc=" + loc);
    }
}

function eulaDownload($file) {
  window.open('/drivers/license.php?file=' + $file, '_download',
              'height=550,width=450,location=no,menubar=no,resizable=yes,status=no,toolbar=no,scrollbars=yes');
  return false;
}

// DHTML menu functions
var timeout;
var menus = Array();

function DOMBrowser() {
	return document.body && document.body.style && document.getElementById;
}
function getX(elem) {
  var x = 0;
  if (elem.offsetParent)
    x = getX(elem.offsetParent);
  return x + elem.offsetLeft;
}
function getY(elem) {
  var y = 0;
  if (elem.offsetParent)
    y = getY(elem.offsetParent);
  return y + elem.offsetTop;
}
function enterMenu(elem) {
  if (DOMBrowser()) {
    // Hide any past menus
    hideMenus(elem.offsetParent.id);
    showSubmenu(elem);
    if (timeout)
      clearTimeout(timeout);
  }
  return true;
}
function leaveMenu(elem) {
  if (DOMBrowser()) {
    timeout = setTimeout("hideMenus()", 500);
  }
  return true;
}
function getXPos(elem, child) {
  //Temporarily set the display to block so that we can calculate offsetWidth/Height
  child.style.display = "block";
  parentX = getX(elem);
  x = parentX + elem.offsetWidth - 5;
  //document.body.scrollLeft;
  if (x + child.offsetWidth > document.body.clientWidth + document.body.scrollLeft) { // If the menu would appear offscreen:
    if (parentX - child.offsetWidth - document.body.scrollLeft + 5 > 0) { // If there's room to the left of the parent menu:
      x = parentX - child.offsetWidth + document.body.scrollLeft + 5;
    } else { // Fit as much in as possible:
      availSpace = (document.body.clientWidth - elem.offsetWidth) / 2;
      x = document.body.clientWidth + document.body.scrollLeft - child.offsetWidth;
      if (parentX > availSpace)
        x = 0;
      //Don't overlap the parent:
      if (x == parentX) x -= 5;
    }
  }
  child.style.display = "none";
  return x;
}
function getYPos(elem, child) {
  //Temporarily set the display to block so that we can calculate offsetWidth/Height
  child.style.display = "block";
  parentY = getY(elem);
  y = parentY + 5;
  if (y + child.offsetHeight > document.body.clientHeight + document.body.scrollTop) { // If the menu would appear offscreen:
    if (parentY - child.offsetHeight - document.body.scrollTop + 5 > 0) { // If there's room above the parent menu:
      y = parentY - child.offsetHeight + document.body.scrollTop + 5 ;
    } else { // Fit as much in as possible:
      y = document.body.clientHeight + document.body.scrollTop - child.offsetHeight - 5;
      if (y < 0) y = 0;
    }
  }
  child.style.display = "none";
  return y;
}
function showSubmenu(elem) {
  var id = elem.id + "_submenu";
  menu = document.getElementById(id);
  if (menu) {
    // Reset display so that browsers are not confused when we postion (Opera in particular)
    menu.style.display = "none";
    menu.style.top = getYPos(elem, menu);
    menu.style.left = getXPos(elem, menu);
    menu.style.display = "block";
    menus.push(menu);
  }
}
function hideMenus(elemID) {
  // Hide up to the passed element:
  var elem;
  if (elemID)
    elem = document.getElementById(elemID);
  while (men = menus.pop()) {
    if (elem && men.id == elem.id) {
      menus.push(men); // Put the match back into the array
      return;
    } else
      men.style.display = "none";
  }
}