var waitbox_state = 0;
var active_waitbox = null;
var WaitBox = function(msg,msg2,innertxt, width, height, exitonesc)
{
    this.message = msg;
    this.subtext = msg2;

    this.innertext = innertxt ? innertxt : null;
    this.width = width ? width : null;
    this.height = height ? height : null; 
    this.exitonesc = exitonesc ? exitonesc : null;
    
    this.gid = "waitbox"+Math.random();
    this.currentshadow = null;
    this.currentdiv = null;

    
    this._ge = function(id){ return document.getElementById(id); }
    this._gt = function(tag){ return document.getElementsByTagName(tag); }
    this._ce = function(tag){ return document.createElement(tag); }

    this.overflow = "auto";
    
    this.Show = function()
    {	
	if(waitbox_state)return;
	active_waitbox = this;
	waitbox_state = 1;
        var b = this._gt("body");
        var div = this._ce("div");
	
	b[0].style.overflow = 'hidden';
        
        div.ID = this.gid+"_shadow";
        div.className="waitboxshadow";
	
        if(this.exitonesc)
	{
		div.onclick = function(){ active_waitbox.Hide(); }

		if($){$(document).keypress(function(event) { if (event.keyCode == '27') { active_waitbox.Hide(); } });}
	}
	    this.currentshadow = div;
	

        b[0].appendChild(div);

        div.ID = this.gid;
	    div = this._ce("div");
	    div.className = "waitbox";

	if( this.width != null ){ div.style.width = parseInt(this.width)+"px"; div.style.marginLeft = "-"+parseInt(this.width/2)+"px"; } 
	if( this.height != null ){ div.style.height = parseInt(this.height)+"px"; div.style.marginTop = "-"+parseInt(this.height/2)+"px"; }

        div.innerHTML = this.innertext != null ? this.innertext :  '<span class="waitboxtxt1">'+this.message+'</span><br /><span class="waitboxtxt2">'+this.subtext+'</span><br /><img src="content/img/cclogo.gif" />';
    
	    this.currentdiv = div;
        
        b[0].appendChild(div);
    }
    
    this.Hide = function()
    {
	try
	{
	        var b = this._gt("body");
		b[0].style.overflow = 'auto';
	        b[0].removeChild(this.currentdiv);        
	        b[0].removeChild(this.currentshadow);        
		waitbox_state = 0;
	}
	catch(e)
	{
	}
    }
}



var waitrect_state = 0;
var active_waitrect = null;
var WaitRect = function(el)
{
    
    this.gid = "waitrect"+Math.random();
    this.currentshadow = null;
    this.currentdiv = null;
    
    this._ge = function(id){ return document.getElementById(id); }
    this._gt = function(tag){ return document.getElementsByTagName(tag); }
    this._ce = function(tag){ return document.createElement(tag); }


    this.target = this._ge(el);

    this.overflow = "auto";
    
    this.Show = function()
    {	
	if(waitrect_state)return;
	active_waitrect = this;
	waitrect_state = 1;

        var div = this._ce("div");
	
	/*b[0].style.overflow = 'hidden';*/
        
        div.ID = this.gid+"_shadow";
        div.className="waitrectshadow";
	    this.currentshadow = div;

        this.target.appendChild(div);

        div.ID = this.gid;
	    div = this._ce("div");
	    div.className = "waitrect";
        div.innerHTML = '<img src="content/img/load.gif" class="waitrectimg" />'; 
    
	    this.currentdiv = div;
        
        this.target.appendChild(div);
    }
    
    this.Hide = function()                            
    {
	try
	{
	        var b = this.target;
		b.style.overflow = 'auto';
	        b.removeChild(this.currentdiv);        
	        b.removeChild(this.currentshadow);        
		waitrect_state = 0;
	}
	catch(e)
	{
	}

	$(document).unbind("keypress");
    }
}
