﻿function HtmlEncode(text){
	var re = {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}
function HtmlDecode(text){
	var re = {'&lt;':'<','&gt;':'>','&amp;':'&','&quot;':'"'};
	for (i in re) text = text.replace(new RegExp(i,'g'), re[i]);
	return text;
}
function UTF8UrlEncode(input){
    var output = "";
    var currentChar = '';
        
    for(var counter = 0; counter < input.length; counter++) {
        currentChar = input.charCodeAt(counter);
        if((48 <= currentChar) && (currentChar <= 57))
            output = output + input.charAt(counter);
        else if((65 <= currentChar) && (currentChar <= 90))
            output = output + input.charAt(counter);
        else if((97 <= currentChar) && (currentChar <= 122))
            output = output + input.charAt(counter);
        else
            output = output + UTF8UrlEncodeChar(currentChar); 
    }
    return output;
}
function UTF8UrlEncodeChar(input){
    if(input <= 0x7F) return "%" + input.toString(16);

    var leadByte = 0xFF80; var hexString = ""; var leadByteSpace = 5;
    while(input > (Math.pow(2, leadByteSpace + 1) - 1)){
        hexString = "%" + ((input & 0x3F) | 0x80).toString(16) + hexString;
        leadByte = (leadByte >> 1);
        leadByteSpace--;
        input = input >> 6;
    } 
    return ("%" + (input | (leadByte & 0xFF)).toString(16) + hexString).toUpperCase();
}
//加载Script
function LoadScript(tag,file){
    var scripttag = $("loadscript"+tag);
    var head = document.getElementsByTagName("head").item(0);
    if(scripttag){head.removeChild(scripttag);}
    script = document.createElement("script");
    with(script){
        src  = ""+file;
        type = "text/javascript";
        id   = "loadscript"+tag;
    }
    head.appendChild(script);
}
//加载Css
function LoadCss(tag,file){
    var csstag = $("loadcss"+tag);
    var head = document.getElementsByTagName("head").item(0);
    if(csstag){head.removeChild(csstag);}
    css = document.createElement("link");
    with(css){
        href = ""+file;
        rel  = "stylesheet";
        type = "text/css";
        id   = "loadcss"+tag;
    }
    head.appendChild(css);
}
String.prototype.Trim = function() { 
    return this.replace(/(^\s*)|(\s*$)/g, "");
}  
String.prototype.LTrim = function() { 
    return this.replace(/(^\s*)/g, "");
} 
String.prototype.RTrim = function() { 
    return this.replace(/(\s*$)/g, "");
} 
//日期转换
Date.prototype.Format = function(fmt){
//author: meizz
//例子1 (new Date()).Format("yyyy年MM月dd日 hh时mm分ss秒");
//例子2 (new Date()).Format("yyyy年M月d日 h时m分s秒");
//例子3 (new Date()).Format("yyyy年MM月dd日 hh时mm分ss秒S毫秒");
    var o = {
        "M+" : this.getMonth()+1, //月份
        "d+" : this.getDate(), //日
        "h+" : this.getHours(), //小时
        "m+" : this.getMinutes(), //分
        "s+" : this.getSeconds(), //秒
        "q+" : Math.floor((this.getMonth()+3)/3), //季度
        "S" : this.getMilliseconds() //毫秒
    };
    if(/(y+)/.test(fmt))
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
        if(new RegExp("("+ k +")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
}
//判断字符串是否符合日期填写规则
//("2007-1-1").isDate()
String.prototype.isDate = function(){
    var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
    if(r==null){
        return false;
    }
    var d = new Date(r[1], r[3]-1, r[4]); 
    return(d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
//判断字符串是否符合日期+时间填写规则
//("2007-1-1 1:1:1").isTime()
String.prototype.isTime = function(){
    var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/); 
    if(r==null){
        return false;
    } 
    var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
    return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
//时间刷新
function getTime(){
    $("lblTime").innerHTML=(new Date()).Format("yyyy年MM月dd日 hh时mm分ss秒");
    setTimeout("getTime()",1000);
}
//数据检测-element
function chkTextByte(obj){
    if(obj.chkMax){
        var chkMaxs=obj.chkMax;
        var b=(chkMaxs.substr(1,1)>0?true:false);//类型：0 汉字为1个字符，1 汉字为2个字符
        var max=chkMaxs.substr(2);//文本长度
        var emValue=obj.value.escapeHTML(obj.value);
        if(getValueLength(emValue,b)>max){
            obj.focus();
            obj.select();
            var errStr="对不起！该项内容只允许填写["+max+"]个字符！";
            if(b){errStr+="或者["+max/2+"]个汉字！";}
            messageBox(errStr,true);
            setTimeout("exitMe('Prompt')",2000);
        }
    }
}
//检测字符串长度
function getValueLength(str,b){
    if(b){//汉字按2字节计算
        return str.replace(/[^\x00-\xff]/gi,'xx').length;
    }else{//汉字按1字节计算
        return str.length;
    }
}
//用户列表
function moveUsers(id,type){
    var tr=$("trUser_"+id);
    var gw=$("gwUser_"+id);
    var lt=$("ltUser_"+id);
    
    if(type==1){
        tr.style.backgroundImage="url(/images/c-libg.gif)";
        gw.href="/WinOA/11/SendBumf.aspx?HotKey="+id;
        gw.style.display="";
        lt.style.display="";
        lt.href="javascript:showChat("+id+")";
    }else if(type==2){
        tr.style.backgroundImage="url(none)";
        gw.style.display="none";
        lt.style.display="none";
    }
}
function treatBox(code,text,b){
    messageBox("编号："+code+"<br>"+"内容："+text,b);
}
var _dbShow=false,_searchUser=false;
function messageBox(str,b,b1){
    showDivMiss(str,b);
    showDivBack();
    _dbShow=b1?true:false;
}
//退出
function exitMe(obj,b){
    if(!_dbShow){d_back.style.visibility="hidden";}
    $(obj).style.display="none";
    if(b){window.location.href=window.location.href;}
    _searchUser=false;
    showSelect();
}
//全屏背景层
function showDivBack(){
    d_back.style.visibility="";
    d_back.style.width=document.documentElement.clientWidth-4+"px";
    d_back.style.height=document.documentElement.clientHeight-4+"px";
    hideSelect();
}
//查找用户层
function showDivPick(){
    d_pick.style.display="";
    d_pick.style.left=(document.documentElement.clientWidth-840)/2+"px";
    d_pick.style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-260)/2+"px";
}
function showDivChat(){
    d_chat.style.display="";
    d_chat.style.left=(document.documentElement.clientWidth-840)/2+"px";
    d_chat.style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-260)/2+"px";
}
//信息提示层
function showDivMiss(str,b){
    d_box.style.display="";
    d_box.style.left=(document.documentElement.clientWidth-260)/2+"px";
    d_box.style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-140)/2+"px";
    d_btext.innerHTML=str;
    if(b){d_btn.style.display="";}else{d_btn.style.display="none";}
}
//查找用户层
function showDivCtrl(obj){
    $(obj).style.display="block";
    $(obj).style.left=(document.documentElement.clientWidth-600)/2+"px";
    $(obj).style.top=document.documentElement.scrollTop+(document.documentElement.clientHeight-260)/2+"px";
}
//错误转向
function errorAjax(){
    window.location.href="/error/default.aspx?type=500";
}
var user_page;
//用户快捷列表
function getUserList(cc,tp,pg,kd){
    user_page=pg;
    var urls="/ajax.aspx";
    var pars="tp="+tp+"&page="+pg;
    var myAjax = new Ajax.Updater({
        success: cc}, 
	    urls, {
		    method: "post", 
		    parameters: pars,
		    onSuccess: function(tr){
		    	var _trArr=treatAjaxValue(tr)
                if(_trArr[0]=="2900"){treatBox(_trArr[0],_trArr[1],true);}
		    },onFailure: errorAjax
	    }
    );
    if(kd>0){setTimeout(function(){getUserList(cc,tp,user_page,kd);},45000);}
}
//用户菜单列表
function getMenus(cc){
    var urls="/ajax.aspx";
    var pars="tp=getMenus";
    var myAjax = new Ajax.Updater({
        success: cc}, 
	    urls, {
		    method: "post", 
		    parameters: pars,
		    onFailure: errorAjax
	    }
    );
}
//循环滚动公告
function getAffiches(dd,mm){
    var urls="/ajax.aspx";
    var pars="tp=getAffiches";
    var myAjax = new Ajax.Updater({
        success: dd}, 
		urls, {
			method: "post", 
			parameters: pars,
			onFailure: errorAjax
		}
	);
	t_aff=setInterval(affturn,20);m_aff=$(mm);d_aff=$(dd);
}
var t_aff,rTop=0,stopscroll=false,m_aff,d_aff;
function affturn(){
    if(stopscroll)return;
    if(d_aff.childNodes.length<2)return;
    rTop++;
    if(rTop==28){
        var o=d_aff.firstChild;
        d_aff.removeChild(o);d_aff.appendChild(o);
        rTop=0;
    }
    m_aff.scrollTop=rTop;
    if(rTop==0){
        clearInterval(t_aff);
        setTimeout(function(){t_aff=setInterval(affturn,20);},3000);
    }
}

//ajax返回值处理
function treatAjaxValue(tr){
    var _arr=new Array();
    var start=tr.responseText.indexOf('|');
    var ret=tr.responseText.substr(0,start);//编号
    var msg=tr.responseText.substr(start+1);//内容
    _arr.push(ret);_arr.push(msg);
    return _arr;
}

//获取企业标签
function getUserTags(cc){
    var urls="/ajax.aspx";
    var pars="tp=userTags";
    var myAjax = new Ajax.Updater({
        success: cc}, 
		urls, {
			method: "post", 
			parameters: pars, 
			onFailure: errorAjax
		}
	);
}
var MSIE=Prototype.Browser.IE;
function iniControlsEvent(frms){
    for(i=0;i<frms.length;i++){
        e=frms.elements[i];
        with(e){
            switch(className.toLowerCase()){
                case "button"://普通按纽
                    if(MSIE){
                        attachEvent("onmouseover",function(){className="topanniu2";});
                        attachEvent("onmouseout",function(){className="topanniu";});
                    }else{
                        addEventListener("mouseover",function(){className="topanniu2";},false);
                        addEventListener("mouseout",function(){className="topanniu";},false);
                    }
                    break;
                case "text"://文本框
                    if(MSIE){
                        attachEvent("onfocus",function(){style.backgroundColor="#FFFADF";select();});
                        attachEvent("onblur",function(){style.backgroundColor="#FFFFFF";});
                    }else{
                        addEventListener("focus",function(){style.backgroundColor="#FFFADF";select();},false);
                        addEventListener("blur",function(){style.backgroundColor="#FFFFFF";},false);
                    }
                    break;
                case "submit"://提交
                    if(MSIE){
                        attachEvent("onmouseover",function(){className="mail2";});
                        attachEvent("onmouseout",function(){className="mail";});
                    }else{
                        addEventListener("mouseover",function(){className="mail2";},false);
                        addEventListener("mouseout",function(){className="mail";},false);
                    }
                    break;
                case "reset"://重置
                    if(MSIE){
                        attachEvent("onmouseover",function(){className="mail2_2";});
                        attachEvent("onmouseout",function(){className="mail_2";});
                    }else{
                        addEventListener("mouseover",function(){className="mail2_2";},false);
                        addEventListener("mouseout",function(){className="mail_2";},false);
                    }
                    break;
            }
        }
    }
}
function changeBigButtonCss(obj,b){
    var elm=$(obj);
    with(elm){
        className=(b?"topanniu":"topanniu12");
        disabled=(b?false:true);
        if(MSIE){
            onmouseout=function(){className="topanniu";};
            onmouseover=function(){className=(b?"topanniu2":"topanniu12");};
        }else{
            addEventListener("mouseout",function(){className="topanniu";},false);
            addEventListener("mouseover",function(){className=(b?"topanniu2":"topanniu12");},false);
        }
    }
}
function changeSmlButtonCss(obj,b){
    var elm=$(obj);
    with(elm){
        className=(b?"bt1":"bt1h");
        disabled=(b?false:true);
        if(MSIE){
            onmouseout=function(){className="bt1";};
            onmouseover=function(){className=(b?"bt2":"bt1h");};
        }else{
            addEventListener("mouseout",function(){className="bt1";},false);
            addEventListener("mouseover",function(){className=(b?"bt2":"bt1h");},false);
        }
    }
}
function changeSmlButtonCss2(obj,b){
    var elm=$(obj);
    with(elm){
        className=(b?"topanniu":"topanniuh");
        disabled=(b?false:true);
        if(MSIE){
            onmouseout=function(){className="topanniu2";};
            onmouseover=function(){className=(b?"topanniu":"topanniuh");};
        }else{
            addEventListener("mouseout",function(){className="topanniu2";},false);
            addEventListener("mouseover",function(){className=(b?"topanniu":"topanniuh");},false);
        }
    }
}
function getChecksValue(tg,obj){
    var result01="",result02=0,result03="";
    var chks=document.getElementsByName(tg);
    for(var i=0;i<chks.length;i++){
        e=chks[i];
        if(obj){e.checked=obj.checked;}
        if(e.checked){
            if(result01.length==0){
                result01=e.value;
                result03=e.title;
            }else{
                result01+=","+e.value;
                result03+=","+e.title;
            }
            result02+=1;
        }
    }
    return {id:result01,cnt:result02,name:result03};
}
//控件X,Y点
function getPointX(obj){
	var _px=obj.offsetLeft;
	while(obj=obj.offsetParent){
		_px+=obj.offsetLeft;
	}
	return _px;
}
function getPointY(obj){
	var _py=obj.offsetTop;
	while(obj=obj.offsetParent){
		_py+=obj.offsetTop;
	}
	return _py;
}
if(MSIE){window.attachEvent("onscroll",function(){d_back.style.top=document.documentElement.scrollTop+2+"px";});}
else{window.addEventListener("scroll",function(){d_back.style.top=document.documentElement.scrollTop+2+"px";},false);}


var _arrSlt=new Array();//存放被隐藏的select控件
function hideSelect(){
    var slts=document.getElementsByTagName("select");
    for(var i=0;i<slts.length;i++){
        if(slts[i].style.display!="none"){
            _arrSlt.push(slts[i]);
            slts[i].style.display="none";
        }
    }
}
function showSelect(){
    for(var i=0;i<_arrSlt.length;i++){_arrSlt[i].style.display="";}
    _arrSlt.length=0;
}