if (!JS_CrossBrowser_API)
{

var JS_CrossBrowser_API=true;
  
// TODO:
// Bubbling issue in IE5 Mac
// Image Loader?
// Outlook-style menu?
// Tabs
// Item collection

var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE55 = IE5 = (IE4 && document.getElementById) ? true : false;
var IE6 = (IE55&&(document.parentNode==null))?true:false;
var NS6 = (document.getElementById && !IE4) ? true : false;
var handCursor=(NS6)?'pointer':'hand';
var stylePrefix=(NS6||IE4||IE5)?'style.':'';
var showMenuTO=0;
var menuTO=0;

var menuStack=new Array();
var sysFeatures=new Array();

var origX, origY, moving=null;

var months=[['Jan', 'January'], ['Feb','February'], ['Mar','March'],
            ['Apr','April'], ['May','May'], ['Jun','June'],
            ['Jul','July'], ['Aug','August'], ['Sep','September'],
            ['Oct','October'], ['Nov','November'], ['Dec','December']];

var   days=[['Sun','Sunday'], ['Mon', 'Monday'], ['Tue','Tuesday'], ['Wed','Wednesday'],
            ['Thr','Thursday'], ['Fri','Friday'], ['Sat','Saturday']];

// IE5+ browsers have issues with some object methods
// Load fixes for these methods if IE5+
if (IE5) document.write('<script src="/descotestw/desco_website/desky/scripts/IE5_Fixes.js"><\/script>');

String.prototype.right = function(len)
{
  return this.substr(this.length-len,len);
}

String.prototype.left = function(len)
{
  return this.substr(0,len);
}

function addFeature(feat,func,desc)
{
  sysFeatures[sysFeatures.length]=new Array(3);
  sysFeatures[sysFeatures.length-1][0]=feat;
  sysFeatures[sysFeatures.length-1][1]=func;
  sysFeatures[sysFeatures.length-1][2]=desc;
  return sysFeatures.length;
}

function explainFeature(feat)
{
  for (var i=0; i<sysFeatures.length; i++)
    if (sysFeatures[i][0]==feat)
      return (sysFeatures[i][2])?sysFeatures[i][2]:'';
  return '';
}

function runFeature(feat)
{
  for (var i=0; i<sysFeatures.length; i++)
    if (sysFeatures[i][0]==feat)
      return eval(sysFeatures[i][1]);
}

function notValid(testElem)
{
  return typeof testElem=="undefined";
}

function getObject(obj)
{
	if (IE4)
	{
		return document.all(obj);
	}

	if (NS4)
	{
		return document.layers(obj);
	}

	return document.getElementById(obj);
}

function srcObject(e)
{
	if (IE4 || IE5)
	{
		return e.srcElement;
	}

	if (NS4 || NS6)
	{
		if (e.target.nodeType) return (e.target.nodeType==3)?e.target.parentNode:e.target;
        return e.target;
	}
}

function eventKeyCode(e)
{
	if (IE4 || IE5)
	{
		return e.keyCode;
	}

	if (NS4 || NS6)
	{
        return e.which;
	}
}

function preloadImage(url)
{
	var img=new Image();
	img.src=url;
}

function documentX(e)
{
  if (IE4 || IE5)
    return e.clientX+document.body.scrollLeft;
  else if (NS4 || NS6)
    return e.pageX;
}

function documentY(e)
{
  if (IE4 || IE5)
    return e.clientY+document.body.scrollTop;
  else if (NS4 || NS6)
    return e.pageY;
}

function pageTop()
{
  if (IE4 || IE5)
    return document.body.scrollTop;
  else if (NS4 || NS6)
    return window.pageYOffset;
}

function pageLeft()
{
  if (IE4 || IE5)
    return document.body.scrollLeft;
  else if (NS4 || NS6)
    return window.pageXOffset;
}

function pageBottom()
{
  if (IE4 || IE5)
    return document.body.scrollTop+document.body.clientHeight;
  else if (NS4 || NS6)
    return window.pageYOffset+window.innerHeight;
}

function pageRight()
{
  if (IE4 || IE5)
    return document.body.scrollLeft+document.body.clientWidth;
  else if (NS4 || NS6)
    return window.pageXOffset+window.innerWidth;
}

function pageWidth()
{
  if (IE4 || IE5)
    return document.body.clientWidth;
  else if (NS4 || NS6)
    return window.innerWidth;
}

function pageHeight()
{
  if (IE4 || IE5)
    return document.body.clientHeight;
  else if (NS4 || NS6)
    return window.innerHeight;
}

function leftCoord(obj)
{
  var result=obj.offsetLeft;
  while (obj.offsetParent!=document.getElementsByTagName("BODY").item(0))
  {
    result+=obj.offsetParent.offsetLeft;
    obj=obj.offsetParent;
  }
  return result;
}

function topCoord(obj)
{
  var result=obj.offsetTop;
  while (obj.offsetParent!=document.getElementsByTagName("BODY").item(0))
  {
    result+=obj.offsetParent.offsetTop;
    obj=obj.offsetParent;
  }
  return result;
}

function withinClass(obj,name)
{
  var o=obj;
  while (o!=document&&o!=null)
  {
    if (o.className==name) return o;
    o=(IE6||NS6)?o.parentNode:o.parentElement;
  }
  return null;
}

function withinId(obj,name)
{
  var o=obj;
  while (o!=document&&o!=null)
  {
    if (o.getAttribute("id")==name) return o;
    o=(IE6||NS6)?o.parentNode:o.parentElement;
  }
  return null;
}

function withinTag(obj,name)
{
  var o=obj;
  while (o!=document&&o!=null)
  {
    if (o.tagName==name) return o;
    o=(IE6||NS6)?o.parentNode:o.parentElement;
  }
  return null;
}

function withinAttribute(obj,name)
{
  var o=obj;
  while (o!=document&&o!=null)
  {
    if (o.getAttribute(name)) return o;    
    o=(IE6||NS6)?o.parentNode:o.parentElement;
  }
  return null;
}

function parentAttribute(obj,name)
{
  var o=obj;
  while (o!=document&&o!=null)
  {
    if (o.getAttribute(name)) return o.getAttribute(name);    
    o=(IE6||NS6)?o.parentNode:o.parentElement;
  }
  return false;
}

function showInfo(obj,x,y)
{
  with (getObject(obj))
  {
    style.zIndex=1000000+menuStack.length; 
    if (style.display!='block') style.display='block';
    if (y+20+offsetHeight>=pageBottom()) 
      style.top=y-offsetHeight-5;
    else
      style.top=y+20;

    if (x+10+offsetWidth>=pageRight())
      style.left=x-offsetWidth-5;
    else
      style.left=x+10;
  }
}

function hideMenu(top)
{
  top=(!top)?'':top;

  while ((menuStack.length>0)&&(menuStack[menuStack.length-1]!=top))
  {
    eval('getObject("'+menuStack.pop()+'").style.display="none";');
  }

}

function showMenu(sub,obj,x,y,w,h)
{
  w=(!w)?0:w;
  h=(!h)?0:h;

  clearTimeout(menuTO);

  if (!sub)
    hideMenu();

  menuStack.push(obj);

  with (getObject(obj))
  {
    var t=getElementsByTagName('SPAN');
    for (var i=0; i<t.length; i++)
    {
      if (t[i].className=='menuItem_hilite') t[i].className='menuItem';
      if (!getAttribute('noImages'))
        if (t[i].getAttribute("useMenu"))
          t[i].innerHTML='<IMG SRC="/desco_website/images/childMenu.gif" STYLE="height:16; width:10; float: right;">'+t[i].innerHTML;
    }
    setAttribute('noImages',true);
    style.zIndex=1000000+menuStack.length-1;
    if (style.display!='block') style.display='block';
    if (y+h+offsetHeight>=pageBottom()) 
      style.top=(!sub)?y-offsetHeight:y-offsetHeight+h;
    else
      style.top=(!sub)?y+h:y;

    if (x+offsetWidth>=pageRight())
      style.left=(!sub)?x+5-offsetWidth:x-offsetWidth;
    else
      style.left=(!sub)?x:x+w;
  }
}

function formatDate(fmt,dateObj)
{
  /*
     day   - full day name (Monday)
     dy    - short day name (Mon)
     month - full month (January)
     mon   - short month (Jan)
     mn    - numeric month (01)
     dd    - numeric date (05)
     yr    - short numeric year (02)
     year  - full numeric year (2002)
     hh    - hours
     mm    - minutes
     ss    - seconds
     ms    - milliseconds
     ampm  - am or pm
     AMPM  - AM or PM
     not having ampm or AMPM will display 24-hour time
  */
  fmt=fmt?fmt:'day, month dd, year hh:mm:ss AMPM';
  var now=dateObj?dateObj:new Date();
  var ampm='';
  var hr=now.getHours();
  if (fmt.indexOf('ampm')>-1) ampm=(hr<12)?'am':'pm';
  if (fmt.indexOf('AMPM')>-1) ampm=(hr<12)?'AM':'PM';
  if (ampm.length==2) hr=(hr<12)?hr:hr-12;
  hr=hr?hr:12;
  fmt=fmt.replace(/dy/g,days[now.getDay()][0]);
  fmt=fmt.replace(/day/g,days[now.getDay()][1]);
  fmt=fmt.replace(/month/g,months[now.getMonth()][1]);
  fmt=fmt.replace(/mon/g,months[now.getMonth()][0]);
  fmt=fmt.replace(/mn/g,('0'+(now.getMonth()+1)).right(2));
  fmt=fmt.replace(/dd/g,('0'+(now.getDate())).right(2));
  fmt=fmt.replace(/year/g,now.getFullYear());
  fmt=fmt.replace(/yr/g,now.getFullYear().toString().right(2));
  fmt=fmt.replace(/hh/g,('0'+(hr)).right(2));
  fmt=fmt.replace(/mm/g,('0'+(now.getMinutes())).right(2));
  fmt=fmt.replace(/ss/g,('0'+(now.getSeconds())).right(2));
  fmt=fmt.replace(/ms/g,('00'+(now.getMilliseconds())).right(3));
  fmt=fmt.replace(/ampm/ig,ampm);
  return fmt;
}

function startMove(e)
{
  moving=withinClass(srcObject(e),'moveable');
  origX=e.screenX;
  origY=e.screenY;
  if (IE5) moving.setCapture();
}

function doMove(e)
{
  with (moving)
  {
    if (leftCoord(moving)+(e.screenX-origX)>=0)
    {
      style.left=leftCoord(moving)+(e.screenX-origX);
      origX=e.screenX;
    }
    else
    {
      origX=origX-leftCoord(moving);
      style.left=0;
    }
    if (topCoord(moving)+(e.screenY-origY)>=0)
    {
      style.top=topCoord(moving)+(e.screenY-origY);
      origY=e.screenY;
    }
    else
    {
      origY=origY-topCoord(moving);
      style.top=0;
    }
  }
}

function stopMove(e)
{
  with (moving)
    if (IE5) moving.releaseCapture();
  moving=null;
}

function GlobalMouseOver(e)
{
    if (moving) return false;

    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    // If expando property is present, do something with it.
    if (srcObject(e).getAttribute('replaceWith'))
      with (srcObject(e))
      {
        if (getAttribute('src')) src=getAttribute('replaceWith');
        else if (!innerHTML) value=getAttribute('replaceWith');
             else {
                   if (IE4||IE5) innerText=getAttribute('replaceWith');
                   else if (NS4||NS6) e.target.data=getAttribute('replaceWith');
                  }
      }

    var o=null;

    if (o=withinClass(srcObject(e),'sideNav'))
      with (o)
      {
        className="sideNav_hilite";
        style.cursor=handCursor;
      }
    if (o=withinClass(srcObject(e),'menu'))
      with (o)
      {
        className="menu_hilite";
        style.cursor='default';
      }
    if (o=withinClass(srcObject(e),'menuItem'))
      with (o)
      {
        className="menuItem_hilite";
        style.cursor='default';
        hideMenu(parentAttribute(o,'id'));
      }

    if ((o=withinAttribute(srcObject(e),'useMenu'))&&!withinClass(srcObject(e),'menuItem_hilite'))
      with (o) showMenuTO=setTimeout("showMenu(0,'"+parentAttribute(srcObject(e),'useMenu')+"', "+leftCoord(o)+", "+topCoord(o)+", "+offsetWidth+", "+offsetHeight+");",300); 

    else if (parentAttribute(srcObject(e),'useMenu')&&(o=withinClass(srcObject(e),'menuItem_hilite')))
      with (o) showMenu(1,parentAttribute(srcObject(e),'useMenu'), leftCoord(o), topCoord(o), offsetWidth, offsetHeight); 

    if (!withinClass(srcObject(e),'menuBox')&&!withinClass(srcObject(e),'menu_hilite')&&!withinAttribute(srcObject(e),'useMenu'))
    {
      clearTimeout(menuTO);
      menuTO=setTimeout('hideMenu()',1000);
    }
    else if (parentAttribute(srcObject(e),'useMenu'))
         {
           clearTimeout(menuTO);
           hideMenu(parentAttribute(srcObject(e),'useMenu'));
         }
         else if (o=withinClass(srcObject(e),'menuBox'))
              {
                clearTimeout(menuTO);
                hideMenu(parentAttribute(o,'id'));
              }

    if (parentAttribute(srcObject(e),'systemFeature'))
    {
      srcObject(e).style.cursor=handCursor;
      window.status=explainFeature(parentAttribute(srcObject(e),'systemFeature'));
    }

    if (parentAttribute(srcObject(e),'useInfo')) showInfo(parentAttribute(srcObject(e),'useInfo'), documentX(e), documentY(e));
}

function GlobalMouseOut(e)
{
    if (moving) return false;

    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    // If expando property is present, do something with it.
    if (parentAttribute(srcObject(e),'systemFeature')) window.status='';

    if (srcObject(e).getAttribute('original'))
      with (srcObject(e))
        if (getAttribute('src')) src=getAttribute('original');
        else if (!innerHTML) value=getAttribute('original');
             else {
                   if (IE4||IE5) innerText=getAttribute('original');
                   else e.target.data=getAttribute('original');
                  }

    var o=null; 
    if (o=withinClass(srcObject(e),'sideNav_hilite')) o.className="sideNav";
    if (o=withinClass(srcObject(e),'menu_hilite')) o.className="menu";
    if (o=withinClass(srcObject(e),'menuItem_hilite')) o.className="menuItem";

    if (parentAttribute(srcObject(e),'useInfo')) getObject(parentAttribute(srcObject(e),'useInfo')).style.display='none';
    if (showMenuTO) clearTimeout(showMenuTO);
}

function GlobalMouseDown(e)
{
    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    // If expando property is present, do something with it.
    if (withinClass(srcObject(e),'moveable')) startMove(e);
}

function GlobalMouseMove(e)
{
    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    // If expando property is present, do something with it.

    if (moving) {doMove(e); return false;}

    if (withinClass(srcObject(e),'menuBox')
        ||withinAttribute(srcObject(e),'useMenu')
        ||withinClass(srcObject(e),'menu_hilite')) clearTimeout(menuTO);
    if (parentAttribute(srcObject(e),'useInfo')) showInfo(parentAttribute(srcObject(e),'useInfo'), documentX(e), documentY(e));

    if (parentAttribute(srcObject(e),'systemFeature')) withinAttribute(srcObject(e),'systemFeature').style.cursor=handCursor;
}

function GlobalMouseUp(e)
{
    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    var o=null;
    // If expando property is present, do something with it.
    if (moving) {stopMove(e);return false;}
}

function GlobalClick(e)
{
    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    if (!withinClass(srcObject(e),'menu_hilite'))
    {
      GlobalMouseOut(e);
      if (!withinClass(srcObject(e),'menuBox') || parentAttribute(srcObject(e),'systemFeature')) hideMenu();
    }

    // If expando property is present, do something with it.
    if (parentAttribute(srcObject(e),'systemFeature'))
      runFeature(parentAttribute(srcObject(e),'systemFeature'));

    var o=null;
    if (o=withinClass(srcObject(e),'menu_hilite')) GlobalMouseOver(e);
}

function GlobalKeyDown(e)
{
    // IE doesn't send the event object, get it manually!
    if (!e) e=event;

    var key=(IE4?e.keyCode:(NS4?e.which:0));

    // If expando property is present, do something with it.
    if (key==13 && parentAttribute(srcObject(e),'systemFeature'))
      runFeature(parentAttribute(srcObject(e),'systemFeature'));

    var o=null;
    if (o=withinClass(srcObject(e),'menu_hilite')) GlobalMouseOver(e);
}

  // Use Event Bubbling to assign one function to handle all objects
  document.onmouseover=GlobalMouseOver;
  document.onmouseout=GlobalMouseOut;
  document.onmousedown=GlobalMouseDown;
  document.onmousemove=GlobalMouseMove;
  document.onmouseup=GlobalMouseUp;
  document.onclick=GlobalClick;
  document.onkeydown=GlobalKeyDown;
  window.status='';
  document.expando=true;
}