

function swapJobs(locale)
{
    var prefix = 'ctl00_ContentPlaceHolderMain_';
    if (locale == 'local')
    {
        showElement(document.getElementById(prefix + 'localJobsHeader'));
        showElement(document.getElementById(prefix + 'localJobTableBody'));
        
        hideElement(document.getElementById(prefix + 'wwJobsHeader'));
        hideElement(document.getElementById(prefix + 'wwJobTableBody'));
    }
    else
    {
        hideElement(document.getElementById(prefix + 'localJobsHeader'));
        hideElement(document.getElementById(prefix + 'localJobTableBody'));
        
        showElement(document.getElementById(prefix + 'wwJobsHeader'));
        showElement(document.getElementById(prefix + 'wwJobTableBody'));
    }
}

function showElement(element)
{
    if (element)
    {
        element.style.display = '';
        element.style.visibility = 'visible';
    }
}

function hideElement(element)
{
    if (element)
    {
        element.style.display = 'none';
        element.style.visibility = 'hidden';
    }
}

setFocus = function(selectorID)
{
	document.getElementById(selectorID).select();
}

changeStyle = function(selectorID,selectorClass)
{
	if (document.getElementById(selectorID) != null)
	{
		document.getElementById(selectorID).className = selectorClass;
	}
}

rateIt = function(selectorClass)
{
	var selectorID = 'ratingMeter';
	{
		document.getElementById(selectorID).className = selectorClass; // selector class equals rating
	}
}

updateEmailContact = function()
{
	var optionGroup = document.getElementById("ddOfficeContact");	
	var optionValue = optionGroup.options[optionGroup.selectedIndex].value;
	var contactAddressContainer = $('contactEmailAddress');
	
	contactAddressContainer.innerHTML = '<a href="mailto:'+optionValue+'"'+'>'+optionValue+'</a>';
	$('contactAddress').style.display = 'block';
}

randomiseBrandTexturePodule = function()
{
	var className = "";
	var item = new Array();
	
	item[0] = "brand-texture-01";
	item[1] = "brand-texture-02";
	item[2] = "brand-texture-03";
	item[3] = "brand-texture-04";
	item[4] = "brand-texture-05";
	item[5] = "brand-texture-06";
	item[6] = "brand-texture-07";
	item[7] = "brand-texture-08";
	item[8] = "brand-texture-09";
	item[9] = "brand-texture-10";
	item[10] = "brand-texture-11";
	item[11] = "brand-texture-12";
	item[12] = "brand-texture-13";
	item[13] = "brand-texture-14";
	item[14] = "brand-texture-15";
	
	now = new Date();
	multiplicationHelper = now.getSeconds();
	
	randomItem = Math.round(Math.random(multiplicationHelper) * item.length);
	if (randomItem == item.length)
		{
			randomItem = 0
		}

	className = item[randomItem];
	changeStyle('brand-texture',className)
}

toggleLogin = function()
{
	new Effect.toggle('login','blind',
	{
		duration: 0.4
	});
}

removePodule = function(selectorID)
{
	new Effect.BlindUp(selectorID,
	{
		duration: 0.4
	});
}

toggleClientList = function()
{
	new Effect.toggle('client-list-complete','blind',
	{
		duration: 0.4
	});
	new Effect.toggle('client-list-partial','blind',
	{
		duration: 0.4
	});
}

stampTime = function()
{
	var clockContainer = document.getElementById('localTime');
	var clockTime = new Date();
	var clockHours = clockTime.getHours();
	var clockMinutes = clockTime.getMinutes();
	var clockSeconds = clockTime.getSeconds();
	var clockSuffix = "AM";
	if (clockHours > 11)
	{
		clockSuffix = "PM";
		clockHours = clockHours - 12;
	}
	if (clockHours == 0)
	{
		clockHours = 12;
	}
	if (clockHours < 10)
	{
		clockHours = "0" + clockHours;
	}
	if (clockMinutes < 10)
	{
		clockMinutes = "0" + clockMinutes;
	}
	if (clockSeconds < 10)
	{
		clockSeconds = "0" + clockSeconds;
	}
	clockContainer.innerHTML = clockHours + ":" + clockMinutes + " " + clockSuffix;
	setTimeout("stampTime()",1000);
}

// image preloading
var arrImgPreload = new Array();
imgPreload = function(strPath)
{
	var objImg = new Image();
	objImg.src = strPath;
	arrImgPreload.push(objImg);
}

// image swapping function
swapImage = function()
{
	// retrieve all anchors with the class name "swapImage" and iterate through them
	$$('a.swapImage').each(function(obj)
	{
		// preload images
		imgPreload(obj.href);
		// attach event handler
		obj.onclick = function()
		{
			// remove "current" classname from all links
			$$('a.swapImage').each(function(obj)
			{
				obj.removeClassName('current');
			});

			// add "current" classname to click link
			obj.addClassName('current');

			// retrieve target
			var objSelector = $('slideshow-target');

			// fade target
			new Effect.Fade(objSelector,
			{
				duration: 0.3,
				fps: 50,
				afterFinish: function()
				{
					// after fade, set target src
					objSelector.src = obj.href;

					// make target re-appear
					new Effect.Appear(objSelector,
					{
						delay: 0.0,
						duration: 0.3,
						fps: 50
					});
				}
			});		
		// return false to avoid following href
		return false;
		}
	});
}

// Handle table zebra striping
// ----------------------------------------------
stripetableBody = function()
{
	if (!document.getElementsByTagName) return false;
	var tableBody = document.getElementsByTagName("tbody");
	for (var i=0; i<tableBody.length; i++)
	{
		if (tableBody[i].getAttribute("class") == "alternateTableRows" || tableBody[i].getAttribute("className") == "alternateTableRows")
		{
		
			var odd = false;
			var rows = tableBody[i].getElementsByTagName("tr");
			for (var j=0; j<rows.length; j++)
			{
				if (odd == true)
				{
					addClass(rows[j],"alternate");
					odd = false;
      			}
				else
				{
					odd = true;
		  		}
			}
	  	}
		if (tableBody[i].getAttribute("class") == "altTableRows" || tableBody[i].getAttribute("className") == "altTableRows")
		{
		
			var odd = false;
			var rows = tableBody[i].getElementsByTagName("tr");
			for (var j=0; j<rows.length; j++)
			{
				if (odd == false)
				{
					addClass(rows[j],"alternate");
					odd = true;
      			}
				else
				{
					odd = false;
		  		}
			}
	  	}	  	
	}
}

// Add classes to selectors
// ----------------------------------------------
addClass = function(element,value)
{
	if (!element.className)
	{
    	element.className = value;
	}
	else
	{
    	newClassName = element.className;
	    newClassName+= " ";
	    newClassName+= value;
	    element.className = newClassName;
  	}
}

// Assist the behaviour and presentation of form elements
// ----------------------------------------------
scanForFormElements = function()
{
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("input");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if ((anchor.getAttribute("type") == "text") || (anchor.getAttribute("type") == "password"))
		{
			if (anchor.className!="noCSS")
			{
				addClass(anchor,'textfield');	
			}
		}
		if ((anchor.getAttribute("type") == "button") || (anchor.getAttribute("type") == "submit"))
		{
			if (anchor.className!="noCSS")
			{
				addClass(anchor,'button');
			}
		}
	}
}

findLabels = function()
{
	var el = document.getElementsByTagName("label");
	for (i=0;i<el.length;i++)
	{
		var thisId = el[i].getAttribute("for");
		if ((thisId)==null)
		{
			thisId = el[i].htmlFor;
		}
		if(thisId!="")
		{
			el[i].onmouseover = highlightRelationship;
		}
	}
}

highlightRelationship = function()
{
	var thisId = this.getAttribute("for");
	if ((thisId)==null)
	{
		thisId = this.aspxFor;
	}	
	if (document.getElementById(thisId).type=="text") document.getElementById(thisId).select();
	if (document.getElementById(thisId).type=="password") document.getElementById(thisId).select();
	if (document.getElementById(thisId).tagName=="textarea") document.getElementById(thisId).select();
}

// Handle the launching of new browser windows for offsite links as well as non-web files.
// ----------------------------------------------
scanForExternalLinks = function()
{
	if (!document.getElementsByTagName) return false;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		{
			anchor.href = "javascript:getOffsiteLink('"+anchor.getAttribute("href")+"');";
		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "nonWebDocument")
		{
			anchor.href = "javascript:getFile('"+anchor.getAttribute("href")+"');";
		}
		else if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "popup")
		{
			anchor.href = "javascript:getFile('"+anchor.getAttribute("href")+"');";
		}
	}
}

getOffsiteLink = function(href)
{
	attributes = 'scrollbars=auto,toolbar=yes,menubar=yes,status=yes,directories=no,location=yes,resizable=yes';
	newWindow = window.open(href,'',attributes);
	newWindow.focus();
}

getFile = function(href)
{
	attributes = 'scrollbars=auto,toolbar=no,menubar=no,status=no,directories=no,location=no,resizable=yes';
	newWindow = window.open(href,'',attributes);
	newWindow.focus();
}

// Code to work with page sizing and the presentation of modal windows
// ----------------------------------------------
Position.getPageSize = function()
{
	var xScroll, yScroll, scrollOffsetY;
	if (window.innerHeight && window.scrollMaxY)
	{  
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{	// all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{	// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	if (self.pageYOffset)
	{
		scrollOffsetY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{	 // Explorer 6 Strict
		scrollOffsetY = document.documentElement.scrollTop;
	}
	else if (document.body)
	{	// all other Explorers
		scrollOffsetY = document.body.scrollTop;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{	// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{	// other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	} 
	
	// for small pages with total height less then height of the viewport
	pageHeight = Math.max(windowHeight,yScroll);
	
	// for small pages with total width less then width of the viewport
	pageWidth = Math.max(windowWidth,xScroll);
	
	return {
		page:
		{
			width: pageWidth,height: pageHeight
		}, 
		window:
		{
			width: windowWidth,height: windowHeight
		},
		scroll:
		{
			top: scrollOffsetY
		}
	};
}

// Modal windows
// ----------------------------------------------
createOverlay = function()
{
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objBody.appendChild(objOverlay);
}

openModalWindow = function(selectorID)
{
	var overlayID = 'overlay';
	var v = Position.getPageSize();

	// Turn off scrollbars in the viewport as they render above the overlay //
	var tas = document.getElementsByTagName("textarea");
	for (var i = 0;i<tas.length;i++)
	{
		if (tas[i].className != "scrollOK")
		{
			tas[i].style.overflow = "hidden";
		}
	}
	if (BrowserDetect.browser=="Explorer")
		{
		var sels = document.getElementsByTagName("select");
		for (var s = 0;s<sels.length;s++)
			{
			sels[s].style.visibility = "hidden";
			}		
		}
	
	// Hide flash in the viewport as it interfers with the overlay //
	var flashObjects = (document.getElementsByTagName("object") || document.getElementsByTagName("embed"));
	for (var i = 0;i<flashObjects.length;i++)
	{
		if (flashObjects[i].className != "viewOK")
		{
			flashObjects[i].style.visibility = "hidden";
		}
	}
	
	// Show the overlay and modal window //

	document.getElementById(overlayID).style.height = v.page.height + "px";
	document.getElementById(selectorID).style.top = (v.scroll.top+((v.window.height/100)*10)) + "px";

	Effect.Appear(overlayID,
	{
		duration: 0.2,
		fps: 50,
		from: 0,
		to: 0.60,
		afterFinish:function()
		{
			Effect.Appear(selectorID,
			{
				delay: 0.2,
				duration: 0.5
			});
		}
	});
}

closeModalWindow = function(selectorID)
{
	var overlayID = 'overlay';
	Effect.Fade(selectorID,
	{
		duration: 0.4,
		fps: 50,
		afterFinish:function()
		{
			Effect.Fade(overlayID,
			{
				delay: 0.1,
				duration: 0.3,
				from: 0.60,
				to: 0.0,
				afterFinish:function()
				{
					if (BrowserDetect.browser=="Explorer")
					{
						var sels = document.getElementsByTagName("select");
						for (var s = 0;s<sels.length;s++)
						{
							sels[s].style.visibility = "visible";
						}		
					}
				}
			});
		}
	});
	
	// Turn scrollbars in the viewport back on //
	var tas = document.getElementsByTagName("textarea");
	for (var i = 0;i<tas.length;i++)
	{
		if (tas[i].className != "scrollOK")
		{
			tas[i].style.overflow = "auto";
			//setStyle('textarea','overflow','auto');
		}	
	}
	
	// Restore flash in the viewport //
	var flashObjects = (document.getElementsByTagName("object") || document.getElementsByTagName("embed"));
	for (var i = 0;i<flashObjects.length;i++)
	{
		flashObjects[i].style.visibility = "visible";
	}
}

// Browser detection
// ----------------------------------------------
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

// Attach functions to window onload
// ----------------------------------------------
Event.observe(window,'load',scanForFormElements);
Event.observe(window,'load',createOverlay);
Event.observe(window,'load',stripetableBody);
Event.observe(window,'load',randomiseBrandTexturePodule);