﻿// ---- BEGIN GLOBAL JS VARS ----

var isIE4 = (document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isDOM = (document.getElementById && !document.all) ? true : false;

// ---- END GLOBAL JS VARS ----

// ---- 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 TREE NAVIGATION FUNCTIONS ----

function ToggleTreeNode(nodeID)
{
    if(document.getElementById([nodeID]).style.display == "none")
    {
        document.getElementById([nodeID]).style.display = "block";
        document.getElementById(['ToggleImage_' + nodeID]).src = "/images/common/TreeNavMinus.gif";
    }
    else
    {
        document.getElementById([nodeID]).style.display = "none";
        document.getElementById(['ToggleImage_' + nodeID]).src = "/images/common/TreeNavPlus.gif";
    }
}

// ---- END TREE NAVIGATION FUNCTIONS ----

// ---- BEGIN NAVIGATION ROLLOVER FUNCTIONS ----
	
function turnOn(imgName)
{
	if (document.images)
	{
		imgOn = eval(imgName + "On.src");
		document[imgName].src = imgOn;
	}
}

function turnOff(imgName)
{
	if (document.images)
	{
		imgOff = eval(imgName + "Off.src");
		document[imgName].src = imgOff;
	}
}

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;
		}
	}		
}

// ---- 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)
{
    document.frmPage[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
// <^>(o^_^o)<^> - J.Chou 20060726

function EnableObjects()
{
	var arrObjects;
	var arrApplets;
	var arrEmbeds;
	
	arrObjects = document.getElementsByTagName("object");
	arrApplets = document.getElementsByTagName("applet");
	arrEmbeds = document.getElementsByTagName("embed");
	
	for(var i = 0; i < arrObjects.length; i++)
	{
        if(arrObjects[i].id.indexOf('NCPHRICH') >= 0) //Enable only for MCMS Placeholder Controls and Windows Media Player
	    {
	        arrObjects[i].outerHTML = arrObjects[i].outerHTML;
	    }
	}
	
	for(var j = 0; j < arrApplets.length; j++)
	{
		arrApplets[j].outerHTML = arrApplets[j].outerHTML;
	}
	
	for(var k = 0; k < arrEmbeds.length; k++)
	{
		arrEmbeds[k].outerHTML = arrEmbeds[k].outerHTML;
	}
}

//---- 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 WINDOWS MEDIA FUNCTIONS ----

function DrawWindowsMedia(strURL, strName, strWidth, strHeight)
{
    var strOutput = "";
    
    strOutput = "<div align=\"center\">\n" +
        "<object id=\"WM_" + strName + "\" Name=\"WM_" + strName + "\" classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6, 4, 5, 715\" height=\"" + strHeight + "\" width=\"" + strWidth + "\">\n" +
        "   <param name=\"filename\" value=\"" + strURL + "\">\n" +
        "   <param name=\"autostart\" value=\"true\">\n" +
        "   <param name=\"showcontrols\" value=\"true\">\n" +
        "   <param name=\"showtracker\" value=\"false\">\n" +
        "   <param name=\"autosize\" value=\"true\">\n" +
        "   <param name=\"showstatusbar\" value=\"true\">\n" +
        "   <param name=\"showdisplay\" value=\"false\">\n" +
        "   <embed type=\"application/x=mplayer2\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" id=\"WM_" + strName + "\" Name=\"WM_" + strName + "\" DisplaySize=\"4\" " +
        "autosize=\"1\" " +
        "bgcolor=\"darkblue\" " +
        "showcontrols=\"1\" " +
        "showtracker=\"0\" " +
        "showdisplay=\"0\" " +
        "showstatusbar=\"1\" " +
        "videoborder3d=\"1\" " +
        "width=\"" + strWidth + "\" " +
        "height=\"" + strHeight + "\" " +
        "SRC=\"" + strURL + "\" " +
        "autostart=\"1\" " +
        "designtimesp=\"5311\">\n" +
        "   </embed>\n" +
        "</object>\n" +
        "</div>\n"; 
    
    document.write(strOutput);    
}

//---- END WINDOWS MEDIA FUNCTIONS ----

function PopulateDomain(frm)
{
    var strDomain;
    strDomain = frm.NR_DOMAIN_LIST[frm.NR_DOMAIN_LIST.selectedIndex].value;
    frm.txtInsDomains.value = strDomain;
    frm.txtNTUser.focus();
}

function ShowPopUpDiv(headerHTML, innerHTML, width, height){
    var htmlText = "";
    var winObj = window.open('','newwin','width=' + width + ',height='+ height + '');
    
    htmlText += "<html><head>";
    htmlText += "<title>" + headerHTML + "</title>";
    htmlText += "<link href=\"/includes/css/Styles.css\" type=\"text/css\" rel=\"stylesheet\" />"
    htmlText += "</head><body style=\"margin:0px;padding:0px;\">";
    htmlText += "<div id=\"popUpDiv\" class=\"popDiv\">";
    htmlText += "   <div class=\"pHeader\">" + headerHTML + "</div>";
    htmlText += "   <div class=\"pBody\">" + innerHTML + "</div>";
    htmlText += "</div></body>";
    
    winObj.document.title = "haha";
    winObj.document.open();
    winObj.document.write(htmlText);
    winObj.document.close();
    
//    if(document.getElementById("popUpDiv") == null){
//        var newElem = document.createElement("div");
//        var pHeaderElem = document.createElement("div");
//        var pBodyElem = document.createElement("div");
//        var pCloseElem = document.createElement("a");
//        var bodyElem = document.getElementsByTagName("body")[0];
//        
//        newElem.setAttribute("id","popUpDiv");
//        newElem.className = "popDiv";
//       
//        pCloseElem.setAttribute("href","#");
//        pCloseElem.innerHTML = "Close X";
//        pCloseElem.className = "pClose";
//        
//        pHeaderElem.className = "pHeader";
//        pHeaderElem.innerHTML = headerHTML;
//        pBodyElem.className = "pBody";
//        pBodyElem.innerHTML = innerHTML;
//        
//        newElem.appendChild(pCloseElem);
//        newElem.appendChild(pHeaderElem);
//        newElem.appendChild(pBodyElem);
//        
//        
//        bodyElem.insertBefore(newElem, bodyElem.firstChild);
//        pCloseElem.onclick = function(){document.getElementById('popUpDiv').style.display = 'none';return false};
//        if(width != "" || height != ""){
//            if(width != ""){
//                if(height!= ""){
//                    newElem.style.width = width + "px";
//                    newElem.style.height = height + "px";
//                }else{
//                    newElem.style.width = width + "px";
//                }
//            }else{
//                if(height != ""){
//                    newElem.style.height = height + "px";
//                }
//            }
//        }        
//        centerObject(newElem);
//        
//    }
//}

//function centerObject(objRef){

//    var obj = objRef;
//    var scrollX = 0;
//    var scrollY = 0;
//    if(document.body && typeof document.body.scrollTop != "undefined"){
//        scrollX += document.body.scrollLeft;
//        scrollY += document.body.scrollTop;
//        if(document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined"){
//            scrollX += document.body.parentNode.scrollLeft;
//            scrollY += document.body.parentNode.scrollTop;

//        }
//    }else if(typeof window.pageXOffset != "undefined"){
//        scrollX += window.pageXOffset;
//        scrollY += window.pageYOffset;
//    }
//    
//    var x = Math.round((getInsideWindowWidth()/2) - (getObjectWidth(obj)/2)) + scrollX;
//    var y = Math.round((getInsideWindowHeight()/2) - (getObjectHeight(obj)/2)) + scrollY;
//    shiftTo(obj,x,y);

}


function shiftTo(objRef,x,y){
    var obj = objRef;
    obj.style.left = x + "px";
    obj.style.top = y + "px";
}

function getInsideWindowWidth(){
    if(window.innerWidth){
        return window.innerWidth - 18;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        return document.documentElement.clientWidth
    }
    return 0;
}

function getInsideWindowHeight(){
    if(window.innerHeight){
        return window.innerHeight;
    }else if(typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
        return document.documentElement.clientHeight;
    }
    return 0;
}


function getObjectWidth(objRef)  {
    var elem = objRef;
    var result = 0;
    if (elem.offsetWidth) {
        result = elem.offsetWidth;
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

function getObjectHeight(objRef)  {
    var elem = objRef;
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}

//---- 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 ----