// $Name:  $
// $Header: /home/cvs/DC5/dc5_barchasp/www/js/dc_dialog.js,v 1.2 2007/02/27 15:00:08 thoms Exp $

/* Call this function to open a dialog */

function DC_Dialog_Open(dialogmode, dialogwidth, dialogheight, winoptions, url)
{ result = '';

  if (dialogmode == 'window')
	{ if (! winoptions) winoptions = new Array;
	  if (! winoptions[ 'left'        ]) winoptions[ 'left'       ] = 400;
	  if (! winoptions[ 'top'         ]) winoptions[ 'top'        ] = 300;
	  if (! winoptions[ 'screenX'     ]) winoptions[ 'screenX'    ] = 400;
	  if (! winoptions[ 'screenY'     ]) winoptions[ 'screenY'    ] = 300;
	  if (! winoptions[ 'scrollbars'  ]) winoptions[ 'scrollbars' ] = 'yes';
	  if (! winoptions[ 'resizable'   ]) winoptions[ 'resizable'  ] = 'yes';
	  if (! winoptions[ 'dependent'   ]) winoptions[ 'dependent'  ] = 'no';
	  if (! winoptions[ 'location'    ]) winoptions[ 'location'   ] = 'no';
	  if (! winoptions[ 'menubar'     ]) winoptions[ 'menubar'    ] = 'no';
	  if (! winoptions[ 'status'      ]) winoptions[ 'status'     ] = 'no';
	  if (! winoptions[ 'toolbar'     ]) winoptions[ 'toolbar'    ] = 'no';

	  optionstr =
		'width='       + dialogwidth                +
		',height='     + dialogheight               +
		',left='       + winoptions[ 'left'       ] +
		',top='        + winoptions[ 'top'        ] +
		',screenX='    + winoptions[ 'screenX'    ] +
		',screenY='    + winoptions[ 'screenY'    ] +
		',scrollbars=' + winoptions[ 'scrollbars' ] +
		',resizable='  + winoptions[ 'resizable'  ] +
		',dependent='  + winoptions[ 'dependent'  ] +
		',location='   + winoptions[ 'location'   ] +
		',menubar='    + winoptions[ 'menubar'    ] +
		',status='     + winoptions[ 'status'     ] +
		',toolbar='    + winoptions[ 'toolbar'    ];

	  if (! url)
		url = '';

	  // DC_Dialog_Close() and DC_Dialog_GetParent() require the window name to start
	  // with "dc_dialog".

	  // When opening a dialog from a frame within a dialog, the parent name
	  // must be checked.
	  // XXX We currently don't support nested framesets here.

	  myname = window.name;

	  if (parent)
		myname = parent.window.name;

	  // Make sure each new dialogs gets its own name.

	  if (myname.substr(0, 9) == 'dc_dialog')
		{ var now = new Date;
		  winname = 'dc_dialog' + now.getTime();
		}
	  else
		winname = 'dc_dialog';

	  winhandle = window.open(url, winname, optionstr);
	  winhandle.focus();

	  result = winname;
	}
  else if (dialogmode == 'layer')
	{ dialoglayer.resizeTo(dialogwidth, dialogheight);
	  dialoglayer.zIndex(100);         // doesn't matter!?
	  dialoglayer.moveTo('n', 0, true);
	  dialoglayer.show();
	  dialoglayer.slideTo('center','center', 500);

	  if (url)
		dialogframe.location.href = url;

	  result = 'dialogframe';
	  document.getElementById('dcModal').style.visibility = 'visible';
	  document.getElementById('dcModal').style.display = 'block';
	}

  return result;
}


/* Call this function from within the dialog to close it */

function DC_Dialog_Close()
{ if (window.opener && (window.name.substr(0, 9) == 'dc_dialog'))
	{ location.href = 'blank.html';
	  self.close();
	}
  else
	{ parent.dialogframe.location.href = 'blank.html';
	  parent.DC_Main_HideMethodWin();
	  parent.document.getElementById('dcModal').style.visibility = 'hidden';
	  parent.document.getElementById('dcModal').style.display = 'block';
	}
}


/* Call this function from within the dialog to determine the parent or opener */

function DC_Dialog_GetParent()
{ if (window.opener && (window.name.substr(0, 9) == 'dc_dialog'))
    return window.opener;
  else
    return parent;
}


function DC_Dialog_OpenInMainWindow(href_to_open, keep_dialog)
{ // XXX DC_Main_InitWindowName() changes dialog names from dc_dialog to dc5win...
  // That's why we're not checking the window name for 'dc_dialog'.
  // Will confuse people who opened DC5 from another window...

  if (window.opener)
	{ window.opener.location.href = href_to_open;

	  if (! keep_dialog)
		window.close();
	}
  else
	location.href = href_to_open;
}
