function JSDialog(dialogName) {
	if(dialogName == null)
		dialogName = 'jsDialogAction';
	this.dialogName = dialogName;
    document.writeln('<div id="jsDialogShutter" class="jsDialogShutter" style="z-index:101;"><!-- --></div>');
    document.writeln('<div id="jsDialogForm" class="jsDialog" style="z-index:200;"><!-- --></div>');
    document.writeln('<div id="jsDialogCont" class="jsDialogContent" style="z-index:250;">');
    document.writeln(
        '<iframe name="' + dialogName + '" width="100%" height="100%" frameborder="0"' +
        'scrolling="no" src="about:blank" marginheight="0" marginwidth="0">'
    );
    document.writeln('iframe -> will not be supported ...');
    document.writeln('</iframe>');
    document.writeln('</div>');
    
    this.dialogForm = document.getElementById('jsDialogForm');
    this.dialogCont = document.getElementById('jsDialogCont');
    this.jsShutter  = document.getElementById('jsDialogShutter');
    
    this.pos00 = null;
    this.pos01 = null;
    
    this.jsDlg = null;
    
    this.openDialog = function(jsPosName, url, withContext) {
        this.pos00 = jsPosition(
            document.getElementById(jsPosName + 'Start'));
        this.pos01 = jsPosition(
            document.getElementById(jsPosName + 'End'));
        
        this.dialogCont.style.top  = '-50px';
        this.dialogCont.style.left = '-50px';
        this.dialogForm.style.top  = '-50px';
        this.dialogForm.style.left = '-50px';
        
        this.dialogCont.style.width  = '1px';
        this.dialogCont.style.height = '1px';
        this.dialogForm.style.width  = '1px';
        this.dialogForm.style.height = '1px';
        
        this.dialogForm.style.visibility = 'visible';
        this.dialogCont.style.visibility = 'visible';
        
        if(url.indexOf('form:') > -1) {
            var actionForm = document.forms[url.substr(5)];
            if(typeof(actionForm) != 'undefined') {
                this.jsDlg = window.open('about:blank', this.dialogName);
                actionForm.target = this.dialogName;
                actionForm.submit();
            }
        } else {
        	if(withContext == null)
        		withContext = true;
        	this.jsDlg = window.frames[this.dialogName];
        	url = (withContext?contextPath:'') + url;
        	this.jsDlg.location.href = url;
        }
    };
    
    this.startDialog = function(dlgWidth, dlgHeight) {
        if(this.jsDlg == null) return;
        
        this.setShutter(true);
        
        this.dialogForm.style.zIndex = '998';
        this.dialogCont.style.zIndex = '999';
        
        var s = -1;
        var h = -1;
        if (typeof window.pageYOffset == "number") {
            s = window.pageYOffset;
        } else if (typeof document.documentElement.scrollTop == "number") {
            s = document.documentElement.scrollTop;
        } else if (typeof document.body.scrollTop == "number") {
            s = document.body.scrollTop;
        }
        if (typeof window.innerHeight == "number") {
            h = window.innerHeight;
        } else if (typeof document.documentElement.clientHeight == "number") {
            h = document.documentElement.clientHeight;
        } else if (typeof document.body.clientHeight == "number") {
            h = document.body.clientHeight;
        }
        
        var x = this.pos00.x + (this.pos01.x - this.pos00.x - dlgWidth - 30)/2;
        var y = 0;
        if(s > -1 && h > 0) {
            y = s + (h - dlgHeight - 30) / 4;
            if(y < s) {
            	if(dlgHeight < h) y = s + (h - dlgHeight - 30)/2;
            	else y = s;
            }
        } else {
            y = this.pos00.y + (this.pos01.y - this.pos00.y - dlgHeight - 30)/2;
            if(y + dlgHeight > this.pos01.y) y = this.pos01.y - dlgHeight;
        }
        if(y < 0) y = 0;
                
        this.dialogForm.style.top  = y + 'px';
        this.dialogForm.style.left = x + 'px';
        this.dialogForm.style.width  = (dlgWidth + 30) + 'px';
        this.dialogForm.style.height = (dlgHeight + 30) + 'px';
        
        this.dialogCont.style.top  = y + 'px';
        this.dialogCont.style.left = x + 'px';
        this.dialogCont.style.width  = dlgWidth + 'px';
        this.dialogCont.style.height = dlgHeight + 'px';
        
        this.jsDlg.focus();
    };
    
    this.closeDialog = function() {
    	if(this.jsDlg != null)
    		this.jsDlg.location.replace('about:blank');
        
        this.dialogCont.style.visibility = 'hidden';
        this.dialogForm.style.visibility = 'hidden';
        
        if(this.setShutter(false)) {
            this.jsDlg = null;
        }
    };
    
    this.setShutter = function(enable) {
        if(typeof(this.jsShutter) != 'undefined') {
            if(enable) {
                var height_ = jsBodyTag.offsetHeight;
                var width_  = jsBodyTag.offsetWidth;
                if(height_ < jsEndSite.offsetTop)
                    height_ = jsEndSite.offsetTop;
                this.jsShutter.style.height = height_ + 'px';
                this.jsShutter.style.width  = width_ + 'px';
                this.jsShutter.style.visibility = "visible";
                return true;
            } else {
                this.jsShutter.style.visibility = "hidden";
                return true;
            }
        }
        return false;
    }
}