  //Child window-specific JS fcuntions

  //(c) 2004 Jean-Yves Rouffiac. All Rights Reserved.

  //Tarithel 1.2.0 - [Patton] - 2006-02-28
  //Added updateChildRefInParent() which updates the window
  //references from the main game window to the child windows
  //every 250 msecs
  //Tarithel 1.2.0 - [Patton] - 2006-03-01
  //Changed closeIfParentClosed() and updateChildRefInParent()
  //so they should both work, in different directions
  //now a close of the parent window should force a close of
  //all the child windows
  //- this relates to bug #48

  //Close child windows after certain preset time if parent has closed
	var parent_window = window.opener;

	function closeIfParentClosed() {
		if (parent_window) {
			var isClosed = true;
			if (!parent_window.closed) {
				isClosed = false;
			}
			if (isClosed){
				window.close();
			}
		} else {
			parent_window = window.opener;
		}
	}

	//Update references in the parent window to the named child windows
	function updateChildRefInParent() {
		if (parent_window) {
			switch(window.name) {
				case "thinkWin":
					parent_window.thinkWindow = window.self;
					break;
				case "hereWin":
					parent_window.hereWindow = window.self;
					break;
				case "aheadWin":
					parent_window.aheadWindow = window.self;
					break;
				case "journalWind":
					parent_window.journalWindow = window.self;
					break;
				case "vassalsWin":
					parent_window.vassalsWindow = window.self;
					break;
				case "strongholdsWin":
					parent_window.strongholdsWindow = window.self;
					break;
				case "treasuryWin":
					parent_window.treasuryWindow = window.self;
					break;
				case "victoriesWin":
					parent_window.victoriesWindow = window.self;
					break;
				case "defeatsWin":
					parent_window.defeatsWindow = window.self;
					break;
				case "mapsWin":
					parent_window.mapsWindow = window.self;
					break;
				case "distributeWin":
					parent_window.distributeWindow = window.self;
					break;
				case "battlesWin":
					parent_window.battleWindow = window.self;
					break;
			}
		} else {
			parent_window = window.opener;
		}
	}

  // Start the check parent interval timer.
  var checkParentIntervalID = window.setInterval("closeIfParentClosed()", 500);

  var checkParentIntervalID = window.setInterval("updateChildRefInParent()", 250);
