var base_href = document.getElementsByTagName('BASE')[0].href;
function ajax_popup_align() {
	resize_popup = function() {
		e = $('#popup_foreground').children().first();
		eheight = e.outerHeight();
		wheight = $(window).height();
		etop = wheight/2-eheight/2;
		e.css({marginTop: etop + 'px'});
	};
	resize_popup();
	$(window).resize(resize_popup);
}
function ajax_popup_close() {
	$('#popup_backdrop').fadeOut(function() { $(this).remove(); });
	$('#popup_foreground').fadeOut(function() { $(this).remove(); });
}
function ajax_popup_open(content) {
	if ($('#popup_backdrop').size())
		return;
	$('body').append('<div id="popup_backdrop"></div><div id="popup_foreground"></div>');
	$('#popup_foreground').click(function(event) {
		if ($(event.target).attr('id') == $(this).attr('id')) {
			ajax_popup_close();
		}
	});	
	$('#popup_foreground').html(content);
	$('#popup_backdrop').fadeTo('normal', 0.4);
	$('#popup_foreground').fadeTo('normal', 1);
}

var the_query_string = new Object();
(function() {
	var qs = location.search.substr(1).replace(/\+/g, ' ').split('&');
	for (var i = 0; i < qs.length; i++) {
		qs[i] = qs[i].split('=');
		if (qs[i][0])
			the_query_string[qs[i][0]] = decodeURIComponent(qs[i][1]);
	}
})();
//from http://jacwright.com/projects/javascript/date_format
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		};
	}
}
function chr(ord) {
	return String.fromCharCode(ord);
}
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};
// This is variable for storing callback function
var ae_cb = null;

// this is a simple function-shortcut
// to avoid using lengthy document.getElementById
function ae$(a) { return document.getElementById(a); }

// This is a main ae_prompt function
// it saves function callback
// and sets up dialog
function ae_prompt(cb, q, a) {
	ae_cb = cb;
	//ae$('aep_t').innerHTML = ':';
	ae$('aep_prompt').innerHTML = q;
	ae$('aep_text').value = a;
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = '';
	ae$('aep_text').focus();
	ae$('aep_text').select();
}

// This function is called when user presses OK(m=0) or Cancel(m=1) button
// in the dialog. You should not call this function directly.
function ae_clk(m) {
	// hide dialog layers
	ae$('aep_ovrl').style.display = ae$('aep_ww').style.display = 'none';
	if (!m)
		ae_cb(null);  // user pressed cancel, call callback with null
	else
		ae_cb(ae$('aep_text').value); // user pressed OK
}
var rname;
function email_friend() {
	ae_prompt(step2, 'Recipient Name:', '');
}
function step2(n) {
	if (null === n)
		return false;
	rname=n;
	ae_prompt(step3, 'Recipient Email:', '');
}
function up(tag,node) {
	while (node.nodeName != tag && node.parentNode) {
		node = node.parentNode;
	}
	return node;
}
function step3(remail) {
	if (null === remail)
		return false;
	link = 'mailto:' + remail + '?subject=' + escape('I thought you might be interested') + '&body=' + escape("Hi " + rname + ",\r\n\r\nI thought you might be interested in this page I found on EICTA.\r\n" + document.location + "\r\n\r\nThank you");
	location.href = link;
}
function is_child_of(parent, child) {
	if( child != null ) {
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
function fixOnMouseOut(element, event, JavaScript_code) {
	var current_mouse_target = null;
	if( event.toElement ) {
		current_mouse_target = event.toElement;
	} else if( event.relatedTarget ) {
		current_mouse_target = event.relatedTarget;
	}
	if(!is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
		eval(JavaScript_code);
	}
}
var buttond;
function button_hover(buttond) {
		bleft = getElementsByClassName('left', 'div', buttond);
		bright = getElementsByClassName('right', 'div', buttond);
		bface = getElementsByClassName('face', 'div', buttond);
		bleft[0].style.backgroundImage = 'url(\'static/img/button-pleft.png\')';
		bright[0].style.backgroundImage = 'url(\'static/img/button-pright.png\')';
		bface[0].style.backgroundImage = 'url(\'static/img/button-pback.png\')';
	}
	function button_depress() {
		bleft = getElementsByClassName('left', 'div', buttond);
		bright = getElementsByClassName('right', 'div', buttond);
		bface = getElementsByClassName('face', 'div', buttond);
		bleft[0].style.backgroundImage = 'url(\'static/img/button-left.png\')';
		bright[0].style.backgroundImage = 'url(\'static/img/button-right.png\')';
		bface[0].style.backgroundImage = 'url(\'static/img/button-back.png\')';
	}
//First things first, set up our array that we are going to use.
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //all caps
"abcdefghijklmnopqrstuvwxyz" + //all lowercase
"0123456789+/="; // all numbers plus +/=
function decode64(inp) {
	var out = ""; //This is the output
	var chr1, chr2, chr3 = ""; //These are the 3 decoded bytes
	var enc1, enc2, enc3, enc4 = ""; //These are the 4 bytes to be decoded
	var i = 0; //Position counter

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	var base64test = /[^A-Za-z0-9\+\/\=]/g;

	if (base64test.exec(inp)) { //Do some error checking
		alert("There were invalid base64 characters in the input text.\n" +
		"Valid base64 characters are A-Z, a-z, 0-9, ?+?, ?/?, and ?=?\n" +
		"Expect errors in decoding.");
	}
	inp = inp.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do { //Here.s the decode loop.

		//Grab 4 bytes of encoded content.
		enc1 = keyStr.indexOf(inp.charAt(i++));
		enc2 = keyStr.indexOf(inp.charAt(i++));
		enc3 = keyStr.indexOf(inp.charAt(i++));
		enc4 = keyStr.indexOf(inp.charAt(i++));

		//Heres the decode part. There.s really only one way to do it.
		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		//Start to output decoded content
		out = out + String.fromCharCode(chr1);

		if (enc3 != 64) {
			out = out + String.fromCharCode(chr2);
		}
		if (enc4 != 64) {
			out = out + String.fromCharCode(chr3);
		}

		//now clean out the variables used
		chr1 = chr2 = chr3 = "";
		enc1 = enc2 = enc3 = enc4 = "";

	} while (i < inp.length); //finish off the loop

	//Now return the decoded values.
	return out;
}


function html_entity_decode(str) {
	return $('<div/>').html(str).text();
}

function cleanurl(str) {
	str = html_entity_decode(str);
	//str.replace(/<[^<>]+>/g, '');
	str = str.toLowerCase();
	str = str.replace(/[^\da-z\$_.!*\'(),]+/g, '-');
	return str.replace(/^\-|\-$/g, '');
}

function cleanSection(str) {
	return str.replace(/[\s\u00A0\-]+/g, '-');
}
function cleanSectionBlur(str) {
	return cleanSection(str).replace(/^\-|\-$/g, '');
}

