function isEmail(emailad) {
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var check=/@[\w\-]+\./;
    var checkend=/\.[a-zA-Z]{2,3}$/;
    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
      return false;
    }else{
      return true;
    }	
}

function isNumber(str) {
	var ValidChars = "0123456789.-";
	var err=0;
	if(str.length>20) return false;
	for (var i =0; i<str.length; i++) {
		if (ValidChars.indexOf(str.charAt(i)) == -1) {
			return false;
		} 
		if (i==0&&((str.charAt(i)=='0'&&str.charAt(i)!='.')||str.charAt(i)=='.')) {
			return false;
		}
		if (i!=0&&str.charAt(i)=='-') {
			return false;
		}
		if (str.charAt(i)=='.') {
			err++;
			if(err==2) return false;
		}
	} 
	return true;
}

function isPhone(str) {
	var valid = 1;
	var ValidChars = "0123456789()-+ ";
	if(str.length>20) valid=0;
	for (var i =0; valid!=0&&i < str.length; i++) {
		if (ValidChars.indexOf(str.charAt(i)) == -1) {
			valid = 0;
		} 
	} 
	return valid;
}

//判断是否为空，是返回true，否返回false
//function isEmpty(str) {
//    if(str=="") return true;
//    else return false;
//}

//判断是否为邮政编码，要求6位数字，是返回true，否返回false
function isZip(str) {
    var reg=/^\d{6}$/;
    return reg.test(str);
}

//判断是否为电子邮件，要求格式abc@alibaba.com，是返回true,否返回false
function isSimpleEmail(str) {
    var reg=/^\S+@\S+\.\S+$/;
    return reg.test(str);
}

//严格的email格式判断
function isEmailAddress(email) {
    invalidChars = " /;,:{}[]|*%$#!()`<>?";
    if (email == "") {
        return false;
    }
    for (i=0; i< invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    pos = email.indexOf("@",1)
    if (pos == -1) {
        return false;
    }
    if (email.indexOf("@", pos+1) != -1) {
        return false;
    }
    periodPos = email.indexOf(".",pos)
    if(periodPos == -1) {
        return false;
    }
    if ( pos + 2 > periodPos) {
        return false;
    }
    if ( periodPos + 3 > email.length) {
        return false;
    }
    return true;
}

//判断是否为网址，要求格式http://www.alibaba.com，是返回true,否返回false
function isWWW(str) {
    var reg=/^http:\/\/\S+\.\S+$/;
    return reg.test(str);
}

//判断是否为手机号码，要求11位数字，前二位为13，是返回true,否返回false
function isMobilePhone(str) {
    var reg=/^13\d{9}$/;
    return reg.test(str);
}

//判断是否为电话号码，要求格式0571-85022088，是返回true,否返回false
function isPhoneNum(str) {
    var reg=/^0\d{2,3}-\d{6,8}$/;
    return reg.test(str);
}

//判断是否是身份证号码
function isPersonID(str) {
    if(isNumber(str) && (str.length==15 || str.length==18)) {
        return true;
    }
    return false;
}

//判断是否为金额，要求格式最多2位小数，是返回true,否返回false
function isMoney(str) {
    var reg=/^\d+\.{0,1}\d{0,2}$/;
    return reg.test(str);
}

//判断是否为日期，要求格式2002-5-13或2002-05-13，是返回true,否返回false
function isDate(str) {
    var flag;
    //用正则表达式判断
    var reg=/^\d{4}-\d{1,2}-\d{1,2}$/;
    flag=reg.test(str);
    if(flag==false) return flag;

    //判断日期是否正确
    var YMD;
    YMD=str.split("-");
    var year,month,date;            //年，月，日
    year=parseInt(YMD[0]);
    month=parseInt(YMD[1]);
    date=parseInt(YMD[2]);
    if(month>12 || month<1) return false;
    if(date>31 || date<1) return false;
    var maxDate=new Array(12);      //每月的最大日期
    if(month==1) maxDate[0]=31;
    if(month==2) maxDate[1]=28;
    if(month==3) maxDate[2]=31;
    if(month==4) maxDate[3]=30;
    if(month==5) maxDate[4]=31;
    if(month==6) maxDate[5]=30;
    if(month==7) maxDate[6]=31;
    if(month==8) maxDate[7]=31;
    if(month==9) maxDate[8]=30;
    if(month==10) maxDate[9]=31;
    if(month==11) maxDate[10]=30;
    if(month==12) maxDate[11]=31;
    //闰月
    if((year%4==0 && year%100!=0) || (year%400==0)) maxDate[1]=29;
    if(maxDate[month-1]<date) return false;
    else return true;
}

//判断用户按键是否为数字
function isNumPress() {    
    if(window.event.keyCode>=48&&window.event.keyCode<=57) return true;
    else return false;
}

//判断用户按键是否为数字或回车
function isNumOrEnterPress() {    
    if((window.event.keyCode>=48 && window.event.keyCode<=57) || window.event.keyCode==13) return true;
    else return false;
}

//字符串去除左右空格的方法
function trim(str) {
    regExp1 = /^ */;
    regExp2 = / *$/;
    return str.replace(regExp1,'').replace(regExp2,'');
}

//显示问候语
function showHello() {
    var greeting;
    var d = new Date();    
    h = d.getHours();
    if(h<6) {
        greeting="凌晨好";
    } else if (h<9) {
        greeting="早上好";
    } else if (h<12) {
        greeting="上午好";
    } else if (h<14) {
        greeting="中午好";
    } else if (h<17) {
        greeting="下午好";
    } else if (h<19) {
        greeting="傍晚好";
    } else if (h<22) {
        greeting="晚上好";
    } else {
        greeting="夜里好";
    }
    document.write(greeting);
}

var whitespace = " \t\n\r";
function isWhitespace (s){
   var i;
    if (isEmpty(s)) 
		return true;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function hasWhitespace (s) {
    var i;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (c == " ") {
            return true;
        }
    }
    return false;
}

//判断是否包含标点符号
function hasInterpunction(s) {
    var i;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (c < "0") {
            return true;
        }
        if (c > "9" && c < "A") {
            return true;
        }
        if (c > "Z" && c < "a") {
            return true;
        }
        if (c > "z" && c <= "~") {
            return true;
        }
    }
    return false;
}

function isEmpty(s){
  return ((s == null) || (s.length == 0))
}

function visibleField(_field,_hs){
   	if (document.all){ 
		if(_hs == 1) eval("document.all."+_field +".style.visibility='visible';");
		if(_hs == 0) eval("document.all."+_field +".style.visibility='hidden';");
	}else{
		if (_hs=='1') eval("document.layers['"+_field+"'].visibility='show';");
		if (_hs=='0') eval("document.layers['"+_field+"'].visibility='hide';");
	}
}
function checkPhone (s){
 	var i;
    if (isEmpty(s)){
       if (checkPhone.arguments.length == 1){ 
	    	return false;
	   }else{
	   		return (checkPhone.arguments[1] == true);
	   }
	}   
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
		if(i == 0){
		 	if(c == '(' ){
		  		continue;
		 	}
		} else 
		if( i == 4 ){
		 	if(c == ')'){
		  		continue;
		 	}
		} else 
		if(i == 8){
		 	if( c == '-'){
		  		continue;
		 	}
		} else{
		 	if (!isDigit(c)) return false; 
		}
    }
    return true;
}

function isDigit (c){   
	return ((c >= "0") && (c <= "9"))
}

function isInteger(getS){
   var i;
    if (isEmpty(getS)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);
    for (i = 0; i < getS.length; i++)
    {   
        var c = getS.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

function setCookie(name, value, expires, path, domain, secure) {
    var caution = false
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie

}

function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}

function encode(str) {
	var result = "";
	
	for (i = 0; i < str.length; i++) {
		if (str.charAt(i) == " ") result += "+";	
		else if (str.charAt(i) == " ") result += "+";
		else result += str.charAt(i);
	}
	
	return escape(result);
}

function decode(str) {
//	var result = "";

 	var result = str.replace(/\+/g, " ");
	
/*	
	for (i = 0; i< str.length; i++) {
		if (str.charAt(i) == "+") result += " ";
		else result += str.charAt(i);
	}
*/
	return unescape(result);
}


function encode1(str) {
	str =  escape(str);
	return str.replace(/\+/g, "%2B");
}

function newwin(url) {
	var win = window.open(url,"newwin","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=600");    	
    win.focus();
}

function newupload(url) {	
	var win = window.open(url,"upload","toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,personal=no,menu=no,location=no,resizable=no,width=620,height=200");    	
    win.focus();
}

function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : ""
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",1000)

}

function goback() {
	if(window.document.forms[1].Done) {
		window.location=window.document.forms[1].Done.value;
	}
	else if (window.document.forms[1].done) {
		window.location=window.document.forms[1].done.value;
	} 
	else {
		history.go(-1)
	}
}

function fullform() {	
	var myform = document.forms[1];		
	for(var i=0;i<myform.elements.length;i++) {
		var element = myform.elements[i];		
		if (eval("typeof("+"cgi_"+element.name+")")=='undefined') 
			continue;
		var jsvar = eval("cgi_"+element.name);				
		if (element.type=="select-one") {
			for(var j=0;j<element.options.length;j++) {
				var option = element.options[j];
				if (option.value==eval("cgi_"+element.name)) {
					option.selected=true;									
					break;
				}				
			}						
		}			
		else if (element.type=="text") {
				element.value=eval("cgi_"+element.name);
		}
		else if (element.type=="checkbox") {
			     jsvar = jsvar+",";
			 	 if (jsvar.indexOf(element.value+",")>-1) {			 	 	
			 	    element.checked=true;
			 	 }
			 	    
		}
		else if (element.type=="radio") {
			 if (jsvar==element.value)
			    element.checked=true;
		}				
		else if (element.type=="textarea") {
			 element.value=jsvar;
		}
		
	}
}

function encode(url) {
	
}

//检查文本框字符长度(str文本框文本,minlen最小长度,maxlen最大长度)
function checkSize(str, minlen, maxlen) {
    
    if(isEmpty(str)) {
        alert("内容为空 ^O^");
        return false;
    }
    else if(str.length < minlen || str.length > maxlen) {
        alert("请调节一下内容大小 ^&^");
        return false;
    }

}

//长度为字符长度(不管单双字节)
function checkSize2(str, minlen, maxlen, objectName) {

    if(isEmpty(str)) {
        alert("“" + objectName + "”" + "内容为空 ^O^");
        return false;
    }
    else if(str.length < minlen || str.length > maxlen) {
        alert("请调节一下" + "“" + objectName + "”" + "内容大小 ^&^");
        return false;
    }

}

function getStrLength(str){
    var length=0;
    for (var i = 0; i < str.length; i++) {   
           var c = str.charCodeAt(i);
           if (c < 128){
                length=length+1;
            }else{
                length=length+2;
            }
      } 
      return length;
}

function drawImage(ImgD,width,height) {
    var image=new Image();
    image.src=ImgD.src;
    if((width/image.width)>(height/image.height)) {
        ImgD.height = height;
        ImgD.width = (height/image.height)*image.width;
    } else {
        ImgD.width = width;
        ImgD.height = (width/image.width)*image.height;
    }
    ImgD.alt = image.width + "x" + image.height;
}

function drawImageByStandard(ImgD,standard) {
    var image=new Image();
    image.src=ImgD.src;
    if ((image.width > standard)  || (image.height > standard)) {
    	if (image.width > image.height){
    		ImgD.width = standard;
        ImgD.height = (standard/image.width)*image.height;
    	} else {
    		ImgD.height = standard;
        ImgD.width = (standard/image.height)*image.width;
    	}
    	
    }  
}

function showimage(imageUrl,size) {
    var imgObj = new Image()
    imgObj.src = imageUrl;
    if(imgObj.width > imgObj.height) {
        document.write("<img src="+imgObj.src+" border=1  class=black-border height=" + imgObj.height*size/imgObj.width + " width=" + size + ">");
    } else if(imgObj.width < imgObj.height) {
        document.write("<img src="+imgObj.src+" border=1 class=black-border height=" + size + " width="+ imgObj.width*size/imgObj.height +">");
    } else {
        document.write("<img src="+imgObj.src+" border=1 class=black-border height=" + size + " width="+ size + " >");
    }
}

function disableRefreshKey() {
    if ( (event.keyCode == 8
        && (event.srcElement.type != "text" 
        && event.srcElement.type != "textarea" 
        && event.srcElement.Type != "password")) //屏蔽退格删除键 
        || (event.keyCode==116) //屏蔽 F5 刷新键
        || (event.ctrlKey && event.keyCode==82) //Ctrl + R
        || (event.ctrlKey && event.keyCode==78) //屏蔽 Ctrl+n
        || (event.shiftKey&& event.keyCode==121) //屏蔽 shift+F10
        || (event.srcElement.tagName == "A" && event.shiftKey) //屏蔽 shift 加鼠标左键新开一网页
        || (event.altKey && event.keyCode==115)) { //屏蔽Alt+F4
        event.keyCode=0;
        event.returnValue=false;
    }
}
