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();
}

function replaceText(Str)
{
	var tempStr = Str;
	if(tempStr.length<1)
	{
		return "";
	}
	else
	{
		for(var i=0;i<tempStr.length;i++)
		{
			tempStr = tempStr.replace("\n","<br>");
			tempStr = tempStr.replace("'","＇");
			tempStr = tempStr.replace(";","；");
			//tempStr = tempStr.replace("\"","＂");
		}
		return tempStr;
	}
}
function drag(o){
	o.onmousedown=function(a){
		var d=document;if(!a)a=window.event;
		var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
		if(o.setCapture)
			o.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);

		d.onmousemove=function(a){
			if(!a)a=window.event;
			if(!a.pageX)a.pageX=a.clientX;
			if(!a.pageY)a.pageY=a.clientY;
			var tx=a.pageX-x,ty=a.pageY-y;
			o.style.left=tx;
			o.style.top=ty;
		};

		d.onmouseup=function(){
			if(o.releaseCapture)
				o.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			d.onmousemove=null;
			d.onmouseup=null;
		};
	};
}
//日期转换
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 chk_air(val)
{  
	if(typeof( val)=='undefined' || val==null || val.length<1)
		return false;
	else
	{
        var patrn = /(^\s+|\s$)/g;   
        val=val.replace(patrn, ""); 
        if(val.length<1)
            return false;
		return true;
    }
}

//返回字符长度
function strLen(key){
	var l=escape(key),len
	len=l.length-(l.length-l.replace(/\%u/g,"u").length)*4
	l=l.replace(/\%u/g,"uu")
	len=len-(l.length-l.replace(/\%/g,"").length)*2
	return len
}

//是否一致
function issame(str1,str2)  
{  
	if(!chk_air(str1))
	{ return false;}
	if (str1==str2)  
	{return(true);}  
	else  
	{return(false);}  
}  

//是否数字
function chk_Num(str)
{return str.match(/\D/)==null}  

//判断是否是字符  true 全字符 false 含有汉字
function chk_allstr(val)
{
	return !(/[^\x00-\xff]/g.test(val)) ;
}

//邮箱格式验证
//函数名：chkemail     
//功能介绍：检查是否为Email Address     
//参数说明：要检查的字符串     
//返回值：0：不是 1：是     
function chkemail(a)     
{ var i=a.length;     
var temp = a.indexOf('@');     
var tempd = a.indexOf('.');     
if (temp > 1) {     
if ((i-temp) > 3){     
if ((i-tempd)>0){     
return 1;     
}     
    
}     
}     
return 0;     
}     

//数字格式验证
//函数名：fucCheckNUM     
//功能介绍：检查是否为数字     
//参数说明：要检查的数字     
//返回值：1为是数字，0为不是数字     
function fucCheckNUM(NUM)     
{     
var i,j,strTemp;     
strTemp="0123456789";     
if ( NUM.length== 0)     
return 0     
for (i=0;i<NUM.length;i++)     
{     
j=strTemp.indexOf(NUM.charAt(i));     
if (j==-1)     
{     
//说明有字符不是数字     
return 0;     
}     
}     
//说明是数字     
return 1;     
}  
function IsNumeric(fData)
{
    if (!chk_air(fData))
        return true
    if (isNaN(fData))
        return false
        
    return true    
} 

//电话号码格式验证
//函数名：fucCheckTEL     
//功能介绍：检查是否为电话号码     
//参数说明：要检查的字符串     
//返回值：1为是合法，0为不合法     
function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789-()#, ";     
for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{     
//说明有字符不合法     
return 0;     
}     
}     
//说明合法     
return 1;     
}    


/*检测帐号
 *返回 0 -- 空
 *返回 1 -- 长度不符合
 *返回 2 -- 有未允许的字符
 *返回 99-- 符合要求
*/
function chk_name(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//帐号以数字、字母、_任意组合
	{
		if(strLen(val)>20||strLen(val)<4)
			return 1;
		if(!/^[a-zA-Z0-9_]*$/.test(val))
			return 2;
		return 99;
	}
}

/*检测密码
 *返回 0 -- 空
 *返回 1 -- 长度不符合
 *返回 2 -- 有未允许的字符
 *返回 99-- 符合要求
*/
function chk_pwd(val,type)
{
	if(!chk_air(val))
		return 0;
	if(type==1)//帐号以数字、字母、_任意组合
	{
		if(strLen(val)>20||strLen(val)<6)
			return 1;
		if(!/^[a-zA-Z0-9]*$/.test(val))
			return 2;
		return 99;
	}
}

function fResizeImg(w, h, id){     
        var img='';     
        var obj;     
        if(id==undefined)obj=document.images;     
        else obj=document.getElementById(id).getElementsByTagName('img');     
             
        for(var i=0; i<obj.length; i++){     
            img=obj[i];     
            if(img.width>w&&(img.height<img.width)){     
                img.height=img.height-(img.height/(img.width/(img.width-w)))     
                img.width=w;     
            }else if(img.height>h&&(img.height>img.width)){     
                img.width=img.width-(img.width/(img.height/(img.height-h)))     
                img.height=h;     
            }     
                 
            img.onclick=function(){     
                try{ imgPopup.close();} catch(e){} 
				imgPopup=open('#', 'imgurl', 'width=500, height=500, left='+(screen.availWidth-500)/2+', top='+(screen.availHeight-500)/2)     
                imgPopup.document.write('<script>document.onclick=function(){ close();} /* 单击关闭窗口 */ <\/script>');     
                     
                imgPopup.document.write('<img src="'+this.src+'"/>'+     
                    '<script>'+     
                        'var w, h;'+     
                        'var img=document.images[0];'+     
                        'if(navigator.appName=="Opera"){w=img.width+10; h=img.height+40} else {w=img.width+10; h=img.height+25};'+     
                        'self.resizeTo(w, h);'+     
                        'self.moveTo((screen.availWidth-img.width)/2,(screen.availHeight-img.height)/2)'+     
                    '<\/script>'+     
                    '<style>body{margin:0; padding:0;} .hd{visibility:hidden;}<\/style>');     
                imgPopup.document.write('<p class="hd">ok</p>');     
                imgPopup.document.close();     
                imgPopup.focus();     
            }     
        } // shawl.qiu script     
    }     
