var popup=null;
var pop2 = null;

function openURL(page, w, h) {		// Opens a resizable pop-up window

	if(popup) {
		popup.close();
	}
		popup = window.open(page, 'popup', 'height=' +h+ ',width=' +w+ ',scrollbars=yes,resizable=yes');
}



function preloadGIF() {					// Load button highlights into the browser's memory cache

	var d = document;

	if (d.images){ 
		if(!d.allImages) d.allImages=new Array();
		var i,j=d.allImages.length, imgList=preloadGIF.arguments;

		for(i=0; i<imgList.length; i++)
			if (imgList[i].indexOf("#")!=0){ 
					d.allImages[j]=new Image; 
					d.allImages[j++].src='images/' + imgList[i] + '.gif';
			}
		}
}


function getObjectByID(name) {				// Get an object's ID tag for easy referencing

	if (document.getElementById) {				// Firefox and Safari
		return document.getElementById(name);
	} else if (document.all) {				// IE
		return document.all[name]; 
	} else if (document.layers) {
		return document.layers[name];
	} else {
		return document.getElementById(name);		// Default for unknown browsers
	}
}


function setValue() {				// Sets the value property of a specified field or control

	var lastObj = (setValue.arguments.length);
	for(n=0; n<lastObj; n++) {
		thisID = setValue.arguments[n]
		thisObj = getObjectByID(thisID);
		thisVal = setValue.arguments[++n];

		thisObj.value = thisVal;
	}
}


function getValue(id) {			// Returns the value property of the specified object

	var obj = getObjectByID(id);
	return obj.value;
}


function embedFlash(thisFile, w, h) {	// Shows the activeX control without an annoying 'activate' prompt
	var embedCode = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " 
		+ "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + w + "' height='" + h + "'> " 
		+ "<param name='allowScriptAccess' value='sameDomain' /> "
		+ "<param name='movie' value='" + thisFile + "' /> " 
		+ "<param name='quality' value='high' /> " 
		+ "<param name='wmode' value='transparent' /> " 
		+ "<embed src='" + thisFile + "' width='" + w + "' height='" + h + "' quality='high' " 
		+ "pluginspage='http://www.macromedia.com/go/getflashplayer' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' wmode='transparent'> " 
		+ "</embed></object>";

	document.write(embedCode);
}

function embedFLV(w, h, vars) {	// Wraps .FLV files in mediaplayer.swf

	var embedCode = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' " 
		+ "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='" + w + "' height='" + h + "'> " 
		+ "<param name='allowScriptAccess' value='sameDomain' /> "
		+ "<param name='movie' value='flash/mediaplayer.swf' /> " 
		+ "<param name='quality' value='high' /> " 
		+ "<param name='wmode' value='transparent' /> " 
		+ "<param name='allowfullscreen' value='true' /> " 
		+ "<param name='flashvars' value='" + vars + "' /> " 
		+ "<embed src='flash/mediaplayer.swf' width='" + w + "' height='" + h + "' quality='high' allowfullscreen='true' flashvars='" + vars + "' " 
		+ "pluginspage='http://www.macromedia.com/go/getflashplayer' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' wmode='transparent'> " 
		+ "</embed></object>";

	document.write(embedCode);
}



function emCode(prefix, suffix, text, loc, offset, mode) {	// E-mail obfuscator

								//	offset specifies how many garbage chars precede both prefix & text

								// 	mode 'a': pairs mailto href with text
								//		Example: emCode('zdn', 'p', 'zDavid Pedergnana', '', 1, 'a');

								//	mode 'n': shows e-mail only (as text)
								//		Example: emCode('zdn', 'p', '', '', 1, 'n');

								//	mode 'm': shows e-mail address as clickable mailto text
								//		Example: emCode('zdn', 'p', '', '', 1, 'm');
	var xString = prefix + suffix;
	var h = '<a href=\"mai';
	var nom = xString.substr(offset);
	h += 'lto:';
	text = text.substr(offset);
	var end = '\">';
	text += "<" + String.fromCharCode(47);
	var z = '@';

	if (!loc) {
		var n = 101;
		loc = 'ksu.' + String.fromCharCode(n) + 'du';
	}

	if (mode == 'n') {
		document.write(nom + z + loc);
	} else if (mode == 'm') {
		document.write(h + nom + z + loc + end);
		document.write(nom + z + loc + 'a>');
	} else {
		document.write(h + nom + z + loc + end);
		document.write(text + 'a>');
	}
}


function toggleBtn(whichBtn, state) {					// State = '_h' (highlighted) or ''

	var currentPage = getValue('currentPage');

	if (currentPage !== whichBtn) {					// Ignore requests if hovering over current page button

		var btnObj = getObjectByID(whichBtn + 'Bt');
		var btnSrc = btnObj.src;

		var newState = 'images/' + whichBtn + 'Bt' + state + '.gif';
		btnObj.src = newState;						// Change the button state
	}
}

function parseURL(param) {	// Reads a frame's URL and splits it into its components
				// 	returns the requested parameter
	var result = null;

	var parameterList = location.href.split("?");		// GET Parameters

	if (parameterList.length > 1) {			// No parameters; set defaults for home page:

				// Split list into name.value pairs

		var parameterPairs = parameterList[1].split("&");
		var nameAndValue = new Array();
		var paramValue;
		var paramKey;

		for (p=0; p < parameterPairs.length; p++) {	// Cycle through name/value pairs & store values

			nameAndValue = parameterPairs[p].split("=");
			paramKey = nameAndValue[0];
			paramValue = nameAndValue[1];

			if (paramKey == param) {		// Is this the target key?
				result = paramValue;
				break;
			}
		}
	}
	return result;
}


function getScreenSpecs(defaultW, defaultH) {		// Accepts default width and height as input and returns 
							// either actual screen width and height or the defaults
	screenH = defaultH
	screenW = defaultW;

	if (parseInt(navigator.appVersion)>3) {
		 screenH = screen.height;
		 screenW = screen.width;
	}
	else if (navigator.appName == "Netscape" 
	    && parseInt(navigator.appVersion)==3
	    && navigator.javaEnabled()
	) 
	{
	 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
	 var jScreenSize = jToolkit.getScreenSize();
	 screenH = jScreenSize.height;
	 screenW = jScreenSize.width;
	}

	return [screenW, screenH];
}



function openWin(whichURL,winW,winH) {				// Open document in a new (minimalist) window

	var screenWH = getScreenSpecs(800, 600);
	screenW = screenWH[0];
	screenH = screenWH[1];

	if (!winW) {
		winW = screenW;
		winH = screenH;
	}

	popWin=window.open(whichURL,"pWin","toolbar=no,scrollbars=yes,resizable=no,width="+winW+",height="+winH+ ",left=" + Math.round((screenW/2)-(winW/2))+ ",top=" + Math.round((screenH/3)-(winH/2)) );
}


function openBrowser(whichURL, winW, winH) {				// Open document in a new (navigable) window

	var screenWH = getScreenSpecs(800, 600);
	screenW = parseInt( screenWH[0] );
	screenH = parseInt( screenWH[1] );

	if (!winW) {
		winW = screenW - 80;
		winH = screenH - 100;
	}
	
	var vPos = Math.round((screenH/2)-(winH/2));
	var hPos =  Math.round((screenW/2)-(winW/2));

	popWin=window.open(whichURL,"pWin","toolbar=yes,scrollbars=yes,menubar=yes,resizable=yes,width="+winW+",height="+winH+ ",left=" + hPos );
	
}


function initFrame() {						// Size the content iFrame to fit the window height
	var frameObj = getObjectByID('mainFrame');
	var windowH = getWindowHeight();

	frameObj.height = (windowH - 168);
}


function setFrame(whichPage) {					// Change the page within the mainFrame
	var frameObj = getObjectByID('mainFrame');
	frameObj.src = whichPage;
}


function getWindowHeight() {			
							
	if (window.innerHeight) {				// Firefox and Safari
		return window.innerHeight;
	} else {								// IE
		return document.body.clientHeight; 
	}
}
	

function getWindowWidth() {
   if (window.innerWidth) {
       return window.innerWidth;
   } else {
       return document.body.clientWidth;
   }	   	   	
	
}


function openShow(page, name, h, w, scrollBool) {

	if(popup) {
		popup.close();
	}
		
		popup = window.open(page, name, 'height=' +h+ ',width=' +w+ ',scrollbars=' +scrollBool+ ',resizeable=no');
}


function openDefault(page) {

	pop2 = window.open(page, 'fullWin', 'scrollbars=yes, status=yes, menubar=yes, toolbar=yes, location=yes, resizable=yes, width=966, height=680');
	
	if(popup) {
		popup.close();
	}
}