
//	---------------------------------------------------------------------------------
//	This function - not original, got from the internet - stacks functions to be
//	executed on window.load. So, rather than having specific assignments of window.unload,
//	which could overwrite each other, use this function.
//	---------------------------------------------------------------------------------
function AddLoadEvent(func)
	{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
		{
		window.onload = func;
		}
	else
		{
		window.onload = function() {if (oldonload) {oldonload();} func();}
		}
	}

//	---------------------------------------------------------------------------------
//	Dummy FormLoad Function - may be overwritten by subsequent definitions in wml scripts
//	---------------------------------------------------------------------------------
function FormLoadFunction() {}

//	---------------------------------------------------------------------------------
//	Dummy ValidateForm Function - may be overwritten by subsequent definitions in wml scripts
//	---------------------------------------------------------------------------------
function ValidateForm() {}

//	---------------------------------------------------------------------------------
//	Dummy ClearForm Function - may be overwritten by subsequent definitions in wml scripts
//	---------------------------------------------------------------------------------
function ClearForm() {}

//	---------------------------------------------------------------------------------
//	Dummy ClearField Function - may be overwritten by subsequent definitions in wml scripts
//	---------------------------------------------------------------------------------
function ClearField(pFieldName)
	{
	var oFieldName = document.getElementById(pFieldName);
	if (oFieldName)
		{
		oFieldName.value = '';
		}
	}

//	---------------------------------------------------------------------------------
//	ClearSearchForm Function
//	---------------------------------------------------------------------------------
function ClearSearchForm(pSearchName)
	{
	var oFieldName = document.getElementById("SearchCourseType");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}

	var oFieldName = document.getElementById("SearchCourseUnitType");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}

	var oFieldName = document.getElementById("SearchCategory");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}

	var oFieldName = document.getElementById("SearchCatalog");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}

	var oFieldName = document.getElementById("SearchCourseUser1");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}

	var oFieldName = document.getElementById("SearchHistoryStatusName");
	if (oFieldName)
		{
		oFieldName.value = '0';
		}

	var oFieldName = document.getElementById("SearchLocation");
	if (oFieldName)
		{
		oFieldName.value = '-1';
		}
	var oFieldName = document.getElementById("SearchKeyword");
	if (oFieldName)
		{
		oFieldName.value = '';
		}
	var oFieldName = document.getElementById("SearchObjectTypeID");
	if (oFieldName)
		{
		oFieldName.value = '';
		}
	return true;
	}

//	---------------------------------------------------------------------------------
//	Function to return the value from a set of Radio buttons
//	---------------------------------------------------------------------------------
function GetRadioButtonValue(pRadioButton)
	{
	var oRadioButton = document.getElementsByName(pRadioButton);
	if (oRadioButton.length)
		{
		for (var i=0; i < oRadioButton.length; i++)
			{
			if (oRadioButton[i].checked)
				{
				vRadioButtonValue = oRadioButton[i].value;
				}
			}
		}
	else
		{
		vRadioButtonValue = oRadioButton.value;
		}
	return vRadioButtonValue;
	}

//	---------------------------------------------------------------------------------
//	Function to reload a windows' parent window with a specific option.
//	MenuAction parameter is optional
//	---------------------------------------------------------------------------------
function ReloadOption(vRemoteST, vSegmentID, vOptionID, vMenuAction, vValuePairs)
{
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	delete locarray[(locarray.length-1)];
	var locStr = locarray.join("/");

	var vURL = locStr+"elmLearner.wml&RemoteST="+vRemoteST+"&Segment=" + vSegmentID + "&Option=" + vOptionID;
	vURL+= ((ReloadOption.arguments.length == 3)?"":((vMenuAction=="None")?"&MenuAction=None":""));
	vURL+= ((ReloadOption.arguments.length == 5)?vValuePairs:"");
//	parent.opener.document.location = vURL;
	if (opener)
		{
		opener.document.location = vURL;
		CloseWindow();
		}
	else
		{
		document.location = vURL;
		}
	}

//	---------------------------------------------------------------------------------
//	Function to close a window
//	---------------------------------------------------------------------------------
function CloseWindow()
	{
	parent.self.close();
	}

//	---------------------------------------------------------------------------------
//	Function to SELECT (or DE-SELECT) all items in a listbox based on the value of a checkbox
//	---------------------------------------------------------------------------------
function SelectAllOptions(oCheckBox, oSelectList)
	{
	if (oCheckBox && oSelectList)
		{
		for (var vIndex = 0; vIndex <oSelectList.length; vIndex++)
			{
			oSelectList.options[vIndex].selected = ((oCheckBox.checked)?true:false);
			}
		}
	return true;
	}

//	---------------------------------------------------------------------------------
//	Function to move selected items from one list box to another
//	---------------------------------------------------------------------------------
function MoveSelectedItems(oSource, oDestination)
	{
	var vText;
	var i = oSource.length - 1;

	while (i > -1)
		{
		if (oSource.options[i].selected)
			{
			vValue = oSource.options[i].value;
			vWanted = true;

			for (j=0; j<oDestination.length; j++)
				{
				if (oDestination.options[j].value == vValue)
					{
					vWanted = false;
					break;
					}
				}
			if (vWanted == true)
				{
				oDestination.options[oDestination.length] = new Option(oSource.options[i].text, vValue);
				}
			oSource.options[i] = null;
			}
		i--;
		}
	oSource.selectedIndex = -1;
	return true;
	}

function popUpN(strURL, strType, strWidth, strHeight) { 

var newWin = null; 

    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;

    var xOffset = (xMax - 200)/2, yOffset = (yMax - 200)/2;

 if (newWin != null && !newWin.closed) 
   newWin.close(); 

//   alert(strType);

 var strOptions=""; 
 if (strType=="console") 
   strOptions="resizable,height="+ 
     strHeight+",width="+strWidth+",screenX="+xOffset+",screenY="+yOffset+",top="+yOffset+",left="+xOffset; 
 if (strType=="fixed") 
   strOptions="status,height="+ 
     strHeight+",width="+strWidth; 
 if (strType=="elastic") 
   strOptions="toolbar,menubar,scrollbars,"+ 
     "resizable,location,height="+ 
     strHeight+",width="+strWidth; 

//	 alert(strOptions);

 newWin = window.open(strURL, 'newWin', strOptions); 
 newWin.focus(); 
}

 var popWin = null    // use this when referring to pop-up window
 var winCount = 0
 var winName = "popWin"

function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop, winClose)
	{
	var d_winLeft = 20  // default, pixels from screen left to window left
	var d_winTop = 20   // default, pixels from screen top to window top
	if (opener == null)
		{
		winName = "popWin" + winCount++ //unique name for each pop-up window
		}
	else
		{
		winName = opener.winName + "_" + "popWin" + winCount++ //unique name for each pop-up window
		}

	if ((winClose == null) || (winClose != 0))
		{
		closePopWin();           // close any previously opened pop-up window
		}

	if (openPopWin.arguments.length >= 4)  // any additional features? 
		winFeatures = "," + winFeatures
	else 
		winFeatures = "" 

	if (openPopWin.arguments.length >= 6)  // location specified
		winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
	else
		winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)

	popWin = window.open(winURL, winName, "width=" + winWidth + ",height=" + winHeight + winFeatures)
	}

function closePopWin()
	{    // close pop-up window if it is open 
	if (navigator.appName != "Microsoft Internet Explorer" || parseInt(navigator.appVersion) >=4) //do not close if early IE
		if(popWin != null)
			if (!popWin.closed)
				popWin.close()
	}

function getLocation(winWidth, winHeight, winLeft, winTop){
   return ""
   }

 function getLocation(winWidth, winHeight, winLeft, winTop){
   var winLocation = ""
   if (winLeft < 0)
     winLeft = screen.width - winWidth + winLeft
   if (winTop < 0)
     winTop = screen.height - winHeight + winTop
   if (winTop == "cen")
     winTop = (screen.height - winHeight)/2 - 20
   if (winLeft == "cen")
     winLeft = (screen.width - winWidth)/2
   if (winLeft>0 & winTop>0)
     winLocation =  ",screenX=" + winLeft + ",left=" + winLeft   
                 + ",screenY=" + winTop + ",top=" + winTop
   else
     winLocation = ""
   return winLocation
   }

_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
 document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
 document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }


var wintop;
function Callexit()
{
	if (wintop != window.screenTop)
	{
		var myloc = window.location.href;
		var locarray = myloc.split("/");
		delete locarray[(locarray.length-1)];
		var locStr = locarray.join("/");	

		document.frmlogout.action=locStr+"Mess_NTAuthEnd.wml";
		document.frmlogout.target="_blank";
		document.frmlogout.submit();	
		
		
	}
}
function GetTop()
{
	wintop=window.screenTop;
}

function openFullWindow(sURL)
	{
	   var d_winLeft = 1  // default, pixels from screen left to window left
	   var d_winTop = 1   // default, pixels from screen top to window top
	   var w = window.screen.availWidth - 10;
	   var h = window.screen.availHeight - 30;
		window.open(sURL,'coursewin','width=' + w + ',height=' + h + ',top=1,left=1,menubar=no,toolbar=no,location=no,resizable=yes,status=no,scrollbars=yes');		<!---window.open(sURL,'coursewin','width=795,height=579,top=0,left=0,menubar=no,toolbar=no,location=yes,resizable=yes,status=no,scrollbars=yes');--->	
	}  //function open window	


//	---------------------------------------------------------------------------------
//	Global variables for milliseconds in an hour and in a minute
//	---------------------------------------------------------------------------------
var gvMS_Day = 86400000.;
var gvMS_Hour = 3600000.;
var gvMS_Minute = 60000.;

//	---------------------------------------------------------------------------------
// function to load the calendar window.
//	---------------------------------------------------------------------------------
function ShowCalendar(FormName, FieldName, DateFormat)
{
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	delete locarray[(locarray.length-1)];
	var locStr = locarray.join("/");
	window.open(locStr+"LWDateSelectPopupWindow.wml&FormName=" + FormName + "&FieldName=" + FieldName + "&DateFormat=" + DateFormat, "CalendarWindow", "width=192,height=256");
}

function ShowCalendar2(FieldName, DateFormat)
{
	var myloc = window.location.href;
	var locarray = myloc.split("/");
	delete locarray[(locarray.length-1)];
	var locStr = locarray.join("/");
	window.open(locStr+"LWDateSelectPopupWindow.wml&FieldName=" + FieldName + "&DateFormat=" + DateFormat, "CalendarWindow", "width=192,height=256");
}

//	---------------------------------------------------------------------------------
//	Function to convert a date string to a date variable
//	---------------------------------------------------------------------------------
function StringToDate(sDate, sDateFormat)
	{
	var dArr = sDate.split("/");

	if (sDateFormat == "mm/dd/yyyy")
		{
		var d = new Date(dArr[2], dArr[0]-1, dArr[1]);
		}
	else
		{
		var d = new Date(dArr[2], dArr[1]-1, dArr[0]);
		}
	return d;
	}

//	---------------------------------------------------------------------------------
//	Function to convert a date variable to a date string
//	---------------------------------------------------------------------------------
function DateToString(vDate, sDateFormat)
	{

	var vMonth = vDate.getMonth() + 1;
	var vDay = vDate.getDate();
	var vYear = FullYear(vDate);

	if (sDateFormat == "mm/dd/yyyy")
		{
		var d = LZ(vMonth) + "/" + LZ(vDay) + "/" + vYear;
		}
	else
		{
		var d = LZ(vDay) + "/" + LZ(vMonth) + "/" + vYear;
		}
	return d;
	}

//	---------------------------------------------------------------------------------
//	Function to check that a date string is a valid date
//	---------------------------------------------------------------------------------
function CheckDate(sDate, sDateFormat)
	{
	var re = /^\d{1,2}\/\d{1,2}\/\d{2}|d{4}$/
	if (re.test(sDate))
		{
		var dArr = sDate.split("/");
		var d = StringToDate(sDate, sDateFormat)
		if (sDateFormat == "mm/dd/yyyy")
			{
			return ((d.getMonth() + 1) == dArr[0]) && (d.getDate() == dArr[1]) && (FullYear(d) == InputYear(dArr[2]));
			}
		else
			{
			return ((d.getMonth() + 1) == dArr[1]) && (d.getDate() == dArr[0]) && (FullYear(d) == InputYear(dArr[2]));
			}
		}
	else
		{
		return false;
		}
	}

function FullYear(date)
	{
	var y = date.getFullYear();
	//if (y < 1000) y += 2000;
	return y;
	}

function InputYear(sYear)
	{
	if (sYear.length == 2) sYear="20" + sYear;
	return sYear;
	}

//	---------------------------------------------------------------------------------
//	Function to check that one date is earlier than another date
//	---------------------------------------------------------------------------------
function DateRangeCheck(FromDate, ToDate)
	{
	if (Date.parse(FromDate.value) <= Date.parse(ToDate.value))
		{
		return true;
		}
	else
		{
		return false;
		}
	}

//	---------------------------------------------------------------------------------
//	Function to check that a time string is a valid time
//	---------------------------------------------------------------------------------
function CheckTime(sTime)
	{
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	var matchArray = sTime.match(timePat);
	if (matchArray == null)
		{
		return false;
		}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="")
		{
		second = null;
		}
	if (ampm=="")
		{
		ampm = null
		}
	if (hour < 0 || hour > 23)
		{
		return false;
		}
	if (hour <= 12 && ampm == null)
		{
		return false;
		}
	if (hour > 12 && ampm != null)
		{
		return false;
		}
	if (minute<0 || minute > 59)
		{
		return false;
		}
	if (second != null && (second < 0 || second > 59))
		{
		return false;
		}
	return true;
	}

function BuildDate(sDate, sHour, sMinute)
	{
	return sDate + " " + sHour + ":" + sMinute;
	}

//	---------------------------------------------------------------------------------
//	Function to return a 2-digit number with leading zeros
//	---------------------------------------------------------------------------------
function LZ(x)
	{
	return (x>9||x<0?"":"0") + x;
	}

//	---------------------------------------------------------------------------------
//	Function to check that a string is a valid integer within a certain range
//	---------------------------------------------------------------------------------
function CheckInteger(sNumString, intMin, intMax)
	{
	var tmpString = sNumString;
	if (tmpString.length < 0)
		{
		return false;
		}
	var intChar = tmpString.charCodeAt(0);
	var intUnary;
	if (intChar == 45)
		{
		intUnary = -1;
		tmpString = tmpString.substr(1);
		}
	else if (intChar == 43)
		{
		intUnary = 1;
		tmpString = tmpString.substr(1);
		}
	else
		{
		intUnary = 1;
		}
	var strLen = tmpString.length;
	for (i=0;i<strLen;i++)
		{
		var intChar = tmpString.charCodeAt(i);
		if ((intChar < 48) || (intChar > 57))
			{
			return false;
			}
		}

	var intNum = parseInt(tmpString, 10);
	intNum = intNum * intUnary;
	if ((intNum < intMin) || (intNum > intMax))
		{
		return false;
		}
	return true;
	}

//	---------------------------------------------------------------------------------
//	Function to check that a string is a valid real number within a certain range
//	---------------------------------------------------------------------------------
function CheckReal(sNumString, realMin, realMax)
	{
	var tmpString = sNumString;
	if (tmpString.length < 0)
		{
		return false;
		}
	var intChar = tmpString.charCodeAt(0);
	var intUnary;
	if (intChar == 45)
		{
		intUnary = -1;
		tmpString = tmpString.substr(1);
		}
	else if (intChar == 43)
		{
		intUnary = 1;
		tmpString = tmpString.substr(1);
		}
	else
		{
		intUnary = 1;
		}
	var strLen = tmpString.length;
	for (i=0;i<strLen;i++)
		{
		var intChar = tmpString.charCodeAt(i);
		if (intChar != 46)
			{
			if ((intChar < 48) || (intChar > 57))
				{
				return false;
				}
			}
		}

	var realNum = parseFloat(tmpString);
	realNum = realNum * intUnary;
	if ((realNum < realMin) || (realNum > realMax))
		{
		return false;
		}
	return true;
	}

