/*
* File Name     : core.js
* Dependencies  : none
* Description   : Basic JavaScript functions commonly used.
* Version       : 1.2.2
* Date Modified : 8/17/2007
* Usage         : Copyright 2007 Craig Phares. All rights reserved.
*/

/*
* 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: getURLVar(urlVarName)
* Desc: retrive the url variable
*/
function getURLVar(urlVarName) {
	//divide the URL in half at the '?'
	var urlHalves = String(document.location).split('?');
	var urlVarValue = '';
	if(urlHalves[1]){
		//load all the name/value pairs into an array
		var urlVars = urlHalves[1].split('&');
		//loop over the list, and find the specified url variable
		for(i=0; i<=(urlVars.length); i++){
			if(urlVars[i]){
				//load the name/value pair into an array
				var urlVarPair = urlVars[i].split('=');
				if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
					//I found a variable that matches, load it's value into the return variable
					urlVarValue = urlVarPair[1];
				}
			}
		}
	}
	return urlVarValue;   
}

/*
* Name: getURLTokens()
* Desc: returns all the URL tokens as a string
*/
function getURLTokens() {
	var urlHalves = String(document.location).split('?');
	return urlHalves[1];
}
