﻿/* Layer Swaps */
function swapLayer(parentDiv, val, val2) {
	var allDivs = document.getElementById(parentDiv);
	var divArray = allDivs.getElementsByTagName('div');
	for (var i = 0; i < divArray.length; ++i) {
		if ((divArray[i].id == val) || (divArray[i].id == val2)) {
			document.getElementById(divArray[i].id).style.display = 'block';
		}
		else {
			document.getElementById(divArray[i].id).style.display = 'none';
		}
	}
}

function toggleButton(parentDiv, val) {
	var allDivs = document.getElementById(parentDiv);
	var divArray = allDivs.getElementsByTagName('div');
	var commonDivArray = getCommonDivIDs();
	var commonMatch = false;
	
	for (var i = 0; i < divArray.length; ++i) {

		//If there are extra DIVs in the array, make sure they aren't used in the function
		for (var j = 0; j < commonDivArray.length; j++) {

			if ((commonDivArray[j] == divArray[i].id) || (commonDivArray[j] == divArray[i].className)) {
				commonMatch = true;
			}
		}
		
		//Proceed with toggle only if matches were not found
		if (!commonMatch)
		{
			if (divArray[i].id == val) {
				document.getElementById(divArray[i].id).getElementsByTagName('a')[0].style.backgroundPosition = 'bottom left';
			}
			else {
				document.getElementById(divArray[i].id).getElementsByTagName('a')[0].style.backgroundPosition = 'top left';
			}
		}

		commonMatch = false;
	}
}

function getCommonDivIDs() {

	var array = new Array("ul", "ur", "ll", "lr");
	return array;
}



/* Open a new window (perfectly centered at 70-90% of screen size) */
function openWin() {
	args = openWin.arguments;

	/*--- Choose window size (full screen minus how many pixels) ---*/
	var windowsize = 150;
	var maxwindowwidth = 1024;
	var maxwindowheight = 768;
	/*--------------------------------------------------------------*/

	if (screen.width > maxwindowwidth)
	{
		var width = maxwindowwidth;
		var widthc = (screen.width - maxwindowwidth) / 2;
	}
	else
	{
		var width = screen.width - windowsize;
		var widthc = windowsize / 2;
	}

	if (screen.height > maxwindowheight)
	{
		var height = maxwindowheight;
		var heightc = ((screen.height - maxwindowheight) / 2) - 50;
	}
	else
	{
		var height = screen.height - (windowsize * 2);
		var heightc = windowsize / 2;
	}
	
	window.open(args[0], 'openWin', 'width=' + width + ',height=' + height + ',top=' + heightc + ',left=' + widthc + ',scrollbars=1,status=1,toolbar=1,menubar=1,resizable=1');
	return false;
}

//Javascript cookies
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	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;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

/*admin section*/
function confirmDelete() {
	return confirm("Are you sure you want to delete this event? This cannot be undone.");
}