
function Modal( t,show_button )
{
	var its_me = this
	this.nodes = {main:null, close: null, title: null, inner:null,obj:null,close_button:null}
	this.isOpen = false
	this.callback = null
	this.save_parent = null

	this.nodes.main = create_elem("div", {style:'padding:0px;left:0px;top:0px;margin:5%;',
								class:'modal'})

	this.nodes.close = create_elem("img", {src:stock_url.modal_close,
									alt:'X',
									style:'float:right;',
									class:'modal_close'} )
	this.nodes.title = create_elem("div", {class:'modal_title',
											style:''})
	this.nodes.title.appendChild( new_text(t) )

	this.nodes.inner = create_elem("div", {style:'height:100%;',
												class:'modal_inner'})

	this.nodes.close_button = create_elem("input", {style:'display:'+((show_button)?'block':'none')+';',
													type:'button',
													value:'Close this window!'})

	this.nodes.main.appendChild( this.nodes.close )
	this.nodes.main.appendChild( this.nodes.title )
	this.nodes.main.appendChild( this.nodes.inner )
	this.nodes.inner.appendChild( this.nodes.close_button )

	this.Open = function (o,c)	
	{
		this.nodes.obj = get_id(o)
		this.save_parent = this.nodes.obj.parentNode
		this.nodes.inner.insertBefore(this.nodes.obj,this.nodes.close_button)
		hide_id("body_main_div")
		if (c)
			this.callback = c
		get_id("body").appendChild(this.nodes.main)
	}

	this.Close = function()
	{
		this.nodes.inner.removeChild(this.nodes.obj)
		if ( this.save_parent )
			this.save_parent.appendChild(this.nodes.obj)
		get_id("body").removeChild(this.nodes.main)
		show_id("body_main_div")
		if ( this.callback )
			this.callback()
	}

	this.SetTitle = function(t)
	{
		this.nodes.title.innerHTML = t
	}

	this.ShowClose = function(x)
	{
		if (!x)
			hide_id(this.nodes.close)
		else
			show_id(this.nodes.close)
	}

	this.ShowCloseButton = function (x)
	{
		if (!x)
			hide_id(this.nodes.close_button)
		else
			show_id(this.nodes.close_button)
	}

	this.GetDim = function ()
	{
		return get_dim( this.nodes.inner )
	}
	this.Adapt = function ()
	{
		var d = get_dim(this.nodes.obj)
		this.nodes.inner.style.width = d.width+"px"
		this.nodes.inner.style.height = d.height+"px"
	}
	addEvent( this.nodes.close, "click", function (e) { its_me.Close() })
	addEvent( this.nodes.close_button, "click", function (e) {	its_me.Close() })

}

function Wait( container )
{
	this.callback = null
	this.obj = get_id(container)
	this.started = false
	this.nodes = {main:null,img:null}

	this.nodes.main = create_elem("div", {class:'wait_div'})
	this.nodes.img = create_elem("img", {src:stock_url.wait,
									alt:'Please wait...',
									class:'wait_img'} )
	this.nodes.main.appendChild(this.nodes.img)


	this.Start = function(tout,cb)
	{
		this.obj.parentNode.insertBefore( this.nodes.main, this.obj)
		hide_id(this.obj)
		this.started = true
		this.callback = cb
		if ( tout )
			 setTimeout( this.Stop, tout )
	}
	
	this.Stop = function()
	{
		if (this.started)
		{
			this.obj.parentNode.removeChild(this.nodes.main)
			show_id(this.obj)
			this.started = false
			if ( this.callback )
				this.callback()
		}
	}
}
