function Dialog(header_text, body_text, button_text_accept, button_text_cancel)
{
    this.button_text_accept = button_text_accept;
    this.button_text_cancel = button_text_cancel;
    
    this.width = 500;
    this.height = 300;
    
    this.number = Math.floor(Math.random()*10000)
    
    this.show = function()
    {
        var overlay_div = document.createElement('div');
        var text_div = document.createElement('div');
        var shadow_div = document.createElement('div');
        var button_container_div = document.createElement('div');
        var accept_button_div = document.createElement('div');
        var cancel_button_div = document.createElement('div');
        var header_div = document.createElement('div');
        
        overlay_div.id = 'overlay_div_'+this.number;
        text_div.id = 'text_div_'+this.number;
        shadow_div.id = 'shadow_div_'+this.number;
        button_container_div.id = 'button_container_div_'+this.number;
        accept_button_div.id = 'accept_button_div_'+this.number;
        cancel_button_div.id = 'cancel_button_div_'+this.number;
        header_div.id = 'header_div_'+this.number;
        
        overlay_div.style.width = '100%';
        overlay_div.style.height = '100%';
        overlay_div.style.position = 'absolute';
        overlay_div.style.backgroundColor = '#fff';
        overlay_div.style.top = '0px';
        overlay_div.style.left = '0px';
        overlay_div.style.textAlign = 'center';
        overlay_div.style.opacity = .75;
        overlay_div.style.filter = 'alpha(opacity=75);';
        overlay_div.style.zIndex = 100;
        
        
        text_div.innerHTML = body_text;
        text_div.style.top = parseInt((parseInt(this.get_browser_height() - parseInt(this.height)) / 2) + 40)+'px';
        text_div.style.left = parseInt((parseInt(this.get_browser_width() - parseInt(this.width)) / 2))+'px';
        text_div.style.position = 'absolute';
        text_div.style.width = this.width+'px';
        text_div.style.height = parseInt(this.height-40)+'px';
        text_div.style.backgroundColor = '#fff';
        text_div.style.padding = '10px';
        text_div.style.color = '#222';
        text_div.style.zIndex = 115;

        shadow_div.style.top = parseInt((parseInt(this.get_browser_height() - parseInt(this.height)) / 2) - 10)+'px';
        shadow_div.style.left = parseInt((parseInt(this.get_browser_width() - parseInt(this.width)) / 2) - 10)+'px';
        shadow_div.style.position = 'absolute';
        shadow_div.style.width = this.width+20+'px';
        shadow_div.style.height = this.height+20+'px';
        shadow_div.style.backgroundColor = '#999';
        shadow_div.style.padding = '10px';
        shadow_div.style.color = '#fff';
        shadow_div.style.opacity = .5;
        shadow_div.style.filter = 'alpha(opacity=50);';
        shadow_div.style.zIndex = 114;
        shadow_div.style.MozBorderRadius = '5px';

        button_container_div.style.position = 'absolute';
        button_container_div.style.top = parseInt((parseInt(this.get_browser_height() - parseInt(this.height)) / 2)+this.height-35)+'px';
        button_container_div.style.left = parseInt((parseInt(this.get_browser_width() - parseInt(this.width)) / 2))+'px';
        button_container_div.style.width = this.width+'px';
        button_container_div.style.height = '35px';
        button_container_div.style.padding = '10px';
        button_container_div.style.borderTop = '1px solid #999';
        button_container_div.style.backgroundColor = '#eee';
        button_container_div.style.zIndex = 116;
        
        header_div.style.position = 'absolute';
        header_div.style.top = parseInt((parseInt(this.get_browser_height() - parseInt(this.height)) / 2))+'px';
        header_div.style.left = parseInt((parseInt(this.get_browser_width() - parseInt(this.width)) / 2))+'px';
        header_div.innerHTML = header_text;
        header_div.style.padding = '10px';
        header_div.style.backgroundColor = '#293244';
        header_div.style.borderBottom = '1px solid #444';
        header_div.style.fontWeight = 'bold';
        header_div.style.fontSize = '15px';
        header_div.style.color = '#eee';
        header_div.height = '35px';
        header_div.style.width = this.width+'px';
        header_div.style.zIndex = 116;

        if (button_text_accept) {
            accept_button_div.style.position = 'absolute';   
            accept_button_div.innerHTML = button_text_accept;   
            accept_button_div.style.width = '150px';
            accept_button_div.style.height = '20px';
            accept_button_div.style.padding = '7px';
            accept_button_div.style.backgroundColor = '#5872a7';
            accept_button_div.style.fontWeight = 'bold';
            accept_button_div.style.fontSize = '13px';
            accept_button_div.style.color = '#fff';
            accept_button_div.style.textAlign = 'center';
            accept_button_div.style.borderTop = '1px solid #637bad';
            accept_button_div.style.borderLeft = '1px solid #637bad';
            accept_button_div.style.borderRight = '1px solid #111';
            accept_button_div.style.borderBottom = '1px solid #111';
            accept_button_div.style.cursor = 'pointer';
            accept_button_div.obj = this;
            accept_button_div.onclick = function() {
                this.obj.onconfirm();
            }
            button_container_div.appendChild(accept_button_div);
        }
        
        if (button_text_cancel) {
            cancel_button_div.style.position = 'absolute';   
            cancel_button_div.innerHTML = button_text_cancel;   
            cancel_button_div.style.width = '150px';
            cancel_button_div.style.height = '20px';
            cancel_button_div.style.padding = '7px';
            cancel_button_div.style.backgroundColor = '#333';
            cancel_button_div.style.fontWeight = 'bold';
            cancel_button_div.style.fontSize = '13px';
            cancel_button_div.style.color = '#fff';
            cancel_button_div.style.textAlign = 'center';
            cancel_button_div.style.borderTop = '1px solid #637bad';
            cancel_button_div.style.borderLeft = '1px solid #637bad';
            cancel_button_div.style.borderRight = '1px solid #111';
            cancel_button_div.style.borderBottom = '1px solid #111';
            cancel_button_div.style.cursor = 'pointer';
            cancel_button_div.obj = this;
            cancel_button_div.onclick = function() {
                this.obj.oncancel();
            }
            button_container_div.appendChild(cancel_button_div);
        }
        
        if (button_text_accept && button_text_cancel) {
            accept_button_div.style.left = '165px';
            cancel_button_div.style.left = '340px';            
        } else if (button_text_accept) {
            accept_button_div.style.left = '340px';
        } else if (button_text_cancel) {
            cancel_button_div.style.left = '340px';            
        } else {
        
        }
                
        document.getElementById('overlay_origin').appendChild(text_div);
        document.getElementById('overlay_origin').appendChild(header_div);
        document.getElementById('overlay_origin').appendChild(overlay_div);
        document.getElementById('overlay_origin').appendChild(shadow_div);
        if (button_text_accept || button_text_cancel) {
	        document.getElementById('overlay_origin').appendChild(button_container_div);
    	}
    }
    
    this.hide = function()
    {
        document.getElementById('overlay_origin').removeChild(document.getElementById('overlay_div_'+this.number));
        document.getElementById('overlay_origin').removeChild(document.getElementById('text_div_'+this.number));
        document.getElementById('overlay_origin').removeChild(document.getElementById('shadow_div_'+this.number));
        document.getElementById('overlay_origin').removeChild(document.getElementById('button_container_div_'+this.number));
        document.getElementById('overlay_origin').removeChild(document.getElementById('header_div_'+this.number));
    }
    
    this.get_browser_width = function()
    {
        var x = 0;
        if (self.innerHeight) {
            x = self.innerWidth;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            x = document.documentElement.clientWidth;
        } else if (document.body) {
            x = document.body.clientWidth;
        }
        return x;
    }
    
    this.get_browser_height = function()
    {
        var x = 0;
        if (self.innerHeight) {
            x = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            x = document.documentElement.clientHeight;
        } else if (document.body) {
            x = document.body.clientHeight;
        }
        return x;
    }
    
    this.set_content = function(content)
    {
		document.getElementById('text_div_'+this.number).innerHTML = content;
    }
    
    this.onconfirm = function()
    {
        this.hide();
    }
    
    this.oncancel = function()
    {
    	this.hide();
    }
    
    this.show();
          
}

function Ajax()
{
    this.http_req_obj = null;
    this.response_text = null;
    this.response_type = 'RAW';
    this.debug = false;
    
    this.create_http_req_obj = function()
    {
        if (window.XMLHttpRequest) {
            this.http_req_obj = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            this.http_req_obj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
        this.http_req_obj.master = this;
    }
    
    this.post = function(url, params, callback)
    {   
        this.http_req_obj.open('POST', url, true);
        if (this.debug) { alert(url); }
        this.http_req_obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        this.http_req_obj.onreadystatechange = function() {
            if (this.readyState == 4) {
                if (this.master.debug) { alert('response text: '+this.responseText); }
                this.master.response_text = this.responseText;
                if (this.master.debug) { alert('data type: '+this.master.response_type); }
                try {
                    if (this.master.response_type == 'RAW') {
                        callback(this.responseText);
                    } else if (this.master.response_type == 'JSON') {
                        var data = eval('(' + this.responseText + ')');
                        callback(data);
                    }
                } catch (e) {
                    if (this.debug) { alert(e.description); }
                    callback(null);
                }
            }
        }
        
        var ps = this.generate_ps(params);
        if (this.debug) { alert(ps); }
        this.http_req_obj.send(ps);
    }
    
    this.generate_ps = function(params)
    {
        var ps = '';

        if (typeof params == 'object') {
            for (k in params) {
                ps = ps+k+'='+escape(params[k])+'&';
            }
            return ps;
        } else {
            return null;
        }
    }
    
    this.create_http_req_obj();
        
    return true;
} 

function bookmark() 
{
	alert('To add a bookmark, close this and then press CTRL and D (for windows), or COMMAND and D (for mac).');
}

function add_class_name(object, class_name)
{
    var class_found = false;
    var class_string = object.className;
    
    if (class_string) {
        class_elements = class_string.split(' ');
        for (i in class_elements) {
            if (class_elements[i] == class_name) {
                class_found = true;
            }
        }
    }
    
    if (! class_found) {
        object.className = object.className + ' ' + class_name;
    }
}

function remove_class_name(object, class_name)
{
    var class_string = object.className;
    
    if (class_string) {
        class_elements = class_string.split(' ');
        for (i in class_elements) {
            if (class_elements[i] == class_name) {
                delete class_elements[i];
            }
        }
        object.className = class_elements.join(' ');
    }    
}

