 var kmcs = {
   getPageOffsetLeft : function (obj) {
     if(obj.offsetParent && obj.offsetParent.tagName && obj.offsetParent.tagName != 'BODY') {
       return(obj.offsetLeft + kmcs.getPageOffsetLeft(obj.offsetParent));
     } else {
       return(obj.offsetLeft);
     }
   },
   getPageOffsetTop : function (obj) {
     if(obj.offsetParent && obj.offsetParent.tagName && obj.offsetParent.tagName != 'BODY') {
       return(obj.offsetTop + kmcs.getPageOffsetTop(obj.offsetParent));
     } else {
       return(obj.offsetTop);
     }
   },
   popupDropDown : function (obj, id) {
     var popupBox = document.getElementById(id);
     if(!popupBox) {
       //error object not found
       return;
     }
     popupBox.style.display = 'block';
     popupBox.style.width = obj.offsetWidth - (document.all ? 0 : 2);
     popupBox.style.left = kmcs.getPageOffsetLeft(obj);
     popupBox.style.top = kmcs.getPageOffsetTop(obj) + obj.offsetHeight;
     if(popupBox.offsetHeight > 200) {
       popupBox.style.overflow = 'auto';
       popupBox.style.height = '200px';
     }
     
     popupBox.onmouseover = function() {
       popupBox.style.display = 'block';
     };
     popupBox.onmouseout = function() {
       popupBox.style.display = 'none';
     };
     obj.onmouseout = function() {
       popupBox.style.display = 'none';
     };
   },
   activeDropDownMenu : false,
   activeDropDownMenuTimeout : false,
   showDropDownMenu : function(obj, id) {
     var popupBox = document.getElementById(id);
     if(!popupBox) {
       //error object not found
       return;
     }
     
     //popupBox.style.visibility = 'hidden';
     //popupBox.style.display = 'block';
     var width = popupBox.getElementsByTagName('table').item(0).offsetWidth;
     if(width < (obj.offsetWidth + 16)) {
       width = obj.offsetWidth + 16;
       popupBox.getElementsByTagName('table').item(0).style.width = width + 'px';
     }
     popupBox.style.width = width;
     popupBox.style.left = kmcs.getPageOffsetLeft(obj) - 8;
     popupBox.style.top = kmcs.getPageOffsetTop(obj) + obj.offsetHeight - 2;
     popupBox._slideOut = false;
     popupBox._timeoutActive = true;

     if(!kmcs.activeDropDownMenu) {
       popupBox._timeout = setTimeout(function() {
         $("#" + id).fadeIn("normal");
         $("#" + id).slideDown("normal");
         popupBox._timeoutActive = false;
         kmcs.activeDropDownMenu = true;
       }, 1000);
     } else {
         if(kmcs.activeDropDownMenuTimeout) {
           clearTimeout(kmcs.activeDropDownMenuTimeout);
         }
         $("#" + id).fadeIn("normal");
         $("#" + id).slideDown("normal");
         popupBox._timeoutActive = false;
     }
     popupBox.onmouseover = function(e) {
       popupBox.style.display = 'block';
       popupBox._slideOut = false;
     };
     popupBox.onmouseout = function(e) {
       popupBox._slideOut = true;
       setTimeout(function() {
         if(popupBox._slideOut) {
           $("#" + id).slideUp("fast");
           $("#" + id).fadeOut("fast");
           kmcs.activeDropDownMenuTimeout = setTimeout(function(e) {
             kmcs.activeDropDownMenu = false;
           }, 1000);
         }
       }, 10);
     };
     obj.onmouseout = function(e) {
       if(popupBox._timeoutActive) {
         clearTimeout(popupBox._timeout);
       } 
       popupBox._slideOut = true;
       setTimeout(function() {
         if(popupBox._slideOut) {
           $("#" + id).slideUp("fast");
           $("#" + id).fadeOut("fast");
           kmcs.activeDropDownMenuTimeout = setTimeout(function(e) {
             kmcs.activeDropDownMenu = false;
           }, 1000);
         }
       }, 10);
      
     }
   }
 };
