/*=============================================
	javascript library
==============================================*/






/*=============================================
	misc utility functions
==============================================*/

/*------------------------------------------------------------
*  Function:  getProps
*  
*  Description:
*  Builds a string from the properties of an object and their values
*  
*  Parameters:
*  which	string or object reference
*  
*  Return:
*  string
*------------------------------------------------------------*/

function getProps(which) {
	var theObj = $(which);
	var str = "";
	for (prop in theObj) {
		str += prop + ": " + eval("theObj." + prop) + " | ";
	}
	return(str);
}


/*------------------------------------------------------------
*  Function:  correctPNG
*  
*  Description:
*  Correctly handle PNG transparency in Win IE 5.5 or higher
*  http://homepage.ntlworld.com/bobosola. Updated 02-March-2004
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/

function correctPNG() {
	if (document.all && navigator.platform.indexOf('Mac')<0) {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:block;" + img.style.cssText;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
	}
}



/*------------------------------------------------------------
*  Function:  parseQuery
*  
*  Description:
*  allows us to set javascript variables by passing them in as
*  values in the query string. by default it looks for the
*  query string after the occurrence of '?' in URL of the
*  current document
*  
*  Parameters:
*  loc		string	url to search for query string
*  key		string	string which delimits query string from rest of URL
*  
*  Return:
*  none
*------------------------------------------------------------*/
function parseQuery(loc,key) {
	if (loc == null) loc = document.location.href;
	if (key == null) key = '?';
	if (loc.indexOf(key) > -1) {
		query = loc.substring(loc.indexOf(key)+key.length,loc.length);
		args = query.split('\&');
		for (i=0; i<args.length; i++) {
			chunk = args[i];
			eval(chunk.split('=')[0] + " = '" + chunk.split('=')[1] + "'");
		}
	}
}



/*------------------------------------------------------------
*  Function:  validEmail
*  
*  Description:
*  validates that an email is formatted properly
*  
*  Parameters:
*  email		string	email address
*  
*  Return:
*  true or false
*------------------------------------------------------------*/

function validEmail(email) {
	var emailRegex = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$/g;
	return(email.match(emailRegex));
}




/*------------------------------------------------------------
*  Function:  stristr
*  
*  Description:
*  checks to see if one string exists in another string
*  
*  Parameters:
*  str		string	the string to search in
*  match	string	the string to search for
*  
*  Return:
*  true or false
*------------------------------------------------------------*/

function stristr(str,match) {
	return (str.indexOf(match) > -1)?true:false; 
}




/*------------------------------------------------------------
*  Function:  newImage
*  
*  Description:
*  accepts a path to an image file. creates a new image object
*  and stuffs the src. used by the rollover framework
*  
*  Parameters:
*  arg		string	path to image file
*  
*  Return:
*  rslt		image object
*------------------------------------------------------------*/
function newImage(arg) {
	rslt = new Image();
	rslt.src = arg;
	return rslt;
}




/*------------------------------------------------------------
*  Function:  openPopupWindow
*  
*  Description:
*  opens a popup window of a passed width and height
*  and loads the passed URL in it
*  
*  Parameters:
*  url			string		page to load
*  w			integer		width of popup window
*  h			integer		height of popup window
*  features		string		window features - see below for defaults
*  
*  Return:
*  none
*------------------------------------------------------------*/
function openPopupWindow(url,w,h,features) {
	if (w == null) w = 400;
	if (h == null) h = 400;
	if (features == null) features = ",menubar=0,status=0,location=0,directories=0,resizable=1,scrollbars=1";
	
	if (url) {
		var popupWindow = window.open(url,'popupWindow','width='+w+',height='+h+features);
		popupWindow.focus();
	}
}




/*------------------------------------------------------------
*  Function:  resizeWindow
*  
*  Description:
*  resizes a window to a given width and height
*  by default, will only resize if the window is smaller than the prescribed width and/or height
*  if forceResize is passed in as true, it will force the window to the desired size
*  
*  Parameters:
*  w				integer	desired width
*  h				integer	desired height
*  forceResize		boolean	if true, forces large window to resize down to desired size
*  
*  Return:
*  none
*------------------------------------------------------------*/
function resizeWindow(w,h,forceResize) {
	if (window.innerWidth && window.innerHeight) {
		var wdiff = window.outerWidth - window.innerWidth;
		var hdiff = window.outerHeight - window.innerHeight;
		
		var windowIsSmaller = false;
		if (window.innerWidth < w) {
			endw = w + wdiff;
			windowIsSmaller = true;
		} else {
			endw = window.outerWidth;
		}
		if (window.innerHeight < h) {
			endh = h + hdiff;
			windowIsSmaller = true;
		} else {
			endh = window.outerHeight;
		}
		if (forceResize) {
			endw = w + wdiff;
			endh = h + hdiff;
		}
		
		if (windowIsSmaller || forceResize) self.resizeTo(endw,endh);
	}
}



/*------------------------------------------------------------
*  Function:  dw
*  
*  Description:
*  shorthand for document.write
*  
*  Parameters:
*  msg		string	text to be written
*  
*  Return:
*  none
*------------------------------------------------------------*/
function dw(msg) {
	document.writeln(msg);
}



/*------------------------------------------------------------
*  Function:  randomNum
*  
*  Description:
*  returns a random number in the specified range of numbers, inclusive
*  
*  Parameters:
*  start	integer	first number in desired range
*  end		integer	last number in desired range
*  
*  Return:
*  n		integer
*------------------------------------------------------------*/
function randomNum(start,end) {
	var range = end - start + 1;
	var n = Math.floor(Math.random() * (range)) + start;
	return(n);
}



/*------------------------------------------------------------
*  Function:  show
*  
*  Description:
*  shows an object, if not nested in a hidden object
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function show(which) {
	var obj = $(which);
	if (obj) obj.style.visibility = "inherit";
}



/*------------------------------------------------------------
*  Function:  hide
*  
*  Description:
*  hides an object from display
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hide(which) {
	var obj = $(which);
	if (obj) obj.style.visibility = "hidden";
}



/*------------------------------------------------------------
*  Function:  showDisplay
*  
*  Description:
*  sets the display value of an object to the passed in display type
*  defaults to "block"
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  type		string			either "inline" or "block" -- defaults to "block"
*  
*  Return:
*  none
*------------------------------------------------------------*/
function showDisplay(which,type) {
	if (! type) type = "block";
	var obj = $(which);
	if (obj) obj.style.display = type;
}



/*------------------------------------------------------------
*  Function:  hideDisplay
*  
*  Description:
*  sets the display value of an object to "none"
*  
*  Parameters:
*  which	string/object	ID of object to be shown, or reference to the object itself
*  
*  Return:
*  none
*------------------------------------------------------------*/
function hideDisplay(which) {
	var obj = $(which);
	if (obj) obj.style.display = "none";
}


/*=============================================
	end misc utility functions
==============================================*/




/*=============================================
	cookie library
==============================================*/


/*------------------------------------------------------------
*  Function:  getExpDate
*  
*  Description:
*  utility function to retrieve an expiration date in proper format
*  pass three integer parameters for the number of days, hours,
*  and minutes from now you want the cookie to expire (or
*  negative values for a past date)
*  all three parameters are required, so use zeros where appropriate
*  
*  Parameters:
*  days	integer
*  hours	integer
*  minutes	integer
*  
*  Return:
*  date	string
*------------------------------------------------------------*/
function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	if (typeof days == "number" && typeof hours == "number" && typeof minutes == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		return expDate.toGMTString();
	}
}


/*------------------------------------------------------------
*  Function:  getCookieVal
*  
*  Description:
*  utility function called by getCookie()
*  
*  Parameters:
*  offset	string
*  
*  Return:
*  cookie	string
*------------------------------------------------------------*/
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

// 


/*------------------------------------------------------------
*  Function:  getCookie
*  
*  Description:
*  primary function to retrieve cookie by name
*  
*  Parameters:
*  name	string	name of cookie to be retrieved
*  
*  Return:
*  value	string	value of named cookie
*------------------------------------------------------------*/
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) {
			return getCookieVal(j);
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return "";
}



/*------------------------------------------------------------
*  Function:  setCookie
*  
*  Description:
*  store cookie value with optional details as needed
*  
*  Parameters:
*  name	string
*  value	string
*  expires	string
*  path	string
*  domain	string
*  secure	boolean
*  
*  Return:
*  none
*------------------------------------------------------------*/
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}




/*------------------------------------------------------------
*  Function:  deleteCookie
*  
*  Description:
*  remove the cookie by setting ancient expiration date
*  
*  Parameters:
*  name	string
*  path	string
*  domain	string
*  
*  Return:
*  none
*------------------------------------------------------------*/
function deleteCookie(name,path,domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/*=============================================
	end cookie library
==============================================*/




/*=============================================
	rollover library
==============================================*/

// array used to store rollover states and image data
var rollovers = new Array();


/*------------------------------------------------------------
*  Function:  imgOn. imgOver, imgOn
*  
*  Description:
*  shorthand functions for calling imgSwap
*  
*  Parameters:
*  which	string 	name of image to swap
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgOn(which) {
	imgSwap(which,'on');
}

function imgOver(which) {
	imgSwap(which,'over');
}

function imgOff(which) {
	imgSwap(which,'off');
}



/*------------------------------------------------------------
*  Function:  imgSwap
*  
*  Description:
*  stub function for rollovers
*  expects an image name and state
*  checks for existence of named image, and defined state
*  also checks to see if image has been disabled -- this is used to freeze an image in a given state
*  
*  Parameters:
*  which	string 	name of image to swap
*  state	string	name of state to swap to
*  
*  Return:
*  none
*------------------------------------------------------------*/
function imgSwap(which,state) {
	if (which && rollovers[which]) {
		if (document.images[which] && eval('rollovers[which].states.' + state)) {
			if (! rollovers[which].frozen) {
				document.images[which].src = eval('rollovers[which].states.' + state).src;
			}
		}
	}
}


/*------------------------------------------------------------
*  Function:  newRollover
*  
*  Description:
*  this function populates the rollovers array with the image
*  objects used for the various states of a rollover
*  
*  Parameters:
*  name		string	name of image object
*  offsrc		string	path to image file for off (normal) state
*  oversrc		string	path to image file for over state
*  onsrc		string	path to image file for on (selected) state
*  disabledsrc	string	path to image file for disabled state
*  
*  Return:
*  none
*------------------------------------------------------------*/
function newRollover(name,offsrc,oversrc,onsrc,disabledsrc) {
	rollovers[name] = new Object();
	rollovers[name].states = new Object();
	rollovers[name].states.off = (offsrc) ? newImage(offsrc) : null;
	rollovers[name].states.over = (oversrc) ? newImage(oversrc) : null;
	rollovers[name].states.on = (onsrc) ? newImage(onsrc) : null;
	rollovers[name].states.disabled = (disabledsrc) ? newImage(disabledsrc) : null;
	// the following variable is used to prevent an image from being changed on rollover
	// used for disabling images that are in a disabled or selected state and shouldn't change
	rollovers[name].frozen = false;
}




/*=============================================
	end rollover library
==============================================*/




/*=============================================
	startup calls
==============================================*/

/*------------------------------------------------------------
*  Function:  startup
*  
*  Description:
*  does various initialization procedures
*  
*  Parameters:
*  none
*  
*  Return:
*  none
*------------------------------------------------------------*/
function globalStartup() {
	correctPNG();
}

window.onload = globalStartup;

/*=============================================
	end startup calls
==============================================*/




/*=============================================
	inline calls
==============================================*/


/*=============================================
	end inline calls
==============================================*/





