// JavaScript Document

window.name = "main";



// Preload navigation roll-over images

 if (document.images)  // prevents older browsers that don't support the Image object from giving a JavaScript error
    {
    
    }


// Pop-up windows for footer links

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();
}

initPage = function() {
	// attach events to media manager links in content
	var url = top.location;
	var atlasHost = '12.31.56.76:8500';
	if(url.hostname != "12.31.56.76") {
		atlasHost = 'www.zimmer.com';
	}

	var content = document.getElementById("col-center");
	if(content) {
		
		var links = document.getElementsByTagName("a");

		for (var i=0;i<links.length;i++) {
		
			if(links[i].href.indexOf("/micro") == -1 && links[i].href.indexOf("template=null") > -1 && links[i].href.indexOf("/web/flashmedia") == -1) {					
				data = createRequestObject(links[i].href);
				var id=data['id'];
	
				links[i].href = "/micro/ctl?op=global&action=1&id=" + id + "&global=1&template=mn";

			}
			if(links[i].href.indexOf("/micro") == -1 && links[i].href.indexOf(".pdf") > -1) {					
		
				links[i].href = 'http://' + atlasHost + links[i].href.substring((links[i].href.indexOf("/web")));

			}
	
			if(links[i].href.indexOf("/web/flashmedia") > -1) {
				links[i].href = 'http://' + atlasHost  + links[i].href.substring((links[i].href.indexOf("/web")));				
				links[i].onclick = function() { return openMediaWindow(this.href) };
			}
		}
		
		for(j=0; (a = content.getElementsByTagName("img")[j]); j++) {
		
			if(a.src.indexOf("/micro") == -1) {
				a.src =  'http://' + atlasHost  + a.src.substring((a.src.indexOf("/web")));
				
			}
		}
		content.style.visibility = 'visible';
	}
}

			
function createRequestObject(theQuery) {

  FORM_DATA = new Object();
    // The Object ("Array") where our data will be stored.
  separator = ',';
    // The token used to separate data from multi-select inputs
  //query = '' + this.location;
  query = '' + theQuery;
  qu = query
    // Get the current URL so we can parse out the data.
    // Adding a null-string '' forces an implicit type cast
    // from property to string, for NS2 compatibility.
  query = query.substring((query.indexOf('?')) + 1);
    // Keep everything after the question mark '?'.
  if (query.length < 1) { return false; }  // Perhaps we got some bad data?
  keypairs = new Object();
  numKP = 1;
    // Local vars used to store and keep track of name/value pairs
    // as we parse them back into a usable form.
  while (query.indexOf('&') > -1) {
    keypairs[numKP] = query.substring(0,query.indexOf('&'));
    query = query.substring((query.indexOf('&')) + 1);
    numKP++;
      // Split the query string at each '&', storing the left-hand side
      // of the split in a new keypairs[] holder, and chopping the query
      // so that it gets the value of the right-hand string.
  }
  keypairs[numKP] = query;
    // Store what's left in the query string as the final keypairs[] data.<
  for (i in keypairs) {
    keyName = keypairs[i].substring(0,keypairs[i].indexOf('='));
      // Left of '=' is name.
    keyValue = keypairs[i].substring((keypairs[i].indexOf('=')) + 1);
      // Right of '=' is value.
    while (keyValue.indexOf('+') > -1) {
      keyValue = keyValue.substring(0,keyValue.indexOf('+')) + ' ' + keyValue.substring(keyValue.indexOf('+') + 1);
        // Replace each '+' in data string with a space.
    }
    keyValue = unescape(keyValue);
      // Unescape non-alphanumerics
    if (FORM_DATA[keyName]) {
      FORM_DATA[keyName] = FORM_DATA[keyName] + separator + keyValue;
        // Object already exists, it is probably a multi-select input,
        // and we need to generate a separator-delimited string
        // by appending to what we already have stored.
    } else {
      FORM_DATA[keyName] = keyValue;
        // Normal case: name gets value.
    }
  }
  return FORM_DATA;
}


// Functions to control text resizing

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("zGSStyles");
  var title = cookie ? cookie : "small";
	createCookie("zGSStyles", title, 365);
 	setActiveStyleSheet(title);
}

reduceFontSize = function() {
	var fs = readCookie("zGSStyles");
	switch(fs) {
		case "small":
			// do nothing
			break;
		case "medium":
			fs = "small";
			break;
		case "large":
			fs = "medium";
			break;
		case "x-large":
			//fs = "large";   //commented out to prevent highest text size setting (equals "do nothing") - client request
			//break;
		default:
			fs = "small";
	}
	createCookie("zGSStyles", fs, 365);
	setActiveStyleSheet(fs);
}

increaseFontSize = function() {
	var fs = readCookie("zGSStyles");
	switch(fs) {
		case "small":
			fs = "medium";
			break;
		case "medium":
			fs = "large";
			break;
		case "large":
			//fs = "x-large";  //commented out to prevent highest text size setting (equals "do nothing") - client request
			//break;
		case "x-large":
			// do nothing
			break;
		default:
			fs = "medium";
	}
	createCookie("zGSStyles", 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;
}


openGlobalContent = function(url) {
	var globalUrl = "/micro" + url;
	return true;
}

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;
}

window.onload = function() {
	initPage();
}