// Global for brower version branching.
var Nav4 = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4))
// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object()
// Since links in IE4 cannot be disabled, preserve
// IE link onclick event handlers while they're "disabled."
// Restore when re-enabling the main window.
var IELinkClicks
// Indicates that the user clicked an object on the page.
var userClicked = false;
// Contains the timer id; useful for clearing an already-executing timer
var timerHandle
// Handle to the main window
var mainWindowHandle
// Handle to the debug window
var debugWindow
// Contains a list of the window names
var windowList = [];
// A boolean indicating that our request has finished and there is no need to show the wait time indicator.
var childPageLoaded = true;
// The amount of time in milliseconds that we wait before displaying the wait icon and message.
var WAIT_IMG_TIMEOUT = 3000;
var shouldUnblockEvents = true;
// this variable was added so that when multiple popup windows are opened and the session expires,
// all the popups close gracefully and return to the main view.
var shouldNotifyUsys = true;
// Navigate the window.opener or the modal dialog parent
// to another URL.  Note: this script is meant to work
// hand in hand with the script in modalpopup.js
function navigateOpener(url) {
  if (!window.opener && window.dialogArguments) {
    window.dialogArguments.location.href = url;
  }
  else if (window.opener && !window.opener.closed) {
    try {
      window.opener.userClicked = true;
      window.opener.showOverlayDiv("transparent");
      window.opener.shouldUnblockEvents = false;
      // Don't notify the system that the window is closing.
      window.opener.location.href = url;
    }
    catch (e) {
      // do nothing, just catch this exception and hide it.
    }
  }
  window.close();
  return false;
}

// Navigate the main window to another URL and close all popup windows.
function navigateOpenerAndCloseAllPopups(url) {
  if (self.name != null && self.name.length > 0) {
    var winList = findMainWindow(self).windowList;
    if (winList.length > 0) {
      for (var i = winList.length - 1; i >= 0; i--) {
        var winHandle = window.open("", winList[i], "", "");
        if (winHandle && !winHandle.closed) {
          winHandle.close();
        }
      }
    }
  }

  findMainWindow(self).location.href = url;

  return false;
}

// Navigate to the URL identified in the document "doc" by the
// value of a selected radio button with name "name".
// If an element isn't selected, display "alertMessage".
function chooseRadioItem(doc, name, alertMessage) {
  var obj = doc.getElementsByName(name);
  var familyIndex = document.getElementById("defaultselection");
  var same = false;
  if (obj) {
    for (var j = 0; j < obj.length; j++) {
      if (obj[j].checked) {
        if (j == familyIndex.value) {
          same = true;
        }
        else {
          return navigateOpener(obj[j].value);
        }
      }
    }
    if (same) {
      return window.close();
    }
    alert(alertMessage);
  }
  return false;
}


// Navigate to the ClosePopupInterceptorAction with location and
// newQueryString as parameters.  The PopupCloseInterceptorAction interceptor will
// get the URL of the window that needs to be refreshed and, if needed, use the
// new query string to refresh it.
function closePopup(location, newQueryString, newParam) {
  var url = "../action/closepopup";
  popWindowName();
  if (newQueryString != null && newQueryString.length > 0) {
    url = url + "?replqs=" + urlEncode(newQueryString);
  }

  if (newParam != null && newParam.length > 0) {
    url = addParameterToUrl(url, "replp", urlEncode(newParam));
  }

  if (location != null && location.length > 0) {
    url = addParameterToUrl(url, "winhref", urlEncode(location));
  }

  var winDepth = document.getElementById("depth");
  if (winDepth != null) {
    url = addParameterToUrl(url, "depth", winDepth.value);
  }

  window.location.href = url;
  return false;
}

// Navigate to the ClosePopupInterceptorAction with location and
// newQueryString as parameters.  The PopupCloseInterceptorAction interceptor will
// get the URL of the window that needs to be refreshed and, if needed, use the
// new query string to refresh it.
function closeTopPopup(location, newQueryString, newParam) {
  var url = "../action/closepopup";
  popWindowName();
  if (newQueryString != null && newQueryString.length > 0) {
    url = url + "?replqs=" + urlEncode(newQueryString);
  }

  if (newParam != null && newParam.length > 0) {
    url = addParameterToUrl(url, "replp", urlEncode(newParam));
  }

  if (location != null && location.length > 0) {
    url = addParameterToUrl(url, "winhref", urlEncode(location));
  }

  var winDepth = document.getElementById("depth");
  if (winDepth != null) {
    url = addParameterToUrl(url, "depth", winDepth.value);
  }

  top.location.href = url;
  return false;
}

function cancelWindow() {
  var url = "../action/closepopup?clearwindow=";
  var depth = document.getElementById("depth");

  if (depth != null) {
    if (depth == 2) {
      url = url + "all";
    }
    else {
      url = url + "one";
    }
  }

  popWindowName();

  window.location.href = url;
  return false;
}

function addParameterToUrl(url, newParam, newVal) {
  if (url.indexOf("?") > 0) {
    url = url + "&";
  }
  else {
    url = url + "?";
  }
  url = url + newParam + "=" + newVal;
  return url;
}

function urlEncode(sStr) {
  return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g, '%22').replace(/\'/g, '%27');
}

// Instruct the opening window to reload itself and
// close this window.
function closeWindow() {
  if (window.opener && !window.opener.closed) {
    try {
    opener.location.reload();
  }
    catch (err) {}
  }

  window.close();
  return false;
}

// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window
//    resize -- "no" for non-resizable window, "yes" for resizable window
//    scroll -- "no" for no scrollbars, "yes" for scrollbars
//    returnFunc -- reference to the function (on this page)
//                  that is to act on the data returned from the dialog
//    args -- [optional] any data you need to pass to the dialog
var openingPopup = false;
function openDGDialog(url, width, height, resize, scroll, returnFunc, args) {
  if (!openingPopup) {
    openingPopup = true;
    if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
      var depth = document.getElementById("depth");
      if (url != null && url.length > 0 && url.indexOf("depth") < 0) {
        if (depth != null) {
          if (url.indexOf("?") >= 0) {
            url = url + "&depth=" + depth.value;
          }
          else {
            url = url + "?depth=" + depth.value;
          }
        }
      }
      // Initialize properties of the modal dialog object.
      dialogWin.returnFunc = returnFunc
      dialogWin.returnedValue = ""
      dialogWin.args = args
      dialogWin.url = url
      dialogWin.width = width
      dialogWin.height = height
      // Keep name unique so Navigator doesn't overwrite an existing dialog.
      dialogWin.name = generateWindowName()
      pushWindowName(dialogWin.name);
      // Assemble window attributes and try to center the dialog.
      if (Nav4) {
        // Center on the main window.
        dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2)
        dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2)
        var attr = "screenX=" + dialogWin.left +
                   ",screenY=" + dialogWin.top + ",resizable=" + resize + ",width=" +
                   dialogWin.width + ",height=" + dialogWin.height + ",scrollbars=yes"
      }
      else {
        // The best we can do is center in screen.
        dialogWin.left = (screen.width - dialogWin.width) / 2
        dialogWin.top = (screen.height - dialogWin.height) / 2
        var attr = "left=" + dialogWin.left + ",top=" +
                   dialogWin.top + ",resizable=" + resize + ",width=" + dialogWin.width +
                   ",height=" + dialogWin.height + ",scrollbars=yes"
      }

      // Generate the dialog and make sure it has focus.
      dialogWin.win = window.open(dialogWin.url, dialogWin.name, attr)
      if (dialogWin.win != null) {
        dialogWin.win.focus();
      }
    }
    else {
      if (dialogWin.win != null) {
        dialogWin.win.focus()
      }
    }
    openingPopup = false;
  }
}

function closeChildWindow() {
  if (dialogWin.win != null) {
    dialogWin.win.closeChildWindow();
  }

  window.close();
}

function openChildWindow(win) {
  win.focus();

  if (dialogWin.win != null) {
    win.dialogWin.win.openChildWindow();
  }
}

function setFramesOnclick() {
  if (Nav4) {
    top.frames['topFrame'].onclick = bringAllChildWindowsToForground;
    top.frames['bottom1'].window.frames['headerFrame'].onclick = bringAllChildWindowsToForground;
    top.frames['bottom1'].window.frames['compareLeft'].onclick = bringAllChildWindowsToForground;
    top.frames['bottom1'].window.frames['compareRight'].onclick = bringAllChildWindowsToForground;
  }
  else {
    top.frames['topFrame'].document.attachEvent('onclick', bringAllChildWindowsToForground);
    top.frames['bottom1'].window.frames['headerFrame'].document.attachEvent('onclick', bringAllChildWindowsToForground);
  }
}

function bringAllChildWindowsToForground() {
  //  debug('bring all children...')
  try {
    if (top.frames['bottom1'].window.frames['compareRight'].dialogWin.win != null &&
        top.frames['bottom1'].window.frames['compareRight'].dialogWin.win.closeChildWindow) {
      //Make sure that all the child windows are still on top.
      top.frames['bottom1'].window.frames['compareRight'].focus();
    }
  }
  catch(e) {
  }

  try {
    if (top.frames['bottom1'].window.frames['compareLeft'].dialogWin.win != null &&
        top.frames['bottom1'].window.frames['compareLeft'].dialogWin.win.closeChildWindow) {
      //Make sure that all the child windows are still on top.
      top.frames['bottom1'].window.frames['compareLeft'].focus();
    }
  }
  catch(e) {
  }
}

function generateWindowName(depth) {
  return (findMainWindow(self).windowList.length + 1) + "_" + (new Date()).getSeconds().toString();
}

function parseWindowDepthFromWindowName(windowName) {
  var delimiterPos = windowName.indexOf('_');
  if (delimiterPos == 1) {
    return windowName.substr(0, 1);
  }
  else {
    return windowName.substr(0, delimiterPos - 1);
  }

  return "";
}

function findMainWindow(thisWindow) {
  if (!mainWindowHandle) {
    if (thisWindow.opener != null && !thisWindow.opener.closed && !thisWindow.windowList[0]) {
      mainWindowHandle = findMainWindow(thisWindow.opener);

      if (mainWindowHandle == null) {
        mainWindowHandle = thisWindow;
        try {
          var title = mainWindowHandle.document.title;
    }
        catch (err) {
          mainWindowHandle = null;
        }
      }
      return mainWindowHandle;
    }
    else {
      mainWindowHandle = thisWindow;
      try {
        // Simply check to see if we can retrieve the title of the page - which won't work if this page is outside our domain.
        var title = mainWindowHandle.document.title;
      }
      catch (err) {
        mainWindowHandle = null;
      }
      return mainWindowHandle;
    }
  }
  else {
    return mainWindowHandle;
  }
}

function pushWindowName(name) {
  if (findMainWindow(self)) {
    var winList;
    try {
      winList = mainWindowHandle.windowList;
    }
    catch (e) {
      return null;
    }
    if (winList) {
      winList.push(name);
    }
  }
}

function popWindowName() {
  if (findMainWindow(self)) {
    var winList;
    try {
      winList = mainWindowHandle.windowList;
    }
    catch (e) {
      return null;
    }
    if (winList && winList.length > 0) {
      return winList.pop();
    }
  }
}

function openPostDialog(name, width, height, resize, scroll, returnFunc, args) {
  if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {
    // Initialize properties of the modal dialog object.
    dialogWin.returnFunc = returnFunc;
    dialogWin.returnedValue = "";
    dialogWin.args = args;
    dialogWin.width = width;
    dialogWin.height = height;
    // Keep name unique so Navigator doesn't overwrite an existing dialog.
    dialogWin.name = name;
    pushWindowName(dialogWin.name);
    // Assemble window attributes and try to center the dialog.
    if (Nav4) {

      // Center on the main window.
      dialogWin.left = window.screenX + ((window.outerWidth - dialogWin.width) / 2);
      dialogWin.top = window.screenY + ((window.outerHeight - dialogWin.height) / 2);
      var attr = "screenX=" + dialogWin.left +
                 ",screenY=" + dialogWin.top + ",resizable=" + resize + ",width=" +
                 dialogWin.width + ",height=" + dialogWin.height + ",scrollbars=yes";
    }
    else {
      // The best we can do is center in screen.
      dialogWin.left = (screen.width - dialogWin.width) / 2;
      dialogWin.top = (screen.height - dialogWin.height) / 2;
      var attr = "left=" + dialogWin.left + ",top=" +
                 dialogWin.top + ",resizable=" + resize + ",width=" + dialogWin.width +
                 ",height=" + dialogWin.height + ",scrollbars=yes";
    }

    // Generate the dialog and make sure it has focus.
    dialogWin.win = window.open('../static/blank.htm', dialogWin.name, attr);
    dialogWin.win.focus();
  }
  else {
    dialogWin.win.focus();
  }
}

// Event handler to inhibit Navigator form element
// and IE link activity when dialog window is active.
function bitbucket() {
  if (dialogWin.win && !dialogWin.win.closed) {
    dialogWin.win.focus()
    return false
  }
}

// Disable form elements and links in all frames for IE.
function disableForms() {
  IELinkClicks = new Array()
  for (var h = 0; h < frames.length; h++) {
    for (var i = 0; i < frames[h].document.forms.length; i++) {
      for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
        frames[h].document.forms[i].elements[j].disabled = true
      }
    }
    IELinkClicks[h] = new Array()
    for (i = 0; i < frames[h].document.links.length; i++) {
      IELinkClicks[h][i] = frames[h].document.links[i].onclick
      frames[h].document.links[i].onclick = bitbucket
    }
    frames[h].window.onfocus = checkModal
    frames[h].document.onclick = checkModal
  }
}

// Restore IE form elements and links to normal behavior.
function enableForms() {
  for (var h = 0; h < frames.length; h++) {
    for (var i = 0; i < frames[h].document.forms.length; i++) {
      for (var j = 0; j < frames[h].document.forms[i].elements.length; j++) {
        frames[h].document.forms[i].elements[j].disabled = false
      }
    }
    for (i = 0; i < frames[h].document.links.length; i++) {
      frames[h].document.links[i].onclick = IELinkClicks[h][i]
    }
  }
}

function blockOpenerEvents() {
  if (opener && !opener.closed) {
    try {
      opener.blockEvents();
    }
    catch (e) {
      // Do nothing; just hide the exception.
    }
  }
}

// Grab all Navigator events that might get through to form
// elements while dialog is open. For IE, disable form elements.
function blockEvents() {
  if (Nav4) {
    window.captureEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
    window.onclick = bitbucket
    window.onmousedown = bitbucket
    window.onmouseup = bitbucket
    window.ondrag = bitbucket
  }
  else {
    disableForms()
  }
  window.onfocus = checkModal
}

function unblockOpenerEvents() {
  if (opener && !opener.closed) {
    try {
      opener.unblockEvents();
    }
    catch (e) {
      // Do nothing; just hide the exception.
    }
  }
}

function unblockEventsImpl() {
  if (shouldUnblockEvents) {
    var overlayDiv = document.getElementById("overlayDiv");
    if (overlayDiv != null) {
      overlayDiv.style.display = "none";
    }
    
  if (Nav4) {
    window.releaseEvents(Event.CLICK | Event.MOUSEDOWN | Event.MOUSEUP | Event.FOCUS)
    window.onclick = null
    window.onfocus = null
    window.onmousedown = null
    window.onmouseup = null
    window.ondrag = null
  }
  else {
    enableForms()
  }
}
}
// As dialog closes, restore the main window's original
// event mechanisms.
function unblockEvents() {
  setTimeout("unblockEventsImpl()", 1000);
}

// Invoked by onFocus event handler of EVERY frame,
// return focus to dialog window if it's open.
function checkModal() {
  setTimeout("finishChecking()", 50)
  return true
}

function finishChecking() {
  if (dialogWin.win && !dialogWin.win.closed) {
    dialogWin.win.focus()
  }
}

document.onkeydown = spy;
document.onmousedown = spy;

function spy() {
  userClicked = true;
  if (timerHandle != null) {
    clearTimeout(timerHandle);
  }
  timerHandle = setTimeout("userClicked=false;timerHandle=null;", 2000);
}

function closeExtraWindows() {
  if (!userClicked) {
    if (self.name != null && self.name.length > 0) {
      var depth = parseWindowDepthFromWindowName(self.name);
      var winList = findMainWindow(self).windowList;
      if (depth < winList.length) {
        for (var i = winList.length - 1; i > depth; i--) {
          if (winList[i].name != undefined) {
            var winHandle = window.open("", winList[i], "", "");
            if (winHandle && !winHandle.closed) {
              winHandle.close();
            }
          }
          else {
            popWindowName();
          }
        }
      }
    }
  }
}

function notifyUSys() {
    if (!userClicked && shouldNotifyUsys) {
    closeExtraWindows();

    if (opener && !opener.closed) {
      opener.gotoWindowStackLocation();
      // we're setting the opener to null, so IE doesn't exhibit its timing problem where
      // the page refreshes the opener (see line above) and then tries to unblock the opener's
      // events (right when the opener is reloading).
      opener = null;
    }
  }
}

function refreshOpener(location, personId) {
  if (!userClicked) {
    closeExtraWindows();

    if (opener && !opener.closed && location) {
      opener.location.replace(location);
      // we're setting the opener to null, so IE doesn't exhibit its timing problem where
      // the page refreshes the opener (see line above) and then tries to unblock the opener's
      // events (right when the opener is reloading).
      opener = null;
    }
    else if (opener && !opener.closed && personId) {
      opener.refreshChildView(personId);
      // we're setting the opener to null, so IE doesn't exhibit its timing problem where
      // the page refreshes the opener (see line above) and then tries to unblock the opener's
      // events (right when the opener is reloading).
      opener = null;
    }
  }
}

var shouldRefreshMainWindow = false;
function gotoWindowStackLocation() {
  loc = "closepopup?locquery=true";
  var depthElement = document.getElementById('depth');
  if (depthElement != null) {
    var newDepth = parseInt(depthElement.value) + 1;
    loc = loc + "&depth=" + newDepth;
  }
  if (window.detailsFrame != null) {
    shouldRefreshMainWindow = true;
    window.showOverlayDiv("transparent");
    window.detailsFrame.location.replace(loc);
  }
}

function asynchLocationNotify() {
  if (shouldRefreshMainWindow) {
    var loc = window.detailsFrame.document.getElementById('locquery').value;
    shouldRefreshMainWindow = false;
    userClicked = true //close the gate around the notifyUSys call so that we don't refresh the the window beneith us.
    window.location.href = loc;
  }
}

// function to set the focus person before forwarding the window.
function setFocusAndForward(origFocusId) {
  if (!userClicked) {
    var url = "../action/focusforward";
    url = addParameterToUrl(url, "origid", urlEncode(origFocusId));
    url = addParameterToUrl(url, "forward", "true");

    if (!window.opener && window.dialogArguments) {
      window.dialogArguments.location.href = url;
    }
    else if (window.opener && !window.opener.closed) {
      try {
        window.opener.userClicked = true;
        // Don't notify the system that the window is closing.
        window.opener.location.href = url;
      }
      catch (e) {
        // do nothing, just catch this exception and hide it.
      }
    }

    return false;
  }
}

// function to set the focus person before closing the window.
function setFocusAndClose(origFocusId) {
  var url = "../action/focusforward";
  url = addParameterToUrl(url, "origid", urlEncode(origFocusId));
  url = addParameterToUrl(url, "forward", "false");

  popWindowName();
  var winDepth = document.getElementById("depth");
  if (winDepth != null) {
    url = addParameterToUrl(url, "depth", winDepth.value);
  }
  window.location.href = url;

  return false;
}

// Function to close all the popups and put the user back to the main page.
function closeAllPopups() {
  if (self.name != null && self.name.length > 0) {
    var winList = findMainWindow(self).windowList;
    if (1 < winList.length) {
      for (var i = winList.length - 1; i >= 0; i--) {
        var winHandle = window.open("", winList[i], "", "");
        if (winHandle && !winHandle.closed) {
          winHandle.close();
        }
      }
    }
  }
}

// Show the debug window
function showDebug() {
  findMainWindow(self).debugWindow = window.open("", "Debug", "left=0,top=0,width=300,height=700,scrollbars=yes,status=yes,resizable=yes", false);
  if (!findMainWindow(self).debugWindow) {
    alert('Unable to create the debug window!');
    return false;
  }
  findMainWindow(self).debugWindow.opener = self;
  // open the document for writing
  findMainWindow(self).debugWindow.document.open();
  findMainWindow(self).debugWindow.document.write(
    "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY><PRE id='preTag'></PRE></BODY></HTML>");
}

// If the debug window exists, then write to it
function debug(text) {
  if (!findMainWindow(self).debugWindow) {
    showDebug();
  }
  if (findMainWindow(self).debugWindow && ! findMainWindow(self).debugWindow.closed) {
    var theDoc = findMainWindow(self).debugWindow.document;
    var newEl = theDoc.createTextNode(text);
    var nodeToInsertBefore = theDoc.getElementById('preTag').firstChild;
    theDoc.getElementById('preTag').insertBefore(newEl, nodeToInsertBefore);
    theDoc.getElementById('preTag').insertBefore(theDoc.createElement('BR'), nodeToInsertBefore);
  }
}

// If the debug window exists, then close it
function hideDebug() {
  if (findMainWindow(self).debugWindow && ! findMainWindow(self).debugWindow.closed) {
    findMainWindow(self).debugWindow.close();
    findMainWindow(self).debugWindow = null;
  }
}

var getSelectedParentsGuard = false;
function getSelectedParents(relativeType, name) {
  if (!getSelectedParentsGuard) {
    showOuterWaitIndicator();
    getSelectedParentsGuard = true;
  var obj = document.getElementsByName(name);
  var selectedIndex = -1;
  if (obj) {
    for (var j = 0; j < obj.length; j++) {
      if (obj[j].checked) {
        selectedIndex = j + 1;
      }
    }
  }
  var fatherId = document.getElementById("fatherid" + selectedIndex);
  var motherId = document.getElementById("motherid" + selectedIndex);
  var familyId = document.getElementById("familyid" + selectedIndex);
  familyId = familyId != null ? familyId:"";
  var bookId = document.getElementById("bookid");

  var ids = "&bookid=" + bookId.value + "&manid=";
  if (fatherId != null) {
    ids = ids + fatherId.value;
  }
  ids = ids + "&womanid=";
  if (motherId != null) {
    ids = ids + motherId.value;
  }
  ids = ids + "&familyid=";
  if (familyId != null) {
    ids = ids + familyId.value;
  }

  if (relativeType == "f") {
    document.multipleparents.action = "resolveduplicatepersons?relativetype=f" + ids;
  }
  else if (relativeType == "m") {
    document.multipleparents.action = "resolveduplicatepersons?relativetype=m" + ids;
  }
  else {
    document.multipleparents.action = "resolveduplicatepersons?relativetype=s";
  }
  document.multipleparents.submit();
    setTimeout("clearGetSelectedParentsGuard()", WAIT_IMG_TIMEOUT);
}
}

function clearGetSelectedParentsGuard() {
  getSelectedParentsGuard = false;
}

var getDuplicateParentsGuard = false;
function getDuplicateParents(relativeType) {
  if (!getDuplicateParentsGuard) {
    showOuterWaitIndicator();
    getDuplicateParentsGuard = true;
  var manId = document.getElementById("manid");
  var womanId = document.getElementById("womanid");
  var bookId = document.getElementById("bookid");
  var ids = "&bookid=" + bookId.value + "&manid=" + manId.value + "&womanid=" + womanId.value;
  if (relativeType == "f") {
    document.matchingRecordsForm.action = "resolveduplicatepersons?relativetype=f" + ids;
  }
  else if (relativeType == "m") {
    document.matchingRecordsForm.action = "resolveduplicatepersons?relativetype=m" + ids;
  }
  else {
    document.matchingRecordsForm.action = "resolveduplicatepersons?relativetype=s";
  }
  document.matchingRecordsForm.submit();
    setTimeout("clearGetDuplicateParentsGuard()", WAIT_IMG_TIMEOUT);
}
}

function clearGetDuplicateParentsGuard() {
  getDuplicateParentsGuard = false;
}

function viewMultipleParents() {
  var bookId = document.getElementById("bookid");
  var returnbookId = document.getElementById("returnbookid");
  var familyId = document.getElementById("familyid");
  var returnfamilyId = document.getElementById("returnfamilyid");
  var datapath = document.getElementById("datapath");
  var findex = document.getElementById("findex");
  var ids = "bookid=" + bookId.value + "&returnbookid=" + returnbookId.value + "&familyid=" + familyId.value + "&returnfamilyid="
    + returnfamilyId.value + "&datapath=" + datapath.value + "&findex=" + findex.value;
  document.matchingRecordsForm.action = "parentview?" + ids;
  document.matchingRecordsForm.submit();
}

function viewMultipleSpouses() {
  var bookId = document.getElementById("bookid");
  var returnbookId = document.getElementById("returnbookid");
  var familyId = document.getElementById("familyid");
  var returnfamilyId = document.getElementById("returnfamilyid");
  var datapath = document.getElementById("datapath");
  var findex = document.getElementById("findex");
  var ids = "bookid=" + bookId.value + "&returnbookid=" + returnbookId.value + "&familyid=" + familyId.value + "&returnfamilyid="
    + returnfamilyId.value + "&datapath=" + datapath.value + "&findex=" + findex.value;
  document.matchingRecordsForm.action = "spouseview?" + ids;
  document.matchingRecordsForm.submit();
}

var getSelectedSpouseGuard = false;
function getSelectedSpouse(relativeType, name) {
  if (!getSelectedSpouseGuard) {
    showOuterWaitIndicator();
    getSelectedSpouseGuard = true;
  var obj = document.getElementsByName(name);
  var selectedIndex = -1;
  if (obj) {
    for (var j = 0; j < obj.length; j++) {
      if (obj[j].checked) {
        selectedIndex = j + 1;
      }
    }
  }
  var bookId = document.getElementById("bookid");
  var spouseId = document.getElementById("spouseid" + selectedIndex);
  var familyId = document.getElementById("familyid" + selectedIndex);
  var ids = "&bookid=" + bookId.value + "&spouseid=" + spouseId.value + "&familyid=" + familyId.value;
  document.multiplespouse.action = "resolveduplicatepersons?relativetype=s" + ids;
  document.multiplespouse.submit();
    setTimeout("clearGetSelectedSpouseGuard()", WAIT_IMG_TIMEOUT);
}
}

function clearGetSelectedSpouseGuard() {
  getSelectedSpouseGuard = false;
}

function updateParentWindow() {
  if (opener && !opener.closed) {
    opener.unblockEvents();
    refreshOpener(mainWindowLocation, personId);
    setTimeout("cancelWindow()", 2000);
  }
}

function showWaitIndicator() {
  if (!childPageLoaded) {
    showOuterWaitIndicatorImpl();
      }
  return true;
}

function switchWaitMessage() {
  var pleaseWaitDiv = document.getElementById("pleaseWaitDiv");
  childPageLoaded = false;

  if (pleaseWaitDiv) {
    var waitMsg1 = document.getElementById("waitMsg1");
    var waitMsg2 = document.getElementById("waitMsg2");
    var waitMsg3 = document.getElementById("waitMsg3");

    if (childViewPage && childViewPage == 7) {
      waitMsg1.style.display = "none";
      waitMsg2.style.display = "none";
      waitMsg3.style.display = "block";
    }
    else {
      waitMsg1.style.display = "block";
      waitMsg2.style.display = "none";
      waitMsg3.style.display = "none";
    }
  }

  return true;
}

function hideWaitIndicator() {
  var pleaseWaitDiv = document.getElementById("pleaseWaitDiv");
  var overlayDiv = document.getElementById("overlayDiv");

  if (pleaseWaitDiv) {
    pleaseWaitDiv.style.visibility = "hidden";
    pleaseWaitDiv.style.display = "none";
  }

  if (overlayDiv) {
    overlayDiv.style.display = "none";
  }

  //Reset our message back to the default.
  document.getElementById("waitMsg1").style.display = "";
  document.getElementById("waitMsg2").style.display = "none";
  document.getElementById("waitMsg3").style.display = "none";

  if (top.frames['topFrame']) {
    top.frames['topFrame'].document.body.style.cursor = "default";
  }
  else {
    document.body.style.cursor = "default";
  }

  childPageLoaded = true;
  return true;
}

function stopWaiting() {
  if (Nav4) {
    window.stop();
  }
  else {
    document.execCommand("Stop");
  }

  if (window["xmlHttpRequest"]) {
    //We are clearing the onreadystatechange property to our xmllHttpRequest so that the callback won't happen when aborting.
    xmlHttpRequest.onreadystatechange = new function() {};
    xmlHttpRequest.abort();
  }

  //Stop the xmlHttpRequest object on our compare duplicates page.
  if (top.frames["bottom1"]) {
    if (top.frames['bottom1'].window.frames["compareLeft"].xmlHttpRequest) {
      top.frames['bottom1'].window.frames["compareLeft"].xmlHttpRequest.abort();
    }
    if (top.frames['bottom1'].window.frames["compareRight"].xmlHttpRequest) {
      top.frames['bottom1'].window.frames["compareRight"].xmlHttpRequest.abort();
    }
  }
  hideWaitIndicator();
}

function UpdateImg(imageID, imgsrc) {
  var img = document.getElementById(imageID);
  img.src = imgsrc;
}

function showOuterWaitIndicator() {
  setTimeout("showOuterWaitIndicatorImpl()", WAIT_IMG_TIMEOUT);
}

function showOuterWaitIndicatorImpl() {
  showOverlayDiv("white");
  //gradualFade();
  var waitDiv = document.getElementById("pleaseWaitDiv");
  var calculatedTop = (((document.body.clientHeight / 2) + document.body.scrollTop) - 75);
  waitDiv.style.top = calculatedTop > 0 ? calculatedTop : document.body.scrollTop;
  waitDiv.style.visibility = "visible";
  waitDiv.style.display = "block";
}

function showOverlayDiv(backgroundColor) {
  var overlayDiv = document.getElementById("overlayDiv");
  if (!overlayDiv) {
    overlayDiv = document.createElement("div");
    document.body.appendChild(overlayDiv);
    overlayDiv.id = "overlayDiv";
  }

  overlayDiv.style.display = "block";
  overlayDiv.style.position = "absolute";
  overlayDiv.style.top = 0.0;
  overlayDiv.style.width = "100%";
  overlayDiv.style.height = document.body.scrollHeight;
  overlayDiv.style.backgroundColor = backgroundColor;
  overlayDiv.style.zIndex = 2000;

  if (Nav4) {
    overlayDiv.style.opacity = .70;
    }    
  else {
    overlayDiv.style.filter = "alpha(opacity=70)";
  }
}

var currentOpacity = 0;
var OPACITY_INCREMENT = .03;
var OPACITY_DURATION = 25;
var OPACITY_MAXIMUM = .70;
function gradualFade() {
  var overlayDiv = document.getElementById("overlayDiv");

  if (currentOpacity < OPACITY_MAXIMUM) {
    currentOpacity += OPACITY_INCREMENT;
    if (Nav4) {
      overlayDiv.style.opacity = currentOpacity;
      }
    else {
      overlayDiv.style.filter = "alpha(opacity=" + (currentOpacity * 100) + ")";  //opacity scale for IE is 0 to 100 instead of 0 to 1;
    }

    setTimeout("gradualFade()", OPACITY_DURATION);
      }
  else {
    currentOpacity = 0;  //reset current opacity back to 0 for next fade effect.
    }
  }

function displayPrintTemplePage(url) {
  window.close();
  opener.openDGDialog(url, 550, 430, "no", "no");
}