/*******************************************************************************
*
* © 2008 Copyright A-Vision
*
* File description :       Notification / tool-tip functions
* 
* Created by       :       Arnold Velzel
* Created on       :       15/12/2008
*
* Last changed by  :       Arnold Velzel
* Last changed on  :       <LastChanged>
* 
*******************************************************************************/

function notify( obj, e)
{
 if ( !obj.getAttribute('notification')) return;
 if ( obj.noteObject) return;
 if ( !e) e=window.event;

 nColor = obj.getAttribute('notificationcolor');
 if ( !nColor) nColor="#ffc";

 var forceWidth = false;
 nWidth = obj.getAttribute('notificationwidth');
 if ( !nWidth) {
  nWidth=200;
 } else {
  forceWidth = true;
 }

 div = document.createElement( 'DIV');
 div.sourceObject = obj;
 div.id = "notify_"+Math.random();
 div.style.position = "absolute";
// t = eval( objectY( obj) + obj.offsetHeight + 10);
 t = eval( mouseY(e) + 20); // Use mouse related positioning rather than object related
 div.style.top = t+"px";
// l = eval( objectX( obj) + 15);
 l = eval( mouseX(e) + 20); // Use mouse related positioning rather than object related
 div.style.left = l+"px";
 div.style.padding = "3px";
 div.style.border = "1px solid navy";
 div.style.backgroundColor = nColor;
 div.style.fontSize = "12px";
 div.style.fontFamily = "sans-serif";
 div.style.zIndex = 9999;
 div.style.opacity = 0.9;
 div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=90)";
 div.innerHTML = obj.getAttribute('notification');
 div.setAttribute('notificationbox',true);
 document.body.appendChild( div);

 if ( forceWidth || ( div.offsetWidth > nWidth)) {
  if ( isNum(nWidth)) nWidth = eval(nWidth)+"px";
  div.style.width = nWidth;
 }
 var appSize = new Array( document.body.offsetWidth, document.body.offsetHeight);
 if ( typeof(applicationSize)=="function") appSize = applicationSize();
 if (div.offsetLeft+div.offsetWidth>appSize[0]) {
  l = eval( mouseX() - div.offsetWidth - 20);
  div.style.left = l+"px";
//  div.style.left = eval(document.body.offsetWidth-div.offsetWidth-10)+"px";
 }
 if (div.offsetTop+div.offsetHeight>appSize[1]) {
  t = eval( mouseY() - div.offsetHeight - 20);
  div.style.top = t+"px";
//  div.style.top = eval(document.body.offsetHeight-div.offsetHeight-10)+"px";
 }

 obj.noteObject = div;
 obj.onmouseout = function() {
  if ( this.noteObject) {
   try {
    document.body.removeChild( this.noteObject);
   }
   catch (e) {
   }
   this.noteObject = null;
  }
 }

}

function removenotifies()
{
 divs = document.getElementsByTagName('DIV');
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notificationbox')) {
   document.body.removeChild( divs[i]);
  }
 }
}

function setnotifications( blk)
{
 if (blk && (typeof(blk)=="object")) {
  divs = blk.getElementsByTagName('*');
 } else {
  divs = document.getElementsByTagName('*');
 }
 for (var i=0;i<divs.length;i++) {
  if ( divs[i].getAttribute('notification')) {
 	 divs[i].onmouseover = function(e) {
 	  notify( this, e);
 	 }
 	 divs[i].onmouseoout = function(e) {
 	  removenotifies(e);
 	 }
  }
 }
}

