﻿// Global functions and event hookup
var preloadImgs = new Array();

function swapImg(obj){
	if(!obj.src)
		return;

	if(obj.src.indexOf('_on') > -1)
		obj.src = obj.src.replace('_on.gif', '_off.gif');
	else
		obj.src = obj.src.replace('_off.gif', '_on.gif');
}

window.onload = function(){
	// external links
	if (document.getElementsByTagName){
		var links = document.getElementsByTagName('a');
		for(i=0;i<links.length;i++){
			if(links[i].getAttribute('rel') == 'external'){
				links[i].onclick=function(){window.open(this.href);return false;}
			}
		}
	}

	// preload images
	imagesArray = new Array();
	n = 0;
	if (document.images) {
		for (i=0; i<document.images.length; i++) {
			if (document.images[i].src.indexOf("-n.png")>0) { 
				img_on = document.images[i].src;
				img_on = img_on.substring(0,img_on.length-5) + "h.png";
				imagesArray[n] = new Image();
				imagesArray[n].src = document.images[i].src;
				imagesArray[n+1] = new Image();
				imagesArray[n+1].src = img_on; 
				n = n+2;
			}
		}
	}
	
	// show login box if error
	if (document.getElementById("ctl00_ctl00_LoginView2_Login1_FailureText")) {
		if (document.getElementById("ctl00_ctl00_LoginView2_Login1_FailureText").innerHTML != "") {
			showLoginBox();
			showRealPasswordBox(false);
		}
	}
	
	document.body.resize = function(){
		if(!document.all)
			return;

		window.location.reload(false);
	}
}

function mouseOut(imgID) {
	if (document.getElementById) {
		img_on = document.getElementById(imgID).src;
		document.getElementById(imgID).src = img_on.substring(0,img_on.length-5) + "n.png";
	}
}
function mouseOver(imgID) {
	if (document.getElementById) {	
		img_on = document.getElementById(imgID).src;
		document.getElementById(imgID).src = img_on.substring(0,img_on.length-5) + "h.png";
	}
}

function searchClicked(objSearch) {
	if (objSearch.value == "I'm looking for...") {
		objSearch.value = "";
	}
}

function showRealPasswordBox(bFocus) {
	document.getElementById("fakePassword").style.display = "none";
	document.getElementById("realPassword").style.display = "block";
	if (bFocus) {
		document.getElementById("realPassword").focus();
		document.forms[0].ctl00$ctl00$LoginView2$Login1$Password.focus();
	}
}

function usernameBoxClicked(objBox) {
	if (objBox.value == "username") {
		objBox.value = "";
	}
}

var closeBox;
var timeOut = 150;

function showLoginBox() {
	document.getElementById("popupLoginForm").style.display = "block";
}

function hideLoginBox() {
	//document.getElementById("popupLoginForm").style.display = "none";
}

function stopHideLoginBox() {
	clearTimeout(closeBox);
}

function reHideLoginBox() {
	closeBox = setTimeout("hideLoginBox()", timeOut);
}

function doSearch() {
	sSearch = document.getElementById("q").value;
	if (sSearch != "") {
		document.location = "http://www.google.com/u/ECCA?q=" + sSearch;
	}
}

function showAllComments() {
	aComments = getElementsByClassName(document, "p", "comment");
	for (n=0; n<aComments.length; n++) {
		comment = aComments[n];
		comment.style.display = "block";
	}
}

function showGalleryImage(obj, iWidth, iHeight) {
	obj.blur();
	objGP = document.getElementById("galleryPopup");
	if (iWidth > 495) {
		iWidth = 495;
	}
	objGP.innerHTML = "<a href='javascript:hidePopup()' title='click to hide image'><img src='" + obj.href + "' width='" + iWidth + "' alt='click to hide image' /></a><p>" + obj.title + "<br /><br />[<a href='javascript:hidePopup()'>close</a>]</p>";
	objGP.style.display = "block";
}

function hidePopup() {
	document.getElementById("galleryPopup").style.display = "none";
}

// general functions

function fieldClicked(objBox, sDefault) {
	if (objBox.value == sDefault) {
		objBox.value = "";
	}
}

function showHide(sID) {
	if (document.getElementById(sID)) {
		if (document.getElementById(sID).style.display == "none") {
			document.getElementById(sID).style.display = "block";
		} else {
			document.getElementById(sID).style.display = "none"
		}
	}
}

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}