// ---- BEGIN BROWSER DETECTION FUNCTIONS ----

var isIE4 = (document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;

function GetViewableBrowserDimension(dimension)
{
    var bWidth = 0, bHeight = 0;
    
    if(typeof(window.innerWidth) == 'number')
    {
        //Non-IE
        bWidth = window.innerWidth;
        bHeight = window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    {
        //IE 6+ in 'standards compliant mode'
        bWidth = document.documentElement.clientWidth;
        bHeight = document.documentElement.clientHeight;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight))
    {
        //IE 4 compatible
        bWidth = document.body.clientWidth;
        bHeight = document.body.clientHeight;
    }
    else
    {
        bWidth = document.offsetWidth;
        bHeight = document.offsetHeight;
    }
    
    if(dimension.toLowerCase() == 'w')
    {
        return bWidth;
    }
    else if(dimension.toLowerCase() == 'h')
    {
        return bHeight;
    }
}

function GetViewableBrowserWidth()
{
    return GetViewableBrowserDimension('w');
}

function GetViewableBrowserHeight()
{
    return GetViewableBrowserDimension('h');
}

function GetScrollPosition(scrollType)
{
    var vXOffset;
    var vYOffset;
 
     if(typeof(window.pageXOffset) == 'number')
    {
        //Non-IE
        vXOffset = window.pageXOffset;
        vYOffset = window.pageYOffset;
    }
    else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
    {
        //IE 6+ in 'standards compliant mode'
        vXOffset = document.documentElement.scrollLeft;
        vYOffset = document.documentElement.scrollTop;
    }
    else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
    {
        //IE 4 compatible
        vXOffset = document.body.scrollLeft;
        vYOffset = document.body.scrollTop;
    }
    
    if(scrollType.toLowerCase() == 'x')
    {
        return vXOffset;
    }
    else if(scrollType.toLowerCase() == 'y')
    {
        return vYOffset;
    }
}

function GetScrollPositionWidth()
{
    return GetScrollPosition('x');
}

function GetScrollPositionHeight()
{
    return GetScrollPosition('y');
}

// ---- END BROWSER DETECTION FUNCTIONS ----

// ---- BEGIN POPUP WINDOW FUNCTIONS ----

function OpenPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=0,scrollbars=0");
	remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenBarlessScrollingPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=yes");
	remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

function OpenBarlessPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=0,status=0,menubar=0,scrollbars=0");
	remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();
}

function OpenScrollingPopup(URL, width, height) {
	window.self.name = "main";
	//var now = new Date();
	//var remote = window.open(URL, "popup" + now.getTime(), "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
	var remote = window.open(URL, "popup", "width=" + width + ",height=" + height + ",toolbar=0,location=0,directories=0,resizable=1,status=1,menubar=1,scrollbars=yes");
	remote.resizeTo(parseInt(width)+2,parseInt(height)+35);
	remote.focus();	
}

// ---- END POPUP WINDOW FUNCTIONS ----

// ---- BEGIN DHTML DISPLAY FUNCTIONS ----

function ToggleDivDisplay(div)
{
    if(document.getElementById(div).style.display == 'none')
    {
        document.getElementById(div).style.display = 'block';
    }
    else
    {
        document.getElementById(div).style.display = 'none';
    }
}
function CenterLayerPosition(divLayer)
{
    var elem = document.getElementById(divLayer);
    var scrollX = parseInt(GetViewableBrowserWidth());
    var scrollY = parseInt(GetViewableBrowserHeight());
    
    elem.style.left = ((scrollX/2) - (parseInt(elem.style.width)/2)) + 'px';
    elem.style.top = ((scrollY/2) + (parseInt(elem.style.height)/2) + GetScrollPositionHeight() - 120) + 'px';
    elem = null;
}

// ---- END DHTML DISPLAY FUNCTIONS ----

// ---- BEGIN NAVIGATION ROLLOVER FUNCTIONS ----
function hideNavMenu(lay) {
	if (isIE4) {document.all[lay].style.visibility = "hidden";}
	if (isNS4) {document.layers[lay].visibility = "hide";}
	if (isDOM) {document.getElementById([lay]).style.visibility = "hidden";}
}

function showNavMenu(lay) {
	var i;

	if('nav0menu' != lay)
	{
		if((lay.charAt(0) == 'n') && (lay.charAt(lay.length - 1) == 'u')) {
			for(i = 1; i < 9; i++) {
				if(('nav' + i + 'menu') == lay) {
					//alert('nav' + i + 'menu is on');
					if (isIE4) {document.all[lay].style.visibility = "visible";}
					if (isNS4) {document.layers[lay].visibility = "show";}
					if (isDOM) {document.getElementById([lay]).style.visibility = "visible";}
				}
				else {
					//alert('nav' + i + 'menu is off');
					if (isIE4) {document.all['nav' + i + 'menu'].style.visibility = "hidden";}
					if (isNS4) {document.layers['nav' + i + 'menu'].visibility = "hide";}
					if (isDOM) {document.getElementById(['nav' + i + 'menu']).style.visibility = "hidden";}		
				}
			}
		}
		else {
				if (isIE4) {document.all[lay].style.visibility = "visible";}
				if (isNS4) {document.layers[lay].visibility = "show";}
				if (isDOM) {document.getElementById([lay]).style.visibility = "visible";}
		}
	}
	else
	{
		for(i = 1; i < 20; i++) {
			if (isIE4 && document.all['nav' + i + 'menu'] != null) {document.all['nav' + i + 'menu'].style.visibility = "hidden";}
			if (isNS4 && document.layers['nav' + i + 'menu'] != null) {document.layers['nav' + i + 'menu'].visibility = "hide";}
			if (isDOM && document.getElementById(['nav' + i + 'menu']) != null) {document.getElementById(['nav' + i + 'menu']).style.visibility = "hidden";}
		}
	}
}
function showNavLayerMenu(lay,intLayCount) {
	var i;
	var intNavCount;
	intNavCount = parseInt(intLayCount) + 1;

	if((lay.charAt(0) == 'n') && (lay.charAt(lay.length - 1) == 'u')) {
		for(i = 1; i < intNavCount; i++) {
			if(('nav' + i + 'menu') == lay) {
				//alert('nav' + i + 'menu is on');
				if (isIE4) {document.all[lay].style.visibility = "visible";}
				if (isNS4) {document.layers[lay].visibility = "show";}
				if (isDOM) {document.getElementById([lay]).style.visibility = "visible";}
			}
			else {
				//alert('nav' + i + 'menu is off');
				if (isIE4) {document.all['nav' + i + 'menu'].style.visibility = "hidden";}
				if (isNS4) {document.layers['nav' + i + 'menu'].visibility = "hide";}
				if (isDOM) {document.getElementById(['nav' + i + 'menu']).style.visibility = "hidden";}		
			}
		}
	}
	else {
			if (isIE4) {document.all[lay].style.visibility = "visible";}
			if (isNS4) {document.layers[lay].visibility = "show";}
			if (isDOM) {document.getElementById([lay]).style.visibility = "visible";}
	}
}
// ---- END NAVIGATION ROLLOVER FUNCTIONS ----

// ---- BEGIN OFFICE FINDER REDIRECT FUNCTION ----

function RedirectOffice(strAppPath,frmValue)
{
	//alert(frm);

	if(frmValue != "")
	{
		var arrData = frmValue.split("|");
		var strLocale = arrData[2].replace(' ', '+');
		strLocale.replace('&aacute;','%E1');
		strLocale.replace('&oacute;','%F3');
		
		if(arrData[1] == "C")
		{
			//alert(strAppPath + "/about+us/office+finder/officeresults.htm?zone=" + arrData[0] + "&city=" + strLocale);
			window.location.href = strAppPath + "/about+us/office+finder/officeresults.htm?zone=" + arrData[0] + "&city=" + strLocale;
		}
		else if(arrData[1] == "A")
		{
			//alert(strAppPath + "/about+us/office+finder/officeresults.htm?zone=" + arrData[0] + "&area=" + strLocale);
			window.location.href = strAppPath + "/about+us/office+finder/officeresults.htm?zone=" + arrData[0] + "&area=" + strLocale;
		}
	}		
}

function SelectRedirect(frmValue)
{
	if(frmValue != '')
	{
		window.location.href = frmValue;
	}
}

// ---- END OFFICE FINDER REDIRECT FUNCTION ----

// ---- BEGIN CLEAR DROP MENU FUNCTION ----

function ClearDropMenu(menu) {
	document.getElementById(menu).selectedIndex = 0;
}

// ---- END CLEAR DROP MENU FUNCTION ----

// ---- BEGIN FORM RELATED FUNCTIONS ----

function SetFocus(frmInput)
{
    if(document.frmPage != null)
    {
        document.frmPage[frmInput].focus();
    }
    else
    {
        document.aspnetForm[frmInput].focus();
    }
}

// ---- END FORM RELATED FUNCTIONS ----

//---- BEGIN OBJECT ACTIVATION FIX ----
// EOLAS won a lawsuit vs. Microsoft.  Apparently EOLAS patented the ability to load an Active X control
// in the browser with the ability to interact with it immediately without pressing "ok".
// http://www.eweek.com/article2/0,1895,1865104,00.asp - Eolas Wins Round vs. MS in Browser Patent Fight
// http://www.eweek.com/article2/0,1895,1895907,00.asp - Microsoft Bows to Eolas, Revamps IE's Multimedia Handling

// ClsDisplay.DrawFlashImage(); calls this Javascript function of the same name to load flash movies

//function DrawFlashImage(divID,objID,strURL,intWidth,intHeight,intCX,intCY,autoStart)
//{
//	var d = document.getElementById(divID);
//	
//	d.innerHTML = '' +
//		'<object id=\"' + objID + '\" codeBase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" height=\"' + intHeight + '\" width=\"' + intWidth + '\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" VIEWASTEXT>\n' +
//		'	<param name=\"_cx\" value=\"' + intCX + '\" >\n' +
//		'	<param name=\"_cy\" value=\"' + intCY + '\" >\n' +
//		'	<param name=\"FlashVars\" value=\"\" >\n' +
//		'	<param name=\"Movie\" value=\"' + strURL + '\" >\n' +
//		'	<param name=\"Src\" value=\"' + strURL + '\" >\n' +
//		'	<param name=\"WMode\" value=\"Window\" >\n' +
//		'	<param name=\"Play\" value=\"-1\" >\n' +
//		'	<param name=\"Loop\" value=\"-1\" >\n' +
//		'	<param name=\"Quality\" value=\"High\" >\n' +
//		'	<param name=\"SAlign\" value=\"\" >\n' +
//		'	<param name=\"Menu\" value=\"-1\" >\n' +
//		'	<param name=\"Base\" value=\"\" >\n' +
//		'	<param name=\"AllowScriptAccess\" value=\"always\" >\n' +
//		'	<param name=\"Scale\" value=\"ShowAll\" >\n' +
//		'	<param name=\"DeviceFont\" value=\"0\" >\n' +
//		'	<param name=\"EmbedMovie\" value=\"0\" >\n' +
//		'	<param name=\"BGColor\" value=\"\" >\n' +
//		'	<param name=\"SWRemote\" value=\"\" >\n' +
//		'	<param name=\"MovieData\" value=\"\" >\n' +
//		'	<param name=\"SeamlessTabbing\" value=\"1\" >\n' +
//		'	<param name=\"autoStart\" value=\"' + autoStart + '\" >\n' +
//		'	<embed src=\"' + strURL + '\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"' + intWidth + '\" height=\"' + intHeight + '\"></embed>\n' +
//		'</object>\n';
//}

//---- END OBJECT ACTIVATION FIX ----

//---- BEGIN FLASH DETECTION KIT ----

//Legacy Function
function SWFObject(strURL, strName, intWidth, intHeight, intVersion, strBGColor)
{
	DrawFlashImage(strURL,strName,intWidth,intHeight,strBGColor);
}

function DrawFlashImage(strURL, strName, intWidth, intHeight, strBGColor)
{
	//**Global Vars**

	//- Major version of Flash required
	var requiredMajorVersion = 8;

	//- Minor version of Flash required
	var requiredMinorVersion = 0;

	//- Minor revision of Flash required
	var requiredRevision = 0;

	//- Version check based upon the values entered in "Global Vars"
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	//- Check to see if the version meets the requirements for playback
	if(hasRequestedVersion)
	{
		// embed the Flash content SWF when all tests are passed
		AC_FL_RunContent(
			"src", strURL,
			"width", intWidth,
			"height", intHeight,
			"align", "middle",
			"id", strName,
			"quality", "high",
			"bgcolor", strBGColor,
			"name", strName,
			"allowScriptAccess", "sameDomain",
			"WMode", "transparent",
			"type", "application/x-shockwave-flash",
			"codebase", "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	}
	else
	{
		//flash is too old or we can't detect the plugin
		var alternateContent = '<p>Adobe Flash Player was not detected on your system.  Please update or download now.</p>' +
							'<p><a href=\"http://www.adobe.com/go/getflash/\">Get Flash</a>';
							
		document.write(alternateContent);
	}
}
//---- END FLASH DETECTION KIT ----


//---- BEGIN BRIGHTCOVE FUNCTIONS ----

function DrawBrightCove(strWidth, strHeight, strPlayerID, strPublisherID, strVideoPlayer)
{
    var strOutput = "";
    
    strOutput = "<div align=\"center\">\n" +
        "<scr" + "ipt language=\"JavaScript\" type=\"text/javascript\" src=\"http://admin.brightcove.com/js/BrightcoveExperiences.js\">" + "</scr" + "ipt>" + 
        "<object id=\"myExperience\" class=\"BrightcoveExperience\">\n" +
        "   <param name=\"bgcolor\" value=\"#FFFFFF\">\n" +
        "   <param name=\"width\" value=\"" + strWidth + "\">\n" +
        "   <param name=\"height\" value=\"" + strHeight + "\">\n" +
        "   <param name=\"playerID\" value=\"" + strPlayerID + "\">\n" +
        "   <param name=\"publisherID\" value=\"" + strPublisherID + "\">\n" +
        "   <param name=\"isVid\" value=\"true\">\n" +
        "   <param name=\"isUI\" value=\"false\">\n" +
        "   <param name=\"@videoPlayer\" value=\"" + strVideoPlayer + "\">\n" +
        "</object>\n" +
        "</div>\n"; 
    
    document.write(strOutput);    
}

//---- END BRIGHTCOVE FUNCTIONS ----