/*
* File Name    :core.js
* Dependencies :none
*/

/*
* Name: prepRollover(objectName,objectState,filePath,fileName)
* Desc: prepares a rollover object for later
*/
function prepRollover(objectName,objectState,filePath,fileName) {
	this[objectName + objectState] = new Image();
	this[objectName + objectState].src = filePath + fileName;
}

/*
* Name: swapImage(imageName,imageState)
* Desc: loads a new image resource
*/
function swapImage(imageName,imageState) {
	document.images[imageName].src = this[imageName + imageState].src;	
}

// global variable for popups
var popUpWin=0;

/*
* Name: popUpWindow(URLStr,left,top,width,height)
* Desc: pop up a window
*/
function popUpWindow(URLStr,left,top,width,height) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr,'popUpWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

/*
* Name: popUpWindowCentered(URLStr,width,height)
* Desc: pop up a window centered on the screen
*/
function popUpWindowCentered(URLStr,width,height) {
	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);
	popUpWindow(URLStr,left,top,width,height);
}

/*
* Name: popUpWindow34(URLStr)
* Desc: pop up a window 3/4 of screen size centered on the screen
* Note: still working out height detection in Firefox
*/
function popUpWindow34(URLStr) {
	var width = screen.width * 0.75;
	var height = screen.height * 0.75;
	var left = (screen.width / 2) - (width / 2);
	var top = (screen.height / 2) - (height / 2);
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr,'popUpWin','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

/*
* Name: closeWindow()
* Desc: close the current window
*/
function closeWindow() { close(); }

/*
* Name: writeEmail(address,domain)
* Desc: write an email address and hide it from spammers
*/
function writeEmail(address,domain) {
	var email = address+"&#64;"+domain;
	document.write('<a href="mailto:'+email+'">'+email+'</a>'); 
}

/*
* Name: emptyField(fieldID)
* Desc: empty a text field on click
*/
function emptyField(fieldID) {
	var myField = document.getElementById(fieldID);
	myField.value = "";
}

/*
* Name: getURLToken(tokenName)
* Desc: return the value of a url token
*/
function getURLToken(tokenName) {
	var tokenStr = location.search.substr(1);
	var tokenArray = tokenStr.split("#");
	var numTokens = tokenArray.length;
	for (var i=0; i<numTokens; i++) {
		var tokenSplit = tokenArray[i].split("=");
		if (tokenSplit[0] == tokenName) return tokenSplit[1];
	}
	return "";
}
