

/*************************************************************************

    dw_event.js
    version date June 2003
    to negotiate cross-browser differences in event models
    for browsers that support addEventListener and attachEvent 
        
    This code is from Dynamic Web Coding 
    at http://www.dyn-web.com/
    See Terms of Use at http://www.dyn-web.com/bus/terms.html
    Permission granted to use this code 
    as long as this entire notice is included.

*************************************************************************/

var dw_event = {

  
  add: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
    else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
  }, 

  remove: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
    else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
  }, 

  DOMit: function(e) {
    e = e? e: window.event;
    e.tgt = e.srcElement? e.srcElement: e.target;
    
    // location of event in document
    if (typeof e.pageX != "number") {
      e.pageX = e.clientX  + document.documentElement.scrollLeft + document.body.scrollLeft;
      e.pageY = e.clientY  + document.documentElement.scrollTop + document.body.scrollTop;
    }
    
    if (!e.preventDefault) e.preventDefault = function () { return false; }
    if (!e.stopPropogation) e.stopPropogation = function () { if (window.event) window.event.cancelBubble = true; }
        
    return e;
  }
  
}





/*************************************************************************



  dw_viewport.js

  version date Nov 2003

  

  This code is from Dynamic Web Coding 

  at http://www.dyn-web.com/

  Copyright 2003 by Sharon Paine 

  See Terms of Use at http://www.dyn-web.com/bus/terms.html

  regarding conditions under which you may use this code.

  This notice must be retained in the code as is!



*************************************************************************/  

  

var viewport = {

  getWinWidth: function () {

    this.width = 0;

    if (window.innerWidth) this.width = window.innerWidth - 18;

    else if (document.documentElement && document.documentElement.clientWidth) 

                this.width = document.documentElement.clientWidth;

    else if (document.body && document.body.clientWidth) 

                this.width = document.body.clientWidth;

  },

  

  getWinHeight: function () {

    this.height = 0;

    if (window.innerHeight) this.height = window.innerHeight - 18;

        else if (document.documentElement && document.documentElement.clientHeight) 

                this.height = document.documentElement.clientHeight;

        else if (document.body && document.body.clientHeight) 

                this.height = document.body.clientHeight;

  },

  

  getScrollX: function () {

    this.scrollX = 0;

        if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;

        else if (document.documentElement && document.documentElement.scrollLeft)

                this.scrollX = document.documentElement.scrollLeft;

        else if (document.body && document.body.scrollLeft) 

                this.scrollX = document.body.scrollLeft; 

        else if (window.scrollX) this.scrollX = window.scrollX;

  },

  

  getScrollY: function () {

    this.scrollY = 0;    

    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;

    else if (document.documentElement && document.documentElement.scrollTop)

                this.scrollY = document.documentElement.scrollTop;

        else if (document.body && document.body.scrollTop) 

                this.scrollY = document.body.scrollTop; 

        else if (window.scrollY) this.scrollY = window.scrollY;

  },

  

  getAll: function () {

    this.getWinWidth(); this.getWinHeight();

    this.getScrollX();  this.getScrollY();

  }

  

}





var position = {

  init : function (sender, tipID) {

     this.sender = sender;

     this.tipID = tipID;

     viewport.getAll();

     this.getSenderTop();

     this.getSenderLeft();

     this.getSenderHeight();

     this.getSenderWidth();

     this.getTipHeight();

     this.getTipWidth();

     this.arrW = 20;

     this.arrH = 90;

     this.tipW = 220;

     if (document.getElementById('new_width')){

         if(document.getElementById('new_width').value == 1) this.tipW = 150;

     }



  },



  compare : function () {

     this.is_hidden_top = (viewport.scrollY>this.SenderY);

     this.is_hidden_bottom = ((this.SenderY+this.SenderH) > (viewport.scrollY+viewport.height));

     if (this.is_hidden_top && this.is_hidden_bottom) this.is_hidden_bottom = false;

     

     this.left_just = false;

     this.right_just = false;

     l_space = this.SenderX - viewport.scrollX; 

     r_space = viewport.width - (this.SenderX + this.SenderW - viewport.scrollX);

     if (l_space>r_space) {

       this.left_just = true

     }else {            

       this.right_just = true

     }



     if (this.is_hidden_top || this.is_hidden_bottom) {

        if (this.is_hidden_top) {

           this.image_name = "up";

           this.arrY = viewport.scrollY + 5;

           this.tipY = viewport.scrollY + 5;

        }

        if (this.is_hidden_bottom) {

           this.image_name = "lower";

           this.arrY = viewport.scrollY + viewport.height - this.arrH;

           this.tipY = viewport.scrollY + viewport.height - this.TipH;

        }

     } else {





          if ((this.SenderH/2 + this.SenderY) < (viewport.height/2 + viewport.scrollY)) {

             this.image_name = "up";

             if ((this.SenderY + this.SenderH/2 - this.TipH/2) < (viewport.scrollY)) {

               this.tipY = viewport.scrollY + 5;

             } else {

               this.tipY = this.SenderY + (this.SenderH/2) - (this.TipH/2);

             }



          } else {

             this.image_name = "lower";

             if ((this.SenderY + this.SenderH/2 + this.TipH/2) > (viewport.scrollY+viewport.height)) {

               this.tipY = viewport.scrollY + viewport.height - this.TipH;

             } else {

               this.tipY = this.SenderY + (this.SenderH/2) - (this.TipH/2);

             }

          }

          this.arrY = this.SenderY + (this.SenderH - this.arrH)/2;

          

          

      }



     if (this.left_just) {

       this.image_name = "spacer.gif";//this.image_name + '-right-combo.gif';

       this.arrX = this.SenderX + 28 - this.arrW;

       this.tipX = this.SenderX + 9 - this.arrW  - this.tipW;

     }

     if (this.right_just) {

       this.image_name = "spacer.gif";//this.image_name + '-left-combo.gif';

       this.arrX = this.SenderX + this.SenderW - 18;

       this.tipX = this.SenderX + this.SenderW  + this.arrW - 9;

     }

     

  },



  compareA : function (x, y) {

     this.left_just = false;

     this.right_just = false;

     l_space = x - viewport.scrollX; 

     r_space = viewport.width - (x - viewport.scrollX);

     if (l_space>r_space) {

       this.left_just = true

     }else {            

       this.right_just = true

     }

     if (y < (viewport.height/2 + viewport.scrollY)) {

             this.image_name = "up";

             if ((y - this.TipH/2) < (viewport.scrollY)) {

               this.tipY = viewport.scrollY + 5;

             } else {

               this.tipY = y - (this.TipH/2);

             }

             this.arrY = this.SenderY +this.SenderH/2 - this.arrH/2 + 15;



          } else {

             this.image_name = "lower";

             if ((y + this.TipH/2) > (viewport.scrollY+viewport.height)) {

               this.tipY = viewport.scrollY + viewport.height - this.TipH;

             } else {

               this.tipY = y - (this.TipH/2);

             }

             this.arrY = this.SenderY + this.SenderH/2 - this.arrH/2 - 20;

          }

     if (this.left_just) {

       this.image_name = "spacer.gif";//this.image_name + '-right-combo.gif';

       this.arrX = x  - this.arrW;

       this.tipX = x + 2 - this.arrW  - this.tipW;

     }

     if (this.right_just) {

       this.image_name = "spacer.gif";//this.image_name + '-left-combo.gif';

       this.arrX = x - 10;

       this.tipX = x - 12 + this.arrW;

     }

  },



  getSenderTop : function (){

     yPos = document.getElementById(this.sender).offsetTop;

     tempEl = document.getElementById(this.sender).offsetParent;

     while (tempEl != null) {

        yPos += tempEl.offsetTop;

        tempEl = tempEl.offsetParent;   

     }
     
     parent_name = this.sender + "parent";
     
     parentEl = null;
     
     eval("   if (typeof("+parent_name+") != 'undefined') { parentEl = document.getElementById("+parent_name+");  }  "); 
     
     if (parentEl){
     
       yPos -=  parentEl.scrollTop;
       
     } 
     
     if (typeof(tip_shift_top) != 'undefined')  yPos -=  tip_shift_top;
     
     this.SenderY = yPos;

  },



  getSenderLeft : function (){

     xPos = document.getElementById(this.sender).offsetLeft;

     tempEl = document.getElementById(this.sender).offsetParent;

       while (tempEl != null) {

        xPos += tempEl.offsetLeft;

        tempEl = tempEl.offsetParent;

      }

      
     if (typeof(tip_shift_left) != 'undefined')  xPos -=  tip_shift_left;  
      
     this.SenderX = xPos;

  },



  getSenderHeight : function (){

    if (document.getElementById(this.sender).height) {

     this.SenderH = document.getElementById(this.sender).height; 

    } else {

      if (document.getElementById(this.sender).offsetHeight) {

       this.SenderH = document.getElementById(this.sender).offsetHeight; 

      } 

    }

  },



  getSenderWidth : function (){

    if (document.getElementById(this.sender).width) {

     this.SenderW = document.getElementById(this.sender).width;

    } else {

      if (document.getElementById(this.sender).offsetWidth) {

       this.SenderW = document.getElementById(this.sender).offsetWidth; 

      } 

    }

  },

  getTipHeight : function (){

     this.TipH = document.getElementById(this.tipID).offsetHeight; 

  },

  getTipWidth : function (){

     this.TipW = document.getElementById(this.tipID).offsetWidth;

  }



}





/*************************************************************************

  dw_tooltip.js   requires: dw_event.js and dw_viewport.js

  version date: May 21, 2005 moved init call to body onload

  (March 14, 2005: minor changes in position algorithm and timer mechanism)

  

  This code is from Dynamic Web Coding at dyn-web.com

  Copyright 2003-5 by Sharon Paine 

  See Terms of Use at www.dyn-web.com/bus/terms.html

  regarding conditions under which you may use this code.

  This notice must be retained in the code as is!

*************************************************************************/



var var_show;
var hideDelay = 10;

var Tooltip = {



             followMouse: false,

             offX: 8,

             offY: 12,

             tipID: "tipDiv",

             arrID: "arrDiv",

             showDelay: 10,

             ready:false,

             timer:null,

             tip:null,

             arr:null,

             list_bool:null,

             list_html:null,

             ttready:true,

             sender:null,

             last_sender:null,



             init:function(){

                if(document.createElement&&document.body&&typeof document.body.appendChild!="undefined"){

                   if(!document.getElementById(this.tipID)){

                      var el1=document.createElement("DIV");

                      el1.id=this.tipID;

                      el1.style.position = "absolute";

                      document.body.appendChild(el1);

                   }

                   if(!document.getElementById(this.arrID)){

                      var el2=document.createElement("DIV");

                      el2.id=this.arrID;

                      el2.style.position = "absolute";

                      document.body.appendChild(el2);

                   }

                   this.ready=true;

                   this.list_bool = new Array();

                   this.list_html = new Array();

                }

             },

             show:function(e,msg){

               if(this.timer){

                   clearTimeout(this.timer);

                   this.timer=0;

                }

                

                if (!this.ttready)  return;

                var sender = document.getElementById(msg);



                if (sender == this.sender) return;



                this.tip=document.getElementById(this.tipID);

                this.arr=document.getElementById(this.arrID);

                this.sender=sender;

                this.sender_id = this.sender.id.substring(0,this.sender.id.indexOf('_'));

                this.last_sender=sender;

                if (this.writeTip(e, msg)) {

                 this.positionTip(e, msg);

                 this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'visible');Tooltip.toggleVis('"+this.arrID+"', 'visible')",this.showDelay);

                } 

             }

             ,writeTip:function(e,msg){

               if (this.sender.tagName == 'A') {

                  viewport.getAll();

                  this.x = e.pageX?e.pageX:e.clientX+viewport.scrollX;

                  this.y = e.pageY?e.pageY:e.clientY+viewport.scrollY;

               }

               this.list_bool[msg.substring(0,msg.indexOf('_'))] = 1;    

               this.list_html[msg.substring(0,msg.indexOf('_'))] = eval("var_"+msg);



               if (this.list_bool[msg.substring(0,msg.indexOf('_'))]) {

                if(this.tip&&typeof this.tip.innerHTML!="undefined")

                  this.tip.innerHTML=this.list_html[msg.substring(0,msg.indexOf('_'))];

                  return true;

               }

             }

             ,positionTip:function(e, msg){

                if(this.tip&&this.tip.style){

                  

                   position.init(msg, this.tipID);

                   if (this.sender.tagName == 'A') {

                     position.compareA(this.x, this.y);

                   } else {

                     position.compare();

                   }

                   this.arr.innerHTML = "<img src='images/" + position.image_name + "'>";

                   this.arr.style.left = position.arrX+"px";

                   this.arr.style.top =  position.arrY+"px";

                   this.tip.style.left = position.tipX +"px";

                   this.tip.style.top =  position.tipY +"px";

                }

             }

             ,hide:function(){



                if(this.timer){

                   clearTimeout(this.timer);

                   this.timer=0;

                }

                this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'hidden'); Tooltip.toggleVis('"+this.arrID+"', 'hidden');",this.hideDelay);

                this.tip=null;

                this.arr=null;

                this.sender=null;

             }

             ,toggleVis:function(id,vis){

                var el=document.getElementById(id);

                if(el)el.style.visibility=vis;

             }

             ,trackMouse:function(e){

                e=dw_event.DOMit(e);

                Tooltip.positionTip(e);

             }

             ,hideImmediately:function(){

                eval("Tooltip.toggleVis('"+Tooltip.tipID+"', 'hidden'); Tooltip.toggleVis('"+Tooltip.arrID+"', 'hidden');");

             }



};



function doTooltip(e, msg) {


  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;


  Tooltip.clearTimer();

  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;

  if ( tip && tip.onmouseout == null ) {

  //      tip.onmouseout = Tooltip.tipOutCheck1;

      tip.onmouseout = hideTip;

      tip.onmouseover = Tooltip.clearTimer;

      tip.onclick = Tooltip.hideImmediately;



  }

  var arr = document.getElementById? document.getElementById(Tooltip.arrID): null;

  if ( arr && arr.onmouseout == null ) {

      //arr.onmouseout = Tooltip.tipOutCheck;

      arr.onmouseout = hideTip;

      arr.onmouseover = Tooltip.clearTimer;

      arr.onclick = Tooltip.hideImmediately;

  }

  Tooltip.show(e, msg);

}

/*

function doTooltip(e, msg) {



  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;

  Tooltip.clearTimer();



  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;

  if ( tip && tip.onmouseout == null ) {

      tip.onmouseout = Tooltip.tipOutCheck;

      tip.onmouseover = Tooltip.clearTimer;

  }

  var arr = document.getElementById? document.getElementById(Tooltip.arrID): null;

  if ( arr && arr.onmouseout == null ) {

      arr.onmouseout = Tooltip.tipOutCheck;

      arr.onmouseover = Tooltip.clearTimer;

  }



  Tooltip.show(e, msg);

}

  */

function hideTip() {

  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;

  Tooltip.timerId = setTimeout("Tooltip.hide()", hideDelay);

}



Tooltip.tipOutCheck = function(e) {

  e = dw_event.DOMit(e);

  // is element moused into contained by tooltip?

  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;

  if (this != toEl && !contained(toEl, this) && Tooltip.sender != toEl) {

    Tooltip.hide(); 

  } else {

//       dw_event.remove(Tooltip.sender)

  }

}



// returns true of oNode is contained by oCont (container)

function contained(oNode, oCont) {

  if (!oNode) return; // in case alt-tab away while hovering (prevent error)

  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;

  return false;

}



Tooltip.timerId = 0;

Tooltip.clearTimer = function() {

  if (Tooltip.timerId) { clearTimeout(Tooltip.timerId); Tooltip.timerId = 0; }

}



Tooltip.unHookHover = function () {

    var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;

    if (tip) {

        tip.onmouseover = null; 

        tip.onmouseout = null;

        tip = null;

    }

}

if (var_show){

    dw_event.add(window, "unload", Tooltip.unHookHover, true);

}




