﻿// (c) visarc 2007

// browser detection

var nn4 = false;	
var ie4 = false;
var ie5 = false;
var ie6 = false;
var moz = false;	
var dom1 = false;	
var dom2 = false;	
var old = false;	

if(window.document.implementation)
{
  dom1 = window.document.implementation.hasFeature("HTML","1.0");
  dom2 = window.document.implementation.hasFeature("HTML","2.0") &&	window.document.implementation.hasFeature("Events","2.0") && 	window.document.implementation.hasFeature("Core","2.0") && window.document.implementation.hasFeature("CSS2","2.0");
}
moz = window.navigator ? (window.navigator.userAgent.indexOf("ecko") != -1)	: false;
nn4 = window.document.layers && !moz;
ie6 = window.document.all && dom1;
ie5 = window.document.all && window.document.getElementsByTagName && !ie6;
ie4 = window.document.all && !ie6 && !ie5;
old = (!ie4 && !ie5 && !ie6 && !dom1 && !nn4 && !moz);

// misc helpers

function getElement(id)
{
  return document.getElementById ? document.getElementById(id) : document.all[id];
}

function getLeft(e)
{
  if(e.offsetParent) return e.offsetLeft + getLeft(e.offsetParent);
  return e.offsetLeft;
}

function getTop(e)
{
  if(e.offsetParent) return e.offsetTop + getTop(e.offsetParent);
  return e.offsetTop;
}

function getWidth(e)
{
  return parseInt(e.offsetWidth, 10);
}

function getHeight(e)
{
  return parseInt(getElement(e).offsetHeight, 10);
}

function getWindowWidth()
{
  if(document.layers || (document.getElementById && !document.all))
  {
    return window.outerWidth;
  }
  return document.body.clientWidth;
}

function getWindowHeight()
{
  if(document.layers || (document.getElementById && !document.all))
  {
    return  window.outerHeight;
  }
  return document.body.clientHeight;
}

function getScrollHeight()
{
   var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
   return h ? h : 0;
}

function setOpacity(e, pc)
{
  var u = (pc * 1.0) / 100.0;
  e.style.opacity = u;
  e.style.MozOpacity = u;
  e.style.KhtmlOpacity = u;
  e.style.filter = "alpha(opacity=" + pc + ")";
}

function setEvent(e, tag, callback)
{
  if(e.addEventListener)
  {
    e.addEventListener(tag, callback, true);
    return true;
  }
  else if(e.attachEvent)
  {
    return e.attachEvent("on" + tag, callback);
  }
  // should really cater for very old browsers, but can't be naffed.
}

function detachEvent(e, tag, callback)
{
  if(e.removeEventListener)
  {
    e.removeEventListener(tag, callback, true);
    return true;
  }
  else if(e.detachEvent)
  {
    return e.detachEvent("on" + tag, callback);
  }
  // ditto
}

function cancelEvent(e)
{
  if(moz || dom2)
  {
    e.stopPropagation();
    e.preventDefault();
  }
  if(ie4 || ie5 || ie6)
  {
	  window.event.cancelBubble = true;
	  window.event.returnValue = false;
  }
}

function checkFlash()
{
  var hasFlash = false;
  if(navigator.plugins && navigator.plugins.length)
  {
    var flash = navigator.plugins["Shockwave Flash"];
    return flash != null;
  }
  else if (navigator.mimeTypes && navigator.mimeTypes.length)
  {
    var flash = navigator.mimeTypes["application/x-shockwave-flash"];
    return flash != null && flash.enabledPlugin;
  }
  else
  {
    // the ie way...
    for(var i = 2; i < 7; i++)
    {
      try
      {
        var flash = new ActiveXObject("ShockwaveFlash.ShockWaveFlash." + i);
        if(flash != null) return true;
      }
      catch(e) { };
    }
    return false;
  }
}

function centreDiv(e)
{
  var left = (getWindowWidth() - getWidth(e)) / 2;
  var top = ((getWindowHeight() - getHeight(e)) / 2) + getScrollHeight() - 50;
  e.style.left = left + "px";
  e.style.top = top + "px";
}

var popup = null;

function showPopup(url, width, height)
{
  var left = (screen.width - width) / 2;
  var top = (screen.height - height) / 2;
  if(popup != null) popup.close();
  popup = window.open(url, "popup", "width=" + width + ",height=" + height + ",screenX=" + left + ",screenY=" + top + ",left=" + left + ",top=" + top + ",toolbar=no,location=no,resize=no,menubar=no,directories=no");
}


function show(id)
{
  var e = getElement(id);
  if(e)
  {
    e.style.display = "block";
  }
}

function hide(id)
{
  var e = getElement(id);
  if(e)
  {
    e.style.display = "none";
  }
}