Dialog2 = function(url,note_id) {
	this.note_id = note_id;
	this.url = url;
	this.width = Ext.getBody().getWidth();
    this.createOverlay(note_id);
	this.loaded = false;
	this.loadMaskPanel.render(document.body);
	this.overlay.render(document.body);
	this.closebtn.render(document.body);
    this.overlay.body.on('click', this.hide, this);
	this.closebtn.body.on('click', this.hide, this);
	this.loadMaskPanel.setPagePosition(0,0);
	this.loadMask = new Ext.LoadMask('noteloadmask'+note_id);
	Ext.EventManager.onWindowResize(this.setPosition, this);
	this.loadMask.show();
    this.dialog_box = new Ext.Panel({
		id: 'notepanel'+note_id,
		frame: false,
		width: this.width,
		autoHeight: true,
		bodyBorder: false,
		border: false,
		bodyStyle: 'text-align: center; background-color: #FFFFFF;',
		floating: true
	});
	Dialog2.superclass.constructor.call(this,{
		id: 'noteobject'+note_id
	});
	this.dialog_box.render(document.body);
    //this.dialog_box.body.on('click', this.hide, this);
};
Ext.extend(Dialog2, Ext.Component, {
  createOverlay: function(note_id) {
	this.loadMaskPanel = new Ext.Panel({
		id: 'noteloadmask'+note_id,
		pageX: 0,
		pageY: 0,
		border: false,
		floating: true,
		bodyBorder: false,
		bodyStyle: 'background: none',
		width: Ext.getBody().getWidth(),
		height: Ext.getBody().getHeight()
	});
	/*
	if ( $('notecloser') == null ) {
		var btn = document.createElement('IMG');
		btn.src = HOME_DIR+'images/x.gif';
		btn.id = 'notecloser';
		btn.style.position = 'absolute';
		btn.style.cursor = 'pointer';
		document.body.insertBefore(btn, document.body.childNodes[0]);
	}
	this.closebtn = new Ext.Element('notecloser');
	this.closebtn.hide();
	*/
	this.closebtn = new Ext.Panel({
		id: 'closebtn'+note_id,
		pageX: 0,
		pageY: 0,
		border: false,
		floating: true,
		bodyBorder: false,
		bodyStyle: 'background: none',
		width: 20,
		height: 20,
		html: { tag: 'img', src: HOME_DIR+'images/x.gif', style: 'cursor: pointer' }
	});
	this.overlay = new Ext.Panel({
		id: 'noteoverlay'+note_id,
		pageX: 0,
		pageY: 0,
		cls: 'note-overlay',
		border: false,
		floating: true,
		bodyBorder: false,
		bodyStyle: 'background: none',
		width: Ext.getBody().getWidth(),
		height: Ext.getBody().getHeight()
	});
  },
  setWidth: function(inwidth) {
	 this.width = inwidth;
  },
  moveDialogBox: function(where) {
    Element.remove(this.dialog_box);
    if(where == 'back')
      this.dialog_box = this.parent_element.appendChild(this.dialog_box);
    else
      this.dialog_box = this.overlay.parentNode.insertBefore(this.dialog_box, this.overlay);
  },

  show: function() {
	//this.overlay.setPagePosition(0,0);
	//this.overlay.getEl().fadeIn({endOpacity: .3, duration: 0});
    this.selectBoxes('hide');
	if ( this.loaded ) {
		this.done();
		return;
	}
	else {
		this.dialog_box.load(
			{
				url: this.url,
				scripts: true
			}
		);
	}
  },

  hide: function() {
    this.selectBoxes('show');
    $A(this.dialog_box.getEl().dom.getElementsByTagName('input')).each(function(e){if(e.type!='submit')e.value=''});
	//this.dialog_box.getEl().fadeOut();
	//this.overlay.getEl().fadeOut();
	this.dialog_box.hide();
	this.closebtn.hide();
	this.overlay.hide();
  },

	done: function() {
		this.loadMask.hide();
		this.loadMaskPanel.hide();
		this.overlay.show();
		this.overlay.setPagePosition(0,0);
		var w = Ext.getBody().getWidth();
		var h = Ext.getBody().getHeight();
		if ( w < 1231 ) w = 1231;
		if ( h < 805 ) h = 805;
		this.overlay.setWidth(w);
		this.overlay.setHeight(h);
		this.overlay.getEl().setWidth(w);
		this.overlay.getEl().setHeight(h);
		this.dialog_box.getEl().fadeIn({endOpacity: 1, duration: 0.2});
		this.dialog_box.setWidth(this.width);
		//var top = (this.overlay.getInnerHeight()/2) - (this.dialog_box.getInnerHeight()/2);
		//var left = (this.overlay.getInnerWidth()/2) - (this.dialog_box.getInnerWidth()/2);
		var b_dims = Element.getDimensions('maintable');
		var left = ((b_dims.width/2) - (this.dialog_box.getInnerWidth()/2));
		var top = ((b_dims.height/2) - (this.dialog_box.getInnerHeight()/2));
		this.dialog_box.setPagePosition(left,top);
		this.closebtn.setPagePosition(left+this.dialog_box.getInnerWidth()-18,top+4);
		this.closebtn.show();
		this.closebtn.getEl().setStyle('z-index',(this.dialog_box.getEl().getStyle('z-index')*1)+1);
		this.loaded = true;
	},

	setPosition: function() {
		this.overlay.setPagePosition(0,0);
		var w = Ext.getBody().getWidth();
		var h = Ext.getBody().getHeight();
		if ( w < 1231 ) w = 1231;
		if ( h < 805 ) h = 805;
		this.overlay.setWidth(w);
		this.overlay.setHeight(h);
		this.overlay.getEl().setWidth(w);
		this.overlay.getEl().setHeight(h);
		//var top = (this.overlay.getInnerHeight()/2) - (this.dialog_box.getInnerHeight()/2);
		//var left = (this.overlay.getInnerWidth()/2) - (this.dialog_box.getInnerWidth()/2);
		var b_dims = Element.getDimensions('maintable');
		var left = ((b_dims.width/2) - (this.dialog_box.getInnerWidth()/2));
		var top = ((b_dims.height/2) - (this.dialog_box.getInnerHeight()/2));
		this.dialog_box.setPagePosition(left,top);
		this.closebtn.setPagePosition(left+this.dialog_box.getInnerWidth()-18,top+4);
	},
  selectBoxes: function(what) {
    $A(document.getElementsByTagName('select')).each(function(select) {
      Element[what](select);
    });

    if(what == 'hide')
      $A(this.dialog_box.getEl().dom.getElementsByTagName('select')).each(function(select){Element.show(select)})
  }
});