// JavaScript Document

var x,y;
var oldx,oldy;
var newx,newy;
var entDrag;

var isDragging;

function include(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	
	head.appendChild(script)
}

//include('/ehr/include/js/CalendarPopup.js');

function mouse(event) {
	var changey,changex, curx,cury;
	
	if (event.pageX || event.pageY) 	{
		x = event.pageX;
		y = event.pageY;
	}
	else if (event.clientX || event.clientY) 	{
		x = event.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		y = event.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	if (isDragging) {
		changey = entDrag.offsetTop + (y-oldy);
		changex = entDrag.offsetLeft + (x-oldx);
		entDrag.style.left = changex+"px";
		entDrag.style.top = changey+"px";
		oldy=y;
		oldx=x;
	} 
	
}

function turnHintOn(event, ent, msg, width, height) {
	if (!isDragging) {
		oldx = x;
		oldy = y;
		isDragging = true;
		entDrag = ent;
		newy = parseInt(y)+10;
		newx = parseInt(x)-(width/2);
		entDrag.style.top = newy + "px";
		entDrag.style.left = newx + "px";
		entDrag.style.width = width + "px";
		entDrag.style.height = height + "px";
		entDrag.innerHTML = '<div id="helpinner">' + msg + '</div>';
		showEnt(ent);	
	} else {
		if (entDrag == ent) { turnHintOff(ent); }
	}
}

function turnHintOff(ent) {
	if ((isDragging) && (ent == entDrag)) {	
		isDragging = false;
		hideEnt(entDrag);
		entDrag = null;
	} 
}

function turnDragOn(event, ent) {
	if (!isDragging) {
		oldx = x;
		oldy = y;
		isDragging = true;
		entDrag = ent;
		ent.style.cursor = 'move';
	}
}

function turnDragOff() {
	isDragging = false;
	entDrag.style.cursor = 'cursor';
	entDrag = null;
}

function hideEnt(ent) {
	ent.style.display = 'none';
}

function showEnt(ent) {
	ent.style.display = 'block';
}

function entity(n, d) { //v4.01
					  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
						d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
					  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
					  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
					  if(!x && d.getElementById) x=d.getElementById(n); return x;
					}
					
					
function changeimage(ent,filename) { ent.src= filename; }
function changeclass(ent, classname) { ent.className = classname; }
function callbackManualReturn(ent) {
	ent.innerHTML = r['callback'][ent.id].responseText;
}

function accordClick(ent,root) {
	if (ent.parentNode.className == root) {
		changeclass(ent.parentNode,root + "on");
	} else {
		changeclass(ent.parentNode,root);
	}
	
}
			
function resetAllPop() {
			hideEnt(entity('menu'));
			hideEnt(entity('search'));
			return false;
		}
		
function goPreviousElement(ent,ct) {
	for(var i=0; i<ct; i++) {
		ent = ent.parentElement;
	}
	return ent;
}

function destroyEnt(ent) {
	document.body.removeChild(ent);
}

function createWhiteoutDiv() {
			ent = entity('whiteoutDIV');
			if (!ent) {
				nent = document.createElement('div');
				nent.style.position = 'absolute';
				nent.style.top = 0; 
				nent.style.left = 0;
				nent.style.overflow = 'hidden';
				nent.style.display = 'none';
				nent.id = 'whiteoutDIV';
				document.body.appendChild(nent);
				ent = entity(nent.id);
			}
   
			 return ent;
		}
		
		function setWhiteOutSize(ent) {
			if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {        
				var pageWidth = document.body.scrollWidth+'px';        
				var pageHeight = document.body.scrollHeight+'px';    
			} else if( document.body.offsetWidth ) {      
				var pageWidth = document.body.offsetWidth+'px';      
				var pageHeight = document.body.offsetHeight+'px';    
			} else {       
				var pageWidth='100%';       
				var pageHeight='100%';    
			}
			 ent.style.width= pageWidth;    
			 ent.style.height= pageHeight; 
		}
		
		function setWhiteOutOp(ent,op) {
			 ent.style.opacity=op;                          
			 ent.style.MozOpacity=op;                       
			 ent.style.filter='alpha(opacity='+op+')';     
			 ent.style.zIndex=50;            
			 ent.style.backgroundColor='#FFFFFF';      
		}
		
		function doWhiteOut(op) {  
			ent = createWhiteoutDiv();
			setWhiteOutSize(ent);
			setWhiteOutOp(ent,op);
			showEnt(ent);
		}
		
		function undoWhiteOut() {
			ent = createWhiteoutDiv();
			hideEnt(ent);
		}


