/* ************************* */
/*  displays hidden elements */
/* ************************* */

function displayElement (whatElement, whatState) {
	
	if (whatState == "open") {
		
		document.getElementById(whatElement).style.display = "block";
		
	} else {
		
		document.getElementById(whatElement).style.display = "none";
		
	}
	
}

/* ************************** */
/*  standard cookie creation  */
/* ************************** */

function createCookie (cookName, whatValue) {
	
	var value = whatValue;

	document.cookie = cookName + "=" + value + "; path=/";
	
}

/* *************************** */
/*  standard cookie retrieval  */
/* *************************** */

function readCookie (cookName) {
	
	var nameEQ = cookName + "=";
	var ca = document.cookie.split(';');
	
	for(var i = 0; i < ca.length; i++) {
		
		var c = ca[i];
		
		while(c.charAt(0) == ' ') {
		
			c = c.substring(1, c.length);
		
		}

		if(c.indexOf(nameEQ) == 0) {
		
			return c.substring(nameEQ.length, c.length);
		
		}
	}
	
	return null;
}

/* ************************* */
/*  standard cookie removal  */
/* ************************* */

function removeCookie (cookName) {
	
	document.cookie = cookName + "=; path=/" + "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		
}

/* ******************************* */
/*  store user prefs when altered  */
/* ******************************* */

function prefsCookie (cookName, prefs) {
	
	var value = prefs;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (365 * 24 * 3600 *1000));

	document.cookie = cookName + "=" + value + "; path=/" + "; expires=" + expDate;
	
}

/* ******************** */
/*  process tool click  */
/* ******************** */

function processTool (doWhat, whatPage) {
	
	switch (doWhat) {
		
		case "enlarge text":
			textSize ('inc');
			break;
			
		case "shrink text":
			textSize ('dec');
			break;
			
		case "print page":
			window.print();
			break;
			
		case "email this page":
			location.href = "http://" + location.hostname + "?pg=emailPage&page=" + whatPage;
			break;
			
		case "site map":
			location.href = "http://" + location.hostname + "?pg=siteMap";
			break;
			
		case "login":
			location.href = "http://" + location.hostname + "?pg=login";
			break;
		
		default:
			break;
		
	}
	
}

/* ************************** */
/*  change prefs (text size)  */
/* ************************** */

function textSize (dir) {
	
	var element = document.getElementById ("content");
	var left = getCSSProp (element, "fontSize");
	
	var result = parseInt (left.slice (0, 2));
	
	if ((dir == "dec" && result > 9) || (dir == "inc" && result < 16)) {
		
		switch (dir) {
			
			case 'inc':			
				element.style.fontSize = (result + 1) + "px";
				prefsCookie ("prefs", (result + 1));
				break;
					
			case 'dec':			
				element.style.fontSize = (result - 1) + "px";
				prefsCookie ("prefs", (result - 1));
				break;
					
			default:			
				break;
				
		}
		
	}
	
}

/* ******************************** */
/*  determine current css settings  */
/* ******************************** */

function getCSSProp (element, prop) {	
	
	if(element.style[prop]) {
		
		// inline style property
		return element.style[prop];
		
	} else if (element.currentStyle) {
		
		// external stylesheet for ie
		return element.currentStyle[prop];
		
	} else if (document.defaultView && document.defaultView.getComputedStyle) {
		
		// external stylesheet for ff and sf 1.3+
		prop = prop.replace(/([A-Z])/g,"-$1");
		prop = prop.toLowerCase();
		return document.defaultView.getComputedStyle(element,"").getPropertyValue(prop);
		
	} else {
		
		// Safari 1.2
		return null;
		
	}
  	
}

/* ********************** */
/*  characters remaining  */
/* ********************** */

var holdChar80 = 80;
var holdChar60 = 60;

function charRemain (charAmount) {
	
	var numChar = document.getElementById('desc').value.length;
	
	var result = (charAmount == 80) ? document.getElementById('maxChar').innerHTML = (holdChar80 - numChar) : document.getElementById('maxChar').innerHTML = (holdChar60 - numChar);
	
}

/* ****************************************************** */
/*  determine screen resolution, assign new window sizes  */
/* ****************************************************** */

var resWidth = screen.width;

if (resWidth.toString() == "800") {
	
	var width = 780;
	var height = 580;
	
} else if (resWidth.toString() == "1024") {
	
	var width = 900;
	var height = 700;

} else if (resWidth.toString() == "1152") {
	
	var width = 900;
	var height = 820;

} else if (resWidth.toString() >= "1280") {
	
	var width = 900;
	var height = 960;
	
}

/* ********************* */
/*  opens a new windows  */
/* ********************* */

var settings = "";
var newWin = "";

function openWin (whatPage) {
	
	var leftPos = (screen.width) ? (screen.width - width) / 2 : 0;

	settings = 'width=' + width + ',height=' + height + ',top=0,left=' + leftPos + ',scrollbars=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,status=yes';

	newWin = window.open(whatPage, 'win', settings);
	
}

function openWinSmall (whatPage) {
	
	var width = 400;
	var height = 160;
	
	var topPos = (screen.height) ? (screen.height - height) / 2 : 0;
	var leftPos = (screen.width) ? (screen.width - width) / 2 : 0;

	settings = 'width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no,status=no';

	newWin = window.open(whatPage, 'win', settings);
	
}

function openImageWin (whatPage, width, height, browser) {
	
	var parsedPage = whatPage.substr (0, 4);

	if (parsedPage == "view") {
		
		if (browser == "ie") {
			
			width += 27;
			height += 34;
			
		} else if (browser == "sf") {
			
			width += 24;
			height += 32;
			
		} else {
			
			width += 22;
			height += 22;
			
		}
		
	} else {
		
		width += 40;
		height += 0;
		
	}
	
	var topPos = (screen.height) ? (screen.height - height) / 2 : 0;
	var leftPos = (screen.width) ? (screen.width - width) / 2 : 0;

	settings = 'width=' + width + ',height=' + height + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=no,toolbar=no,menubar=no,location=no,resizable=no,status=no';

	newWin = window.open(whatPage, 'win', settings);
	
}