    function CenterWin(url, x, y, name)
    {
        n_width  = x;
        n_height = y;
        n_top = (screen.height - n_height)/2-50;
        n_left= (screen.width - n_width)/2;
        param="resizable=yes,scrollbars=yes,status=yes,dependent=no";
        window.open(url, name, "top="+n_top+",left="+n_left+",width="+n_width+",height="+n_height+","+param+"");
        return false;
    }

    function resizeDialogToContent()
    {
        // resize window so there are no scrollbars visible
        var dw = window.dialogWidth;
        while (isNaN(dw))
        {
          dw = dw.substr(0,dw.length-1);
        }
        difw = dw - this.document.body.clientWidth;
        window.dialogWidth = this.document.body.scrollWidth+difw+'px';

        var dh = window.dialogHeight;
        while (isNaN(dh))
        {
          dh = dh.substr(0,dh.length-1);
        }
        difh = dh - this.document.body.clientHeight;
        window.dialogHeight = this.document.body.scrollHeight+difh+'px';
    }
    
    function handleState(data) {
        if (data.status == 0) {
            return true;
        }
    }

    function is_empty_str(str)
    {
        return (str.toString().replace(/ +/i,"")=="");
    }
    
    function format(str, replacements)
    {
        if (typeof(str) != 'string') {return str;}
        if (typeof(replacements) !== 'object' && arguments.length > 2) {
            replacements = Array.prototype.slice.call(arguments, 1);
        }
        for (var i in replacements) {
            if (!replacements.hasOwnProperty(i)) {continue;}
            str = str.replace(new RegExp('\\{' + i + '\\}', 'g'), replacements[i]);
        }
        return str;
    };
    

