//-----------------------------------------------------------------------------------------|
//-----------------------------------------------------------------------------------------|
// PURPOSE:                 this file contains objects and static methods for displaying
//							dynamic inline message windows.  It requires 
//-----------------------------------------------------------------------------------------|
//-----------------------------------------------------------------------------------------|

//---Page-level variables
var po_Window = new Window();
var po_Browser = new Browser();

//-----------------------------------------------------------------------------------------|
//---Window class and associated members
function Window() {
	this.DEFAULT_WIDTH = 175;					//---the width of the window if not otherwise specified
	this.MAX_HEIGHT = 350;						//---if the content of the body area excedes this, scroll bars will appear 
	this.DEFAULT_X_OFFSET = 30;					//---the number of pixels on the X axis that the window will appear away from the mouse
	this.DEFAULT_Y_OFFSET = 10;					//---the number of pixels on the Y axis that the window will appear away from the mouse
	this.DEFAULT_Z_INDEX = 500;					//---the default z-index of the window
	this.DEFAULT_WIN_ID = "inlineWin";			//---the default ID of the window div tag
	this.DEFAULT_HEADER_TEXT_ID = "inlineHeaderText";//---the default ID of the window header text div
	this.DEFAULT_BODY_ID = "inlineBody";		//---the default ID of the window body text div
	this.DO_EXPAND = true;						//---whether or not expand animation should be used
	this.EXPAND_GROWTH_SIZE = 30;				//---the number of pixels the window grows per evaluation during expand
	this.EXPAND_GROWTH_TIMING = 10;  			//---the number of milliseconds before re-evaluating the window's size
	this.EXPAND_X = 0;							//---used internally to evaluate the expand
	this.EXPAND_Y = 0;							//---used internally to evaluate the expand
	this.BodyText = "";
	this.HeaderText = "";
	this.X = 0;
	this.Y = 0;
	this.WinEl = GetElement(this.DEFAULT_WIN_ID);
	this.HeaderEl = GetElement(this.DEFAULT_HEADER_TEXT_ID);
	this.BodyEl = GetElement(this.DEFAULT_BODY_ID);
	this.ShimEl = GetElement("inlineShim");
	this.ReClass = changeClasses;	
	this.Show = showObject;
	this.Hide = hideObject;
	this.DragStart = pickup;
	this.Drag = drag;
	this.DragStop = release;	
	this.Expand = expand;	
	this.Broswer = new Browser();
}		

function showObject(ao_evt, as_HeaderText, as_InnerText, ai_Width, style) {
    this.ReClass(style);
	this.BodyEl.style.height = null;
	this.WinEl.style.display = "block";
	this.ShimEl.style.display = "none";
	this.HeaderEl.innerHTML = as_HeaderText;
	if(as_InnerText != ""){
	  var str = as_InnerText;
	  var regex=/&apos;/g;
	  this.BodyEl.innerHTML = str.replace(regex,"'");		
	}
	this.Y = parseInt(po_Window.WinEl.style.top);
	this.X = parseInt(po_Window.WinEl.style.left);
	this.Width = ai_Width ? ai_Width + 'px' : this.DEFAULT_WIDTH + 'px';
	this.WinEl.style.width = po_Window.Width;
	
	this.WinEl.style.top = GetElementTop(ao_evt) + 'px';
	this.WinEl.style.left = GetElementLeft(ao_evt) + 'px';
	
	this.WinEl.style.zIndex = this.DEFAULT_Z_INDEX;
	
	if(this.BodyEl.offsetHeight > this.MAX_HEIGHT) {
		this.BodyEl.style.height = this.MAX_HEIGHT + 'px';
		this.BodyEl.style.overflow = 'auto';		
	} else {
		this.BodyEl.style.height = this.BodyEl.offsetHeight + 'px';
	}
	
	if(this.DO_EXPAND) {
		this.EXPAND_X = 0;
		this.EXPAND_Y = 0;		
		
		this.Expand();
	}
	
    this.ShimEl.style.width = this.WinEl.offsetWidth + 'px';
    this.ShimEl.style.height = this.WinEl.offsetHeight + 'px';
    this.ShimEl.style.top = this.WinEl.style.top;
    this.ShimEl.style.left = this.WinEl.style.left;
    this.ShimEl.style.zIndex = this.WinEl.style.zIndex - 1;
    this.ShimEl.style.display = "block";
}		

function changeClasses(style) {
	style = (!style) ? "defaultInline" : style;
	this.WinEl.className = style;
	document.getElementById("inlineHeader").className = style;
	this.HeaderEl.className = style;
	document.getElementById("inlineHeaderLink").className = style;
}

function hideObject(evt, divId) {
	this.WinEl.style.display = "none";
	this.ShimEl.style.display = "none";
}		

function GetElementTop(ao_evt) {
	var y = 0;
	var ls_WorkingHeight = po_Window.WinEl.offsetHeight < po_Window.MAX_HEIGHT ? po_Window.WinEl.offsetHeight : po_Window.MAX_HEIGHT;

	if((GetMouseY(ao_evt) + parseInt(ls_WorkingHeight)) + (po_Window.DEFAULT_Y_OFFSET * 2) > WindowY()) {
		y =  GetMouseY(ao_evt) - parseInt(ls_WorkingHeight) - po_Window.DEFAULT_Y_OFFSET;
	} else {
		y =  GetMouseY(ao_evt) + po_Window.DEFAULT_Y_OFFSET;
	}
	
	return y > 0 ? y : po_Window.DEFAULT_Y_OFFSET;
}

function GetElementLeft(ao_evt) {
	var x = 0;
	
	if((GetMouseX(ao_evt) + parseInt(po_Window.Width) + (po_Window.DEFAULT_X_OFFSET * 2)) > WindowX())
		x =  GetMouseX(ao_evt) - (parseInt(po_Window.Width) + po_Window.DEFAULT_X_OFFSET);
	else
		x =  GetMouseX(ao_evt) + po_Window.DEFAULT_X_OFFSET;
		
	return x > 0 ? x : po_Window.DEFAULT_X_OFFSET;
}

function expand() {
	var lb_continue = false;
	
	if((parseInt(po_Window.WinEl.clientWidth) + 2 >= po_Window.EXPAND_X) || (parseInt(po_Window.WinEl.clientHeight) + 2 >= po_Window.EXPAND_Y)) { 
		po_Window.WinEl.style.clip = GetClipString(po_Window.EXPAND_X, po_Window.EXPAND_Y);
		po_Window.ShimEl.style.clip = GetClipString(po_Window.EXPAND_X, po_Window.EXPAND_Y);
		
		po_Window.EXPAND_X += po_Window.EXPAND_GROWTH_SIZE;
		po_Window.EXPAND_Y += po_Window.EXPAND_GROWTH_SIZE;
		lb_continue = true;
	}
	
	if(lb_continue) {				
		setTimeout("expand()", this.EXPAND_GROWTH_TIMING);
	} else {			
		po_Window.WinEl.style.clip = "rect(auto, auto, auto, auto)";
		po_Window.ShimEl.style.clip = "rect(auto, auto, auto, auto)";	
	}
}

function GetClipString(ai_x, ai_y) {
	if(parseInt(ai_x) >= po_Window.EXPAND_X)
		ai_x = po_Window.EXPAND_X + 10;
		
	if(parseInt(ai_y) >= po_Window.EXPAND_Y)
		ai_y = po_Window.EXPAND_Y + 10;

	return "rect(0px, " + ai_x + "px, " + ai_y + "px, 0px)";	
}
//---end window class
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---Browser class and associated members
function Browser() {
	var ua, s, i;

	this.isIE = false;
	this.isNS = false;
	this.version = null;

	ua = navigator.userAgent;

	s = "MSIE";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isIE = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Netscape6/";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = parseFloat(ua.substr(i + s.length));
		return;
	}

	s = "Gecko";
	if ((i = ua.indexOf(s)) >= 0) {
		this.isNS = true;
		this.version = 6.1;
		return;
	}
}
//---end Browser class
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---static Window helper methods
function WindowX() {
	if(po_Browser.isIE)
		return document.body.offsetWidth + document.documentElement.scrollLeft + document.body.scrollLeft;
	else
		return window.innerWidth + document.documentElement.scrollLeft + document.body.scrollLeft;		
}

function WindowY() {
	if(po_Browser.isIE)
		return document.body.offsetHeight + document.documentElement.scrollTop + document.body.scrollTop;
	else
		return window.innerHeight + document.documentElement.scrollTop + document.body.scrollTop;				
}

function GetEvent(ao_evt) {
	return window.event ? window.event : ao_evt;
}

function GetElement(as_el) {
	var lo_el = document.getElementById(as_el);
	
	if(!lo_el)
		return null;
		
	if(lo_el.nodeType == 3)
		return lo_el.parentNode;
	else
		return lo_el;
}

function GetMouseX(ao_evt) {
	// Handles the way events are fired (especially when dealing with all CSS layouts)
	var e = GetEvent(ao_evt);
	if (e.pageX) {
		return e.pageX;
	} else if (e.clientX) {
	   return 	e.clientX + (document.documentElement.scrollLeft ?
	   						 document.documentElement.scrollLeft :
	   						 document.body.scrollLeft);
	} else {
		return null;
	}
}

function GetMouseY(ao_evt) {
	// Handles the way events are fired (especially when dealing with all CSS layouts)
	var e = GetEvent(ao_evt);
	if (e.pageY) {
		return e.pageY;
	} else if (e.clientY) {
		return e.clientY + (document.documentElement.scrollTop ?
	   	        		    document.documentElement.scrollTop :
	   						document.body.scrollTop);
	} else {
		return null;
	}
}

function SetOpacity(ao_el, ai_Opacity) {
	ao_el.style.opacity = (ai_Opacity / 100);
   	ao_el.style.MozOpacity = (ai_Opacity / 100);
  	ao_el.style.KhtmlOpacity = (ai_Opacity / 100);
   	ao_el.style.filter = "alpha(opacity=" + ai_Opacity + ")";
}
//---end static Window helper methods
//-----------------------------------------------------------------------------------------|


//-----------------------------------------------------------------------------------------|
//---Static drag-drop members
function pickup(ao_evt) {
	var e = GetEvent(ao_evt);

	po_Window.Y = parseInt(po_Window.WinEl.style.top);
	po_Window.X = parseInt(po_Window.WinEl.style.left);
	po_Window.CursorLeft = GetMouseX(ao_evt);
	po_Window.CursorTop = GetMouseY(ao_evt);
	
	po_Window.WinEl.style.zIndex = po_Window.DEFAULT_Z_INDEX;	
	
	po_Window.OffX = po_Window.CursorLeft - po_Window.X;
	po_Window.OffY = po_Window.CursorTop - po_Window.Y; 
				
	if(po_Browser.isIE) {
		document.attachEvent("onmousemove", drag);
		document.attachEvent("onmouseup", release);
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		document.addEventListener("mousemove", drag, true);
	    document.addEventListener("mouseup", release, true);
	    e.preventDefault();
	}
}

function drag(ao_evt) {
	var e = GetEvent(ao_evt);

	po_Window.CursorLeft = GetMouseX(ao_evt);
	po_Window.CursorTop = GetMouseY(ao_evt);
	
	var y = po_Window.CursorTop - po_Window.OffY;
	var x = po_Window.CursorLeft - po_Window.OffX;
	
	po_Window.WinEl.style.top = y + "px";
	po_Window.WinEl.style.left = x + "px";
	po_Window.ShimEl.style.top = y + "px";
	po_Window.ShimEl.style.left = x + "px";
	
	if(po_Browser.isIE) {
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		e.preventDefault()
	}
}

function release(ao_evt) {
	var e = GetEvent(ao_evt);			
	
	if(po_Browser.isIE) {
		document.detachEvent("onmousemove", drag);
		document.detachEvent("onmouseup", release);	
		e.cancelBubble = true;
		e.returnValue = false;
	} else {
		document.removeEventListener("mousemove", drag, true);
  			document.removeEventListener("mouseup", release, true);
	}
}	
//---end static drag-drop members
//-----------------------------------------------------------------------------------------|