//CollectGarbage();
var unload = -1;	//trigger to hide or leave visible the context menu
var spd = 1.5;		//time to leave the context menu up without action in seconds
var hold = 0;		//Delay further execution until complete
var updateTmr=null;
var actnTmr=new Array();
var actnMv=20;
var clientHeight =document.body.clientHeight-2; 
var clientWidth =document.body.clientWidth-2;
var lastSize;
var lastPos;
var originalPos;
var lms=false;
var originalSize;
var sessionKeepAlive;
var events;
var clientHeight =document.body.clientHeight-2; 
var clientWidth =document.body.clientWidth-2;

function animEvent(func,start,end,time){
	this.value=start;
	this.time=time;
	this.end=end;
	this.start=start;
	this.func=func;
	this.step=((start-end)*Math.abs(start-end))/time;
	this.nextStep=function(){		
		this.value=this.value-this.step;
		
		if((start<end && this.value<this.end) || (start>end && this.value>this.end)){
			this.func();
			beginAnimation(this.func,this.start,this.end,this.time);
		}else{
			this.value=this.end;
			this.func();
		}
		return false;
	}
	
}
function beginAnimation(func,start,end,time){
	
	if(!events||events==null||events.start!=start){			
		events=null;
		events=new animEvent(func,start,end,time);
	}
	setTimeout('events.nextStep()',1);
}
function newScriptElement(){
	/***********************************************************************************************************
	Purpose: Function to standardize script creation for database interaction; Appends javascript element to the 
				head tag
	Usage: Function takes first argument from argument array as url of script, each successive argument is 
			appended to the parameter string followed with an &, finally a timestamp is appended to eliminate 
			caching issues
	Createdby: Joshua Boyce
	CreatedOn: 12/28/2005
	LastEdited: 12/28/2005
		*********************************************CHANGES*********************************************
		
	***********************************************************************************************************/
	var url=null;
	var dte = new Date();
	var id;
	var old  = document.getElementById('fnc' + dte.valueOf());
		if (old){
			do{
				dte = new Date();
				old  = document.getElementById('fnc' + dte.valueOf());
			}while(old)
		}	
	if(arguments.length){
		
		url = arguments[0] + "?"
		for(var i=1;i<arguments.length;i++){
			if(arguments[i]!="debug"){
			url += arguments[i] + "&";
			}else{
				var elem = document.createElement("div");
				if(document.getElementById("debugArea")){
					//clearElements(document.getElementById("debugArea"));
				}
				gBody().appendChild(elem);
				elem.innerHTML = url + "<br>";
				
			}
		}
		url += "dte=" + dte.valueOf();	
		//alert(url);
		try{
		var head = document.getElementsByTagName('head').item(0);
			
		var s=document.createElement('script');
		id = 'fnc' + dte.valueOf()
		void(s.id = id );
		void(s.language='javascript');
		void(s.type='text/javascript');
		void(s.src=url);
		//alert(url);
		//alert(head + " " +s.src);		
		//s.defer = true;		

		//alert(s.id);
		//alert("here");
		void(head.appendChild(s));	
		//alert(head.children.length);
		sRn=null;
		head=null;
		old=null;
		s=null;
		}catch(error){
			alert(error.description)
		}
		return id;
	}
}
/***********************************BEGIN XML PROCESSING CODE*******************************************/
var req=new Array();
function loadXMLDoc() {
	try{
	var lastIndex = req.length;
	var url=null;
	var data = "";
	var dte = new Date();
	var id;
	if(arguments[0].indexOf("?")==-1){
		url = arguments[0] + "?"
	}else{
		url = arguments[0] + "&"
	}
	
	data +="id=fnc" + dte.valueOf() + "&"; 
	url += "id=fnc" + dte.valueOf();
	if(arguments.length){		
		for(var i=1;i<arguments.length;i++){
			if(arguments[i]!="debug"){
				data += arguments[i] + "&";
			}else{
				var elem = document.createElement("div");
				if(document.getElementById("debugArea")){
					clearElements(document.getElementById("debugArea"));
				}
				gBody().appendChild(elem);
				elem.innerHTML = url + "<br>";				
			}
		}
	}
	if(window.XMLHttpRequest) {
		try {
			req.push(new XMLHttpRequest());
		} catch(e) {
			//tmpReq = false;
		}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req.push(new ActiveXObject("Msxml2.XMLHTTP"));
		} catch(e) {
			try {
				req.push(new ActiveXObject("Microsoft.XMLHTTP"));
			} catch(e) {
				//tmpReq = false;
			}
		}
	}
	if(req[lastIndex]) {
		//req.push(tmpReq);
		if(arguments[0]=="dynamicpages/lms_course_test_close.asp"){
				//alert(url);
				//alert(data);
			}
		req[lastIndex].open("POST", url, true);
		req[lastIndex].onreadystatechange = function(){
			var elem=processReqChange()
			if(elem>-1){
				//self.status="remove " + elem;
				req[elem]=null;
				req.splice(elem,1);
			}
			return false;
		}
		req[lastIndex].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req[lastIndex].send(data);
	}
	}catch(error){}
}
function loadTestXMLDoc() {
	try{
	var lastIndex = req.length;
	var url=null;
	var data = "";
	var dte = new Date();
	var id;
	if(arguments[0].indexOf("?")==-1){
		url = arguments[0] + "?"
	}else{
		url = arguments[0] + "&"
	}
	
	data +="id=fnc" + dte.valueOf() + "&"; 
	url += "id=fnc" + dte.valueOf();
	if(arguments.length){		
		for(var i=1;i<arguments.length;i++){
			if(arguments[i]!="debug"){
				data += arguments[i] + "&";
			}else{
				var elem = document.createElement("div");
				if(document.getElementById("debugArea")){
					clearElements(document.getElementById("debugArea"));
				}
				gBody().appendChild(elem);
				elem.innerHTML = url + "<br>";				
			}
		}
	}
	if(window.XMLHttpRequest) {
		try {
			req.push(new XMLHttpRequest());
		} catch(e) {
			//tmpReq = false;
		}
	// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject) {
		try {
			req.push(new ActiveXObject("Msxml2.XMLHTTP"));
		} catch(e) {
			try {
				req.push(new ActiveXObject("Microsoft.XMLHTTP"));
			} catch(e) {
				//tmpReq = false;
			}
		}
	}
	if(req[lastIndex]) {
		//req.push(tmpReq);
		if(arguments[0]=="dynamicpages/lms_course_test_close.asp"){
				//alert(url);
				//alert(data);
			}
		req[lastIndex].open("POST", url, true);
		/*req[lastIndex].onreadystatechange = function(){
			var elem=processReqChange()
			if(elem>-1){
				//self.status="remove " + elem;
				req[elem]=null;
				req.splice(elem,1);
			}
			return false;
		}*/
		req[lastIndex].setRequestHeader('Content-Type', 'application/msword');
		req[lastIndex].send(data);
	}
	}catch(error){}
}
function processReqChange(){
	var retval=-1
	for(i=0;i<req.length;i++){
		try{
		if(req[i].readyState==4){
			retval=i;
			try{
			//alert(req[i].getResponseHeader("fired") + " " + req[i].status);
			var q = req[i].responseText
			if(q){
			req[i]=null;
			//req.splice(i,1);
				eval(q);
				/*var elem = document.createElement("div");
					elem.id="debug";
					gBody().appendChild(elem);		
	
					elem.innerHTML+=q;*/
				
				//alert(error.name + '\n' + error.description + '\n' + error.message);
			}
			}catch(error){
					var elem = document.createElement("div");
					elem.id="debug";
					gBody().appendChild(elem);		
	
					elem.innerHTML+=q;
				
				alert(error.name + '\n' + error.description + '\n' + error.message);
			}
			
			/*if(req.length==0){
				processed();
			}*/
		}
		}catch(error){}
	}
	
	return retval;
}
/***********************************END XML PROCESSING CODE*******************************************/
function removeScriptElement(elemName){
	/***********************************************************************************************************
	Purpose: Clean up any code generated script elements - Attempt to minimize memory usage
	Usage: Function is called as last step in dynamic files
	Createdby: Joshua Boyce
	CreatedOn: 12/13/2005
	LastEdited: 12/13/2005
		*********************************************CHANGES*********************************************
		
	***********************************************************************************************************/
	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById(elemName);		
	if (old){	
		head.removeChild(old);
		//discardElement(old)
	}else{
		//alert("no script to unload");
	}
	var head = null;
	var old=null;
	//CollectGarbage();
	return null;
}
function gBody(){
	/***********************************************************************************************************
	Purpose: Return body element
	Usage: Called in place of document.getElementsByTagName('body').item(0) to eliminate need for variable 
			creation
	Createdby: Joshua Boyce
	CreatedOn: 1/10/2006
	LastEdited: 1/10/2006
		*********************************************CHANGES*********************************************
		
	***********************************************************************************************************/
	return document.getElementsByTagName('body').item(0);
}
function handy(){document.body.style.cursor = "pointer";return null;};
function cancelhandy(){document.body.style.cursor = "default";return null;};

//--begin context menu trap
//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com
//var message="Function Disabled!";
///////////////////////////////////
function clickIE4(){
	if (event.button==2){
		return false;
	}
}
function clickNS4(e){
	if (document.layers||document.getElementById&&!document.all){
		if (e.which==2||e.which==3){
			return false;
		}
	}
}
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}else if (document.all&&!document.getElementById){
	document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function("return false")
//--end contextmenu trap
function fireContextMenu(e){
	/***********************************************************************************************************
	Purpose: Perform action based on context; Actions are:Selection, and show context menu
	Usage: Function is called onmousedown of a student element
	Future: 
	Createdby: Joshua Boyce
	CreatedOn: 12/27/2005
	LastEdited: 12/28/2005
		*********************************************CHANGES*********************************************
		12/28/2005
			1. Adjusted selection algorithm to work as expected on both right and left clicks
	***********************************************************************************************************/
	var btn;							//variable to check if mouse down button was button 2
	var evnt;							//pointer to mouse down event 
	//var shift;							//
	var IE=false;						//Browser is IE
	var mString;						//Used to check button two in netscape browser
	var shiftPressed;					//Boolean to indicate whether shift is pressed
	var ctrlPressed;					//Boolean to indicate whether ctrl is pressed
	var altPressed;						//Boolean to indicate whether alt is pressed
	//--begin netscape button check
	if (document.layers){
		btn = e.which==3;
		evnt=e;
		mString =(e.modifiers+32).toString(2).substring(3,6);
		shiftPressed=(mString.charAt(0)=="1");
		ctrlPressed =(mString.charAt(1)=="1");
		altPressed  =(mString.charAt(2)=="1");
	}
	//--end netscape button check
	//--begin Firefox button check
	else if(navigator.userAgent.indexOf("Firefox") != -1){
		btn = e.which==3;
		evnt=e;	
		shiftPressed=evnt.shiftKey;
		ctrlPressed =evnt.ctrlKey;
		altPressed  =evnt.altKey;		
	}
	//--end Firefox button check
	//--begin Internet Explorer button check
	else{
		btn = event.button==2;
		evnt=event;
		shiftPressed=evnt.shiftKey;
		ctrlPressed =evnt.ctrlKey;
		altPressed  =evnt.altKey;
		IE=true;
	}	
	//--end Internet Explorer button check
	//--begin capture mouse position 
	if (IE) { // grab the x-y pos.s if browser is IE - used to position context menu
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	} else {  // grab the x-y pos.s if browser is NS - used to position context menu
		tempX = e.pageX
		tempY = e.pageY
	}  
	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  	
	//--end capture mouse position 
	//--begin element selection
	if(!shiftPressed && !altPressed && !ctrlPressed){
		//No special keys are pressed
		if(this.className=="selected"){
			//element is selected
			if(!btn){
				//left mouse click
				clearSelect(this);
			}
		}else{
			if(!btn){
				//left mouse click
				//clearSelect(this);
			}
			//select(this);
		}
	}else if(shiftPressed){
		//shift is pressed
		//shiftSelect(this);						
	}else if(ctrlPressed){
		//ctrl is pressed
		//select(this);
	}
	if(btn){
		//Right mouse click therefore show context menu
		fireLeftClick(this)
		unload=-1;														//set clear context menu
		clearContext();													//clear context menu so that two cannot exist at the same time
		var ary
		var tmpStr = new String(this.id).toLowerCase();
		var prnt = new String(this.parentNode.id)
		prnt = prnt.split("_");
		//self.status=prnt[1];
		if(tmpStr.indexOf("title")>-1){		
			prnt = tmpStr.split("_");
			switch(prnt[1]){			
				case "syllabustitle":
					ary= new Array("SaveSyllabus","ClearSyllabus");				//Actions in context menu from bottom to top
				break;
				case "lessontitle":			
					ary= new Array("MoveAllToSyllabus");
				break;
				case "quiztitle":
					ary= new Array("NewQuiz","MoveAllToSyllabus");
				break;
				case "testtitle":
					ary= new Array("NewTest","MoveAllToSyllabus");
				break;
				case "surveytitle":
					ary= new Array("NewSurvey","MoveAllToSyllabus");
				break;
				case "assignmenttitle":
					ary= new Array("NewAssignment","MoveAllToSyllabus");
				break;
				case "studentlisttitle":
					ary= new Array("NewStudent","GrantCourseAccessToAll");
				break;
				case "studentaccesstitle":
					ary= new Array("NewStudent","RemoveCourseAccessFromAll");
				break;
				case "questionstitle":
					ary= new Array("EditTestInfo","ClearAllQuestions","AddQuestion");
				break;edit
				case "filetitle":
					//ary= new Array("hello");
				break;
			}
		}else{
			switch(prnt[1]){
				
				case "syllabus":
					ary= new Array("RemoveSyllabusItem","SaveSyllabus","Edit","MoveDown","MoveUp");				//Actions in context menu from bottom to top
				break;
				case "lesson":
					ary= new Array("MoveToSyllabusEnd","InsertAfter","InsertBefore");				
				break;
				case "quiz":
					ary= new Array("DeleteQuiz","EditQuiz","NewQuiz","MoveToSyllabusEnd","InsertAfter","InsertBefore");
				break;
				case "test":
					ary= new Array("DeleteTest","EditTest","NewTest","MoveToSyllabusEnd","InsertAfter","InsertBefore");
				break;
				case "survey":
					ary= new Array("DeleteSurvey","EditSurvey","NewSurvey","MoveToSyllabusEnd","InsertAfter","InsertBefore");
				break;
				case "assignment":
					ary= new Array("DeleteAssignment","EditAssignment","NewAssignment","MoveToSyllabusEnd","InsertAfter","InsertBefore");
				break;
				case "studentList":
					ary= new Array("DeleteStudent","_","NewStudent","GrantCourseAccess");
				break;
				case "studentAccess":
					ary= new Array("DeleteStudent","_","NewStudent","ManageStudent","RemoveCourseAccess");
				break;
				case "studentManage":
					ary= new Array("ManageStudent");
				break;
				case "studentTutor":
					ary= new Array("TutorStudent");
				break;
				case "answer":
					ary= new Array("EditAnswer","DeleteAnswer","ToggleCorrect","MoveAnswerDown","MoveAnswerUp");
				break;
				case "tutorQuestion":
					ary= new Array("ToggleCorrectTutor");
				break;
				case "question":
					ary= new Array("EditQuestion","DeleteQuestion","MoveQuestionDown","MoveQuestionUp","AddAnswer");
				break;
				case "studentSyll":
					ary= new Array("ClearProgress");
				break;
				case "studentTutorSyll":
					ary= new Array("TutorClearProgress");
				break;
				case "syllLine":
					if(this.innerHTML!=""){
						window.event.cancelBubble = true;
						ary= new Array("AdjustGrade");
					}
				break;
				case "file":
					ary= new Array("SetGrade","UploadGraded","DownloadFile");
				break;
				case "courseDocList":
					ary= new Array("AddDoc");
				break;
				case "userWinAccess":
					ary=new Array("ChatRoomBan","RemoveChatRoomAccess");
				break;
				case "userWinNoAccess":
					ary=new Array("ChatRoomBan","GrantChatRoomAccess");
				break;
				case "userWinBanned":
					ary=new Array("RemoveChatRoomBan");
				break;
				case "tutorSyllabus":
					ary=new Array("Launch" + this.id.split("_")[0]);
				break;
				case "tutorList":
					ary=new Array("GrantTutorAccess");
				break;
				case "tutorAccess":
					ary=new Array("AssignStudents","RemoveTutorAccess");
				break;
				case "tutorStudentList":
					ary=new Array("AssignStudentToTutor");
				break;
				case "tutorStudentAccess":
					ary=new Array("RemoveStudentFromTutor");
				break;
			}
		}
		var line= new Array(-1,0);										//Position divider from top to bottom *must always contain -1 as first element
		
		var menu = document.createElement("div")						//Menu container
		var bdy = gBody();		//Reference the body tag
		var tmpelem														//Temporary container to hold reference of context items
		//--Begin loading context menu
		if(ary){
		for(i=ary.length-1;i>-1;i--){									
			if(ary[i]=="_"){											//Check to see if a seperator is needed in this position
				tmpElem=document.createElement("div");
				tmpElem.className="seperator";
				menu.appendChild(tmpElem);								//Add seperator
				tmpElem=null;											//release reference for mememory
				if(i==0){
					break;
				}else{
					i--;
				}
				
				//sep++;
			}
			tmpElem=document.createElement("div")						//new context item
			tmpElem.id = ary[i] + "_" + this.id
			tmpElem.appendChild(document.createTextNode(ary[i]));
			tmpElem.onmouseover = contextHighlight;						//set context mouse over
			tmpElem.onmouseout = contextClearHighlight;					//set context mouse out
			tmpElem.className="contextItem";							//set css class
			
			menu.appendChild(tmpElem);
			tmpElem = null;												//release reference from mememory
		}	
		//--end loading context menu
		//--begin position menu
		menu.style.position = "absolute";	
		menu.style.left=tempX + "px";
		menu.style.top=tempY + "px";
		//--end position menu
		menu.className="contextMenu";					
		//menu.onmousedown=function(){return false;}						//capture text highlighting NS/FF
		//menu.onselectstart = function () { return false; }				//capture text highlighting IE
		menu.id="menu"
		bdy.appendChild(menu);
		}
		ary = null;														//release reference from mememory
		menu = null;													//release reference from mememory
		bdy = null;														//release reference from mememory
		tmpelem = null;													//release reference from mememory
		unload=-1														//set clear context menu
	}else{
		fireLeftClick(this);
	}
	evnt=null;
	return false;
}
function contextHighlight(){
	/***********************************************************************************************************
	Purpose: Highlight context menu item and set actions
	Usage: Function is called from context item onmouseover
	Future: 
	Createdby: Joshua Boyce
	CreatedOn: 12/28/2005
	LastEdited: 12/28/2005
		*********************************************CHANGES*********************************************

	***********************************************************************************************************/
	this.style.background = "blue";
	this.onclick = fireAction;
	this.onmousedown=function(){return false;}			
	this.onselectstart = function () { return false; }
	unload=0;
	handy();
	return null;
}
function contextClearHighlight(){
	/***********************************************************************************************************
	Purpose: disengage Highlight context menu item and clear actions
	Usage: Function is called from context item onmouseover
	Future: 
	Createdby: Joshua Boyce
	CreatedOn: 12/28/2005
	LastEdited: 12/28/2005
		*********************************************CHANGES*********************************************

	***********************************************************************************************************/
	this.style.background = "";
	cancelhandy();
	unload=-1;
	fireClearContext();
	return null;
}
function fireAction(e){
	/***********************************************************************************************************
	Purpose: perform action indicated by context menu
	Usage: Function is called from context item onclick
	Future: Include Properties action
	Createdby: Joshua Boyce
	CreatedOn: 12/27/2005
	LastEdited: 12/28/2005
		*********************************************CHANGES*********************************************
		12/28/2005
			1. Allowed for moving of multiple items
			2. Allowed for deletion of multiple items
	***********************************************************************************************************/
	
	//alert("fireAction")
	var str= new String(this.id);														//get id string for parse
	var mnu = document.getElementById("menu")											//reference context menu
	var bdy = document.getElementsByTagName('body').item(0);							//reference body tag
	//--begin fireaction based on str left of the "_"
	//alert(str.lastIndexOf("_"))
	//alert(str.substr(0,str.indexOf("_")))
	switch(str.substr(0,str.indexOf("_"))){
		case "Delete":		
//			alert(document.getElementById(str.substr(str.indexOf("_")+1,str.length-(str.indexOf("_")+1))).parentNode.parentNode.className)
			if(document.getElementById(str.substr(str.indexOf("_")+1,str.length-(str.indexOf("_")+1))).parentNode.parentNode.className=="goalContainer"){			
				var prnt = document.getElementById(str.substr(str.indexOf("_")+1,str.length-(str.indexOf("_")+1))).parentNode.parentNode
				promptYesNo(e,"deleteGoal","cancelDelete",prnt.id,prnt.id);
//				clearElements(prnt);
//				alert(document.getElementById(str.substr(str.indexOf("_")+1,str.length-(str.indexOf("_")+1))));
				prnt=null;
			}else{
				clearElements(document.getElementById(str.substr(str.indexOf("_")+1,str.length-(str.indexOf("_")+1))));
			}			
			break;
		case "Move":
			if(document.getElementById(str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1))).className=="selected"){
				var prnt = document.getElementById(str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1))).parentNode
				for(i=prnt.childNodes.length-1;i>-1;i--){
					try{
						if(prnt.childNodes[i].className=="selected"){
							
							//alert("here");
							dbMove(prnt.childNodes[i].id,courseID);												
						}
					}catch(error){}
				}
				prnt=null;
			}else{
				
				dbMove(str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)),courseID);
			}
			break;	
		
		case "Add":
			//alert(str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)))
			addGoalFormWithEvent(e,str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)))
			//alert(document.getElementById().parentNode.id + " Add");
			break;
		case "AddComment":
			//alert(str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)))
			//addGoalFormWithEvent(e,str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)))
			addComments(e,str.substr(str.lastIndexOf("_")+1,str.length-(str.lastIndexOf("_")+1)));
//			alert() + " Add Comment");
			/*
			case "syllabus":
				ary= new Array("RemoveSyllabusItem","Edit","MoveDown","MoveUp","InsertBefore");				//Actions in context menu from bottom to top

			case "lesson":
				ary= new Array("MoveToSyllabusEnd","InsertBefore");				
			case "quiz":
				ary= new Array("DeleteQuiz","EditQuiz","NewQuiz","MoveToSyllabusEnd","InsertBefore");
			case "test":
				ary= new Array("DeleteTest","EditTest","NewTest","MoveToSyllabusEnd","InsertBefore");
			case "survey":
				ary= new Array("DeleteSurvey","EditSurvey","NewSurvey","MoveToSyllabusEnd","InsertBefore");
			case "assignment":
				ary= new Array("DeleteAssignment","EditAssignment","NewAssignment","MoveToSyllabusEnd","InsertBefore");*/
			break;
		case "MoveToSyllabusEnd":
			appendToSyllabusEnd(this.id);
			break;
		case "RemoveSyllabusItem":
			removeSyllabusItem(this.id);
			break;
		case "PreviewLesson":
			startLesson(this.id);
			break;
		case "InsertBefore":
			insertBefore(this.id);
			break;
		case "InsertAfter":
			insertAfter(this.id);
			break;
		case "MoveUp":
			moveUp(this.id);
			break;
		case "MoveDown":
			moveDown(this.id);
			break;
		case "ClearSyllabus":
			clearSyllabus(this.id);
			break;
		case "MoveAllToSyllabus":
			moveAllToSyllabus(this.id);
			break;		
		case "SaveSyllabus":
			saveSyllabus(this.id);
			break;
		case "GrantCourseAccessToAll":
			grantAccessToAll(this.id);
			break;
		case "RemoveCourseAccessFromAll":
			removeAccessToAll(this.id);
			break;
		case "GrantCourseAccess":
			grantAccessToStudent(this.id);
			break;
		case "RemoveCourseAccess":
			removeAccessToStudent(this.id);
			break;
		case "ManageStudent":
			var containID= new String(document.getElementById(this.id.substr(this.id.indexOf("_")+1)).parentNode.id)
			manageStudent(this.id.substr(this.id.lastIndexOf("_")+1),containID.substr(containID.lastIndexOf("_")+1));
		break;
		case "TutorStudent":
			var containID= new String(document.getElementById(this.id.substr(this.id.indexOf("_")+1)).parentNode.id)
			tutorStudent(this.id.substr(this.id.lastIndexOf("_")+1),containID.substr(containID.lastIndexOf("_")+1));
		break;
		case "NewStudent":
			newStudent(this.id);
			break;
		case "NewQuiz":
			newTestQuiz(this.id.substr(this.id.lastIndexOf("_")),2);
			break;
		case "NewTest":
			newTestQuiz(this.id.substr(this.id.lastIndexOf("_")),1);
			break;
		case "NewSurvey":
			newTestQuiz(this.id.substr(this.id.lastIndexOf("_")),3);
			break;
		case "EditSurvey":
			EditTestSurvey(this.id.substr(this.id.lastIndexOf("_")+1),"Survey",document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
			break;
		case "EditTest":
			EditTestSurvey(this.id.substr(this.id.lastIndexOf("_")+1),"Test",document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
			break;
		case "EditQuiz":
			EditTestSurvey(this.id.substr(this.id.lastIndexOf("_")+1),"Quiz",document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
			break;
		case "AddQuestion":
			createQuestion(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "AddAnswer":
			createAnswer(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "ToggleCorrect":
			setCorrect(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "ToggleCorrectTutor":
			setCorrect(this.id.substr(this.id.indexOf("_")+1),-1);
		break;
		case "MoveQuestionUp":
			moveQuestion(this.id.substr(this.id.indexOf("_")+1),-1);
		break;
		case "MoveQuestionDown":
			moveQuestion(this.id.substr(this.id.indexOf("_")+1),1);
		break;
		case "EditQuestion":
			editQuestion(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "EditAnswer":
			editAnswer(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "MoveAnswerUp":
			moveAnswer(this.id.substr(this.id.indexOf("_")+1),-1);
		break;
		case "MoveAnswerDown":
			moveAnswer(this.id.substr(this.id.indexOf("_")+1),1);
		break;
		case "DeleteAnswer":
			deleteAnswer(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "DeleteQuestion":
			deleteQuestion(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "DeleteTest":
			deleteTest(this.id.substr(this.id.indexOf("_")+1),"Test");
		break;
		case "DeleteQuiz":
			deleteTest(this.id.substr(this.id.indexOf("_")+1),"Quiz");
		break;
		case "DeleteSurvey":
			deleteTest(this.id.substr(this.id.indexOf("_")+1),"Survey");
		break;
		case "Edit":
			editFire(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "NewAssignment":
			newAssignment(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "DeleteAssignment":
			deleteAssignment(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "EditAssignment":
			EditAssignment(this.id.substr(this.id.lastIndexOf("_")+1),"Assignment",document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "ClearProgress":
			clearProgression(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "TutorClearProgress":
			clearProgression(this.id.substr(this.id.indexOf("_")+1),"tutor");
		break;
		case "DownloadFile":
			getFile(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "UploadGraded":
			putFile(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "AddDoc":
			fireAddDoc(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "SetGrade":
			setGrade(this.id.substr(this.id.indexOf("_")+1));
		break;
		case "EditTestInfo":
			EditTestInfo(this.id.substr(this.id.lastIndexOf("_")+1),currentTest.type,document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "GrantChatRoomAccess":
			grantAccess(this.id.substr(this.id.lastIndexOf("_")+1),"access","1");//EditTestInfo(this.id.substr(this.id.lastIndexOf("_")+1),currentTest.type,document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "RemoveChatRoomAccess":
			grantAccess(this.id.substr(this.id.lastIndexOf("_")+1),"access","0");//EditTestInfo(this.id.substr(this.id.lastIndexOf("_")+1),currentTest.type,document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "ChatRoomBan":
			grantAccess(this.id.substr(this.id.lastIndexOf("_")+1),"banned","1");//EditTestInfo(this.id.substr(this.id.lastIndexOf("_")+1),currentTest.type,document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "RemoveChatRoomBan":
			grantAccess(this.id.substr(this.id.lastIndexOf("_")+1),"banned","0");//(this.id.substr(this.id.lastIndexOf("_")+1),currentTest.type,document.getElementById(this.id.substr(this.id.indexOf("_")+1)).innerHTML);
		break;
		case "AdjustGrade":
			gradeElement(this.id);
		break;
		case "DeleteStudent":
			deleteStudent(this.id);
		break;
		case "LaunchQuiz":
		case "LaunchSurvey":
		case "LaunchTest":
			tutorTest(this.id.split("_")[2]);
		break;
		case "LaunchAssignment":
			tutorAssignment(this.id.split("_")[2])
		break;
		case "LaunchLesson":
			tutorLesson(this.id.split("_")[2]);
			clearElements(document.getElementById(this.id.substr(this.id.indexOf("_")+1)).parentNode.parentNode);
		break;
		case "GrantTutorAccess":
			grantAccessToTutor(this.id);
			break;
		case "RemoveTutorAccess":
			removeAccessFromTutor(this.id);
			break;
		case "AssignStudents":
			assignStudents(this.id);
		break;
		case "RemoveStudentFromTutor":
			removeStudentFromTutor(this.id);
			break;
		case "AssignStudentToTutor":
			assignStudentToTutor(this.id);
		break;
	}	
	//--end action call
	unload=-1;
	clearContext();																	//remove context menu
	var str = null;
	var mnu = null;																		//release reference from mememory
	var bdy = null;																		//release reference from mememory
	return false;
}
function fireClearContext(){
	/***********************************************************************************************************
	Purpose: fire clearContext menu after seconds indicated by the global variable spd
	Usage: Function is called after context menu is opened and after a menu item is mouseoffed
	Future: 
	Createdby: Joshua Boyce
	CreatedOn: 12/27/2005
	LastEdited: 12/27/2005
		*********************************************CHANGES*********************************************
	***********************************************************************************************************/
	setTimeout("clearContext()",spd*1000);
	return null;
}
function clearContext(){
	
	/***********************************************************************************************************
	Purpose: remove context menu from body tag
	Usage: called from fireClearContext(),
	Future:
	Createdby: Joshua Boyce
	CreatedOn: 12/27/2005
	LastEdited: 12/27/2005
		*********************************************CHANGES*********************************************

	***********************************************************************************************************/
	var mnu = document.getElementById("menu")
	if(mnu && unload==-1){		
		try{			
			var bdy = document.getElementsByTagName('body').item(0);
			bdy.removeChild(mnu);
			//var mnu = null;
			var bdy = null;
			//discardElement(mnu)
			mnu=null;
			return null;
		}catch(error){			
		}
	}
	return null;
}
function clearElements(){
	/***********************************************************************************************************
	Purpose: Clear sub elements.
	Usage: Parameter is object whose children we want to clear.
	Createdby: Joshua Boyce
	CreatedOn: 1/10/2006
	LastEdited: 1/10/2006
		*********************************************CHANGES*********************************************
		
	***********************************************************************************************************/
	//window.clearInterval(updateTmr)
	var clearcontainer=null
	if(arguments.length){
		clearcontainer=arguments[0]
	}else{
		clearcontainer=gBody();
	}
	if(clearcontainer.childNodes.length>0){
		for(var i=clearcontainer.childNodes.length-1;i>-1;i--){
			clearElements(clearcontainer.childNodes[i]);
			try{
			clearcontainer.removeChild(clearcontainer.childNodes[i]);
			//discardElement(clearcontainer.childNodes[i])
			}catch(error){};
		}
	}
	if(arguments.length){
		if(arguments[1]==0){
			//alert(arguments[1]);
		}else{
			clearcontainer.parentNode.removeChild(clearcontainer)
			//discardElement(clearcontainer);
		}
	}else{
		build();
	}
	clearcontainer=null;
	//CollectGarbage();
	return null;
}
function processing(){
	var caption;
	var parent;
	var hold = document.createElement("div")
	var holdContainer = document.createElement("div")
	var updater=document.createElement("div")
	gBody().appendChild(holdContainer);	
	holdContainer.appendChild(hold);
	holdContainer.appendChild(updater);
	if(arguments.length){
		if(arguments[0]!=""){
			caption = arguments[0];
		}
		if(arguments[1]){
			parent=arguments[1];
		}else{
			parent="Processing"
		}
	}else{
		parent=gBody()
		caption = "Processing";
	}
	holdContainer.style.position="absolute";
	holdContainer.style.top="0px";
	holdContainer.style.left="0px";
	holdContainer.style.width ="100%";
	holdContainer.style.height="100%";
	holdContainer.style.border="1px solid gray";
	holdContainer.style.zindex=1000;
	holdContainer.id="hold";
	hold.className="holder";
	hold.style.position="absolute";
	hold.style.top="0px";
	hold.style.left="0px";
	hold.style.width ="100%";
	hold.style.height="100%";
	hold.style.border="1px solid gray";
	hold.style.backgroundColor="gray";
	hold.style.filter="alpha(opacity=50)";
	hold.style.opacity=".5";
	//hold.onclick=processed;
	
	updater.innerHTML=caption
	updater.style.position="absolute";
	updater.style.left = "100px";
	updater.style.top = "100px";
	updater.style.backgroundColor="red";
	updater.style.border = "1px solid black";
	//updater.style.filter="alpha(opacity=100)";
	updater.style.width="200px";
	updater.id="updater"

	actnTmr.push(processingTimer())
	updater = null;
	parent = null;
	caption=null;
	parent=null;
	hold=null;
	holdContainer=null;
	return null;
}
function processingTimer(){
	return window.setInterval("processAction()", 50)
}
function processAction(){
	var updater = document.getElementById("updater");
	var wdth=stripPX(updater.style.width);
	if(wdth>500){
		actnMv=-1*actnMv;
	}else{
		if(wdth<Math.abs(actnMv)){
			actnMv=-1*actnMv;
		}
	}
	updater.style.width = (wdth + actnMv) + "px";
	updater = null;
	wdth=null;
	return null;
}
function processed(){
	window.clearInterval(actnTmr.pop())	
	clearElements(document.getElementById("hold"))
	return null;
}
function stripPX(txt){
	var str = new String(txt)
	if(str.lastIndexOf("p")!=-1){
		str = str.slice(0,str.lastIndexOf("p"))
	}
	return parseInt(str)
}
function anchorWindow(e){
	var prntObj = e;
	lastPos = originalPos;
	lastSize= originalSize;
	prntObj.style.width = originalSize[0] + "px";
	prntObj.style.height =originalSize[1] + "px";
	prntObj.style.left =originalPos[0] + "px";
	prntObj.style.top =originalPos[1] + "px";
	resizeContents(prntObj);
	prntObj=null;
}
function minimizeWin(e){
	var prntObj = e;
	if(lastSize==null){
		lastPos = new Array(stripPX(prntObj.style.left),stripPX(prntObj.style.top));
		lastSize=new Array(stripPX(prntObj.style.width),stripPX(prntObj.style.height));
		originalPos = new Array(stripPX(prntObj.style.left),stripPX(prntObj.style.top));
		originalSize=new Array(stripPX(prntObj.style.width),stripPX(prntObj.style.height));
		
	}
	if(stripPX(prntObj.style.height)==17){
		prntObj.style.width = lastSize[0] + "px";
		prntObj.style.height =lastSize[1] + "px";
		for(var children=2;children<prntObj.childNodes.length;children++){
			prntObj.childNodes[children].style.display="";
		}
	}else{
		prntObj.style.width = originalSize[0] + "px";
		prntObj.style.height = "17px";
		for(var children=2;children<prntObj.childNodes.length;children++){
			prntObj.childNodes[children].style.display="none";
		}
	}
	resizeContents(prntObj);
	prntObj=null;
	return null;
}
function maximizeWin(e){									
	var prntObj = e;
	if(lastSize==null){

		lastSize=new Array(stripPX(prntObj.style.width),stripPX(prntObj.style.height));
		originalSize=new Array(stripPX(prntObj.style.width),stripPX(prntObj.style.height));
	}
	if(lastPos==null){
		lastPos = new Array(stripPX(prntObj.style.left),stripPX(prntObj.style.top));
		originalPos = new Array(stripPX(prntObj.style.left),stripPX(prntObj.style.top));
	}
	/*if(stripPX(prntObj.style.left)!=0){
		
	}*/
	if(clientWidth==stripPX(prntObj.style.width)){
		prntObj.style.width = lastSize[0] + "px";
		prntObj.style.height =lastSize[1] + "px";
		prntObj.style.left =lastPos[0] + "px";
		prntObj.style.top =lastPos[1] + "px";
		if(prntObj.childNodes[2]){
			prntObj.childNodes[2].style.height=lastSize[1]-19 + "px";
		}
		//prntObj.lastSize=coordinates.create(stripPX(prntObj.style.width),stripPX(prntObj.style.height));
		this.src = "Consoles/v12_00/WinMax.gif";
	}else{
		
		prntObj.style.left = "0px";
		prntObj.style.top = "0px";
		if(parseInt(document.body.clientHeight)<parseInt(document.body.scrollHeight)){
		clientHeight =document.body.scrollHeight//document.body.clientHeight-2; 
		//self.status=document.body.clientHeight + " " + document.body.scrollHeight;
		}else{
		clientHeight =document.body.clientHeight//document.body.clientHeight-2; 
		//self.status=document.body.clientHeight + " " + document.body.scrollHeight + "clientHeight";
		}
		clientWidth =document.body.clientWidth//document.body.clientWidth-2;
		var tmpHeight=clientHeight
		var tmpWidth=clientWidth
		if(prntObj.parentNode!=gBody()){
			tmpHeight=stripPX(readStyle(prntObj.parentNode,"height"));
			tmpWidth=stripPX(readStyle(prntObj.parentNode,"Width"));
			//alert(prntObj.parentNode.id);
		}
		prntObj.style.width = tmpWidth + "px";
		prntObj.style.height = tmpHeight + "px";		
		if(prntObj.childNodes[2]){
			prntObj.childNodes[2].style.height=tmpHeight-19 + "px";
		}
		this.src = "Consoles/v12_00/WinRes.gif";
	}
	for(var children=2;children<prntObj.childNodes.length;children++){
			prntObj.childNodes[children].style.display="";
	}
	resizeContents(prntObj);
	prntObj=null;
	return false;									
}
function resizeContents(obj){
	var totalHeight=0;
	for(var child=1;child<obj.childNodes.length;child++){		
		obj.childNodes[child].style.width = obj.style.width;		
		if((child==obj.childNodes.length-2 && obj.childNodes.length>3) || (obj.childNodes.length==2 && child==obj.childNodes.length-1)){
			if(stripPX(obj.style.height)-totalHeight-30>=0){
			obj.childNodes[child].style.height=stripPX(obj.style.height)-totalHeight-30 +"px";
			}
		}
		if(child==obj.childNodes.length-1){
			//obj.childNodes[child].style.top=totalHeight+ 5 +"px";
		}
		if(!isNaN(stripPX(readStyle(obj.childNodes[child],"height")))){
			totalHeight+=stripPX(readStyle(obj.childNodes[child],"height"));
		}
	}
}
function findDragWin(elem){
	var retVal;
	
	if(elem!=gBody()){
		if(elem.className){
			if(elem.className!="dragWindow"){
				retVal=findDragWin(elem.parentNode)
			}else{
				retVal = elem;
			}
		}else{
			retVal=findDragWin(elem.parent);
		}
	}else{
		retVal="notFound";
	}
	return retVal;
}
function getQueryStrVar(q){
	var retval=null;
	var qString = window.location.search
	var valuePairArray;
	var valueArray;
	qString = new String(qString).substr(1);
	if(q && qString.length >0){
		valuePairArray = qString.split("&");
		for(var vals = 0; vals<valuePairArray.length;vals++){
			valueArray=valuePairArray[vals].split("=");
			if(valueArray[0].toUpperCase()==q.toUpperCase()){
				retval=valueArray[1];
			}
		}
	}
	return retval;	
}
	/*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.getKeyValuePairs = function() { return this.keyValuePairs; }
	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;
	}
	this.getParameters = function() {
	var a = new Array(this.getLength());
	for(var j=0; j < this.keyValuePairs.length; j++) {
	a[j] = this.keyValuePairs[j].split("=")[0];
	}
	return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
	}
	function queryString(key){
		var page = new PageQuery(window.location.search); 
		return unescape(page.getValue(key)); 
	}
	function displayItem(key){
		if(queryString(key)=='false') 
		{
		document.write("you didn't enter a ?name=value querystring item.");
		}else{
		document.write(queryString(key));
		}
	}
*/
//CollectGarbage();
function adjust(){
	clientHeight =document.body.clientHeight-2; 
	clientWidth =document.body.clientWidth-2;
}
function highlight(){
	if(getState(this.id)=="inactive"){
		setState(this.id,"highlight");
	}
}
function nohighlight(){
	if(getState(this.id)=="highlight"){
		setState(this.id,"inactive");
	}
}
function getState(elemID){	
	var elem = document.getElementById(elemID);
	var classString = new String(elem.className);
	elem=null;
	return classString.substr(classString.lastIndexOf("_")+1);
	
}
function setState(elemID,newstate){
	try{
	var elem=document.getElementById(elemID);
	var classString = new String(elem.className);
	
	classString = classString.substr(0,classString.lastIndexOf("_")+1);
	elem.className=classString + newstate;
	classString = null;
	elem=null;
	}catch(error){alert("Can't set state to " + newstate +  " for element " + elemID)}
}
function clearActive(courseID){
	var logArea = document.getElementById(courseID);	
	for(var i=1; i<logArea.childNodes.length; i++){
		if(getState(logArea.childNodes[i].id)=="active"){
			if(true==false){
				setState(logArea.childNodes[i].id,"inactive");
			}else{
				setState(logArea.childNodes[i].id,"inactive");
				//setStatus(logArea.childNodes[i].id,"inactive");
			}
		}
	}
	logArea=null;
	return null;
}
function clearConActive(elemID,courseID){
	
	var groups = new Array( "container_lesson_",  "container_survey_", "container_quiz_", "container_test_", "container_assignment_","container_tutorList_","container_tutorAccess_","container_tutorStudentAccess_","container_tutorStudentList_");
	var elem = document.getElementById(elemID);
	if(elem.parentNode.id!="container_syllabus_" + courseID && elem.parentNode.id!="container_studentList_" + courseID && elem.parentNode.id!="container_studentManage_" + courseID && elem.parentNode.id!="container_studentAccess_" + courseID && elem.parentNode.id!="container_studentTutor_" + courseID){
		//alert(elem.parentNode.id);
		//self.status="here";
		for(var i=0; i<groups.length;i++){
			if(document.getElementById(groups[i] + courseID) && document.getElementById(groups[i] + courseID).childNodes.length>0){
				clearActive(groups[i]+ courseID);
			}
		}
	}else{
		clearActive(elem.parentNode.id);		
	}
	elem=null;
	groups=null;
}
function fireLeftClick(e){
	var idArray= new String(e.id);
	var pidArray = new String(e.parentNode.id);
	pidArray = pidArray.split("_");
	idArray= idArray.split("_");
	if(idArray.length>0){
		switch(idArray[0]){
			case "itm":
				clearConActive(e.id,pidArray[2]);
				setState(e.id,"active");
			break;
		}
	}
	e=null;
}
function convertTrueFalse(val){
	var retval = 0;
	if(val){
		retval = 1
	}
	return retval;
}
function headScrollTop(){
	//alert("here");
	//var newid=this.id.split("_")
	var syllLineId=this.childNodes[0].id;//"container_syllLine1_"+ newid[2]	+ "_" + newid[3] + "_header";
	document.getElementById(syllLineId).style.top=this.scrollTop+"px";
	//newid=null;
	syllLineId=null;
	return null;
}
function dateFormat(strDate,formatID){
	var retStrDte;
	if(strDate){
	var dte = new Date(strDate);
	
	var hrs=calcMilitary(dte.getHours());
	if(!formatID){
		formatID=1;
	}
	switch(formatID){
		case 1:
			//No Seconds with AM/PM
			retStrDte=dte.getMonth()+1 + "/" + dte.getDate() + "/" + dte.getYear() + "&nbsp;" + emptyTens(hrs[0]) + ":" + tens(dte.getMinutes())+ " " + hrs[1];
		break;
		case 2:
			//No Seconds with AM/PM on two lines
			retStrDte=dte.getMonth()+1 + "/" + dte.getDate() + "/" + dte.getYear() + "<br>" + emptyTens(hrs[0]) + ":" + tens(dte.getMinutes())+ " " + hrs[1];
		break;
	}
	}else{
		retStrDte="";
	}
	return retStrDte;
}

function calcMilitary(intHour){
	var retVals=new Array();
	if(intHour>12){
		retVals.push(intHour-12);
		retVals.push("PM");
	}else{
		if(intHour==0){
			retVals.push(12);
			retVals.push("AM");
		}else{
			retVals.push(intHour);
			retVals.push("AM");
		}
	}
	return retVals;
}
function tens(val){
	if(val<10){
		val = "0" + val;
	}else{
		val = new String(val);
	}
	return val;
}
function emptyTens(val){
		if(val<10){
		val = " " + val;
	}else{
		val = new String(val);
	}
	return val;
}
function loadCSS(cssTitle,sheetTitle){
	var head = document.getElementsByTagName('head').item(0);
	url=GetCompanyCSS() + "CSS/" + cssTitle

	if(!sheetTitle){
	    sheetTitle="style";
	}
	q = document.getElementById(sheetTitle);
	if(q){
	    head.removeChild(q)
	    //discardElement(q);
		
	}
	var s=document.createElement('link');
	sid = sheetTitle;
	void(s.id = sid );
	void(s.rel='stylesheet');
	void(s.href=url +"?" + Date());
	void(s.type="text/css");
	void(head.appendChild(s));
	s = null;
	q=null;
	head = null;
}
function GetCompanyCSS(){
	var retval="";
	if(getQueryStrVar("CompanyID")){
		retval="../" + getQueryStrVar("CompanyID") + "/";
	}
	return retval;
}
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
function ask(msg,type,action,fill){
	var container=document.createElement("div");
	container.className=type;
	var popup=document.createElement("div");
	popup.className=type + "_form";
	var shadow=document.createElement("div");
	shadow.className=type + "_shade";
	var message=document.createElement("div");
	message.className=type + "_msg";
	var shadowblock=document.createElement("iframe");
	shadowblock.className=type+"_block";
	message.innerHTML=msg;
	popup.appendChild(message);
	container.appendChild(popup);
	container.appendChild(shadowblock);
	container.appendChild(shadow);	
	switch(type){
		case "yesNo":
			var btn_Yes = document.createElement("a");
			var btn_No = document.createElement("a");
			btn_Yes.id="btn_Yes";
			btn_No.id="btn_No";
			btn_Yes.className="askButton";
			btn_No.className="askButton";
			btn_Yes.innerHTML="Yes";
			btn_No.innerHTML="No";
			btn_Yes.href="#";
			btn_No.href="#";
			btn_Yes.onclick=action;
			btn_No.onclick=action;
			popup.appendChild(btn_Yes);
			popup.appendChild(btn_No);
			btn_Yes=null;
			btn_No=null;
		break;
		case "valPrompt":
			var txt_input = document.createElement("input");
			var btn_Yes = document.createElement("a");
			var btn_No = document.createElement("a");
			txt_input.id="txt_input";
			btn_Yes.id="btn_Yes";
			btn_No.id="btn_No";
			txt_input.className="txtInput";
			btn_Yes.className="askButton";
			btn_No.className="askButton";
			btn_Yes.innerHTML="Go";
			btn_No.innerHTML="Cancel";
			btn_Yes.href="#";
			btn_No.href="#";
			btn_Yes.onclick=action;
			btn_No.onclick=action;
			popup.appendChild(txt_input);
			popup.innerHTML+="<BR><br>";
			popup.appendChild(btn_Yes);
			popup.appendChild(btn_No);
			txt_input=null;
		    btn_Yes=null;
		    btn_No=null;
		break;
		case "ddPrompt":
			var txt_input = document.createElement("select");
			var btn_Yes = document.createElement("a");
			var btn_No = document.createElement("a");
			txt_input.id="cmb_input";
			btn_Yes.id="btn_Yes";
			btn_No.id="btn_No";
			txt_input.className="txtInput";
			btn_Yes.className="askButton";
			btn_No.className="askButton";
			btn_Yes.innerHTML="Go";
			btn_No.innerHTML="Cancel";
			btn_Yes.href="#";
			btn_No.href="#";
			btn_Yes.onclick=action;
			btn_No.onclick=action;
			popup.appendChild(txt_input);
			popup.innerHTML+="<BR><br>";
			popup.appendChild(btn_Yes);
			popup.appendChild(btn_No);
			fill();
			txt_input=null;
			btn_Yes=null;
			btn_No=null;
		break;
	}
	gBody().appendChild(container);
	container=null;
	popup=null;
	shadow=null;
	message=null;
	shadowblock=null;
}
function addDDVal(trgtDD,strVal,dataVal){
	var elem = document.getElementById(trgtDD);
	var optn =document.createElement("OPTION");
	optn.text = strVal;
	optn.value=dataVal;
	try{
		elem.options.add(optn);
	}catch(error){
	elem.appendChild(optn);
	}
	optn=null;
	elem=null;
}
function trimAll(sString){
	if(sString!=null){
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	}
	return sString;
}
function cleanquote(val){
	if(val){
	val=val.replace("'", "&#39;")
	}
	return val
}
BrowserDetect.init();
function ieVersion(){
    
    var str = navigator.appVersion;
    
    
    var retval;
    str=str.split(";");
    
    for(i=str.length-1;i>=0;i--){
        if(str[i].indexOf("MSIE")>-1){
            retval=str[i].split(" ")[2];
        }
    }
    str=null;
    retval=null;
    return retval;
}
sessionKeepAlive=setInterval("fireSessionKeepAlive()",30000);//,120000);
function fireSessionKeepAlive(){
    //alert(document.getElementsByTagName("div").length);
    //document.getElementsByTagName("div").length
    var title='';
    
    //self.status="elems length=" + gBody().childNodes.length;
    
    for(var i=gBody().childNodes.length-1;i>-1;i--){
        if(gBody().childNodes[i].className=="dragWindow"){
            //self.status+="found drag window " + gBody().childNodes[i].id;
            //var windowElems=gBody().childNodes[i].childNodes;
            for(var z=0;z<gBody().childNodes[i].childNodes.length-1;z++){
               if(gBody().childNodes[i].childNodes[z].className=="dragHandle"){
                    title=gBody().childNodes[i].childNodes[z].childNodes[1].innerHTML;
                    break;
               }
            }        
            //windowElems=null;
            break;
        }
    }
    //elems=null;
	loadXMLDoc("/QView13_LMS/dynamicPages/sessionKeepAlive.asp","elemTitle=" + escape(title));
	
}
function executeAction(actionType){
    switch(actionType){
        case 1:
            self.status= "Message Received";
            getNewMessages();
        break;
    }
}
function discardElement(element) {
    var garbageBin = document.getElementById('IELeakGarbageBin');
    if (!garbageBin) {
        garbageBin = document.createElement('DIV');
        garbageBin.id = 'IELeakGarbageBin';
        garbageBin.style.display = 'none';
        gBody().appendChild(garbageBin);
    }

    // move the element to the garbage bin
    garbageBin.appendChild(element);
    garbageBin.innerHTML = '';
}
function appCleanup(){
    gBody().innerHTML='';
    return null;
}