var DIALOG_DONE = false;

function DIALOG_show(title, url, height, width) {
  
  DIALOG_HEIGHT = height || 400;
  DIALOG_WIDTH = width || 500;
  if(!DIALOG_DONE) {
    $(document.body)
      .append(	'<div id="DIALOG_overlay"></div><div id="DIALOG_window"><div id="DIALOG_title"></div>'+
         		'<img src="/js/dialog/close.png" alt="Close window"/></div>');
    
	$('#DIALOG_window img').click(DIALOG_hide);
    $('#DIALOG_overlay').click(DIALOG_hide);
    
	$(window).resize(DIALOG_position);
    $(window).scroll(DIALOG_position);
    
	DIALOG_DONE = true;
  }

  $('#DIALOG_frame').remove();
  $('#DIALOG_window').append('<iframe id="DIALOG_frame" src="'+url+'" frameborder="0" border="0"></iframe>');

  $('#DIALOG_title').html(title);
  $('#DIALOG_overlay').show();
  DIALOG_position();
  
  //$('#DIALOG_window').slideDown("slow");
  $('#DIALOG_window').show(); 
}

function DIALOG_hide() {
  $('#DIALOG_window, #DIALOG_overlay').hide();
}

function DIALOG_position()
{
    var de = document.documentElement;
    var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
    var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
    var dsocleft=document.all? iebody.scrollLeft : pageXOffset;
    var dsoctop=document.all? iebody.scrollTop : pageYOffset;
    
    var height = h < DIALOG_HEIGHT ? h - 32 : DIALOG_HEIGHT;
    var top = (h - height)/2 + dsoctop;
	var left = (w - DIALOG_WIDTH)/2 + dsocleft;
    
    $('#DIALOG_window').css({'width':DIALOG_WIDTH+'px', 'height':height+'px', 'left':left+'px', 'top': top+'px' });
    $('#DIALOG_frame').css('height',height - 32 +'px');
    $('#DIALOG_overlay').css({'height':h+'px', 'top':dsoctop + 'px', 'width':w+'px', 'left':dsocleft + 'px'});
}
