

// =========== used by FrontEndMenu =======================
function expand(s)
{
	var td, d;
	td = s;
	d = td.getElementsByTagName("div").item(0);
	td.className = "menuHover";
	d.className = "menuHover";
}
function collapse(s)
{
	var td, d;
	td = s;
	d = td.getElementsByTagName("div").item(0);
	td.className = "menuNormal";
	d.className = "menuNormal";
}
// ========================================================



openWindow = function (url, windowName, windowAttributes, errorMessage)
{
	var handle, myURL;
	if (!errorMessage)
	{
		errorMessage = "";
	}

	handle = window.open(url, windowName, windowAttributes);
	myURL = escape(url);
	
	return handle;
};


function doClose(w)
{
	if (w)
	{
		if (w.closed && w.closed === false && w.close)
		{
			w.close();
		}
		else
		{
			var topWindow = w.top;
			if (topWindow.handleClose)
			{
				topWindow.handleClose();
			}
			else
			{
				topWindow.close();
			}
		}
	}
}

function getCookie(name)
{ 
	var pos, token, tnlen, cklen, i, j;
	token = name + "=";
	tnlen = token.length;
	cklen = document.cookie.length;
	i = 0;
	
	while (i < cklen)
	{ 
		j = i + tnlen;
		if (document.cookie.substring(i, j) === token)
		{ 
			pos = document.cookie.indexOf(";", j);
			if (pos === -1)
			{
				pos = document.cookie.length;
			}
			return unescape(document.cookie.substring(j, pos));
		}

		i = document.cookie.indexOf(" ", i) + 1;
		if (i === 0)
		{
			break;
		}
	} //End While
	
	return null;
}

function setCookie(name, value, expires, path, domain)
{ 
	// set time, it's in milliseconds
	var today, expires_date;
	
	today = new Date();
	today.setTime(today.getTime());

	if (expires)
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	expires_date = new Date(today.getTime() + (expires));
	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString():"") +
		((path) ? ";path=" + path:"") + 
		((domain) ? ";domain=" + domain:"");
}

function deleteCookie(name)
{ 
	var cval = getCookie(name);
	document.cookie = name + "=" + "" + "; expires=Wednesday, 09-Nov-99 23:12:40 GMT";
}

function isIE()
{
	var dom, ie4, ie5, ie6, ie7;
	dom = (document.getElementById) ? true : false;
	ie4 = (document.all && !dom) ? true : false;
	ie5 = ((navigator.userAgent.indexOf("MSIE") > -1) && dom) ? true : false;
	ie6 = (navigator.userAgent.indexOf("MSIE 6.0") > -1) ? true : false;
	ie7 = (navigator.userAgent.indexOf("MSIE 7.0") > -1) ? true : false;

	return (ie5 || ie4 || ie6 || ie7);
}

function isNetscape()
{
	var dom, ns5, ns4;
	dom = (document.getElementById) ? true : false;
	ns5 = ((navigator.userAgent.indexOf("Gecko") > -1) && dom) ? true: false;
	ns4 = (document.layers && !dom) ? true : false;

	return (ns5 || ns4);
}


function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

positionMe = function (dEle)
{
	var divWidth, divHeight, documentWidth, 
		documentHeight, currentLeft, currentTop;
	
	dEle = $(dEle);
	divWidth = dEle.offsetWidth;
	divHeight = dEle.offsetHeight;
	documentWidth = document.body.clientWidth;
	documentHeight = document.body.clientHeight;

	//this will hopefully be the top left
	currentLeft = parseInt(dEle.style.left, 10);
	currentTop =  parseInt(dEle.style.top, 10);

	//make sure it fits on the right
	if (currentLeft + divWidth >= documentWidth + document.body.scrollLeft)
	{
		//make top left scoot over the width of the div
		currentLeft = (documentWidth + document.body.scrollLeft) - divWidth;
	}

	if (currentLeft < 0)
	{
		currentLeft = 0;
	}
		
	//make sure it fits the bottom
	if (currentTop + divHeight >= documentHeight + document.body.scrollTop)
	{
		currentTop = (documentHeight + document.body.scrollTop) - divHeight;
	}
	
	if (currentTop < 0)
	{
		currentTop = 0;
	}

	if (currentTop && currentTop > 0)
	{
		dEle.style.top = parseInt(currentTop, 10);
	}

	if (currentLeft && currentLeft > 0)
	{
		dEle.style.left = parseInt(currentLeft, 10);	
	}
};

doDynamicDiv = function (cEle, url, params, w, h, title, onloadedfcn)
{

	var myWidth, myHeight, maxZ, elePos, sr, divParams;
	try
	{
		Maple.dynaCurrentEle = cEle; 
		document.body.style.cursor = "wait";
		Maple.dynaCurrentEle.style.cursor = "wait";
		
		Maple.theDiv = $("myDynamicDivcreate");
		if (Maple.theDiv)
		{
			Maple.theDiv.style.display = 'none';
		}
	
		document.onmousemove = mouseMove1;
		document.onmouseup = mouseUp;
		myWidth = parseInt(w, 10);
		if (!myWidth)
		{
			myWidth = 375;
		}
		myHeight = parseInt(h, 10);
		if (!myHeight)
		{
			myHeight = 500;
		}
		if (!title)
		{
			title = "";
		}
	
		if (!Maple.theDiv) 
		{
			Maple.theDiv = new Element("DIV", {id: 'myDynamicDivcreate'});
			Maple.theDiv.setStyle("width:" + String(myWidth + 15) + 
				"px;display:block; position:absolute;z-index:4;overflow:auto;display:none");
		}
	
		maxZ = 0;
		$$("div").each(function (e, i) {
				var z = e.getStyle("z-index");
				if (z && (!isNaN(z)) && Number(z) > maxZ) {
					maxZ = z;
				}
			});
			
	    
		Maple.theDiv.setStyle("z-index:" + (maxZ + 5));
		 
		//initialize position next to element	
		elePos = getPosition(Maple.dynaCurrentEle);
		Maple.theDiv.setStyle("top:" + elePos.y + ";left:" + (elePos.x + Maple.dynaCurrentEle.offsetWidth + 5) + ";");
		
		divParams = "w=" + w + "&h=" + myHeight + "&_dyn_url=" + encodeURIComponent(url) + "&t=" + title;
		if (params && params.length > 0)
			params += "&" + divParams;
		else
			params = divParams;
	
		//make sure it attaches to something
		//alert('parentNode=' + Maple.dynaCurrentEle.parentNode.nodeName);
		
		try
		{
			$(Maple.dynaCurrentEle.parentNode).insert(Maple.theDiv);
		}
		catch (e)
		{
			$('main').insert(Maple.theDiv);
		}

		if (onloadedfcn)
		{
			Maple.theDiv.outerOnloadedfcn = onloadedfcn;
		}
		else
		{
			Maple.theDiv.outerOnloadedfcn = null;
		}

		sr = new SimpleRequest(Maple.theDiv, "/pub/dynamicWindow.jsp", "post",  params, Maple.dynaCompleteFunction);
	
		//set helper functions
		Maple.theDiv.hideClose = function () {
				$("imageDiv").style.display = "none";
			};
		Maple.theDiv.setNonMoveable = function () {
				$("moveableDiv").id = "";
				document.onmousemove = null;
				document.onmouseup = null;
			};
		Maple.theDiv.getContentDiv = function () {
				return $("contentSubDiv");
			};
	}
	catch (ex)
	{
		document.body.style.cursor = "";
		Maple.dynaCurrentEle.style.cursor = "";
		Maple.theDiv = null;
	}
	return Maple.theDiv;
};

doCloseDynamicDiv = function ()
{
	//close the window (hide)
	if ($('myDynamicDivcreate'))
	{
		$('myDynamicDivcreate').style.display = 'none';
	}
	//don't need to listen for mouse events anymore
	document.onmousemove = null;
	document.onmouseup   = null;
};


/* handles moving the mouse anywhere on the document. */

mouseUp = function (ev)
{
	Maple.dragObject = null;
};


makeDraggable = function (item) {
	if (!item)
	{
		return;
	}
	item.onmousedown = function (ev) {
		Maple.dragObject  = this.parentNode.parentNode;
		Maple.mouseOffset = getMouseOffset(Maple.dragObject, ev);
		return false;
	};
};

makeExistingDivDraggable = function (item) {
	if (!item)
	{
		return;
	}
	document.onmousemove = mouseMove1;
	document.onmouseup   = mouseUp;

	item.onmousedown = function (ev) {
		Maple.dragObject  = this.parentNode;
		Maple.mouseOffset = getMouseOffset(Maple.dragObject, ev);
		return false;
	};
};

mouseMove1 = function (ev)
{
	ev           = ev || window.event;
	var mousePos = mouseCoords(ev);
	
	if (Maple.dragObject)
	{
		Maple.dragObject.style.position = 'absolute';
		Maple.dragObject.style.top      = mousePos.y - Maple.mouseOffset.y;
		Maple.dragObject.style.left     = mousePos.x - Maple.mouseOffset.x;
		return false;
	}
	
};


getMouseOffset = function (target, ev)
{
	var docPos, mousePos;
	ev = ev || window.event;
	
	docPos    = getPosition(target);
	mousePos  = mouseCoords(ev);
	return {x: mousePos.x - docPos.x, y: mousePos.y - docPos.y};
};

getPosition  = function (e) {
	var top, left;
	
	left = 0;
	top  = 0;

	try
	{
		while (e.offsetParent) {
			left += e.offsetLeft;
			top  += e.offsetTop;
			e     = e.offsetParent;
		}
	}
	catch (ex)
	{
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return {x: left, y: top, left: left, top: top};
};

getDimensions  = function (e) {
	var height, width;

	width = 0;
	height  = 0;

	try
	{
		while (e.offsetParent) {
			width += e.offsetWidth;
			height  += e.offsetHeight;
			e     = e.offsetParent;
		}
	}
	catch (ex)
	{
	}

	width += e.offsetWidth;
	height  += e.offsetHeight;

	return {w: width, h: height, width: width, height: height};
};


mouseCoords = function (ev)
{
	if (ev.pageX || ev.pageY) {
		return {x: ev.pageX, y: ev.pageY};
	}
	return {
		x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y: ev.clientY + document.body.scrollTop  - document.body.clientTop
	};
};


function findPos(obj) {
	var pos = {left: 0, top: 0};
	if ($(obj))
	{
		pos = $(obj).cumulativeOffset();
	}
	return pos;
}


/*
* deprecated use Maple.setHaze()
*/
setHaze = function (eleObj, hideLoading)
{
	Maple.setHaze(eleObj, hideLoading);
};

clearHaze = function (eleObj)
{
	Maple.clearHaze(eleObj);
};

function validateHTML(obj, minimum)
{
	var sr;
	if (obj)
	{
		Maple.valDiv = $("validateDiv");
		if (!Maple.valDiv) 
		{
			Maple.valDiv = new Element("div", {id: "validateDiv"});
			Maple.valDiv.setStyle("display:none; position:absolute;z-index:4");
			$(obj.parentNode).insert(Maple.valDiv);
		}
	
		sr = new SimpleRequest("validateDiv", '/adm/validateHTML.jsp', 'post', 'text=' + escape(obj.value) + '&min=' + minimum + '&t=' + new Date().getTime());
	}
}

showUserInfo = function (userId, ele, w, h, title, t, l)
{
	if ((!title) || title === "")
	{
		title = "Contact Information";
	}

	if ((!w) || w === "")
	{
		w = 450;
	}
	
	if ((!h) || h === "")
	{
		h = 200;
	}

	if(window['DynamicDivWindow'])
	{
		new DynamicDivWindow(
		{title:'Contact Information',type:'url',positionType:'center',
			width:w,height:h,params:'userId='+userId,
			top:t, left:l,
			url:'/pub/user/contactInfo.htm',method:'get'}
		);
	}	
};

/**
 * 
 * @param {Object} cd
 * @param {Object} tc
 * @param {Object} rt
 * @param {Object} ele
 * @param {Object} w
 * @param {Object} h
 * @param {Object} title
 * @param {Object} pos
 * @param {Object} bShowXtra - shows detailElementXtra (extra media content for course)
 * @param (Object) onBeforeCloseFn - function that gets called on closing this div
 */
showDescription = function (cd, tc, rt, ele, w, h, title, pos, bShowXtra, onBeforeCloseFn)
{
	var url, params, tName;
	
	if ((!title) || title === "")
	{
		title = "Details";
	}
	
	
	
	if ((!w) || w === "")
	{
		w = "500";
	}
	else
	{
		if(!isNaN(w))
			w=w+"px";
	}
	
	if ((!h) || h === "")
	{	
		h = "600";
	}	
	else
	{
		if(!isNaN(h))
			h=h+"px";
	}
		
	if((!pos) || pos == "")
	{
		pos = "center";
	}
	
	
	tName = 'details.htm';
	if(bShowXtra && bShowXtra == true)
	{
		tName = 'detailsXtra.htm';
	}
	
	url = "/pub/cms/" + escape(cd) + "/" + escape(tc) + "/" + escape(rt) + "/" + tName;
	params = "inline=1&d=" + new Date().getTime();

	//alert('our p=' + pos);
	
  	new DynamicDivWindow({modal:'true',
		style:'block', title:title, onBeforeClose:onBeforeCloseFn,
		width:w,height:h,positionType:pos,
		params:params,url:url,method:'post'});

};

showEmailFriend = function (ele, courseId, w, h, title)
{
	var url, params, d;

	if ((!title) || title === "")
	{
		title = "Email Friend";
	}
		
	if ((!w) || w === "")
	{
		w = 450;
	}
	else
	{
		if(!isNaN(w))
			w=w+"px";
	}
	
	if ((!h) || h === "")
	{
		h = 300;
	}
	else
	{
		if(!isNaN(h))
			h=h+"px";
	}		
		
	url = "/pub/displayEmailFriend.htm";
	params = "inline=1&ruleId=" + courseId;

  	new DynamicDivWindow({modal:'true',
		style:'block', title:title,
		width:w,height:h,positionType:'center',
		params:params,url:url,method:'post'});
};

toggle_div = function (obj, id)
{
	var e = $(id);
	if (e.style.display === "none")
	{
		obj.src = '/images/expand.gif';
		obj.title = 'Click to hide details';
		e.style.display = "block";
	}
	else
	{
		obj.src = '/images/collapse.gif';
		obj.title = 'Click to show details';
		e.style.display = "none";
	}
};


function toggleImage(id)
{ 
	var item;
	if ((item = $(id + 'A'))) 
	{
		if (item.title === "Expand") 
		{
			item.innerText = ' - ';
			item.title = "Collapse";
		}
		else 
		{
			item.innerText = ' + ';
			item.title = "Expand";
		}
	}
}

function toggleButton(id)
{ 
	var item, outerItem;
	if ((item = $(id + 'B'))) 
	{
		outerItem = $(id);
		if (outerItem.style.visibility ===  "visible") 
		{
			item.value = "Hide";
		}
		else 
		{
			item.value = "Show";
		}
	}
}

function toggle(id)
{
	var state, item;
  	
	if (document.getElementById && ((item = document.getElementById(id)))) 
	{
		if (item.style.visibility === "visible") 
		{
			item.style.position = "absolute";
			item.style.visibility = "hidden";
			state = 0;
		} 
		else 
		{
			item.style.position = "relative";
			item.style.visibility = "visible";		 
			state = 1;
		}
		toggleImage(id);
		toggleButton(id);
	}
}




/*  Maple javascript functions
*
*/
if (!window.Maple) {
	window.Maple = {theDiv: null,
						 canHaveCookies: false};
}

/**
	Checks for inputs, select, and text area with a name, but no id attribute
	and sets the id = name
*/
Maple.checkInputIdAttribs = function ()
{
	var ilist, i;
	
	ilist = $$("input","select","textarea");
	
	for (i = 0; i < ilist.length; i += 1)
	{
		if (!ilist[i].id)
		{
			ilist[i].id = ilist[i].name;
		}
	}
};

Maple.cookiesEnabled = function (v)
{
	if (!Maple.canHaveCookies)
	{
		setCookie("a", "b", 100, "/");
		var b = getCookie("a");
		if (b === "b")
		{
			Maple.canHaveCookies = true;
		}
	}
	
	return Maple.canHaveCookies;
};

Maple.dynaCompleteFunction = function ()
{
	var params;
	
	//allow for the dragging of the window
	makeDraggable($("moveableDiv"));
	params = params + "&t=" + new Date().getTime();

	//show it		
	Maple.theDiv.style.position = "absolute";
	Maple.theDiv.style.display = "block";
	
	//position the final window - after it is shown
	positionMe(Maple.theDiv);
	
	//reset the cursor
	document.body.style.cursor = "";
	Maple.dynaCurrentEle.style.cursor = "";
	
	if (Maple.theDiv.outerOnloadedfcn)
	{
		Maple.theDiv.outerOnloadedfcn();
	}
};


//cycles through all forms and elements to disable/enable combo boxs.  Mainly used
//because of IE6 while using "haze" to disable screen
Maple.resetComboBoxs = function (bReadOnly)
{
	var f, eles, i, k;
	
	f = document.forms;
	for (k = 0; k < f.length; k += 1)
	{
		eles = f[k].elements;
		for (i = 0; i < eles.length; i += 1)
		{
			if (f[k].elements[i] && (f[k].elements[i].type === "select" ||  f[k].elements[i].type === "select-one"))
			{
//				f[k].elements[i].readOnly = bReadOnly;
			}
		}
	}
};



/*
*	getScreenDimension - returns the inner size of window - browser independent
*	returns {width:w,height:h}
*
*	Example:  alert(Maple.getScreenDimension().width + " by " + Maple.getScreenDimension().height);
*/
Maple.mapletag = "mapleJS";

Maple.getScreenDimension = function ()
{
	var retval, myWidth, myHeight;
	
	retval = {};
	myWidth = 0;
	myHeight = 0;
	
	if (typeof(window.innerWidth) === 'number') {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	retval.width = myWidth;
	retval.height = myHeight;
	  
	return retval;
};

Maple.makeBigScreen = function()
{
var dim  = Maple.getScreenDimension();
if((screen.availHeight - dim.height  > (screen.availHeight * .30)) ||
	screen.availWidth - dim.width  > (screen.availWidth * .1))
{
		var topLeft = {left:screen.availLeft,top:screen.availTop};
		if(! topLeft.left)
		{
			topLeft.left = 0;
		}
		else if (! topLeft.top)
		{
			topLeft.top = 1;
		}
		if(! topLeft.top)
		{
			topLeft.top =0;
		}
		try
		{
		window.moveTo(topLeft.left,topLeft.top);
		}
		catch(e) { }
		try
		{
			window.resizeTo(screen.width,screen.height);
		}
		catch(e) {;}
} 

};

Maple.getTopZIndex = function()
{
	var maxZ = 0;
	$$("div").each(function (e,i) {var z = e.getStyle("z-index") ;
				if(z && isNaN(z) == false && Number(z) > maxZ) { maxZ = z;};});
	
	var newZ = Number(maxZ);
	if(isNaN(newZ))
	{
		newZ = 0;
	}	

	return (newZ + 1);
};

/**
*	getScrollPosXY(ele) - returns the scroll offset of the ele - browser independent
*	if ele is null, then it returns the scroll position of the window.
*	0,0 is the top left of the element.
*	returns {x,y} {left,top} also work.
*
*	Example:  alert(Maple.getScrollPosXY().x + ", " + Maple.getScrollPosXY().y);
*			   
*
**/
Maple.getScrollPosXY = function (theEle) {
	var scrOfX, scrOfY, obj, docObj;
	scrOfX = 0;
	scrOfY = 0;
	obj = window;
	docObj = document.body;
	
	if (theEle)
   	{
		obj = theEle;
		docObj = theEle;
	}
  	else if (this !== window.Maple)
 	{
		obj = this;
		docObj = this;
	}
	if (typeof(obj.pageYOffset) === 'number') {
	    //Netscape compliant
	    scrOfY = obj.pageYOffset;
	    scrOfX = obj.pageXOffset;
	} else if (docObj && (docObj.scrollLeft || docObj.scrollTop || docObj.nodeType === 1)) {
	    //DOM compliant
	    scrOfY = docObj.scrollTop;
	    scrOfX = docObj.scrollLeft;
	} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	}
	return {x: scrOfX, y: scrOfY, left: scrOfX, top: scrOfY};
};


/**
*  This method will start resizing the passed in element to be the largest
size it can be without scrolling the window.

For this to work it must be:
	1. a sizable element (e.g. div)
	2. a child of 'main'
	
	Some inner elements such as tables need to be sized as well on the resize. any div that has the
class 'resizable' will be set to the max size less the scroll bar dimensions.

To turn off this feature call Maple.disablePageSizer(ele)
	
*
*/

Maple.enablePageSizer = function (ele)
{
	if (!ele)
	{
		if ($('main'))
		{
			ele = $('main').childElements().find(function (e) {
					return true;
				});
		}
	}
	ele = $(ele);
	if (ele && ele.parentNode && ele.parentNode.id === 'main')
	{
		if (!ele.maple_resizeHandler)
		{
			ele.maple_resizeHandler = Maple.eleResizerFunction.bind(ele);
			Event.observe(window, "resize", ele.maple_resizeHandler);
			Event.observe(document, "resize", ele.maple_resizeHandler);
			Event.observe(document, "click", ele.maple_resizeHandler);
			Event.observe(window.document.body, "maple:resize", ele.maple_resizeHandler);
			var rsizables = ele.select(".resizable");
			if((!rsizables) || (rsizables.length <= 0))
			{
				ele.setStyle({overflow:'auto'});
			}
			ele.maple_resizeHandler();
		}
	}
};


Maple.disablePageSizer = function (ele)
	{
		ele = $(ele);
		if (ele && ele.maple_resizeHandler)
		{
			try
			{
				Event.stopObserving(window, "resize", ele.maple_resizeHandler);
			}
			catch (ex)
			{
				;
			}
			Event.stopObserving(document, "resize", ele.resizeHandler);
			Event.stopObserving(document, "click", ele.resizeHandler);
			Event.stopObserving(window.document.body, "maple:resize", ele.resizeHandler);
			ele.maple_resizeHandler = null;
			ele.setStyle("height:auto");
			ele.select(".resizable").each(function (e, i)
				{
					if (e.nodeName !== "SCRIPT")
					{
						e.setStyle("height:auto");
					}
				});
		}
	};


Maple.sizeme = function ()
{
	Event.fire(window.document.body, "maple:resize");
};

/**
* This function will stretch the bound element to be the maximum height that
*  will not cause scrolling.
**/
Maple.eleResizerFunction = function (event)
{
	var screen, bH, wrap, otherH, ele, pH, pHi;
 	
	ele = this;
	if (ele === window || !ele.nodeName || ele.mapletag)
	{
		if (document.body && $(document.body).down("div#main"))
		{
			ele = $(document.body).down("div#main").childElements().find(function (e) {
					return true;
				});
		}
		
	}
	if (!ele) {
		return;
	}

	screen = Maple.getScreenDimension();
	bH = screen.height;
	wrap = $(document.body).down("div#wrap");
	otherH = Number(0);
	wrap.childElements().each(function (e, i)
		{
			if (e.id !== 'main' && e.nodeName !== "SCRIPT" && $(e).visible())
			{
				otherH += e.getHeight();
			}
		});

	$(ele).siblings().each(function (e, i)
		{
			if ($(e).visible() && e.nodeName !== "SCRIPT" && e.getStyle("z-index") === ele.getStyle("z-index"))
			{
				otherH += e.getHeight(); 
			}
		});

	pH = Number(bH);
	pH = pH - otherH;
	pH = pH - 40;

	if (this.lastMapleSize !== pH && pH > 0)
	{
		this.lastMapleSize = pH;
		this.setStyle({height: pH + "px"});
		this.select("div.resizable").each(function (e, i)
			{
				if (e.nodeName !== "SCRIPT")
				{
					pHi = pH - 20;
					e.setStyle({height: pHi + "px"});
				}
			});
	}
};

Maple.removeFromHazeList = function(eleObj)
{

  hazeId = '_hze_' + $(eleObj).identify();
  
  if (Maple.hazeList)
  {
	if (Maple.hazeList[hazeId])
	{
	  // alert('removing hazeId: ' + hazeId);
	   Maple.hazeList[hazeId] = null;
	}
  }
}

/**
 * 
 * @param {Object} eleObj
 * @param {Object} hideLoading
 * @param {Object} modalHaze
 * @param {Object} loadTxt    : this text displays in the loading haze
 * @return {TypeName} 
 */
Maple.setHaze = function (eleObj, hideLoading, modalHaze, loadTxt)
{
	var ele, hazeId, hazer, dim, maxZ, newZ;
	ele = $(eleObj);
	hazeId = '_hze_' + $(ele).identify();

	if (!Maple.hazeList)
	{
		Maple.hazeList = {};
	}
	hazer = Maple.hazeList[hazeId];
	if (!hazer)
	{
	
	    //alert('inserting new hazerId: ' + hazeId);
	    
	    
		hazer = new Element("div", {id: hazeId});
		if(!modalHaze)
		{
			Maple.hazeList[hazeId] = hazer;
		}
		if($(ele.parentNode))
			$(ele.parentNode).insert(hazer);
		else
			$(ele).insert(hazer);
	}
	else
	{
	  //alert('already have hazeId: ' + hazeId);
	}
	
	dim = ele.getDimensions();
	hazer.style.position = "absolute";
	try
	{
		// try catch is for protecting against <html> in IE being included
		// in the position calculation.
		hazer.clonePosition(ele);
	}
	catch(ex)
	{
	
	}
	maxZ = 0;
	$$("div").each(function (e, i) {
			var z = e.getStyle("z-index");
			if (z && (!isNaN(z)) && Number(z) > maxZ) {
				maxZ = z;
			}
		});
	
	newZ = Number(maxZ);
	if (isNaN(newZ))
	{
		newZ = 0;
	}	
	newZ += 10;
	hazer.style.zIndex = newZ;
	hp = hazer.down("div.loadingHaze");	
	if (!hp)
	{
		hp = new Element("div");
		hp.addClassName("loadingHaze");
		hazer.appendChild(hp);
	}

	if (!hideLoading)
	{
		ld = hp.down("div");	
		if (!ld)
		{
			ld = new Element("div");
			ld.id = 'loadingInfoMain';

			spanTxt = new Element("span");
			spanTxt.style.fontSize = '12';
			spanTxt.style.fontWeight = 'bold';
			
			
			
			if(!loadTxt || loadTxt == null)
			{
				
				spanTxt.update('Loading...');
			}
			else
			{
				spanTxt.update(loadTxt);
			}
			
			
			imageDiv = new Element("div");
			imageDiv.id = 'loadingImage';	
			
			if(isIE())
			{	
				 imageDiv.style.height = '16px';
				 imageDiv.style.width = '16px';
			}
			else
			{
				imageDiv.style.padding = "0 16px 0 0";
			}
			
			
			image2 = new Element("img");
			image2.style.height = dim.height + "px";
			image2.style.width = '0';
			image2.style.verticalAlign = 'middle';	
			
			ld.appendChild(imageDiv);
			ld.appendChild(spanTxt);
			ld.appendChild(image2);
			
			hp.appendChild(ld);
		}
	}
	hazer.show();
	hazer.style.cursor = "wait";
	
	return hazer;
};

Maple.clearHaze = function (eleObj)
{
	var ele, hazeId, hazer;
	
	ele = $(eleObj);
	hazeId = '_hze_' + ele.id;
	if (Maple.hazeList)
	{
		hazer = Maple.hazeList[hazeId];
		if (hazer)
		{
			hazer.style.cursor = "default";

			hazer.hide();
		}
	}
};
Maple.removeTinyMCEEditors = function(parentEle)
    {
    	if($(parentEle) && $(parentEle).select && window['tinyMCE'])
    	{
		   	$(parentEle).select("TEXTAREA", "DIV").each(function(ele,i)
		   	{
				if(ele.id )
				{
					var eleID = ele.id;
					var eleIdEditor = window['tinyMCE'].get(eleID);
					if(eleIdEditor)
					{
						eleIdEditor.remove();
					} 
				} 
			})
		}
   };

Maple.showUserInfoEx = function(targ,userId, ele, w, h, title)
{
	showUserInfo(userId, ele, w, h, title, targ.offsetTop, targ.offsetLeft);
}

Maple.hasJVM = function()
{
	if(window.navigator && navigator.javaEnabled() )
	{
		return true;
	}
	else
	{
		return false;
	}
};

Maple.isIE = function(ver)
{
	var dom, ie4, ie5, ie6, ie7;
	dom = (document.getElementById) ? true : false;
	ie4 = (document.all && !dom) ? true : false;
	ie5 = ((navigator.userAgent.indexOf("MSIE") > -1) && dom) ? true : false;
	ie6 = (navigator.userAgent.indexOf("MSIE 6.0") > -1) ? true : false;
	ie7 = (navigator.userAgent.indexOf("MSIE 7.0") > -1) ? true : false;
     
	if(ver == "6")
		return ie6;
	else	
		return (ie5 || ie4 || ie6 || ie7);
};


Maple.openReceipt = function(obj, receiptIds, w, h, _title)
{
	if (!_title || _title === "")
	{
		_title = "Receipt Information";
	}
	w = w?parseInt(w):600;
	h = h?parseInt(h):400;
	
	p = receiptIds + '&isIE=' + isIE();
	new DynamicDivWindow(
		{title: _title,modal:'true',type:'url',positionType:'center',
		width:w+'px',height:h+'px',params: p,
		url:'/pub/user/viewReceipt.jsp',method:'post'});
};

if (window.Class && (!window.MapleTools))
{
	MapleTools = Class.create({
		error: function (msg)
		{
			if (window.console)
			{
				console.error(msg);
			} else {
				alert(msg);
			}
		},
		debug: function (msg)
		{
			if (window.console) {
				console.debug(msg);
			}
			else if (top && top.console)
			{
				top.console.debug(msg);
			}
		}
	});
}

if (window.Draggable)
{
/*
*  adds the option mapleScrolloffset  which will take into account the 
*	scroll position of the container when starting to drag.
*	see /pub/support/mapleDraggableSample.html

*/
	window.MapleDraggable = Class.create(Draggable, {
    	initDrag: function (event) {
			var src, pointer, pos;

			if (!Object.isUndefined(Draggable._dragging[this.element]) &&
		    	Draggable._dragging[this.element])
		    {
				return;
		    }
		    
		    if (Event.isLeftClick(event)) {
			    // abort on form elements, fixes a Firefox issue
			    src = Event.element(event);
			    if ((tag_name = src.tagName.toUpperCase()) && (
			      tag_name === 'INPUT' ||
			      tag_name === 'SELECT' ||
			      tag_name === 'OPTION' ||
			      tag_name === 'BUTTON' ||
			      tag_name === 'TEXTAREA'))
			      {
					return;
				}
		
			    pointer = [Event.pointerX(event), Event.pointerY(event)];
			    pos     = Position.cumulativeOffset(this.element);
		    	if (this.options.mapleScrolloffset) {
		    		if (!Prototype.Browser.IE)
		    		{
						pos[0] -= Maple.getScrollPosXY(this.element.parentNode).x;
						pos[1] -= Maple.getScrollPosXY(this.element.parentNode).y;
					}
				}
		
				this.offset = [0, 1].map(function (i) {
						return (pointer[i] - pos[i]);
					});
		    	Draggables.activate(this);
		    	Event.stop(event);
			}
		}
	});
}

/**
 * Meant to display context sensitive help.  
 * 	hoverObj - the item hovering over to display help (this item should have onMouseOver = to this function
 * 	contentObj - a hidden item holding the text to display
 *  params - any addition params needed 
 */
Maple.contextHelp = function(hoverObj, contentObj, params) 
{  
	var ttPrefix = "d";
	//make them prototype friendly
	hoverObj=$(hoverObj);
	contentObj = $(contentObj);
	//see if the element already exists
	var toolTipBox = $(ttPrefix+contentObj.identify());
	if(toolTipBox == null)
	{
		toolTipBox = new Element("div", {"class":"contextHelp",id:ttPrefix+contentObj.identify()}).update(contentObj.innerHTML);
		toolTipBox = $(toolTipBox);
		toolTipBox.setStyle({position:"absolute", zIndex:"9999999"});

		hoverObj.insert({ before: toolTipBox});
	}
	
	toolTipBox.show();
	window.onscroll = function (evt)
	{
		var ev=arguments[0]?arguments[0]:event;
		var x=ev.clientX;
		var y=ev.clientY;
		diffX=5;
		diffY=-40;
		$(toolTipBox).style.top  = y-2+diffY+document.body.scrollTop+ "px";
		$(toolTipBox).style.left = x-2+diffX+document.body.scrollLeft+"px";
	};
	
	hoverObj.onmousemove=window.onscroll;
	hoverObj.onmouseout= function (evt)
	{
		$(toolTipBox).hide();
	};
}

formBusy = function (flag)
{
	var ele = $("main");
	
	if (ele)
	{
		Maple.resetComboBoxs(flag);
		if (flag)
		{
			Maple.setHaze(ele);
		}
		else
		{
			Maple.clearHaze(ele);
		}
	}
};

