
//  UTILITIES
// ......................................

var oEventUtil = new Object();

oEventUtil.addEvent = function(oTarget, sEventType, fHandler)
{
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fHandler);
	} else {
		oTarget["on" + sEventType] = fHandler;
	}
}

// BROWSER DETECTION
var IEX = (document.all) ? 1 : 0;
var N4 = (document.layers) ? 1 : 0;
var N6 = (document.getElementById && !document.all) ? 1 : 0;
var oldIE = (document.all && !document.getElementById) ? 1 : 0;


// FIND CURRENT YEAR FOR COPYRIGHT NOTICE
var today = new Date();
var thisYear = today.getFullYear();


// PLATFORM DETECTION
var MAC = (navigator.userAgent.indexOf("Mac") != -1) ? true : false;


// IMAGE PRELOADING AND SWAPING SCRIPTS
function swapImage () { // (ImgId, NewImgName)
	var args = swapImage.arguments;
	for (i=0; i<args.length; i=i+2) {
		document[args[i]].src = eval(args[i+1] + ".src");
	}
}

function createImage(imgRef) {
	img = new Image();
	img.src = imgRef;
	return img;
}		
 

// FIND OBJECT'S DOM REFERENCE
function findDomObjRef (objectId, withStyle) {
	var addStyle = (withStyle == 1) ? '.style' : ''
	if (IEX) return "document.all." + objectId + addStyle
	if (N4) return "document." + objectId
	if (N6) return "document.getElementById('" + objectId + "')" + addStyle
}


// OPEN NEW CENTERED WINDOW
function openWindow (url, windName, width, height) {
	var myWindow;
	var left = parseInt((screen.availWidth/2) - (width/2));
	var top = parseInt((screen.availHeight/2) - (height/2));
	var windowFeatures = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",screenX=" + left + ",screenY=" + top;
	myWindow = window.open(url, windName, windowFeatures); 
	myWindow.focus();
}


// CONFIRM DELETION CALL
function confirmDelete (url) {
    var msg = "Are you sure you want \nto delete this item?";
    if(confirm(msg)) { location.href = url; }
}


// FILTER REDIRECT
function filterRedirect(url){
    location.href=url;
}


// POSITIONING THE SIDEBAR IMAGE
function positSideImg(){
    var imgRef = findDomObjRef("sideBarImg", 1);
    var units = (typeof imgRef.left == "string") ? "px" : 0;
    var srcElemRight = parseInt(getObjDimension("midSecMid", "right"));
    var srcElemBottom = parseInt(getObjDimension("midSecMid", "bottom"));
    imgRef.left = srcElemRight - 229 + units;
    imgRef.top = srcElemBottom - 203 + units;
    showHideLayer("sideBarImg", 1);
}


// CREATE AN EMAIL LINK ON THE FLY (IN ORDER TO AVOID SPAM SPIDERS)
function createEmailLink( pEmailName, pDomainName ) {
    var sEmailLink = "mailto:" + pEmailName + "@" + pDomainName + ".com";
    location.href = sEmailLink;
}


// RANDOM BANNER IMAGE GENERATION
// ......................................

var bannerImgArray = new Array();
bannerImgArray[0] = "http://www.e-arc.com/_imgs/banner/bridge.jpg";
bannerImgArray[1] = "http://www.e-arc.com/_imgs/banner/building.jpg";
bannerImgArray[2] = "http://www.e-arc.com/_imgs/banner/columns.jpg";
bannerImgArray[3] = "http://www.e-arc.com/_imgs/banner/house.jpg";
bannerImgArray[4] = "http://www.e-arc.com/_imgs/banner/sailboats.jpg";

var randomNum = Math.floor((Math.random() * bannerImgArray.length));



//  MENU SCRIPTS
// ......................................

// MENU ARRAYS
if(!N4){
    var menus = []

    menus[0] = []
    menus[0][0] = ["aboutMenu", "170"] // menu id, menu width in pixels
    menus[0][1] = ["Overview", "http://www.e-arc.com/about/index.php"]
    menus[0][2] = ["Products and Services", "http://www.e-arc.com/about/services.php"]
    menus[0][3] = ["Premier Accounts", "http://www.e-arc.com/premier/index.php"]
    menus[0][4] = ["Who We Serve", "http://www.e-arc.com/about/who.we.serve.php"]
    menus[0][5] = ["Technology", "http://www.e-arc.com/about/technology.php"]
    menus[0][6] = ["Management Profiles", "http://www.e-arc.com/about/team.php"]

    menus[1] = []
    menus[1][0] = ["premierAccnts", "170"] // menu id, menu width in pixels
    menus[1][1] = ["Overview", "http://www.e-arc.com/premier/index.php"]
    menus[1][2] = ["On-site Services", "http://www.e-arc.com/premier/onsite.services.php"]
    menus[1][3] = ["Technology", "http://www.e-arc.com/premier/technology.php"]
    menus[1][4] = ["Contacts", "http://www.e-arc.com/premier/contacts.php"]

    menus[2] = []
    menus[2][0] = ["irMenu", "170"] // menu id, menu width in pixels
    menus[2][1] = ["Overview", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-irhome"]
    menus[2][2] = ["News Releases", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-news"]
    menus[2][3] = ["Stock Information ", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-stockchart"]
    menus[2][4] = ["SEC Filings", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-sec"]
    menus[2][5] = ["Management Profiles", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-govManage"]
    menus[2][6] = ["Board of Directors", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-govBoard"]
    menus[2][7] = ["Corporate Governance", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-govHighlights"]
    menus[2][8] = ["Calendar of Events", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-calendar"]
    menus[2][9] = ["E-mail Alerts", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-alerts"]
    menus[2][10] = ["Info Request", "http://ir.e-arc.com/phoenix.zhtml?c=184915&amp;p=irol-infoReq"]
}

/*
    menus[2] = []
    menus[2][0] = ["irMenu", "170"] // menu id, menu width in pixels
    menus[2][1] = ["Overview", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-irhome"]
    menus[2][2] = ["News Releases", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-news"]
    menus[2][3] = ["Stock Information ", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-stockchart"]
    menus[2][4] = ["SEC Filings", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-sec"]
    menus[2][5] = ["Management Profiles", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-govManage"]
    menus[2][6] = ["Board of Directors", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-govBoard"]
    menus[2][7] = ["Corporate Governance", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-govHighlights"]
    menus[2][8] = ["Calendar of Events", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-calendar"]
    menus[2][9] = ["E-mail Alerts", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-alerts"]
    menus[2][10] = ["Info Request", "http://phx.corporate-ir.net/phoenix.zhtml?c=184915&amp;p=irol-infoReq"]
*/

// WRITE MENUS
if(!N4){
    for (i=0; i<menus.length; i++) {
    	var menuHTML = 	'<div id="' + menus[i][0][0] + 'Container" '
    	    menuHTML +=	'style="position:absolute; overflow:hidden; visibility:hidden; padding: 4px 0px 0px 0px; text-align: left; width:' + menus[i][0][1] + 'px; background: transparent;" '

    		menuHTML += 'onmouseover = "showMenu(this.id);'
    		for (k=2; k<menus[i][0].length; k++) {
    		menuHTML += 'showMenu(\'' + menus[i][0][k] + 'Container\'); '
    		}
    		menuHTML += '" onmouseout = "hideTimeout(this.id);'
    		for (l=2; l<menus[i][0].length; l++) {
    		menuHTML += 'hideTimeout(\'' + menus[i][0][l] + 'Container\'); '
    		}
    		menuHTML += '"'

    		menuHTML +=	'<div id="' + menus[i][0][0] + 'Content" '
    		menuHTML +=	' style="padding: 3px 0px 0px 0px; background: transparent; "><div style="border: 1px solid #B1B1B1; ">'
    		
    	for (j=1; j<menus[i].length; j++) {
    		if (menus[i][j][2] == null) {
    		
    		menuHTML += '<div class="menuItem" id="' + menus[i][0][0] + 'Item' + j + '">'
    		menuHTML += '<a href="' + menus[i][j][1] + '" hideFocus="true"><span style="color:#999;font-size:10px">»</span> &nbsp;'
    		menuHTML +=  menus[i][j][0]
    		menuHTML += '</a>'
    		menuHTML += '</div>'
    		
    		} else {
    		
    		menuHTML += '<div class="menuItem" id="' + menus[i][0][0] + 'Item' + j + '" '
    		menuHTML += 'onmouseover="showMenu(\'' + menus[i][j][2] + 'Container\', this.id, \'rightTop\')" '
    		menuHTML += 'onmouseout="hideTimeout(\'' + menus[i][j][2] + 'Container\')">'
    		menuHTML += '<a href="../../web-content/site/scripts/' + menus[i][j][1] + '" hideFocus="true"><span style="color:#999;font-size:10px">»</span>  '
    		menuHTML +=  menus[i][j][0]
    		menuHTML += '</a>'
    		menuHTML += '</div>'
    		}
    	}

    		menuHTML += '</div></div></div>'
    	
    	document.write(menuHTML);
    	
    	// create a unique timeout variable for each menu, and set to false
    	eval("var " + menus[i][0][0] + "ContainerTimeout = false")
    }
}


// PLATFORM DETECTION
var MAC = (navigator.userAgent.indexOf("Mac") != -1) ? 1 : 0;


// FIND OBJECT'S DOM REFERENCE
function findDomObjRef (objectId, withStyle) {
	var addStyle = (withStyle == 1) ? '.style' : '';
	if (addStyle == "") {
		if (oldIE) return document.all[objectId];
		else return document.getElementById(objectId);
	} else {
		if (oldIE) return document.all[objectId].style;
		else return document.getElementById(objectId).style;
	}	
}


// SHOWING AND HIDING LAYERS
function showHideLayer (layerId, showHide) {
	var layerRef = findDomObjRef(layerId, 1);
	var showHideVar = (showHide == 0) ? "hidden" : "visible"; 
	layerRef.visibility = showHideVar;
}


// GET INLINE, NONPOSITIONED ELEMENT'S POSITION ON PAGE
function getElementPosition(elemId) {
	// Auth: Danny Goodman - JavaScript & DHTML Cookbook
	var offsetTrail =   findDomObjRef(elemId); //  document.getElementById(elemId)  document.all[elemId]
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (MAC && typeof document.body.leftMargin != "undefined") {
		offsetLeft += document.body.LeftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft, top:offsetTop};
}

function getObjDimension (objectId, dimParam) {
	var objRef = findDomObjRef(objectId);
	var obj = getElementPosition(objectId);	

	switch (dimParam) {
		case "top" :
			return obj.top;
			break
		case "left" :
			return obj.left;
			break	
		case "width" :
			return objRef.offsetWidth;
			break
		case "height" :
			return objRef.offsetHeight;
			break
		case "right" :
			return obj.left + objRef.offsetWidth;
			break
		case "bottom" :
			return obj.top + objRef.offsetHeight;
			break
	}
}

function showMenu (menuID, srcElemID, pos) {
	if (!menuID) menuID = this.id;
	timeoutRef = eval(menuID + "Timeout");
	
	if (timeoutRef) { 
		window.clearTimeout(timeoutRef);
		timeoutRef = false;
	}
	
	if (srcElemID) {
		var srcElemTop = parseInt(getObjDimension(srcElemID, "top"));
		var srcElemBottom = parseInt(getObjDimension(srcElemID, "bottom"));
		var srcElemLeft = parseInt(getObjDimension(srcElemID, "left"));
		var srcElemRight = parseInt(getObjDimension(srcElemID, "right"));
		var srcElemHeight = parseInt(getObjDimension(srcElemID, "height"));
		var srcElemWidth = parseInt(getObjDimension(srcElemID, "width"));
		
		if (!pos) pos = "bottomLeft"
		switch (pos) {
			case "bottomLeft":
				var menuTop = srcElemBottom;
				var menuLeft = srcElemLeft;
				break
			case "bottomRight":
				var menuTop = srcElemBottom;
				var menuLeft = srcElemRight - srcElemWidth;  
				break
			case "rightTop":
				var menuTop = srcElemTop
				var menuLeft = srcElemRight 
				break
			case "rightBottom":
				var menuTop = srcElemBottom - srcElemHeight;
				var menuLeft = srcElemRight;
				break
			case "topLeft":
				var menuTop = srcElemTop - srcElemHeight; 
				var menuLeft = srcElemLeft;
				break
			case "topRight":
				var menuTop = srcElemTop - srcElemHeight;
				var menuLeft = srcElemRight - srcElemWidth;
				break
			case "leftTop":
				var menuLeft = srcElemLeft - srcElemWidth;
				var menuTop = srcElemTop;
				break
			case "leftBottom":
				var menuLeft = srcElemLeft - srcElemWidth;
				var menuTop = srcElemBottom - srcElemHeight;
				break
		}
		
		var menuRef = findDomObjRef(menuID, 1);
		var units = (typeof menuRef.left == "string") ? "px" : 0;
		menuRef.left = menuLeft + units;
		menuRef.top = menuTop + units;
		showHideLayer (menuID, 1);
	}
}

function hideTimeout (menuID) {
	if (!menuID) menuID = this.id;
	timerId = menuID + "Timeout";
	hideFunction = "hideMenu('" + menuID + "')";
	eval("window." + timerId + "= setTimeout(hideFunction, 20)");
}

function hideMenu (menuID) {
	showHideLayer (menuID, 0);
	
	var menuRef = findDomObjRef (menuID, 1);
	menuRef.left = -1000;
	menuRef.top = -1000;
}



// DYNAMIC DEPENDENT LIST MENU SCRIPTS
/*
 * @arg formId = the id of the form containing the dynamic dep. lists
 * @arg listValue = the value of the selected option in the list menu calling the function
 * @arg listId = the id of the current select list calling the function
 * @arg subcatListId = the id of the dependent subcategory list
 * @arg subcatDependentListId (optional) = the id of the subcategory's dependent list menu
 * @arg noSelectionTxt (optional) = the text that appears in the sub menu when no selection is made
 * @arg noOptionTxt (optional) = the text that appears in the sub menu when no selections are available
 */
function dynDepList( formId, listValue, listId, subcatListId, subcatDependentListId, noSelectionTxt, noOptionTxt ) {
	var formRef = document.forms[formId];
	var catListRef = formRef.elements[listId];
	var subcatListRef = formRef.elements[subcatListId];

    if(!noSelectionTxt) var noSelectionTxt = '* select a state first';
    if(!noOptionTxt) var noOptionTxt = '* no locations in this state';


	if (subcatDependentListId)
		var subcatDependentListRef = formRef.elements[subcatDependentListId];

 // if the category menu selected index is greater than 1
	if (catListRef.selectedIndex > 1) {

		var subMenArrayRef = eval(listValue);

	 // if the submenu array has a length greater than 0
		if (subMenArrayRef.length > 0) {
			subcatListRef.disabled = false;

		 // fill the subcat menu with the array elements
			for (i=0; i<subMenArrayRef.length; i++) {
				var id = i+1;

				if (i < 1) {
				 // clear out the current menu options and add "- choose one -" as first option
					subcatListRef.length = 0;
					subcatListRef.options[0] = new Option('- choose one -', '');
					subcatListRef.options[1] = new Option('- - - - - - - - - - - - - - - - - - - - -', '');
				} 

				subcatListRef.options[++id] = 
					new Option(subMenArrayRef[i].name, subMenArrayRef[i].value);

				// new key to allow a selection in the dependent list
				if (subMenArrayRef[i].selected)
					subcatListRef.options[id].selected = true; 

			} // end for loop
			
		} else { clearSubcatList( subcatListRef, noOptionTxt ); }
		
	} else { // if caListRef.selectedIndex is not greater than 1
		clearSubcatList( subcatListRef, noSelectionTxt );
		
	 // if the list's subcategory list has a dependent list identified in the function call
		if(subcatDependentListId) {
			clearSubcatList( subcatDependentListRef, noSelectionTxt );
		}
	}
} // end dynDepList function


function dynDepListStateProvince( formId, listValue, listId, subcatListId, chooseOne ) {
    var formRef = document.forms[formId];
    var catListRef = formRef.elements[listId];
    var subcatListRef = formRef.elements[subcatListId];
    var subMenArrayRef = eval(listValue);

 // fill the subcat menu with the array elements
    for (i=0; i<subMenArrayRef.length; i++) {
        var id = i+1;

        if (i < 1) {
         // clear out the current menu options and add "- choose one -" as first option
            subcatListRef.length = 0;
            subcatListRef.options[0] = new Option(chooseOne, '');
            subcatListRef.options[1] = new Option('- - - - - - - - - - - - - - - - - - - - -', '');
        }

        subcatListRef.options[++id] =
            new Option(subMenArrayRef[i].name, subMenArrayRef[i].value);

        // new key to allow a selection in the dependent list
        if (subMenArrayRef[i].selected)
            subcatListRef.options[id].selected = true;

    } // end for loop


} // end dynDepList function


function clearSubcatList( subcatListRef, optionText ) {
	subcatListRef.options.length = 0;
	subcatListRef.options[0] = new Option( optionText, "");
	subcatListRef.disabled = true;
}