








//holds all responses
var response = new Array();

/*
This file is used to make an ajax call to the given url.

Upon success, the function given in _functionName will be called. If an error 
occurs, the function _functionName<error code> will be attempted.  If that function
does not exist, then the function given by _functionName will be called with
the error code as the third parameter.

Parameters for a 'GET' can be passed via '_url', '_params', or both in the XMLRequest
constructor.

Example:
function getSomething(text, doc, errorCode)
{
	document.getElementById('divTag').innerHTML = text;
}
function doSomething()
{
	x = new XMLRequest('/doSomething.jsp?t=' + new Date().getTime(), 'GET', '', 'id', 'getSomething', true);
	x.process();
}
function doSomething404()
{
	alert('ajax call failed with a 404');
}
*/


//Constructor
function XMLRequest(_url, _method, _params, _id, _functionName, _async)
{
	//variables
	this.xmlhttp;
	this._requestId = _id;
	
	//the url to call
	this.URL = _url;
	//method of call 'GET' or 'POST'
	this.method = _method;
	//parameters for call - appended for GET but mainly used for POST
	var time = new Date().getTime();
	this.params = _params

	//is this call asynchronous
	this.async = _async;
	
	if(this.async == null)
		this.async = false;

	if(this.method.toLowerCase() == "get")
	{
		//append the params for a get if they were not appended to the URL already
		if((this.URL.indexOf("?") < 0) && (this.params != null) && (this.params != "") && (this.method.toUpperCase() == "GET"))
		{
			this.URL += ("?"+this.params + "&t=" + time);
		}
		else if((this.URL.indexOf("?") > 0) && (this.params != null) && (this.params != "") && (this.method.toUpperCase() == "GET"))
		{
			this.URL += ("&"+this.params + "&t=" + time);
		}
		else
		{
			if(this.URL.indexOf("?") < 0) {
				 this.URL += "?";
			} else {
				 this.URL += "&";
			}
			this.URL += ("t=" + time);
		}
	}
	else if(this.method.toLowerCase() == "post")
	{
		//see if params were sent on url and take them off
		var idx = this.URL.indexOf("?");
		if(idx >= 0)
			this.params = this.URL.substring(idx+1);
	}
	
	this.responseHandler = _handleAjaxResponse;
	this.handleResponse = new Function("response['"+_id+"'].responseHandler();");
	
	if(_functionName != null)
	{
		//create handlers
		var  doResponse= "if(window."+_functionName+" == null){;}else{window."+_functionName+"(this.onResponse.arguments[0], this.onResponse.arguments[1], this.onResponse.arguments[2], this.onResponse.arguments[3])}";
		var  do404= "if(window."+_functionName+"404 == null){window."+_functionName+"(this.on404.arguments[0], this.on404.arguments[1], this.on404.arguments[2], this.on404.arguments[3]);}else{window."+_functionName+"404(this.on404.arguments[0], this.on404.arguments[1], this.on404.arguments[2], this.on404.arguments[3])}";
		var  do500= "if(window."+_functionName+"500 == null){window."+_functionName+"(this.on500.arguments[0], this.on500.arguments[1], this.on500.arguments[2], this.on500.arguments[3]);}else{window."+_functionName+"500(this.on500.arguments[0], this.on500.arguments[1], this.on500.arguments[2], this.on500.arguments[3])}";
		var  do505= "if(window."+_functionName+"505 == null){window."+_functionName+"(this.on505.arguments[0], this.on505.arguments[1], this.on505.arguments[2], this.on505.arguments[3]);}else{window."+_functionName+"505(this.on505.arguments[0], this.on505.arguments[1], this.on505.arguments[2], this.on505.arguments[3])}";

		this.onResponse = new Function(doResponse);
		this.on404 = new Function(do404);
		this.on500 = new Function(do500);
		this.on505 = new Function(do505);
	}
	else
		this.onResponse= new Function("");

	response[_id] = this;
	
	//functions
	this.process = processMe;
		
	//getters
	this.getMethod = getMyMethod;
	this.getURL = getMyURL;
	this.getParameters = getMyParameters;

	try 
	{
		if(typeof XMLHttpRequest != 'undefined')
		{
			   this.xmlhttp = new XMLHttpRequest();
		 }
		 else
		 {
		 	try
		 	{
		     this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (e) {
	          this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}		 
		 }
	}
	catch (e) 
	{
	   // browser doesn't support ajax. handle however you want
	   alert(e.description );
	}

	this.xmlhttp.onreadystatechange = this.handleResponse;
}

function _isIE()
{
	var dom = (document.getElementById) ? true : false;
	var ie4 = (document.all && !dom) ? true : false;
	var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
	var ie6 = (navigator.userAgent.indexOf("MSIE 6.0")>-1) ? true : false;
	var ie7 = (navigator.userAgent.indexOf("MSIE 7.0")>-1) ? true : false;

	return (ie5 || ie4 || ie6 || ie7);
}

function _handleAjaxResponse()
{
	if(this.xmlhttp.readyState == 4)
	{
		if(this.xmlhttp.status == 200)
  		{
  			this.onResponse(this.xmlhttp.responseText,this.xmlhttp.responseXML,this.xmlhttp.status, this._requestId);
  		}
		else if(this.xmlhttp.status == 404)
  		{
  			this.on404(this.xmlhttp.responseText, '', this.xmlhttp.status, this._requestId);
  		}
	else if(this.xmlhttp.status == 500)
  		{
  			this.on500(this.xmlhttp.responseText, '', this.xmlhttp.status, this._requestId);
  		}
	else if(this.xmlhttp.status == 505)
  		{
  			this.on505(this.xmlhttp.responseText, '', this.xmlhttp.status, this._requestId);
  		}
	else
  		{
  			this.onResponse(this.xmlhttp.responseText, this.xmlhttp.responseXML, this.xmlhttp.status, this._requestId);
  		}
  	}
}

function processMe()
{
    this.xmlhttp.open(this.method, this.URL, this.async);
   this.xmlhttp.setRequestHeader("Cache-Control", "no-cache");
    if((this.method != null) && (this.method.toUpperCase() == "POST"))
    {
		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	   	this.xmlhttp.send(this.params);
	}
    else 
	    r = this.xmlhttp.send(null);

	if(!this.async && !_isIE())
		this.responseHandler();	    
}

function getMyMethod()
{
	return this.method;
}

function getMyURL()
{
	return this.URL;
}

function getMyParameters()
{
	return this.params;
}
//locates the top window of the application
function findTop(window)
{
	var nCount=0;
	while(window != null)
	{
		//variable isTopWindow is located in menu.jsp.
		if(window.isTopWindow != null)
		{
			return window;
		}
		else
			window = window.parent;
			
		//don't let the javascript continue - return actual top
		if(nCount++ > 20)
			return top;
	}
}

function doClose(window)
{
	var topWindow = findTop(window);
	if(topWindow.handleClose != null)
		topWindow.handleClose();
	else
		topWindow.close();
}

function getCookie(name)
{ 
	var pos
  	var token = name + "=";
  	var tnlen = token.length;
  	var cklen = document.cookie.length;
  	var i = 0;
  	var j;
  	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 = new Date();
	today.setTime( today.getTime() );
	
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var 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";
}

var canHaveCookies = false;
function getCheckResponse(text, doc, code)
{
	var count=0;
	
	try
	{
		count = doc.selectSingleNode("html/body/count").text;
		var value = doc.selectSingleNode("html/body/value").text;
		if(value == null || value == "undefined" || value == "")
		{
			cookiesEnabled("test");
			return;
		}
	}
	catch(e)
	{
		//browser doesn't support XML object
		var nodeNameOpen = "<count>";
		var nodeNameClose = "</count>";
		
		var s = text.indexOf(nodeNameOpen);
		var e = text.indexOf(nodeNameClose);
		
		if(s > 0)
		{
			count = text.substring(s + nodeNameOpen.length, e);
			if(text.indexOf("<value>test") < 0)
			{
				cookiesEnabled("test");
				return;
			}
		}
	}
		
	if(parseInt(count) >= 1)
		canHaveCookies = true;
}


function cookiesEnabled(v)
{
	if(getCookie("canHaveCookies") == null)
	{
		x = new XMLRequest('/support/testCookie.jsp', 'POST', 'v='+v+'&t=' + new Date().getTime(), 'getCheckResponse', 'getCheckResponse', false);
		x.process();
	
		if(canHaveCookies)
		{
			setCookie("canHaveCookies", "true");
		}	
	}
	else
		canHaveCookies = true;		
	
	return(canHaveCookies);
}

function isIE()
{
	var dom = (document.getElementById) ? true : false;
	var ie4 = (document.all && !dom) ? true : false;
	var ie5 = ((navigator.userAgent.indexOf("MSIE")>-1) && dom) ? true : false;
	var ie6 = (navigator.userAgent.indexOf("MSIE 6.0")>-1) ? true : false;
	var ie7 = (navigator.userAgent.indexOf("MSIE 7.0")>-1) ? true : false;

	return (ie5 || ie4 || ie6 || ie7);
}

function isNetscape()
{
	var dom = (document.getElementById) ? true : false;
	var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) && dom) ? true: false;
	var ns4 = (document.layers && !dom) ? true : false;

	return (ns5 || ns4);
}

function openReceipt(receiptIds)
{
   var winName = "receiptWindow";
   var url = "/user/viewReceipt.jsp?" + receiptIds;
   var win = window.open(url, winName, "toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes,width=800,height=350, left=100, top=100");
   win.focus();
}

function formatPhone(obj)
{
re = /^\(?[0-9]{0,3}\)?[0-9]{0,3}-?[0-9]{0,4}$/g;
var f = obj.value;

if(!re.test(f))
{
	f = f.substring(0, f.length-1);
}
else
{	
	if(f.length >= 1)
	{
		if(f.charAt(0) != "(")
			f = "(" + f;
	}
	if(f.length >= 5)
	{
		if(f.charAt(4) != ")")
		{
			f = f.substring(0,4) + ")" + f.substring(4);
		}
	}
	if(f.length >= 9)
	{
		if(f.charAt(8) != "-")
		{
			f = f.substring(0,8) + "-" + f.substring(8);
		}
	}
}
obj.focus();
obj.value = f;
}

function initMapleCss()
{
	if(parent != window)
	{
		if(parent.document.styleSheets.length > 0)
		{
			var headID = document.getElementsByTagName("head")[0];
			var cssNode = document.createElement('link');
			cssNode.type = 'text/css';
			cssNode.rel = 'stylesheet';
			cssNode.href = parent.document.styleSheets[parent.document.styleSheets.length-1].href;
			cssNode.media = 'screen';
			headID.appendChild(cssNode);
		}
	}

}

//cycles through all forms and elements to disable/enable combo boxs.  Mainly used
//because of IE6 while using "haze" to disable screen
function resetComboBoxs(bReadOnly)
{
	var f = document.forms;
	for(k=0;k<f.length;k++)
	{
		var eles = f[k].elements;
		for(i=0;i<eles.length;i++)
		{
			if(f[k].elements[i] != null && (f[k].elements[i].type == "select" ||  f[k].elements[i].type == "select-one"))
			{
//				f[k].elements[i].readOnly = bReadOnly;
			}
		}
	}
}

function startList()
{
if (document.all&&document.getElementById) {
navRoot = document.getElementById("nav");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
	node.onmouseover=function() {this.className+=" over";}
  	node.onmouseout=function() {this.className=this.className.replace(" over", "");}
   	for(j=0;j<node.childNodes.length;j++)
   	{
   		n2 = node.childNodes[j];
   		if(n2.nodeName=="UL")
   		{
   			for(k=0;k<n2.childNodes.length;k++)
   			{
   				n3 = n2.childNodes[k];
   				if(n3.nodeName=="LI") {
					n3.onmouseover=function() {this.className+=" over";}
				  	n3.onmouseout=function() {this.className=this.className.replace(" over", "");}
   				}
   			}
   		}
   	}
   }
  }
 }
}

setHaze = function (ele)
{
	var hazeId = '_hze_'+ele.id;
	if(window._hazeEle == null)
	{
		window._hazeEle = new Array();
	}
	var hazer = _hazeEle[hazeId];
	if(hazer == null)
	{
		hazer = document.createElement("div");
		hazer.id = hazeId;
	}
	_hazeEle[hazeId] = hazer;
	ele.parentNode.appendChild(hazer);
	hazer.style.position = "absolute";
	hazer.style.top =  ele.parentNode.offsetTop + ele.offsetTop;
	hazer.style.left =  ele.parentNode.offsetLeft + ele.offsetLeft;
	hazer.style.zIndex = ele.style.zIndex + 10;
	hazer.style.width = ele.offsetWidth;
	hazer.style.height = ele.offsetHeight;
	hazer.style.display = "block";
}

clearHaze = function(ele)
{
	var hazeId = '_hze_'+ele.id;
	if(_hazeEle != null)
	{
		var hazer = _hazeEle[hazeId];
		if(hazer !== null)
		{
			hazer.style.display = "none";
		}
	}
}

function findParent()
{
	var c = window;
	var p = window.parent;
	
	while(c != p)
	{
		c = p;
		p=p.parent;
	}

	return p;
}

function testWindow()
{
	openWindow("http://www.yahoo.com");
}

function openWindow(url, windowName, windowAttributes, errorMessage)
{
	if(("undefined" == errorMessage) || (errorMessage == null))
		errorMessage="";
		
	handle = window.open(url, windowName, windowAttributes);
	var myURL = escape(url);
	//no window found so redirect to blocked ino		
	if(handle == null)
	{
		findParent().document.location = "/site/popupBlockerBlocked.jsp?message=" + errorMessage + "&url=" + myURL;
		return;
	}
	
	return handle;
}

//**********************************************************************************
// Copyright 1999 - 2002 by Ray Stott, Pop-up Windows Script ver 2.0
// OK to use if this copyright is included
// Script is available at http://www.crays.com/jsc
//
// Code found on the following site:
//http://www.javascriptmall.com/jsc/jsPWin.htm
//
//EXAMPLE:  openPopWin('jsPWinHow.htm', 740, 450, 'menubar,toolbar,scrollbars,resizable,status')
//EXAMPLE:  openPopWin("C.htm", 250, 180, "", "cen", "cen")

var popWin  = null    // use this when referring to pop-up window
var winName = "popWin";  // USED IN openPopWindow function  this is default

var winCount = 0
// var winName = "popWin"

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop)
{
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top

  //winName = "popWin" + winCount++ //unique name for each pop-up window

  closePopWin()           // close any previously opened pop-up window

  if (openPopWin.arguments.length >= 4)  // any additional features?
    winFeatures = "," + winFeatures
  else
    winFeatures = ""
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth
           + ",height=" + winHeight + winFeatures)
  }

function closePopWin()     // close pop-up window if it is open
{
  if (navigator.appName != "Microsoft Internet Explorer"
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close()
  }

 function getLocation(winWidth, winHeight, winLeft, winTop)
 {
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }

 // **** END OF Pop Window code ******
 //
 //**********************************************************************************

if(document.orig == null && document.getElementById != getElement)
	document.orig = document.getElementById;

if(!isIE())
	document.getElementById = getElement;

function getElement(_name)
{
	var obj = this.orig(_name);
	if(obj == null)
		obj = this.getElementsByName(_name)[0];
	
	return obj;
}


//holds all ajax requests
var gMapleAPI_Requests = new Array();
//holds all of the registered objects for the signon event
var gRegisteredSignOnEventList = new Array();
var gRegisteredSignOutEventList = new Array();
var gRegisteredProfileChangedEventList = new Array();
var gRequestCallCount = 1;
var gUser = null;

function MapleAPI()
{
	this._objName = "MapleAPI";
	this._objId = 0;

	this._url = null;
	this._params = null;
	this._isAsync = null;
	this._method = null;
	this._isRetry = false;
	
	this.getObjectName = mapleAPI_getObjectName;
	this.getObjectId = mapleAPI_getObjectId;

	this._processItems = false;
	this.setProcessItems = mapleAPI_onSetProcessItems;
	this.getProcessItems = mapleAPI_onGetProcessItems;
	this.onItemData = null;
	this._doFireSignOn = false;
	this._isloggedOn = false;
			
	this.getUser = mapleAPI_getUser;
	
	this._localprofile = null;
	this._profile = null;
	this.getProfile = mapleAPI_getProfile;
	this.setProfile = mapleAPI_setProfile;
	
	this._errMsg = null;
	this.getErrorMsg = mapleAPI_getErrorMsg;
	this.setErrorMsg = mapleAPI_setErrorMsg;

	this._viewData= null;
	this.getViewHTML = mapleAPI_getViewHTML;
	this.setViewHTML = mapleAPI_setViewHTML;

	this._emptyData = "";
	this.getEmptyHTML = mapleAPI_getEmptyHTML;
	this.setEmptyHTML = mapleAPI_setEmptyHTML;
	
	this._viewItemCount = 0;
	this.getViewItemCount = mapleAPI_getViewItemCount;
	this.setViewItemCount = mapleAPI_setViewItemCount;
	
	this.draw = mapleAPI_draw;
	
	this._xmlDoc = null;
	this.ajax = mapleAPI_doAJAX;
	this.onXMLDocument = mapleAPI_onXMLDocument;
	this.onRefreshCompleted =null;
	this.onProfileChanged = null;
	
	//signOn event	
	this.registerSignOnEvent = mapleAPI_registerSignOnEvent;
	this.fireSignOnEvent = mapleAPI_fireSignOnEvent;
	//signOut event
	this.registerSignOutEvent = mapleAPI_registerSignOutEvent;
	this.fireSignOutEvent = mapleAPI_fireSignOutEvent;
	//profileChanged event
	this.registerProfileChangedEvent = mapleAPI_registerProfileChangedEvent;
	this.fireProfileChangedEvent = mapleAPI_fireProfileChangedEvent;
}

function mapleAPI_getObjectName()
{
	return this._objName;
}

function mapleAPI_getObjectId()
{
	return this._objId;
}

function mapleAPI_registerProfileChangedEvent()
{
	var p = parent;
	while (p != null && p.mapleAPI_registerProfileChangedEvent != null && p != p.parent)
	{
		p = p.parent;
	}

	if(p!= null && p.gRegisteredProfileChangedEventList != null)
		p.gRegisteredProfileChangedEventList[p.gRegisteredProfileChangedEventList.length] = this;
}

function mapleAPI_fireProfileChangedEvent()
{
	for(var i=0;i<gRegisteredProfileChangedEventList.length;i++)
	{
		try
		{
			var obj = gRegisteredProfileChangedEventList[i];
			if(obj != null && obj != 'undefined' && obj.onProfileChangedEvent != null && obj.onProfileChangedEvent != 'undefined')
			{
				obj.setProfile("");
				obj.onProfileChangedEvent();
			}
		}
		catch(err)
		{
			//alert(err + ": " + err.description);
			//couldn't find function - remove obj;
			gRegisteredProfileChangedEventList[i] = null;
		}
	}
	if(parent != null && parent.mapleAPI_fireProfileChangedEvent != null && parent != self)
	{
		parent.mapleAPI_fireProfileChangedEvent();
	}

	try
	{
		if(top.opener != null && top.opener != self && top.opener.mapleAPI_fireProfileChangedEvent != null)
		{
			top.opener.mapleAPI_fireProfileChangedEvent();
		}	
	}
	catch (err)
	{
		;
	}
}

function mapleAPI_registerSignOnEvent()
{
	var p = parent;
	while (p != null && p.mapleAPI_registerSignOnEvent != null && p != p.parent)
	{
		p = p.parent;
	}

	if(p!= null && p.gRegisteredSignOnEventList != null)
		p.gRegisteredSignOnEventList[p.gRegisteredSignOnEventList.length] = this;
}

function mapleAPI_fireSignOnEvent()
{
	for(var i=0;i<gRegisteredSignOnEventList.length;i++)
	{
		try
		{
			var obj = gRegisteredSignOnEventList[i];
			if(obj != null && obj != 'undefined' && obj.onSignOnEvent != null && obj.onSignOnEvent != 'undefined')
			{
				obj.onSignOnEvent();
			}
		}
		catch(err)
		{
			//alert(err + ": " + err.description);
			//couldn't find function - remove obj;
			gRegisteredSignOnEventList[i] = null;
		}
	}
	if(parent != null && parent.mapleAPI_fireSignOnEvent != null && parent != self)
	{
		parent.mapleAPI_fireSignOnEvent();
	}
	
	try
	{
		if(top.opener != null && top.opener != self && top.opener.mapleAPI_fireSignOnEvent != null)
		{
			top.opener.mapleAPI_fireSignOnEvent();
		}	
	} catch (err)
	{
	;
	}
}

function mapleAPI_registerSignOutEvent()
{
	var p = parent;
	while (p != null && p.mapleAPI_registerSignOutEvent != null && p != p.parent)
	{
		p = p.parent;
	}

	if(p != null && p.gRegisteredSignOutEventList != null)
		p.gRegisteredSignOutEventList[p.gRegisteredSignOutEventList.length] = this;
}

function mapleAPI_fireSignOutEvent()
{
	for(var i=0;i<gRegisteredSignOutEventList.length;i++)
	{
		try
		{
			var obj = gRegisteredSignOutEventList[i];
			if(obj != null && obj != 'undefined' && obj.onSignOutEvent != null && obj.onSignOutEvent != 'undefined')
			{
				obj.onSignOutEvent();
			}
		}
		catch(err)
		{
			//couldn't find function - remove obj;
			gRegisteredSignOutEventList[i] = null;
		}
	}

	if(parent != null && parent.mapleAPI_fireSignOutEvent != null && parent != self)
	{
		parent.mapleAPI_fireSignOutEvent();
	}

	try
	{
		if(top.opener != null && top.opener.mapleAPI_fireSignOutEvent != null && top.opener != self)
		{
			top.opener.mapleAPI_fireSignOutEvent();
		}
	} catch (err)
	{
	;
	}
}

function mapleAPI_onSetProcessItems(flag)
{
	this._processItems = flag;
}

function mapleAPI_onGetProcessItems()
{
	return this._processItems;
}

function mapleAPI_getUser()
{
	return gUser;
}

function mapleAPI_getProfile()
{
	if(this._localprofile != null)
		return this._localprofile;
	else
		return this._profile;
}

function mapleAPI_setProfile(prof)
{
	this._localprofile = prof;
}

function mapleAPI_getErrorMsg()
{
	return this._errMsg;
}

function mapleAPI_setErrorMsg(msg)
{
	 this._errMsg = msg;
}

function mapleAPI_setViewHTML(txt)
{
	this._viewData = txt;
}

function mapleAPI_getViewHTML()
{
	return this._viewData;
}

function mapleAPI_getEmptyHTML()
{
	return this._emptyData;
}

function mapleAPI_setEmptyHTML(txt)
{
	this._emptyData = txt;
}

function mapleAPI_getViewItemCount()
{
	return this._viewItemCount;
}

function mapleAPI_setViewItemCount(n)
{
	this._viewItemCount = n;
}

function mapleAPI_doAJAX(url,method,params,isAsync)
{
	this._url = url;
	this._method = method;
	this._params = params;
	this._isAsync = isAsync;
	
	var isUnused = this;
	var ct = gMapleAPI_Requests['ct'];
	if(ct == null) ct = 0;
	var theKey = "m" +  new Date().getTime();
	
	while (isUnused != null )
	{
		
		theKey +=  "_"  + ct;
		isUnused =  gMapleAPI_Requests[theKey];
		ct++;
	}

	gMapleAPI_Requests[theKey] = this;
	gMapleAPI_Requests['ct'] = ct;

	
	this.setErrorMsg(null);
	this._isloggedOn = gUser != null;
	this._xmlRequest = new XMLRequest(url, method, params,theKey, 'mapleAPI_onAJAXResponse', isAsync);
	this._xmlRequest.process();
}

function mapleAPI_onAJAXResponse(text, doc, code, id)
{
	var obj = gMapleAPI_Requests[id];
	if(obj != null)
	{
		obj.onXMLDocument(text,doc,code);
	}
	else
	{
		alert("lost Message: " + id);
	}
	gMapleAPI_Requests[id] = null;
}

function mapleAPI_onXMLDocument(text,doc,code)
{
	if(code == 200) 
	{
		var bHasUser = false;
		var profileChanged = false;
		var temp = doc.getElementsByTagName("listData")[0];
		var d = doc.firstChild;
		if(temp != null)
		{
			this._xmlDoc =temp;
			var items = this._xmlDoc.childNodes;
			for(var i=0;i<items.length;i++) 
			{
				if(items[i].nodeName == "item")
				{
						//see if it is the user item
						if( (items[i].getAttribute("type") != null) && (items[i].getAttribute("type") == "user"))
						{
							gUser = new MapleUser();
							gUser.readElement(items[i]);
							bHasUser = true;
						}
						else if((items[i].getAttribute("type") != null) && (items[i].getAttribute("type") == "profile"))
						{
							// do not use the get/setProfile() here
							var t = this._profile;
							this._profile = items[i].firstChild.nodeValue;
							if(t != this._profile && this._profile != null)
							{
								profileChanged = true;
								this._localprofile = null;
							}
								
						}
						else if((items[i].getAttribute("type") != null) && (items[i].getAttribute("type") == "viewData"))
						{
							this._viewItemCount = items[i].getAttribute("itemCount");
							if( items[i].firstChild != null &&  items[i].firstChild.nodeValue != null)
							{
								this.setViewHTML(unescape( items[i].firstChild.nodeValue));
							}
							else
							{
								this.setViewHTML("");
							}
						}
						else if((items[i].getAttribute("type") != null) && (items[i].getAttribute("type") == "msg"))
						{
							this.setErrorMsg(items[i].firstChild.nodeValue);
						}
						else
						{
							if(this.onItemData != null)
							{
								if(items[i].getAttribute("type") != null ||  this.getProcessItems() == true)
								{
									this.onItemData(items[i]);
								}
							}
						}
				}
			}
			
			//a user wasn't sent - so they must have signed out
			if(!bHasUser)
				gUser = null;
				
			if(this.onRefreshCompleted != null)
				this.onRefreshCompleted();
			
			if(profileChanged == true && gUser == null && this._doFireSignOn == true)
			{
				this.fireProfileChangedEvent();
			}

			if(gRequestCallCount == 2 && this._doFireSignOn == true)
			{
				if(gUser != null && this._isloggedOn == false)
				{
					this.fireSignOnEvent();
				}
				else if (gUser == null && this._isloggedOn == true)
				{
					this.fireSignOutEvent();
				}
			}
			else
			{
				gRequestCallCount++;
			}

			this._url = null;
			this._params = null;
			this._isAsync = null;
			this._method = null;
			this._isRetry = false;
		}
		else
		{
			if(!this._isRetry)
			{
				this._isRetry = true;

				if(this._params != null)
					this._params += "&";
				this._params += "bForce=1&t=" + new Date().getTime();

				this.ajax(this._url, this._method, this._params, this._isAsync);
			}
			else
			{
				alert("listData was not found [" + this.getObjectId() + "]");
				this._url = null;
				this._params = null;
				this._isAsync = null;
				this._method = null;
				this._isRetry = false;
			}
		}
	}
	else
	{
		this.setErrorMsg("[" + code + "] (" + text + ")");
		alert("Error Communicating! [" + code + "] (" + text + ") for [" + this.getObjectId() + "]");
	}
}

function mapleAPI_draw(theDiv)
{
	if(this.getViewItemCount() > 0)
	{
		theDiv.innerHTML = this.getViewHTML();
	}
	else
	{
		theDiv.innerHTML = this.getEmptyHTML();
	}
}


function MapleUser()
{
	this._objName = "MapleUser";
	this._objId = 13;

	this._firstName = null;
	this.getFirstName = new Function('', 'return this._firstName;');
	this.setFirstName = new Function('val', 'this._firstName = val;');

	this._lastName = null;
	this.getLastName = new Function('', 'return this._lastName;');
	this.setLastName = new Function('val', 'this._lastName = val;');

	this._email = null;
	this.getEmail = new Function('', 'return this._email;');
	this.setEmail = new Function('val', 'this._email = val;');

	this._jobTitle = null;
	this.getJobTitle = new Function('', 'return this._jobTitle;');


	this._userId = 0;
	this.getUserId = new Function('', 'return this._userId;');

	this._topGroup = null;
	this.getTopGroup = new Function('', 'return this._topGroup;');

	this._group = null;
	this.getGroup = new Function('', 'return this._group;');
	
	this.readElement = mapleUser_readElement;
}

function mapleUser_readElement(node)
{
	if(node.getElementsByTagName("firstName") != null  && node.getElementsByTagName("firstName")[0] != null && node.getElementsByTagName("firstName")[0].firstChild != null)
		this._firstName =node.getElementsByTagName("firstName")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("lastName") != null  && node.getElementsByTagName("lastName")[0] != null && node.getElementsByTagName("lastName")[0].firstChild != null)
		this._lastName =node.getElementsByTagName("lastName")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("email") != null  && node.getElementsByTagName("email")[0] != null && node.getElementsByTagName("email")[0].firstChild != null)
		this._email =node.getElementsByTagName("email")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("jobTitle") != null  && node.getElementsByTagName("jobTitle")[0] != null && node.getElementsByTagName("jobTitle")[0].firstChild != null)
		this._jobTitle =node.getElementsByTagName("jobTitle")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("topGroup") != null  && node.getElementsByTagName("topGroup")[0] != null && node.getElementsByTagName("topGroup")[0].firstChild != null)
		this._topGroup = node.getElementsByTagName("topGroup")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("group") != null  && node.getElementsByTagName("group")[0] != null && node.getElementsByTagName("group")[0].firstChild != null)
		this._group = node.getElementsByTagName("group")[0].firstChild.nodeValue;
	if(node.getElementsByTagName("userId") != null && node.getElementsByTagName("userId")[0] != null && node.getElementsByTagName("userId")[0].firstChild != null)
		this._userId = node.getElementsByTagName("userId")[0].firstChild.nodeValue;
}


function MapleKeywordList(setName)
{
	this._objName = "MapleKeywordList";
	this._objId = 5;

	this.kwsetName = setName;
	this.wordList = null;
	this.getItems = MapleKeywordList_getItems;
	this.refresh = MapleKeywordList_refresh;
	this.onItemData = MapleKeywordList_onItemData;
}

MapleKeywordList.prototype = new MapleAPI();

function MapleKeywordList_getItems()
{
	return this.wordList;
}

function MapleKeywordList_refresh()
{
	this.setProcessItems(true);
	this.wordList = new Array();

	this.ajax('/anon/getKeywordList.jsp','GET','kwSet=' + this.kwsetName,false);
}

function MapleKeywordList_onItemData(item)
{
	var keyword = new MapleKeywordItem(item.getAttribute("id"), unescape(item.firstChild.nodeValue));
	this.wordList[this.wordList.length] = keyword;
}

//KeywordItem
function MapleKeywordItem(_id, _name)
{
	this._objName = "MapleKeywordItem";
	this._objId = 6;

	this.id = _id;
	this.name = _name;

	this.getId = new Function('', 'return this.id;');
	this.getName = new Function('', 'return this.name;');
}
function MapleMenu()
{
	MENU_URL = "/anon/menuJump.jsp?";

	this._objName = "MapleMenu";
	this._objId = 7;

	//member items
	this._menuItems = null;
	this.getItems = mapleMenu_getItems;
	this.getItem = mapleMenu_getItem;

	this._target = "";
	this.getTarget = new Function('', 'return this._target;');
	this.setTarget = new Function('v', 'this._target = v;');
	// override setting the view data
	this.setViewHTML = mapleMenu_setViewHTML;

	//function calls
	this.refresh = mapleMenu_refresh;
	this.logon = mapleMenu_logon;
	this.logout = mapleMenu_logout;
	this.onItemData = mapleMenu_onItemData;
	this.getMenuURL = mapleMenu_getMenuURL;
	this._doFireSignOn = true;
}

//inherit from MapleAPI
MapleMenu.prototype = new MapleAPI();

function mapleMenu_getMenuURL(_menuItem)
{
	var m = MENU_URL;
	m += ("menuItem=" + _menuItem + "&hideHeader=1");
	
	return m;
}

function mapleMenu_refresh()
{
	this._user = null;
	
	var params = "cmd=menu";
	if(this.getProfile() != null)
	{
		params += "&ap=" + this.getProfile();
	}

//	if(getCookie("user") != null)
//	{
//		params += "&userId=" + getCookie("user");
//	}

	this.getViewItemCount(0);
	this._menuItems = new Array();

	var isAsync =(this.onRefreshCompleted != null);	
	this.ajax('/anon/getMenuList.jsp','POST',params,isAsync);
}

function mapleMenu_onItemData(item)
{
	this._menuItems[this._menuItems.length] = new MapleMenuItem(item.getAttribute("name"), unescape(item.firstChild.nodeValue), item.getAttribute("locked"), item.getAttribute("newwin"));
}

function mapleMenu_setViewHTML(txt)
{
	var target = this.getTarget();
	if(target == null) target = "_self";
	// replace XXTARGETXX with the real target;
	var newTxt = txt.replace(/XXTARGETXX/g," target='"+target+"'" );
	this._viewData = newTxt;
}

function mapleMenu_getItems()
{
	return this._menuItems;
}

function mapleMenu_getItem(mName)
{
	var retval = null;
	
	if(this._menuItems != null)
	{
		for(i=0;i<this._menuItems.length && retval == null;i++)
		{
			retval = this._menuItems[i];
			if(retval._name != mName)
			{
				retval = null;
			}
		}
	
	}
	
	return retval;
}

function mapleMenu_logout()
{
	this.getViewItemCount(0);
	this._menuItems = new Array();
	this.ajax('/anon/logout.jsp','GET','',false);
	deleteCookie("user");
	deleteCookie("logon");
}

function mapleMenu_logon(uname,upassword, bRemember)
{
	var params = "cmd=logon&nam="+uname+"&pwd="+upassword+"&r="+(bRemember?"1":"0");
	if(this.getProfile() != null)
	{
		params += "&ap=" + this.getProfile();
	}

	this.getViewItemCount(0);
	this._menuItems = new Array();
	this.ajax('/anon/getMenuList.jsp','POST',params,false);

	
	return this.getErrorMsg();
}

// MapleMenuItem
function MapleMenuItem(name, caption, isLocked, useNewWindow)
{
	this._objName = "MapleMenuItem";
	this._objId = 8;

	this._name = name;
	this.getName = new Function('',"return this._name;");
	this.setName = new Function('v',"this._name = v;");
	this._caption = caption;
	this.getCaption = new Function('',"return this._caption;");
	this.setCaption = new Function('v',"this._caption = v;");
	
	if("true" == isLocked || "TRUE" == isLocked || "1" == isLocked)
		this._isLocked = true;
	else
		this._isLocked = false;
	this.isLocked = new Function('',"return this._isLocked;");
	this.setIsLocked = new Function('v',"this._isLocked = v;");

	if("true" == useNewWindow || "TRUE" == useNewWindow || "1" == useNewWindow)
		this._useNewWindow = true;
	else
		this._useNewWindow = false;
	this.getUseNewWindow = mapleMenuItem_getUseNewWindow;
	this.setUseNewWindow = mapleMenuItem_setUseNewWindow;
		
}

function mapleMenuItem_getUseNewWindow()
{
	return this._useNewWindow;
}
function mapleMenuItem_setUseNewWindow(val)
{
	if("true" == val || "TRUE" == val || "1" == val || val == true)
		this._useNewWindow = true;
	else
		this._useNewWindow = false;
}


//Catalog Search
function MapleSearch()
{
	this._objName = "MapleSearch";
	this._objId = 11;

	this._searchItems = null;
	this.getItems = mapleSearch_getSearchItems;
	
	this._keywordList = new Array(); 
	this.clearKeywords = mapleSearch_clearKeywords;
	this.addKeyword = mapleSearch_addKeyword;

	this._classificationList = new Array(); 
	this.clearClassifications = mapleSearch_clearClassifications;
	this.addClassification = mapleSearch_addClassification;

	this._searchTerm = null;
	this.setSearchTerm = mapleSearch_setSearchTerm;
	this.getSearchTerm = mapleSearch_getSearchTerm;
	
	this._maxResults = 0;
	this.getMaxResults = mapleSearch_getMaxResults;
	this.setMaxResults = mapleSearch_setMaxResults;
	
	this._wantStatus = false;
	this.setWantStatus = mapleSearch_setWantStatus;
	this.getWantStatus = mapleSearch_getWantStatus;

	this._wantAssignedOnly = false;
	this.setAssignedOnly = mapleSearch_setWantAssignedOnly;
	this.getAssignedOnly = mapleSearch_getWantAssignedOnly;
	

	var header = "<table width='100%' cellpadding='0' cellspacing='0' border='2'><tr><th>Course Listing</th</tr><tr><td>";
	var footer = "</td></tr></table>";
	var emptyViewData = "<div id=\"mapleSearch\">";
	emptyViewData += header + "There are no items available" + footer;
	emptyViewData += "</div>";
	
	this.setEmptyHTML(emptyViewData);
		
	//functions
	this.search = mapleSearch_doGetSearch;
	
	this.getAvailKeywords  = mapleSearch_getAvailKeywords;
	this.getAvailClassifications  = mapleSearch_getAvailClassifications;
	this.getAvailLocations = mapleSearch_getAvailLocations;
	
	this.onItemData = mapleSearch_onItemData;
	
	this._availKeywords =  new  MapleKeywordList("DS_GROUPINGS_CAT");
	this._availClassifications =  new  MapleKeywordList("DS_CLASSIFS_EMPS");
	this._availLocations = new MapleLocationList();
	
	this._availKeywords.refresh();
	this._availClassifications.refresh();
	this._availLocations.refresh();
}

//inherit from MapleAPI
MapleSearch.prototype = new MapleAPI();


//returns an array of SearchItems which is the result of the search
function mapleSearch_getSearchItems()
{
	return this._searchItems;
}

function mapleSearch_getAvailLocations()
{
	return this._availLocations.getItems();
}

function mapleSearch_setWantStatus(f)
{
		this._wantStatus = f;
}
function mapleSearch_getWantStatus()
{
		return this._wantStatus;
}

function mapleSearch_setWantAssignedOnly(f)
{
		this._wantAssignedOnly = f;
}
function mapleSearch_getWantAssignedOnly()
{
		return this._wantAssignedOnly;
}



//returns an array of KeywordItem with the available classifications to search on.
function mapleSearch_getAvailClassifications()
{
	return this._availClassifications.getItems();
}
//returns an array of KeywordItem with the available keywords to search on
function mapleSearch_getAvailKeywords()
{
	return this._availKeywords.getItems();
}

//clears out selected keywords
function mapleSearch_clearKeywords()
{
	this._keywordList = new Array();
}

//add a keyword to search against
function mapleSearch_addKeyword(_keyword)
{
	this._keywordList[this._keywordList.length] = _keyword;
}

//clears out selected classifications
function mapleSearch_clearClassifications()
{
	this._classificationList = new Array();
}

//add a classification to search against
function mapleSearch_addClassification(_keyword)
{
	this._classificationList[this._classificationList.length] = _keyword;
}

//set the search words to search against
function mapleSearch_setSearchTerm(_searchTerm)
{
	this._searchTerm = _searchTerm;
}
function mapleSearch_getSearchTerm()
{
	return this._searchTerm;
}

function  mapleSearch_getMaxResults()
{
	return this._maxResults;
}

function  mapleSearch_setMaxResults(x)
{
	this._maxResults = x;
}
	

//perform ajax search
function mapleSearch_doGetSearch()
{
	var keywords ="";
	if(this._keywordList != null)
	{
		for(var i= 0;i<this._keywordList.length;i++)
		{
			keywords += "&keyword=";
			keywords += this._keywordList[i];
		}
	}
		
	var classifications ="";
	if(this._classificationList != null)
	{
		for(var i= 0;i<this._classificationList.length;i++)
		{
			classifications += "&classification=";
			classifications += this._classificationList[i];
		}
		
	}
	
	var profile = "";
	if(this.getProfile() != null)
	{
		profile="&ap="+this.getProfile();
	}
	
	profile += "&mx="+this.getMaxResults();
	
	var searchTerms = "";
	if(this._searchTerm != null)
	{
		searchTerms =  '&terms=' + this._searchTerm;
	}
	
	if(this._wantStatus)
	{
		profile += "&stat=1";
	}
	if(this._wantAssignedOnly)
	{
		profile += "&cw=1";
	}
	

	this._searchItems = new Array();
	var isAsync =(this.onRefreshCompleted != null);
	
	this.ajax('/anon/getCatalogSearchList.jsp','POST',"s=1" + profile +  searchTerms + keywords + classifications,isAsync);
}

function mapleSearch_onItemData(item)
{
	var search = new MapleSearchItem();
	
	search.setName(unescape(item.getElementsByTagName("name")[0].firstChild.nodeValue));
	search.setTitle(unescape(item.getElementsByTagName("title")[0].firstChild.nodeValue));
	search.setRuleTypeId(item.getElementsByTagName("ruleTypeId")[0].firstChild.nodeValue);
	search.setRuleId(item.getElementsByTagName("ruleId")[0].firstChild.nodeValue);

	if(item.getElementsByTagName("timeMessage")[0].firstChild != null)
		search.setTimeMessage(item.getElementsByTagName("timeMessage")[0].firstChild.nodeValue);

	search.setHasDetail(item.getElementsByTagName("hasDetail")[0].firstChild.nodeValue);
	search.setHasSuppliedMaterials(item.getElementsByTagName("hasSuppliedMaterials")[0].firstChild.nodeValue);
	search.setHasHyperLink(item.getElementsByTagName("hasHyperLink")[0].firstChild.nodeValue);
	search.setIsAssigned(item.getElementsByTagName("isAssigned")[0].firstChild.nodeValue);
	search.setCode(item.getElementsByTagName("code")[0].firstChild.nodeValue);
	search.setTrackingCode(item.getElementsByTagName("trackingCode")[0].firstChild.nodeValue);

	var price = item.getElementsByTagName("price");
	if(price != null && price[0] != null)
	{
		if(price[0].getElementsByTagName("member") != null)
			search.setMemberPrice (price[0].getElementsByTagName("member")[0].firstChild.nodeValue);
		if(price[0].getElementsByTagName("non-member") != null)
			search.setNonMemberPrice(price[0].getElementsByTagName("non-member")[0].firstChild.nodeValue);
	}
	
	this._searchItems[this._searchItems.length] = search;
}

//SearchItem
function MapleSearchItem()
{
	this._objName = "MapleSearchItem";
	this._objId = 12;

	this._name = null;
	this._title = null;
	this._ruleTypeId = null;
	this._timeMessage = null;
	this._hasDetail = null;
	this._hasSuppliedMaterials = null;
	this._hasHyperLink = null;
	this._isAssigned = null
	this._ruleId = null;
	this._code = null;
	this._trackingCode = null;
	this._memberPrice = "00.00";
	this._nonMemberPrice = "00.00";
	
	this.getName = new Function('', 'return this._name;');
	this.getTitle = new Function('', 'return this._title;');
	this.getRuleTypeId = new Function('', 'return this._ruleTypeId;');
	this.getRuleId = new Function('', 'return this._ruleId;');
	this.getTimeMessage = new Function('', 'return this._timeMessage;');
	this.getHasDetail = new Function('', 'return this._hasDetail;');
	this.getHasSuppliedMaterials = new Function('', 'return this._hasSuppliedMaterials;');
	this.getHasHyperLink = new Function('', 'return this._hasHyperLink;');
	this.getIsAssigend = new Function('', 'return this._isAssigned;');
	this.getCode = new Function('', 'return this._code;');
	this.getTrackingCode = new Function('', 'return this._trackingCode;');
	this.getMemberPrice = new Function('', 'return this._memberPrice;');
	this.getNonMemberPrice = new Function('', 'return this._nonMemberPrice;');

	this.setName = new Function('_val', 'this._name = _val;');
	this.setTitle = new Function('_val', 'this._title = _val;');
	this.setRuleTypeId = new Function('_val', 'this._ruleTypeId = _val;');
	this.setRuleId = new Function('_val', 'this._ruleId = _val;');
	this.setTimeMessage = new Function('_val', 'this._timeMessage = _val;');
	this.setHasDetail = new Function('_val', 'this._hasDetail = _val;');
	this.setHasSuppliedMaterials = new Function('_val', 'this._hasSuppliedMaterials = _val;');
	this.setHasHyperLink = new Function('_val', 'this._hasHyperLink = _val;');
	this.setIsAssigned = new Function('_val', 'this._isAssigned = _val;');
	this.setCode = new Function('_val', 'this._code = _val;');
	this.setTrackingCode = new Function('_val', 'this._trackingCode = _val;');
	this.setMemberPrice = new Function('_val', 'this._memberPrice = _val;');
	this.setNonMemberPrice = new Function('_val', 'this._nonMemberPrice = _val;');
}
// News
function MapleNews()
{
	this._objName = "MapleNews";
	this._objId = 9;

	//local variables
	this._newsItems = null;
	
	//function calls
	this.refresh = mapleNews_refreshNews;
	this.getItems = mapleNews_getItems;
	this.getItem = mapleNews_getItem;
	this.onItemData = mapleNews_onItemData;
}

//inherit from MapleAPI
MapleNews.prototype = new MapleAPI();

function mapleNews_refreshNews()
{
	var params = "";
	if(this.getProfile() != null)
	{
		params += "&ap=" + this.getProfile();
	}
	
	this._newsItems = new Array();

	var isAsync =(this.onRefreshCompleted != null);
	this.ajax('/anon/getNewsList.jsp','GET',params,isAsync);
}


function mapleNews_onItemData(item)
{
	var ni = new MapleNewsItem();
	
	ni.setTitle(unescape(item.getElementsByTagName("title")[0].firstChild.nodeValue));
	ni.setText(unescape(item.getElementsByTagName("text")[0].firstChild.nodeValue));
	if(item.getElementsByTagName("url") != null && item.getElementsByTagName("url")[0] != null && item.getElementsByTagName("url")[0].firstChild != null)
		ni.setURL(unescape(item.getElementsByTagName("url")[0].firstChild.nodeValue));
	ni.setGroup(unescape(item.getElementsByTagName("group")[0].firstChild.nodeValue));
	ni.setGroupName(unescape(item.getElementsByTagName("groupName")[0].firstChild.nodeValue));
	
	this._newsItems[this._newsItems.length] = ni;
}

function mapleNews_getItems()
{
	return this._newsItems;
}

function mapleNews_getItem(nName)
{
	var retval = null;
	
	if(this._newsItems != null)
	{
		for(i=0;i<this._newsItems.length && retval == null;i++)
		{
			retval = this._newsItems[i];
			if(retval._name != nName)
			{
				retval = null;
			}
		}
	}

	return retval;
}

//MapleNewsItem
function MapleNewsItem()
{
	this._objName = "MapleNewsItem";
	this._objId = 10;

	this._title = null;
	this._text = null;
	this._url = null;
	this._group = null;
	this._groupName = null;
	
	this.getTitle = new Function('', 'return this._title;');
	this.getText = new Function('', 'return this._text;');
	this.getURL = new Function('', 'return this._url;');
	this.getGroup = new Function('', 'return this._group;');
	this.getGroupName = new Function('', 'return this._groupName;');

	this.setTitle = new Function('_val', 'this._title = _val;');
	this.setText = new Function('_val', 'this._text = _val;');
	this.setURL = new Function('_val', 'this._url = _val;');
	this.setGroup = new Function('_val', 'this._group = _val;');
	this.setGroupName = new Function('_val', 'this._groupName = _val;');
}
//Calendar
var _selectedDay = "";

function MapleCalendar()
{
	this._objName = "MapleCalendar";
	this._objId = 1;
	//variables
	this._startDate = null;
	this.setStartDate = mapleCalendar_setStartDate;
	this.getStartDate = mapleCalendar_getStartDate;
	
	this._endDate = null;
	this.setEndDate = mapleCalendar_setEndDate;
	this.getEndDate = mapleCalendar_getEndDate;

	this._format = this.LIST;
	this.setFormat = mapleCalendar_setFormat;
	this.getFormat = mapleCalendar_getFormat;
	
	this._ruleId = 0;
	this.setRuleId = mapleCalendar_setRuleId;
	this.getRuleId = mapleCalendar_getRuleId;

	this._categoryId = 0;
	this.setCategoryId = mapleCalendar_setCategoryId;
	this.getCategoryId = mapleCalendar_getCategoryId;

	this._locationId = 0;
	this.setLocationId = mapleCalendar_setLocationId;
	this.getLocationId = mapleCalendar_getLocationId;
	
	this._calendarKeywordItems = new Array();
	
	this._calendarItems = null;
	this.getItems = mapleCalendar_getItems;
	this._calendarCourseItems = null;
	
	this.getCalendarCourseItems = mapleCalendar_getCalendarCourseItems;
	this.getCalendarKeywordItems = new Function('', 'return this._calendarKeywordItems;');
	
	this._calViewData = null;
	this.getGraphicalViewHTML = mapleCalendar_getGraphicalViewHTML;
	this.setGraphicalViewHTML = mapleCalendar_setGraphicalViewHTML;

	this._listViewData = null;
	this.getListViewHTML = mapleCalendar_getListViewHTML;
	this.setListViewHTML = mapleCalendar_setListViewHTML;
	
	this._smartViewData = null;
	this.getSmartViewHTML = mapleCalendar_getSmartViewHTML;
	this.setSmartViewHTML = mapleCalendar_setSmartViewHTML;

	//functions
	this.refresh = mapleCalendar_refresh;
	this.draw = mapleCalendar_drawCalendar;
	
	this.onItemData = mapleCalendar_onItemData;
}

//inherit from MapleAPI
MapleCalendar.prototype = new MapleAPI();
MapleCalendar.prototype.GRAPHICAL = "GRAPHICAL";
MapleCalendar.prototype.LIST = "LIST";
MapleCalendar.prototype.SMART = "SMART";

	
function mapleCalendar_setRuleId(val)
{
	this._ruleId = val;
}

function mapleCalendar_getRuleId()
{
	return this._ruleId;
}

function mapleCalendar_setLocationId(val)
{
	this._locationId = val;
}

function mapleCalendar_getLocationId()
{
	return this._locationId;
}

function mapleCalendar_getCategoryId()
{
	return this._categoryId;
}

function mapleCalendar_setCategoryId(val)
{
	this._categoryId = val;
}

function mapleCalendar_setListViewHTML(txt)
{
	this._listViewData = txt;
}

function mapleCalendar_getListViewHTML()
{
	return this._listViewData;
}

function mapleCalendar_setGraphicalViewHTML(txt)
{
	this._calViewData = txt;
}

function mapleCalendar_getGraphicalViewHTML()
{
	return this._calViewData;
}

function mapleCalendar_setSmartViewHTML(txt)
{
	this._smartViewData = txt;
}

function mapleCalendar_getSmartViewHTML()
{
	return this._smartViewData;
}

function mapleCalendar_setStartDate(_startDate)
{
	this._startDate = _startDate;
}

function mapleCalendar_getStartDate()
{
	return this._startDate;
}

function mapleCalendar_setEndDate(_endDate)
{
	this._endDate = _endDate;
}

function mapleCalendar_getEndDate()
{
	return this._endDate;
}

function mapleCalendar_setFormat(_format)
{
	this._format = _format;
}

function mapleCalendar_getFormat()
{
	return this._format;
}

function mapleCalendar_getItems()
{
	return this._calendarItems;
}

function mapleCalendar_refresh()
{
	var params = "";
	
	params += "&ruleId=" + this._ruleId;
	params += "&locationId=" + this._locationId;
	params += "&keywordId=" + this._categoryId;
	if(this._startDate != null)
		params += "&startDate=" + this._startDate.getTime();
	if(this._endDate != null)
		params += "&endDate=" + this._endDate.getTime();

	this._calendarCourseItems = null;
	this._calendarItems = new Array();
	var isAsync =(this.onRefreshCompleted != null);	
	this.ajax('/anon/getCalendarList.jsp','GET',params,isAsync);
}

function mapleCalendar_getCalendarCourseItems()
{
	if(this._calendarCourseItems == null)
	{
		this._calendarCourseItems = new Array();

		var items = this.getItems();
		var bFound = false;
		//remove duplicate names
		for(var i=0;i<items.length;i++)
		{
			bFound = false;
			for(var j=0;j<this._calendarCourseItems.length;j++)
			{
				if(this._calendarCourseItems[j].getName() == items[i].getName())
				{
					bFound = true;
					break;
				}
			}
			
			if(!bFound)
				this._calendarCourseItems[this._calendarCourseItems.length] = items[i];
		}
	}
		
	return this._calendarCourseItems;
}

function mapleCalendar_onItemData(item)
{
	var type = item.getAttribute("type");
	var val = item.getAttribute("itemCount");

	if(type  == "calView")
	{
		if(val != null)
		{
			this.setViewItemCount(val);
		}
		this._calViewData = unescape(item.firstChild.nodeValue);
	}
	else if(type == "listView")
	{
		if(val != null)
		{
			this.setViewItemCount(val);
		}
		this._listViewData = unescape(item.firstChild.nodeValue);
	}
	else if(type == "smartView")
	{
		if(val != null)
		{
			this.setViewItemCount(val);
		}
		this._smartViewData = unescape(item.firstChild.nodeValue);
	}
	else if (type == null)
	{
		var ci = new MapleCalendarItem();

		ci.ruleId = unescape(item.getElementsByTagName("ruleId")[0].firstChild.nodeValue);
		ci.name = unescape(item.getElementsByTagName("name")[0].firstChild.nodeValue);
		ci.title = unescape(item.getElementsByTagName("title")[0].firstChild.nodeValue);

		if(item.getElementsByTagName("description") != null && item.getElementsByTagName("description")[0].firstChild != null)
			ci.description = unescape(item.getElementsByTagName("description")[0].firstChild.nodeValue);
		
		ci.location = unescape(item.getElementsByTagName("location")[0].firstChild.nodeValue);
		ci.enrollStatus = unescape(item.getElementsByTagName("enrollStatus")[0].firstChild.nodeValue);
		ci.sessionStatus = unescape(item.getElementsByTagName("sessionStatus")[0].firstChild.nodeValue);
		ci.status = unescape(item.getElementsByTagName("status")[0].firstChild.nodeValue);
		ci.startDate = unescape(item.getElementsByTagName("startDate")[0].firstChild.nodeValue);
		ci.endDate = unescape(item.getElementsByTagName("endDate")[0].firstChild.nodeValue);

		if(item.getElementsByTagName("instructor") != null && item.getElementsByTagName("instructor")[0] != null && item.getElementsByTagName("instructor")[0].firstChild != null)
		{
			ci.instructor = unescape(item.getElementsByTagName("instructor")[0].firstChild.nodeValue);
		}

		var price = item.getElementsByTagName("price");
		if(price != null && price[0] != null)
		{
			if(price[0].getElementsByTagName("member") != null)
				ci.memberPrice = price[0].getElementsByTagName("member")[0].firstChild.nodeValue;
			if(price[0].getElementsByTagName("non-member") != null)
				ci.nonMemberPrice = price[0].getElementsByTagName("non-member")[0].firstChild.nodeValue;
		}

		var categories = item.getElementsByTagName("categories");
		if(categories != null)
		{
			var kwItem;
			ci.categoryList = new Array();
			for(var j=0;j<categories.length;j++) 
			{
				if(categories[j].getElementsByTagName("category") != null && categories[j].getElementsByTagName("category")[0] != null && categories[j].getElementsByTagName("category")[0].firstChild != null)
				{
					ci.categoryList[ci.categoryList.length] = categories[j].getElementsByTagName("category")[0].firstChild.nodeValue;

					kwItem = new MapleKeywordItem(categories[j].getElementsByTagName("category")[0].getAttribute("id"), categories[j].getElementsByTagName("category")[0].firstChild.nodeValue);
					this._calendarKeywordItems[this._calendarKeywordItems.length] = kwItem;
				}
			}
		}

		this._calendarItems[this._calendarItems.length] = ci;
	}
}

function mapleCalendar_drawCalendar(theDiv)
{
		
	if(this.getViewItemCount()  != null && this.getViewItemCount() > 0)
	{
		if(this.getFormat() == this.LIST)
		{
			theDiv.innerHTML = this.getListViewHTML();
		}
		else if(this.getFormat() == this.GRAPHICAL)
		{
			theDiv.innerHTML = this.getGraphicalViewHTML();
		}
		else if(this.getFormat() == this.SMART)
		{
			theDiv.innerHTML = this.getSmartViewHTML();
		}
	}
	else
	{
		theDiv.innerHTML = this.getEmptyHTML();
	}
}

//Calendar Item
function MapleCalendarItem()
{
	this._objName = "MapleCalendarItem";
	this._objId = 2;

	this.ruleId = 0;
	this.getRuleId = new Function('', 'return this.ruleId;');
	this.setRuleId = new Function('_val', 'this.ruleId = _val;');

	this.title = "";
	this.setTitle = new Function('_val', 'this.title = _val;');
	this.getTitle = new Function('', 'return this.title;');

	this.name = "";
	this.setName = new Function('_val', 'this.name = _val;');
	this.getName = new Function('', 'return this.name;');

	this.description = null;
	this.getDescription = new Function('', 'return this.description;');
	this.setDescription = new Function('_val', 'this.description = _val;;');

	this.location = null;
	this.setLocation = new Function('_val', 'this.location = _val;;');
	this.getLocation = new Function('', 'return this.location;');

	this.enrollStatus = 0;
	this.getEnrollStatus = new Function('', 'return this.enrollStatus;');
	this.setEnrollStatus = new Function('_val', 'this.enrollStatus = _val;;');

	this.sessionStatus = 0;
	this.getSessionStatus = new Function('', 'return this.sessionStatus;');
	this.setSessionStatus = new Function('_val', 'this.sessionStatus = _val;');

	this.status = 0;
	this.getStatus = new Function('', 'return this.status;');
	this.setStatus = new Function('_val', 'this.status = _val;');

	this._startDate = null;
	this.getStartDate = new Function('', 'return this._startDate;');
	this.setStartDate = new Function('_val', 'this._startDate = _val;');

	this._endDate = null;
	this.getEndDate = new Function('', 'return this._endDate;');
	this.setEndDate = new Function('_val', 'this._endDate = _val;');

	this.instructor = null;
	this.getInstructor = new Function('', 'return this.instructor;');
	this.setInstructor = new Function('_val', 'this.instructor = _val;');

	this.memberPrice = null;
	this.getMemberPrice = new Function('', 'return this.memberPrice;');
	this.setMemberPrice = new Function('_val', 'this.memberPrice = _val;');

	this.nonMemberPrice = null;
	this.getNonMemberPrice = new Function('', 'return this.nonMemberPrice;');
	this.setNonMemberPrice = new Function('_val', 'this.nonMemberPrice = _val;');

	this.categoryList = new Array();
	this.getCategories = new Function('', 'return this.categoryList;');
	this.setCategories = new Function('_val', 'this.categoryList = _val;');
}

function getApptContents(apptId,sd,ed)
{
	var s= null;
	var sel = getSelectedDay();
	
	if(sel != '')
	{
		s=document.getElementById(sel);
		s.style.width='0';
		s.style.height='0';
		s.style.visibility='hidden';
	}
	setSelectedDay(apptId);
	
	s = document.getElementById(apptId);
	
	s.style.visibility = 'visible';
	s.style.width = '300';
	
	var params = "id=" + apptId + "&t=0&v=AV&c=1&s="+sd+"&e="+ed;
	
	x = new XMLRequest('/calendar/calendarDisplay.jsp', 'POST',params, apptId,'onUpdateLink', true);
	x.process();
}
	
function onUpdateLink(text, doc, code,id)
{
	var ele = document.getElementById(id);
	ele.innerHTML = text;
}

function setSelectedDay(day)
{
	_selectedDay = day;
}

function getSelectedDay()
{
	return _selectedDay;
}
function MapleGroupItem(nam,prof,fnam,id)
{
	this._objName = "MapleGroupItem";
	this._objId = 4;

	if(nam != null)
		nam = unescape(nam);
		
	if(fnam != null)
		fnam = unescape(fnam);

	this._name = nam;
	this.getName =  new Function('', 'return this._name;');

	this._profile = prof;
	this.getProfile =  new Function('', 'return this._profile;');

	this._fqn = fnam;
	this.getFQN =  new Function('', 'return this._fqn;');

	this._parent = null;
	this.getParent = new Function('', 'return this._parent;');
	this.setParent = new Function('v', 'this._parent = v;');

	this._orgId = id;
	this.getOrgId = new Function('', 'return this._orgId;');
}

MapleGroupItem.prototype.getItems = mapleGroupList_getItems;
MapleGroupItem.prototype.getItem = mapleGroupList_getItem;
MapleGroupItem.prototype._groups = null;

function MapleGroups()
{
	this._objName = "MapleGroups";
	this._objId = 3;
	
	//member items
	this._startGrp = null;
	this.setStartingGroup = mapleGroups_setStartingGroup;
	this.getStartingGroup = mapleGroups_getStartingGroup;

	this._depth = 0;
	this.getMaxDepth = new Function('', 'return this._depth;');
	this.setMaxDepth = new Function('v', 'this._depth = v;');

	//function calls
	this.refresh = mapleGroups_refresh;
	
	this.onItemData = mapleGroups_onItemData;
}

//inherit from MapleAPI
MapleGroups.prototype = new MapleAPI();
MapleGroups.prototype._groups = null;
MapleGroups.prototype.getItems = mapleGroupList_getItems;
MapleGroups.prototype.getItem = mapleGroupList_getItem;
	
function mapleGroups_setStartingGroup(grp)
{
	this._startGrp = grp;
}

function mapleGroups_getStartingGroup()
{
	return this._startGrp;
}

function mapleGroups_readItemEle(theList, ele,parent)
{
	var msg = null;
	var eleType;
	var thisItem = null;

	eleType =  ele.getAttribute("type");
	
	if(eleType == null)
	{
		// normal group item
		var name = ele.getAttribute("name");
		var profile = ele.getAttribute("profile");
		var fqn = ele.getAttribute("fqn");
		var orgid = ele.getAttribute("orgId");

		if(parent == null || parent.getFQN() != fqn)
		{
			thisItem = new MapleGroupItem(name,profile,fqn,orgid);
			thisItem.setParent(parent);
			theList[theList.length] = thisItem;
		}
		else
		{
			thisItem  = parent;
		}

		var newList = ele.childNodes;
		for(var i=0;i<newList.length;i++)
		{
			if(newList[i].nodeName == "item" && newList[i].getAttribute("type") != null && newList[i].getAttribute("type")  == "children")
			{
				thisItem._groups = new Array();
				var newList = newList[i].childNodes;
				for(var ii=0;ii<newList.length;ii++)
				{
					var theItem = newList[ii];
					if(theItem.nodeName == "item")
					{
						msg = mapleGroups_readItemEle(thisItem._groups,theItem,thisItem);
					}
				}
			}
		}
	}
	else if(eleType == "msg")
	{
		msg = ele.firstChild.nodeValue;
	}

	return msg;
}

function mapleGroups_refresh()
{
	var params = "d="+this._depth;
	var startGrp =this.getStartingGroup();
	if(startGrp != null)
	{
		params += "&s="+startGrp.getOrgId();
	}

	if(startGrp == null)
	{
		this._groups = new Array();
	}
	else
	{
		 startGrp._groups = new Array();
	}
	
	this.setProcessItems(true);
	this.getViewItemCount(0);
	var isAsync =(this.onRefreshCompleted != null);
	this.ajax('/anon/getOrgList.jsp','GET',params,isAsync);
}

function mapleGroups_onItemData(item)
{
	var msg = null;
	var theRoot = null;
	var parent = null;
	
	if(this._startGrp == null)
	{
		 theRoot = this;
		 parent = null;
	}
	else
	{
		 theRoot = this._startGrp;
		 parent = theRoot;
	}

	msg = mapleGroups_readItemEle(theRoot._groups,item,parent);
		
	if(msg != null)
	{
		this.setErrorMsg(msg);
		theRoot._groups = null;
	}
}

function mapleGroupList_getItems()
{
	return this._groups;
}

function mapleGroupList_getItem(mName)
{
	var retval = null;
	
	if(this._groups != null)
	{
			for(var i=0;i<this._groups.length && retval == null;i++)
			{
				if(this._groups[i]._fqn == mName)
				{
					retval = this._groups[i];
				}
				else
				{
					var prefix = mName.substring(0,this._groups[i]._fqn.length);
					if(prefix == this._groups[i]._fqn)
					{
						retval = this._groups[i].getItem(mName);
					}
				}
			}
	}
	
	return retval;
}
function MapleLocationList()
{
	this._objName = "MapleLocationList";
	this._objId = 14;

	this.getItems = MapleLocationList_getItems;
	this.refresh = MapleLocationList_refresh;
	this.onItemData = MapleLocationList_onItemData;
	
	this._locationList = null;
}

MapleLocationList.prototype = new MapleAPI();

function MapleLocationList_getItems()
{
	return this._locationList;
}

function MapleLocationList_refresh()
{
	this.setProcessItems(true);
	this._locationList = new Array();

	this.ajax('/anon/getLocationList.jsp','GET','',false);
}

function MapleLocationList_onItemData(item)
{
	var location = new MapleLocationItem(item.getAttribute("id"), unescape(item.firstChild.nodeValue));
	this._locationList[this._locationList.length] = location;
}

//KeywordItem
function MapleLocationItem(_id, _name)
{
	this._objName = "MapleLocationItem";
	this._objId = 15;

	this.id = _id;
	this.name = _name;

	this.getId = new Function('', 'return this.id;');
	this.getName = new Function('', 'return this.name;');
}


alert("This account [null] does not have access");





  
