﻿var ie=window.ActiveXObject!=null,ie7=navigator.userAgent.indexOf('MSIE 7.0')>-1,ie6=ie&&(!ie7);
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"")};
String.prototype.encode=function(){return this.toString().replace(/＆/g,"&").replace(/＜/g,"<").replace(/＞/g,">").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\r/g,"\\r").replace(/\n/g,"\\n");},
String.prototype.unencode=function(){return this.replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&nbsp;/g," ");}
String.prototype.leftTrim=function(v){//等待测试
    var p = new RegExp("^"+v+"*");
    p.global=true;
    return this.replace(p,"");
};
String.prototype.replaceAll = function(n,r){
    var rg = new RegExp(n,"g");
    return this.replace(rg,r);
}
Array.prototype.indexOf=function(v){
    var len=this.length;
	for(var i=0; i<len; i++) if(this[i]==v) return i;
    return -1;
};
Array.prototype.insert=function(v,pos){
	if(pos==null||pos<0) pos = 0;
	if(pos>this.length) pos=this.length;
	for(var i=this.length; i>pos; i--) this[i]= this[i-1];
	this[pos]=v;
    return this;
};
Array.prototype.remove=function(pos){
    var len=this.length;
	if(pos==null||pos<0||pos>=len) return;
	for(var i=pos;i<len-1;i++) this[i]= this[i+1];
    return this.pop();
};
Array.prototype.equals=function(a){
    if(a==null||tool.type(a)!="array") return;
    var len=this.length,alen=a.length;
	if(len!=alen) return false;
	for(var i=0;i<len;i++){
	    var p1=this[i],p2=a[i],b=tool.equals(p1,p2);
	    if(!b) return false;
	}
	return true;
};
Array.prototype.clear=function(){ //清空数组
   var len = this.length;
   for(var i=0;i<len;i++) this.pop();
};
Array.prototype.clone=function(b){ //数组克隆,b是否子对象也克隆
   var len = this.length,l=[];
   for(var i=0;i<len;i++){
        var c=this[i];
        if(b&&c.clone)l.push(c.clone());
        else l.push(c);
   }
   return l;
};
Array.prototype.sort=function(b){//排序，b,是否倒序
    if(this.length==0)return;
    var l=__sort(this,__less),len=l.length;
    if(!b)for(var i=0;i<len;i++)this[i]=l[i];
    else for(var i=len;i>0;i--)this[len-i]=l[i-1];
};
var __less=function(a,b){
    if(tool.type(a)=="number"&&tool.type(b)=="number") return a<b;
    else return (a+"").length<(b+"").length;
}
var __sort=function(l,less){
    if (l.length == 1) return l;
    var lft=[],rgt=[];
    if (l.length > 2){
        var p=0,q=parseInt(l.length/2),r=l.length-1;
        if (l.length%2==1) q--;
        for (var i=p;i<=q;i++) lft.push(l[i]);
        for (var i=q+1;i<=r;i++) rgt.push(l[i]);
    }
    else{
        lft.push(l[0]);
        rgt.push(l[1]);
    }
    lft=__sort(lft,less);
    rgt=__sort(rgt,less);

    return __merge(lft, rgt,less);
}
var __merge=function(lft,rgt,less){
    var k=0,j=0,n=lft.length+rgt.length,a =[];
    for (var i=0;i<n;i++){
        if (k<lft.length&&j<rgt.length){
            if(less(lft[k],rgt[j])){a.push(lft[k]);k++;}
            else{a.push(rgt[j]); j++;}
        }else if(k<lft.length){a.push(lft[k]); k++;}
        else{a.push(rgt[j]);j++;}
    }
    return a;
}

Date.prototype.toShort=function(s){
    if(!s)s="/";
    var y=this.getFullYear(),m=this.getMonth()+1,d=this.getDate();
    return y+s+tool.addBit(m,2,"0")+s+tool.addBit(d,2,"0");
};
Date.prototype.toLong=function(sp){
    if(!sp)sp="/";
    var y=this.getFullYear(),m=this.getMonth()+1,d=this.getDate(),h=this.getHours(),mm=this.getMinutes(),s=this.getSeconds();
    return y+sp+tool.addBit(m,2,"0")+sp+tool.addBit(d,2,"0")+" "+tool.addBit(h,2,"0")+":"+tool.addBit(mm,2,"0")+":"+tool.addBit(s,2,"0");
};
Date.prototype.dateAdd=function(si, n) {    
    var t = this;
    switch(si){
        case 's' :return new Date(Date.parse(t) + (1000 * n));   
        case 'n' :return new Date(Date.parse(t) + (60000 * n));   
        case 'h' :return new Date(Date.parse(t) + (3600000 * n));   
        case 'd' :return new Date(Date.parse(t) + (86400000 * n));
        case 'w' :return new Date(Date.parse(t) + ((86400000 * 7) * n));   
        case 'q' :return new Date(t.getFullYear(), (t.getMonth()) + n*3, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds());   
        case 'm' :return new Date(t.getFullYear(), (t.getMonth()) + n, t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds());   
        case 'y' :return new Date((t.getFullYear() + n), t.getMonth(), t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds());   
    }   
};
Date.prototype.addDay=function(n) {    
    return this.dateAdd('d',n);
};

if(window.Event){
 window.constructor.prototype.__defineGetter__("event", function(){
  var o = arguments.callee.caller,e;
  while(o != null){
   e = o.arguments[0];
   if(e && (e.constructor == Event || e.constructor == MouseEvent || e.constructor==KeyboardEvent)) return e;
   o = o.caller;
  }
  return null;
 });
 
 Event.prototype.__defineGetter__("fromElement",function(){   
  var o=null;
  if(this.type == "mouseover") o = this.relatedTarget;   
  else if(this.type=="mouseout") o=this.target;   
  if(o) while(o.nodeType!=1)o=o.parentNode;   
  return o;   
});
Event.prototype.__defineGetter__("toElement",function(){   
  var o=null;
  if(this.type=="mouseout") o=this.relatedTarget;   
  else if(this.type=="mouseover")o=this.target;   
  if(o)while(o.nodeType!=1)o=o.parentNode;   
  return o;   
});
Event.prototype.__defineSetter__("cancelBubble",function(b){   
  if(b)this.preventDefault();
  else this.stopPropagation();
});

Event.prototype.__defineGetter__("offsetX",function(){
    return this.layerX;
});

Event.prototype.__defineGetter__("offsetY",function(){
    return this.layerY;
    });
 
}

if(window.HTMLElement){
    HTMLElement.prototype.__defineGetter__("outerHTML",function(){   
        var a=this.attributes,str="<"+this.tagName,i=0;
        for(;i<a.length;i++)  if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';   
        if(!this.canHaveChildren) return   str+" />";   
        return str+">"+this.innerHTML+"</"+this.tagName+">";   
    });
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s){   
        var d=document.createElement("DIV");
        d.innerHTML=s;   
        for(var i=0;i<d.childNodes.length;i++)this.parentNode.insertBefore(d.childNodes[i],this);   
        this.parentNode.removeChild(this);
    });
    HTMLElement.prototype.__defineGetter__("scopeName",function(){
        return this.tagName.substring(0,this.tagName.indexOf(':')).toLowerCase();});
    HTMLElement.prototype.__defineGetter__("innerText",function(){
        var s = "",c = this.childNodes,len=c.length;
        for(var i=0; i<len; i++){
            if(c[i].nodeType==1)s += c[i].tagName=="BR" ? '\n':c[i].innerText;
            else if(c[i].nodeType==3)s += c[i].nodeValue;
        }
        return s;
    });
   HTMLElement.prototype.__defineSetter__("innerText",function(s){this.textContent=s;}); 
   HTMLElement.prototype.__defineGetter__("currentStyle", function(){
        return this.ownerDocument.defaultView.getComputedStyle(this,null);
    });
}

Number.prototype.toFixed =function(n){
    var s=this+"",v=s,p=s.indexOf(".");
    if(p!=-1){ p+=n+1;v=s.substring(0,p);}
    return parseFloat(v);
}

if(!window.execScript)window.execScript=window.eval;

function $(){var a=arguments,len = a.length;
	if(len <= 1) return document.getElementById(a[0]);
	var l=[];
	for (var i=0;i<len;i++) l.push($(a[i]));
	return l;
}

function $$(o,n){
    var t=n;
    if(n==null){t=o;o=document;}
    else if(ie&&(n.indexOf("fancy:")!=-1)) t=n.replace("fancy:","");
    return o.getElementsByTagName(t);
}
function $$$(o,n,l){//根据属性得到对象集合
    if(!l)l=[];
    if(dom.get(o,n))l.push(o);
    var c=dom.childs(o),len=c.length;
    for(var i=0;i<len;i++)$$$(c[i],n,l);
    return l;
}

var http={
    getRequest:function(){
        if(window.XMLHttpRequest) return new XMLHttpRequest();
        var ms = ['Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP'];
        var len=ms.length;
        for(var i=0;i<len;i++){try{return new ActiveXObject(ms[i]);}catch(e){}}
    },
    lcur:null,
    load:function(url,p){
        if(!this.get)this.get=this.getRequest();
        if(!p){//同步加载服务器文件
            this.get.onreadystatechange=function(){};
		    this.get.open("GET",url,false);
		    this.get.send(null);
		    return this.get.responseText;
		}
		//异步加载
		if(!p.masked)p.mask();
		this.lcur=p;
		this.get.open("GET",url,true);
		this.get.setRequestHeader("If-Modified-Since","0");
        this.get.onreadystatechange=this.lcomp;
        this.get.send(null);
	},
	lcomp:function(){
	    if(http.get.readyState ==4){
	        var g=http.get,o=http.lcur;
	        o.emask();
	        o.parse(g.responseText);
	        http.lcur=null;
	    }
	},
	scur:null,
	sq:[],
	send:function(p,c){
	    var act=p.action?p.action:p,a=act.act,x="",s=p.script,u=s.url;
	    if(this.scur) {if(!p.masked){p.mask();p.masked=true;};this.sq.push({p:p,c:c}); return; };
	    if(act.before&&(act.before(act)==false)) return;
	    if(p.xml)x=p.xml();
	    if(!p.masked){p.mask();p.masked=true;}
	    this.scur=p;
	    if(!this.post)this.post=this.getRequest();
	    if(a.indexOf('.htm')>0) {u=a;a="";}
	    else if(a.indexOf('.')>0){var t=a.split('.');a=t[1];u=t[0]+".htm";}
	    this.post.open("POST",u,c);
	    this.post.setRequestHeader("SOAPAction",a);
        this.post.setRequestHeader("Content-Length",x.length);
        this.post.setRequestHeader("Content-Type","text/xml;charset=utf-8");
        this.post.onreadystatechange=this.scomp;
        this.post.send("<object>"+x+"</object>");
	},
	scomp:function(){
	    if(http.post.readyState ==4){
            var p=http.post,t,r,o=http.scur;
            if(o!=null){//如果当前请求的对象还存在，则处理请求完成后的事件
                eval("r={"+p.responseText+"};");
                o.emask();o.masked=false;http.scur=null;
                if(r.error){alert(r.error.Text);return;};
                var act=o.action?o.action:o;
                if(t=act.after) t(r,o);
            }
	        if(t=http.sq.pop()) http.send(t.p,t.c);
	    }
	}
}

var data={};
var core={
    init:function(){
            var s;
            if(ie6) document.documentElement.style.overflowX="hidden";
            if(!document.script) s=document.script=new script("",window.location.pathname);
            if(window.start) window.start();
            document.body.style.height="100%";
            dom.init(dom.childs(document.body),s);
            if(window.end) window.end();
            s.finish();
            css.init();
        }
}

var iframe={
    cache:[],
    get:function(){
        var c=this.cache;
        if(c.length>0){ var o=c.pop();o.style.display="block";return o;}
        return null;
    },
    set:function(o){
        o.style.display="none";
        o.contentWindow.document.body.innerHTML="";
        dom.append(document.body,o);
        this.cache.push(o);
    }
}

var dom ={
    style:function(o,n){
        if (o.style[n]) return o.style[n];
        else if (o.currentStyle)return o.currentStyle[n];
        else if (document.defaultView && document.defaultView.getComputedStyle){
            n = n.replace(/([A-Z])/g,"-$1");
            n = n.toLowerCase();
            var s = document.defaultView.getComputedStyle(o,"");
            return s && s.getPropertyValue(n);
        } else return null;
    },
    setSrc:function(o,s){//无视缓存文件
        var v=s+"?r="+new Date().getTime();
        if(dom.tag(o)=="img")o.src=v;
        else o.style.backgroundImage="url("+v+")";
    },
    hidden:function(o,b){
        if(b) o.style.visibility="hidden";
        else{
            var t=dom.style(o,"display");
            if(t!="none")o.__display=t;//记录下元素第一次被隐藏时的真实显示类型（隐藏之前不可能是none）
            o.style.display="none";
        }
    },
    show:function(o,b,i){
        if(dom.tag(o)=="tr"){
            o.style.display="";
            return;
        }
        
        if(b) o.style.visibility="visible";
        else{
            if(i){o.style.display="inline";}
            else if(!ie&&dom.tag(o)=="tr")o.style.display="";
            else {
                if(o.__display)o.style.display=o.__display;
                o.style.display="block";
            }
        }
    },
    showI:function(o){//显示内联元素
        dom.show(o,false,true);
    },
    isHTML:function(o){//判断对象是否在html中
        return dom.father(o,"body")!=null;
    },
    clear:function(o){
        o.innerHTML="";
    },
    del:function(o){
        var l=dom.childs(o),len=l.length;
        for(var i=0;i<len;i++) dom.del(l[i]);
        if(dom.tag(o)!="iframe") o.parentNode.removeChild(o);   // iframe是不能被移除的，否则在ie下会出现下次载入iframe不能被编辑
        else iframe.set(o);
        o=null;
    },
    init:function(l,s){
        var len = l.length;
        for(var i=0;i<len;i++){
            var o=l[i],n=dom.get(o,"name"),t=dom.get(o,"fancy"),b=true,u=dom.get(o,"ui");
            if(o.scopeName=="fancy") t=dom.tag(o);
            if(t){b=ui[t].init(o,s);}
            if(u)s.uis[u]=o;
            if(b) dom.init(dom.childs(o),s);
        }
    },
    att:["innerHTML","innerText","className"],
    get:function(o,n){
            if(!ie&&this.att.indexOf(n)!=-1) return o[n];
            return o.getAttribute(n);
        },
    set:function(o,n,v){
            if(!ie&&this.att.indexOf(n)!=-1) o[n]=v;
            o.setAttribute(n,v);
        },
    tag:function(o){
            if(!o.tagName)return"";
            var t=o.tagName.toLowerCase();
            if(!ie)t=t.replace(t.substring(0,t.indexOf(':')+1),"").trim().toLowerCase();
            return t;
        },
    childs:function(o,t,b,level){//b代表是否只要直系子对象,默认情况下只要直系子对象
            var n=[],c=o.childNodes,len=c.length;
            if(!b){
                for(var i=0;i<len;i++){
                    var d=c[i];
                    if(d.nodeType==1&&(!t||t==dom.tag(d))) n.push(d);
                }
            }
            else{
                if(!level) level=1;else level++;
                var ns=[];
                for(var i=0;i<len;i++){
                    var d=c[i];
                    if(d.nodeType==1){
                        var l=dom.childs(d,t,b,level),le=l.length;
                        for(var j=0;j<le;j++) ns.push(l[j]);
                    }
                }
                ns.push(o);
                if(t){
                    var le=ns.length;
                    for(var i=0;i<le;i++){
                        if(t==dom.tag(ns[i]))n.push(ns[i]);
                    }
                }
                else n=ns;
            }
            if(level==1) n.pop();else level--;
            return n;
        },
    create:function(){
            var a=arguments,len=a.length,o;
            if(len == 1){
                o=document.createElement(a[0]);
                if(dom.tag(o)=="a"){o.href="";o.onfocus=function(){this.blur();}};
                return o;
            }
            var l={};
            for(var i=0;i<len;i++)
            {
                var t= a[i];
                if(!l[t]) l[t]=[];
                o=document.createElement(t);
                if(dom.tag(o)=="a"){o.href="";o.onfocus=function(){this.blur();}};
                l[t].push(o);
            }
            return l;
        },
    txt:function(v){
            return document.createTextNode(v);
        },
    append:function(){
            var a=arguments,len=a.length;
            for(var i=1; i<len;i++){
                if(tool.type(a[i])=="array"){var iLen=a[i].length; for(var k=0;k<iLen;k++) a[0].appendChild(a[i][k]);}
                else a[0].appendChild(a[i]);
            }
        },
    father:function(o,t){
        if(!t) return o.parentNode;
        var p=o;
        while((p=p.parentNode)&&(dom.tag(p)!=t));
        return p;
    },
    contain:function(o,c){
        return dom.childs(o,null,true).indexOf(c)!=-1;
    },
	left:function(e,b){
			var t=e.offsetLeft,p=e.offsetParent;
            if(p!=null&&((!b)||p.currentStyle.position!="absolute")) t+=dom.left(p,b);
            return t;
		},
 	top:function(e,b) {
 	    var t=e.offsetTop,p=e.offsetParent;
        if(p!=null&&((!b)||p.currentStyle.position!="absolute")) t+=dom.top(p,b); 
        return t;
	},
	avaiHeight:function(){//浏览器有效高度
	    return document.documentElement.clientHeight;
	},
	avaiWidth:function(){//浏览器有效宽度
	    return document.documentElement.clientWidth;
	},
	clientHeight:function(){//浏览器工作区高度
	    return document.body.clientHeight;
	},
	clientWidth:function(){//浏览器工作区宽度
	    return document.body.clientWidth;
	},
	scrollHeight:function(){//滚动条高度
	    return document.documentElement.scrollHeight;
	},
	scrollTop:function(){ return document.documentElement.scrollTop;},
	setScrollTop:function(v){document.documentElement.scrollTop=v;}
}

var evt ={
    add:function(o,t,n,f){
        var s=t+n,a=[],len=arguments.length;
        for(var i=4;i<len;i++) a.push(arguments[i]);
        if(!o.events) o.events={};
        else if (o.events[s]) return;
        o.events[s] = function(){f.apply(f,a);};
        if(ie) o.attachEvent("on"+t,o.events[s]);else o.addEventListener(t,o.events[s],false);
    },
    del:function(o,t,n){
        var s = t+n;if(!o.events||!o.events[s]) return;
		if(ie) o.detachEvent("on"+t,o.events[s]);else o.removeEventListener(t,o.events[s],false);
		delete o.events[s];
    },
    clear:function(o,t){//清空对象上t事件挂载的所有方法
        var evts=o.events;
        for(var e in evts){
            if(e.indexOf(t)>-1) evt.del(o,t,e.replace(t,""));
        }
    },
    fire:function(o,n){//触发系统事件
         if (ie) o.fireEvent("on"+n);
         else{
             var t="Event";
             if(n.indexOf("key")!=-1) t="KeyboardEvent";
             else if(n.indexOf("mouse")!=-1) t="MouseEvents";
             var e = document.createEvent(t);
             e.initEvent(n, true, true);
             o.dispatchEvent(e);
         }
    },
    exec:function(s,t){//触发架构事件
        if(!t)return;
        if(t.indexOf(".")>-1){var l=t.split(".");eval("s="+l[0]+";");t=l[1];}
        var l=arguments,len=l.length,ar=[],r;
        if(len==0) r=s[t]();
        else{
            for(var i=2;i<len;i++)ar.push("l["+i+"]");
            eval("r=s[t]("+ar.join(",")+");");
        }
        return r;
    }
}

var css={
    init:function(){//读取已加载的css文件
        var l=dom.childs($$("head")[0],"link"),len=l.length;
        for(var i=0;i<len;i++){
            var o=l[i];
            if(dom.get(o,"type")=="text/css") this.loaded[dom.get(o,"href")]=o;
        }
    },
    add:function(n){
        if(this.loaded[n]) return;
        var l=dom.create("link")
        dom.set(l,"rel","stylesheet");
        dom.set(l,"type","text/css");
        dom.set(l,"href",n);
        $$("head")[0].appendChild(l);
        this.loaded[n]=l;
    },
    del:function(n){
        var l=this.loaded[n];
        if(l){
            dom.del(l);
            this.loaded[n]=null;
        }
    },
    replace:function(n,url){
        var l=this.loaded[n];
        if(l) dom.set(l,"href",url);
    },
    loaded:{}
}

var tool={
    isUndefined:function(v){
        return !v&&(tool.type(v)=="undefined");
    },
    isNull:function(v){
        return !v&&(tool.type(v)=="object");
    },
    addBit:function(s,n,v,r){//补位操作,s需要补位的字符串，n总共的位数，v补位的字符，r从右边补位
        if(v.length>1)return;
        s=s+"";
        var len=s.length,dis=n-len;
        while(dis>0){
            if(r)s+=v;else s=v+s;
            dis--;
        }
        return s;
    },
    timeDiff:function(b,a){
       return Number((b.getTime()-a.getTime())/1000).toFixed(2);
    },
    randf:function(){
        tool.randf.seed = (tool.randf.seed*9301+49297) % 233280; 
　　　　return tool.randf.seed/(233280.0); 
    },
    randi:function(n){
        return Math.ceil(tool.randf()*n); 
    },
    type:function(o){
		if(o&&(typeof o=='object')&&o.constructor==Array)  return "array";
		return typeof o;
	},
	getKey:function(){
	    if(!this.getKey_root) this.getKey_root=0;
	    return ++this.getKey_root;
	},
	repair:function(s){//自动修复未闭合的html标签
	    var d=dom.create("div");
	    d.innerHTML=s;
	    return d.innerHTML;
	},
	mask:function(o){
	    if(!this.loading){
            var l=dom.create("div","span"),d=l.div[0];
            d.style.position="absolute";
            d.style.zIndex=952;
            d.style.display="none";
            d.className="cmdLoading";
            d.show=function(){
                dom.show(this);
                var x=parseInt(dom.avaiWidth()/2)-parseInt(this.offsetWidth/2),t=parseInt(dom.scrollTop());
                if(!t)t=0;
                var y=parseInt(dom.avaiHeight()/2)-parseInt(this.offsetHeight/2)+t;
                this.style.left=x+"px";
                this.style.top=y+"px";
            }
            d.close=function(){dom.hidden(this);}
            
            l.span[0].innerHTML="操作处理中，请稍后…";
            dom.append(d,l.span[0]);
            dom.append(document.body,d);
            this.loading=d;
        }
        
        if(o){
            if(dom.style(o,"position")!="absolute"){
                o.style.position="absolute";
                o.style.zIndex=952;
            }
            dom.show(o);
            var x=parseInt(dom.avaiWidth()/2)-parseInt(o.offsetWidth/2),t=parseInt(dom.scrollTop());
            if(!t)t=0;
            var y=parseInt(dom.avaiHeight()/2)-parseInt(o.offsetHeight/2)+t;
            o.style.left=x+"px";
            o.style.top=y+"px";
        }else this.loading.show();
        
        var w = document.body.offsetWidth,s=dom.scrollTop();//记录原始body的宽度
        document.documentElement.style.overflow="hidden";
        if(!ie)dom.setScrollTop(s);
        if(!tool.__bg){
            var bg=dom.create("div");
            bg.style.position="absolute";
            bg.style.left="0px";
            bg.style.top="0px";
            bg.className="mask";
            dom.append(document.body,bg);
            tool.__bg=bg;
        }
        var ch=parseInt(dom.clientHeight()),ah=parseInt(dom.avaiHeight()),b=tool.__bg,cw=parseInt(dom.clientWidth()),aw=parseInt(dom.avaiWidth());
        b.style.height=(ch<ah?ah:ch)+"px";
        b.style.width=(cw<aw?aw:cw)+"px";
        b.style.display="block";
        document.body.style.width=w+"px";
	},
	emask:function(o){
	    if(o)dom.hidden(o);
	    else this.loading.close();
	    
        dom.hidden(tool.__bg);
        document.documentElement.style.overflowY="auto";
        //document.documentElement.style.overflowX="hidden";
        //document.body.style.width="100%";
	},
	getExt:function(p){//得到文件后缀名
	    return p.substring(p.lastIndexOf(".")+1).toLowerCase();
	},
	getName:function(f){//得到文件名
	    if(f.indexOf("\\")!=-1) return f.substring(f.lastIndexOf("\\")+1);
	    if(f.indexOf("/")!=-1) return f.substring(f.lastIndexOf("/")+1);
	    return f;
	},
	getDay:function(y,m){//得到一个月的天数，闰年为29天
	    var ds =[31,28,31,30,31,30,31,31,30,31,30,31],c=ds[m-1]; 
        if((m==2)&&tool.isPinYear(y)) c++;
        return c;
	},
	isPinYear:function(y){   
        return (0==y%4&&((y%100!=0)||(y%400==0)));
    },
    equals:function(a,b){
        if(a==null&&b==null)return true;
        if(a==null||b==null)return false;
        var tya= tool.type(a),tyb=tool.type(b);
        if(tya=="string"||tyb=="string") {a=a+"";b=b+"";tya=tyb="string";}//如果比较的值有一个是字符串，则将另外个参数转换成字符串
        else if(tya!=tyb) return false;
        if(a.equals) return a.equals(b);
        if(tya=="object"){
            for(var e in a){
                var p1=a[e],p2=b[e],re=tool.equals(p1,p2);
                if(!re)return false;
            }
            return true;
        }
        return a==b;
    },
    isEmpty:function(o){//判断一个对象是否为空
        switch(tool.type(o)){
            case "string":return o==""||o==null;
            case "number":return o==0;
            case "array":{
                var len=o.length;
                for(var i=0;i<len;i++) if(!tool.isEmpty(o[i]))return false;
                return true;
            }
            case "object":{
                for(var e in o){
                    if(!tool.isEmpty(o[e]))return false;
                }
                return true;
            }
        }
    }
}

var tree=function(d){
    this.data = d;
    function _find(r,key,l){
        var cs=r.childs,len=cs.length;
        for(var i=0;i<len;i++){
            var c=cs[i];
            if(l)l.push(c);
            if(c.key==key) return c;
            else{var t=_find(c,key,l);if(t)return t;else {if(l)l.pop();}}
        }
    }
    this.getPath=function(key){//在集合中找到key对应的数据路径
        var l=[];
        _find(this.data,key,l);
        return l;
    }
    this.getPathText=function(k,s){//在集合中找到key对应的数据路径的文本
        var l=this.getPath(k),len=l.length,s=s?s:" > ",texts="";
        if(len>0){
            for(var i=0;i<len;i++){
                texts+=s+l[i].name;
            }
            texts=texts.substring(s.length);
        }
        return texts;
    }
    this.find=function(key){//在集合中找到key对应的数据
        return _find(this.data,key);
    }
    this.findByName=function(n,b){//b是否精确查找,true精确查找
        var l=[];
        _findByName(this.data,n,l,b);
        return l;
    }
    function _findByName(r,n,l,b){
        var cs=r.childs,len=cs.length;
        for(var i=0;i<len;i++){
            var c=cs[i];
            if((b&&c.name==n)||(!b&&c.name.indexOf(n)>-1))l.push(c);
            _findByName(c,n,l,b);
        }
    }
}

tool.randf.today=new Date(); 
tool.randf.seed=tool.randf.today.getTime(); 

var timer={
    start:function(f,t){
        var a=[];
        var len=arguments.length;
		for(var i=2;i<len;i++)a.push(arguments[i]);
        return setInterval(function(){f.apply(f,a);},t);
    },
    end:function(i){
        clearInterval(i);
    },
    delay:function(f,t){
        var a=[];
        var len=arguments.length;
		for(var i=2;i<len;i++)a.push(arguments[i]);
        return setTimeout(function(){f.apply(f,a);},t);
    },
    clear:function(k){clearTimeout(k);}
}

var actScript=null;
var script = function(c,url){
    this.name=url.substring(url.lastIndexOf("/")+1,url.lastIndexOf("."));
    this.url=url,this.uis={};
    eval(c);
    this.callBack=function(t,f){
        var l=this.callBack.list;
        if(!l) l=this.callBack.list={};
        if(!l[t]) l[t]=[];
        var a=[],len=arguments.length;
        for(var i=2;i<len;i++) a.push(arguments[i]);
        l[t].push({fun:f,args:a});
    }
    this.finish=function(){//完成文档的分析
        var l=this.callBack.list,t,len,ty=["link","send"],tyl=ty.length;
        if(!l)return;
        this.insideCount=0;
        for(var i=0;i<tyl;i++){
            var n=l[ty[i]];
            if(n)this.insideCount+=n.length;
        }       
        if(l){
            for(var i=0;i<tyl;i++){
                if(t=l[ty[i]]){
                    len=t.length;
                    for(var k=0;k<len;k++){
                        var p=t[k],f=p["fun"];
                        f.apply(f,p["args"]);
                    }
                }
            }
            this.callBack.list=null;
        }
    }
    this.reduce=function(){//减去完成数计数
        this.insideCount--;
        if(this.insideCount<=0)
            if(this.render)this.render();
    }
    this.destroy=function(){
        
    }
 }
 
var cmd = function(s,act,x){
    if(!(this.para=x))this.para="";
    this.action=this;
    this.script=s?s:new script("",window.location.pathname);
    this.act=act;
    this.text=null;
    this.xml=function(){return this.para;}
    this.mask=function(){tool.mask();}
    this.emask=function(){tool.emask();}
    this.exec=function(){http.send(this,true);}
    this.add=function(n,v,l){//增加参数
        if(l){}else this.para+="<"+n+" value='"+v+"' />";
    }
    this.clear=function(){//清空参数
        this.para="";
    }
}

var ui={
    init:function(o,s){
        var t;
        if(t=dom.get(o,"fancy"))ui[t].init(o,s);
    }
}

/*obj*/
ui.obj={
    init:function(o,s){
            if(!s.obj) s.obj={};
            var n=dom.get(o,"name"),a=dom.get(o,"act"),dep=dom.get(o,"deplay"),t,obi;
            if(s.obj[n]) return;//如果已经存在该对象控件则退出
            else obi=s.obj[n]={
                save:dom.get(o,"save"),//是否在根对象上保留所有数据
                antetype:o.cloneNode(true),//原型
                list:[],//对象队列
                create:function(d){//根据数据，创建新对象实例
                    var ol=this.list,ant=this.antetype,cur=ol.length==0?o:ant.cloneNode(true);
                    ui.obj.bind(cur,d,s,cur);
                    this.list.push(cur);
                    if(this.save)cur.data=d;
                    evt.exec(s,dom.get(cur,"onbind"),cur,d);//绑定结束时触发的事件
                    return cur;
                },
                bind:function(d,i){
                    if(!i)i=0;
                    var l=this.list,c;
                    if(l.length==0)this.create(d);
                    else{
                        c=l[i];
                        ui.obj.bind(c,d,s,c);
                        if(this.save)c.data=d;
                        evt.exec(s,dom.get(c,"onbind"),c,d);//绑定结束时触发的事件
                    }
                },
                clear:function(i){
                    if(!i)i=0;
                    var l=this.list,c;
                    if(l.length>0){
                        c=l[i];
                        ui.obj.bind(c,{},s,c);
                        evt.exec(s,dom.get(c,"onclear"),c);//绑定清空时触发的事件
                    }
                }
            }
            ui.obj.parse(o,o,s);
            
            if(t=dom.get(o,"onmask"))o.mask=function(){evt.exec(s,dom.get(o,"onmask"),o);};
            if(t=dom.get(o,"onemask"))o.emask=function(){evt.exec(s,dom.get(o,"onemask"),o);};
            
            if(a&&!dep){//有请求
                o.act=a;
                o.xml=function(){return "";};
                if(!(t=dom.get(o,"onmask")))o.mask=function(){tool.mask();};
                if(!(t=dom.get(o,"onemask")))o.emask=function(){tool.emask();};
                o.after=function(r){
                    var d;
                    for(var e in r){d=r[e];break;}
                    if(!d){alert("无对象数据！");debugger;return;}
                    obi.bind(d,0);//根据对象信息创建一个对象实例
                    s.reduce();
                }
                s.callBack("send",function(o){http.send(o,true);},o);//等待代码分析完后发送请求
            }
            o.script=s;
    },
    parse:function(o,r,s){
        var l=dom.childs(o),len=l.length;
        for(var i=0;i<len;i++){
            var c=l[i],u=dom.get(c,"ui");
            ui.init(c,s);
            if(u){if(!r.uis)r.uis={};if(!r.uis[u])r.uis[u]=c;}
            ui.obj.parse(c,r,s);
        }
    },
    bind:function(o,d,s,r){//r为根节点root
        ui.init(o,s);
        if(o.isNotBind)return;
        var b=dom.get(o,"bind"),ct=true;
        if(b){
            eval("b="+b+";");
            //检测标签正确性
            var loop=b["loop"],obj=b["obj"],cd;
            if(loop&&obj){alert("不能同时指定loop和obj绑定标签！");return;};
            //处理普通标签
            for(var e in b){
                if(e=="loop"||e=="obj")continue;
                var t,n=b[e],v=d[n];
                if(v==undefined)v="";
                if(t=ui.obj.bindExt[e]) e=t;
                dom.set(o,e,v);
                if(!cd)cd={};
                cd[n]=v;
            }
            if(cd){//如果有普通标签绑定，则触发事件
                var t=dom.get(o,"onbind");
                evt.exec(s,t,o,cd);
            }
            
            if(loop){//处理循环类型
                if(!o.antetype)o.antetype=o.cloneNode(true);//得到循环原型
                if(!o.list)o.list=[o];//循环队列
                var v=d[loop];
                if(!v)v=[];
                var vl=v.length,f=dom.father(o),ds=vl-o.list.length,ant=o.antetype;
                for(var k=0;k<ds;k++){
                    var c=ant.cloneNode(true);
                    c.isNotBind=true;//标示该对象自身不参与绑定引擎(由它的克隆原型指挥对象进行绑定操作)
                    dom.append(f,c);
                    o.list.push(c);
                }
                var cl=o.list.length;
                for(var k=0;k<cl;k++){
                    if(k<vl){
                        var c=o.list[k],t=dom.get(c,"onbind"),l=dom.childs(c),len=l.length,d=v[k];
                        for(var j=0;j<len;j++)ui.obj.bind(l[j],v[k],s,r);
                        c.data=d;
                        dom.show(c);
                        evt.exec(s,t,c,d);
                    }
                    else dom.hidden(o.list[k]);
                }
                ct=false;
            }
            else if(obj){//处理对象
                
            }
        }
        
        if(ct){
            var l=dom.childs(o),len=l.length;
            for(var i=0;i<len;i++){
                var c=l[i],u=dom.get(c,"ui");
                if(u){if(!r.uis)r.uis={};if(!r.uis[u])r.uis[u]=c;}
                ui.obj.bind(c,d,s,r);
            }
        }
    },
    bindExt:{html:"innerHTML",text:"innerText"}
}

/*mask*/
ui.mask={
    init:function(o){
        o.mask=function(){
            o.style.display="block";
        }
        o.emask=function(){
            o.style.display="none";
        }
        var t;
        if(t=dom.get(o,"src"))
        {
            o.style.backgroundImage="url("+t+")";
            o.style.backgroundRepeat="no-repeat";
        }
        if(t=dom.get(o,"text"))
        { 
            o.innerHTML=t;
        }
    }
}

/*input*/
ui.input={
    init:function(o,s){
        if(o.inited)return;else o.inited=true;//检查是否已经被初始化过
        if(dom.get(o,"inside")){//分析输入控件之前，先分析内部fancy
            dom.init(dom.childs(o),s);
        }
        var n=dom.get(o,"name"),ty=dom.get(o,"type");
        if(!ty)ty="text";
        var pi=o.parts={};
        this.parse(o.parts,o);//收集控件信息
        for(var e in pi){
            var c=pi[e];
            if(e=="core"){
                var f=this[ty];
                if(f)f(c,o,s);
            }
            else if(e=="error"){
                c.set=function(er){if(er)this.innerHTML=er;else this.innerHTML="";};
            }
        }
        
        o.get=function(){
            var c=this.parts["core"];
            if(c.get)return c.get();
        }
        o.set=function(v){
            var c=this.parts["core"],t=dom.get(o,"onset"),r;
            if(c.set) r=c.set(v);
            evt.exec(s,t,o,v);
            return r;
        }
        o.clear=function(){
            var c=this.parts["core"],e=this.parts["error"],t=dom.get(this,"onclear");
            if(c.clear)c.clear();
            else c.set("");
            if(e)e.set("");
            evt.exec(s,t,o);
        }
        o.mask=function(){
            var c=this.parts["core"];
            if(c.mask)c.mask();
            else if(dom.tag(c)=="input")c.disabled=true;
        }
        o.emask=function(){
            var c=this.parts["core"];
            if(c.emask)c.emask();
            else if(dom.tag(c)=="input")c.disabled=false;
        }
        o.check=function(){
            var c=this.parts["core"],e=this.parts["error"],er;
            if(c.check)er=c.check();
            var t=dom.get(o,"oncheck"),b;
            if(t&&s[t])b=s[t](er,o);
            if(e&&b!=false)e.set(er,e);
            o.__error=er;
            return !er;//如果有er则返回false,否则true
        }
    },
    parse:function(pi,o){
        var t=dom.get(o,"part");
        if(t)pi[t]=o;
        else{
            var l=dom.childs(o),len=l.length;
            for(var i=0;i<len;i++) this.parse(pi,l[i]);
        }
    },
    text:function(c,o,s){
        var t=dom.tag(c);
        if(t!="input"){alert("text类型的组件core对象必须为input！");return;};
        if(c.type!="text"){alert("text类型的组件input-type属性必须为text！");return;};
        ui.input.common(c,o);
    },
    pwd:function(c,o,s){
        var t=dom.tag(c);
        if(t!="input"){alert("pwd类型的组件core对象必须为input！");return;};
        if(c.type!="password"){alert("pwd类型的组件input-type属性必须为password！");return;};
        ui.input.common(c,o);
    },
    standard:function(c,o,s){//标准输入，只允许英文字母和数字,允许输入空格  . ,
        var t=dom.tag(c);
        if(t!="input"){alert("standard类型的组件core对象必须为input！");return;};
        if(c.type!="text"){alert("standard类型的组件input-type属性必须为text！");return;};
        ui.input.common(c,o);
        c.onkeydown=function(){
            var key,e=window.event,kc = e.keyCode?e.keyCode:e.which;
            if((kc >= 48 && kc <= 57)||(kc >= 65 && kc <= 90) || (kc == 8)||(kc == 9)||kc==32||kc==190||kc==188||kc==37||kc==39)return true;
            return false;
        }
        c.onpaste=function(){//ff3已支持
            return false;
        }
    },
    textarea:function(c,o,s){
        var t=dom.tag(c);
        if(t!="textarea"){alert("textarea类型的组件core对象必须为textarea！");return;};
        ui.input.common(c,o);
        if(c.maxLength){
            c.onkeydown=function(){
                var key,e=window.event,kc = e.keyCode?e.keyCode:e.which;
                if(kc==8||kc==9)return true;
                else if(this.value.length>=this.maxLength) return false;
            }
            evt.add(c,"blur","cklength",function(a){
                if(a.value.length>=a.maxLength) a.value=a.value.substring(0,a.maxLength);
            },
            c);
        }
        c.get=function(){
            if(!this.value) this.value="";//防止undefined出现
            return this.value;
        }
        c.set=function(v){
            this.value=v;
        }
    },
    common:function(c,o){
        var t;
        if(t=dom.get(o,"max")) c.maxLength=t;
        c.check=function(){
            var m=dom.get(o,"min"),n=dom.get(o,"need"),er,v=this.value,ca=dom.get(o,"call");
            if(n&&(v.length==0)) er="请输入"+ca;
            else if(m&&(v.length<m)) er=ca+"不能少于"+m+"个字符";
            return er;
        }
        c.get=function(){
            if(!this.value) this.value="";//防止undefined出现
            return this.value;
        }
        c.set=function(v){
            this.value=v;
        }
    },
    number:function(c,o,s){
        var t=dom.tag(c);
        if(t!="input"){alert("number类型的组件core对象必须为input！");return;};
        if(c.type!="text"){alert("number类型的组件input-type属性必须为text！");return;};
        c.maxLength=15;
        
        c.onkeyup=function(){
            var key,e=window.event,kc = e.keyCode?e.keyCode:e.which,v=c.value;
            if(kc>=37&&kc<=40)return;
            c.value=v.replace(/[^0-9.]/g,'').replace(/[.][0-9]*[.]/,'.');
        }
          
        c.get=function(){
            if(!this.value) this.value="";//防止undefined出现
            return this.value;
        }
        c.set=function(v){
            this.value=v;
        }
        c.check=function(){
            var n=dom.get(o,"need"),er,v=this.value,ca=dom.get(o,"call");
            if(n&&(v.length==0)) er="请输入"+ca;
            return er;
        }
    },
    hidden:function(c,o,s){
        var t=dom.tag(c);
        if(t!="input"){alert("hidden类型的组件core对象必须为input！");return;};
        if(c.type!="hidden"){alert("hidden类型的组件input-type属性必须为hidden！");return;};
        c.get=function(){
            if(!this.value) this.value="";//防止undefined出现
            return this.value;
        }
        c.set=function(v){
            this.value=v;
        }
        dom.hidden(o);
    },
    single:function(c,o,s){
        o.collect=function(){//重新收集选项信息
            c.options=[];
            var l=$$$(c,"option"),len=l.length;
            for(var i=0;i<len;i++){
                var p=l[i];
                p.select=function(b){
                    if(b!=false)b=true;
                    if(b)c.clear();
                    this.selected=b;
                    evt.exec(s,dom.get(o,"onselect"),this);
                }
                c.options.push(p);
            }
        }
        
        c.get=function(){
            var l=this.options,len=l.length,v="";
            for(var i=0;i<len;i++){
                var p=l[i];
                if(p.selected){v=dom.get(p,"value");break;}
            }
            return v;
        }
        c.set=function(v){
            if(!v&&v!=0)v="";
            var l=this.options,len=l.length;
            for(var i=0;i<len;i++){
                var p=l[i];
                if(dom.get(p,"value")==v){p.select();break;}
            }
        }
        c.clear=function(){
            var l=this.options,len=l.length;
            for(var i=0;i<len;i++){var t=l[i];if(t.selected){t.select(false);break;}}
        }
        c.check=function(){
            var n=dom.get(o,"need"),er,v=this.get(),ca=dom.get(o,"call");
            if(n&&!v) er="请选择"+ca;
            return er;
        }
        o.select=function(i){
            c.options[i].select();
        }
        
        c.options=[];
        var l=$$$(c,"option"),len=l.length,sp;
        for(var i=0;i<len;i++){
            var p=l[i];
            if(dom.get(p,"selected"))sp=p;
            p.select=function(b){
                if(b!=false)b=true;
                if(b)c.clear();
                this.selected=b;
                evt.exec(s,dom.get(o,"onselect"),this);
            }
            c.options.push(p);
        }
        if(sp)sp.select();
    },
    multi:function(c,o,s){
        c.options=[];
        var l=$$$(c,"option"),len=l.length,sl=[];
        for(var i=0;i<len;i++){
            var p=l[i];
            p.select=function(b){
                if(b!=false)b=true;
                this.selected=b;
                evt.exec(s,dom.get(o,"onselect"),this);
            }
            if(dom.get(p,"selected"))sl.push(p);
            c.options.push(p);
        }
        len=sl.length;
        for(var i=0;i<len;i++)sl[i].select();
        
        c.get=function(){
            var l=this.options,len=l.length,v=[];
            for(var i=0;i<len;i++){
                var p=l[i];
                if(p.selected)v.push(dom.get(p,"value"));
            }
            v=v.join(",");
            if(v.length==0)return"";
            return v;
        }
        c.set=function(v){
            if(!v&&v!=0) v="";
            var l=this.options,len=l.length,vl=v.split(',');
            for(var i=0;i<len;i++){
                var p=l[i],cv=dom.get(p,"value");
                if(vl.indexOf(cv)>-1)p.select();else p.select(false);
            }
        }
        c.clear=function(){
            c.set("");
        }
        c.check=function(){
            var n=dom.get(o,"need"),er,v=this.get(),ca=dom.get(o,"call");
            if(n&&!v) er="请选择"+ca;
            return er;
        }
    },
    custom:function(c,o,s){
        var t=dom.get(c,"get");
        if(t)c.get=s[t];
        else c.get=function(){return this.value;}
        t=dom.get(c,"set");
        if(t)c.set=s[t];
        else c.set=function(v){this.value=v;}
        t=dom.get(c,"clear");
        if(t)c.clear=s[t];
        else c.clear=function(){this.value="";}
        t=dom.get(c,"check");
        if(t)c.check=s[t];
    },
    file:function(c,o,s){
        var t=dom.tag(c),f=$$(o,"form")[0],upf,l=$$(o,"input"),len=l.length,upid=tool.randi(99999999);
        if(t!="input"){alert("file类型的组件core对象必须为input！");return;};
        if(c.type!="text"){alert("file类型的组件input-type属性必须为text！");return;};
        if(!f){alert("file类型的组件内必须包含form元素！");return;};
        if(!(t=dom.get(f,"enctype"))||t.toLowerCase()!="multipart/form-data"){alert("form元素的enctype值必须为multipart/form-data！");return;};
        for(var i=0;i<len;i++){if(l[i].type=="file"){upf=l[i];break;}}
        if(!upf){alert("file类型的组件内必须包含<input type=file />！");return;};
       
        dom.set(f,"method","post");
        dom.set(f,"target","upstatus");
        dom.set(f,"action",__fwww+"HttpUploadFinish.htm?uploadId="+upid);
        
        if(!document.body.upstatus){
            var d=dom.create("div");
            d.innerHTML="<iframe name=\"upstatus\" frameborder=\"no\"></iframe>";
            d.style.display="none";
            dom.append(document.body,d);
            document.body.upstatus=$$(d,"iframe")[0];
        }
        
        o.cancel=function(){
            document.body.upstatus.contentWindow.location=__fwww+"HttpUploadEnd.htm?uploadId="+upid;
            o.status.cancel=true;
        }
        
        o.upfile=function(){
            var path=upf.value;
            if(!path){alert("请选择上传的文件！");return;}
            else if(c.value.indexOf("/")!=-1){alert("文件已经上传！");return;}
            var e=dom.get(o,"ext"),ex=[],ext=tool.getExt(path);
            if(e){
                var l=e.split(","),len=l.length;
                for(var i=0;i<len;i++)ex.push(l[i]);
                if(ex.indexOf(ext)==-1){alert("文件格式非法，只能上传"+e+"格式的文件！");return;};
            }

            f.submit();
            var s=o.status;
            s.times=1;//请求次数设置为1
            s.cancel=false;
            s.start=new Date();
            timer.delay(function(s){http.send(s,true);},500,s);
            return true;
        }
        
        o.status={
            script:s,
            act:__fwww+"HttpUploadStatus.htm?uploadId="+upid,
            mask:function(){},
            emask:function(){},
            after:function(r){
                var t=dom.get(o,"onuping"),st=o.status,rs=r.status;
                if(st.cancel) return;
                st.times++;
                if(!rs&&st.times>25)rs={error:"上传文件失败，连接超时！"};//当请求过了25次都得不到状态则退出
                if(rs)evt.exec(s,t,rs,o);
                if(rs&&rs.error)return;
                if(rs&&rs.isComplete){//当上传完成，并且处理完成后
                    var fn=rs.files[0];
                    c.set(fn);
                    return;
                }
                timer.delay(function(s){http.send(s,true);},500,st);
            }
        }
        
        c.clear=function(){
            c.value="";
            if(upf.value){
                var tfi=dom.create("input"),fa=dom.father(upf);
                dom.del(upf);
                dom.set(tfi,"type","file");
                dom.set(tfi,"name","file");
                dom.append(fa,tfi);
                upf=tfi;
            }
        }
        
        c.get=function(){
            if(!this.value) this.value="";//防止undefined出现
            return this.value;
        }
        c.set=function(v){
            this.value=v;
        }
        
        c.check=function(){
            var er;
            if(this.value.indexOf("\\")>-1)er="您选择的文件还没有上传，请点击提交按钮上传文件，或者清空文件后再提交数据！";
            return er;
        }
    },
    date:function(c,o,s){
        var t=dom.tag(c);
        if(t!="input"){alert("date类型的组件core对象必须为input！");return;};
        if(c.type!="text"){alert("date类型的组件input-type属性必须为text！");return;};
        c.maxLength=15;
        
        dom.set(o,"format","[{type:'custom',rule:'year_month_day',length:4},{type:'occupy',text:'/'},{type:'custom',rule:'year_month_day',length:2},{type:'occupy',text:'/'},{type:'custom',rule:'year_month_day',length:2}]");
        ui.input.validate(o,c);
        c.get=function(){
            var v=this.value;
            if(v=="    /  /  ") return "1753/01/01";
            return v;
        }
        c.set=function(v){
            if(tool.type(v)=="string"){
               v=v.split(' ')[0];
               var sp='-';
               if(v.indexOf(sp)==-1)sp='/';
               var t=v.split(sp),y=t[0],m=t[1],d=t[2];
               if(m.length==1)m="0"+m;
               if(d.length==1)d="0"+d;
               v=y+"/"+m+"/"+d;
            }
            else v=v.toShort();
            if(v=="1753/01/01") this.value="    /  /  ";
            else this.value=v;
            return v;
        }
        c.check=function(){
            var n=dom.get(o,"need"),er,v=this.get(),ca=dom.get(o,"call");
            if(n&&(v=="    /  /  "||v=="1753/01/01")) er="请输入"+ca;
            return er;
        }
        c.clear=function(v){
            this.value="    /  /  ";
        }
    },
    edit:function(c,o,s){
        var ifr=$$(c,"iframe")[0];
        if(!ifr){alert("edit类型的组件core对象内必须包含iframe！");return;}
        var e=c.edit=ifr.contentWindow,d=e.document;
        d.open();
	    d.write("<html><head><style type=\"text/css\">body {font-size:14px;font-family:Arial;margin:2px;height:90%;width:99%;}table {border:1px solid #333;border-collapse:collapse;}td {border:1px solid #333;text-align:center;padding:0px 5px;}p{margin-top:10px;}img{border:0px;}.pagespliter{height:10px;width:100%;background:url(/pic/edit/pagespliter.gif) repeat-x left center;}</style><script>if(window.Event){window.constructor.prototype.__defineGetter__(\"event\", function(){var o = arguments.callee.caller,e;while(o != null){e = o.arguments[0];if(e && (e.constructor == Event || e.constructor == MouseEvent || e.constructor==KeyboardEvent)) return e;o = o.caller;}return null;});}</script></head><body></body></html>");
	    d.close();
	    d.charset="utf-8";
	    if(ie) d.designMode="On";
        else{//解决ff下隐藏的文本编辑器不能直接设置designMode属性
	        e.document.onmousedown=function(){
	            if(this.editmode) return;
	            this.designMode="On";
                this.editmode=true;
	        }
	    }
	    
	    var ms=function(e){
            var ed=c.edit,ci;
            if(!e)e=ed.event;
//            if(!ie) ci=e.explicitOriginalTarget;
//            else if(ed.document.selection.type == "Control") ci=e.srcElement;
//            else ci= ed.document.selection.createRange();
            ////else ci= ed.document.selection.createRange().parentElement();
            if(ed.document.selection){
                var sel=ed.document.selection;
                if(sel.type == "Control") ci=e.srcElement;
                else ci= sel.createRange();
            }
            else{//ff下暂时没有判断是否非文字，等下补充
                ci=ed.getSelection().getRangeAt(0);
            }
            c.current= ci;
        }
	    if(ie){e.document.onmouseup=ms;e.document.onkeyup=ms;}
	    else{
	        e.document.addEventListener("mouseup",function(event){ms(event)},true);
	        e.document.addEventListener("keyup",function(event){ms(event)},true);
	    }

	    c.execCmd=function(cmd,p1,p2){
            var e = this.edit,ci=this.current;
            e.focus();
            if(ci){
                if(ci.collapse){//选中的是文本
                    if(!ci.htmlText)ci.collapse(false);
                    if(ie)ci.select();
                    else{//ff
                        //event.srcElement.setSelectionRange();
                    }
                }
            }
            e.document.execCommand(cmd,p1,p2);
        }
        
        c.insert=function(s){
            var ed=this.edit;
            ed.focus();
            var cu=this.current;
            if(!cu){cu=ed.document.body;cu.innerHTML=s.outerHTML;}
            else if(cu.pasteHTML)cu.pasteHTML(s.outerHTML);
            else {
                if(!dom.isHTML(cu)) cu=ed.document.body;
                var tg=dom.tag(cu);
                if(tg=="img"){cu.outerHTML=s.outerHTML;}
	            else if(cu.appendChild){dom.append(cu,s);}
	            else cu.innerHTML=cu.outerHTML;
	        }
        }
	    
	    var l=$$$(c,"cmd"),len=l.length;
	    for(var i=0;i<len;i++){
	        var ci=l[i],n=dom.get(ci,"cmd");
	        dom.set(ci,"unselectable","on");
	        switch(n){
	            case "b":
                    ci.onmousedown=function(){c.execCmd("bold",false);}
                break;
                case "i":
                    ci.onmousedown=function(){c.execCmd("Italic",false);}
                break;
                case "u":
                    ci.onmousedown=function(){c.execCmd("Underline",false);}
                break;
                case "left":
                    ci.onmousedown=function(){c.execCmd("JustifyLeft",false);}
                break;
                case "center":
                    ci.onmousedown=function(){c.execCmd("JustifyCenter",false);}
                break;
                case "right":
                    ci.onmousedown=function(){c.execCmd("JustifyRight",false);}
                break;
                case "pagespliter":
                    ci.onclick=function(){
                        var p=dom.create("p");
                        p.className="pagespliter";
                        if(!ie){
                            var rs = c.edit.window.getSelection(),rlen=rs.rangeCount,io;
                            if(rlen>0){
                                for (var i=0;i<rlen;i++) rs.getRangeAt(i).deleteContents();
                                io=rs.getRangeAt(0);
                                io.insertNode(p);
                            }else {io=c.edit.document.body;dom.append(io,p);}
                            
                        }else c.insert(p);
                    }
                break;
	        }
	    }
	    
	    //额外
	    //code
	    c.toCode=function(){
            var b=c.edit.document.body;
            if(c.mode=="code") return;
            if(ie)b.innerText=b.innerHTML;
            else{
                var t=dom.txt(b.innerHTML);
		        b.innerHTML = "";
		        b.appendChild(t);
            }
            c.mode="code";
        }
        //设计
        c.toDesign=function(){
            var b=c.edit.document.body;
            if(c.mode=="design") return;
            if(ie)b.innerHTML=b.innerText;
            else b.innerHTML=b.textContent;
            c.mode="design";
        }
        
        c.check=function(){
            var bo=c.edit.document.body,v;
            if(ie)v=bo.innerText; else v=bo.textContent;
            var n=dom.get(o,"need"),er,ca=dom.get(o,"call");
            if(n&&v.length==0) er="请输入"+ca;
            return er;
        }
        
        c.get=function(){
            var b=this.edit.document.body,s;
            if(this.mode=="code") s=ie?b.innerText:b.textContent;
            else s=b.innerHTML;
            s = s.replace(/<\/?SPAN[^>]*>/gi, "");
	        s = s.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	        s = s.replace(/<(\w[^>]*) style="([^"]*)"([^>]*)/gi, "<$1$3") ;
	        s = s.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	        s = s.replace(/<\\?\?xml[^>]*>/gi, "") ;
	        s = s.replace(/<\/?\w+:[^>]*>/gi, "") ;
	        s = s.replace(/&nbsp;/, " " );
	        var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different because of a IE 5.0 error
	        s = s.replace(re, "<div$2</div>");

	        return s;
        }
        c.set=function(s){
            this.toDesign();
            var doc=this.edit.document,b=doc.body;
            b.innerHTML=s;
            return o.get();
        }
        c.clear=function(){
            this.set("");
            this.toDesign();
        }
    },
    validate:function(o,p){
        eval("var f="+dom.get(o,"format")+";");
        var len=f.length,tokens=[],startIndex=0,val=[],avaiIndexs=[];
        for(var i=0;i<len;i++){
            var token={occupy:" ",align:"left"},inf=f[i];
            switch(inf.type){
                case "number":
                {
                    token.max=999999999;
                    token.min=0;
                    
                    if(inf.max||inf.max==0)token.max=inf.max;
                    if(inf.min||inf.min==0)token.min=inf.min;
                    if(inf.align) token.align=inf.align;
                    if(inf.occupy) token.occupy=inf.occupy;
                    if(token.min<0) token.occupy=" ";
                    
                    token.length = (token.max+"").length;
                    var sma = token.max+"",smi =token.min+"";
                    token.length = sma.length>smi.length?sma.length:smi.length;
                }
                break;
                case "custom":
                {
                    var r=ui.input.rule[inf.rule];
                    token.rule=r;
                    token.length=r.length;
                    if(inf.align) token.align=inf.align;
                    if(inf.length) token.length=inf.length;
                }
                break;
                default:
                {
                    //占位符
                    var t=inf.text;
                    token.length = t.length;
                    token.value = t;
                    val[startIndex] = t;
                }
            }
            if(inf.type!="occupy")avaiIndexs.push(i);
            if(inf.empty) token.empty=true;else token.empty=false;//是否允许为空
            token.type=inf.type,tlen=token.length;
            if(token.type!="occupy") for(var k=0;k<tlen;val[startIndex+k++]=token.occupy);
            token.startIndex = startIndex;
            startIndex+=token.length;
            tokens[i] = token;
            token.index = i;
        }
        
        var totLen = startIndex,tlen= tokens.length;
        for(var i=0;i< tlen;i++ ){
            var token = tokens[i];
            token.endIndex = totLen - token.startIndex - token.length;
        }
        tokens.defText = val.join("");    //该格式输出的默认文本
        p.avaiIndexs=avaiIndexs;
        p.changeCheck=function(){//输入结束时的验证,b代表是单元切换还是整个输入结束
            var tokens = this.tokens,txt="",len=tokens.length;
            for(var i=0;i<len;i++){
                var token = tokens[i],t=this.getAvaiText(token);
                if(t.length!=0||!token.empty){
                    switch(token.type)
                    {
                        case "number":
                        {
                            if(t.length==0||parseInt(t)<token.min) {t=token.min;break;}
                            if(t.length==0||parseInt(t)>token.max) {t=token.max;break;}
                            t=t+"";
                            var tlen=token.length;
                            if(t.length<tlen){
                                if(token.align=="right")
                                    for(var k=t.length;k<tlen;k++) t+=token.occupy;
                                else
                                    for(var k=t.length;k<tlen;k++) t=token.occupy+t;
                            }
                        }
                        break;
                        case "custom":
                        {
                            t=token.rule.changeExec(this,token,t); //规则验证过滤
                        }
                        break;
                    }
                }
                txt+=t;
            }
            this.value = txt;
        }

        p.getAvaiText= function(token,input){ //获得有效区域的value值
            if(!input) input = this;
            var t = input.value.substring(token.startIndex,token.startIndex+token.length);
            if(token.align&&token.occupy!=undefined) t=token.align=="left"?t.leftTrim(token.occupy):t.rightTrim(token.occupy);
            return t.trim();
        };
        
        p.selectRange=function(){    //根据当前token的坐标与鼠标坐标的对比来得到当前活动的range
              this.setArea();
              this.setAvaiAct();
              this.showFocus();
        }
        
        p.setArea=function(){    //根据当前的文字大小和token对象起始index值,分配token的区域坐标
            var tlen=this.tokens.length;
            if(ie){
                for(var i=0;i<tlen;i++){
                    var token = this.tokens[i],range = this.createRange(token);
                    token.left = range.offsetLeft;
                    token.right = range.offsetLeft + range.boundingWidth;
                    token.top = range.offsetTop;
                    token.bottom = range.offsetTop + range.boundingHeight;
                }
            }
        }
        
        p.createRange=function(token){  //根据token的起始值,得到token对应的range
           var range = this.createTextRange();
           range.moveStart('character', token.startIndex);
           range.moveEnd('character', -token.endIndex);
           return range;
        };
        
        p.setAvaiAct=function(){ //设置有效的act
            var tokens = this.tokens,event = window.event, x = event.offsetX, y = event.offsetY;
            this.prvAct = this.act;//记录上次有效的act
            for(var i=0;i<tlen;i++){
               var token = tokens[i];
               if(token.left <= x && x <= token.right && token.top <= y && y <= token.bottom){ this.act = i;break; }
            }
            
            
            if(this.act==undefined){
                for(var i=0;i<tlen;i++){
                    if(tokens[i].type!="occupy") {this.act=i;break;}
                }
            }
            else{
                if(tokens[this.act].type=="occupy"&&this.prvAct==undefined) {
                    for(var i=0;i<tokens.length;i++){
                        if(tokens[i].type!="occupy") {this.act=i;break;}
                    }
                }
                if(tokens[this.act].type=="occupy") this.act = this.prvAct;
            }
        }
        
        p.showFocus=function(){  //显示选择区域的背景
            var token = this.tokens[this.act];
            if(ie)this.createRange(token).select();
            else this.setSelectionRange(token.startIndex, token.startIndex + token.length);
        };
        
        p.onmousedown = function(){
            //this.endCheck();
            if(ie)this.selectRange();
            else this.setSelectionRange(0, 0);
        };
        
        p.onmouseup = function(){
            if(ie){
                if(this.act==undefined)
                    this.selectRange();    //防止在外面mousedown,然后拖进控件内mouseup
                else
                    this.showFocus();
            }else{
                var ci = this.selectionStart,avaiIndexs=this.avaiIndexs,alen=avaiIndexs.length;
                for(var i=0;i<alen;i++){
                     var token = this.tokens[avaiIndexs[i]];
                     if(token.startIndex <= ci && ci <= token.startIndex + token.length){
                        this.act = avaiIndexs[i];
                        break;
                     }
                }
                this.showFocus();
            }
        };
        
        p.ondragstart = function(){ return false;};
        
        p.onkeydown=function(){
            this.processCheck();
            return false;
        };
        
        p.onfocus=function(){
            this.selectRange();
        };
        
        p.endCheck=function(){
            var tokens = this.tokens,txt="",len=tokens.length;
            for(var i=0;i<len;i++){
                var token = tokens[i],t=this.getAvaiText(token);
                if(t.length!=0||!token.empty){
                    switch(token.type)
                    {
                        case "number":
                        {
                            if(t.length==0||parseInt(t)<token.min) {t=token.min;break;}
                            if(t.length==0||parseInt(t)>token.max) {t=token.max;break;}
                            t=t+"";
                            var tlen=token.length;
                            if(t.length<tlen){
                                if(token.align=="right")
                                    for(var k=t.length;k<tlen;k++) t+=token.occupy;
                                else
                                    for(var k=t.length;k<tlen;k++) t=token.occupy+t;
                            }
                        }
                        break;
                        case "custom":
                        {
                            t=token.rule.endExec(this,token,t); //规则验证过滤
                        }
                        break;
                    }
                }
                txt+=t;
            }
            this.value = txt;
        }
        
        p.onblur= function(){
            this.changeCheck();
            this.endCheck();
            var t = this.value.indexOf(' ');
            switch(this.type)
            {
                case "date_area":
                    if(t>-1) this.value=this.father.tokens.mask;
                break;
                case "date":
                    if(t>-1) this.value=this.father.tokens.mask;
                break;
                case "dateTime":
                    if(t>-1&&t!=10) this.value=this.father.tokens.mask;
                break;
            }            
        };
        
        p.processCheck=function(){ //正在输入时的验证
            if(this.act==undefined) return;
            var event = window.event,ek = event.which ? event.which : event.keyCode;

            if(ek==9){//tab
                var nextToken = this.getNearToken(this.act);
                if(!nextToken) return;
                this.act = nextToken.index;
                this.changeCheck();
                this.showFocus();
                return;
            }
            
            if(ek==37||ek==39){  //如果是箭头,则跳转range
                var act = this.act;
                var nextToken = ek==37?this.getNearToken(act,"prev"):this.getNearToken(act,"next");
                if(!nextToken) return;
                this.act=nextToken.index;
                
                this.changeCheck();
                this.showFocus();
                return;
            }

            var token = this.tokens[this.act],val =ui["input"]["codeVal"][ek];
            if(val==undefined&&ek!=8&&ek!=46)return;
            
            if(this.act+1<this.tokens.length&&this.act+2<this.tokens.length&&val==this.tokens[this.act+1].value){    //分隔符号自动跳转到下一个区域
                var nextToken = this.getNearToken(this.act);
                if(!nextToken) return;
                this.act = nextToken.index;
                this.changeCheck();
                this.showFocus();
                return;
            }
            
            var txt = this.getAvaiText(token).trim(),b = true,t=txt;
            if(ek==8||ek==46){
                t="";   //del键
                if(ek==8){   //backspace键
                    var arr = txt.split(''),len=arr.length-1;
                    for(var i=0;i<len;i++) t+=arr[i];
                }
            }
            else
            {
                switch(token.type)
                {
                    case "number":
                    {
                        if(val<=9&&val>=0){
                            if(txt.length >=token.length||txt.length==0) t=val; else t=txt+val;
                        }
                        else if(val=="-"){
                            if(token.min>=0){b = false;break;}
                            
                            if(txt.length >=token.length||txt.length==0) t=val;
                            else{
                                if(txt.indexOf('-') ==-1) t=val+txt; else {b=false;break;}
                            }
                        }
                        if(t.length==token.length){   //字数满时就检查数据的合法性
                            if(parseInt(t)<token.min || parseInt(t)>token.max) t=val;
                            else{
                                //验证成功,则跳到下一个输入区域
                                var t2;
                                if(t2= this.getNearToken(this.act,"next")){this.act = t2.index;this.showFocus();}
                            }
                        }
                    }
                    break;
                    case "custom":
                    {
                        var r=token.rule.processExec(this,token,txt,val); //规则验证过滤
                        t=r.value;
                        if(r.end){//如果验证结束
                            var t2;
                            if(t2= this.getNearToken(this.act,"next")){this.act = t2.index;this.showFocus();}
                        }
                    }
                    break;
                } 
            }
            
            if(b) this.setAvaiText(t,token);
            
            this.showFocus();
        }
        
        p.setAvaiText=function(txt,token){   //设置有效区域的value值
            txt = txt+"";
            var tlen=token.length;
            for(var i=txt.length;i<tlen;i++) txt =" "+txt;
            
            var ml = token.startIndex+token.length,t = this.value.split('');
            txt = txt.split('');
            for(var i=token.startIndex,k=0;i<ml;i++,k++)t[i] = txt[k];
            this.value = t.join('');
        }
        
        
        p.getNearToken=function(act,sign){ //获得离act最近的,有效的token(非占位token)
            if(act<0||act>=this.tokens.length) return;
            
            switch(sign)
            {
                case "next":
                    act++;
                    while(act<this.tokens.length&&this.tokens[act].type=="occupy") act++;
                    if(act<this.tokens.length&&this.tokens[act].type!="occupy")  return this.tokens[act]; else return null;
                break;
                case "prev":
                    act--;
                    while(act>=0&&this.tokens[act].type=="occupy") act--;
                    if(act>=0&&this.tokens[act].type!="occupy")  return this.tokens[act]; else return null;
                break;
                default:    //循环找
                {
                    act++;
                    if(act>=this.tokens.length) act = 0;
                    while(act<this.tokens.length&&this.tokens[act].type=="occupy") act++;
                    if(act<this.tokens.length&&this.tokens[act].type!="occupy")  return this.tokens[act]; else return null;
                }
            }
        }
        
        p.value=tokens.defText;
        p.tokens=tokens;
        p.endCheck();
        
        return p;
    }
}

ui["input"]["codeVal"]={48:0,49:1,50:2,51:3,52:4,53:5,54:6,55:7,56:8,57:9,190:'.',191:'/'};
if(ie) ui["input"]["codeVal"][189]="-";else ui["input"]["codeVal"][109]="-";

ui.input.rule={
    year_month_day:{
        processExec:function(p,t,v,val){//正在输入时的验证,v代表当前执行验证区域的有效值,val是用户按键对应的值,返回值是一个类似{value:'',end:true}的对象
              var r={value:"",end:false};
              if(v==""&&(val>9||val<=0)) return r;//输入的不是数字
              switch(t.index){
                case 0:{//验证年
                    var txt=v+val;
                    if(txt.length>4)r.value=val;
                    else if(txt.length==4){
                        var num=parseInt(txt);
                        if(num>2999||num<1753) r.value=val;
                        else {r.value=txt;r.end=true;}
                    }
                    else r.value=txt;
                    return r;
                }
                break;
                case 2:{//验证月
                    var txt=v+val;
                    if(txt.length>2) r.value=val;
                    else if(txt.length==2){
                        var num=parseInt(txt);
                        if(num>12||num<1) r.value=val;
                        else {r.value=txt;r.end=true;}
                    }
                    else r.value=txt;
                    return r;
                }
                break;
                case 4:{//验证日
                    var s=p.value.split('/'),y=s[0].trim(),m=s[1].trim(),d=s[2].trim(),max;
                    if(y.length==0||m.length==0) max=31;
                    else max = tool.getDay(parseInt(y),parseInt(m));
                    var txt=v+val;
                    if(txt.length>2) r.value=val;
                    else if(txt.length==2){
                        var num=parseInt(txt);
                        if(num>max||num<1) r.value=val;
                        else {r.value=txt;r.end=true;}
                    }
                    else r.value=txt;
                    return r;
                }
                break;
              }
        },
        changeExec:function(p,t,v){//切换选区时的验证,v代表当前执行验证区域的有效值,t是token对象
            switch(t.index){
                case 0:{
                    if(v.length==0) return "    ";
                    if(v.length<4) return "1753";
                    return v;
                }
                break;
                case 2:{
                    if(v.length==0) return "  ";
                    if(v.length<2) return "0"+v;
                    return v;
                }
                break;
                case 4:{
                    if(v.length==0) return "  ";
                    if(v.length<2) return "0"+v;
                    if(v.length==2){
                        var s=p.value.split('/'),y=s[0].trim(),m=s[1].trim(),d=s[2].trim(),max;
                        if(y.length==0||m.length==0) max=31;
                        else max = tool.getDay(parseInt(y),parseInt(m));
                        var num=parseInt(v);
                        if(num>max) return max+"";
                        else return v;
                    }
                }
                break;
            }
        },
        endExec:function(p,t,v){//全部输入完时的验证,v代表当前执行验证区域的有效值,t是token对象
            var s=p.value.split('/'),y=s[0].trim(),m=s[1].trim(),d=s[2].trim(),empty;
            if(y.length==0||m.length==0||d.length==0) empty=true;
            if(empty){
                if(t.index==0) return "    ";
                else return "  ";
            }
            return v;
        }
    }
}

/*form*/
ui.form={
    init:function(o,s){
        if(!s.form) s.form={};
        var n=dom.get(o,"name"),f=s.form[n];
        if(!f){s.form[n]=f={
                    uis:{},
                    act:{},
                    sub:{},
                    action:null,
                    set:function(d,n){
                        if(!tool.isUndefined(n)){d.set(n);d.initValue=n;return;}
                        else{
                            //先清空整个表单
                            f.clear();
                            var uis=f.uis;
                            for(var e in d){
                                if(e=="key") f.submitKey.set(d[e]);
                                else{
                                    var u=uis[e],v,iv;if(!u) continue;
                                    v=d[e];
                                    iv=u.set(v);
                                    if(!tool.isUndefined(iv))u.initValue=iv;else u.initValue=v;
                                }
                            }
                        }
                        f.editMode=true;//开启编辑模式
                    },
                    check:function(){
                        var b=true,uis=f.uis,fe,t;
                        for(var e in uis){
                            var u=uis[e];
                            if(u.check&&!u.check()){
                                if(b) fe=u;
                                b=false;
                            }
                        }
                        if(fe){
                            if(fe.parts&&(t=fe.parts["error"]))t.scrollIntoView(true);
                            else if(fe.__error) alert(fe.__error);
                        }
                        return b;
                    },
                    xml:function(){
                        var s=[],uis=f.uis;
                        for(var e in uis){
                            var u=uis[e],v=u.get(),key=dom.get(u,"key"),sub=dom.get(u,"sub"),n=dom.get(u,"name");
                            if(v==null) v="";
                            var b=tool.equals(u.initValue,v);
                            if(f.editMode&&b&&(!key)&&(!sub)) continue;//如果是编辑模式，并且不是主键,不是绝对提交则对比值
                            if(f.editMode) u.initValue=v;//如果是编辑模式，则更新初始值未修改后的值
                            if(u.xml) s.push(u.xml());//如果子控件自定义了xml方法，则首选
                            else s.push("<"+n+" value=\""+(v.encode?v.encode():v)+"\" />");
                        }
                        return s.join("");
                    },
                    clear:function(){
                        var uis=f.uis;
                        for(var e in uis){
                            var u=uis[e];
                            if(u.clear) u.clear();
                        }
                    },
                    script:s
                 };
              }
        var t;
        if(t=dom.get(o,"onmask"))f.mask=function(){evt.exec(s,dom.get(o,"onmask"),o);};else f.mask=function(){tool.mask();};
        if(t=dom.get(o,"onemask"))f.emask=function(){evt.exec(s,dom.get(o,"onemask"),o);};else f.emask=function(){tool.emask();};
        this.parse(f,dom.childs(o));
    },
    parse:function(f,l){
        var len = l.length,s=f.script;
        for(var i=0;i<len;i++){
            var o=l[i],n=dom.get(o,"name"),t=dom.get(o,"fancy"),b=true,act=dom.get(o,"act"),key=dom.get(o,"key"),u=dom.get(o,"ui"),sub=dom.get(o,"sub");
            if(t){
                o.form=f;
                var bc=ui[t].init(o,s);
                if(bc) dom.init(dom.childs(o),s);
                if(key) f.submitKey=o;
                if(n)f.uis[n]=o;
                if(sub) f.sub[n]=o;
                b=false;
            }
            if(u) f.script.uis[u]=o;
            if(b) this.parse(f,dom.childs(o));
            if(act){
                f.act[act]=o;
                o.act=act;
                var mact=act,pmact=mact.indexOf(".");
                if(pmact!=-1)mact=mact.substring(pmact+1);
                var t=s[mact+"_b"];
                if(t) o.before=t;
                t=s[mact+"_a"];
                if(t) o.after=t;
                o.onclick=function(){
                    if(f.check()&&!f.masked){
                        f.action=this;
                        http.send(f,true);
                    }
                    return false;
                }
                o.mask=function(){
                    dom.hidden(this);
                }
                o.emask=function(){
                    dom.show(this);
                }
            }
        }
    }
}

ui.list={
    init:function(o,s){
        var t;
        if(t=dom.get(o,"name")) o.name=t;
        var l=$$$(o,"row"),len=l.length,rows=o.rows=[];
        for(var i=0;i<len;i++){
            var r=l[i];r.uis={};
            this.initRow(r,r,s);
            r.clear=function(){
                var uis=this.uis;
                for(var e in uis) uis[e].clear();
            }
            r.index=i;
            rows.push(r);
        }
        
        //得到默认值对象
        var uis=rows[0].uis,val={};
        for(var e in uis)val[e]=uis[e].get();
        o.defaultValue=val;
        
        o.set=function(v){
            if(!v&&v!=0) return;
            var l=v,len=l.length,rs=o.rows,f=dom.get(o,"onset"),t,rv=[];
            for(var i=0;i<len;i++){
                var r=rs[i],uis=r.uis,val=l[i],rva={};
                for(var e in uis){
                    var u=uis[e],value=val[e];
                    if(u.set) u.set(value);
                    if(f) evt.exec(s,f,u,e,value);
                    rva[e]=value;
                }
                rv.push(rva);
            }
            if(!this.isCleared){alert(1);
                var rlen=rs.length;f=dom.get(o,"onclear");
                for(var i=len;i<rlen;i++){
                    var r=rs[i],uis=r.uis;
                    for(var e in uis){
                        var u=uis[e];
                        if(u.clear) u.clear();
                        if(f) evt.exec(s,f,u,e);
                    }
                }
            }
            this.isCleared=false;
            return rv;//返回实际有效的值,（服务器传来的值，有可能没有对应的控件与之对接，这种情况下值为无效）
        }
        o.get=function(){
            var v=[],l=this.rows,len=l.length;
            for(var i=0;i<len;i++){
                var uis=l[i].uis,val={};
                for(var e in uis)val[e]=uis[e].get();
                if(!tool.equals(val,o.defaultValue)) v.push(val);//如果不等于默认的空值则加入提交数组
            }
            return v;
        }
        o.clear=function(){
            var l=this.rows,len=l.length,f=dom.get(o,"onclear");
            for(var i=0;i<len;i++){
                var uis=l[i].uis;
                for(var e in uis){
                    var u=uis[e];
                    if(u.clear) u.clear();
                    if(f) evt.exec(s,f,u,e);
                }
            }
            this.isCleared=true;
        }
        o.xml=function(){
            var s=["<"+o.name+">"],rs=o.rows,len=rs.length;
            for(var i=0;i<len;i++){
                var uis=rs[i].uis;
                s.push("<object>");
                for(var e in uis){
                    var u=uis[e],v=u.get(),n=dom.get(u,"name");
                    if(v==null) v="";
                    if(u.xml) s.push(u.xml());//如果子控件自定义了xml方法，则首选
                    else s.push("<"+n+" value=\""+(v.encode?v.encode():v)+"\" />");
                }
                s.push("</object>");
            }
            s.push("</"+o.name+">");
            return s.join("");
        }
        o.check=function(){
            var b=true,fe,t,l=this.rows,len=l.length,er;
            for(var i=0;i<len;i++){
                var uis=l[i].uis;
                for(var e in uis){
                    var u=uis[e];
                    if(u.check&&!u.check()){
                        er=u.__error;break;
                    }
                }
            }
            o.__error=er;
            return !er;//如果有er则返回false,否则true
        }
    },
    initRow:function(o,r,s){
        var cs=dom.childs(o),csl=cs.length;
        for(var k=0;k<csl;k++){
            var c=cs[k],n=dom.get(c,"name"),t=dom.get(c,"fancy"),b=true;
            if(t){
                var bc=ui[t].init(c,s);
                if(bc) dom.init(dom.childs(c),s);
                b=false;
            }
            if(n)r.uis[n]=c;
            if(b)this.initRow(c,r,s);
        }
    }
}

/* container */
ui.container={
    init:function(o,s){
        var n=dom.get(o,"name");
        o.max=999;
        o.view=null;//当前的视图
        o.cache=[];//拥有的内容视图缓存列表
        o.load=function(url){
            if(this.view&&this.view.url==url)return;
            if(this.max>0){
                var v,len=this.cache.length;
                for(var i=0;i<len;i++){
                    if(this.cache[i].url==url){
                        dom.hidden(this.view);
                        this.view=this.cache[i];
                        dom.show(this.view);
                        actScript=this.view.script;//设置全局活动脚本对象
                        return;
                    }
                }
            }
            this.url=url;
            var t=dom.get(this,"onload_b");
            if(t)this.script[t]();
            http.load(url,this);
        };
        o.url=null;
        o.parse=function(t){
            if(this.view) dom.hidden(this.view);
            var m = dom.create("div");
            m.url=this.url;

            //解析js代码
            var reg=/<script[^>]*>[.\s\S]*?<\/script>/img,code="",cl,clen,sc;
            if(cl=t.match(reg)){
                clen=cl.length;
                for(var i=0;i<clen;i++)code+=cl[i];
                code=code.replace(/<script[^>]*>|<\/script>/g,"");
            }
            sc=m.script=new script(code,this.url);
            if(sc.start)sc.start();
            m.innerHTML=t.replace(reg,"");
            dom.append(this,m);
            if(sc.name) m.name=sc.name;
            this.view=m;
            dom.init(dom.childs(m),m.script);
            actScript=m.script;//设置全局活动脚本对象
            if(sc.end)sc.end();
            m.script.finish();//完成文档分析,一定要sc.end之后执行，避免出现漏洞
            //将新视图放入缓存区
            if(this.max>0){
                if(this.cache.length>=this.max){this.destroy(this.cache[0]);this.cache.remove(0);}
                this.cache.push(this.view);
            }
            var t=dom.get(this,"onload_a");
            if(t)this.script[t]();
        };
        o.remove=function(n){
            var cs=this.cache,len=cs.length;
            for(var i=0;i<len;i++){
                var v=cs[i];
                if(v.name==n){ this.destroy(v);cs.remove(i);break;};
            }
        }
        o.clear=function(l){//清空全部视图，除传递的参数以外
            var cs=this.cache,len=cs.length,ns=[];
            if(!l)l=[];
            for(var i=0;i<len;i++){
                var n=cs[i].name;
                if(l.indexOf(n)==-1)ns.push(n);
            }
            len=ns.length;
            for(var i=0;i<len;i++)this.remove(ns[i]);
        }
        o.destroy=function(v){
            var c=http.scur,s=v.script;
            if(c&&c.script==s)http.scur=null;
            s.destroy();
            if(this.view&&(v.script.name==this.view.name))this.view=null;
            v.script=null;
            dom.del(v);
            if(ie)CollectGarbage();
        }
        o.mask=function(){
            if(this.view) this.view.style.display="none";
            tool.mask();
        };
        o.emask=function(){
            tool.emask();
        };
        if(!s.cont)s.cont=[];
        s.cont[n]=o;
        o.script=s;     
    }
}

ui.builder={
    init:function(o,s){
        var tname=dom.get(o,"tname"),t;
        if(!(t=ui.builder.template[tname])){
            var te={},l=$$$(o,"btype"),len=l.length;
            for(var i=0;i<len;i++){
                var c=l[i];
                te[dom.get(c,"btype")]=c.cloneNode(true);
            }
            ui.builder.template[tname]=te;
        }
        o.innerHTML="";
        
        o.clear=function(){
            o.innerHTML="";
            o.current=null;
            o.uis={};
        }
        o.create=function(l){
            if(!tool.equals(o.current,l)){//如果当前配置等于新配置，则不用更新
                this.clear();
                if(!l)return;
                var len=l.length,tyns=ui.builder.typename,te=ui.builder.template[dom.get(o,"tname")];
                for(var i=0;i<len;i++){
                    var item=l[i],ty=tyns[item.type],c=te[ty].cloneNode(true),cl=$$$(c,"bpart"),clen=cl.length;
                    for(var k=0;k<clen;k++){
                        var cc=cl[k],bn=dom.get(cc,"bpart");
                        if(bn=="head"){
                            cc.innerHTML=item.name+"：";
                        }else if(bn=="note"){
                            cc.innerHTML=item.note;
                        }
                    }
                    
                    if(ty=="single"||ty=="multi"){
                        var ops=item.options.split(","),olen=ops.length,op=$$$(c,"loop")[0],opf=dom.father(op);
                        for(var k=0;k<olen;k++){
                            var lp=k==0?op:op.cloneNode(true),oc=$$$(lp,"option")[0],ot=$$$(lp,"optext")[0],opv=ops[k];
                            if(!oc&&dom.get(lp,"option"))oc=lp;
                            if(!ot&&dom.get(lp,"optext"))ot=lp;
                            dom.set(oc,"value",opv);
                            ot.innerHTML=opv;
                            dom.append(opf,lp);
                        }
                    }
                    
                    dom.set(c,"fancy","input");
                    dom.set(c,"type",ty);
                    dom.set(c,"call",item.name);
                    dom.set(c,"name",item.name);
                    if(item.need)dom.set(c,"need","1");
                    ui.input.init(c,s);
                    dom.append(o,c);
                    c.btype=item.type;
                    this.uis[item.name]=c;
                    
                }
                o.current=l;
            }
            //清空值
            var uis=this.uis;
            for(var e in uis){
                var t=uis[e];
                if(t.clear) t.clear();
            }
            if(this.objValue){//如果已有值，则绑定值
                var list=this.objValue.list,len=list.length,uis=this.uis;
                for(var i=0;i<len;i++){
                    var c=list[i],name=c.name,v=c.value,t=uis[name];
                    if(t) t.set(v);
                }
            }
        }
        o.check=function(){
            var b=true,uis=this.uis,fe,t;
            for(var e in uis){
                var u=uis[e];
                if(u.check&&!u.check()){
                    if(b) fe=u;
                    b=false;
                }
            }
            if(fe){
                if(fe.parts&&(t=fe.parts["error"]))t.scrollIntoView(true);
                else alert(fe.__error);
            }
            return b;
        }
        o.get=function(){
            if(!this.uis)return "";
            var uis=this.uis,val=[],n=dom.get(this,"name");
            for(var e in uis){
                var u=uis[e];
                val.push("<attr name=\""+dom.get(u,"name")+"\" value=\""+u.get()+"\" type=\""+u.btype+"\"></attr>");
            }
            this.value=val.join("");
            return this.value;
        }
        o.set=function(r){
            this.objValue=r;
            var l=r.list,len=l.length,val=[],uis=this.uis,tyns=ui.builder.typename;
            if(!uis) uis={};
            for(var i=0;i<len;i++){
                var c=l[i],n=c.name,v=c.value,type=c.type,tyn=tyns[type];
                if(tyn=="date")v=v.toShort();
                val.push("<attr name=\""+n+"\" value=\""+v+"\" type=\""+type+"\"></attr>");
                if(uis[n]) uis[n].set(v);
            }
            this.value=val.join("");//提供以后对比值用
            return this.value;
        }
    },
    typename:{
        1:"text",
        2:"number",
        3:"date",
        4:"textarea",
        10:"single",
        11:"multi"
    },
    template:{}
}