// JavaScript Document


// 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 content = document.getElementById("col-full");
	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) {					
				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://www.zimmer.com' + links[i].href.substring((links[i].href.indexOf("/web")));

			}
		}
		
		for(j=0; (a = content.getElementsByTagName("img")[j]); j++) {
		
			if(a.src.indexOf("/micro") == -1) {
				a.src =  'http://www.zimmer.com' + a.src.substring((a.src.indexOf("/web")));
				
			}
		}
	}
}

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;
}

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;
}

window.onload = function() {
	initPage();
}