///!!!!IMPORTANT!!!! This JavaScript file has been MOVED to the lib folder as these script should NOT be tied to theme
///This file needs to be split up later

// Global Variables
var jsDateFormat = "MM/DD/YYYY";
// Global Methods
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null)
  {
  	v=args[i+2];
    if (obj.style)
    {
    	obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v;
    }
    obj.visibility=v;
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showNavLayer(divObject, visible, tdObject) { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;

  var Y = findY(tdObject);
  obj=MM_findObj(divObject)
  if (obj !=null)
  {
    if (obj.style)
    {
    	obj=obj.style; visible=(visible=='show')?'visible':(visible=='hide')?'hidden':visible;
    }
    obj.visibility=visible;
    // if a popup dont change the height
    if(tdObject.id.indexOf("leftnavdiv_popup") > -1)
    {
    	obj.top = Y;
    }
    else
    {
    	obj.top = Y;
    }

    obj.left = "225px";
  }
}

/// <summary>Gets the y position of the obj</summary>
function findY(obj)
{
	var y = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		y += obj.y;
	}
	return(y);
}

function openWin(theURL, width, height, scrollbars, windowName, resize, toolbar, menubar, directories, titlebar, addressbar, statusbar)
{
	if(width == null) width = 680;
	if(height == null) height = 350;
	if(scrollbars == null) scrollbars = "yes";
	if(windowName == null) windowName = "mywindow";
	if(resize == null) resize = "yes";
	if(toolbar == null) toolbar = "no";
	if(menubar == null) menubar = "no";
	if(directories == null) directories = "no";
	if(titlebar == null) titlebar = "no";
	if(addressbar == null) addressbar = "no";
	if(statusbar == null) statusbar = "no";
	if(location == null) location = "no";

	var thewindow = window.open (theURL, windowName, "status=" + statusbar + ",statusbar=" + statusbar + ",location=" + location + ",directories=" + directories + ",titlebar="+ titlebar + ",menubar=" + menubar + ",toolbar=" + toolbar + ",resizable=" + resize + ",scrollbars=" + scrollbars + ",width=" + width + ",height=" + height);
	if(!thewindow)
	{
		if(theURL.indexOf("/studentportal/") > -1)
			alert("The portal window could not open, probably because you have a Popup Blocker enabled!. Please follow the following steps. \n - Please disable the blocker for this site. \n - Then click the Course Portal Link again.");
		else
			alert("The popup window could not open, probably because you have a Popup Blocker enabled! \n - Please disable the blocker for this site.");
	}
	else
	{
		thewindow.focus();
	}

	return thewindow;
}


// The following function, help to disable the right click for a certain element name called imagetag
function rightclick(e) {
	if (document.getElementById || document.all || document.layers) {
		if (event.button == 2) {
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			if (targ.nodeType == 3) { // defeat Safari bug
				targ = targ.parentNode;
			}

			if(targ.id == "imagetag" && targ.id != "")
			{
				alert("This file is copyright of realestateeducate.com");
				return false;
			}
		}
	}
	if (document.layers)
	{
		if (e.which == 3)
		{
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			if (targ.nodeType == 3) { // defeat Safari bug
				targ = targ.parentNode;
			}
			if(targ.id == "imagetag")
			{
				alert("You cannot save this file");
				return false;
			}
		}
	}
}
if (document.layers) {
	document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=rightclick;

function printWindow(){
	window.print();
	return (true);
}

function CheckState(object)
{
	document.location = "/course/" + object.value;
}

if (document.all) {
	var theTables = document.all.tags("TABLE");
	var theRows = document.all.tags("TR");
	var theCols = document.all.tags("TD");
} else {
	var theTables = document.getElementsByTagName("TABLE");
	var theRows = document.getElementsByTagName("TR");
	var theCols = document.getElementsByTagName("TD");
}

// This toggles all table rows with an id tag named theObject
function toggleDisplay(theObject, theTD)
{
	for (i=0; i<theRows.length; i++)
	{
		if (theRows[i].id == theObject)
		{
			if (theRows[i].style.display == "table")
			{
				theRows[i].style.display = "none";
			}
			else
			{
				theRows[i].style.display = "table";
			}
		}
	}

	try
	{
		if(theTD.innerHTML.indexOf("+") > -1)
		{
			theTD.innerHTML = " - ";
		}
		else if(theTD.innerHTML.indexOf("-") > -1)
		{
			theTD.innerHTML = " + ";
		}
	}
	catch(err)
	{
	}
}
//Added this from the hTheme page_ajax_request.js jjervis 2009-04-17
function initFlyoutJS(theElmID, theLinkID)
{
	var theElmToFly = document.getElementById(theElmID);
	var theElmToClick = theLinkID;
	var theLinkText=new String(theElmToClick.innerHTML);
	var fOut = "+"; // replace this
	var fIn = "-"; // with this
	//theLinkText = theElmToClick.innerHTML;
	if (theElmToFly.style.display == "block")
	{
		theElmToFly.style.display = "none";
	}
	else
	{
		theElmToFly.style.display = "block";
	}
	try
	{
		if(theLinkText.indexOf(fOut) > -1)
		{
			var pos = theLinkText.indexOf(fOut);
			theLinkText = "" + (theLinkText.substring(0, pos) + fIn +
			theLinkText.substring((pos + fOut.length), theLinkText.length));
			theElmToClick.innerHTML = theLinkText;
		}
		else if(theLinkText.indexOf(fIn) > -1)
		{
			var pos = theLinkText.indexOf(fIn);
			theLinkText = "" + (theLinkText.substring(0, pos) + fOut +
			theLinkText.substring((pos + fIn.length), theLinkText.length));
			theElmToClick.innerHTML = theLinkText;
		}
	}
	catch(err)
	{
	}
}



////////////////////////////
function showRow(theName) {
	for (i=0; i<theRows.length; i++) {
		if (theRows[i].id.indexOf(theName) == 0) {
			theRows[i].style.display = "inline";
		}
	}
}

function hideRow(theName) {
	for (i=0; i<theRows.length; i++) {
		if (theRows[i].id.indexOf(theName) == 0) {
			theRows[i].style.display = "none";
		}
	}
}
//************** PORTAL FUNCTIONS *********************************
// openWin(theURL, width, height, scrollbars, windowName, resize, toolbar, menubar, directories, titlebar, addressbar, statusbar)
function portal_navigate(url, object, root)
{
	try
	{
		if(window.opener != null && window.opener.closed == false)
		{
			window.opener.location = root + url;
			window.opener.focus();
		}
		else
		{
			var newwindow = openWin(root + url, 800, 600, 1, "parentwindow", "yes", 'yes', 'yes', 'yes','yes', "yes", "yes");
			window.opener = newwindow;
			newwindow.focus();
		}
	}
	catch(err)
	{
		alert(err.description);
	}
}

function portal_openwindow(url, windowname, width, height, scrollbar, toolbar, resize)
{

}

// Change the location on the parent page to the logout/login page, then close this window
// openWin(theURL, width, height, scrollbars, windowName, resize, toolbar, menubar, directories, titlebar, addressbar, statusbar)
function portal_logout(type, root)
{
	if(type == null) type = "logout";

	try
	{
		// if type is login
		if(type == "login")
		{
				if(window.opener != null && window.opener.closed == false)
				{
					window.opener.location = root + "/login/index.php";
					window.opener.focus();
					window.close();
				}
				else
				{
					var newwindow = openWin(root + "/login/index.php", 800, 600, 1, "parentwindow", "yes", 'yes', 'yes', 'yes','yes', 'yes');
					window.opener = newwindow;
					newwindow.focus();
					window.close();
				}
		}
		else // default logout
		{
			if(confirm("Are you sure you want to logout"))
			{
				if(window.opener != null && window.opener.closed == false)
				{
					window.opener.location = root + "/login/logout.php";
					window.opener.focus();
					window.close();
				}
				else
				{
					var newwindow = openWin(root + "/login/logout.php", 800, 600, 1, "parentwindow", "yes", 'yes', 'yes', 'yes','yes', 'yes');
					window.opener = newwindow;
					newwindow.focus();
					window.close();
				}
			}
		}
	}
	catch(err)
	{
		//openWin(root + url, 800, 600, false, "parentwindow", true);
		alert(err.description);
	}

}

//convert Value into Money
function convertMoney(theValue)
{

	jsMoney = new Number(theValue);
	jsString = '' + Math.round(jsMoney*100)/100;

	for (i=0; i<jsString.length; i++)
	{
		if (jsString.charAt(i) == '.') break;
	}
	if (i == jsString.length) return(jsString + ".00");
	else if (i == (jsString.length-1)) return(jsString + "00");
	else if (i == (jsString.length-2)) return(jsString + "0");
	else return(jsString);
}

var portalwindow;
// openWin(theURL, width, height, scrollbars, windowName, resize, toolbar, menubar, directories, titlebar, addressbar, statusbar)
function open_portal_main(url, confirmopen)
{
	var result = true;
	if(result)
	{
		if (screen.height <= 600) {
			portalwindow = openWin(url, 785, 580, "yes", 'portal_window', "yes", "no", "no", "no","no", "no", "no");
		} else {
			portalwindow = openWin(url, 785, 580, "no", 'portal_window', "yes", "no", "no", "no","no", "no", "no");
		}
		if (!portalwindow.opener) portalwindow.opener = self;

		if (window.focus)
		{
			portalwindow.focus()
		}
	}
	else
	{
		window.document.location = url;
	}
	//return true;
}
var popupWin;
function open_portal(url, force)
{
	try
	{
		if(force)
		{
			open_portal_main(url, false);
		}
		else
		{
			var name = 'portal_window';
			if(popupWin)
			{
				if(typeof(popupWin) != "object" || popupWin.closed)
				{
					if (screen.height <= 600)
					{
						popupWin = openWin(url, 785, 580, "yes", 'portal_window',  "yes", "no", "no", "no", "no", "no", "no");
					}
					else
					{
						popupWin = openWin(url, 785, 580, "no", 'portal_window',  "yes", "no", "no", "no", "no", "no", "no");
					}
				}
				else
				{
					if (name != popupWin.name)
					{
						popupWin.close();
						if (screen.height <= 600)
						{
							popupWin = openWin(url, 785, 580, "yes", 'portal_window',  "yes", "no", "no", "no", "no", "no", x);
						}
						else
						{
							popupWin = openWin(url, 785, 580, "no", 'portal_window',  "yes", "no", "no", "no", "no", "no", x);
						}
					}
				}
			}
			else
			{
				if (screen.height <= 600)
				{
					popupWin = openWin(url, 785, 580, "yes", 'portal_window',  "yes", "no", "no", "no", "no", "no");
				}
				else
				{
					popupWin = openWin(url, 785, 580, "no", 'portal_window',  "yes", "no", "no", "no", "no", "no");
				}
			}

			if(popupWin) popupWin.focus();
		}
	}
	catch(err)
	{
		//alert(err.description);
	}
}

if (document.all)
{
	var theTables = document.all.tags("TABLE");
	var theRows = document.all.tags("TR");
	var theImages = document.all.tags("img");
}
// This toggles all table rows with an id tag named theObject
/*function toggleDisplay(theObject, theImage)
{
	var image = "arrowright.gif";
	for (i=0; i<theRows.length; i++)
	{
		if (theRows[i].id == theObject)
		{
			if (theRows[i].style.display == "inline")
			{
				theRows[i].style.display = "none";
				image = "<?php echo $CFG->wwwroot; ?>/images/arrowright.gif";
			}
			else
			{
				theRows[i].style.display = "inline";
				image = "<?php echo $CFG->wwwroot; ?>/images/arrowdown.gif";
			}
		}
	}

	for (i=0; i<theImages.length; i++)
	{
		if (theImages[i].id == theImage)
		{
			theImages[i].src = theImages[i].src;
		}

	}
}*/

// check if at least one checkbox item is checked, before selecting the action
function validateAction(theForm, theName, theAction, theObject)
{
	var elements = document.getElementsByTagName("input");
	with (theForm)
	{
		isSelected = false;
		for (i=0; i<elements.length; i++)
		{
			if (elements[i].name == theName)
			{
				if (isSelected = elements[i].checked) break;
			}
		}
		if (!isSelected)
		{
			alert("You must check at least one checkbox before selecting an action to perform");
			return(false);
		}
	}
	return(confirm("Are you sure you want to " + theAction + " " + theObject + "?"));
}

// Display the email popup window
function email_popup(type, subject, from, to, course, root)
{
	// three types (instructor, info, tech support)
	if(root == "" || root == null) root = "<?php echo $CFG->wwwroot?>";
	var useremail = "<?php echo $USER->email ?>";
	var width = 400;
	if(from != "" && useremail != "")
	{
		width = 376;
	}

	url = root + "/mod/message/email.php?type=" + type + "&to=" + to + "&from=" + from + "&subject=" + subject + "&course=" + course;
	openWin(url, 517, width, 0, "email", 1);
}

// Display the email popup window
function quickbase_popup(type, subject, from, to, course, root, supportFor, redirect)
{
	// three types (instructor, info, tech support)
	if(root == "" || root == null) root = "<?php echo $CFG->wwwroot?>";
	var useremail = "<?php echo $USER->email ?>";
	var width = 600;
	if(redirect)
	{
		var redirectOuput = "&redirect=" + redirect;
	}
	else
	{
		var redirectOuput = "";
	}

	url = root + "/mod/message/qbmessage.php?type=" + type + "&to=" + to + "&from=" + from + "&subject=" + subject + "&course=" + course + "&supportFor=" + supportFor + redirectOuput;
	openWin(url, width, 500, 0, "email", 1);
}

// default onload, calls setdefaults if one exists.
function on_load()
{
	try
	{
		setDefaults();
	}
	catch(err)
	{
		// do nothing
	}
}

// print the selected resource
function portal_print(module, cmid, root)
{
	try
	{
		if(module == "resource")
		{
			var newwindow = openWin(root + "/studentportal/print/print" + module + ".php?id=" + cmid, 780, 550, 1, "parentwindow", 1, 'yes', 'yes', 'yes','yes', 'yes');
			newwindow.focus();
		}
		else if(module == "reportcard")
		{
			var newwindow = openWin(root + "/studentportal/print/print" + module + ".php?id=" + cmid, 780, 550, 1, "parentwindow", 1, 'yes', 'yes', 'yes','yes', 'yes');
			newwindow.focus();
		}
		else
		{
			alert("You cannot print lessons or quizs");
		}
	}catch(err)
	{
		alert(err.description)
	}
}
// Toggle checkboxes in a list
checked = false;
function itemSelect(theForm, theName) {
	checked = !checked;
	with (theForm) for (i=0; i<elements.length; i++) {
		if (elements[i].name == theName) elements[i].checked = checked;
	}
}
function itemChecked(theForm, theName) {
	with (theForm) for (i=0; i<elements.length; i++) {
		if (elements[i].name == theName) {
			if (elements[i].checked) return(true);
		}
	}
	return(false);
}

function cancelsubmit(url)
{
	if(confirm("Are you sure you want to cancel?"))
	{
		document.location = url;
	}
}
function changedropdown(action, object, folder)
{
	folder = (folder == null) ? folder = "/course/" : folder;

	if(action == "location")
	{
		if(object.value != "")
		{
			window.top.location  = folder + object.value;
		}
	}
}

function isMoney(theField)
{
	if (theField.value > '' && theField.value != ".")
	{
		var jsMoney = new Number(theField.value);
		jsString = '' + Math.round(jsMoney*100)/100;
		for (i=0; i<jsString.length; i++)
		{
			if (jsString.charAt(i) == '.') break;
		}
		if (i == jsString.length) theField.value = jsString + ".00";
		else if (i == (jsString.length-1)) theField.value = jsString + "00";
		else if (i == (jsString.length-2)) theField.value = jsString + "0";
		else theField.value = jsString;
	}
	else if(theField.value == ".")
	{
		theField.value = "0.00";
	}

	if(theField.value.indexOf("NaN") > -1)
	{
		theField.value = "";
		theField.focus();
		alert("This is an invalid money value");
	}
	return theField.value;
}

// Character Date
function getDateString(theDate, theFormat)
{
	if (theDate.getMonth() < 9) theMonth = "0" + (theDate.getMonth() + 1);
	else theMonth = (theDate.getMonth() + 1);
	if (theDate.getDate() < 10) theDay = "0" + theDate.getDate();
	else theDay = theDate.getDate();
	theYear = theDate.getFullYear();
	theFormat = jsDateFormat;
	if (theFormat == "DD/MM/YYYY") theString = theDay + "/" + theMonth + "/" + theYear;
	else theString = theMonth + "/" + theDay + "/" + theYear;
	return theString;
}


// Character Time
function getTimeString(theTime)
{
	theHours = theTime.getHours();
	theMinutes = theTime.getMinutes();
	theTime = theHours +":"+ theMinutes;
	return theTime;
}

// Date value based on DateFormat system default
function getDateValue(theDate, theFormat)
{
	theResult = new String(theDate);
	if (theFormat == null) theFormat = jsDateFormat;
	if (theFormat == "DD/MM/YYYY") theDate = theResult.substring(3,5) + "/" + theResult.substring(0,2) + "/" + theResult.substring(6,10);
	else theDate = theResult;
	return(new Date(theDate));
}

// Date Selection Window
function getDate(theField) {
	remote = window.open("/help/calendarFrame.html", "CalendarWindow", "toolbar=no,scrollbars=no,resizable=yes,width=250,height=200");
	if (remote != null) {
		if (remote.opener == null) remote.opener = self;
		if (remote.dateField == null) remote.dateField = theField;
	}
}
// Date Selection Window
function getDate(theField) {
	remote = window.open("/lib/calendarFrame.html", "CalendarWindow", "toolbar=no,scrollbars=no,resizable=yes,width=250,height=200");
	if (remote != null) {
		if (remote.opener == null) remote.opener = self;
		if (remote.dateField == null) remote.dateField = theField;
	}
}

// Substitute String
function getSubstituteString(theString, theChar, theSubstitute)
{
	theReplacement = "";
	for (i=0; i<theString.length; i++)
	{
		if (theString.charAt(i) == theChar) theReplacement = theReplacement += theSubstitute;
		else theReplacement = theReplacement += theString.charAt(i);
	}
	return theReplacement;
}

// Validate Date field
function isDate(theField, theFormat)
{
	var theDate;
	var theCentury = new Date("1/1/1900");
	theFormat = jsDateFormat;
	if (theField.value != "")
	{
		if (theField.value == ".")
		{
			theDate = new Date();
		}
		else if (theField.value == "?")
		{
			getDate(theField);
			theField.value = "";
			theField.focus();
			return false;
		}
		else if ((theField.value.length == 6) && (theField.value.indexOf("/") == -1) && (theField.value.indexOf("-") == -1))
		{
			theString = new String(theField.value);
			if (theFormat == "DD/MM/YYYY")
			{
				theDay = theString.substring(2, 4);
				theMonth = theString.substring(0, 2);
				theYear = new Number(theString.substring(4, 6));
			}
			else
			{
				theDay = theString.substring(0, 2);
				theMonth = theString.substring(2, 4);
				theYear = new Number(theString.substring(4, 6));
			}
			if (theYear <= 50) theYear += 2000;
			theDate = new Date(theDay + '/' + theMonth + '/' + theYear);
		}
		else if ( (theField.value == "2/29/00") || (theField.value == "02/29/00") || (theField.value == "022900") )
		{
			theDate = new Date("02/29/2000");
		}
		else if ( (theField.value == "29/2/00") || (theField.value == "29/02/00") || (theField.value == "290200") )
		{
			theDate = new Date("02/29/2000");
		}
		else
		{
			theString = getSubstituteString(theField.value, "-", "/")
			if (theFormat == "DD/MM/YYYY")
			{
				theDay = theString.substring(0, theString.indexOf("/"));
				theString = theString.substring(theString.indexOf("/") + 1, theString.length);
				theMonth = theString.substring(0, theString.indexOf("/"));
			}
			else
			{
				theMonth = theString.substring(0, theString.indexOf("/"));
				theString = theString.substring(theString.indexOf("/") + 1, theString.length);
				theDay = theString.substring(0, theString.indexOf("/"));
			}
			theYear = new Number(theString.substring(theString.indexOf("/") + 1, theString.length));
			if (theYear <= 50) theYear += 2000;
			theDate = new Date(theMonth + "/" + theDay + "/" + theYear);
		}

		if ( isNaN(theDate.getMonth()) || (theDate.getTime() < theCentury.getTime()) )
		{
			alert("This is an invalid date (" + theField.value + ").");
			theField.value = "";
			theField.focus();
			return false;
		}
		else
		{
			theField.value = getDateString(theDate, theFormat);
		}
	}
	return theField;
}

function isInteger(theField)
{
	var valid = false;

	var integer = /^([-]||[+]){0,1}([0-9])*$/;

	if(!integer.test(theField.value))
	{
		alert("'" + theField.value + "' is an incorrect Integer Format");

		theField.value = "";
		theField.focus();
	}
}

function isNumber(theField)
{
	var valid = false;

	var integer = /^([-]||[+]){0,1}([0-9])*([.]{0,1})([0-9])*$/;

	if(!integer.test(theField.value))
	{
		alert("'" + theField.value + "' is not a valid number");

		theField.value = "";
		theField.focus();
	}
}

function isDecimal(theField)
{
	var valid = false;

	var integer = /^([-]||[+]){0,1}([0-9])*$/;

	if(!integer.test(theField.value))
	{
		alert("'" + theField.value + "' is an incorrect Integer Format");

		theField.value = "";
		theField.focus();
	}
}
// DHTML Reordering routines
/**
* @todo hardcode - These routines need to be identified and moved out of this file
*/
//Set a global variable to hold the last rerdered element so the onmouseup can release it withou affecting other elements
var theLastReOrderAbleElm = null;
document.onmouseover = function (e) {
//function trMouseOver(e) {
	try
	{
		if (window.event)
			e = window.event;

		var srcEl = e.srcElement? e.srcElement : e.target;

		if(srcEl.parentNode)
		{
			var trValid = ((srcEl.parentNode.tagName == 'TR') && (srcEl.parentNode.className == 'reOrderAble')) ? true : false;

			if (trValid)
				window.self.moveTrTo = srcEl.parentNode.rowIndex;

			if(window.self.moving)
			{
				var agt=navigator.userAgent.toLowerCase();

		        var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

	            if(is_ie)
	            {
					theElement.parentNode.moveRow(theGotIndex,moveTrTo);
				}
				else
				{
					var oldHTML = srcEl.parentNode.parentNode.rows[theGotIndex].innerHTML;
					var newHTML = srcEl.parentNode.parentNode.rows[moveTrTo].innerHTML;

					srcEl.parentNode.parentNode.rows[theGotIndex].innerHTML = newHTML;
					srcEl.parentNode.parentNode.rows[moveTrTo].innerHTML = oldHTML;
				}
				window.self.theGotIndex = moveTrTo;
			}
		}
	}
	catch(E)
	{
	}
	return(false);
}



document.onmouseup = function (e) {
	try {
		if (window.event)
			e = window.event;

		var srcEl = e.srcElement? e.srcElement : e.target;
			//rowObj = srcEl.parentNode.childNodes;
			if(theLastReOrderAbleElm != null && theLastReOrderAbleElm != undefined && theLastReOrderAbleElm != "")
			{
				rowObj = theLastReOrderAbleElm;
					 if (rowObj)
						for (var i=0;i<rowObj.length;i++)
						  if (rowObj[i].style)
						    rowObj[i].style.backgroundColor = ''
				document.onselectstart = function () {return true}
				window.self.moving = false;
				window.self.theGotIndex = null;
			}
	} catch(E) {

	}
	return(true);
}



document.onmousedown = function (e) {
	try {

		if (window.event)
			e = window.event;

		var srcEl = e.srcElement? e.srcElement : e.target;

		var trValid = ((srcEl.parentNode.tagName == 'TR') && (srcEl.parentNode.className == 'reOrderAble'))? true : false;
		if (trValid) {
				window.self.moving = true;
				window.self.theGotIndex = srcEl.parentNode.rowIndex;
				window.self.theElement = srcEl.parentNode;
				document.onselectstart = function () {return false}
				rowObj = srcEl.parentNode.childNodes;
				if (rowObj)
				 for (var i=0;i<rowObj.length;i++)
				   if (rowObj[i].style)
				     rowObj[i].style.backgroundColor = '#99FF66'
				theLastReOrderAbleElm = rowObj;
		}
	} catch(E) {

	}
	return(true);
}

function setRowOrder(theForm, theIdentifier) {
	with (theForm) {
		for (i=0; i<elements.length; i++) {
			if (elements[i].name == theIdentifier) {
				elements[i].checked = true;
				eval(theIdentifier + "Order" + elements[i].value + ".value=" + (elements[i].parentNode.parentNode.rowIndex-1));
			}
		}
	}
}

function twin_onLoad(){
	if (document.forms.length > 0){
		for (frm = 0; frm < document.forms.length; frm++){
			var frmObj = document.forms[frm];
			if(frmObj.elements.length > 0){
				for (itm = 0; itm < frmObj.elements.length; itm++){
					var itmObj = frmObj.elements[itm];
					if(itmObj.twinObject != null){
						var twinObj = frmObj.elements[itmObj.twinObject];
						switch (itmObj.type){
							case "text":
								itmObj.value = twinObj.value;
							break;
							case "checkbox":
								if (itmObj.value == twinObj.value) itmObj.checked = true;
							break;
							case "radio":
								if (itmObj.value == twinObj.value) itmObj.checked = true;
							break;
							case "select-one":
								for (i = 0; i < itmObj.length; i++){
									if (itmObj[i].value == twinObj.value) itmObj.selectedIndex = i;
								}
							break;
							case "textarea":
								itmObj.value = twinObj.value;
							break;
						}
					}
				}
			}
		}
	}
}

function twin_onSave(){
	if (document.forms.length > 0){
		for (frm = 0; frm < document.forms.length; frm++){
			var frmObj = document.forms[frm];
			if(frmObj.elements.length > 0){
				for (itm = 0; itm < frmObj.elements.length; itm++){
					var itmObj = frmObj.elements[itm];
					if(itmObj.twinObject != null){
						var twinObj = frmObj.elements[itmObj.twinObject];
						switch (itmObj.type){
							case "text":
								twinObj.value = itmObj.value;
							break;
							case "checkbox":
								if (itmObj.checked) twinObj.value = itmObj.value
								else twinObj.value = null;
							break;
							case "radio":
								if (itmObj.checked) twinObj.value = itmObj.value;
							break;
							case "select-one":
								twinObj.value = itmObj.value;
							break;
							case "textarea":
								twinObj.value = itmObj.value;
							break;
						}
					}
				}
			}
		}
	}
}

// To enable textares tabbing, set the BODY tag's onMouseUp function to call tabClear();
//		set the textarea onFocus to "window.self.tabFocus=this;"
//		set the textarea onKeydown to "tabCapture(this);"

function tabClear()
{
	if (window.self.tabFocus) {
		window.self.tabFocus.onblur = null;
		window.self.tabFocus = null;
	}
}

function tabCapture (obj)
{
	if (!window.self.workingObj) window.self.workingObj  = new Object();
	if (!window.self.workingId) window.self.workingId  = new Object();
	if (!window.self.tabMode) window.self.tabMode = new Object();

	if (new String(tabMode[event.srcElement.id]) == 'undefined') tabMode[event.srcElement.id] = false;
	status = 'TabMode = ' + tabMode[event.srcElement.id]
	window.self.theRange = document.selection.createRange();
	window.self.workingObj[obj.id] = obj;
	window.self.workingId[obj.id] = obj.id;

	if (event.keyCode == 9 && tabMode[event.srcElement.id]) {
		workingObj[event.srcElement.id].onblur = function anonymous () {
			this.focus();
			theRange.select();
		}
		theRange.text = "\t";
	}
	if (! tabMode[event.srcElement.id]) {
		if (workingObj[event.srcElement.id]) workingObj[event.srcElement.id].onblur = null;
	}
	if (event.keyCode == 84 && event.ctrlKey) {
		tabMode[event.srcElement.id] = !tabMode[event.srcElement.id];
		status = 'TabMode = ' + tabMode[event.srcElement.id];
	}
}
var myRegxp = /[^\da-z]+/gi;
var reg = /'[^']*'/;
maskArray=new Array();
message="";
function doMask(textBox, mask)
{
   // grab the textBox value and the mask
   var val = textBox.value.toUpperCase();
   message="";
   var udTxt="";
   udTxt = reg.exec(mask);

   if(udTxt != null)
   {
	   mask = mask.replace(udTxt,'');
	   //strip off single quotes
	   udTxt = udTxt[0].replace(/'/g,"")

	   //if user changes input after literal has been added.
	   val = val.replace(udTxt,'');
   }
   else
   {
		udTxt = "";
   }
   // get value minus any masking by removing all non-numerics
   val = val.replace(myRegxp,'');
   stripmask = mask.replace(myRegxp,'');

	// mask it...val holds the existing TextBox.value + the current keystroke
	if(val.length > stripmask.length)
	{
		//strip off extra chars
		val=val.substring(0,stripmask.length);
	}
	textBox.value = val.maskValue(mask);
    textBox.value = udTxt + textBox.value;

	if(message!="")
	{
		alert(message);
	}
   return false;
}
 function intObject()
 {
      this.j;
      return this;
 }

String.prototype.maskValue = function(mask)
{
   var val = this;
   maskArray=new Array();

   if( maskArray.length==0 )
   {
     setMask(mask);
   }
	//loop every char in input
	var myIntObject = new intObject();
	myIntObject.j = 0;
	k=0;

   while(myIntObject.j<=mask.length)
   {
		if(val.charAt(k) != "")
		{
			check = doCheck(mask.charAt(myIntObject.j),val.charAt(k),mask,myIntObject);
		}
		myIntObject.j++;
   }
   //convert array to string
   retVal = maskArray.join("");
   return retVal;
}
function setMask(mask)
{
   for (i=0; i<mask.length; i++)
   {
      maskArray[i] = mask.charAt(i)
   }
}
function doCheck(c,val,mask,obj)
{
   if(c == "N")
   {
       if(IsNumeric(val))
       {
		  maskArray[obj.j]=val;
       }
	   else
	   {
			maskArray[obj.j]="N";
			message="Please replace any X(s) with a character and/or N(s) with a number.";
	   }
	   k++;
   }
   else if(c == "X")
   {
       if(!IsNumeric(val))
       {
          maskArray[obj.j]=val;
       }
	   else
	   {
			maskArray[obj.j]="X";
			message="Please replace any X(s) with a character and/or N(s) with a number.";
	   }
	   k++;
   }
   else
   {
	   obj.j++;
	   doCheck(mask.charAt(obj.j),val,mask,obj);
   }
}
function IsNumeric(strString)
{
	var strValidChars = "0123456789";
	var strChar;
	var blnResult = true;
	if (strString.length == 0) return false;
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
 }

// This function will make the first letter of each word
function Capitalize(theObject)
{
	var ValueString = theObject.value;
	ValueString = ValueString.replace(/ +/g,' ');
    var names = ValueString.split(' ');
    for(var i = 0; i < names.length; i++)
	{
		if(names[i].length > 1)
		{
			names[i] = names[i].toLowerCase();
			letters = names[i].split('');
			letters[0] = letters[0].toUpperCase();
			names[i] = letters.join('');
		}
		else
		{
			names[i] = names[i].toUpperCase();
		}
	}
	ValueString = names.join(' ');
	theObject.value = ValueString;
	return true;
}

function noCapitals(txtbox,showhint)
{
    var origValue = txtbox.value;
    var lowercaseValue = origValue.toLowerCase();
    if(origValue != lowercaseValue)
    {
        txtbox.value = lowercaseValue;
        if(showhint)showhint('NOTE: Username has been modified to ALL lower case characters', txtbox,null,'150px');
    }

}
function confirmAction(msg,url)
{

	var answer = confirm(msg);
	if (answer)
	{
		window.location = url;
		status=true;
	}
	else
	{
		status = false;
	}
	return(status);
}


function showCCDetails()
{
	if(document.getElementById("paypalMsg"))
	{document.getElementById("paypalMsg").innerHTML="";}


	obj = document.getElementsByTagName('TR');
     for (i=0; i<obj.length; i++)
     {
            if (obj[i].id == 'ccdetails')
            {
            	obj[i].style.display = 'block';
            }
          	if(obj[i].id == 'ppdetails')
          	{
          		obj[i].style.display = 'none';
          	}
     }
}
function hideCCDetails()
{

	 if(document.getElementById("paypalMsg"))
	{document.getElementById("paypalMsg").innerHTML="";}

	 obj = document.getElementsByTagName('TR');
     for (i=0; i<obj.length; i++)
     {
            if (obj[i].id == 'ccdetails')
            {
          		obj[i].style.display = 'none';
          	}
          	if(obj[i].id == 'ppdetails')
          	{
          		obj[i].style.display = 'block';
          	}
     }

}

function initAjaxObj(stateChangeFunction)
{
	var xmlHttp;
	// Initialise xmlHttp object:
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
  	{
    	// Internet Explorer
    	try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		try
      		{
      			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		}
    		catch (e)
      		{
      			//alert("Browser does not support AJAX");
      			return false;
      		}
      	}
    }
    xmlHttp.onreadystatechange = (stateChangeFunction) ? stateChangeFunction : function stateChanged(){};

    return xmlHttp;
}

function limitText(limitField, limitCount, limitNum)
{
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////START ELEMENT POSITION FUNCTIONS///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This function is used to find the window size current browser window   - called to parent in case of iFrame
window.size = function()
{
    var w = 0;
    var h = 0;

    //IE
    if(!window.innerWidth)
    {
        //strict mode
        if(!(document.documentElement.clientWidth == 0))
        {
            w = document.documentElement.clientWidth;
            h = document.documentElement.clientHeight;
        }
        //quirks mode
        else
        {
            w = document.body.clientWidth;
            h = document.body.clientHeight;
        }
    }
    //w3c
    else
    {
        w = window.innerWidth;
        h = window.innerHeight;
    }
    return {width:w,height:h};
}
//This function is used to find the window center - called to parent in case of iFrame
window.center = function()
{
    var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};

    var _x = 0;
    var _y = 0;
    var offsetX = 0;
    var offsetY = 0;

    //IE
    if(!window.pageYOffset)
    {
        //strict mode
        if(!(document.documentElement.scrollTop == 0))
        {
            offsetY = document.documentElement.scrollTop;
            offsetX = document.documentElement.scrollLeft;
        }
        //quirks mode
        else
        {
            offsetY = document.body.scrollTop;
            offsetX = document.body.scrollLeft;
        }
    }
    //w3c
    else
    {
        offsetX = window.pageXOffset;
        offsetY = window.pageYOffset;
    }

    _x = ((this.size().width-hWnd.width)/2)+offsetX;
    _y = ((this.size().height-hWnd.height)/2)+offsetY;

    return{x:_x,y:_y};
}
//Find the X location of an element
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1)
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
//Find the Y location of an element
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////END ELEMENT POSITION FUNCTIONS///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showDisclaimer(callingTagId)
{
	// show the popup

        var callingTag = document.getElementById(callingTagId);
        disclaimerdiv = document.getElementById("disclaimerpopup");
        if(callingTag != null || callingTag != "" || callingTag != undefined)
        {
            //Move to position of calling tag
            disclaimerdiv.style.display = "block";
            try
            {
                var relPosleft = findPosX(callingTag)- (disclaimerdiv.offsetWidth / 2);// + (callingTag.offsetWidth / 2) - (disclaimerdiv.offsetWidth / 2);
                var relPostop = findPosY(callingTag)- (disclaimerdiv.offsetHeight / 2);// + (callingTag.offsetHeight / 2) - (disclaimerdiv.offsetHeight / 2);
                disclaimerdiv.style.left =  relPosleft + "px";
                disclaimerdiv.style.top = relPostop + "px";
            }
            catch(err)
            {
                alert(err.description);
            }

        }
        else
        {
            // Center the ProgressBar in the window regardless of the scroll positions
            var locate = window.center({width:200,height:100})
            disclaimerdiv.style.left = locate.x + "px";
            disclaimerdiv.style.top = locate.y + "px";
            disclaimerdiv.style.display = "block";
        }

        /*
        //Old Method
		var browserWidth = document.body.clientWidth;
		var browserHeight = document.body.clientHeight;

		objLeft = 210;
		objTop = (document.body.scrollTop + (browserHeight / 2)) - 100;

		disclaimerdiv = document.getElementById("disclaimerpopup");
		disclaimerdiv.style.display = "inline";
		disclaimerdiv.style.top = objTop;
		disclaimerdiv.style.left = objLeft
        */
}
function openpreview(link)
{
	var load = window.open(link,'','scrollbars=yes,menubar=no,height=300,width=600,resizable=yes,toolbar=no,location=no,status=no');
}

function getCurrentZindex()
{
	var currentzindex = new Number(document.getElementById('currentzindex').value);
	document.getElementById('currentzindex').value = currentzindex+1;

	return currentzindex;
}

// Show and hide flyout areas
function showFlyOut(xPos, yPos, flyOutId)
{
	if (!flyOutId)
		flyOutId = 'flyOutDiv';
	var flyOut = document.getElementById(flyOutId);
	flyOut.style.display = "block";

	flyOut.style.left = (xPos ? xPos : 30);
	flyOut.style.top = (yPos ? yPos : 40);
	if (document.getElementById('currentzindex'))
		flyOut.style.zIndex = getCurrentZindex();
}
function hideFlyOut(flyOutId)
{
	if (!flyOutId)
		flyOutId = 'flyOutDiv';
	var flyOut = document.getElementById(flyOutId);
	if (flyOut)
		flyOut.style.display = "none";
}


function showFlyOutLoading(yPos, flyOutArea, loadingArea)
{
	if (flyOutArea == null)
		flyOutArea = 'flyOutDiv';
	if (loadingArea == null)
		loadingArea = 'loadingDiv';

	flyOutArea = document.getElementById(flyOutArea);
	loadingArea = document.getElementById(loadingArea);

	if (flyOutArea && loadingArea)
	{
		flyOutArea.style.display = 'block';
		flyOutArea.innerHTML = loadingArea.innerHTML;
		if (yPos)
			flyOutArea.style.top = yPos;
		else
			flyOutArea.style.top = 310 + document.body.scrollTop;

		flyOutArea.style.left = 350;
		if (document.getElementById('currentzindex'))
			flyOutArea.style.zIndex = getCurrentZindex();
	}
}

function showCourseDetails(course, hide, resultArea)
{
	var xmlHttp = initAjaxObj();
	var yPos = 0;
	if (window.event) // (ie only)
		yPos = window.event.clientY;
	yPos += document.body.scrollTop;
	if (yPos > 40)
		yPos -= 40;

	if (resultArea == null)
		resultArea = 'flyOutDiv';

	if (!document.getElementById(resultArea))
		return;

	if (xmlHttp)
  	{
		//Display 'Loading' div:
		showFlyOutLoading();

	    document.body.style.cursor = 'wait';
		xmlHttp.onreadystatechange = function()
	    {
	    	if(xmlHttp.readyState == 4)
	    	{
	    		hideFlyOut();
				document.body.style.cursor = 'auto';
				document.getElementById(resultArea).innerHTML = xmlHttp.responseText;
	    		showFlyOut(0, yPos, resultArea);
 	 	    }
	    }
	    // Assemble the url which will be called:
	    var url = '/clientadmin/coursedetails.php';
	    url = url + "?course=" + course;
	    url = url + "&div=" + resultArea;

	   	if (hide)
	   		url = url + "&hide=" + hide;
	    // Add random number to prevent server using cached page:
	  	url = url + "&sid=" + Math.random();

	  	// Send the request:
	  	xmlHttp.open("GET", url, true);
	  	xmlHttp.send(null);
  	}
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////

//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id, useDocZindex) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.
  if (useDocZindex && document.getElementById('currentzindex'))
  	  dragObj.elNode.style.zIndex = getCurrentZindex();
  else
	  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////

function toggleSub(submenu, scrollLocation) {
	toggleItems = document.getElementsByName(submenu);
	if (toggleItems.length > 0)
	{
	    if (toggleItems[0].style.display == 'none')
	    {
			//Show:
			for (i=0; i<toggleItems.length; i++)
			{
				if (scrollLocation)
				{
					// Show at position relative to where the browser is currently scrolled (scrollLocation):
					toggleItems[i].style.position = 'absolute';
					toggleItems[i].style.top = scrollLocation;
				}
				toggleItems[i].style.display = '';
			}
	    }
	    else
	    {
			// Hide:
	        for (i=0; i<toggleItems.length; i++)
				toggleItems[i].style.display = 'none';
		}
	}
}



/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
// this part of javascript is used to show hint box,
// for using this code you need too other pieces
// 1. the following javascript which is specific to page so, copy and paste the below script in your page
/*var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="14" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox
*/
//2.#hintbox,.hintanchor classes which are defined in hTheme/XXX/styles.css file
function getposOffset(what, offsettype)
{
    var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
    var parentEl=what.offsetParent;
    while (parentEl!=null){
    totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
    parentEl=parentEl.offsetParent;
    }
    return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
 if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

function process_predecessor1()
{
    var elements = document.getElementsByName("sequence[]");
}

//////////////////////////////////////////////////////////////////////////////
// GKELLEY_: COPIED OVER FROM LIB/JAVASCRIPT-STATIC.JS //////////////////////
////////////////////////////////////////////////////////////////////////////
function submitFormById(id) {
    var theform = document.getElementById(id);
    if(!theform) {
        return false;
    }
    if(theform.tagName != 'FORM') {
        return false;
    }
    if(!theform.onsubmit || theform.onsubmit()) {
        return theform.submit();
    }
}

function select_all_in(elTagName, elId, elClass) {
try{
    var inputs = document.getElementsByTagName('INPUT');
    inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elId, elClass);});
    for(var i = 0; i < inputs.length; ++i) {
        if(inputs[i].type == 'checkbox') {
            inputs[i].checked = 'checked';
        }
    }
   }catch(err)
   {
       alert(err.description);
   }
}

function deselect_all_in(elTagName, elId, elClass) {
    var inputs = document.getElementsByTagName('INPUT');
    inputs = filterByParent(inputs, function(el) {return findParentNode(el, elTagName, elId, elClass);});
    for(var i = 0; i < inputs.length; ++i) {
        if(inputs[i].type == 'checkbox') {
            inputs[i].checked = '';
        }
    }
}

function filterByParent(elCollection, parentFinder) {
    var filteredCollection = [];
    for(var i = 0; i < elCollection.length; ++i) {
        var findParent = parentFinder(elCollection[i]);
        if(findParent.nodeName != 'BODY') {
            filteredCollection.push(elCollection[i]);
        }
    }
    return filteredCollection;
}

function findParentNode(el, elName, elClass, elId) {
    while(el.nodeName != 'BODY') {
        if(
            (!elName || el.nodeName == elName) &&
            (!elClass || el.className.indexOf(elClass) != -1) &&
            (!elId || el.id == elId))
        {
            break;
        }
        el = el.parentNode;
    }
    return el;
}
