
// Rollover Code ==============================================================
var arrRollovers = new Array();
var arrRollouts = new Array();
var gstrInvalidChars = "<>#%&*;,.:()[]{}|'\"";
var gstrInvalidUserNameChars = "<>#%&*;:()[]{}|\"";

function	registerPageImages () {
	
	var oImage1, oImage2;
	var strImageID = "";
	var strImageSRC = "";
	
	if (!document.images) return;
	
	
	for (var i=0; i < document.images.length; i++)
	{
		strImageID = "";
		
		if (document.images[i] != null) {
			
			if (document.images[i].id != null)
				if (document.images[i].id != "")
					strImageID = "" + document.images[i].id;
		
			if (strImageID.length == 0)
				if (document.images[i].name != null)
					if (document.images[i].name != "")
						strImageID = "" + document.images[i].name;
		
		
			strImageSRC = "" + document.images[i].src;
		
			if (strImageID != "" && (strImageSRC.indexOf(".gif") > -1 || 
					strImageSRC.indexOf(".jpg") > -1))
				registerRollover( strImageID, strImageSRC );
		}//end if
	}//end for
	
}//end registerPageImages

function	registerRollover(inImageID, inImageSrc)
{
	var strImageRollover = "" + inImageSrc;
	var oImage1 = new Image();
	var oImage2 = new Image();
	
	// If it's already on, we're not rolling over.
	if (strImageRollover.indexOf("_on.") > -1)
		return;
		
	
	if (strImageRollover.lastIndexOf(".") > -1)
		strImageRollover = strImageRollover.substring(0, strImageRollover.lastIndexOf(".")) + "_on" + strImageRollover.substring(strImageRollover.lastIndexOf("."));
	
	oImage1.src = strImageRollover;
	oImage2.src = inImageSrc;
	
	
	arrRollovers[inImageID] = oImage1;
	arrRollouts[inImageID] = oImage2;
	
}//end registerRollover

function	rollover(inImageID)
{	
	if (arrRollovers[inImageID] != null)
	{
		if (document.images[inImageID] != null)
			document.images[inImageID].src = arrRollovers[inImageID].src;
			
	}//end if
	
}//end rollover

function	rollout(inImageID)
{
	if (arrRollouts[inImageID] != null)
	{
		if (document.images[inImageID] != null)
			document.images[inImageID].src = arrRollouts[inImageID].src;
	
	}//end if
	
}//end rollout

function	rolloverButton(inObject) {

	var oCell = null;
	var oRow = null;
	
	if (inObject) {
		for (var k=0; k < inObject.rows.length; k++) {
			oRow = inObject.rows[k];
			if (oRow) {
				for (var i=0; i < oRow.cells.length; i++) {
					oCell = oRow.cells[i];
					if (oCell) {
						if (oCell.className == "StandardButton") {
							oCell.className = "StandardButtonOver";
							for(var j=0; j < oCell.children.length; j++) {
								if (oCell.children[j].id && oCell.children[j].id != "") 
									rollover(oCell.children[j].id);
								oCell.children[j].className = "StandardButtonOver";
							}//end for
						}//end if
					}//end if
				}//end for
			}//end if
		}//end for
	}//end if
}//end rolloverButton

function	rolloutButton(inObject) {

	var oCell = null;
	var oRow = null;
	
	if (inObject) {
		for (var k=0; k < inObject.rows.length; k++) {
			oRow = inObject.rows[k];
			if (oRow) {
				for (var i=0; i < oRow.cells.length; i++) {
					oCell = oRow.cells[i];
					if (oCell) {
						if (oCell.className == "StandardButtonOver") {
							oCell.className = "StandardButton";
							for(var j=0; j < oCell.children.length; j++) {
								if (oCell.children[j].id && oCell.children[j].id != "")
									rollout(oCell.children[j].id);
								oCell.children[j].className = "StandardButton";
							}//end for
						}//end if
					}//end if
				}//end for
			}//end if
		}//end for
	}//end if
}//end rolloutButton

function	rolloverMenu(inObject) {

	var oCell = null;
	var oRow = null;
	var strClassName = "";
	
	if (inObject) {
		for (var k=0; k < inObject.rows.length; k++) {
			oRow = inObject.rows[k];
			if (oRow) {
				for (var i=0; i < oRow.cells.length; i++) {
					oCell = oRow.cells[i];
					if (oCell && oCell.className && oCell.className != "") {
						strClassName = "" + oCell.className;
						if (strClassName.substring(strClassName.length-2) != "On") {
							if (strClassName.substring(strClassName.length-3) == "Off")
								return;
							else
								strClassName = strClassName + "On";
						}//end if
						oCell.className = strClassName;
						
						for(var j=0; j < oCell.children.length; j++) {
							if (oCell.children[j].id && oCell.children[j].id != "") 
								rollover(oCell.children[j].id);
							oCell.children[j].className = strClassName;
						}//end for
					}//end if
				}//end for
			}//end if
		}//end for
	}//end if
}//end rolloverMenu

function	rolloutMenu(inObject) {

	var oCell = null;
	var oRow = null;
	
	if (inObject) {
		for (var k=0; k < inObject.rows.length; k++) {
			oRow = inObject.rows[k];
			if (oRow) {
				for (var i=0; i < oRow.cells.length; i++) {
					oCell = oRow.cells[i];
					if (oCell && oCell.className && oCell.className != "") {
						strClassName = "" + oCell.className;
						
						if (strClassName.substring(strClassName.length-3) != "Off" && 
							 strClassName.substring(strClassName.length-2) == "On") 
							strClassName = strClassName.substring(0, strClassName.length-2);
							
						oCell.className = strClassName;
						
						for(var j=0; j < oCell.children.length; j++) {
							if (oCell.children[j].id && oCell.children[j].id != "") 
								rollover(oCell.children[j].id);
							oCell.children[j].className = strClassName;
						}//end for
					}//end if
				}//end for
			}//end if
		}//end for
	}//end if
}//end rolloutMenu

// END Rollover Code ===================================================================


// Open Win Code =======================================================================

function	openWin(inURL, inName, inFeatures, inWidth, inHeight)
{
	var strURL = "";
	var strFeatures = "";
	var intWidth = 0;
	var intHeight = 0;
	var intLeft = 0;
	var intTop = 0;
	var strName = "";
	
	if (inURL == null)
		return;
	
	strURL = "" + inURL;
	if (inName != null)
		strName = "" + inName;
	
	if (inFeatures != null)
		strFeatures = "" + inFeatures;
	
	if (inWidth != null)
		if (!isNaN(parseInt(inWidth, 10)))
			intWidth = parseInt(inWidth, 10);
	
	if (inHeight != null)
		if (!isNaN(parseInt(inHeight, 10)))
			intHeight = parseInt(inHeight, 10);
	
	if (intWidth == 0)
		intWidth = 500;		// Default
		
	if (intHeight == 0)
		intHeight = 400;	// Default
	
	strFeatures = strFeatures.toLowerCase();
	
	if (strFeatures.indexOf("scrollbars") == -1)
	{
		if (strFeatures.length > 0)
			strFeatures = strFeatures + ",";
		strFeatures = strFeatures + "scrollbars=1";
	}//end if
	if (strFeatures.indexOf("resizable") == -1)
	{
		if (strFeatures.length > 0)
			strFeatures = strFeatures + ",";
		strFeatures = strFeatures + "resizable=1";
	}//end if
	
	if (window.screen != null)
	{
		intLeft = (window.screen.width / 2) - (intWidth / 2);
		intTop = (window.screen.height / 2) - (intHeight / 2);
	
	}//end if
	
	strFeatures = "width=" + intWidth + ",height=" + intHeight + "," + strFeatures;
	strFeatures = strFeatures + ",left=" + intLeft + ",top=" + intTop;
	
	return window.open(strURL, strName, strFeatures);
	
}//end openWin


function	openHelp(inCode)
{
	openWin("/asp/help/help.asp?topic=" + inCode, "PACEHelp", "", 740, 450);
}//end openHelp

function	openHelpWithLink(inCode, inLink)
{
	openWin("/asp/help/help.asp?topic=" + inCode + "&qLink=" + inLink, "PACEHelp", "", 740, 450);
	
}//end openHelp

// END Open Win Code ===============================================================================


// Other Code ====================================================================================

function	submitForm(inValidation)
{
	var bSuccess = true;
	
	eval( "bSuccess = " + inValidation + ";");
	
	if (bSuccess)
		document.forms[0].submit();
	
}//end submitForm

//Function used to make sure ALL values are 0...9
function isDigits(str, num) {
	var i
	if (num == 0)
		num = str.length
	for (i = 0; i < num; i++) {
		mychar = str.charAt(i)
		if (mychar < "0" || mychar > "9")
			return false
	}
	return true
}


function	doResizeToMax(inMinW, inMinH)
{
	var intTop = 0;
	var intLeft = 0;
	var intWidth = inMinW;
	var intHeight = inMinH;
	
	if (screen != null)
	{
		intLeft = (screen.width / 2) - (inMinW / 2);
		if (document.layers)
			intHeight = screen.availHeight - 100;
		else
			intHeight = screen.availHeight;
		intTop = 0;
		window.moveTo(intLeft, intTop);
	}//end if
	
	window.resizeTo( intWidth, intHeight );
	
}//end  doResizeToMax

function	doCaseStudy(inStudyCode)
{
	
	openWin("/casestudies/casestudies.asp?qCS=" + inStudyCode, "", "", 600, 400); 

}//end doCaseStudy

function	openPrivacy()
{
	openWin("http://www.blackboard.com/Alert-Notification/Legal/Privacy-Policy.aspx", "BlackboardPrivacy", "", 800, 600); 

}//end openPrivacy

function	openTOS()
{
	openWin("http://www.blackboard.com/Alert-Notification/Legal/Terms-of-Use.aspx", "BlackboardTOS", "", 600, 400); 

}//end openTOS

function	openTOSAnchor(inAnchor)
{
	openWin("/about/termsofuse.asp?#" + inAnchor, "NTITOS", "", 600, 400); 

}//end openTOSAnchor

function	openNewsItem(intNewsID)
{
	openWin("/about/newscontent.asp?newsID=" + intNewsID, "NTI News", "", 600, 400); 

}//end openNewsItem

function	showNotice( inNotice, inWidth, inHeight )
{
	
	if (inNotice != "")
		openWin(inNotice, "", "status=0,scrollbars=0,resizable=no", inWidth, inHeight);
	
}//end showNotice

function validateEmail(emailStr) {

	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    emailStr = emailStr.ToLowerCase();
    
	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
	
	//alert("Email address seems incorrect (check @ and .'s)");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];


	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			//alert("Ths username contains invalid characters.");
			return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
			//alert("Ths domain name contains invalid characters.");
			return false;
			}
	}

	if (user.match(userPat)==null) {
		//alert("The username doesn't seem to be valid.");
		return false;
		}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		
		for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
			//alert("Destination IP address is invalid!");
			return false;
			}
		}
		return true;
	}


	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
		//alert("The domain name does not seem to be valid.");
		return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
		}

	if (len<2) {
		//alert("This address is missing a hostname!");
		return false;
		}

	return true;
}//end ValidateEmail

function validatePhone(inPhoneNumber)
{
	var strPhoneWork, strPhoneAreaCode, strPhonePrefix, strPhoneNumber;
	var searchPattern = new RegExp("[0-9]{10}");
	
	
	strPhoneWork = "" + inPhoneNumber;
	
	// Normal, 10-digit phone required.
	// Note: This will need to change for international number support!! ****
//	if (strPhoneWork.length != 10)
//		return false;
	
	if (strPhoneWork.match(searchPattern) == null)
		return false;
		
	strPhoneAreaCode = strPhoneWork.substring(0, 3);
	strPhonePrefix = strPhoneWork.substring(4, 3);
	strPhoneNumber = strPhoneWork.substring(7);
	
	// Make sure the area code and prefix look normal.
	if (strPhoneAreaCode.substring(0,1) == "0" || strPhoneAreaCode.substring(0,1) == "1")
		return false;
		
	if (strPhonePrefix.substring(0,1) == "0" || strPhonePrefix.substring(0,1) == "1")
		return false;
	
	if (strPhoneAreaCode == "976" || strPhoneAreaCode == "967" || strPhoneAreaCode == "881" || 
		strPhoneAreaCode == "880" || strPhoneAreaCode == "882" || strPhoneAreaCode == "710" || 
		strPhoneAreaCode == "700" || strPhoneAreaCode == "809" || strPhoneAreaCode == "456" || 
		strPhoneAreaCode == "900")
		return false;
	
	if (strPhonePrefix == "555")
		return false;
	
	return true;
	
}//end validatePhone

function checkInvalidChars(inField)
{
	var invalidChars = gstrInvalidChars;
		
	for (var j = 0; j < inField.length; j++)
	{
		for (var i = 0; i < invalidChars.length; i++) 
		{
			if(inField.charAt(j) == invalidChars.charAt(i))
			{
				return false;
			}
		}
	}	
	
	return true;
}// end checkInvalidChars

// Just filter out <> plus their HTML equivalents
// to weed out possible script and other tags
function stripScriptChars(inField)
{
	var x1 = inField;
	var rgx = /<|>|&gt\;|&lt\;/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '');
	}
	return x1;
}

function checkInvalidUserNameChars(inField)
{
	var invalidChars = gstrInvalidUserNameChars;
		
	for (var j = 0; j < inField.length; j++)
	{
		for (var i = 0; i < invalidChars.length; i++) 
		{
			if(inField.charAt(j) == invalidUserNameChars.charAt(i))
			{
				return false;
			}
		}
	}	
	
	return true;
}// end checkInvalidUserNameChars



//cookie functions
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//end cookie functions

// End Other Code ================================================================================


