// The URI! Zone: Common JavaScript Functionality
//
// (c) 2010 by Brian Uri!
// You may not use, duplicate, or modify this code without permission.

// ### LOCATIONS ###

var xDir = "/"
var xPics = xDir + "images/"

// Subsection constants
var NEWS = "News"
var ABOUT = "About"
var MUSIC = "Music"
var GAMES = "Games"

// Subsection locations
var x = new Array()
x[NEWS] = xDir + NEWS + "/"
x[ABOUT] = xDir + ABOUT + "/"
x[MUSIC] = xDir + MUSIC + "/"
x[GAMES] = xDir + GAMES + "/"

// ### VARIABLES ###

// StatCounter
var sc_project=3932423; 
var sc_invisible=0; 
var sc_partition=47; 
var sc_click_stat=1; 
var sc_security="c019035f"; 
var sc_text=2; 
	
var CENTER = "center"
var RIGHT = "right"
var LEFT = "left"
var EMPTY = ""
var YES = "yes"
	
var eMail = "\u0062\u0072\u0069\u0061\u006e\u0040\u0075\u0072\u0069\u007a\u006f\u006e\u0065\u002e\u006e\u0065\u0074"

var clearDiv = "<div class='clear'></div>"
var atomIcon = makePic(xPics + "AtomIcon.jpg", "*", EMPTY)
var dotIcon = makePic(xPics + "Dot.jpg", "*", EMPTY)
var deadDotIcon = makePic(xPics + "DeadDot.jpg", "*", EMPTY)
var mailIcon = makePic(xPics + "Mail.gif", "mail")

// ### FUNCTIONS ###

// Collapsible subsection code
$(document).ready(function() {
	$("div.divExpand").toggle(
		function() {
			contentDiv = $(this).parent().next();
			contentDiv.show("fast");
			delCookie(contentDiv.get(0).id);		     
			$(this).attr("class", "divCollapse");
		},
		function() {
			contentDiv = $(this).parent().next();
			contentDiv.hide("fast");
			setCookie(contentDiv.get(0).id, "true");
			$(this).attr("class", "divExpand");
		});	  
	$("div.divCollapse").toggle(
		function() {
			contentDiv = $(this).parent().next();
			contentDiv.hide("fast");
			setCookie(contentDiv.get(0).id, "true");
			$(this).attr("class", "divExpand");
		},
		function() {
			contentDiv = $(this).parent().next();
			contentDiv.show("fast");
			delCookie(contentDiv.get(0).id);
			$(this).attr("class", "divCollapse");
		});
	});	
	
function getPage() {
	var pageId = parent.location.href.substring(parent.location.href.indexOf("?page=") + 6, parent.location.href.length);
	return (pageId);
}

function contact(subject) {
	return (eMail + " <a href='mailto:" + eMail + "?Subject=" + subject + "'>" + mailIcon + "</a>")
}

// Checks if a form field is empty, null, or just contains html tags and no text
function isFieldEmpty(theField) {
	if (theField != null && theField.value != null) {
		fieldValue = theField.value.replace(/&nbsp;/g,'');
		fieldValue = fieldValue.replace(/&(lt|gt);/g, function (strMatch, p1){
				return (p1 == "lt")? "<" : ">";
		});
		fieldValue = fieldValue.replace(/<\/?[^>]+(>|$)/g, "");
	}
	return (theField == null || theField.value == null || fieldValue == null || fieldValue == '' || fieldValue.replace(/^\s*|\s*$/g,'') == '');
}

function makePic(pic, titleText, align, width, height) {
	alignText = (align != EMPTY) ? " align='" + align + "'" : EMPTY
	if (width != undefined && height != undefined)
		alignText += " width=" + width + " height=" + height
	return ("<img src='" + pic + "' title='" + titleText + "' border='0'" + alignText + " />")
}

function getCookie(name) {
	i = 0
	cookieArg = name + "="
	theCookie = document.cookie
	while (i < theCookie.length) {
		j = i + cookieArg.length
		if (theCookie.substring(i, j) == cookieArg) {
			endToken = theCookie.indexOf (";", j)
			endToken = (endToken == -1) ? theCookie.length : endToken
			return (unescape(theCookie.substring(j, endToken)))
		}
		i = theCookie.indexOf(" ", i) + 1
		if (i == 0)
			break
	}
	return (null)
}

function setCookie(NameOfCookie, value, expiredays) { 
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? ";" : "; expires=" + ExpireDate.toGMTString() + ";");
}

function delCookie(NameOfCookie) { 
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
