// Pop up a window to show Zone "details"
function zonePopUp(smovieid, id_Zone, id_proccont) {
  if (document.location.protocol == ('file:')) {
    var url = "zone" + id_Zone + "_" + id_proccont + ".htm";
  } else {
    var url = Application.relapproot + "/zoneData.cfm?"+ Application.passthis +"&id_Zone=" + escape(id_Zone) + "&id_proccont=" + escape(id_proccont) + "&id_Manual=" + escape(Application.currentmanualid);
  };  
  positionedPopUp(url, _zoneWinPos.width, _zoneWinPos.height, smovieid, "zonePopup", true);
};


var imgMagnifOn  = new Image();
imgMagnifOn.src = Application.relapproot + '/Icons/ZoomIn1.gif';

var imgMagnifOff  = new Image();
imgMagnifOff.src = Application.relapproot + '/Icons/ZoomIn.gif';

if (window.createPopup) {
  var oPopup = window.createPopup();
};  


function positionedPopUp(url, w, h, sImgID, sWinName, bScrollbars) {
  var newWin, pos;
  var winWidth  = w;
  var winHeight = h;
  var winLeft   = _zoneWinPos.left;
  var winTop    = _zoneWinPos.top;

  var isIE    =  navigator.appName.indexOf("Microsoft") != -1;
  var oAnchor =  isIE ? document.all[sImgID] : null;

  // If it's possible to calculate position for new window (basically, if browser is IE), do so
  if (window.screenLeft && window.screenTop && (oAnchor != null)) {
    // Get the position of the flash object, relative to the top-left of the BODY
    pos = getPosition(oAnchor);

    // Add the window's position on the screen to the relative positions we got above
    winLeft = pos.left - document.body.scrollLeft + window.screenLeft + parseInt(oAnchor.width) + 7;
    winTop  = pos.top  - document.body.scrollTop  + window.screenTop + 2;

    // If the proposed window position will put it off the edge of the screen, put it at right/bottom edge instead
    if ((winLeft + winWidth + 10) > window.screen.availWidth)   { winLeft = window.screen.availWidth - winWidth - 10;  }
    if ((winTop + winHeight + 50) > window.screen.availHeight)  { winTop = window.screen.availHeight - winHeight - 50; }
  }; 

  // Go ahead and open the pop-up window
  //var id_proccont = parseInt(smovieid.substring(7));
  if (window.createPopup && url.indexOf("ShowFAQx.cfm") >= 0) {
    var url = url + "&popup=1";
    oPopup.document.open();
    oPopup.show(100, 20, winWidth, winHeight, oAnchor);
    dwn.startDownload(url, onDone);
  } else {
    var winFeatures = "scrollbars="+ (bScrollbars == true ? "yes" : "no" ) +",status=no,resizable=no,width="+winWidth+",height="+winHeight+",left="+winLeft+",top="+winTop;
    newWin = window.open(url, (sWinName == null ? "" : sWinName), winFeatures);
  };
  
  return null;
};



function onDone(src){
  oPopup.document.write(src); 
}
    
    
/********* UTILITY FUNCITONS *******/  
// Utility Function that returns (cross-browser) an object reference to a flash player, based on ID/Name
function getFlashMovieInstance(smovieid) {
  var isIE   =  navigator.appName.indexOf("Microsoft") != -1;
  var result =  isIE ? document.all[smovieid] : document.embeds[smovieid];

  //if (result == null) window.defaultStatus = ('Could not obtain movie instance for: ' + smovieid);
  return result;
};

// Utility function that returns the left/top (x/y) position (in pixels)
// of object "obj", recursively walking up the document's object tree if needed
// (basically, it totals up the x/y offsets of the object and all its parents)
// Returns: an object with two properties: "object.left" and "object.top"
function getPosition(obj) {
  var par, pos;
  
  // We'll be returning two values (top and left) to the calling function
  pos = new Object;
  pos.top  = obj.offsetTop;
  pos.left  = obj.offsetLeft;

  // Find out if the object has a parent in the "positioning tree"
  par = obj.offsetParent;
   
  // If there is such a parent, add its offsets to our return values
  while (par != null) {
    pos.top  = pos.top  + par.offsetTop;
    pos.left = pos.left + par.offsetLeft;
  
    // Run the test again, this time testing for the parent's parent (if any)
    par = par.offsetParent;
  };

  return pos;
};    

