var DisplayMessage;

function scriptStart()
{
	if(DisplayMessage)
		alert(DisplayMessage);
		
	try {
		document.password.PasswordField.focus();
	} catch(err) {
	}
	
	try {
		document.editFile.S1.focus();
	} catch(err) {
	}

	try {
		document.alumnipassword.AlumniPasswordField.focus();
	} catch(err) {
	}

	if(document.getElementById("fillMe"))
		fillMe();

	if(document.getElementById("bottomPictures"))
		bp_DisplayPics();
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// This section is used to open windows.

function openWindow(pageURL)
{
	window.open(pageURL);
}

function openWindowAdmin()
{
	window.open("Admin.asp", "_blank", "location=no,menubar=no,toolbar=no,width=1010,height=735,resizable=yes,scrollbars=yes,status=yes");
	// document.location.href = "Admin.asp";
}

function openWindowAdminInstructions()
{
	window.open("AdminInstructions.asp", "_blank", "location=no,menubar=no,toolbar=no,width=700,height=600,resizable=yes,scrollbars=yes,status=yes");
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function fillMe()
{
	var h = document.body.clientHeight - 433;
	
	if(h > document.getElementById("fillMe").offsetHeight)
		document.getElementById("fillMe").height = h;
	
	setTimeout("fillMe2()", 25);
}

function fillMe2()
{
	var i;
	var r;
	var fillInDiv;
	var stagingDiv;
	var availableHeight;
	var totalBoxCount = 0;
	var purpleBoxCount = 0;
	var orangeBoxCount = 0;
	var pictureBoxCount = 0;
	var minDiff =99999999;
	var selectedHTML = "";

	stagingDiv = document.getElementById("fillMeStage");
	fillInDiv = document.getElementById("fillMe");
	
	availableHeight = fillInDiv.offsetHeight;
	
	if(document.getElementById("ContentDivHomePage")) {

		stagingDiv.innerHTML = fillInDiv.innerHTML + ajax("NewsApp.asp", "<body>", "</body>");
		fillInDiv.innerHTML = fillInDiv.innerHTML + stagingDiv.innerHTML;
		availableHeight -= stagingDiv.offsetHeight;
		stagingDiv.innerHTML = "";
		
		return;
		
		for(i = 0; i < 7; i++) {
			
			stagingDiv.innerHTML = ajax("PicturesApp.asp?color=orange", "<body>", "</body>");

			if(Math.abs(stagingDiv.offsetHeight - availableHeight) < minDiff) {
				minDiff = Math.abs(stagingDiv.offsetHeight - availableHeight);
				selectedHTML = stagingDiv.innerHTML;
			}
			
			stagingDiv.innerHTML = "";
			
			if(minDiff <= 20)
				break;
		}
		
		if(selectedHTML != "")
			fillInDiv.innerHTML = fillInDiv.innerHTML + selectedHTML;

		return;
	}

	for(i = 0; i < 10; i++) {
	
		if(availableHeight < 50)
			break;

		if(totalBoxCount >= 3)
			break;

		if(String(document.location).toUpperCase().indexOf("VIEWPROJECT.ASP?PROJECTID=") > -1)
			r = 2;	// This is for project pages only - always display orange boxes.
		else
			r = Math.floor(Math.random() * 10);
			
		switch(r) {

			case 0:
			case 1:		
				purpleBoxCount++;
				if(purpleBoxCount <= 2)
					stagingDiv.innerHTML = ajax("QuotesApp.asp", "<body>", "</body>");
				else
					continue;
				break;

			case 2:
			case 3:
			case 4:
				orangeBoxCount++;
				if(orangeBoxCount <= 2)
					stagingDiv.innerHTML = ajax("FactsFiguresApp.asp", "<body>", "</body>");
				else
					continue;
				break;

			case 5:
			case 6:
			case 7:
			case 8:
			case 9:
				pictureBoxCount++;
				if(pictureBoxCount <= 2)
					stagingDiv.innerHTML = ajax("PicturesApp.asp", "<body>", "</body>");
				else
					continue;
				break;
		}
		
		if(stagingDiv.innerHTML.indexOf("ERROR: NOTHING FOUND!") != -1)
			continue;

		if(fillInDiv.innerHTML.indexOf(stagingDiv.innerHTML) == -1) {
			if(stagingDiv.offsetHeight <= availableHeight) {
				totalBoxCount++;
				fillInDiv.innerHTML = fillInDiv.innerHTML + stagingDiv.innerHTML;
				availableHeight -= stagingDiv.offsetHeight;
			}
		}

		stagingDiv.innerHTML = "";
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// This section is used to rotate the seven pictures at the bottom of the page. 
// Note: The array bp_PicList[] is created by the VB code.

var bp_Ptrs = new Array(7);
var bp_CurrentPics = new Array(7);
var bp_SelectedPic;
var bp_LastSelectedPic;
var bp_NewPic;
var bp_Opacity;
var bp_OpacityInc;

var bp_RorationTimeout = 2000;
var bp_FadeTimeout = 30;

function bp_DisplayPics()
{
	var f, i, j, x;
	
	if(bp_PicList.length < 7)
		return;

	bp_Ptrs[0] = document.getElementById("bottomPicture0");
	bp_Ptrs[1] = document.getElementById("bottomPicture1");
	bp_Ptrs[2] = document.getElementById("bottomPicture2");
	bp_Ptrs[3] = document.getElementById("bottomPicture3");
	bp_Ptrs[4] = document.getElementById("bottomPicture4");
	bp_Ptrs[5] = document.getElementById("bottomPicture5");
	bp_Ptrs[6] = document.getElementById("bottomPicture6");
	
	for(i = 0; i < 7; i++) {
		do {
			x = Math.floor(Math.random() * bp_PicList.length);
			f = false;
			for(j = 0; j < 7; j++)
				if(bp_CurrentPics[j] == x)
					f = true;
		} while(f)
		bp_CurrentPics[i] = x;
		bp_Ptrs[i].src = bp_PicList[bp_CurrentPics[i]];
	}

	if(bp_PicList.length < 10)
		return;

	// Preload all pictures.
	for(i = 0; i < bp_PicList.length; i++) {
		var pic = new Image();
		pic.src = bp_PicList[i];
	}

	setTimeout("bp_RotatePic()", bp_RorationTimeout);
}

function bp_RotatePic()
{
	var f, i;
	
	do
		bp_SelectedPic = Math.floor(Math.random() * 7);
	while(bp_SelectedPic == bp_LastSelectedPic)
	
	do {
		bp_NewPic = Math.floor(Math.random() * bp_PicList.length);
		f = false;
		for(i = 0; i < 7; i++)
			if(bp_CurrentPics[i] == bp_NewPic)
				f = true;
	} while(f)
	
	bp_Opacity = 90;
	bp_OpacityInc = -10;
	
	if(navigator.appName == "Microsoft Internet Explorer") {
		
	bp_Ptrs[bp_SelectedPic].style.filter = "progid:DXImageTransform.Microsoft.Fade(Duration=0.7,Overlap=0.1)";
	
	bp_Ptrs[bp_SelectedPic].filters(0).apply();

	bp_CurrentPics[bp_SelectedPic] = bp_NewPic;
	bp_Ptrs[bp_SelectedPic].src = bp_PicList[bp_CurrentPics[bp_SelectedPic]];
	bp_LastSelectedPic = bp_SelectedPic;
	
	bp_Ptrs[bp_SelectedPic].filters(0).play();

	setTimeout("bp_RotatePic()", bp_RorationTimeout);
		
	} else {
		
		bp_PicFade();
	}
}

function bp_PicFade()
{
	// IE/Win
	bp_Ptrs[bp_SelectedPic].style.filter = "alpha(opacity:" + bp_Opacity + ")";
	
	// Safari < 1.2, Konqueror
	bp_Ptrs[bp_SelectedPic].style.KHTMLOpacity = bp_Opacity / 100;
	
	// Older Mozilla and Firefox
	bp_Ptrs[bp_SelectedPic].style.MozOpacity = bp_Opacity / 100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	bp_Ptrs[bp_SelectedPic].style.opacity = bp_Opacity / 100;

	switch(bp_Opacity) {

		case 0:
		
			bp_CurrentPics[bp_SelectedPic] = bp_NewPic;
			bp_Ptrs[bp_SelectedPic].src = bp_PicList[bp_CurrentPics[bp_SelectedPic]];
			
			bp_OpacityInc = +10;
			
			bp_Opacity += bp_OpacityInc;
			
			break;
			
		case 100:
		
			bp_LastSelectedPic = bp_SelectedPic;
	
			setTimeout("bp_RotatePic()", bp_RorationTimeout);
			
			return;
			
		default:
		
			bp_Opacity += bp_OpacityInc;
			
			break;
	}
	
	setTimeout("bp_PicFade()", bp_FadeTimeout);
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function trimString(x)
{
	while(x.slice(0, 1) == " " || x.slice(0, 1) == String.fromCharCode(13) || x.slice(0, 1) == String.fromCharCode(10))
		x = x.slice(1, x.length)

	while(x.slice(x.length - 1, x.length) == " " || x.slice(x.length - 1, x.length) == String.fromCharCode(13) || x.slice(x.length - 1, x.length) == String.fromCharCode(10))
		x = x.slice(0, x.length - 1)

	return x
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// This function is used by CalendarApp.asp.

function calendarClick(calendarURL)
{
	var html = ajax(calendarURL, "<custom_calendar_tag>", "</custom_calendar_tag>");
	
	if(html)
		document.getElementById("calendarDiv").innerHTML = html;
		
	if(calendarURL.indexOf("Day=") != -1) {

		if(document.getElementById("calendarDivBottom")) {
			var destinationLink = document.getElementById("calendarDivBottom");
			var desty = destinationLink.offsetTop;
			var thisNode = destinationLink;
			while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) {
				thisNode = thisNode.offsetParent;
				desty += thisNode.offsetTop;
			}
			desty += 5;
			window.scrollTo(0, desty)
		}

	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// This function is used to retrive the html of a page using the Ajax technology.
// It will return the html inside the body tag.
// Additionally, if the startTag and endTag are specified, will return the html inside those tags.
// The pageURL argument is mandatory. The startTag and endTag are optional - use them if needed, otherwise don't supply them.

function ajax(pageURL, startTag, endTag)
{
	var now = new Date;
	var randomNumber;
	var cacheOverride;
	var html = null;
	var xmlHttp = null;
	var p;

	randomNumber = escape(now.toUTCString() + " " + now.getUTCMilliseconds() + " " + Math.floor(Math.random()*100000));

	if(pageURL.indexOf("?") == -1)
		cacheOverride = "?CacheOverride=" + randomNumber;
	else
		cacheOverride = "&CacheOverride=" + randomNumber;

	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try {
			xmlHttp=new ActiveXObject("Msxml2.xmlHttp");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.xmlHttp");
		}
	}

	xmlHttp.open("get", pageURL + cacheOverride, false);
	xmlHttp.send(null);
	
	if(xmlHttp.readyState == 4) {
		try {
			if(xmlHttp.status == 200) {
				html = xmlHttp.responseText;
			}
		} catch (e) {
			html = null;
		}
	} else {
		html = null;
	}
	
	if(html == "")
		html = null;
		
	if(!html)
		return null;

	if((p = html.toUpperCase().indexOf("<BODY")) > -1)
		if((p = html.indexOf(">")) > -1)
			html = html.slice(p + 1);
	
	if((p = html.toUpperCase().indexOf("</BODY>")) > -1)
		html = html.slice(0, p);

	if(startTag)
		if((p = html.toUpperCase().indexOf(startTag.toUpperCase())) > -1)
			html = html.slice(p + startTag.length);

	if(endTag)
		if((p = html.toUpperCase().indexOf(endTag.toUpperCase())) > -1)
			html = html.slice(0, p);

	return html;
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
