var is = {
// The -is- object is used to identify the browser.  Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be 
// Mozilla 4. Netscape 6 claims to be version 5.
    ie:      navigator.appName == 'Microsoft Internet Explorer',
    java:    navigator.javaEnabled(),
    ns:      navigator.appName == 'Netscape',
    ua:      navigator.userAgent.toLowerCase(),
    version: parseFloat(navigator.appVersion.substr(21)) ||
             parseFloat(navigator.appVersion),
    win:     navigator.platform == 'Win32'};
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
    is.ie = is.ns = false;
    is.opera = true;
} else {is.opera = false;}
if (is.ua.indexOf('gecko') >= 0) {
    is.ie = is.ns = false;
    is.gecko = true;
} else {is.gecko = false;}
Date.prototype.getTotalMilliseconds = function () {
	return ((this.getHours() * 3600000) + (this.getMinutes() * 60000) + (this.getSeconds() * 1000) + this.getMilliseconds());
}
function checkTimeout() {
	if (frames.length > 0) {
		frames(0).location.replace(frames(0).location.href);
		if ((window.timerLastChecked + window.timeout) < (new Date()).getTotalMilliseconds()) {
			frames(0).location.replace("/IClassroom/SignOut.aspx?Err=SESSION");
			if (typeof dialogArguments != "undefined") {
				close();
				return;
			}
		}
	}
	resetTimeout();
}
registerEvent(window, "onfocus", checkTimeout);
function resetTimeout() {
	window.timerLastChecked = (new Date()).getTotalMilliseconds();
}
function doPostBack(sEventTarget, sEventArgument)
//	Provided to be called from VbScript functions
{
	__doPostBack(sEventTarget, sEventArgument);
}
///////////////////////////////////////////////////////////
// registerEvent(oElement, sEvent, fpFunc)
//		oElement -> element that event will be added to
//		sEvent -> string name of event to add, ex. "onclick"
//		fpFunc -> function to register with event
//	Registers a function with the specified Event on the specified Element
///////////////////////////////////////////////////////////
function registerEvent(oElement, sEvent, fpFunc)
{
	var fpOld = (oElement[sEvent]) ? oElement[sEvent] : function () {};
	oElement[sEvent] = function (e) {if (fpOld(e) == false) return false; else return fpFunc(e)};
}
///////////////////////////////////////////////////////////
// writeCookie(sName, oValue, nDays)
//		sName -> name of cookie to be written
//		oValue -> value of cookie to be written
//		nDays -> number of days until cookie expires
//	Creates a cookie (if necessary), and assigns its value
///////////////////////////////////////////////////////////
function writeCookie(sName, oValue, nDays)
{
	var sExpires = "";
	if (nDays)
	{
		var dDate = new Date();
		dDate.setTime(dDate.getTime() + (nDays * 24 * 60 * 60 * 1000));
		sExpires = "; expires=" + dDate.toGMTString();
	}
	document.cookie = sName + "=" + oValue + sExpires + "; path=/";
}
///////////////////////////////////////////////////////////
// readCookie(sName)
//		sName -> name of cookie to be read
//		Return Value: value of cookie, or null if cookie not found
//	Returns the value of a cookie
///////////////////////////////////////////////////////////
function readCookie(sName)
{
	var sRet = null;
	var nameEQ = sName + "=";
	var ca = document.cookie.split(";");
	for (var i=0; i < ca.length; i++)
	{
		var c = ca[i];
		while (c.charAt(0) == " ")
			c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
		{
			sRet = c.substring(nameEQ.length, c.length);
			break;
		}
	}
	return sRet;
}
///////////////////////////////////////////////////////////
// deleteCookie(sName)
//		sName -> name of cookie to be deleted
//	Deletes a cookie
///////////////////////////////////////////////////////////
function deleteCookie(sName)
{
	writeCookie(sName, "", -1);
}
///////////////////////////////////////////////////////////
function DetectBrowser()
{
// This function sets the following four variables:
//  navigator.OS
//  navigator.version
//  navigator.org
//  navigator.family
//
  var oldOnError = window.onerror;
  var element = null;

  window.onerror = null;

  // work around bug in xpcdom Mozilla 0.9.1
  window.saveNavigator = window.navigator;

  navigator.OS    = '';
  navigator.version  = parseFloat(navigator.appVersion);
  navigator.org    = '';
  navigator.family  = '';

  var platform;
  if (typeof(window.navigator.platform) != 'undefined')
  {
    platform = window.navigator.platform.toLowerCase();
    if (platform.indexOf('win') != -1)
      navigator.OS = 'win';
    else if (platform.indexOf('mac') != -1)
      navigator.OS = 'mac';
    else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
      navigator.OS = 'nix';
  }

  var i = 0;
  var ua = window.navigator.userAgent.toLowerCase();

  if (ua.indexOf('opera') != -1)
  {
    i = ua.indexOf('opera');
    navigator.family  = 'opera';
    navigator.org    = 'opera';
    navigator.version  = parseFloat('0' + ua.substr(i+6), 10);
  }
  else if ((i = ua.indexOf('msie')) != -1)
  {
    navigator.org    = 'microsoft';
    navigator.version  = parseFloat('0' + ua.substr(i+5), 10);

    if (navigator.version < 4)
      navigator.family = 'ie3';
    else
      navigator.family = 'ie4'
  }
  else if (ua.indexOf('gecko') != -1)
  {
    navigator.family = 'gecko';
    var rvStart = navigator.userAgent.indexOf('rv:') + 3;
    var rvEnd = navigator.userAgent.indexOf(')', rvStart);
    var rv = navigator.userAgent.substring(rvStart, rvEnd);
    var decIndex = rv.indexOf('.');
    if (decIndex != -1)
    {
      rv = rv.replace(/\./g, '')
      rv = rv.substring(0, decIndex) + '.' + rv.substr(decIndex)
    }
    navigator.version = parseFloat(rv);

    if (ua.indexOf('netscape') != -1)
      navigator.org = 'netscape';
    else if (ua.indexOf('compuserve') != -1)
      navigator.org = 'compuserve';
    else
      navigator.org = 'mozilla';
  }
  else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  {
    var is_major = parseFloat(navigator.appVersion);

    if (is_major < 4)
      navigator.version = is_major;
    else
    {
      i = ua.lastIndexOf('/')
      navigator.version = parseFloat('0' + ua.substr(i+1), 10);
    }
    navigator.org = 'netscape';
    navigator.family = 'nn' + parseInt(navigator.appVersion);
  }
  else if ((i = ua.indexOf('aol')) != -1 )
  {
    // aol
    navigator.family  = 'aol';
    navigator.org    = 'aol';
    navigator.version  = parseFloat('0' + ua.substr(i+4), 10);
  }
  else if ((i = ua.indexOf('hotjava')) != -1 )
  {
    // hotjava
    navigator.family  = 'hotjava';
    navigator.org    = 'sun';
    navigator.version  = parseFloat(navigator.appVersion);
  }

  window.onerror = oldOnError;
}
DetectBrowser();
///////////////////////////////////////////////////////////
if (navigator.OS == "mac")
{
	document.onkeydown = e_KeyDown;
	document.onkeyup = e_KeyUp;
}
else if (navigator.org == "microsoft")
{
	document.attachEvent("onkeydown", e_KeyDown);
	document.attachEvent("onkeyup", e_KeyUp);
}
else
{
	document.addEventListener("keydown", e_KeyDown, true);
	document.addEventListener("keyup", e_KeyUp, true);
}
document.ShiftDown = false;
document.CtrlDown = false;
///////////////////////////////////////////////////////////
function e_KeyDown(e)
{
	if (e == null)
		e = event;
	switch (e.keyCode)
	{
		case 16:	//ShiftKey
			document.ShiftDown = true;
			break;
		case 17:	//CtrlKey
		case 91:    //MacOptionKey
			document.CtrlDown = true;
			break;
	}
}
///////////////////////////////////////////////////////////
function e_KeyUp(e)
{
	if (e == null)
		e = event;
	switch (e.keyCode)
	{
		case 16:	//ShiftKey
			document.ShiftDown = false;
			break;
		case 17:	//CtrlKey
		case 91:    //MacOptionKey
			document.CtrlDown = false;
			break;
	}
}
///////////////////////////////////////////////////////////
String.prototype.trimLeft = stringTrimLeft;
String.prototype.trimRight = stringTrimRight;
String.prototype.trim = stringTrim;
String.prototype.replaceAt = stringReplaceAt;
function stringTrimLeft()
{
	var rStr = new String(this);
	while (rStr.length != 0 && rStr.charAt(0) == " ")
	{
		rStr = rStr.substring(1,rStr.length);
	}
	return rStr;
}
function stringTrimRight()
{
	var rStr = new String(this);
	while (rStr.length != 0 && rStr.charAt(rStr.length - 1) == " ")
	{
		rStr = rStr.substring(0,rStr.length - 1);
	}
	return rStr;
}
function stringTrim()
{
	var rStr = new String(this);
	rStr = rStr.trimLeft();
	rStr = rStr.trimRight();
	return rStr;
}
function stringReplaceAt(nOrd, cChar)
{
	return new String(this.slice(0, nOrd) + cChar + this.slice(nOrd + 1));
}
///////////////////////////////////////////////////////////////////////////////
function clickElement (element)
{
	if (element.click)
		element.click();
	else if (element.dispatchEvent)
	{
		var evt = document.createEvent('MouseEvents');
		evt.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		element.dispatchEvent(evt);
	}
}
///////////////////////////////////////////////////////////////////////////////
//This line disables right-click menus
//document.oncontextmenu = new Function("return false");
//
///////////////////////////////////////////////////////////////////////////////
//This function initializes a Browse
function initBrowse(pTable,pSelected,pHeaderRows,pIsMultiSelect)
{
	//is there any data in this table?
	if (pTable.rows.length>pHeaderRows)
	{
		if (pIsMultiSelect == true)
		{
			var x;
			//build pSelected.value if necessary
			if (pSelected.value == "")
			{
				for (x = pHeaderRows; x < pTable.rows.length; ++x)
				{
					pSelected.value += "0";
				}
			}
			//make sure a row is selected, and all selected rows are colored properly
			if (pSelected.value.indexOf("1") < 0)
			{
				setRow(pTable.rows[pHeaderRows],pTable,pSelected,pHeaderRows,pIsMultiSelect);
			}
			else
			{
				for (x = 0; x < pSelected.value.length; ++x)
				{
				    if (pSelected.value.charAt(x) == "1")
				    {
						{
							pSelected.value = pSelected.value.slice(0, x) + "0" + pSelected.value.slice(x + 1);
							setRow(pTable.rows[x + pHeaderRows],pTable,pSelected,pHeaderRows,pIsMultiSelect);
						}
					}
				}
			}
		}
		else //pIsMultiSelect == false
		{
			//make sure a row is selected
			if ((pSelected.value == "") || (pSelected.value > (pTable.rows.length - 1)) || (pSelected.value < pHeaderRows))
			{
				pSelected.value = pHeaderRows;
			}
			//color selected row properly
			setRow(pTable.rows[pSelected.value],pTable,pSelected,pHeaderRows,pIsMultiSelect);
		}
	}
	//If there is no data in this table, clear pSelected.value
	else
	{
		pSelected.value = "";
	}
}
///////////////////////////////////////////////////////////////////////////////
//This function marks the currently selected row within a Browse
function setRow(pRow,pTable,pSelected,pHeaderRows,pIsMultiSelect)
{
	var oRow;
	if (pIsMultiSelect == true)
	{
		for (var x = pHeaderRows; x < pTable.rows.length; ++x)
		{
			oRow = pTable.rows[x];
			if (oRow == pRow)
			{
				if (pSelected.value.charAt(x - pHeaderRows) == "1")
				{
					pSelected.value = pSelected.value.slice(0, x - pHeaderRows) + "0" + pSelected.value.slice(x - pHeaderRows + 1);
					oRow.bgColor = "";
				}
				else
				{
					pSelected.value = pSelected.value.slice(0, x - pHeaderRows) + "1" + pSelected.value.slice(x - pHeaderRows + 1);
					oRow.bgColor = "LightBlue";
				}
				break;
			}
		}
	}
	else //pIsMultiSelect == false
	{
		pTable.rows[pSelected.value].bgColor = "";
		for (var x = pHeaderRows; x < pTable.rows.length; ++x)
		{
			oRow = pTable.rows[x];
			if (oRow == pRow)
			{
				pSelected.value = x;
				oRow.bgColor = "LightBlue";
				break;
			}
		}
	}
}
///////////////////////////////////////////////////////////////////////////////
//This function Enables/Disables a button
function setButton(pButton,pEnabled)
{
	if (pButton != null)
	{
		with (pButton)
		{
			if (pEnabled == false)
			{
				disabled = "disabled";
				href = "#";
			}
			else
			{
				disabled = "";
				href = "javascript:__doPostBack('" + id + "','')";
			}
		}
	}
}
///////////////////////////////////////////////////////////////////////////////
//This function HiLites a Menu option
function HiLiteRow (oRow) {
	oRow.style.background = "LightBlue";
}
function RestoreRow (oRow) {
	oRow.style.background = "LightGrey";
}
function ShowMenu (oMenu) {
	oMenu.style.display = "";
}
function HideMenu (oMenu) {
	oMenu.style.display = "none";
}
function HideDrops() {
	var a = document.getElementsByTagName("select");
	for (var i = 0; i < a.length; i++)
		a[i].style.visibility = "hidden";
}
function ShowDrops() {
	var a = document.getElementsByTagName("select");
	for (var i = 0; i < a.length; i++)
		if (a[i] && a[i].offsetParent)
			a[i].style.visibility = "visible";
}
///////////////////////////////////////////////////////////////////////////////
//This function retrieves a Cookie
function GetCookie(name)
{
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if (startOfCookie != -1)
	{
		startOfCookie += searchName.length; // skip past cookie name;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}
	return result;
}
///////////////////////////////////////////////////////////////////////////////
//This function sets a Cookie
function SetCookie(name, value, expires, path, domain, secure)
{
	if ((expires == null) || (expires < 0))
	{
		expires = 0;
	}
	var nOneDay = 86400000; // 24 * 60 * 60 * 1000 = 86400000
	var nExpire = expires * nOneDay;
	var dExpire = new Date();
	dExpire.setTime(dExpire.getTime() + nExpire);
	var expString = "; expires=" + dExpire.toGMTString();
	var pathString = ((path == null) ? "" : ("; path=" + path));
	var domainString = ((domain == null) ? "" : ("; domain=" + domain));
	var secureString = ((secure == true) ? "; secure" : "");
	document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}

