// browser check
IS_DOM = (document.getElementById) ? true : false;
IS_NS4 = (document.layers) ? true : false;
IS_IE = (document.all) ? true : false;
IS_IE4 = IS_IE && !IS_DOM;
IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);
IS_IE4M = IS_IE4 && IS_Mac;
IS_NS4M = IS_NS4 && IS_Mac;
IS_NS6 = IS_DOM && ! IS_IE;
IS_NS6M = (IS_DOM && IS_Mac && !IS_IE);
IS_Opera = (navigator.userAgent.indexOf("Opera")!=-1);
IS_Konqueror = (navigator.userAgent.indexOf("Konqueror")!=-1);

// smallest # left-hand column can be compressed to
MINIMUM_WIDTH = 43;
// overall width of design inside centering
DESIGN_WIDTH = 694;
// constant to offset dynamically positioned elements by
FINAL_OFFSET = getPageOffset();

function changeImages() 
{
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) { 
  		document[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src"); 
	}
  }
}

/*
changeLayeredImages(image,new state,parentLayer,childLayer, n subchildLayers);
*/
function changeLayeredImages()
{
	imageName = changeLayeredImages.arguments[0];
	newSource = changeLayeredImages.arguments[1];
	if (!document.layers) {
		document[changeLayeredImages.arguments[0]].src = eval(changeLayeredImages.arguments[1] + ".src");
	} else {
		allParameters = changeLayeredImages.arguments.length;
		NN4_layer_name = "";
		for (i = 2; i < allParameters; i++) {
			NN4_layer_name += "document.layers['" + changeLayeredImages.arguments[i] + "']."
		}
		eval(NN4_layer_name + "document.images['" + imageName + "'].src = " + newSource + ".src");
	}
}

function popIt(x) {
window.open(x,"pollWindow","top=100,left=100,scrollbars=yes,width=500,height=300,resizable=yes")
}

function popWindow(url, windowName, width, height) {
window.open(url,windowName,"top=0,left=10,scrollbars=no,width=" + width + ",height=" + height + ",resizable=no")
}

function popEthicsGuide()
{
	popWindow("/TycoWeb/WWW/gtec/home/index.htm", "guide", 660, 581);
}

// preload level 1 menu buttons
var btnLevel1 = new Array();
btnLevel1 = ["who_we_are","commitment","businesses","investor"];
for (i=0;i<btnLevel1.length;i++) { 
	eval("menu"+i+"on = new Image();"); eval("menu"+i+"off = new Image();");
	eval("menu"+(i)+"on.src = \"" + folderLevel + "img/l1_"+btnLevel1[i]+"_r.gif\";");
	eval("menu"+(i)+"off.src = \"" + folderLevel + "img/l1_"+btnLevel1[i]+"_0.gif\";");
}

function getObject(id) {
	alert(id);
	if (IS_DOM) {
		object = document.getElementById(id).style
	}
	if (IS_IE4) {
		object = document.all[id].style
	}
	if (IS_NS4) {
		object = document.layers[id]
	}
	return object;
}

function getPageOffset()
{
	var offset;
	offset = 0;

	ie4_mac_fix = fixIE4MacCenter();
	ns6_fix = adjustMozilla();
	offset += ie4_mac_fix;
	offset += ns6_fix;
	
	if (IS_NS4) {
		offset = 3;
	}
	
	return offset;
}

function displayDiv(prefix,name,offsetLeft,visibilityState)
{
	var displayOffset;
	displayOffset = FINAL_OFFSET;
	// assemble DIV ID
	turnOnThis = prefix + name;
	// find left edge of design
	LEFT_EDGE = getLeftEdge(DESIGN_WIDTH);
	// get hold of DIV object
	showDIV = getObject(turnOnThis);
	// set left position
	showDIV.left = LEFT_EDGE + offsetLeft - displayOffset;
	// set visibility
	showDIV.visibility = visibilityState;
}

/*
this function finds total width of user's browser screen -- must be called after page is rendered for IE to work (uses bodyWidth)
*/
function getWindowWidth()
{
	WINDOW_WIDTH = IS_IE ? document.body.clientWidth : window.innerWidth;
	if (IS_DOM) {
		// IE5+
		if (IS_IE) {
			WINDOW_WIDTH = document.documentElement.offsetWidth - 20;
		} else {
		// All other DOM-Compliant Browsers 
			WINDOW_WIDTH = document.documentElement.offsetWidth + 7;
		}
	}
	return WINDOW_WIDTH;
}

/*
This function deals with centering problems in IE4 Mac (i.e., design is pushed to right rather
than centered). Call if necessary in getLeftEdge().
*/
function fixIE4MacCenter()
{
	adjustment = 0;
	if (IS_IE4M) {
		whereAmI = WINDOW_WIDTH - DESIGN_WIDTH;
		adjustment = (-0.34 * whereAmI)
	}
	return adjustment;
}

function adjustMozilla()
{
	adjustment = 0;
	// if scrollbars are showing in NS6, adjust Netscape offset
	if (IS_NS6) {
		adjustment = 2;
		//alert("Doc Height: " + document.height + " | Screen Height: " + window.innerHeight);
		if ((document.height + 30) > window.innerHeight) {
			 adjustment += 0;
		}
	}
	//alert(adjustment);
	return adjustment;
}

/*
this function provides the base left position of a centered design on the screen
two parameters: the # of pixels it will never shrink past no matter how small the window (usually a lefthand column buffer with a transparent image) and the total width of the design (e.g., 780)
*/
function getLeftEdge(totalDesignWidth)
{
	WINDOW_WIDTH = getWindowWidth();
	SCREEN_CENTER = (WINDOW_WIDTH/2);
	halfOfDesign = (totalDesignWidth/2);

	// left edge should be @ (middle of screen - half of design's width)
	LEFT_EDGE = ((SCREEN_CENTER - halfOfDesign) - FINAL_OFFSET);
	
	// if the left edge # is smaller than the minimum possible, reset to minimum possible
	if (LEFT_EDGE < MINIMUM_WIDTH) {
		LEFT_EDGE = MINIMUM_WIDTH;
	}
	
	return LEFT_EDGE;
}

function setSublevelPositions() 
{
	// array of item ids, their offset from the left edge and visiblity on page load (1 = on)
	align_these = new Array();
	align_these = [
		["constants",315,1]
	];
	
	// loop over align_these array and reposition elements, then make visible
	for (i = 0; i < align_these.length; i++) {
		var showMe = "hidden";
		var leftPos = align_these[i][1];
		if (align_these[i][2] == 1) {
			showMe = "visible";
		}
		displayDiv("",align_these[i][0],leftPos,showMe)
	}
}

function hidePositionedElements()
{
	for (i = 0; i < align_these.length; i++) {
		var showMe = "hidden";
		var leftPos = align_these[i][1];
		displayDiv("",align_these[i][0],leftPos,showMe)
	}
}

function setSectorPositions()
{

}

// --- row highlighting
function selectRow(id, state) {
	if (state == 'on') {
		document.getElementById(id).className = 'selectedRow';
	} else {
		document.getElementById(id).className = 'unselectedRow';
	}
}
// --- / row highlighting

// --- application openwin function
function openWin ( url, width, height ) {
	var winName = "newWind" + Math.round(Math.random() * 9999999);
	window.open (url, winName, 'height=' + height + ',width=' + width + ',scrollbars,resizable,top=100,left=100')
}
// --- / application openwin function

if (IS_NS4) {
	origWidth = innerWidth; 
	origHeight = innerHeight; 
}

function redo() {
	if (IS_NS4) {
		if (innerWidth != origWidth || innerHeight != origHeight) {
			location.reload(); 
		}
	} else {
		window.location.reload();
	}
}

function openSurvey()
{
	window.open("http://www.tyco.com/survey/index.asp","surveyWindow","width=500,height=500,toolbar=yes,location=no,scrollbars=yes,resizable=yes,top=20,left=20")
}

// set up onload function depending on location
function doPositioning() {
	if (folderLevel == "") {
		setHomepagePositions();
		
		// 07-24-2003 choose random sector on visit. comment out these lines to stop
		var sRandomSectorName;
		sRandomSectorName = chooseRandomSector();
		setInitialOnSector(sRandomSectorName);
	} else {
		setSublevelPositions();
		setSectorPositions();
	}
	window.onresize = redo;
}

//window.onload = doPositioning;

// Off Site Link Disclaimer
function disclaimer(){
	alert("You are now leaving the Tyco International Ltd. website. Tyco makes no representations, warranties, or assurances as to the accuracy or completeness of the information provided.");
}


function hideshow(sID) {
// Function that will swap the display/no display for
// all content within span tags
oObject = document.getElementById(sID);

if (oObject.style.display == "none")
{
oObject.style.display = "block";
}
else
{
oObject.style.display = "none";
}
}


oExpandImage = new Image; oExpandImage.src = "http://www.tyco.com/img/buttons/button_collapse.gif";
oCollapseImage = new Image; oCollapseImage.src = "http://www.tyco.com/img/buttons/button_expand.gif";

function expandNavigation(sBoxId, sImgId)
{
	if (document.getElementById) {
		oNavBox = document.getElementById(sBoxId).style;
		oImage = document.getElementById(sImgId);

		if (oNavBox.display == "none" || oNavBox.display == "NULL") {
			changeDisplayState(sBoxId);
			oImage.src = oExpandImage.src;
		} else {
			changeDisplayState(sBoxId);
			oImage.src = oCollapseImage.src;
		}
	}
}

function changeDisplayState(sBoxId)
{
	if (document.getElementById) {
		oBox = document.getElementById(sBoxId).style;

		if (oBox.display == "none" || oBox.display == "NULL") {
			oBox.display = "block";
		} else {
			oBox.display = "none";
		}
	}
}



function hillpop(geturl, htmlwidth, htmlheight)
	{
		window.open(geturl,'_blank','width='+htmlwidth+',height='+htmlheight+',left='+(screen.width/2-htmlwidth/2)+',top='+(screen.height/2-htmlheight/2)+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
	}
	

