// break out of frameset (production only!)
var s = self.location;
if(top != self && s.toString().indexOf("zimmer.dev.biggs-gilmore.com") == -1 && s.toString().indexOf("zimmer.stage.biggs-gilmore.com") == -1) top.location.replace(s);

// load stylesheet for js-enabled browsers
if(document.getElementById && document.createTextNode) {
	document.writeln("<link href=\"/web/css/z5jsenabled.css\" rel=\"stylesheet\" type=\"text/css\" media=\"all\">");
}

var dest = Array();
dest["enUS"] = {
	pc: "http://www.zimmer.com/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.com/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.com/z/ctl/op/global/action/1/template/CP/id/562",
        ca: "http://www.zimmer.com/z/ctl/op/global/action/1/template/CP/id/10141"
}
dest["enAU"] = {
	pc: "http://zimmer.com.au/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://zimmer.com.au/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://zimmer.com.au/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enCA"] = {
	pc: "http://www.zimmer-canada.com/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer-canada.com/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer-canada.com/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["nlNL"] = {
	pc: "http://www.zimmer.co.nl/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.co.nl/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.co.nl/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enNZ"] = {
	pc: "http://www.zimmer.co.nz/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.co.nz/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.co.nz/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enZA"] = {
	pc: "http://www.zimmer.co.za/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.co.za/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.co.za/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enN2"] = {
	pc: "http://www.zimmerspine.eu/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmerspine.eu/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmerspine.eu/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enUK"] = {
	pc: "http://www.zimmer.co.uk/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.co.uk/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.co.uk/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["esLA"] = {
	pc: "http://www.zimmer-latinoamerica.com/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer-latinoamerica.com/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer-latinoamerica.com/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["frFR"] = {
	pc: "http://www.zimmer.com/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.com/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.com/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["geAT"] = {
	pc: "http://www.zimmer-austria.at/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer-austria.at/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer-austria.at/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["geCH"] = {
	pc: "http://www.zimmer-orthopedics.ch/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer-orthopedics.ch/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer-orthopedics.ch/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["enIN"] = {
	pc: "http://www.zimmerindia.com/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmerindia.com/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmerindia.com/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["geEU"] = {
	pc: "http://www.zimmer.eu/z/ctl/op/global/action/1/template/PC/id/561",
	mp: "http://www.zimmer.eu/z/ctl/op/global/action/1/template/MP/id/560",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer.eu/z/ctl/op/global/action/1/template/CP/id/562"
}
dest["itIT"] = {
	pc: "http://www.zimmer2.eu/it/pazienti/index.html",
	mp: "http://www.zimmer2.eu/it/professionisti/index.html",
	ir: "http://investor.zimmer.com",
	cp: "http://www.zimmer2.eu/it/corporate_home.html"
}


jumpToOrientation = function() {
	var cl = document.getElementById("selLanguage");
	cl = cl[cl.selectedIndex].value;
	var o = document.getElementById("orientationCode").value;
	if(cl != "enUS" && o == "ir") {
		window.open("http://investor.zimmer.com");
	} else {
		location.href = dest[cl][o];
	}
	return false;
}

jumpToOrientation2 = function() { 
	var s = document.getElementById("selGoTo");
	if(s) {
		var o = s.value;
		if(o == "investor") {
			window.open("http://investor.zimmer.com");
		} else {
			location.href = o;
		}
	}
}

switchLanguage = function(lang) {
	var f = document.getElementById("frmDestination");
	if(f) {
		if(lang.indexOf("http") != -1) {
			// switch language/country options
			for(i=0; (d = f.getElementsByTagName("div")[i]); i++) {
				d.style.display = "none";
			}
			location.href = lang;
		} else {
			if(document.getElementById && document.createTextNode) {
				// uncheck radio buttons
				for(i=0; (r = f.getElementsByTagName("input")[i]); i++) {
					r.checked = false;
				}
				// hide enter button
				var b = document.getElementById("btnEnter");
				if(b) b.style.visibility = "hidden";
				// switch language/country options
				for(i=0; (d = f.getElementsByTagName("div")[i]); i++) {
					d.style.display = "none";
				}
				d = document.getElementById("destination-" + lang);

				if(d) d.style.display = "block";
			}
		}
	}
}

switchHostname = function(lang) {
	var h = location.host;
	dest[lang]["pc"] = "http://" + h + "/z/ctl/op/global/action/1/template/PC/id/561/";
	dest[lang]["mp"] = "http://" + h + "/z/ctl/op/global/action/1/template/MP/id/560/";
	dest[lang]["cp"] = "http://" + h + "/z/ctl/op/global/action/1/template/CP/id/562/";
}

setOrientation = function(o) {
	document.getElementById("orientationCode").value = o;
	var b = document.getElementById("btnEnter");
	if(b) b.style.visibility = "visible";
}

initPage = function() {
	if(document.getElementById && document.createTextNode) {
		var f = document.getElementById("frmDestination");
		if(f) {
			// attach event to home page form
			f.onsubmit = function() {return jumpToOrientation()};
			// attach events to home page destination form radio buttons
			for(i=0; (r = f.getElementsByTagName("input")[i]); i++) {
				if(r.getAttribute("type") == "radio") {
					r.checked = false;
					r.onclick = function() {setOrientation(this.value)};
				}
			}
			// get default country code and configure the home page destination selector
			var bc = document.getElementsByTagName("body")[0].className;
			var lang = bc.split(" ");
			switchLanguage(lang[1]);
			//switchHostname(lang[1]);
			// set country language selector to default value
			var s = document.getElementById("selLanguage");
			for(i=0; (o = s.getElementsByTagName("option")[i]); i++) {
				if(o.value == lang[1]) {
					o.selected = true;
					break;
				}
			}
			// attach event to country language selector
			s.onchange = function() {switchLanguage(this.value)};
		}
		// add "text" and "button" classes to input elements
		var t = document.getElementsByTagName("input");
		if(t) {
			for(i=0; i<t.length; i++) {
				var tt = t[i].getAttribute("type");
				if(tt == "text" || tt == "password") {
					t[i].className = "text";
				} else if(tt == "submit" || tt == "reset") {
					t[i].className = "button";
				}
			}
		}
		// attach classes/events to site nav elements
		var sitenav = document.getElementById("navigation");
		if(sitenav) {
			for(i=0; (u = sitenav.getElementsByTagName("ul")[i]); i++) {
				if(u.parentNode.nodeName == "DIV") {
					u.className = "level1";
				} else if(u.parentNode.parentNode.parentNode.nodeName == "DIV") {
					u.className = "level2";
				} else {
					u.className = "level3";
				}
				var c = u.childNodes;
				for(j=0; j < c.length; j++) {
					if(c[j].nodeName == "LI") {
						c[j].className = "first";
						break;
					}
				}
			}
			// nav category headers: replace <b> tags with <a> tags with event handlers
			var arrB = sitenav.getElementsByTagName("b");
			for(i = arrB.length - 1; i>= 0; i--) {
				b = arrB[i];
				var p = b.parentNode;
				var bnv = b.firstChild.nodeValue;
				var a = document.createElement("a");
				a.setAttribute("href", "null.html");
				p.replaceChild(a, b);
				var c = p.firstChild;
				var t = document.createTextNode(bnv);
				c.appendChild(t);
				c.className = "more";
				c.onfocus = function() {window.status=" "; return true;};
				c.onmouseover = function() {window.status=" "; return true;};
				c.onclick = function() {showMenu(this); this.blur(); return false;};
				c.onkeypress = function() {showMenu(this); return false;};
			}
		}
		// reset go to selector (for firefox!)
		var s = document.getElementById("selGoTo");
		if(s) s.selectedIndex = 0;
		// attach event to locate form
		var l = document.getElementById("txtLocate");
		if(l) {
			l.onfocus = function() {if(l.value == "Enter your ZIP Code") l.value = ""};
		}
		// attach events to font-controls
		a = document.getElementById("font-smaller");
		if(a) {
			a.onclick = function() {reduceFontSize(); this.blur(); return false};
			a.onkeypress = function() {reduceFontSize(); return false};
		}
		a = document.getElementById("font-larger");
		if(a) {
			a.onclick = function() {increaseFontSize(); this.blur(); return false};
			a.onkeypress = function() {increaseFontSize(); return false};
		}
		// attach events to media manager links in content
		var content = document.getElementById("content");
		if(content) {
			for(i=0; (a = content.getElementsByTagName("a")[i]); i++) {
				//alert(this.href);
				
				if(a.href.indexOf("/web/flashmedia") > -1) {
					
					a.onclick = function() {return openMediaWindow(this.href)};
				}
			}
		}
	}
}

expandMenus = function() {
	var prcat = getPRCat(query);
	if(document.getElementById && document.createTextNode) {
		// expand left nav
		var sitenav = document.getElementById("navigation");
		if(sitenav) {
			for(i=0; (a = sitenav.getElementsByTagName("a")[i]); i++) {
				var hr = a.getAttribute("href");
			
				if(hr) {
					if(query && hr == query) {
						a.className = "current";
						var c = a.parentNode.parentNode.className;
						switch(c) {
							case "level3":
								var a = a.parentNode.parentNode.parentNode.firstChild;
								a.className = "level2-on";
								var oc = a.parentNode.className; // check for existing class "first" and pre-pend if necessary
								if(oc) oc += " ";
								a.parentNode.className = oc + "level2-on";
							case "level2":
								var a = a.parentNode.parentNode.parentNode.firstChild;
								a.className = "level1-on";
								var oc = a.parentNode.className; // check for existing class "first" and pre-pend if necessary
								if(oc) oc += " ";
								a.parentNode.className = oc + "level1-on";
								break;
						}
					}
				} 
			}
			sitenav.style.visibility = "visible";
		}
		// highlight product nav
		var topnav = document.getElementById("header-nav");
		if(topnav) {
			for(i=0; (a = topnav.getElementsByTagName("a")[i]); i++) {
				if(prcat && getPRCat(a.getAttribute("href")) == prcat) { 
					a.className = "current";
					break;
				}
			}
		}
	}
}

showMenu = function(obj) {
	if(document.getElementById && document.createTextNode) {
		if(obj.className.indexOf("-on") == -1) {
			var c = obj.parentNode.parentNode.className;
			var sitenav = document.getElementById("navigation");
			for(i=0; (li = sitenav.getElementsByTagName("li")[i]); i++) {
				if(c == "level1" && li.className.indexOf("level1-on") != -1) {
					li.className = "";
					li.firstChild.className = "";
				} else if(li.className.indexOf("level2-on") != -1) {
					if(li.className.indexOf("first") != -1) {
						li.className = "first";
					} else {
						li.className = "";
					}
					li.firstChild.className = "more";
				}
			}
			obj.className = c + "-on";
			var oc = obj.parentNode.className; // check for existing class "first" and pre-pend if necessary
			if(oc) oc += " ";
			obj.parentNode.className = oc + c + "-on";
		}
	}
}

getPRCat = function(str) {
	var queryStart = str.indexOf('prcat/');
	if (queryStart!=-1) {
		var subInxStrt = queryStart + 6;
		var subInxEnd = queryStart + 8;
		var query = str.substring(subInxStrt, subInxEnd);
		return query;
	}
	return null;
}

function setActiveStyleSheet(title) {
  if(document.getElementById && document.createTextNode) {
		var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
	     	a.disabled = true;
	      if(a.getAttribute("title") == title) a.disabled = false;
	    }
	  }
	}
}

setStyles = function() {
  var cookie = readCookie("z5Styles");
  var title = cookie ? cookie : "small";
	createCookie("z5Styles", title, 365);
 	setActiveStyleSheet(title);
}

reduceFontSize = function() {
	var fs = readCookie("z5Styles");
	switch(fs) {
		case "small":
			// do nothing
			break;
		case "medium":
			fs = "small";
			break;
		case "large":
			fs = "medium";
			break;
		case "x-large":
			fs = "large";
			break;
		default:
			fs = "small";
	}
	createCookie("z5Styles", fs, 365);
	setActiveStyleSheet(fs);
}

increaseFontSize = function() {
	var fs = readCookie("z5Styles");
	switch(fs) {
		case "small":
			fs = "medium";
			break;
		case "medium":
			fs = "large";
			break;
		case "large":
			fs = "x-large";
			break;
		case "x-large":
			// do nothing
			break;
		default:
			fs = "medium";
	}
	createCookie("z5Styles", fs, 365);
	setActiveStyleSheet(fs);
}

createCookie = function(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

readCookie = function(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

popUpWindow = function(URL,windowName,width,height) {
	var w = screen.availWidth;
	var h = screen.availHeight;
	var leftPos = Math.round((w-width)/2);
	var topPos = Math.round((h-height)/2);
	var defaults = "scrollbars=yes,resizable=yes,";
	var centerOnScreen = "top="+topPos+",left="+leftPos+",width="+width+",height="+height;
	// safari seems to need the trailer comma
	var options = defaults + centerOnScreen + ",";
	var msgWindow = window.open(URL,windowName,options);
	msgWindow.focus();
}

popUpVideoWindow = function(URL,windowName,width,height) {
	var w = 955;
	var h = screen.availHeight;
	var leftPos = Math.round((w-width)/2);
	var topPos = Math.round((h-height)/2);
	var defaults = "scrollbars=no,resizable=no,";
	var positionOnScreen = "top="+topPos+",left="+leftPos+",width="+width+",height="+height;
	// safari seems to need the trailer comma
	var options = defaults + positionOnScreen + ",";
	var msgWindow = window.open(URL,windowName,options);
	msgWindow.focus();
}

// deals with query string
var query = new String(window.location); 

var thisimg = 0, allimages = new Array("1a.jpg","1b.jpg","2a.jpg","2b.jpg","3a.jpg","3b.jpg","4a.jpg","4b.jpg","5a.jpg","5b.jpg","6a.jpg","6b.jpg","7a.jpg","7b.jpg","8a.jpg","8b.jpg");

function rotateimg(){
	if(document.homeimg) {
		document.homeimg.src = "/web/images/home_img/" + allimages[thisimg];
		setTimeout("rotateimg()", 3000);
		thisimg++;
		if(thisimg == allimages.length) thisimg = 0;
	}
}

window.onload = function() {
	var x = new Date();
	initPage();
	expandMenus();
	setStyles();
	rotateimg();
	var y = new Date();
	//alert("time to run onload functions: " + (y.getTime() - x.getTime()));
}

// function that's called if pre-onload handlers are available
beforeOnloadInit = function() {
	window.onload();
	window.onload = null;
};

// proprietary DOMContentLoaded Mozilla event handler
if (document.addEventListener) document.addEventListener("DOMContentLoaded", beforeOnloadInit, null);

// legacy z4 functions

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function jumpPage(menu) {
	var url = menu.options[menu.selectedIndex].value;
    window.location.href = url;
}

function launchMovie(url) {
	testDW = window.open(url,"testDW","toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,width=340,height=400,top=20,left=20");
	return false;
}

// Array Extensions  v1.0.6
// documentation: http://www.dithered.com/javascript/array/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}


// add load event 
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

// Hide Flash Container Div Layer when "close" is clicked
function hidden() {
		document.getElementById("flashcontent").style.display = "none";
		document.getElementById("flashcontent").innerHTML = "";
		if (window.opener && s.toString().indexOf("/web/flashmedia/") > -1 ) self.close();
}
	
// Load Flash Video
//
function loadflash(url, width, height, autoclz) {
		// content variables
		// if you want to test a .swf file change path to "", filename to "test_movie" and type to ".swf"
		//var path = "http://www.helpexamples.com/flash/video/";
		//var filename = "water";
		//var type = ".flv";
		var myFlash = new FlashObject("/web/flashmedia/ad_media_module.swf", "zimmerad", width, height, "8.0.22.0", "#FFFFFF", true);
		myFlash.addVariable("lang", "Close");
		myFlash.addVariable("closefunction", "hidden");      //add "hide layer" function instead of "closedlayer" 
		myFlash.addVariable("filepassed", url);
		myFlash.addVariable("autoclose",autoclz); //1 use autoclose, 0 don't use autoclose
		myFlash.write("flashcontent");
		document.getElementById("flashcontent").style.display = "block";
}

openMediaWindow = function(url) {
	var mw = window.open(url, "mw", "width=875,height=600,toolbar=no,location=no,status=no,menubar=no");
	if(mw) mw.focus();
	return false;
}
