function Format() {
        var len= arguments.length;
        if (len < 1) return null;
        var format= arguments[0];
        var re= new RegExp("(\{(.+?)\})", "ig"); // ? - non-gready matching
        var arr;
        var result= "";
        var index, si, ei;
        ei= 0;
        while ((arr= re.exec(format)) != null) {
                si= arr.index;
                result+= format.substring(ei, si);
                ei= arr.lastIndex;
                index= parseInt(RegExp.$2);
                if (index + 1 < len) result+= arguments[index + 1];
        }
        result+= format.substr(ei);
        return result;
    }

	function res_RunModalControl(wsroot, CtlPath, width, height, aux_query, Title, params, features) {
        var url= wsroot + "/ASP.Net/Resources/Modal/ModalPageRunner.aspx";
        if (Title == null) Title= "Modal Control";
        var Mode= 0; // modal control
        var query= Format("wpMode={0}&CtlPath={1}&Title={2}&{3}", Mode, CtlPath, Title, aux_query);
//        window.open(url + "?" + query);
        return res_ShowModalDialog(url, query, params, width, height, features);
    }

    function res_ShowModalDialog(url, query, params, width, height, features) {
        //"status:no;help:no;resizable:" + isResizable + ";scroll:no;dialogHeight:" + height + "px;dialogWidth:" + width + "px";
        if(features == null) features= "";
        if(features.search("dialogWidth") < 0) features= "dialogWidth:" + width + "px;" + features;
        if(features.search("dialogHeight") < 0) features= "dialogHeight:" + height + "px;" + features;
        if(features.search("scroll") < 0) features= "scroll:yes;"  + features;
        if(features.search("help") < 0) features= "help:no;"  + features;
        if(features.search("resizable") < 0) features= "resizable:no;"  + features;
        if(features.search("status") < 0) features= "status:no;"  + features;
        return window.showModalDialog(url + "?" + query, params, features);
    }

    function res_RunHtmlEditorForUrl(ResourceUrl) {
        return res_RunHtmlEditor2(null, null, null, ResourceUrl);
    }
    function res_RunHtmlEditor4WebPart(wpID) {
        return res_RunHtmlEditor2(null, null, wpID, null);
    }
// PageUrl - relative path to HtmlPage
// HtmlValue - HTML value
// wpID - Web Part ID for flushing web part cache
