 window.onload = function(){ 
    SetTab("HOME");
    helpDIV = document.getElementById('helpDIV');
    var helpTimer;
  }

  function SetTab(Item) {
    var ActiveTab = document.getElementById('MAIN_BODY').getAttribute('ActiveTab');
    if (ActiveTab != Item) {
     if (ActiveTab != null) {
        document.getElementById(ActiveTab).className = "MENU_TAB";
        document.getElementById(ActiveTab + '-Left').className = "TLEFT";
        document.getElementById(ActiveTab + '-Right').className = "TRIGHT";
      } 
      ActiveTab = Item;
      document.getElementById(ActiveTab).className = "ACTIVE_MENU_TAB";
      document.getElementById(ActiveTab + '-Left').className = "ACTIVE_TLEFT";
      document.getElementById(ActiveTab + '-Right').className = "ACTIVE_TRIGHT";
      document.getElementById('MAIN_BODY').setAttribute('ActiveTab', ActiveTab);
      GetAJAX(document.getElementById(ActiveTab).getAttribute('TargetURL'), document.getElementById('MAIN_BODY')); 
    } 
  }
  function GetAJAX(URLtext,TARGET) {
    var http = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        http = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
	http.open('GET', URLtext, true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http.onreadystatechange = function() {
		if (http.readyState == 4) {
			TARGET.innerHTML = http.responseText ;
    	}
    }
    http.send(null);
    return false;
  }
  function closeHelp() {
    clearTimeout(helpTimer);
    helpDIV.style.visibility = 'hidden';
  }
  function popHelp(item) {
    helpTimer = window.setTimeout( function() {
      helpDIV.innerHTML = "";
      var http = this;
      // Mozilla/Safari
      if (window.XMLHttpRequest) {
        http = new XMLHttpRequest();
      }
      // IE
      else if (window.ActiveXObject) {
        http = new ActiveXObject("Microsoft.XMLHTTP");
      }
	http.open('GET', item.getAttribute('helpUrl'), true);
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      http.onreadystatechange = function() {
        if (http.readyState == 4) {
	    helpDIV.innerHTML = http.responseText ;
          var epos = getPosition(item);
//          alert(
//'document.height:' + document.body.clientHeight + 
//'\ndocument.body.scrollHeight:' + document.body.scrollTop + 
//'\nwindow.innerHeight:' + window.innerHeight + 
//
//                '\nwindow.pageYOffset:' + window.pageYOffset +
//                '\nmouseY: ' + epos.y + '\nhelpDIV.innerHeight:' + helpDIV.offsetHeight +
//                '\n' + (window.innerHeight - window.pageYOffset) + ' ?< ' + ((epos.y - window.pageYOffset) + helpDIV.offsetHeight));
          if ((document.body.clientHeight  + document.body.scrollTop)  < (epos.y - document.body.scrollTop) + helpDIV.offsetHeight+50) {
            helpDIV.style.top = epos.y - helpDIV.offsetHeight;
            helpDIV.style.left = epos.x + 5;
          } else {
            helpDIV.style.top = epos.y + item.offsetHeight;
            helpDIV.style.left = epos.x + 5;      
          }
          helpDIV.style.visibility = 'visible';
        }
      }
      http.send(null);
    }, 1000);
  }

  var helpDIV;
function getPosition(e){
	var left = 0;
	var top  = 0;
	while (e.offsetParent){
		left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
		top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);
		e     = e.offsetParent;
	}


	left += e.offsetLeft + (e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);
	top  += e.offsetTop  + (e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);

	return {x:left, y:top};

}
Number.prototype.NaN0=function(){return isNaN(this)?0:this;}  
