/*
Ensure we have the indexOf method for arrays.  This exists is JS5 by default
*/
if (!Array.prototype.indexOf)
{
	Array.prototype.indexOf = function(val, fromIndex, exact)
	{
		if (typeof(fromIndex) != 'number') fromIndex = 0;
		if (exact != true) exact = false;
		for (var index = fromIndex,len = this.length; index < len; index++)
			if (this[index] == val || (!exact && this[index].toLowerCase() == val.toLowerCase())) return index;
		return -1;
	}
}

/*
Global error handler to use within a try/catch
functionName	Name of function that caused the error
exceptionObject	Exception object caught by catch statement
*/
function g_errorHandler(functionName, exceptionObject) {
	try {
		if (exceptionObject == null)
			msg = "[Unknown exception]";
		else if (exceptionObject.message)
			msg = exceptionObject.message
		else
			msg = exceptionObject;
		
		if (functionName == null)
			functionName = "[Unknown function]";
	}
	catch (e) {
		functionName = "g_errorHandler";
		msg = e.message;
	}
	finally {					
		alert("Error: " + functionName + ": " + msg);
	}
}

/* global javascript function for displaying */
/* a message beside contribution links */
function g_contribInfoText(textToDisplay){
 	var IsCont = new Boolean(SSContributor);
    var myCont = IsCont.toString();
    if (myCont !="false")
    {
        document.write('<span class="contribInfoText">' + textToDisplay + '</span>');
    } 
}

/*
// Function : Popup Window
// Written By: Alex Suhre
// Comments : This function creates the popup window.  It takes parameters for
//		the width, height, window name, and a URL.
*/

function g_commonPopupWindow(width, height, windowName, myURL){
	try{
		window.open(myURL, windowName, 'scrollbars=1, resizable=1,width=' + width +'px,height=' + height + 'px');
	}
	catch (e) {
		alert("Error on popup: " + e);
	}

}

function g_findPagePos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showHideTechnologies()
{
	var caseStudyID = document.getElementById("caseStudyBox");
	var techLink = document.getElementById("showHideTech");
	
	if (caseStudyID.style.display == 'block')
	{
		caseStudyID.style.display = 'none';
		techLink.innerHTML = 'Show Technologies';
		techLink.style.borderStyle = 'outset';
	}
	else
	{
		caseStudyID.style.display = 'block';
		techLink.innerHTML = 'Hide Technologies';
	}
}
