// xModalDialog
// by Mike Foster (cross-browser.com)

window.onload = function()
{
  //alert('Load Event');
};
window.onunload = function() // assigning an unload listener disables bfcache (fastback) in Opera and Firefox
{
  //alert('Unload Event');
};

xAddEventListener(window, 'load',
	function() {
		if (document.getElementById && document.createElement && document.body.appendChild) {
			// setup MD - ENVIAR PARA UM AMIGO
			if (xGetElementById('idEnviarAmigoBtn') != null) {
				new xModalDialog('idMDEnviarAmigo');
				xGetElementById('idEnviarAmigoBtn').onclick = function() {
					xModalDialog.instances['idMDEnviarAmigo'].show();
				};
			}
		}
	}, false
);

function xModalDialog(sDialogId) // Object Prototype
{
  /*@cc_on @if (@_jscript_version >= 5.5) @*/ //  not supported in IE until v5.5
  this.dialog = xGetElementById(sDialogId);
  xModalDialog.instances[sDialogId] = this;
  if (!xModalDialog.ele) { // only one per page
    xModalDialog.ele = document.createElement('div');
    xModalDialog.ele.className = 'xModalDialogGreyElement';
    document.body.appendChild(xModalDialog.ele);
  }
  /*@end @*/
}

// Public Methods

xModalDialog.prototype.show = function()
{
  var e = xModalDialog.ele;
  
  if (e) {
    var ds = xDocSize();
    xMoveTo(e, 0, 0);
    xResizeTo(e, ds.w, ds.h);
    if (this.dialog) {
    
      this.dialog.style.display='block';
    
      xMoveTo(this.dialog,
              200,
              xScrollTop()+(xClientHeight()-this.dialog.offsetHeight)/2);
    }
  }
};

xModalDialog.prototype.hide = function()
{
  var e = xModalDialog.ele;
  
  if (e) {
    xResizeTo(e, 10, 10);
    xMoveTo(e, -10, -10);
    if (this.dialog) {
      this.dialog.style.display='none';
      xMoveTo(this.dialog, -(this.dialog.offsetWidth), 0);
    }
  }
};

// Static Properties

xModalDialog.ele = null;
xModalDialog.instances = {};
