var oIThelp = {
	oFocus : [], /* [0] = selected Grid/Listbox, [1] = selected row  [2] = shiftKey state*/
	bShim : oClient.bIEwin,
	oUserDef : {},
	aImages : {},
	oBroadcastEvent : {},
	oObserver : {},
	mInit : function () {
		
		oLayout.oRoot.onkeydown	= function( e ) {
			oIThelp.mBroadcastEvent('onkeydown', e);
		}
		//document.onselectstart= function() { return false }; // disable selection
		/*oIThelp.aImages['calendar']=new Image();
		oIThelp.aImages['calendar'].src=oIThelp.mGetApplicationPath()+'/Wendy/Brix/Images/calendar.gif';*/

	},
	
	// Initialize flash objects
	mActivateEmbeddedObjects : function(oParent){
		if(oClient.bIE){
			oParent = oParent ? oParent : document;
			objects = oParent.getElementsByTagName("object");
			for (var i = 0; i < objects.length; i++)
				objects[i].outerHTML = objects[i].outerHTML;
		}
	},
	
	// Central Observer design pattern
	mAttachObserver : function (sSubject, oNode, func) {
		if ( !oIThelp.oObserver [ sSubject ]) oIThelp.oObserver [ sSubject ] = [ [oNode, func] ];
		else oGod.mPush ( oIThelp.oObserver [ sSubject ], [oNode, func] );
	},
	
	mDetachObserver : function (sSubject, oNode, func) {
		var aObservers = oIThelp.oObserver [ sSubject ]; 
		var i = 0; while ( aObservers [ i ]) {
			if ( aObservers [ i ] == oNode) aObservers [ i ] = new Function ();
			i++;
		}
	},
	
	mUpdateObserver : function ( sSubject, id, params ) {
		if ( oIThelp.oObserver [ sSubject ]) 
			for (var i=0;i<oIThelp.oObserver [ sSubject ].length;i++) 
				if (oIThelp.oObserver [sSubject][i][1]!=null)
					oIThelp.oObserver [sSubject][i][0][oIThelp.oObserver[sSubject][i][1]].apply(oIThelp.oObserver [sSubject][i][0], [id, params]);
				else
					oIThelp.oObserver [sSubject][i][0]['mUpdateObserver'].apply(oIThelp.oObserver [sSubject][i][0], [id, params]);
	},
	
	// central event broadcasting service
	mSubscribeEvent : function ( sBroadcast, oNode, func ) {
		if ( !oIThelp.oBroadcastEvent [ sBroadcast ]) oIThelp.oBroadcastEvent [ sBroadcast ] = [ [oNode, func] ];
		else oGod.mPush ( oIThelp.oBroadcastEvent [ sBroadcast ], [oNode, func] );
	},
	
	mUnsubscribeEvent : function ( sBroadcast, oNode ) {
		var aSubscribers = oIThelp.oBroadcastEvent [ sBroadcast ]; 
		var i = 0; while ( aSubscribers [ i ]) {
			if ( aSubscribers [ i ] == oNode) aSubscribers [ i ] = new Function ();
			i++;
		}
	},
	
	mBroadcastEvent : function ( sBroadcast, e ) {
		if ( oIThelp.oBroadcastEvent [ sBroadcast ]) 
			for (var i=0;i<oIThelp.oBroadcastEvent [ sBroadcast ].length;i++) 
				if (oIThelp.oBroadcastEvent [sBroadcast][i][1]!=null)
					oIThelp.oBroadcastEvent [sBroadcast][i][0][oIThelp.oBroadcastEvent[sBroadcast][i][1]].apply(oIThelp.oBroadcastEvent [sBroadcast][i][0], [e]);
				else
					oIThelp.oBroadcastEvent [sBroadcast][i][0][sBroadcast].apply(oIThelp.oBroadcastEvent [sBroadcast][i][0], [e]);
	},
	
	mKeyPress : function (oSender, e, oKeyCodes){
		var iKeyID = (e.charCode) ? e.charCode  : e.keyCode;
		if(typeof(oKeyCodes[iKeyID]) == 'function'){
			oKeyCodes[iKeyID]();
			return false;
		}
	},
	
	mGetUrlParam : function( paramName )
	{
		var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
		var oMatch = oRegex.exec( window.top.location.search ) ;
		
		if ( oMatch && oMatch.length > 1 )
			return oMatch[1] ;
		else
			return '' ;
	},
	
	pageQuery : function(q) {
		if(!q) q = window.location.search;
		if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
							
		this.keyValuePairs = new Array();
		if(q) {
			for(var i=0; i < this.q.split("&").length; i++) {
				this.keyValuePairs[i] = this.q.split("&")[i];
			}
		}
		
		this.getValue = function(s) {
			for(var j=0; j < this.keyValuePairs.length; j++) {
				if(this.keyValuePairs[j].split("=")[0] == s)
					return this.keyValuePairs[j].split("=")[1];
			}
			return 'false';
		}
	},

	getAssociativeArrayLength : function(asArray) { 
		var i=0;
		for (var item in asArray) i++;	
		return i;
	},
	
	getCallBackSOAP : function(sResponseText){
		var beginContent=sResponseText.indexOf('&lt;content&gt;');
		var endContent=sResponseText.indexOf('&lt;/content&gt;');
		var resp=sResponseText.substring(beginContent+15, endContent);
		resp=resp.replaceAll('&lt;','<').replaceAll('&gt;','>').replaceAll('&amp;','&').replaceAll('&quot;','"');
		return resp;
	},
	
	getCallBackEndContent : function(sResponseText, s){
		var startTAG = s ? '<content'+s+'>' : '<content>', endTAG = s ? '</content'+s+'>' : '</content>';
		var beginContent=sResponseText.indexOf(startTAG);
		var endContent=sResponseText.indexOf(endTAG);
		var resp=sResponseText.substring(beginContent+startTAG.length, endContent);
		return oXMLLib.mXMLUnEscape(resp);
	},
	
	getElementById : function(id) {
		if (document.getElementById) return document.getElementById(id);
		else return document.all[id];
	},
		
	redirect : function(aspxPath, keys, menuid) {
		var page = new oIThelp.pageQuery(window.location.search);
		var menu;
		
		if (menuid=="") { // Preserve menuid
			menu = page.getValue("menuid");
			if (menu=='false') menu="";
			else menu="menuid="+menu;
		}
		else {
			menu="menuid="+menuid;
		}
		
		if (keys!="" && menu!="") menu=menu+"&";
		window.location=aspxPath+'?'+menu+keys;
	},
	
	mRedirectWithParam : function(paramName, paramValue, removeParams, pHash){
		var q = window.location.search, hash = window.location.hash, q1 = '', u = window.location.toString().replaceAll(q+hash, '');

		if (typeof(pHash) !='undefined' && pHash!='') hash="#"+pHash;

		if(q.length > 1) q = q.substring(1, q.length);
		var aPNames = paramName.split('@sep'), aPValues = paramValue.split('@sep');
		if(aPNames.length != aPValues.length){alert('Parameter missing or invalid!'); return false;}
		var aParams = q.split('&'), oParams = {};
		
		var aRemoveParams;
		if (typeof(removeParams) !='undefined') aRemoveParams=removeParams.split('@sep');
		else aRemoveParams=[];
		
		var oRemoveParams = {};
		for (var r = 0;r<aRemoveParams.length; r++) {
			oRemoveParams[aRemoveParams[r].trim()]="1";
		}

		for(var i = 0; i < aPNames.length; i++){
			paramName = aPNames[i].trim();
			paramValue = aPValues[i].trim();
			oParams[paramName] = paramValue;
		}

		for(var p = 0; p < aParams.length; p++){
			if(!oParams[aParams[p].split('=')[0]] && !oRemoveParams[aParams[p].split('=')[0]])
				oParams[aParams[p].split('=')[0]] = aParams[p].split('=')[1];
		}
		
		for(var s in oParams){
				if (s != '')
					q1 += (q1 == '' ? '?' : '&') + s + '=' + oParams[s];
		}
		window.location = u + q1 + hash;
	},

	// globals: schoolId, languageId, taughtLanguageId, yearId, menuId
	mRedirectWendy : function(globals, params) {
		var appPath=oIThelp.mGetApplicationPath();
		var page = new oIThelp.pageQuery(window.location.search);
		var queryString='';
		var aGlobals;
		if (!params) params='';
		var globalId=page.getValue('globalid');
		if (globalId=='false') {
			aGlobals=[-1, -1, -1, -1];
		}
		else {
			aGlobals=globalId.split('_');
		}
		
		var menuid=-1;
		
		if (globals.menuId) menuid=globals.menuId;
		else if (page.getValue('menuid')!='false') menuid=page.getValue('menuid');
		
		
		if (globals.schoolId) aGlobals[0]=globals.schoolId;
		else if (page.getValue('schoolid')!='false') aGlobals[0]=page.getValue('schoolid');
		
	
		if (globals.languageId) aGlobals[1]=globals.languageId;
		else if (page.getValue('languageid')!='false') aGlobals[1]=page.getValue('languageid');
		
		if (globals.taughtLanguageId) {
			aGlobals[2]=globals.taughtLanguageId;
			params+=(params==''?'':'&')+'taughtlanguageid='+globals.taughtLanguageId;
		}
		else if (page.getValue('taughtlanguageid')!='false') aGlobals[2]=page.getValue('taughtlanguageid');
		
		
		if (globals.yearId) {
			aGlobals[3]=globals.yearId;
			params+=(params==''?'':'&')+'yearid='+globals.yearId;
		}
		else if (page.getValue('yearid')!='false') aGlobals[3]=page.getValue('yearid');
	
		var st=appPath+'/Render.aspx?menuid='+menuid+'&globalid='+aGlobals[0]+'_'+aGlobals[1]+'_'+aGlobals[2]+'_'+aGlobals[3]+(params!=''?'&'+params:'');
		//alert(st);
		window.location=st;
		
	},
	
	mGetCursorPosition : function (o) {
		var oCursorPos = {};
		oCursorPos.start = 0;
		oCursorPos.end = 0;
		if (document.selection) { // IE...
			o.focus();
			var sel1 = document.selection.createRange();
			var sel2 = sel1.duplicate();
			sel2.moveToElementText(o);
			var selText = sel1.text;
			sel1.text = "\001";
			var index = sel2.text.indexOf("\001");
			oCursorPos.start = oIThelp.mCountChars((index == -1) ? sel2.text : sel2.text.substring(0, index));
			oCursorPos.end = oIThelp.mCountChars(selText) + oCursorPos.start;
			sel1.moveStart('character', -1);
			sel1.text = selText;
		} else if (o.selectionStart || (o.selectionStart == "0")) { // Mozilla/Netscape...
			oCursorPos.start = o.selectionStart;
			oCursorPos.end = o.selectionEnd;
		}
		return oCursorPos;
	},
	
	mCountChars : function(text) {
		var n = 0;
		for (var i = 0; i < text.length; i++) {
			if (text.charAt(i) != '\r') {
			n++;
			}
		}
		return n;
	},
	
	createEmbeddedTextNode: function(elementName, text, className) {
		var oTemp=document.createElement(elementName);
		oTemp.className=className;
		oTemp.appendChild(document.createTextNode(text));
		return oTemp;
	},
	
	createEmbeddedNode: function(elementName, node, className) {
		var oTemp=document.createElement(elementName);
		oTemp.className=className;
		oTemp.appendChild(node);
		return oTemp;
	},
	
	callPopper : function(url, xslName, nodeId, param) {
		oIThelp.mPlainLoading();
		oXMLLib.mCallBackEnd(url, param, oIThelp.callBackPopper, nodeId);
	}, 
				
	callBackPopper : function(oRequest, nodeId, sContent) {
		//alert(oRequest.responseText);
		var sTitle = '';
		if(nodeId.contains('_ith_popper_title=')){
			sTitle = nodeId.substring(nodeId.indexOf('_ith_popper_title=')+18);
			nodeId = nodeId.substring(0,nodeId.indexOf('_ith_popper_title='));
		}
		var i=0;
		var oPopper=null;
		var response = sContent ? sContent : oIThelp.getCallBackEndContent(oRequest.responseText);
		var aPoppers=oIThelp.getAllElementsByClassName(document, 'popped');
		while ((oPopper=aPoppers[i++])!=null) {
			if (oPopper.id==nodeId) {
				if(sTitle != '') oPopper.oTitle.nodeValue = sTitle;
				break;
			}
		}
		var callBack=new function() {
			return function(b) {
				
				if (!b) alert('waitTill failed');
				var aDivs=oPopper.getElementsByTagName('div');
				for (var j=0;j<aDivs.length;j++) {
					if (aDivs.item(j).className=='body') {
						/*var oPopperForm = document.createElement('FORM');
						oPopperForm.id = 'formid';
						oPopperForm.className = 'form';
						oPopperForm.innerHTML = response;*/
						aDivs.item(j).innerHTML= response;
						//aDivs.item(j).appendChild(oPopperForm);
						break;
					}
				}
				oPopper.oBody.style.display='block';
				oPopper.oBodyTemp.style.display='none';
				if (typeof(oTabboxes)!='undefined') oTabboxes.mInit(nodeId)(); // Initializes tabboxes if any
				if (typeof(oPoppers)!='undefined') oPoppers.mInit(nodeId, false)(); // Initializes poppers if any
				if (typeof(oGrids)!='undefined') oGrids.mInit(nodeId)(); // Initializes grids if any
				if (typeof(oListboxes)!='undefined') oListboxes.mInit(nodeId)(); // Initializes listboxes if any
				if (typeof(oForms)!='undefined') oForms.mInit(nodeId)(); // Initializes forms if any
				oIThelp.initializeJavascripts(oPopper);
				oGod.mBroadcast (oPopper.id + " popper filled");
				oIThelp.mStopPlainLoading();
				//alert('popper end');
			}
		}
		oIThelp.mWaitTill(new function() {return function() { return !oPopper.bInitializing}}, callBack);
	},
	
	callBackBase : function(oRequest, nodeId) {
		
		var oNode=document.getElementById(nodeId);
		var aDivs=oNode.getElementsByTagName('div');
		for (var j=0;j<aDivs.length;j++) {
			if (aDivs.item(j).className=='body') {
				aDivs.item(j).innerHTML=oRequest.responseText;
				break;
			}
		}
		
		//oPopper.oBody.style.display='block';
		//oPopper.oBodyTemp.style.display='none';
		if (typeof(oTabboxes)!='undefined') oTabboxes.mInit(nodeId)(); // Initializes tabboxes if any
		if (typeof(oPoppers)!='undefined') oPoppers.mInit(nodeId, false)(); // Initializes poppers if any
		if (typeof(oGrids)!='undefined') oGrids.mInit(nodeId)(); // Initializes grids if any
		if (typeof(oListboxes)!='undefined') oListboxes.mInit(nodeId)(); // Initializes listboxes if any
		if (typeof(oForms)!='undefined') oForms.mInit(nodeId)(); // Initializes forms if any
		oIThelp.initializeJavascripts(oNode);
		//oGod.mBroadcast (oPopper.id + " popper filled");
	},
	
	initializeJavascripts : function(oNode) {
		var aScripts=oIThelp.getAllElementsByClassName(oNode, 'script');
		for (var i=0;i<aScripts.length;i++) {
			eval(aScripts[i].innerHTML.replaceAll('\n','').substring(0));
		}
	},
	
	getAllElementsByClassName : function(oNode, className) {
		var arr=[];
		var tempNode;
		for (var i=0;i<oNode.childNodes.length;i++) {
			if (oNode.childNodes[i].nodeType!=Node.TEXT_NODE && oNode.childNodes[i].className!=null) {
				aClassNames=oNode.childNodes[i].className.split(' ');
				for (var j=0;j<aClassNames.length;j++) {
					if (aClassNames[j].trim()==className) {
						arr=arr.concat(oNode.childNodes[i]);
						break;
					}
				}
			}
			arr=arr.concat(oIThelp.getAllElementsByClassName(oNode.childNodes[i], className));
		}
		return arr;
	},
	
	/*getAllElementsByTagName : function(oNode, tagName) {
		var arr=[];
		var tempNode;
		for (var i=0;i<oNode.childNodes.length;i++) {
			if (oNode.childNodes[i].nodeType!=Node.TEXT_NODE) {
				oNode.childNodes[i].tagName
				if (aClassNames[j]==className) {
					arr=arr.concat(oNode.childNodes[i]);
				}
				
			}
			arr=arr.concat(oIThelp.getAllElementsByClassName(oNode.childNodes[i], className));
		}
		return arr;
	},*/
	
	containClassName : function(classNameBase, className) {
		aClassNames=classNameBase.split(' ');
		for (var j=0;j<aClassNames.length;j++) {
			if (aClassNames[j].trim()==className) {
				return true;
			}
		}
		return false;
	},
	
	getParentByClassName : function(oNode, className) {
    if (oNode == null) return null;
		if (oNode.id=="worksheet") return oNode;
		if (oNode.parentNode.className!=null && oNode.parentNode.className.contains(className)) 
			return oNode.parentNode;
		else
			return oIThelp.getParentByClassName(oNode.parentNode, className);
	},
	
	getContainerParent : function(oNode) {
		//if (oNode.tagName=='TD') return {nodeType: 'td', node: oNode, initialWidth : oNode.offsetWidth}
		if(oNode.id.contains('MSOZoneCell_WebPartWPQ2'))  return {nodeType: 'wepartzone', node: oNode, initialWidth : oNode.offsetWidth}
		if (oNode.id=="worksheet") return {nodeType: 'worksheet', node: oNode, initialWidth : oNode.initialWidth}
		if (oNode.className!=null && oNode.className.contains('popped')) 
			return {nodeType: 'popped', node: oNode, initialWidth : oNode.initialWidth}
		else if (oNode.className!=null && oNode.className.contains('tabbox')) 
			return {nodeType: 'tabbox', node: oNode, initialWidth : oNode.offsetWidth}
		else
			return oIThelp.getContainerParent(oNode.parentNode);
	},
	
	setStatusBar : function(message) {
		window.status=message;
	},
	
	mElementReady : function(a, func) {
		//initialise the counter
		var n = 0;
		//start the timer
		var t = setInterval(function()
		{
			var c = true;
			n++;
		
			if(typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
			{
				c = false;
				if(typeof a == 'object')
				{
					if ((a.type == 'id' && document.getElementById(a.value) == null) || (a.type == 'tag' && document.getElementsByTagName(a.value).length < 1)) 
						c = true; 
					
				}
				if(!c) { clearInterval(t); func(true); }
			}
			if(n >= 30) { clearInterval(t); func(false) }
		}, 250);
	},
	
	iFocusCycleNum : 0,
	iFocusCycleInterval : 100,
	oFocusElement : null,
	mFocus : function(aNode, num, interval) {
		oIThelp.oFocusElement=aNode;
		if (arguments[1]) oIThelp.iFocusCycleNum=num;
		else oIThelp.iFocusCycleNum=10;
		if (arguments[2]) oIThelp.iFocusCycleInterval=interval;
		setTimeout(oIThelp.mFocusTimer, oIThelp.iFocusCycleInterval);
	},
	mFocusTimer : function() {
		if (0<oIThelp.iFocusCycleNum--) {
			try { oIThelp.oFocusElement.focus();}
			catch (ex) {
				setTimeout(oIThelp.mFocusTimer, oIThelp.iFocusCycleInterval);
			}
		}
	},
	
	mEscape : function(name) {
		return typeof(name) != 'undefined' ? name.replaceAll(';', '$ith_sc').replaceAll('=', '$ith_eq').replaceAll('@', '$ith_at').replaceAll('>', '$ith_gt').replaceAll('<', '$ith_lt') : name;
		return name;
	},
	
	mUnEscape : function(name) {
		return typeof(name) != 'undefined' ? name.replaceAll('$ith_sc',';').replaceAll('$ith_eq','=').replaceAll('$ith_at','@').replaceAll('$ith_gt','>').replaceAll('$ith_lt','<') : name;
	},
	
	
	mGetLocalName : function (sName) {
		return oNames[sName];
	},
	
	mGetAttribute : function(oNode, sAttrName) {
		var oAttribute;
		if (oNode.NodeType!=Node.TEXT_NODE) {
			for (var i=0; i < oNode.attributes.length; i++) {
				if (oNode.attributes[i].name == sAttrName) {
					oAttribute = oNode.attributes[i].value;
					break;
				}
			}
		}
		else oAttribute=null;
		return oAttribute;
	},
	
	mAddAttribute : function(oNode, sAttrName, sAttrValue) {
		var oAttribute=document.createAttribute(sAttrName);
		if (oNode.NodeType!=Node.TEXT_NODE) {
			oAttribute.value = sAttrValue;
			oNode.setAttributeNode(oAttribute);
		}
		else oAttribute=null;
		return oAttribute;
	},

	mAddClass : function(oNode, className) {
		if (oNode.className) {
			if (!oNode.className.contains(className)) {
				oNode.className += ' ' + className;
			}
		}
		else oNode.className=className;
	},
	
	mRemoveClass : function(oNode, className) {
		if (oNode.className.split(' ').length>1)  {
			oNode.className=oNode.className.replace(className, '' ).trim();
		}
		else if (oNode.className.contains(className)) oNode.className='';
	},
	
	mGetEventFunc : function(command) {
		return function(e) {
			eval(command);
		}
	},
	
	mGetApplicationPath : function() {
		var appPath=document.URL;
		appPath=appPath.substring(appPath.indexOf('://')+3, appPath.length);
		appPath=appPath.substring(appPath.indexOf('/'), appPath.length);
		appPath=appPath.substring(0, appPath.indexOf('?'));
		appPath=appPath.substring(0, appPath.lastIndexOf('/'));
		return appPath;
	},
	
	mGetStatusBar : function(text) {
		if (!arguments[0]) text='';
		var oStatusBar = oIThelp.createEmbeddedTextNode ( "div",  text, 'statusbar');
		oStatusBar.items={};
		oStatusBar.addItem=function(mode, name, text) {
			this.items[mode]={};
			this.items[mode][name]=text;
		}
		oStatusBar.switchMode=function(mode) {
			var str='';
			for (word in this.items[mode]) {
				str+=(str==''?'':' ')+this.items[mode][word];
			}
			this.firstChild.nodeValue=str;
		}
		oStatusBar.clear=function() {
			this.items={}
			this.firstChild.nodeValue='';
		}
		return oStatusBar;
	},
	
	mGetInverseColor : function(cN) {
		var c='#';
		for (var i=1;i<cN.length;i++) {
			c+="0123456789ABCDEF".charAt(15-"0123456789ABCDEF".indexOf(cN.charAt(i)));
		}
		return c;
	},
	
	/*getAbsolutePos : function(el, oParent) { // with Scroll
		if (el==oParent) return {x: 0, y: 0};
		var scrollLeft = 0, scrollTop = 0;
		var is_div = /^div$/i.test(el.tagName);
		if (is_div && el.scrollLeft) scrollLeft = el.scrollLeft;
		if (is_div && el.scrollTop) scrollTop = el.scrollTop;
		var r = { x: el.offsetLeft - scrollLeft, y: el.offsetTop - scrollTop };
		if (el.offsetParent) {
			var tmp = this.getAbsolutePos(el.offsetParent, oParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	},*/
	
	getAbsolutePos : function(el, oParent) { // without scroll
		if (el==oParent) return {x: 0, y: 0};
		var is_div = /^div$/i.test(el.tagName);
		var r = { x: el.offsetLeft, y: el.offsetTop };
		if (el.offsetParent) {
			var tmp = this.getAbsolutePos(el.offsetParent, oParent);
			r.x += tmp.x;
			r.y += tmp.y;
		}
		return r;
	},
	
	mWaitTill : function(func, callBack) {
		//initialise the counter
		var n = 0;
		//start the timer
		var t = setInterval(function()
		{
			n++;
			if(func()) { clearInterval(t); callBack(true); }
			if(n >= 30) { clearInterval(t); callBack(false) }
		}, 250);
	},
	
	aPlainLoadings : [],
	
	mStopPlainLoading : function(){
		oIThelp.aPlainLoadings[0] = oIThelp.aPlainLoadings[0] - 1;
		if(oIThelp.aPlainLoadings.length == 1 && oIThelp.aPlainLoadings[0] == 0){
			if(document.getElementById('plainLoadingBox'))
				document.body.removeChild(document.getElementById('plainLoadingBox'));
		}
	},
	
	mPlainLoading : function(){
		if(oIThelp.aPlainLoadings.length == 0){
			oIThelp.aPlainLoadings.push(0);
			var loadingOnScroll = function(){
				if(document.getElementById('plainLoadingBox'))
					document.getElementById('plainLoadingBox').style.top = (1 + document.body.scrollTop) + 'px';
			}
			if(oClient.bIE){ 
				window.attachEvent("onscroll", loadingOnScroll);
			}
			else{
				window.addEventListener('scroll',loadingOnScroll,false);
			}
		}
		if(!document.getElementById('plainLoadingBox')){
			var oL = document.createElement('SPAN');
			oL.style.position = 'absolute';
			oL.style.top = (1 + document.body.scrollTop) + 'px';
			oL.style.left = '1px';
			oL.id = 'plainLoadingBox';	
			oL.appendChild(document.createTextNode(oIThelp.mGetLocalName('LOADING') + ' ...'));
			document.body.appendChild(oL);
		}
		oIThelp.aPlainLoadings[0] = oIThelp.aPlainLoadings[0] + 1;
	},
	
	mLoadingText : function(id) {
		return function() {
			var oLoading=oIThelp.aLoadingIds[id];
			var points='';
			oLoading.state=(oLoading.state+1) % 4;
			for (var i=0;i<oLoading.state;i++) points+='.';
			oLoading.oNode.firstChild.nodeValue = oLoading.text+' '+points;
		}
	},
	
	aLoadingIds : {},
	
	mLoading : function(id, text) {
		if (!oIThelp.aLoadingIds[id] || oIThelp.aLoadingIds[id] == null) {
			oIThelp.aLoadingIds[id]={};
			var oLoading=oIThelp.aLoadingIds[id], oLoadingBody = document.getElementById('ith_loadingbody');
			var oNode=oIThelp.createEmbeddedTextNode( "div", text, 'msgloading' );
			//oLayout["worksheet"].appendChild(oNode);
			if(!oLoadingBody){
				oLoadingBody = document.createElement('DIV');
				oLoadingBody.id = 'ith_loadingbody';
				oLayout["worksheet"].appendChild(oLoadingBody);
			}
			oLoadingBody.innerHTML = '';
			oLoadingBody.appendChild(oNode);
			oLoading.oNode=oNode;
			oLoading.text=text;
			oLoading.state=0;
			var zIndex = 99;
			if (typeof(oPoppers) != 'undefined') zIndex=oPoppers.mGetZIndex();
			oNode.style.zIndex = zIndex + 2;
			oLoading.timerId=setInterval(oIThelp.mLoadingText(id), 500);
			//alert(oTools.mWindow ( "xscroll" )+" "+oTools.mWindow ("width")+" "+oTools.mWindow ( "yscroll" )+" "+oTools.mWindow ("height"));
			oNode.style.left = ((oTools.mWindow ( "xscroll" )) + (oTools.mWindow ("width") / 2) - 55) + "px";
			oNode.style.top = ((oTools.mWindow ( "yscroll" ))  + (oTools.mWindow ("height") / 2) - 30) + "px";
			
			var oShimFrame = document.createElement ( "iframe" );
			oShimFrame.src="App/Cuba/Images/spacer.gif";
			oShimFrame.scrolling='no';
			oShimFrame.frameBorder='0';
			oShimFrame.style.display='block';
			oShimFrame.style.position='absolute';
			oShimFrame.style.top=oNode.offsetTop;
			oShimFrame.style.left=oNode.offsetLeft;
			oShimFrame.style.width=oNode.offsetWidth;
			oShimFrame.style.height=oNode.offsetHeight;
			oShimFrame.style.zIndex=zIndex + 1;
			oLoading.oShim=oShimFrame;
			oLoadingBody.appendChild(oShimFrame);
		}
	},

	mStopLoading : function(id) {
		var oLoading=oIThelp.aLoadingIds[id];
		if (oLoading  || oLoading != null) {
			oLoadingBody = document.getElementById('ith_loadingbody');
			//oLayout["worksheet"].removeChild(oLoading.oNode);
			oLoadingBody.removeChild(oLoading.oNode);
			clearInterval(oLoading.timerId);
			oIThelp.aLoadingIds[id]=null;
			oLoadingBody.removeChild(oLoading.oShim);
		}
	},

	mHoeChildTextNodes : function (oParentNode) {
		var i=0, oNode;
		while ((oNode=oParentNode.childNodes[i++])!=null) {
			if (oNode.nodeType==Node.TEXT_NODE)
				oParentNode.removeChild(oNode);
		}
	}, 
	
	mAddLog : function(oSender, sUrl, sParam){
		if(typeof(oIThelp.mGetAttribute(oSender, 'logged')) == 'undefined'){
			oXMLLib.mPostHTTPRequestByParam(sUrl, 'SPSCuba_AddLog', sParam, new function(){return function(){return false;}}, null);
			oIThelp.mAddAttribute(oSender, 'logged', 'true');
		}
	},
	
	mWsAddLog : function(oSender, sUrl, sType, sCategory, sParams){
		// TYPE must be one of the following types: DEBUG, ERROR, FATAL, INFO, WARN
		if(typeof(oIThelp.mGetAttribute(oSender, 'logged')) == 'undefined'){
			var type="", category="", siteUrl=document.location.toString(), queryString=document.location.search, parameters="";
			if(siteUrl.indexOf("?") != -1) siteUrl = siteUrl.substring(0, siteUrl.indexOf("?"));
			oXMLLib.mPostHTTPRequestByParam_LOG(sUrl,sType, sCategory, siteUrl, queryString, sParams, new function(){return function(){return false;}}, null);
			oIThelp.mAddAttribute(oSender, 'logged', 'true');
		}
	},

	mClearCacheItem : function(sAdminUrl, sCacheItem){
		var oIf = document.getElementById('ith_clearcache_frame') ? document.getElementById('ith_clearcache_frame') : document.createElement('IFRAME');
		oIf.src = sAdminUrl+'?clearcache='+sCacheItem+'&notopmenu=true'; oIf.id = 'ith_clearcache_frame'; oIf.name = 'ith_clearcache_frame';
		oIf.style.display = 'none'; oIf.style.position = 'relative'; oIf.style.left = '0px'; oIf.style.top = '0px'; oIf.style.height = '0px'; oIf.style.width = '0px';
		if(!document.getElementById('ith_clearcache_frame')) document.body.appendChild(oIf);
	},
	
	mCallBackClearCache : function(sMessage){
		var oIf = document.getElementById('ith_clearcache_frame');
		oIf.src = 'about:blank';
		if(!sMessage.contains('SUCCESS'))
			alert(sMessage);
	},
	
	mMessageBox : function (sDefaultText,sBody, sTitle, iCommandButton, iPic, sParams) {
		alert(sDefaultText+' - '+sBody+' - '+ sTitle+' - '+ iCommandButton+' - '+ iPic+' - '+ sParams);
		//var fPostBackIthMessageBox = function(oRequest, nodeId){
			var resp=sBody;
			if (!sBody) sBody = "";
			if (!sTitle) sTitle = "IThelp web application"; 
			if (!iCommandButton) iCommandButton = 0;		// 0 = OK ; 1 = OK and Error sender
			if (!iPic) iPic = 0;							// 0 = !; 1 = ?; 2 = Information;
			var iRetVal=-1;									// OK = 1; Cancel = 0; Close = 0; No = 2; 
			
			var mDrag = function() { // drag show
				return function (e) {
					e = e ? e : window.event;
					switch ( e.type ) {
						case "mousedown" :
							window.oPop	= e.currentTarget ? e.currentTarget.parentNode : e.srcElement.parentNode;
							oPop.iX		= e.clientX + oTools.mWindow ( "xscroll" );
							oPop.iY		= e.clientY + oTools.mWindow ( "yscroll" );
							oPop.iL		= oPop.offsetLeft;
							oPop.iT  	= oPop.offsetTop;
							oPop.iW		= oPop.offsetWidth;
							oPop.iH 	= oPop.offsetHeight;
							oLayout.oRoot.onmousemove = mDrag();
							oLayout.oRoot.onmouseup = mDrag();
							break;
						case "mousemove" :
							if ( oClient.bIE && e.button != 1 ) oLayout.oRoot.fireEvent ( "onmouseup" );
							else {
								var iX = e.clientX + oTools.mWindow ( "xscroll" );
								var iY = e.clientY + oTools.mWindow ( "yscroll" );
								var iH = oTools.mWindow ( "height" );
								var iW = oTools.mWindow ( "width" );
								var iO = 16;
								var iL = iX + ( oPop.iW - ( oPop.iX - oPop.iL )) > iW - iO ? iW - oPop.offsetWidth - iO : ( iX - ( oPop.iX - oPop.iL ) < 0 ? 0 : oPop.iL + iX + - oPop.iX );
								var iT = iY + ( oPop.iH - ( oPop.iY - oPop.iT )) > iH ? iH - oPop.offsetHeight : ( iY - ( oPop.iY - oPop.iT ) < 0 ? 0 : oPop.iT + iY + - oPop.iY );
								oPop.style.left = iL + "px";
								oPop.style.top = ( iT > 0 ? iT : 0 ) + "px";
								if ( e.preventDefault ) e.preventDefault ();
								else e.returnValue = false;
							}
							break;
						case "mouseup" : 
							oLayout.oRoot.onmousemove = null;
							oLayout.oRoot.onmouseup = null;
							break;
					}
					return false;
				}
			}		
			
			var mOnClickButton = function(sParam) { // click OK button
				return function(e) {
					e = e ? e : window.event;
					switch (sParam) {
						case 'OK' : 
							// TO DO modify param
							oXMLLib.mPostHTTPRequestByParam(oIThelp.mGetApplicationPath()+'/BackEnd.aspx?xslname=admin&mode=errorlog&submode=newmsglog', 'errormsg='+oIThelp.mEscape(document.getElementById("errorMsgBox").value)+";logid="+resp.replace("<content>","").replace("</content>","").trim(), function(){return false;}, null);
							break;
						case 'CANCEL' : iRetval = 0; break;
						case 'NO' : iRetval = 2; break;
					}
					oLayout["worksheet"].removeChild(oMessageBox);
				}
			}
			
			var oMessageBox = document.createElement ( "div" );
			oMessageBox.id = "messagebox";
			// Create title
			var oTitle = document.createElement ( "div" );
			oTitle.className = "title";
			var oClosePic = document.createElement ( "img" );
			oClosePic.src = oIThelp.mGetApplicationPath() + "/Wendy/Brix/Images/msgBox/icon_x.gif";
			oClosePic.onclick = mOnClickButton('CANCEL');
			oTitle.innerHTML = sTitle;
			oTitle.appendChild(oClosePic);
			oMessageBox.appendChild(oTitle);
			oTitle.onmousedown = mDrag();
			// Create body
			var oBody = document.createElement ( "div" );
			oBody.className = "body";
			var oImg = document.createElement ( "img" );
			switch (iPic) {
				case 0 : 
					oImg .src = oIThelp.mGetApplicationPath() + "/Wendy/Brix/Images/msgBox/alert.gif";
					break;
				case 1 : 
					oImg .src = oIThelp.mGetApplicationPath() + "/Wendy/Brix/Images/msgBox/question.gif";
					break;
				case 2 : 
					oImg .src = oIThelp.mGetApplicationPath() + "/Wendy/Brix/Images/msgBox/info.gif";
					break;
			}
			if (iCommandButton==1) {
				var imgondblclick = function() {
					return function(e) {
						var oSender = document.getElementById("errorMsgBox");
						var oAnother = document.getElementById("errorBox");
						oSender.style.display = oSender.style.display == "none" ? "block" :  "none";
						oAnother.style.display = oAnother.style.display == "none" ? "block" :  "none";
					}
				}
				
				oImg.ondblclick = imgondblclick();
			}
	
			var iHeight = 100;
			var iWidth = 400;
			var sLine = iCommandButton==1 ? oNames["ERROR_MESSAGE"] : sBody;
			var oText = document.createElement('div');
			oText.className = "text";
			for (var i = 0; i < sLine.length; i++) {
				if ((sLine.charCodeAt(i) == 10)) { 
					oText.innerHTML += sLine.charAt(i) + '<br/>';
					iHeight = iHeight + 14;
					oText.innerHTML += sLine.charAt(i);
				} 
				else {
					oText.innerHTML += sLine.charAt(i);
				}
			}
			oBody.appendChild(oText);
			if (iCommandButton==1) { // Error occours
				iHeight = iHeight + 180;
				var oErrorBox = document.createElement("textarea");
					oErrorBox.id = "errorBox";
					oErrorBox.setAttribute("disabled","disabled");
					oErrorBox.setAttribute("name","mytextarea1");
					oErrorBox.setAttribute("wrap","PHYSICAL");
					oErrorBox.style.display = "none";
					oErrorBox.value = sBody + "\n";
					oBody.appendChild(oErrorBox);
				var oErrorMessageBox = document.createElement("textarea");
					oErrorMessageBox.id = "errorMsgBox";
					oErrorMessageBox.setAttribute("enabled","true");
					oErrorMessageBox.setAttribute("name","mytextarea2");
					oErrorMessageBox.setAttribute("wrap","PHYSICAL");
					oErrorMessageBox.style.display = "block";
					oErrorMessageBox.value = sDefaultText;
					oBody.appendChild(oErrorMessageBox);
			}
			oMessageBox.style.height = (iHeight) + "px";
			oMessageBox.style.width = (iWidth) + "px";
			oBody.appendChild(oImg);
			oMessageBox.appendChild(oBody);
	
			// Create buttons
			var oButtons = document.createElement ( "div" );
			oButtons.className = "buttons";
			switch (iCommandButton) {
				case 0 || 1: //only OK
					var oButtonOK = document.createElement ( "div" );
					oButtonOK.className = "button";
					oButtonOK.innerHTML = oIThelp.mGetLocalName("BUTTON_OK");
					oButtonOK.onclick = mOnClickButton('OK');
					oButtons.appendChild(oButtonOK);
					break;
			}
			oMessageBox.appendChild(oButtons);
	
			var zIndex=oPoppers.mGetZIndex();
	
			alert(oMessageBox);
			oLayout["worksheet"].appendChild(oMessageBox);
			oMessageBox.style.zIndex = zIndex + 1;
			oClosePic.style.left = (oMessageBox.offsetWidth - 20) + 'px';
			var iL = 0.5 * ( oTools.mWindow ( "width" ) -  oMessageBox.offsetWidth );
			var iT = 100;
			oMessageBox.style.left	= iL + "px";
			oMessageBox.style.top	= ( iT > 0 ? iT : 0 ) + "px";
			oMessageBox.onselectstart = function() { return false };
			oButtons.style.left =  ((oMessageBox.offsetWidth / 2) - 34) + "px";
			oButtons.style.top =  (oMessageBox.offsetHeight - 35 ) + "px";
		//}
		/*var page = new oIThelp.pageQuery(window.location.search);
		var globalId=page.getValue('globalid');
		// TO DO modify param
		oXMLLib.mPostHTTPRequestByParam(oIThelp.mGetApplicationPath()+'/BackEnd.aspx?xslname=admin&mode=errorlog&submode=newlog&globalid='+globalId, 'errormsg='+oIThelp.mEscape(sBody)+";params="+sParams, fPostBackIthMessageBox, null);*/
	},
	
	mSet_Cookie : function ( name, value, expires, path, domain, secure ){
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		
		/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
		*/
		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 : "" ) +
		( ( secure ) ? ";secure" : "" );
	},
	
	mGet_Cookie : function( name ) {
		var start = document.cookie.indexOf( name + "=" );
		var len = start + name.length + 1;
		if ( ( !start ) &&	( name != document.cookie.substring( 0, name.length ) ) ) return null;
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
	},
	
	mDelete_Cookie : function ( name, path, domain ) {
		if ( Get_Cookie( name ) ) document.cookie = name + '=' + ( ( path ) ? ';path=' + path : '') + ( ( domain ) ? ';domain=' + domain : '' ) + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	}	
	
}

var oXMLLib = {
		// Constants
	sIEPrefix4XSLParam : "xsl:",
	sDOMProgId : "",
	sXMLHTTPProgId : "",
	mInit : function () {
		
		// Initializes constants
		oXMLLib.sDOMProgId=oXMLLib.mPickRecentProgId(["Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"], [["SelectNodes", 2],["TransformNode", 2]]);
		oXMLLib.sXMLHTTPProgId=oXMLLib.mPickRecentProgId(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]);
		oXMLLib.sThreadedDomProgId=oXMLLib.mPickRecentProgId(["Msxml2.FreeThreadedDOMDocument.5.0", "MSXML2.FreeThreadedDOMDocument.4.0", "MSXML2.FreeThreadedDOMDocument.3.0"]);
		oXMLLib.sXSLTemplateProgId=oXMLLib.mPickRecentProgId(["Msxml2.XSLTemplate.5.0", "Msxml2.XSLTemplate.4.0", "MSXML2.XSLTemplate.3.0"], [["XSLTProc", 2]]);
		
		if(window.XMLHttpRequest) 
			oXMLLib.mGetXMLHttpRequest=function() {
				return new window.XMLHttpRequest;
			}
		else 
			oXMLLib.mGetXMLHttpRequest=function() {
				return new ActiveXObject(oXMLLib.sXMLHTTPProgId);
			}
		
	},
	
	
	mPickRecentProgId : function(idList, enabledList){
        // found progId flag
        var bFound = false;
        var ex, o2Store;
        for(var i=0; i < idList.length && !bFound; i++){
            try{
                var oDoc = new ActiveXObject(idList[i]);
                o2Store = idList[i];
                bFound = true;
                for(var j=0;j<enabledList.length;j++)
                    if(i <= enabledList[j][1])
                        oXMLLib["bEnabled"+enabledList[j][0]] = true;
            }catch (oException){
                ex=oException;
            };
        };
        if (!bFound)
            //throw "Could not retreive a valid progID of Class: " + idList[idList.length-1]+". (original exception: "+ex+")";
        idList = null;
        return o2Store;
    },
    
    mGetHTTPRequest: function(url, proc) 
	{
		var oRequest=oXMLLib.mGetXMLHttpRequest();
		oRequest.open("GET", url, true);
		// Initiate handler
		if (proc!=null) oRequest.onreadystatechange=proc;
		else {
			oRequest.onreadystatechange=function() {
			  if (oRequest.readyState==4) {
				if (oRequest.status == 200) {
					alert(oRequest.responseText);
				}
				else {
					alert("There was a problem retrieving the XML data:\n" + oRequest.statusText);
				}
			  }
			}
		}
		oXMLLib.oRequest.send(null);
	},
    
    mPostHTTPRequestWS : function(url, soapAction, wsBody, proc, nodeId) {
		//url = url.contains('&amp;') ? url.replaceAll('&amp;', '&') : url;
		//alert(url + ' - ' + soapAction + ' - ' + wsBody + ' - ' +  proc);
		
		//if (notrim==null) notrim=false;
		/*var aParams=params.split(';');
		var aParam*/
		var body='<?xml version="1.0" encoding="utf-8"?>';
		body+='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
		body+='<soap:Body>';
		body+=wsBody;
		body+='</soap:Body>';
		body+='</soap:Envelope>';
	
		//url=url.replaceAll('&amp;','&');
		var oRequest=oXMLLib.mGetXMLHttpRequest();
		oRequest.open("POST", url ,true);
		oRequest.setRequestHeader('SOAPAction',soapAction);
		oRequest.setRequestHeader('Content-Type','text/xml; charset=utf-8');
		
		//alert(body);
		// Initiate handler
		oRequest.onreadystatechange=function() {
		  if (oRequest.readyState==4) {
			if (oRequest.status == 200) {
				if (proc!=null) proc(oRequest, nodeId, "");
				else {
					oIThelp.setStatusBar("proc not exist (mPostHTTPRequestWS)");
				}
			}
			else {
				if (proc!=null) proc(oRequest, nodeId, "There was a problem retrieving the data:\n");
				else {
					oIThelp.setStatusBar("proc not exist (mPostHTTPRequestWS)");
				}
			}
		  }
		}
		
		oRequest.send(body);
	},
    
    mCallBackEnd : function(url, params, proc, nodeId, trim) {
		url = url.contains('&amp;') ? url.replaceAll('&amp;', '&') : url;
		//alert(url + ' - ' + params + ' - ' +  proc);
		var body = "";
		if (trim==null) trim=true;
		var aParams=params.splitStr('@sep');
		var aParam;
		body="<params>"
		if (params!='') {
			var i=0;
			while (aParams[i]!=null) {
				aParam=aParams[i].splitStr('@eq');
				var sParamValue = oXMLLib.mXMLEscape(aParam[1]);
				body+="<param>";
				body+="<key>"+oXMLLib.mXMLEscape(aParam[0].trim())+"</key>";
				body+="<value>"+(trim?sParamValue.trim():sParamValue)+"</value>";
				body+="</param>";
				i++;
			}
		}
		body+="</params>";
		url=url.replaceAll('&amp;','&');
		var oRequest=oXMLLib.mGetXMLHttpRequest();
		oRequest.open("POST", url ,true);
		//alert(body);
		// Initiate handler
		oRequest.onreadystatechange=function() {
      var aborted = false;
      try {
        aborted = (oRequest.readyState == 4 && oRequest.status == 0);
      } catch (ex) {
        // Mozilla gets an exception throw here - you abort the thread, it calls
        // the readystatechange as part of the abort, and you're not
        // allowed to look at the status field. So, if we get one
        // just assume the request is aborted.
        aborted = true;
      }

      if (oXMLLib.mGenericCallback(oRequest) || (aborted)) {
        if (!aborted) {
          if (proc!=null) proc(oRequest, nodeId);
        }
        // Note that this is not just a simple detach call. IE has a bug where
        // it'll crash if we detach in the middle of this routine. So, we need to
        // delay a tiny bit, to get out of here, before we do the detach. Without
        // this, IE crashes badly.
        window.setTimeout(function() {
          // Get rid of circular reference leaks
          // Sometimes we see a readyState of 0 here, as though the object was being
          // reused. So, to be on the safe side, dont clear the handler in that case.
          if (oRequest.readyState == 4) {
            oRequest.onreadystatechange = oXMLLib.mFoofunc;
          }
        }, 10);
      }
      else if(aborted){
				alert("There was a problem retrieving the XML data:\n" + oRequest.statusText);
      }
		
		  /*if (oRequest.readyState==4) {
			if (oRequest.status == 200) {
				if (proc!=null) proc(oRequest, nodeId);
				else {
					alert(oRequest.responseText);
				}
			}
			else {
				alert("There was a problem retrieving the XML data:\n" + oRequest.statusText);
			}
		  }*/
		}
		oRequest.send(body);
	},

    mFoofunc : function() {},
  
    mGenericCallback : function (req) {
      return req.readyState == 4 && req.status == 200;
    },
    mXMLEscape : function(text) {
		return text.replaceAll('<', '&lt;').replaceAll('>','&gt;').replaceAll('&','&amp;').replaceAll('"','&quot;').replaceAll("'",'&apos;');
	},
	
    mXMLUnEscape : function(text) {
		return text.replaceAll('&lt;', '<').replaceAll('&gt;', '>').replaceAll('&amp;', '&').replaceAll('&quot;', '"').replaceAll('&apos;', "'");
	}
}

var oAdmin = {
	login : function (oUserName, oPassword, schoolId) {
		if (oUserName.value=='') {
			alert('User Name required');
			return false;
		}
		if (oPassword.value=='') {
			alert('Password required');
			return false;
		}
		oIThelp.mLoading('login', oNames['LOGING_IN']);
		var mLoginPostBack = function (oRequest, oNode) {
			var response=oRequest.responseText.substring(9, oRequest.responseText.length-10).trim();
			oIThelp.mStopLoading('login');
			if (response!='SUCCESS') alert(response);
			else {
				var page = new oIThelp.pageQuery(window.location.search);
				var aGlobals;
				var globalId=page.getValue('globalid');
				if (globalId=='false') {
					aGlobals=[-1, -1, -1, -1];
				}
				else {
					aGlobals=globalId.split('_');
				}
				oIThelp.mRedirectWendy({}, 'languageid='+aGlobals[1]+'&taughtlanguageid='+aGlobals[2]+'&yearid='+aGlobals[3]);
			}
		}
		var page = new oIThelp.pageQuery(window.location.search);
		var globalId=page.getValue('globalid');
		// TO DO modify param
		oXMLLib.mPostHTTPRequestByParam(oIThelp.mGetApplicationPath()+'/BackEnd.aspx?xslname=admin&mode=login&globalid='+globalId, 'username='+oUserName.value+';password='+oPassword.value+';schoolid='+schoolId, mLoginPostBack, null, true);
	},
	
	logout : function() {
		var mLogoutPostBack = function (oRequest, oNode) {
			var response=oRequest.responseText.substring(9, oRequest.responseText.length-10).trim();
			if (!response.contains('SUCCESS')) alert(response);
			else {
				// window.location.href = oIThelp.mGetApplicationPath()+'/Render.aspx?menuid=6&schoolid='+response.substring(8)+'&languageid='+oNames['LANGUAGEID'];
				oIThelp.mRedirectWendy({menuId : 6});
			}
		}
		var page = new oIThelp.pageQuery(window.location.search);
		var globalId=page.getValue('globalid');
		// TO DO modify param
		oXMLLib.mPostHTTPRequestByParam(oIThelp.mGetApplicationPath()+'/BackEnd.aspx?xslname=admin&mode=logout&globalid='+globalId, '', mLogoutPostBack, null);
	}
}

var oDebug = {
	print : function(oNode) {
		var message='';
		message+='tagName: '+oNode.tagName+'; id:'+oNode.id+'; className:'+oNode.className+'\n  style:\n';
		/*var style=oNode.style;
		
		for (var st in style) {
			message+=style.item(i)+'; ';
		}*/
		return message;
	},
	
	alertA : function(a) {
		var m='';
		for (word in a) {
			if (typeof(a[word])=='function') {
				m+=(m==''?'':' ')+word+': function() {code}';
			}
			else {
				m+=(m==''?'':' ')+word+': '+a[word];
			}
		}
		alert(m);
	},
	
	mSleep : function(ms) {
		//alert('df');
		var dialogScript =
           'window.setTimeout(' +
           ' function () { window.close(); }, ' + ms + ');';
        //alert(oClient.oClient.bIEwin);
		if (oClient.bIEwin) {
			//alert('df');
			var result = window.showModalDialog(
				'javascript:document.writeln(' +
				'"<script>' + dialogScript + '<' + '/script>")');
		}
		else {
			java.lang.Thread.sleep(ms);
			/*openDialog(
			   'javascript:document.writeln(' +
				'"<script>' + dialogScript + '<' + '/script>"',
			   'pauseDialog', 'modal=1,width=10,height=10');*/
			/*d = new Date() //today's date
			while (1)
			{
				mill=new Date() // Date Now
				diff = mill-d //difference in milliseconds
				if( diff > ms ) {break;}
			}*/
		}
	}
}

var oITHNavs = {
	aNavs		: [],
	oActPopUp	: null,
	
	mInit : function( parent ){
		return function(){
			if(oIThelp.getElementById(parent)){
				oITHNavs.aNavs = oIThelp.getAllElementsByClassName(oIThelp.getElementById(parent), 'ith_PopUp');
				oTools.mMap(oITHNavs.aNavs, oITHNavs.mSetup);
			}
		}
	},
	
	mSetup : function(oPopUp){
		oPopUp.iInit = 0;
		oPopUp.iH = 0;
		oPopUp.oTargets = [];
		oPopUp.sButton = '';
		if(oPopUp.parentNode != document.body)
			document.body.appendChild(oPopUp);
		oPopUp.iRowHeight = parseInt(oIThelp.mGetAttribute(oPopUp, 'rowheight'));
		oPopUp.iDropSpeed = parseInt(oIThelp.mGetAttribute(oPopUp, 'dropspeed'));
		
		if(oIThelp.mGetAttribute(oPopUp, 'needopacity') && oIThelp.mGetAttribute(oPopUp, 'needopacity') == 'true') oIThelp.mAddClass(oPopUp, 'needOpacity');
		oPopUp.oTable = oPopUp.getElementsByTagName('TABLE').item(0);
		oIThelp.mAddClass(oPopUp, 'PopUp_hide');
		oIThelp.mAddClass(oPopUp.oTable, 'PopUp_hide');
		var aTargets = oIThelp.mGetAttribute(oPopUp, 'params').split('@ITHSEP@');
		for(var t = 0; t < aTargets.length; t++)
			oITHNavs.mSetupTarget(oPopUp, aTargets[t].trim());
		oPopUp.aItems = oPopUp.oTable.rows;
		if(oPopUp.aItems.length == 0) alert('No menu items!');
		else oPopUp.style.width = (parseInt(oPopUp.oTable.getElementsByTagName('COL')[0].width) + parseInt(oPopUp.oTable.getElementsByTagName('COL')[1].width) + 2) + 'px';
		for(var i = 0; i < oPopUp.aItems.length; i++)
			oITHNavs.mSetupItem(oPopUp.aItems[i], oPopUp.oTable);
		
	},
	
	mSetupItem : function(oItem, oTable){
		var aCols = oTable.getElementsByTagName('COL');
		oItem.setWidth	= parseInt(aCols[0].width) + parseInt(aCols[1].width);
		oItem.cells[0].setWidth = parseInt(aCols[0].width);
		oItem.cells[1].setWidth = parseInt(aCols[1].width);
		oItem.onmouseover = function(){oIThelp.mAddClass(this, 'popuptrover');}
		oItem.onmouseout = function(){oIThelp.mRemoveClass(this, 'popuptrover');}
	},
	
	mSetupTarget : function(oPopUp, sParams){
		/*
		sParams eg:
		<target Dom Id>;iex=<x correction from the target object's absolute position (int)>;iey=<y correction from the target object's absolute position>;ffx=<x correction from the target object's absolute position (int)>;ffy=<y correction from the target object's absolute position>;button=<R/L>;iframe=<T/F>
		*/
		var oParams = {}, aParams = sParams.split(';');;
		for(var p = 0; p < aParams.length; p++)
			oParams[aParams[p].split('=')[0]] = aParams[p].split('=')[1];
		
		var sId = oParams['targetid'];
		var aClasses = oParams['targetclass'];
		var aTargets = [];
		if(oParams['targetclass']){
			aTargets = oIThelp.getAllElementsByClassName(document, oParams['targetclass'].trim());
		}
		if(oParams['targetid']){
			aTargets.push(document.getElementById(oParams['targetid'].trim()));
			if(!document.getElementById(oParams['targetid'].trim())){ alert('Target "'+oParams['targetid'].trim()+'" does not exist!'); return false;}
		}
		for(var o = 0; o < aTargets.length; o++){
			var oTarget  = aTargets[o];
			oTarget.oParams = oParams;
			oTarget.iCorX = oClient.bIE ? parseInt(oTarget.oParams['iex']) : parseInt(oTarget.oParams['ffx']);
			oTarget.iCorY = oClient.bIE ? parseInt(oTarget.oParams['iey']) : parseInt(oTarget.oParams['ffy']);
			oTarget.actionButton = oTarget.oParams['button'];
			oTarget.isIframeNeed = oTarget.oParams['iframe'];
			oTarget.bIsPopUpAtMouse = oTarget.oParams['popupatmouse'];
			oTarget.sRelativeFrom = oTarget.oParams['relativefrom'] ?  oTarget.oParams['relativefrom'] : '';
			oTarget.oRefPopUp = oPopUp;
			if(oTarget.actionButton == 'R')
				oTarget.oncontextmenu = oITHNavs.mPopUp;
			else
				oTarget.onclick = oITHNavs.mPopUp;
			if(oTarget.isIframeNeed == 'T' && oClient.bIE){
				var oIf = document.createElement('IFRAME');
				oIf.src="App/Cuba/Images/spacer.gif";
				oIf.frameBorder = '0';
				oIf.scrolling = 'no';
				oIf.style.display = 'none';
				oIf.width = '0'
				oIf.height = '0';
				oTarget.parentNode.appendChild(oIf);
				oIThelp.mAddClass(oIf, 'ith_PopUp_frame');
				if(oIThelp.mGetAttribute(oPopUp, 'needopacity') && oIThelp.mGetAttribute(oPopUp, 'needopacity') == 'true') oIThelp.mAddClass(oIf, 'needOpacity_frame');
				oTarget.oIframe = oIf;
			}
			oPopUp.oTargets.push(oTarget);
		}
	},
	
	mPopUp : function(e){
 		e = e ? e : window.event;
		if(this.actionButton == 'R') e.cancelBubble=true;
		if(this.actionButton == 'R' && oITHNavs.oActPopUp != null) oITHNavs.mPopDown();
		var pX = oITHNavs.mFPX(this), pY = oITHNavs.mFPY(this), oRefPopUp = this.oRefPopUp; oActTarget = this;
		if(this.bIsPopUpAtMouse == 'T'){
			pX = 0;pY = 0;
			if(this.sRelativeFrom != '' && oClient.bIE){
				var oRelativeFrom = document.getElementById(this.sRelativeFrom);
				pX = oRelativeFrom.scrollLeft;
				pY = oRelativeFrom.scrollTop;
			}
			else if(!oClient.bIE){
				pX = e.pageX;
				pY = e.pageY;
			}
			if(oClient.bIE){
				pX = e.clientX + document.body.scrollLeft;
				pY = e.clientY + document.body.scrollTop;
			}
		}
		// TODO: Left-Bottom corner has done. Left-Top, Right-Top. Right-Bottom corners are missing.
		var iScreenBottom = oTools.mWindow ( "height" ) + document.body.scrollTop;
		var iApproxPopupBottom = (oRefPopUp.aItems.length * oRefPopUp.iRowHeight) + pY + this.iCorY;
		oRefPopUp.sButton = this.actionButton;
		oRefPopUp.style.left = (pX + this.iCorX)+'px';
		if(iApproxPopupBottom > iScreenBottom)
			oRefPopUp.style.top = (pY - (oRefPopUp.aItems.length * oRefPopUp.iRowHeight))+'px';
		else
			oRefPopUp.style.top = (pY + this.iCorY)+'px';
		if(this.oIframe){
			this.oIframe.style.left = oRefPopUp.style.left;
			this.oIframe.style.top = oRefPopUp.style.top;
			this.oIframe.width = (parseInt(oRefPopUp.oTable.getElementsByTagName('COL')[0].width) + parseInt(oRefPopUp.oTable.getElementsByTagName('COL')[1].width) + 2).toString();
			this.oIframe.style.display = 'block';
		}	
		oRefPopUp.iH = 0;
		if(oITHNavs.oActPopUp != null && oITHNavs.oActPopUp.sButton == 'L'){oRefPopUp.iInit = 1; oITHNavs.mPopDown();}
		oITHNavs.oActPopUp = oRefPopUp;
		oITHNavs.oActPopUp.oActTarget = this;
		oRefPopUp.style.height = '0px';
		if(oClient.bIE){ 
			document.attachEvent("onclick", oITHNavs.mPopDown);
			window.attachEvent("onscroll", oITHNavs.mPopDown);
		}
		else{
			document.addEventListener('click',oITHNavs.mPopDown,false);
			window.addEventListener('scroll',oITHNavs.mPopDown,false);
		}
		oIThelp.mRemoveClass(oRefPopUp, 'PopUp_hide');
		var iPopUpHeight = 0;
		for(var i = 0; i < oRefPopUp.aItems.length; i++){
			oRefPopUp.aItems[i].style.display = 'block'; 
			oRefPopUp.aItems[i].cells[0].style.width = oRefPopUp.aItems[i].cells[0].setWidth + 'px';
			oRefPopUp.aItems[i].cells[1].style.width = oRefPopUp.aItems[i].cells[1].setWidth + 'px';
			oRefPopUp.aItems[i].style.width = oRefPopUp.aItems[i].setWidth + 'px'; 
			iPopUpHeight = iPopUpHeight + oRefPopUp.iRowHeight;
		}
		if (oRefPopUp.iDropSpeed == 0) {
			oIThelp.mRemoveClass(oRefPopUp.oTable, 'PopUp_hide');
			if(!oClient.bIE) oRefPopUp.style.height = (iPopUpHeight + 2) + 'px';
		}
		else {
			var h = setInterval(function(){
			if(oRefPopUp.iH > iPopUpHeight){oIThelp.mRemoveClass(oRefPopUp.oTable, 'PopUp_hide'); clearInterval(h);}
			oRefPopUp.iH = oRefPopUp.iH + 2;
			oRefPopUp.style.height = (oRefPopUp.iH) + 'px';
			if(oActTarget.oIframe) oActTarget.oIframe.height = oRefPopUp.iH.toString();
			}, oRefPopUp.iDropSpeed);
		}
		return false;		
	},

	mPopDown : function(){
		if(oITHNavs.oActPopUp.sButton == 'L' && oITHNavs.oActPopUp.iInit == 1){
			oITHNavs.oActPopUp.iInit = 0;
			oITHNavs.mHidePopUp();
		}
		else if(oITHNavs.oActPopUp.sButton == 'L' && oITHNavs.oActPopUp.iInit == 0){ oITHNavs.oActPopUp.iInit = 1;}
		else{ oITHNavs.mHidePopUp(); }
	},
	
	mHidePopUp : function(){
		oIThelp.mAddClass(oITHNavs.oActPopUp, 'PopUp_hide');
		oIThelp.mAddClass(oITHNavs.oActPopUp.oTable, 'PopUp_hide');
		if(oITHNavs.oActPopUp.oActTarget.isIframeNeed == 'T' && oClient.bIE){
			var oIf = oITHNavs.oActPopUp.oActTarget.oIframe;
			oIf.frameBorder = '0';
			oIf.scrolling = 'no';
			oIf.style.display = 'none';
			oIf.width = '0';
			oIf.height = '0';
		}			
		if(oClient.bIE){
			document.detachEvent("onclick", oITHNavs.mPopDown);
			window.detachEvent("onscroll", oITHNavs.mPopDown);
		}
		else{
			document.removeEventListener("click", oITHNavs.mPopDown, false);
			window.removeEventListener("scroll", oITHNavs.mPopDown, false);
		}
		oITHNavs.oActPopUp = null;
	},

	mFPX : function(obj){
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	},
	
	mFPY : function(obj){
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}
	
}

var oCubaSPS = {
	aMenus	: {},
	aSurveies: {},
	oSurveyPopper : null,
	mInit	: function () {
			oCubaToolBar = document.getElementById('topbar');
			if(oCubaToolBar != null){
				var aMenus = oCubaToolBar.getElementsByTagName('li');
				for(var i = 0; i < aMenus.length; i++)
					oCubaSPS.mSetupCubaSPS(aMenus[i]);
			}

			if(oCubaSPS.mGetUserName() != '')
				document.title += '   ( ' + oCubaSPS.mGetUserName() + '  -  ' + oCubaSPS.mGetUserLogonName() + ' )';
	},
	
	mSetupCubaSPS	: function (oMenuLink) {
		oMenuLink.oLink		= oMenuLink.getElementsByTagName('a')[0];
		oMenuLink.oLink.onclick = function () { // Add log event to the menulink's onclick
			oIThelp.mWsAddLog(oMenuLink.oLink, oCubaSPS.mGetLogWSURL(), 'INFO', 'MENUCLICK','menu_url='+oIThelp.mGetAttribute(oMenuLink.oLink, 'href'));
		}
	},
	
	mGetLogWSURL	: function(){
		return document.getElementById('cubaspslogwsurl') == null ? '' : document.getElementById('cubaspslogwsurl').value;
	},
	
	mGetUserName	: function(){
		return document.getElementById('cubaspsmenuusername') == null ? '' : document.getElementById('cubaspsmenuusername').value;
	},

	mGetUserLogonName	: function(){
		return document.getElementById('cubaspsmenuuserlogonname') == null ? '' : document.getElementById('cubaspsmenuuserlogonname').value;
	},

	mWriteProductContent : function (oRequest, nodeId){
		var beginContent=oRequest.responseText.indexOf('&lt;content&gt;');
		var endContent=oRequest.responseText.indexOf('&lt;/content&gt;');
		var response=oRequest.responseText.substring(beginContent+15, endContent);
		response=response.replaceAll('&lt;','<').replaceAll('&gt;','>');
		var oTarget = document.getElementById(nodeId);
		oTarget.innerHTML = response.length <= 75 ? oNames['FOLDER_IS_EMPTY'] : response;
		oIThelp.initializeJavascripts(oTarget);
	},
	
	mAddProductToShoppingCart : function(wsUrl, siteUrl, iId, sName, sFolder, productTypeId){
		/*var sQuantity = document.getElementById('ith:product_'+iId).value, iQuantity = null;
		if (sQuantity!='' && !/^[0-9]+$/.test( sQuantity)){ alert(oNames['QUANTITY_MUST_BE_AN_INTEGER'] + '!'); return false;}
		else if (sQuantity == '' || parseInt(sQuantity) <= 0 || parseInt(sQuantity) > 9) { alert(oNames['ADD_REASONABLE_QUANTITY'] + ' (<10)!'); return false;}
		else {iQuantity = parseInt(sQuantity);}*/
		var oGrid=document.getElementById('ith:grdShoppingCart2');
		if (oGrid.oBody.oTable.oTBody.aRows.length<1) {
			if(oGrids.mIsExistRow('ith:grdShoppingCart2', iId) == null) {
				oGrid.mInsertRow(iId, 'productName='+sName+';quantity=1;folderRef='+sFolder+';productTypeId='+productTypeId);
				
				if (typeof(provisionProductType)!='undefined') {
					provisionProductType('add', productTypeId);
				}
			}
			else {
				//oGrid.mUpdateRow(iId, 'productName='+sName+';quantity='+(iQuantity+parseInt(oGrids.mIsExistRow('ith:grdShoppingCart2', iId).cells[1].firstChild.nodeValue))+';folderRef='+sFolder+';productTypeId='+productTypeId);
				}
			oCubaSPS.mBuildCartData();
		}
	},
	
	mModifyItemQuantity : function(iRowId){
		var oRow = oGrids.mGetSelectedRowsToArray('ith:grdShoppingCart2')[0], value = '', iQuantity = null, newParams='' ;
		for(var i = 0; i < oRow['params'].split(';').length; i++){
			if(oRow['params'].split(';')[i].split('=')[0] == 'quantity') value = oRow['params'].split(';')[i].split('=')[1];
			else newParams += newParams != '' ? ';' + oRow['params'].split(';')[i] : oRow['params'].split(';')[i];
		}
		var sQuantity=window.prompt("please enter the quantity", value);
		if(sQuantity!=null){
			if (sQuantity!='' && !/^[0-9]+$/.test( sQuantity)){ alert(oNames['QUANTITY_MUST_BE_AN_INTEGER'] + '!'); return false;}
			else if (sQuantity == '' || parseInt(sQuantity) <= 0 || parseInt(sQuantity) > 9) { alert(oNames['ADD_REASONABLE_QUANTITY'] + ' (<10)!'); return false;}
			else {iQuantity = parseInt(sQuantity);}
			var oGrid=document.getElementById('ith:grdShoppingCart2');
			oGrid.mUpdateRow(iRowId, newParams+';quantity='+iQuantity);
			oCubaSPS.mBuildCartData();
		}
	},
	
	mBuildCartData : function(){
		var oBasketData = document.getElementById('ith:@cartData');
		oBasketData.value = '';
		var aContent = oGrids.mGetAllRowsToArray('ith:grdShoppingCart2');
		for(var i = 0; i < aContent.length; i++)
			oBasketData.value += oBasketData.value != '' ? '@ITHSEP@' + 'productId='+aContent[i]['rowid']+';'+aContent[i]['params'] : 'productId='+aContent[i]['rowid']+';'+aContent[i]['params'];
		oCubaSPS.mBuildGridFromCartData('ith:grdShoppingCart1');
		oCubaSPS.mBuildCartBeanXML();
	},
	
	mBuildGridFromCartData : function(sGridId){
		var sContent = document.getElementById('ith:@cartData').value;
		var oGrid=document.getElementById(sGridId);
		if (oGrid!=null) {
			while(oGrids.mGetAllRowsToArray(sGridId)[0]!=null){
				oGrid.mRemoveRow(oGrids.mGetAllRowsToArray(sGridId)[0]['rowid']);
			}
			for(var i = 0; i < sContent.split('@ITHSEP@').length; i++){
				if(sContent.split('@ITHSEP@')[i] != '') 
					oGrid.mInsertRow(sContent.split('@ITHSEP@')[i].split(';')[0].split('=')[1], sContent.split('@ITHSEP@')[i]);
			}
		}
	},
	
	mRemoveProductFromShoppingCart : function() {
		try{
			var oRow = oGrids.mGetSelectedRows('ith:grdShoppingCart2')[0];
			var oGrid=document.getElementById('ith:grdShoppingCart2');
			//alert(typeof(provisionProuctType)!='undefined');
			var productTypeId = oGrid.mGetCellByName(oRow.id, 'productTypeId').firstChild.nodeValue;
			if (typeof(provisionProductType)!='undefined') {
				var num=0;
				var aRows = oGrid.oBody.oTable.oTBody.aRows;
				for (var i=0;i<aRows.length;i++) {
					if (aRows[i].id!=oRow.id && productTypeId == oGrid.mGetCellByName(aRows[i].id, 'productTypeId').firstChild.nodeValue) { num++; break; }
				}
				if (num==0) provisionProductType('remove', productTypeId);
			}
			
			oGrid.mRemoveRow(oRow.id);
			oCubaSPS.mBuildCartData();
			
		}
		catch(e){alert(oNames['NO_PRODUCT_HAS_BEEN_SELECTED'] + '!');}
	},
	
	mSetSelectedTreeNode : function(sUrl){
		var oTree = document.getElementById('ith:productTree'), aNodes = oTree.getElementsByTagName('A');
		for(var i = 0; i < aNodes.length; i++){
			oIThelp.mRemoveClass(aNodes[i], 'selected');
			if(oIThelp.mGetAttribute(aNodes[i], 'identifier')){
				if(oIThelp.mGetAttribute(aNodes[i], 'identifier') == sUrl) oIThelp.mAddClass(aNodes[i], 'selected');
			}
		}
	},
	
	mBuildCartBeanXML : function(){
		var sBean = '<products>', aContent = document.getElementById('ith:@cartData').value.split('@ITHSEP@');
		for(var i = 0; i < aContent.length; i++){
			if(aContent[i].split(';').length > 0){
				if(aContent[i].split(';')[0].split('=')[1]){
					sBean += '<element>';
					for(var ii = 0; ii < aContent[i].split(';').length; ii++){
						if(aContent[i].split(';')[ii].split('=')[0]=='productId') sBean += '<id>' + aContent[i].split(';')[ii].split('=')[1] + '</id>';
						else if(aContent[i].split(';')[ii].split('=')[0]=='productName') sBean += '<title>' + aContent[i].split(';')[ii].split('=')[1] + '</title>';
						else if(aContent[i].split(';')[ii].split('=')[0]=='quantity') sBean += '<quantity>' + aContent[i].split(';')[ii].split('=')[1] + '</quantity>';
						else if(aContent[i].split(';')[ii].split('=')[0]=='folderRef') sBean += '<folderRef>' + aContent[i].split(';')[ii].split('=')[1] + '</folderRef>';
						else if(aContent[i].split(';')[ii].split('=')[0]=='productTypeId') sBean += '<productTypeId>' + aContent[i].split(';')[ii].split('=')[1] + '</productTypeId>';
					}
					sBean += '</element>';
				}
			}
		}
		sBean += '</products>';
		//alert(sBean);
		document.getElementById('ith:@cartBean').value = sBean;
	}
}

oGod.mOnload ( oIThelp.mInit );
oGod.mOnload ( oXMLLib.mInit );
//oGod.mOnload ( oCubaSPS.mInit );
oGod.mOnload ( oITHNavs.mInit('worksheet') );

