String.format = function(str) {
    var args = arguments, re = new RegExp("%([1-" + args.length + "])", "g");
    return String(str).replace(
    re,
    function($1, $2) {
        return args[$2];
    }
    );
};

String.formatmodel = function(str,model){
	for(var k in model){
		var re = new RegExp("{"+k+"}","g");
		str = str.replace(re,model[k]);
	}
	return str;
}

var  Util = {};

/*
* 配置信息
*/
Util.Config = {
    //遮罩层背景颜色
    Screen_Background: "#FFF",
    //遮罩层透明度
    Screen_Opacity: "4",
    //遮罩层内容背景颜色
    Screen_ContentBg: "transparent",
    Screen_PositionTop:"0",
    Screen_PositionLeft:"50%",

    //结果隐藏时间
    Result_HideTime:4000,
    //结果背景色（警告）
    Result_Alert_BgColor:"#FFE222",
    //结果背景色（成功）
    Result_Success_BgColor:"#008000",
    //结果背景色（失败）
    Result_Failed_BgColor:"#D84544",
    //结果字体色（警告）
    Result_Alert_FontColor:"#000",
    //结果字体色（成功）
    Result_Success_FontColor:"#fff",
    //结果字体色（失败）
    Result_Failed_FontColor:"#fff",

    TextBoxDefaultColor: "#666",
    TextBoxActiveColor:"#000",
    EnterCallback: false,
    EscCallback: false,
    BindEnterStatus: false
}
Util.CACHE = {};

Util.Load = {
    JS: function(url,complete){
        var code = document.createElement("script");
        code.src = url;
        code.onload = (function(){
            document.body.removeChild(code);
            if(complete) complete();
        })
        code.onreadystatechange = (function(){
            if(code.readyState == "complete" || code.readyState == "loaded"){
                document.body.removeChild(code);
                if(complete) complete();
            }
        });
        document.body.appendChild(code);
    }
}

function getClipboardData(){
	window.document.ff_clipboard_swf.SetVariable('str', Util.CACHE.CLIPBOARD_TEXT);
}

function hideMenu(){
	Util.CACHE.CopyBox && Util.CACHE.CopyBox.hide();
}

/*
*
* 复制
*/
Util.Copy = function(pStr,hasReturn, isdo){
	var result = false;
    //IE
    if(window.clipboardData)
    {
        window.clipboardData.clearData();
        result = window.clipboardData.setData("Text", pStr);
    }
    //FireFox
    else
    {
		if(top.window && !isdo){
			top.window.Util.Copy(pStr,hasReturn, true);
			return;
		}
		Util.CACHE.CLIPBOARD_TEXT = pStr;
		if(!Util.CACHE.CopyBox){
			Util.CACHE.CopyBox = $('<div id="ff_clipborad_swf_box" style="position:absolute;width:220px;padding:8px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;background:#CBCBCB;background:rgba(0, 0, 0, 0.2);overflow:hidden; z-index:99999999999;">'+
				'<div style="padding:6px 10px 10px;background:#FFF;overflow:hidden;">'+
					'<h3 style="height:30px;margin:0;padding:0;overflow:hidden;font-size:14px;"><span style="float:left;line-height:30px;">提示信息</span><a href="javascript:;" style="float:right;width:18px;height:18px;margin-top:5px;line-height:18px;text-align:center;overflow:hidden;font-size:12px;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;color:#FFF;background:#A4A4A4;" onclick="'+"$('#ff_clipborad_swf_box').hide();"+'">X</a></h3>'+
					'<div style="position:relative;height:40px;overflow:hidden;line-height:35px;text-align:center;text-decoration:underline;" id="js_ff_copy_box_con">点此复制到剪切板</div>'+
				'</div>'+
			'</div>');
			//创建Flash按钮
			$(document.body).append(Util.CACHE.CopyBox);
		}
		if(document.getElementById('ff_clipboard_swf')){
			$("#ff_clipboard_swf").empty().remove();
		}
		var html = [];
		html.push('<object type="application/x-shockwave-flash" data="/static/js2/clipboard.swf" width="200" height="40" style="position:relative;top:-35px;" id="ff_clipboard_swf">');
		html.push('<param name="quality" value="high" />');
		html.push('<param name="allowScriptAccess" value="sameDomain" />');
		html.push('<param name="allowFullScreen" value="true" />');
		html.push('<param name="wmode" value="transparent" />');
		html.push('</object>');
		$("#js_ff_copy_box_con").append(html.join(""));
		Util.Layer.Center(Util.CACHE.CopyBox);
		Util.CACHE.CopyBox.show();
		return;
    }
	if(hasReturn){
    	return result;
	}
	else{
		if(result){
			 alert("内容已复制至剪贴板");
		}
		else{
			alert("复制失败! 您使用的浏览器不支持复制功能。");
		}
	}
}

/*
* 弹出层
*/
Util.ScreenManager = {
    /*Public 隐藏方法*/
    Hide: function(doFun){
        this.canClose = true;
        this.popCoverDiv(false);
        if(doFun){
            doFun();
        }
        if(Util.Config.EnterCallback){
            Util.Config.EnterCallback = false;
        }
        if(Util.Config.EscCallback){
            Util.Config.EscCallback = false;
        }
    },
    /*Public 显示方法*/
    Show: function(containBox,isClickHide){
        if(!Util.Config.BindEnterStatus){
            
            $(document).bind("keyup", function(e){
                if(e.keyCode == 13){
                    if(Util.Config.EnterCallback){
                        Util.Config.EnterCallback();
                    }
                }
                else if(e.keyCode == 27){
                    if(Util.Config.EscCallback){
                        Util.Config.EscCallback();
                    }
                }
            })
            Util.Config.BindEnterStatus = true;
        }
        if(isClickHide != undefined){
            Util.ScreenManager.IsClickHide = isClickHide;
        }
        else{
            Util.ScreenManager.IsClickHide = false;
        }
        this.popCoverDiv(true,containBox);
    },
    //取得页面的高宽
    getBodySize: function (){
        var bodySize = [];
        with(document.documentElement) {
            bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;//如果滚动条的宽度大于页面的宽度，取得滚动条的宽度，否则取页面宽度
            bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;//如果滚动条的高度大于页面的高度，取得滚动条的高度，否则取高度
            }
        return bodySize;
    },
    config:{
        cachebox:"screen_cache_box",/*缓存层*/
        contentbox:"screen_content_box",/*内容层*/
        coverbox:"screen_cover_div",/*透明层*/
        gonebox:"screen_gone_box"	/*移位缓存层*/
    },
    canClose:true,
    ShowSelfControl:function(containBox,showFun){
        Util.ScreenManager.IsClickHide = true;
        this.popCoverDiv(3,containBox,showFun);
    },
    //创建遮盖层
    popCoverDiv: function (isShow,containBox,showFun){
        
        var screenBox = document.getElementById(Util.ScreenManager.config.coverbox);
        if (!screenBox) {
            //如果存在遮盖层，则让其显示
            //否则创建遮盖层
            var coverDiv = document.createElement('div');
            document.body.appendChild(coverDiv);
            coverDiv.id = Util.ScreenManager.config.coverbox;
            var bodySize;
            with(coverDiv.style) {
                if ($.browser.msie && $.browser.version == 6) {
                    position = 'absolute';
                    background = Util.Config.Screen_Background;
                    left = '0px';
                    top = '0px';
                    bodySize = this.getBodySize();
                    width = '100%';
                    height = bodySize[1] + 'px';
                }
                else{
                    position = 'fixed';
                    background = Util.Config.Screen_Background;
                    left = '0';
                    top = '0';
                    width = '100%'
                    height = '100%';
                }
                zIndex = 9998;
                if ($.browser.msie) {
                    filter = "Alpha(Opacity=" + Util.Config.Screen_Opacity + "0)";	//IE逆境
                } else {
                    opacity = Number("0."+Util.Config.Screen_Opacity);
                }
                if(!isShow){
                    display = "none";
                }
            }
            coverDiv.onclick = function(){
                if(Util.ScreenManager.canClose){
                    if(Util.ScreenManager.IsClickHide == undefined || Util.ScreenManager.IsClickHide == false){
                        coverDiv.style.display = "none";
                        document.getElementById(Util.ScreenManager.config.contentbox).style.display = "none";
                    }
                }
            };

            var contentDiv = document.createElement("div");
            contentDiv.id = Util.ScreenManager.config.contentbox;
            contentDiv.style.position = "absolute";
            contentDiv.style.zIndex = 9999;
			contentDiv.style.top = "0";
            document.body.appendChild(contentDiv);
            contentDiv.onmouseover = function(){
                Util.ScreenManager.canClose = false;
            };
            contentDiv.onmouseout = function(){
                Util.ScreenManager.canClose = true;
            };
            screenBox = contentDiv;
        }
		
        screenBox.style.display = isShow ? "" : "none" ;
        if(isShow == 3){
            if(showFun){
                showFun();
            }
        }
        else{
            document.getElementById(Util.ScreenManager.config.contentbox).style.display = isShow ? "" : "none" ;
            if(isShow && containBox){
                //创建Cache Box
                var cacheBox = document.getElementById(Util.ScreenManager.config.cachebox);
                if(!cacheBox){
                    var cBox = document.createElement("div");
                    document.body.appendChild(cBox);
                    cBox.id = Util.ScreenManager.config.cachebox;
                    cBox.style.display = "none";
                    cacheBox = cBox;
                }
				
                var cBox = document.getElementById(Util.ScreenManager.config.contentbox);
                var contentNodes = cBox.childNodes;
                for(var i = 0,len = contentNodes.length; i < len; i++){
                    cacheBox.appendChild(contentNodes[i]);
                }
                containBox.style.display = "";
                cBox.appendChild(containBox);
				Util.Layer.Center($(containBox));
            }
        }
        this.canClose = true;
    }
}

/**
* 显示结果静态方法
* Util.Result.Show(msg,isSuccess); //(msg: 内容; isSuccess： 0失败，1成功，2警告)
*/
Util.Result = {
    Show:function(msg,isSuccess,timeOut,isHide){
        if(!Util.Result.show_result_class){
            Util.Result.show_result_class = new ShowResultObject();
        }
        Util.Result.show_result_class.ShowMessage(msg,isSuccess);
        var time = Util.Config.Result_HideTime;
        if(timeOut){
            time = timeOut
        }
        if(isHide == undefined || isHide == true){
            window.setTimeout("Util.Result.show_result_class.Hide()",time);
        }
    },
    Hide: function(){
        if(Util.Result.show_result_class){
            Util.Result.show_result_class.Hide();
        }
    }
}

var ShowResultObject = function(boxID,displayBoxId){
    var _ResultBpx;
    var _DisplayTextBox;
    if(boxID !=undefined){
        _ResultBpx = document.getElementById(boxID);
    }
    else{
        _ResultBpx = document.createElement("div");
        document.body.appendChild(_ResultBpx);
    }
    if(displayBoxId != undefined){
        _DisplayTextBox = document.getElementById(displayBoxId);
    }
    else{
        _DisplayTextBox = document.createElement("span");
        _ResultBpx.appendChild(_DisplayTextBox);
    }

    var setStyle = function(isPerfect){
        var fontColor = "#69AE03";
        var bgColor = "#fff";
        switch(isPerfect){
            case 0:	//失败
            fontColor = Util.Config.Result_Failed_FontColor;
            bgColor = Util.Config.Result_Failed_BgColor;
            break;
            case 1:	//成功
            fontColor = Util.Config.Result_Success_FontColor;
            bgColor = Util.Config.Result_Success_BgColor;
            break;
            case 2:	//警告
            fontColor = Util.Config.Result_Alert_FontColor;
            bgColor = Util.Config.Result_Alert_BgColor;
            break;
        }

        _DisplayTextBox.style.color = fontColor;
        var  resultStyle = _ResultBpx.style;
        resultStyle.backgroundColor = bgColor;
        resultStyle.position = "absolute";
        resultStyle.zIndex = 1000;
        resultStyle.top = document.body.scrollTop + "px";
        resultStyle.padding = "2px 6px";
        var l = document.documentElement.clientWidth * 48/100;
        resultStyle.left = l + "px";

    }

    this.getResultBox = _ResultBpx;
    this.getDisplayBox = _DisplayTextBox;
    this.Hide = function(){
        this.getResultBox.style.display = "none";
        this.getDisplayBox.innerHTML =  "";
		/*取消监听 zen 2009-11-17 17:24*/
        $(window).unbind("scroll");
    },
    this.ShowMessage = function(text,isSuccess){
        setStyle(isSuccess);
        this.getDisplayBox.innerHTML = text;
        this.getResultBox.style.display = "";

        /*总是相对于窗口的顶部 zen 2009-11-17 17:24*/
        $(this.getResultBox).css("top",$("html").scrollTop());
        var box=$(this.getResultBox);
        $(window).bind("scroll",function(){
            box.css("top",$("html").scrollTop());
        });
	}
}

/*
* 文件
*/
Util.File = {
    /**
    * 显示文件大小
    *
    *
    */
    ShowSize:function(bytes){
        bytes = parseInt(Number(bytes));
        var unit = new Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB',
            'DB', 'NB');
        var extension = unit[0];
        var max = unit.length;
        for (var i = 1; ((i < max) && (bytes >= 1024)); i++) {
            bytes = bytes / 1024;
            extension = unit[i];
        }
        return Number(bytes).toFixed(2) + extension;
    },
    Cut: function(str,count){
        if(str.length > count){
            return str.substring(0,count/2) + "..." + str.substring(str.length - (count/2),str.length);
        }
        return str;
    },
    GetInputFilePath: function (ele){  
        if(ele){  
            if (window.navigator.userAgent.indexOf("MSIE")>=1){  
                ele.select();  
                return document.selection.createRange().text;
            }
            else if(window.navigator.userAgent.indexOf("Firefox")>=1){  
                if(ele.files){  
                    return ele.files.item(0).getAsDataURL();  
                }  
                return ele.value;  
            }  
            return ele.value;  
        }  
    }
}

Util.Date = {
    GetTimeText:function(num){
        var arr = [3600,60];
        var result = "";
        for(var i = 0,len = arr.length; i < len; i++){
            var item = arr[i];
            if(num >= item){
                var s = (num / item).toFixed(0);
                result += Util.Date._getDoubleText(s) + ":";
                num = num % item;
            }
            else{
                result += "00:";
            }
        }
        result += Util.Date._getDoubleText(num);
        return result;
    },
    _getDoubleText: function(num){
        if(num.toString().length > 1){
            return num;
        }
        else{
            return "0" + num.toString();
        }
    }
}

/*
* Cookie控制
*/
Util.Cookie = {
    get:function(name){
        var cookieValue = "";
        var search = name + "=";
        if (document.cookie.length > 0) {
            offset = document.cookie.indexOf(search);
            if (offset != -1) {
                offset += search.length;
                end = document.cookie.indexOf(";", offset);
                if (end == -1)
                    end = document.cookie.length;
                cookieValue = unescape(document.cookie.substring(offset, end));
            }
        }
        return cookieValue;
    },
    set:function(name, value, hours){
        var expire = "";
        if (hours != null) {
            expire = new Date((new Date()).getTime() + hours * 3600000);
            expire = "; expires=" + expire.toGMTString();
        }
        document.cookie = name + "=" + escape(value) + expire +";path=/";
    }
}

Util.Event = {
    GetSrcElement: function(){
        var e = Util.Event.getEvent();
        return e.target || e.srcElement;
    },
    getEvent: function(){
        if (document.all) {
            return window.event;
        }
        func = Util.Event.getEvent.caller;
        while (func != null) {
            var arg0 = func.arguments[0];
            if (arg0) {
                if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
                    return arg0;
                }
            }
            func = func.caller;
        }
        return null;
    }
};

Util.TextBox = {
    BindDefaultText: function(ele,text){
        ele.value = text;
        ele.style.color = Util.Config.TextBoxDefaultColor;
        ele.onblur = function(){
            if(ele.value == ""){
                ele.value = text;
                ele.style.color = Util.Config.TextBoxDefaultColor;
            }
            else{
                ele.style.color = Util.Config.TextBoxActiveColor;
            }
        };
        ele.onfocus = function(){
            ele.style.color = Util.Config.TextBoxActiveColor;
            if(ele.value == text){
                ele.value = "";
            }
        };
        ele.GetValue = function(){
            if(ele.value == text){
                return "";
            }
            return ele.value;
        };
        ele.Clear = function(){
            ele.value = "";
            ele.onblur();
        };
        return ele;
    }
}

/**
* 验证
*/
Util.Validate = {
    mb_strlen: function(str){
        var offset = 0;
        for(var i=0; i<str.length; i++){
            var string = str.substr(i,1);
            if(escape(string).substr(0,2)=="%u"){
                offset +=3;
            }
            else{
                offset +=1;
            }
        }
        return offset;
    },
    FileName: function(file_name) {
        if (file_name.length < 1) {
            alert("文件名不能少于1个字符！");
            return false;
        }
        var regular = /^[^\\/:*?<>\s\"\']{1,}$/;
        if (!regular.test(file_name)) {
            alert('文件名不能包含下列任意字符之一\ / :. * ?" < > |');
            return false;
        }
        return true;
    },
    ShopFileName: function(file_name){
        if (file_name.length < 1) {
            return "文件名不能少于1个字符！";
        }
        var regular = /^[^\\/:*?<>\s\"\']{1,}$/;
        if (!regular.test(file_name)) {
            return '文件名不能包含下列任意字符之一\ / :. * ?" < > |';
        }
        return "";
    },
    FileNameCut: function(file_name){
        var lL = file_name.lastIndexOf(".");
        var pey = file_name.substring(lL);
        var name = file_name.substring(0,lL);
        var flong = Util.Validate.mb_strlen(file_name);
        var plong = Util.Validate.mb_strlen(pey);
        if(flong > 451){
            if(plong > 451){
                pey = pey.substring(0,400);
                if(Util.Validate.mb_strlen(name+pey) > 451){
                    name = name.substring(0,49);
                }
            }
            else{
                var lesslong = flong - plong;
                name = name.substring(0,lesslong - 1);
            }
        }
        return name + pey;
    },
    Desc: function(description) {
        if (description.length > 11500) {
            alert("描述字符长度不能超过11500字节");
            return false;
        }
        return true;
    },
    CategoryName: function(category_name) {
        category_name = category_name.replace(' ', '');
        if (category_name.length < 1) {
            alert("目录名称不能为空");
            return false;
        }
        if (category_name.length > 20) {
            alert("目录名称不能超过20个字");
            return false;
        }
        var regular = /^[^\\/:*?<>\|\\\\\"]*$/;
        if (!regular.test(category_name)) {
            alert('目录名称不能包含下列任意字符之一\ \ / : * ? "  < > |');
            return false;
        }
        return true;
    },
    Email: function(email) {
        var regular = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/;
        if (!regular.test(email)) {
            return false;
        } else {
            return true;
        }
    }
};

Util.GetFlashVersion = function() {
    var hasFlash = 0;
    var flashVersion = 0;
    if (document.all) {
        var swf = null;
        try {
            swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
        } catch (e) {
        }
        if (swf) {
            hasFlash = 1;
            VSwf = swf.GetVariable("$version");
            flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
        }
    } else {
        if (navigator.plugins && navigator.plugins.length > 0) {
            var swf = null;
            try {
                swf = navigator.plugins['Shockwave Flash'];
            } catch (e) {
            }
            if (swf) {
                hasFlash = 1;
                var words = swf.description.split(" ");
                for (var i = 0; i < words.length; ++i) {
                    if (isNaN(parseInt(words[i]))) {
                        continue;
                    }
                    flashVersion = parseInt(words[i]);
                }
            }
        }
    }
    return {
        f : hasFlash,
        v : flashVersion
    };
}

/*提示框*/
Util.MsgBox = (function(){
    var _Config = {
        confirmTemp:'<div class="pop-box pop-min"><h2><a href="javascript:;" class="close" rel="close">'+"关闭"+'</a>%2</h2><div class="con"><div class="msg-box"><i class="icon %3"></i><span class="msg-text">%1</span></div><div class="bottom"><button class="active" rel="enter">'+"确定"+'</button>&nbsp;<button rel="close">'+"取消"+'</button></div></div></div>',
        confirmConTemp: '<div class="pop-box pop-min">'+
							'<h2><a href="javascript:;" class="close" rel="close">'+"关闭"+'</a>%2</h2>'+
							'<div class="con">'+
								'<div class="msg-box msg-contents">%1</div>'+
								'<div class="bottom"><a href="javascript:;" class="button active" rel="enter">'+"确定"+'<b></b></a>&nbsp;<a href="javascript:;" class="button" rel="close">'+"取消"+'<b></b></a></div>'+
							'</div>'+
						'</div>',
        alertTemp:'<div class="pop-box pop-min"><h2><a href="javascript:;" class="close" rel="close">'+"关闭"+'</a>%2</h2><div class="con"><div class="msg-box"><i class="icon %3"></i><span class="msg-text">%1</span></div><div class="bottom" style="text-align:center"><button class="active" rel="enter">'+"确定"+'</button></div></div></div>',
        msgTemp:'<div class="pop-box pop-min"><h2><a href="javascript:;" class="close" rel="close">'+"关闭"+'</a>%2</h2><div class="con">%1</div></div>',
        iframeTemp:'<div class="iframe-box" style="width:%2px;height:%3px;"><div class="pop-iframe" style="width:%2px;height:%3px;"><iframe src="%1" frameborder="0" width="%2" height="%3"></iframe></div><div class="pop-bg" style="width:%2px;height:%3px;"></div><a href="javascript:;" rel="close" style="left:%2px;top:-5px;" class="btn-file-close"></a></div>',
        boxType:{
            warm:"i-war",
            suc:"i-suc",
            fail:"i-err",
            hint: "i-war",
            err:"i-err",
            ques:"i-war"
        }
    }
    var _cacheConfirmBox,_cacheIframeBox,_cacheConfirmConBox,_cacheAlertBox,_cacheShowBox,_cacheFormBox,_cacheFormHideBox,_cacheUrlBox;
    var createBox = function(obj){
        obj.type = _Config.boxType[obj.type];
        if(typeof obj.type == "undefined"){
            obj.type = _Config.boxType.hint;
        }
        if(typeof obj.title == "undefined"){
            obj.title = "系统提示";
        }
    }

    var bindBox = function(cachebox,obj){
        $(cachebox).find("[rel]").bind("click",function(){
            var returnr;
            if(obj.callback){
                returnr = obj.callback(this);
            }
            if(returnr !== false){ 
                Util.ScreenManager.Hide();
            }
        });
        if(obj.isClickHide){
            Util.ScreenManager.Show(cachebox,true);
        }
        else{
            Util.ScreenManager.Show(cachebox);
        }
    }
	
	var bindMove = function(box){
		var move_title = box.find("h2");
		Util.Mouse.MoveBox({
			ClickBox: move_title,
			Box: box,
			Outer: $(document.body)
		})
		move_title.find("a").bind("mousedown", function(e){
			if($.browser.msie){
				event.cancelBubble=true;
			}else{
				e.stopPropagation();
				e.preventDefault();
			}	//停止冒泡
		})
	}

    var Return = {
        /*
		选择提示框
		参数：
		Util.MsgBox.Confirm({
		text: "提示内容",	//[必填]提示内容
		type: "suc",	//[可选]提示类型 warm[警告],suc[成功],fail[失败],hint[信息],err[错误],ques[疑问]  默认为hint
		title:"提示头",	//[可选]提示头
		callback:function(r){} //[可选]点击按钮后执行的方法 r参数：true为点击确定 false为取消
		});
		*/
        Confirm: function(obj){
            createBox(obj);
            if(_cacheConfirmBox){
				_cacheConfirmBox.empty().remove();
			}
            _cacheConfirmBox = $(String.format(_Config.confirmTemp,obj.text,obj.title,obj.type));
            _cacheConfirmBox.find("[rel]").bind("click",function(){
                var returnr;
                if(obj.callback){
                    returnr = obj.callback(($(this).attr("rel") == "enter"));
                }
                if(returnr !== false){
                    Util.ScreenManager.Hide();
                }
            });
            Util.Config.EnterCallback = function(){
                _cacheConfirmBox.find("[rel='enter']").click();
            }
            Util.Config.EscCallback = function(){
                _cacheConfirmBox.find("[rel='close']").click();
            }
			bindMove(_cacheConfirmBox);
            Util.ScreenManager.Show(_cacheConfirmBox[0],true);
            _cacheConfirmBox.find("[rel='enter']")[0].focus();
        },
        ConfirmBox: function(obj){
			createBox(obj);
			if(_cacheConfirmConBox){
				_cacheConfirmConBox.empty().remove();
			}
			_cacheConfirmConBox = $(String.format(_Config.confirmConTemp,obj.text,obj.title,obj.type));
			_cacheConfirmConBox.find("[rel]").bind("click",function(){
				var returnr;
				if(obj.callback){
					returnr = obj.callback(($(this).attr("rel") == "enter"));
				}
				if(returnr !== false){
					Util.ScreenManager.Hide();
				}
			});
            Util.Config.EnterCallback = function(){
                _cacheConfirmConBox.find("[rel='enter']").click();
            }
            Util.Config.EscCallback = function(){
                _cacheConfirmConBox.find("[rel='close']").click();
            }
			bindMove(_cacheConfirmConBox);
			Util.ScreenManager.Show(_cacheConfirmConBox[0],true);
            _cacheConfirmConBox.find("[rel='enter']")[0].focus();
			
        },
        /*
		选择提示框
		参数：
		Util.MsgBox.Alert({
		text: "提示内容",	//[必填]提示内容
		type: "suc",	//[可选]提示类型 warm[警告],suc[成功],fail[失败],hint[信息],err[错误],ques[疑问]  默认为hint
		title:"提示头",	//[可选]提示头
		callback: function(){} //[可选]点击按钮后的回调
		});
		*/
        Alert: function(obj){
            createBox(obj);

			if(_cacheAlertBox){
				_cacheAlertBox.empty().remove();
			}
			_cacheAlertBox = $(String.format(_Config.alertTemp,obj.text,obj.title,obj.type));
            bindBox(_cacheAlertBox[0],obj);
			bindMove(_cacheAlertBox);
            Util.Config.EscCallback = Util.Config.EnterCallback = function(){
                _cacheAlertBox.find("[rel='enter']").click();
            }
            _cacheAlertBox.find("[rel='enter']")[0].focus();
        },


        /*
		Iframe提示框
		参数：
		Util.MsgBox.IframeBox({
		url: "http://",
		width: "400",
		height:"500"
		});
		*/
        IframeBox: function(obj){
            if(top && top.window.Ext){
                top.window.Ext.App.Message(obj.url);
                return;
            }
            createBox(obj);
            if(!_cacheIframeBox){
                _cacheIframeBox = $(String.format(_Config.iframeTemp,obj.url,obj.width,obj.height));
            }
            _cacheIframeBox.find("[rel]").bind("click",function(){
                if(obj.callback){
                    obj.callback(($(this).attr("rel") == "enter"));
                }
                if(_cacheIframeBox){
                    _cacheIframeBox.empty().remove();
                    _cacheIframeBox = false;
                }
                Util.ScreenManager.Hide();
            });
            Util.ScreenManager.Show(_cacheIframeBox[0], true);
        },


        /*
		内容显示
		参数：
		Util.MsgBox.Show({
		text: "提示内容",	//[必填]提示内容
		title:"提示头"	//[可选]提示头
		});
		*/
        Show: function(obj){
            createBox(obj);
			
			if(_cacheShowBox){
				_cacheShowBox.empty().remove();
			}
			_cacheShowBox = $(String.format(_Config.msgTemp,obj.text,obj.title));
            if(obj.className){
                _cacheShowBox.addClass(obj.className);
            }
            if(obj.width){
				_cacheShowBox.width(obj.width);
            }
            bindBox(_cacheShowBox[0],obj);
			bindMove(_cacheShowBox);
        }
		
    }

    return Return;
})();

Util.Common = (function(){
    return {
        Center: function(box){
            box.css({
                top: ($(window).height() - box.height())/3
                });
        }
    }
})();

Util.TabManager = function(pList,pActiveStyle,pDisableStyle){
    var _self = this;
    var _obj = {
        List: pList,
        ActiveStyle: pActiveStyle,
        DisableStyle: pDisableStyle
    };
    var _ChangeHandler;
    var time ;
    var _autoTimer;
    this._autoTimeOut = 3000;
    var overObj;
    var activeIndex;
    var _autostate = false;
    function display(){
        for(var j = 0; j < _obj.List.length; j++){
            var ele = _obj.List[j].Tab;
            ele.removeClass(_obj.ActiveStyle);
            ele.addClass(_obj.DisableStyle);
            _obj.List[j].Content.hide();
        }

        overObj.Tab.addClass(_obj.ActiveStyle);
        overObj.Content.show();
        if(_ChangeHandler){
            _ChangeHandler(overObj);
        }
    }

    function autoDisplay(){
        activeIndex++;
        if(activeIndex >= _obj.List.length){
            activeIndex = 0;
        }
        overObj = _obj.List[activeIndex];
        display();
    }

    var init = function(){
        for(var i = 0; i < _obj.List.length; i++){
            var item = _obj.List[i];
            item.Tab.bind("mouseover",{
                obj:item,
                index:i
            },function(e){
                overObj = e.data.obj;
                activeIndex = e.data.index;
                time = window.setTimeout(display,300);
                _self.SetAuto(_autostate);
            }).bind("click",{
                obj:item,
                index:i
            },function(e){
                overObj = e.data.obj;
                activeIndex = e.data.index;
                if(time != undefined){
                    window.clearTimeout(time);
                }
                display();
                this.blur();
                _self.SetAuto(_autostate);
            }).bind("mouseout",function(){
                if(time != undefined){
                    window.clearTimeout(time);
                }
            });
        }

    }
    this.SetAuto = function(v){
        if(_autoTimer){
            window.clearInterval(_autoTimer);
        }
        if(v){
            _autoTimer = window.setInterval(autoDisplay,_self._autoTimeOut);
        }
        _autostate = v;
    }
    this.SetChangeHandler = function(pHandler){
        _ChangeHandler = pHandler;
    },
    this.Select = function(key){
        activeIndex = key;
        overObj = _obj.List[key];
        display();
    }
    init();
}

//标签控制
Util.Layer = (function(){
	var _cache = {},Return = {};	//缓存类
	
	//最小化
    Return.Min = function(box,mBox,callback){
        if(!_cache.MinBorder){
            _cache.Minborder = $('<div style="z-index:10000;border:1px solid #333;position:absolute;top:0;left0;display:none;"></div>');
            $(document.body).append(_cache.Minborder);
        }
        mBox.show();
        var w = box.width(), h = box.height(), t = box.offset().top, l = box.offset().left, eT = mBox.offset().top, eL = mBox.offset().left, eW = mBox.width(), eH = mBox.height();
        _cache.Minborder.width(w).height(h).css({
            left:l,
            top:t
        });
        _cache.Minborder.animate({
            width:eW,
            height:eH,
            top:eT,
            left:eL
        },250,function(){
            _cache.Minborder.hide();
        });

        if(callback){
            callback();
        }
    }
	
	/*
	设置标签居中(左右居中，上下1:2)
	
	*/
	Return.Center = function(box,setting){
		var mainBox;
		var cut = 0, t = 0, l = 0;
		if(setting){
			if(setting.Main){
				mainBox = setting.Main;
				t = mainBox.offset().top;
				l = mainBox.offset().left;
			}
			else{
				mainBox = $(window);
			}
			if(setting.Cut != undefined){
				cut = setting.Cut;
			}
		}
		else{
			mainBox = $(window);
		}
		var cssT = (mainBox.height() - box.height())/3 + cut + t;
		var cssL = (mainBox.width() - box.width())/2 + cut + l;
		if(cssT < 0){
			cssT = 0;
		}
		if(cssL < 0){
			cssL = 0;
		}
		
		box.css({
			top: cssT, 
			left: cssL
		});
	}
		
	return Return;
})();

/*
	公共函数
*/
Util.Mouse = (function(){
    var _cache = {
        move: {x:0,y:0,eX:0,eY:0},	//手动层缓存对象
		line: {x:0,y:0,eX:0,eY:0},	//拖动线缓存对象
		sq: {t:0,l:0,x:0,y:0,w:0,h:0,st:0}	//框选缓存对象
    },Return = {};

	//获取透明遮罩层
	var GetLayOutBox = function(){
		if(!_cache.LayOutBox){
			_cache.LayOutBox = $('<div style="z-index: 9000000; display: none;background: none repeat scroll 0 0 black;height: 100%;left: 0;position: absolute;top: 0;width: 100%;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;"><div style="height:100%;width:100%;"></div></div>');
			$(document.body).append(_cache.LayOutBox);
		}
		return _cache.LayOutBox;
	}

	//移动层，mouseover函数
    var moveBoxFun = function(e){
        //鼠标移动
        if(_cache.move.state){			
			_cache.move.eX = e.screenX;
			_cache.move.eY = e.screenY;
			var lessX = _cache.move.eX - _cache.move.x;
			var lessY = _cache.move.eY - _cache.move.y;
			if(_cache.move.box){
				var t = _cache.move.sT + lessY;
				var l = _cache.move.sL + lessX;
				if(t > _cache.move.maxT){
					t = _cache.move.maxT;
				}
				else if(t < _cache.move.minT){
					t = _cache.move.minT;
				}
				if(l > _cache.move.maxL){
					l = _cache.move.maxL;
				}
				else if(l < _cache.move.minL){
					l = _cache.move.minL;
				}
				_cache.move.box.css({
					left: l + "px",
					top: t + "px"
				});
			}
			if(e.data.move_callback){
				e.data.move_callback();
			}
            return false;
        }
    }

	/*
		绑定移动函数
		obj
		{
			ClickBox 	--点击的标签
			Box		--移动的层
		}
	*/
    Return.MoveBox = function(obj){
        var outer = obj.Outer;
        var box = obj.Box;
		obj.ClickBox.attr("ws_property","1");
        obj.ClickBox.bind("mousedown",{box:box,outer:outer,callback:obj.Callback, move_callback: obj.MoveCallback},function(e){
            _cache.MoveLayOut = GetLayOutBox();
			_cache.MoveLayOut.css({cursor:"default"});
			var lay = ($.browser.msie)? _cache.MoveLayOut : $(window);
			lay.unbind("mousemove").bind("mousemove",{move_callback:e.data.move_callback},function(e){if(_cache.move.state){_cache.MoveLayOut.show();} moveBoxFun(e);  return false;});
			lay.unbind("mouseup").bind("mouseup",function(e){
				//鼠标按起来
				if(_cache.move.state){
					_cache.move.state = false;
					_cache.MoveLayOut.hide();
					_cache.MoveLayOut.css({cursor:"default"});
					if($.browser.msie){
						_cache.MoveLayOut[0].releaseCapture();
					}
					//return false;
				}
			});
			
			if($.browser.msie){
				_cache.MoveLayOut[0].setCapture();
			}

			_cache.move.state = true;
			_cache.move.box = e.data.box;
            _cache.move.outer = e.data.outer;
			_cache.move.x = e.screenX;
			_cache.move.y = e.screenY;
			_cache.move.eX = e.screenX;
			_cache.move.eY = e.screenY;
			_cache.move.sT = _cache.move.box.offset().top;
			_cache.move.sL = _cache.move.box.offset().left;
			_cache.move.minT = _cache.move.outer.offset().top;
			_cache.move.maxT = _cache.move.outer.offset().top + _cache.move.outer.height() - _cache.move.box.height();
			_cache.move.minL = _cache.move.outer.offset().left;
			_cache.move.maxL = _cache.move.outer.offset().left + _cache.move.outer.width() - _cache.move.box.width();
			
            if(e.data.callback){
				e.data.callback();
			}

            return false;
        });
		return {
			Disable: function(){
				obj.ClickBox.attr("stop_move","1");
			},
			Enable: function(){
				obj.ClickBox.attr("stop_move")
			}
		}
    }

    return Return;
})();

