  var topVal;
  var leaving;
  $(document).ready(function () {

    $("a.prompt").click(function(e) {
      topVal = null;
      topVal = e.pageY  - 100 + "px";
      leaving = '<div style="height: 100px;"><h1 class="headline2">You are leaving the Norditropin U.S. website</h1>';
      leaving += '<p class="gfb">The selected link will take you outside the Norditropin U.S. website.</p></div>';
	  leaving += '<p class="popupq">Are you sure you want to leave the Norditropin U.S. website?</p>';
	  destiNation = $(this).attr("href");
      doLeave(destiNation, true);
      return false;
    });
	
	$("a.hcp-prompt").click(function(e) {
      topVal = null;
      topVal = e.pageY  - 100 + "px";
	  leaving = '<div style="height: 120px;"><h1 class="headline2">For health care professionals only</h1><p class="gfb">The information contained on this site is intended for use only by health care professionals in the United States. ';
      leaving += 'Countries outside the United States may have different regulatory requirements or medial practices than the United States. Therefore this information may not be appropriate for use outside of the United States.</p></div>';
	  leaving += '<p class="popupq">Are you a health care professional in the United States?</p>';
	  destiNation = $(this).attr("href");
      doLeave(destiNation, false);
      return false;
    });

  });
  
   function makeRound(){
      var els = document.getElementsByTagName('div');
      for (var i = 0; el = els[i]; i++) 
          if (el.className.indexOf('round') > -1 && el.firstChild && el.firstChild.className != 't') 
              el.innerHTML = '<b class="tl">&nbsp;</b><b class="tr">&nbsp;</b><div class="c">' + el.innerHTML + '</div><b class="bl">&nbsp;</b><b class="br">&nbsp;</b>';
   }

  function doLeave(href, cancel) {

    //$("#divFloatPop").css("top", topVal);
    var scrolledX = document.body.scrollLeft || document.documentElement.scrollLeft || self.pageXOffset;
    var scrolledY = document.body.scrollTop || document.documentElement.scrollTop || self.pageYOffset;

    if (!scrolledX) {
      scrolledX = 0;
    }

    if (!scrolledY) {
      scrolledY = 0;
    }

    var screenWidth = document.body.clientWidth || document.documentElement.clientWidth || self.innerWidth;
    var screenHeight = document.body.clientHeight || document.documentElement.clientHeight || self.innerHeight;

    var left = (scrolledX + screenWidth - $("#divFloatPop").width())/2;
    var top = (scrolledY + screenHeight - $("#divFloatPop").height())/2-120;
	
	if (navigator.appVersion.indexOf("Mac") != -1) {
		$("#modalOverlay").addClass('modalOverlay-mac');
	} else {
		$("#modalOverlay").addClass('modalOverlay');
	}
	$("#modalOverlay").css('opacity', '0.75');
	$("#modalOverlay").css('filter', 'alpha(opacity=75)');
	$("#modalOverlay").fadeIn("normal", function(){
		$("#modalOverlay").css('opacity', '0.75');
		$("#modalOverlay").css('filter', 'alpha(opacity=75)');
	});

    //Set the popup window to center
    $("#divFloatPop").css('top',  ''+top+'px');
    $("#divFloatPop").css('left', ''+left+'px');
	
	$("#divFloatPop").html('<div style="clear: both;"><!-- c --></div>');
	$("#divFloatPop").append(leaving);
    $("#divFloatPop").fadeIn("normal");
	
	$("#divFloatPop").append('<a href="'+ href +'" target="_blank" onclick="stay();return true;">Yes</a>');
    if (cancel) {
      $("#divFloatPop").append('<a href="#" onclick="return stay();">Cancel</a>');
    } else {
      $("#divFloatPop").append('<a href="#" onclick="return stay();">No</a>');
    }
	
	$("#divFloatPop").append('<div style="clear: both;"><!-- c --></div>');
	makeRound();
	
  }

  function stay() {
    destiNation = '';
    $("#divFloatPop").fadeOut("normal");
	$("#modalOverlay").fadeOut("normal");
    return false;
  }

