﻿// 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(){
	// Performs WebAttache load methods (automatic include)
	_waLoad();

	// 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;
			}
		}
	}
	
	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 showRealPasswordBox(bFocus) 
{
	document.getElementById("fakePassword").style.display = "none";
	document.getElementById("realPassword").style.display = "inline";
	if (bFocus) 
	{
		document.getElementById("realPassword").focus();
		document.forms[0].ctl00$ctl00$LoginView2$Login1$Password.focus();
	}
}

function usernameBoxClicked(objBox) 
{
	if (objBox.value == "username") 
	{
		objBox.value = "";
	}
}

function doSearch() 
{
	//document.location = sURL + "?q=" + document.getElementById("searchBox").value;
	document.location = "http://www.google.com/cse?cx=011084494591359026171:syt4lkplrxg&q=" + document.getElementById("searchBox").value;
}

function doAdvancedSearch() 
{
	if (document.getElementById("searchArea").value != "") 
	{
	document.location = "http://www.google.com/cse?cx=011084494591359026171:syt4lkplrxg&q=" + document.getElementById("searchBoxAdvanced").value + " AND " + document.getElementById("searchArea").value;
	}
	else
	{
	document.location = "http://www.google.com/cse?cx=011084494591359026171:syt4lkplrxg&q=" + document.getElementById("searchBoxAdvanced").value;
	}
}

function goArea() 
{
	if (document.getElementById("workSelect")) 
	{
		sURL = document.getElementById("workSelect").value;
		if (sURL != "") 
		{
			document.location = sURL;
		}
	}
}

function goRegion() 
{
	if (document.getElementById("ctl00_ctl00_ContentPlaceHolder_regionSelect")) 
	{
		sURL = document.getElementById("ctl00_ctl00_ContentPlaceHolder_regionSelect").value;
		if (sURL != "") 
		{
			document.location = sURL;
		}
	}
}

function findByArea(sURL) 
{
	if (document.getElementById("findByArea")) 
	{
		sArea = document.getElementById("findByArea").value;
		if (sArea != "") 
		{
			document.location = sURL + "?area=" + sArea;
		}
	}
}

function findByCategory(sURL) 
{
	if (document.getElementById("findByCategory")) 
	{
		sCategory = document.getElementById("findByCategory").value;
		if (sCategory != "") 
		{
			document.location = sURL + "?category=" + sCategory;
		}
	}
}

// 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;
	}
}