﻿//2008-11-21 Public Domain No warranty expressed or implied. Use at your own risk. This file has been superceded by http://www.JSON.org/json2.js
if(!this.JSON){
  JSON={};
}
(function(){
  function f(n){
    return n<10?"0"+n:n;
  }
  if(typeof Date.prototype.toJSON!=="function"){
    Date.prototype.toJSON=function(key){
      return this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z";
    };
    String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){
      return this.valueOf();
    };
  }
  var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r","\"":"\\\"","\\":"\\\\"},rep;
  function quote(string){
    escapable.lastIndex=0;
    return escapable.test(string)?"\""+string.replace(escapable,function(a){
      var c=meta[a];
      return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);
    })+"\"":"\""+string+"\"";
  }
  function str(key,holder){
    var i,k,v,length,mind=gap,partial,value=holder[key];
    if(value&&typeof value==="object"&&typeof value.toJSON==="function"){
      value=value.toJSON(key);
    }
    if(typeof rep==="function"){
      value=rep.call(holder,key,value);
    }
    switch(typeof value){
    case "string":
      return quote(value);
    case "number":
      return isFinite(value)?String(value):"null";
    case "boolean":
    case "null":
      return String(value);
    case "object":
      if(!value){
        return "null";
      }
      gap+=indent;
      partial=[];
      if(Object.prototype.toString.apply(value)==="[object Array]"){
        length=value.length;
        for(i=0;i<length;i+=1){
          partial[i]=str(i,value)||"null";
        }
        v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";
        gap=mind;
        return v;
      }
      if(rep&&typeof rep==="object"){
        length=rep.length;
        for(i=0;i<length;i+=1){
          k=rep[i];
          if(typeof k==="string"){
            v=str(k,value);
            if(v){
              partial.push(quote(k)+(gap?": ":":")+v);
            }
          }
        }
      }else {
        for(k in value){
          if(Object.hasOwnProperty.call(value,k)){
            v=str(k,value);
            if(v){
              partial.push(quote(k)+(gap?": ":":")+v);
            }
          }
        }
      }
      v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";
      gap=mind;
      return v;
    }
  }
  if(typeof JSON.stringify!=="function"){
    JSON.stringify=function(value,replacer,space){
      var i;
      gap="";
      indent="";
      if(typeof space==="number"){
        for(i=0;i<space;i+=1){
          indent+=" ";
        }
      }else {
        if(typeof space==="string"){
          indent=space;
        }
      }
      rep=replacer;
      if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){
        throw new Error("JSON.stringify");
      }
      return str("",{"":value});
    };
  }
  if(typeof JSON.parse!=="function"){
    JSON.parse=function(text,reviver){
      var j;
      function walk(holder,key){
        var k,v,value=holder[key];
        if(value&&typeof value==="object"){
          for(k in value){
            if(Object.hasOwnProperty.call(value,k)){
              v=walk(value,k);
              if(v!==undefined){
                value[k]=v;
              }else {
                delete value[k];
              }
            }
          }
        }
        return reviver.call(holder,key,value);
      }
      cx.lastIndex=0;
      if(cx.test(text)){
        text=text.replace(cx,function(a){
          return "\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);
        });
      }
      if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){
        j=eval("("+text+")");
        return typeof reviver==="function"?walk({"":j},""):j;
      }
      throw new SyntaxError("JSON.parse");
    };
  }
})();
//if(!Object.prototype.toJSONString){
//  Object.prototype.toJSONString=function(filter){
//    return JSON.stringify(this,filter);
//  };
//  Object.prototype.parseJSON=function(filter){
//    return JSON.parse(this,filter);
//  };
//}
var $id=function(id){return document.getElementById(id);};
var $tag=function(tag){return document.getElementsByTagName(tag);};
var $name=function(name){return document.getElementsByName(name);};
var jq = jQuery.noConflict();
jQuery.fn.extend({
    "post":function(url,params,callback,debug){
        if(this.length==1&&this.parents("body").length==1&&this[0].getElementsByTagName("form").length==0){
            var f=this[0];
            if(f.tagName.toLowerCase()!="form"){
                f=this.parents("form");
                switch(f.length){
                    case 0:
                        f=document.createElement("form");
                        this[0].parentNode.insertBefore(f,this[0]);
                        f.appendChild(this[0]);
                        break;
                    case 1:
                        f=f[0];
                        break;
                }
            }
            if(typeof(f.tagName)=="string"&&f.tagName.toLowerCase()=="form"){
                jQuery.submit.apply(f,arguments);
            }
        }
        return false;
    }
});
jQuery.extend({
    "e":function(){
        if(window.event){
            return this.event.fix(window.event);
        }
        else{
            var fn=arguments.callee.caller;
            while(fn!=null){
                if(fn.arguments.length>0&&/Event/.test(fn.arguments[0].constructor)){
                    return this.event.fix(fn.arguments[0]);
                }
                fn=fn.caller;
            }
            return null;
        }
    },
    "submit":function(url,params,callback,debug){
        var args={"event":jQuery.e(),"debug":false};
        if(typeof(this.tagName)=="string"&&this.tagName.toLowerCase()=="form"){
            args.form=this;
        }
        else if(args.event!=null&&args.event.target!=null){
            args.target=args.event.target;
            if(jQuery(args.target).attr("_lock")==undefined){
                jQuery(args.target).attr("_lock",true);
            }
            else{
                return false;
            }
            if(typeof(args.target.disabled)!="undefined"){
                args.target.disabled=true;
            }
            if(args.target.form!=null){
                args.form=args.target.form;
            }
            else{
                var nodes=jQuery(args.target).parents("form");
                if(nodes.length>0){
                    args.form=nodes[0];
                }
            }
        }
        if(typeof(args.form)=="undefined"){
            if(document.forms.length==0){
                args.form=document.createElement("form");
                var nodes=document.body.childNodes;
                document.body.insertBefore(args.form,nodes[0]);
                while(nodes.length>1){
                    args.form.appendChild(nodes[1]);
                }
            }
            else if(document.body.childNodes.length==1&&document.body.childNodes[0].tagName.toLowerCase()=="form"){
                args.form=document.body.childNodes[0];
            }
            else if(args.target!=null){
                var node=args.target;
                while(node.parentNode!=null&&node.parentNode!=document.body&&node.parentNode.getElementsByTagName("form").length==0){
                    node=node.parentNode;
                }
                args.form=document.createElement("form");
                node.parentNode.insertBefore(args.form,node);
                args.form.appendChild(node);
            }
            else{
                alert("\n - 触发事件的DOM对象不明确无法自动添加表单!　　\n");
                return false;
            }
        }
        for(var i=0;i<arguments.length;i++){
            switch(typeof(arguments[i])){
                case "object":
                    args.params=arguments[i];
                    break;
                case "string":
                    args.url=arguments[i];
                    break;
                case "function":
                    args.callback=arguments[i];
                    break;
                case "boolean":
                    args.debug=arguments[i];
                    break;
            }
        }
        if(typeof(arguments.callee.guid)=="number"){
            arguments.callee.guid++;
        }
        else{
            arguments.callee.guid=1;
        }
        var init=function(guid){
            var iframe=document.createElement("div");
            iframe.innerHTML=['<iframe name="#iframe[',guid,']" style="width:100%; height:500px; display:none;"></iframe>'].join("");
            iframe=iframe.childNodes[0];
            document.body.appendChild(iframe);
            args.nodes=[];
            var insertParams=function(name,value){
                var input=document.createElement("input");
                input.type="hidden";
                input.name=name;
                input.value=value;
                args.nodes.push(input);
                args.form.appendChild(input);
            };
            var removeParams=function(input){
                input.parentNode.removeChild(input);
            };
            insertParams("ifrRequest","true");
            if(typeof(args.params)=="object"){
                for(var key in args.params){
                    insertParams(key,args.params[key]);
                }
            }
            var handle=function(){
                if(typeof(args.callback)=="function"){
                    args.callback.apply(iframe,arguments);
                }
                else{
                    iframe.remove();
                }
            };
            if(iframe.addEventListener){
                iframe.addEventListener("load",handle,false);
            }
            else if(iframe.attachEvent){
                iframe.attachEvent("onload",handle);
            }
            iframe.remove=function(){
                if(args.target){
                    jQuery(args.target).removeAttr("_lock");
                    if(typeof(args.target.disabled)!="undefined"){
                        args.target.disabled=false;
                    }
                }
                if(this.removeEventListener){
                    this.removeEventListener("load",handle,false);
                }
                else if(this.detachEvent){
                    this.detachEvent("onload",handle);
                }
                if(args.debug){
                    this.style.display="block";
                }
                else{
                    this.contentWindow.location.replace("about:blank");
                    this.parentNode.removeChild(this);
                }
                delete args;
            }
            args.form.setAttribute("method","post");
            args.submit=document.createElement("input");
            args.submit.type="submit";
            args.submit.style.display="none";
            args.form.appendChild(args.submit);
            args.action=args.form.getAttribute("action");
            args.form.setAttribute("action",args.url||args.action||location.href);
            args.form.setAttribute("target",iframe.name);
            args.submit.click();
            args.form.removeAttribute("target");
            args.form.setAttribute("action",args.action);
            args.form.removeChild(args.submit);
            for(var i=0;i<args.nodes.length;i++){
                removeParams(args.nodes[i]);
            }
            delete args.nodes;
            return false;
        };
        return init(arguments.callee.guid);
    },
    "htmlEncode":function(s){
        return this(document.createElement("div")).text(s).html();
    },
    "htmlDecode":function(s){
        return this(document.createElement("div")).html(s).text();
    },
    "showAttr":function(o){
        var attr=[];
        for(var i in o){
            try{
                attr.push([i," : ",o[i],"\n\n"].join(""));
            }
            catch(e){
                attr.push([i," : ",e,"\n\n"].join(""));
            }
        }
        var width="848", height="480";
        var left = (screen.width/2) - width/2;
        var top = (screen.height/2) - height/2;
        var msgWindow = window.open("","msgWindow",["width=",width,",height=",height,",left=",left,",top=",top,",screenX=",left,",screenY=",top].join(""));
        msgWindow.document.write("<html><style>*{margin:0;padding:0;}textarea{width:100%; height:100%; border:0;}</style><head></head><body></body></html>");
        msgWindow.document.close();
        var textarea=msgWindow.document.createElement("textarea");
        textarea.value=attr.sort().join("");
        msgWindow.document.body.appendChild(textarea);
        msgWindow.focus();
    },
    "url":function(url,params){
        var _url={
            "init":function(url){
                this.path=url.toString().replace(/[#\?].*$/,"");
                this.search=url.toString().match(/[^&=\?]+=[^&#]*/g);
                this.search=this.search==null?[]:this.search;
                this.params={};
                for(var i=0;i<this.search.length;i++){
                    var tmp=this.search[i].split("=");
                    this.params[tmp[0]]=tmp[1];
                }
                return this.refresh();
            },
            "refresh":function(){
                var search=[];
                for(var attr in this.params){
                    search.push([attr,this.params[attr]].join("="));
                }
                this.search=search.join("&");
                this.href=[this.path,(search.length==0?"":["?",this.search].join(""))].join("");
                return this;
            },
            "query":function(key,value){
                switch(arguments.length){
                    case 1:
                        switch(key.constructor){
                            case String:
                                return this.params[key]?this.params[key]:"";
                            case Object:
                                for(var attr in key){
                                    this.params[attr]=key[attr];
                                }
                                return this.refresh();
                        }
                        break;
                    case 2:
                        this.params[key]=value;
                        return this.refresh();
                    
                };
                return this;
            },
            "removeQuery":function(keys){
                keys=keys.split(",");
                for(var i=0;i<keys.length;i++){
                    delete this.params[keys[i]];
                }
                return this.refresh();
            }
        };
        switch(arguments.length){
            case 0:
                return _url.init(location);
            case 1:
                if(typeof(arguments[0])=="object"){
                    return _url.init(location).query(arguments[0]);
                }
                else{
                    return _url.init(url);
                }
            case 2:
                return _url.init(url).query(params);
        }
    },
    "dialog":function(url,width,height,callback){
        var args={},count=arguments.length;
        for(var i=0;i<count;i++){
            switch(typeof(arguments[i])){
                case "string":
                    args.url=arguments[i];
                    break;
                case "function":
                    args.callback=arguments[i];
                    break;
                case "number":
                    if(typeof(args.width)=="undefined"){
                        args.width=arguments[i];
                    }
                    else{
                        args.height=arguments[i];
                    }
                    break;
            }
        }
        args.url=args.url||"about:blank";
        args.width=args.width||400;
        args.height=args.height||300;
        args.show=function(){
            if(typeof(this.callback)=="function"){
                window["dialogCallback"]=this.callback;
            }
            if(window.showModalDialog){
                window.showModalDialog(this.url,window,["dialogWidth:",this.width,"px; dialogHeight:",
                    this.height,"px; help:no; scroll:no; status:no;"].join(""));
            }
            else{
                window.open(this.url,null,["Width=",this.width,",Height=",this.height,",left=",(window.screen.availWidth-this.width)/2,
                    ",top=",(window.screen.availHeight-this.height)/2].join("")).dialogArguments = window;
            }
            return false;
        }
        return args.show();
    },
    "linkage":function(elems,source){
        return{
            elems:elems,
            source:source,
            sign:"*",
            digit:2,
            fixed:1,
            attr:function(key,value){
                this[key]=value;
                return this;
            },
            save:function(){
                var value=[];
                for(var i=0;i<this.elems.length;i++){
                    value.push([this.elems[i].value,this.sign,this.elems[i].value.length==0?"":
                        this.elems[i].options[this.elems[i].selectedIndex].text].join(""));
                }
                this.save.target.value=value.join(",");
            },
            bind:function(index){
                var prefix=index==0?"":this.elems[index-1].value;
                var nodes=(prefix.length!=index*this.digit)?"":
                    this.source.match(new RegExp(["\\b",prefix,"\\d{",this.digit,"}\\b[^,]+"].join(""),"g"));
                var max=nodes==null?0:nodes.length;
                this.elems[index].selectedIndex=0;
                this.elems[index].length=this.fixed;
                for(var i=0; i<max; i++){
                    var _option=new Option(nodes[i].split(this.sign)[1],nodes[i].split(this.sign)[0]);
                    this.elems[index].options.add(_option);
                    if(new RegExp(["\\b",_option.value].join("")).test(this.save.target.value)){
                        _option.selected=true;
                    }
                }
            },
            change:function(index){
                var _this=this;
                return function(){
                    if(index<_this.elems.length){
                        _this.bind(index);
                        _this.elems[index].onchange();
                    }
                    else{
                        _this.save();
                    }
                }
            },
            init:function(target){
                this.save.target=document.getElementById(target);
                for(var i=0;i<this.elems.length;i++){
                    var elem=document.getElementById(this.elems[i]);
                    if(elem==null){
                        return this;
                    }
                    else{
                        this.elems[i]=elem;
                    }
                    this.elems[i].onchange=this.change(i+1);
                    this.bind(i);
                }
                this.save();
                return this;
            }
        };
    },
    "request":function(url,charset,timeout,callback){
        var iframe=document.createElement("iframe");
        iframe.style.display="none";
        document.body.appendChild(iframe);
        iframe.contentWindow.document.write('<script type="text/javascript" src="'+url+'" charset="'+charset+'"><'+'/script>');
        var increment=100,loaded=setInterval(function(){
            if(iframe.contentWindow.document.body!=null&&iframe.contentWindow.document.readyState!="loading"){
                clearInterval(loaded);
                callback(iframe.contentWindow.document.body.innerHTML);
                iframe.contentWindow.location.replace("about:blank");
                document.body.removeChild(iframe);
            }
            else{
                if(typeof(arguments.callee.timekeeping)=="number"){
                    arguments.callee.timekeeping+=increment;
                    if(arguments.callee.timekeeping>=timeout){
                        clearInterval(loaded);
                        callback();
                        iframe.contentWindow.location.replace("about:blank");
                        document.body.removeChild(iframe);
                    }
                }
                else{
                    arguments.callee.timekeeping=0;
                }
            }
        },increment);
    },
    "scroll":function(target,point,speed){
        target=document.getElementById(target);
        if(target!=null){
            var args={
                target:target,
                point:point,
                speed:speed||15,
                span:1,
                interval:-1,
                container:function(){
                    for(var i=0;i<target.childNodes.length;i++){
                        if(target.childNodes[i].tagName){
                            return target.childNodes[i];
                        }
                    }
                }()
            };
            args["cells"]=args.container.childNodes;
            args["height"]=0;
            args["width"]=0;
            args["init"]={
                top:function(){args.container.style.height=(args.height*2)+"px";},
                left:function(){args.container.style.width=(args.width*2)+"px";}
            };
            for(var i=0;i<args.cells.length;i++){
                if(args.cells[i].tagName){
                    args.width+=args.cells[i].clientWidth;
                    args.height+=args.cells[i].clientHeight;
                }
            }
            args.init[args.point]();
            args.container.innerHTML+=args.container.innerHTML;
            args["act"]={
                top:function(){args.target.scrollTop>=args.height?args.target.scrollTop=0:args.target.scrollTop+=args.span;},
                left:function(){args.target.scrollLeft>=args.width?args.target.scrollLeft=0:args.target.scrollLeft+=args.span;}
            };
            args["stop"]=function(){clearInterval(args.interval);};
            args["start"]=function(){args.stop();args.interval=setInterval(args.act[args.point],args.speed);};
            args.target.onmouseout=args.start;
            args.target.onmouseover=args.stop;
            args.start();
        }
    },
    "upload":function(id,params){
        var func=function(url){
            document.getElementById(id).value=url;
        };
        if(typeof(params)=="object"){
            func.params=params;
        }
        this.dialog('/upload.aspx',func);
    },
    "calendar":function(){
        if(typeof(HS_setDate)=="function"){
            HS_setDate(this.e().target);
        }
    },
    "paging":function(holder,content,handles,callback){
        holder=$id(holder);
        if(holder==null){return;}
        handles=handles.split(",");
        if(typeof(holder.post)!="function"){
            new Image().src="/images/loading.gif";
            holder.post=function(url){
                url=typeof(url)=="string"?url:this.href;
                var html=holder.innerHTML;
                var target=$id(content);
                target.style.zoom=1;
                var parent=target.parentNode;
                while(parent.style.position=="inherit"){
                    parent=parent.parentNode;
                }
                if(parent.style.position.length==0){
                    target.parentNode.style.position="relative";
                }
                var cover=document.createElement(target.parentNode.tagName);
                cover.innerHTML=["<",target.tagName," style='",
                    "width:",target.clientWidth,"px;",
                    "height:",target.clientHeight,"px;",
                    "top:",target.offsetTop,"px;",
                    "left:",target.offsetLeft,"px;",
                    "display:block; position:absolute;'>",
                        "<p style='width:100%; height:100%;",
                        cover.style.filter==undefined?" opacity:0.25;":" filter:alpha(opacity=25)","'></p>",
                        "<img alt='数据加载中...' src='/images/loading.gif' style='",
                        "width:",24,"px;",
                        "height:",24,"px;",
                        "top:",target.clientHeight/2-12,"px;",//(function(e){var top=document.documentElement.scrollTop-e.offsetTop;while(e=e.offsetParent){top-=e.offsetTop;}return (target.clientHeight-top)/2+top-12;})(target)
                        "left:",target.clientWidth/2-12,"px;",
                        "display:block; position:absolute;' />",
                    "</",target.tagName,">"].join("");
                cover=cover.getElementsByTagName(target.tagName)[0];
                target.parentNode.appendChild(cover);
                cover.getElementsByTagName("p")[0].style.background="#FFFFFF";
                return jq.submit(url,{"#listing":holder.id},function(){
                    var result=this.contentWindow.result;
                    this.remove();
                    setTimeout(function(){
                        if(result==null){
                            holder.innerHTML=html;
                            alert("\n - 服务器无响应, 数据加载失败!　　\n");
                        }
                        else{
                            holder.innerHTML=result;
                        }
                        if(typeof(callback)=="function"){
                            callback();
                            jq.paging(holder.id,content,handles.join(","),callback);
                        }
                        else{
                            jq.paging(holder.id,content,handles.join(","));
                        }
                    },0);
                });
            };
        }
        for(var i=0;i<handles.length;i++){
            var links=$id(handles[i])
            if(links!=null){
                links=links.getElementsByTagName("a");
                for(var j=0;j<links.length;j++){
                    if(links[j].href.indexOf("javascript:")==-1){
                        jQuery(links[j]).click(holder.post);
                    }
                }
            }
        }
    },
    "grid":function(target){
        return {
            "target":target,
            "reload":function(action){
                var state=this.target.stateField.value;
                var field=state.split("|");
                if(typeof(action)=="undefined"){
                    field[0]="-1";
                }
                else{
                    field[1]=Math.abs(parseInt(field[1])-1);
                    document.forms[0].action=action;
                }
                this.target.stateField.value=field.join("|");
                this.target.callback(state);
            },
            "open":function(url){
                var _this=this;
                jq.dialog(url,848,480,function(){
                    _this.reload();
                });
                return false;
            },
            "select":function(){
                var checked=jq.e().target.checked;
                var keys=$name("ckbKeys");
                for(var i=0;i<keys.length;i++){
                    keys[i].checked=checked;
                }
            },
            "action":function(action){
                var keys=$name("ckbKeys"),count=0;
                for(var i=0;i<keys.length;i++){
                    if(keys[i].checked){
                        count++;
                    }
                }
                if(count==0){
                    alert("\n - 请选择要设定的行.　　\n");
                }
                else{
                    if(confirm("\n - 将设定[" + count + "]行数据,确定继续?　　　　\n")){
                        jq.submit({"action":action});
                    }
                }
                return false;
            },
            "del":function(){
                var keys=$name("ckbKeys"),count=0;
                for(var i=0;i<keys.length;i++){
                    if(keys[i].checked){
                        count++;
                    }
                }
                if(count==0){
                    alert("\n - 请选择要删除的行.　　\n");
                }
                else{
                    if(confirm("\n - 将删除[" + count + "]行数据,确定继续?　　　　\n")){
                        jq.submit({"action":"delete"});
                    }
                }
                return false;
            }
        };
    }
});
var tip=function(title,tips){
    var _this=arguments.callee;
    var elem=$id("#errors");
    var highlight=function(){
        if(_this.lock!=true){
            _this.lock=true;
            var color=elem.style.borderColor;
            var i=1,interval=setInterval(function(){
                if(i%2){
                    elem.style.borderColor="#FFFFFF";
                }
                else{
                    elem.style.borderColor=color;
                }
                if(i>5){
                    _this.lock=false;
                    return clearInterval(interval);
                }
                i++;
            },50);
        }
    };
    var loading=elem.getElementsByTagName("b")[0];
    var success=elem.getElementsByTagName("strong")[0];
    var failure=elem.getElementsByTagName("em")[0];
    var message=elem.getElementsByTagName("ul")[0];
    elem.style.display="block";
    switch(arguments.length){
        case 1:
            success.innerHTML=title==null?success.innerHTML:title;
            loading.style.display="none";
            success.style.display="inline";
            failure.style.display="none";
            message.style.display="none";
            highlight();
            break;
        case 2:
            failure.innerHTML=title==null?failure.innerHTML:title;
            message.innerHTML=["<li>",tips.join(".</li><li>"),".</li>"].join("");
            loading.style.display="none";
            success.style.display="none";
            failure.style.display="inline";
            message.style.display="block";
            highlight();
            break;
        default:
            loading.style.display="inline";
            success.style.display="none";
            failure.style.display="none";
            message.style.display="none";
            break;
    }
};
var tabs=function(handles,list,speed){
    if(typeof(speed)!="number"){
        speed=0;
    }
    return {
        "lock":false,
        "id":undefined,
        "index":0,
        "choose":function(index){
            var _this=this;
            for(var i=0;i<handles.length;i++){
                if(i==index){
                    handles.eq(i).addClass("on");
                    if(speed>0){
                        _this.index=i;
                        if(!_this.lock){
                            _this.lock=true;
                            list.eq(i).addClass("on").find("img").eq(0).fadeIn(500,function(){
                                _this.lock=false;
                                if(_this.index!=i){
                                    _this.choose(_this.index);
                                }
                            });
                        }
                    }
                    else{
                        list.eq(i).show().addClass("on");
                        _this.lock=false;
                    }
                }
                else{
                    handles.eq(i).removeClass("on");
                    if(speed>0){
                        list.eq(i).removeClass("on").find("img").eq(0).fadeOut(500);
                    }
                    else{
                        list.eq(i).hide().removeClass("on");
                    }
                }
            }
            this.index=index;
        },
        "stop":function(){clearInterval(this.id);},
        "start":function(){
            if(speed>0){
                this.stop();
                var _this=this;
                this.id=setInterval(function(){
                    _this.choose(_this.index==handles.length-1?0:_this.index+1);
                },speed);
            }
        },
        "init":function(){
            var _this=this;
            handles.each(function(i){
                jq(this).hover(function(){
                    _this.stop();
                    _this.choose(i);
                },function(){
                    _this.start();
                });
            });
            list.each(function(i){
                jq(this).hover(function(){
                    _this.stop();
                },function(){
                    _this.start();
                });
            });
            this.choose(this.index);
            this.start();
            return this;
        }
    }.init();
};
var scroll=function(target,speed){
    if(typeof(speed)!="number"){
        speed=3000;
    }
    return {
        "id":undefined,
        "start":function(){
            this.id=setInterval(function(){
                var items=target.find("> *");
                items.animate({"top":target[0].clientHeight*-1},1000,function(){
                    if(this==items[0]){
                        this.parentNode.appendChild(this);
                    }
                    this.style.top="0";
                });
            },speed);
        },
        "stop":function(){
            clearInterval(this.id);
        },
        "init":function(){
            var _this=this;
            var el=target.find("> *").eq(0)
            var cl=el.clone(false);
            target.append(cl);
            var items=el.find("> *");
            items.each(function(i){
                if(i>=items.length/2){
                    cl.append(this);
                }
            });
            target.hover(function(){
                _this.stop();
            },function(){
                _this.start();
            });
            this.start();
        }
    }.init();
};
var photoshow={
    "skip":0,
    "take":4,
    "index":0,
    "reg":/,/i,
    "autostatus":true,
    "play":Object,
    "date":''.split(','),
    "init":function(){
        jq("#pics")[0].innerHTML="";
        for (var i=this.skip;i<((this.date.length-this.skip)>=this.take?(this.take+this.skip):this.date.length);i++){
            var img=document.createElement("img");
            img.id=i;
            img.onload=function(){
                this.style.display="";
            };
            img.style.display="none";
            var a=document.createElement("a");
            a.href="javascript:;";
            var li=document.createElement("li");
            a.appendChild(img);
            li.appendChild(a);
            jq("#pics")[0].appendChild(li);
            img.src=encodeURI(this.date[i]);
            a.href=encodeURI(this.note[i]);
            a.target="_blank";
            if(i==this.index){this.choose(this.index);};
        }
        jq("#pics a").click(function(){
            var target=jq(this).find("img")[0];
            photoshow.index=parseInt(target.id);
            photoshow.choose(photoshow.index);
        });
    },
    "previous":function(){
        this.skip-=this.take;
        if(this.skip<0){
            this.skip= parseInt(this.date.length/this.take)*this.take;
        }
        this.index=this.date.length>(this.skip+this.take)?(this.skip+this.take-1):this.date.length-1;
        this.init();
    },
    "next":function(){
        this.skip+=this.take;
        if(this.skip>=this.date.length){
            this.skip=0;
        }
        this.index=this.skip;
        this.init();
    },
    "choose":function(j){
        if(j<this.date.length){
            jq("#bigpic").addClass("dis");
            img.src=encodeURI(this.date[j]);
            if(this.note.length>1){
                if(this.note[j]!=undefined)
                {
                    jq("#notes").html(this.note[j]);
                }else{
                    jq("#notes").html(this.note[0]);
                }
            }else{
                jq("#notes").html(this.note[0]);
            }
        }
    },
    "previousimg":function(){
        this.index-=1;
        if(this.index<this.skip){
           this.previous();
        }else{
            this.choose(this.index);
        }
    },
    "nextimg":function(){
        this.index+=1;
        if(this.index>=this.skip+this.take|| this.index>=this.date.length){
           this.next();
        }else{
            this.choose(this.index);
        }
    },
    "autoplay":function(){
        if(this.autostatus){
            jq("#autoplay")[0].src="/images/autoplay2.gif";
            this.play=setInterval("photoshow.nextimg();",5000);
            this.autostatus=false;
        }else{
            jq("#autoplay")[0].src="/images/autoplay.gif";
            clearInterval(this.play);
            this.autostatus=true;
        }
    },
    "change":function(j){
        var sk=this.skip;
        this.skip= parseInt((j-1)/this.take)*this.take;
        this.index=j-1;
        if(sk==this.skip){   
            this.choose(this.index);
        }else{
            this.init();
        }
    }
};

jq(function(){
    //if($(".t_l").length==1){tabs($(".t_l > p > a"),$(".t_l  ul"))}
    //if($("#notice").length==1){$.scroll("notice","left",50);}
    if(jq(".subnav").length==1){
        jq(".subnav > li").hover(function(){
            jq(this).addClass("on");},function(){
            jq(this).removeClass("on");
            }); 
    }
    jq(".comment > li").hover(function(){
        jq(".comment > li").removeClass("on");
        jq(this).addClass("on");},function(){
        
    });
    jq(".footer .selectli").each(function(){
        jq(this).prepend("<option value=>友情链接</option>")[0].selectedIndex=0;
		jq(this).change(function(){
		    if(this.value!=""){
		        window.open(this.value);
		    }
		});
    });
    jq("body *").each(function(){
        if(this.className.indexOf("rotation")==0){
            if(jq(this).find("> b").length>0){
                jq(this).find(" > b > a").eq(0)[0].href="/html/technique/cornea/index.shtml";
                jq(this).find(" > p > a").eq(0)[0].href="/html/technique/cornea/index.shtml";
                jq(this).find(" > b > a").eq(1)[0].href="/html/technique/RGP/index.shtml";
                jq(this).find(" > p > a").eq(1)[0].href="/html/technique/RGP/index.shtml";
                jq(this).find(" > b > a").eq(2)[0].href="/html/technique/optometrist/index.shtml";
                jq(this).find(" > p > a").eq(2)[0].href="/html/technique/optometrist/index.shtml";
                tabs(jq(this).find("> b"),jq(this).find("> p"),3000);
            }
        }
    });
});
