//requires ajax.js

var helpID=null;
var contentDiv=null;
var helpEnabled=true;
var httpHelp = getHTTPObject();

function helpOver(id,wWidth,wType,imageUrl){

idDb=id; 
d = new Date();
t = d.getTime();
id=t+id;

if(helpEnabled==true){
createWindow(id,idDb,wType,imageUrl);
}

helpID=id;

}

var mousex = 0;
var mousey = 0;



function init(){
  document.onmousemove = update; // update(event) implied on NS, update(null) implied on IE
  update();
}

function getMouseXY(e){ 
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      mousex = e.pageX;
      mousey = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      mousex = e.clientX + document.body.scrollLeft;
      mousey = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }
}

function update(e){
getMouseXY(e); // NS is passing (event), while IE is passing (null)
if(document.getElementById(helpID)){
document.getElementById(helpID).style.top =mousey-10+'px';
document.getElementById(helpID).style.left = mousex+10+'px';
}
}


function createWindow(divId,idDb,wType,imageUrl){

update(); //ensure starting pos is correct

newWindow=document.createElement('div');
newWindow.id=divId;
newWindow.className='windowShell';

content=document.createElement('div');
content.className='windowContent';

urlVar="?id="+idDb;
contentDiv=content;
document.body.appendChild(newWindow);

newWindow.appendChild(content);

if(wType=="image"){
content.style.margin='0px';	
contentDiv.innerHTML=imageUrl;
}else{
getContent(urlVar)
}

}

function receiveContent() {
if (httpHelp.readyState == 4){
data= httpHelp.responseText;
contentDiv.innerHTML=data;
init();
}

}


function getContent(variables){
	httpHelp.open("GET", '/lib/scripts/javascript/help.html'+variables, true);
  	httpHelp.onreadystatechange = receiveContent; 
	httpHelp.send(null);

}

function helpOut(id){
var del = document.getElementById(id);
del.parentNode.removeChild(del);
}


