//验证特殊字符
function checkSpecial(str){
	var SPECIAL_STR = "~!@%^&*();'\"?><[]{}\\|,:/=+—“”‘";
	for(i=0;i<str.length;i++)
		if (SPECIAL_STR.indexOf(str.charAt(i)) !=-1){
		return true;
	}
	return false;
}
//验证日期
function checkDate(str){  
	var reg = "^([0-9]{4})-([0-9]{2})-([0-9]{2})$"; 
	var r = str.match(reg);  
	if(r==null)return false;  
	r[2]=r[2]-1;  
	var d= new Date(r[1], r[2],r[3]);  
	if(d.getFullYear()!=r[1])return false;  
	if(d.getMonth()!=r[2])return false;  
	if(d.getDate()!=r[3])return false;  
	return true;  
}
function lostlayerfocus()
{
	inover=false;
}
//获得包含中文字符串长度
function chinalen(s){
    var clen=s.length;				//初始化len，先不管中英文
    if(s.match(/[\u0391-\uFFE5]/ig)){			//判断字符串中是否包含中文
       clen+=s.match(/[\u0391-\uFFE5]/ig).length
    }
    return clen;
}
//只能输入1-20个以字母开头的字串
function isTrueName(s){
  var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._-]){0,20}$/;
    if (!patrn.exec(s)) return false
    return true
}
function iscode(s)
{
var patrn=/^[0-9 a-z A-Z]|[- _]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function isPasswda(s)
{
var patrn=/^[0-9 a-z A-Z]|[- _]{0,20}$/;
if (!patrn.exec(s)) return false
return true
}
function isdigits(s)
{
var patrn=/^[-]{0,1}([0-9]|[.]){0,20}$/;
if (!patrn.exec(s)) return false
return true
}
function isnumbers(s)
{
var patrn=/^[0-9]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function isintegers(s)
{
var patrn=/^[0-9]{0,20}$/;
if (!patrn.exec(s)) return false
return true
}
function istele(s)
{
var patrn=/^[0-9]|[- _ ,]{0,30}$/;
if (!patrn.exec(s)) return false
return true
}
function isDigit(str)
{
var patrn=/^[0-9]{1,2}$/;
if (!patrn.exec(str)) return false
return true
}
function ifdel(){
	return window.confirm("\u786E\u8BA4\u5220\u9664\uFF1F");
}
//校验是否全由数字组成
function isDigit(s)
{
    var patrn=/^[0-9]{1,20}$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验登录名：只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
function isRegisterUserNameeng(s)
{
    var patrn=/^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$/;
    if (!patrn.exec(s)) return false
    return true
}
function isRegisterUserName(s)
{
    var patrn=/^[a-zA-Z0-9]|[._]|[\u0391-\uFFE5]{0,20}$/;
    if (!patrn.exec(s)) return false
    return true
}
//English : /^[A-Za-z]+$/,
//Chinese : /^[\u0391-\uFFE5]+$/,

//校验用户姓名：只能输入1-30个以字母开头的字串
function isTrueName(s)
{
    var patrn=/^[a-zA-Z]{1,30}$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验密码：只能输入6-20个字母、数字、下划线
function isPasswd(s)
{
    var patrn=/^(\w){6,20}$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验普通电话、传真号码：可以“+”开头，除数字外，可含有“-”
function isTel(s)
{
    //var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?(\d){1,12})+$/;
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验手机号码：必须以数字开头，除数字外，可含有“-”
function isMobil(s)
{
    var patrn=/^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;
    if (!patrn.exec(s)) return false
    return true
}

//校验邮政编码
function isPostalCode(s)
{
    //var patrn=/^[a-zA-Z0-9]{3,12}$/;
    var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
    if (!patrn.exec(s)) return false
    return true
}


function isIP(s)  //by zergling
{
    var patrn=/^[0-9.]{1,20}$/;
    if (!patrn.exec(s)) return false
    return true
}
function　isEmail(strEmail)　{
if　(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)　!=　-1)
　　return　true;
else
　　return　false;
}
function isPersonIdValid(pszId)
{
    var  nLen, nIndex, nRet ;
    var  strTmp ;

    nRet = true ;

    /*判断身份证的长度是否为18或15位*/
    nLen = pszId.length ;
    if ((nLen != 15) && (nLen != 18))
       return (false) ;

    /*如果长度为15位，判断其各位是否为数字*/
    if (nLen == 15)
    {
        for (nIndex=0; nIndex<nLen; nIndex++)
        {
            strTmp = pszId.charAt(nIndex) ;
            if (( strTmp  < '0') || (strTmp > '9'))
            {
                nRet = false ;
                break ;
            }
        }
    }

    return (nRet) ;
}

function back() {
   javascript:history.go(-1);
}

/**
* added by LxcJie 2004.6.25
* 去除多余空格函数
* trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
* 用法：
*     var str = "  hello ";
*     str = str.trim();
*/
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, "");
}
/********************************** Empty **************************************/
/**
*校验字符串是否为空
*返回值：
*如果不为空，定义校验通过，返回true
*如果为空，校验不通过，返回false               参考提示信息：输入域不能为空！
*/
function checkIsNotEmpty(str)
{
    if(str.trim() == "")
        return false;
    else
        return true;
}//~~~
/*--------------------------------- Empty --------------------------------------*/

function ischina(s){
    if(s.match(/[\u0391-\uFFE5]/ig)){
    	return true	
    }
    return false;
}
/***/
function noshow(name,error){
	var names=document.getElementById(name);
	var errors=document.getElementById(error);
	errors.innerHTML='';
	names.className="";	
}
function show(name,error,msg){
	var names=document.getElementById(name);
	var errors=document.getElementById(error);
	var alertinfo=document.getElementById("alert-info");
	errors.innerHTML=msg;
	errormessage = errormessage+'<li>'+msg;
	names.className="input-erro";
	alertinfo.innerHTML=errormessage+'</ui>';
	sub = false;
}

function isname(s)
{
var patrn=/^[0-9 a-z A-Z]{1,20}$/;
if (!patrn.exec(s)) return false
return true
}
function re(){
	var alertinfo=document.getElementById("alert-info");
	alertinfo.style.display="none";	
	noshow('user','usernameerror');
	noshow('pass','passerror');
	noshow('mail','mailerror');
	noshow('code','codeerror');
    document.forms[0].username.value ="";
    document.forms[0].password.value ="";
    document.forms[0].email.value ="";
    document.forms[0].Rand.value ="";
    document.forms[0].passworded.value ="";
	document.forms[0].lost.checked=false;
	document.forms[0].subform.disabled="disabled";
}
function partSpace(s){
    var len = s.length;
    var i;
    var ch;
    var result = "";
    i = 0;
    while (i < len){
        ch = s.charAt(i++);
        result += ch;
        if (ch == ' '){
            return true;
        }
    }
    return false;
}

function valid(path){
	//return document.forms[0].submit();
	errormessage = "<h3><img id='alert-icon' src='"+path+"/web/img/alert-icon.gif' alt='错误' />请确认下面黄色高亮区内是否有未填写、填写不完全等错误</h3><ul>";
	sub = true;
    var user_name=document.forms[0].username.value;
    var user_password=document.forms[0].password.value;
    var user_email=document.forms[0].email.value;
    var user_rand=document.forms[0].Rand.value;
    user_name = trim(user_name);
    document.forms[0].username.value = user_name;
    user_password = trim(user_password);
    document.forms[0].password.value = user_password;
    user_email = trim(user_email);
    user_rand = trim(user_rand);
    head = user_name.substr(0,1);
    var nameerror=document.getElementById("usernameerror");
    nameerror.style.color='red';
	if(user_name==""){
		document.forms[0].username.value='';
		show('user','usernameerror','用户名不能为空！');
		document.forms[0].username.focus();
	}else if(partSpace(user_name)){
		show('user','usernameerror','用户名中不允许有不可见字符！');
		document.forms[0].username.focus();
	}else if(user_name.length*1>16||user_name.length*1<4){
		show('user','usernameerror','用户名由4-16位之间的字符或者数字组成！');
		document.forms[0].username.focus();
	}else if(isdigits(user_name)){
		show('user','usernameerror','用户名不能用纯数字！');
		document.forms[0].username.focus();
	}else if(isdigits(head)){
		show('user','usernameerror','用户名不能用数字开头！');
		document.forms[0].username.focus();  
	}else if(ischina(user_name)){ 
		show('user','usernameerror','用户名不能用中文！');
		document.forms[0].username.focus(); 	 
	}else{
		noshow('user','usernameerror');
	}
	if(user_password==""){ 
		document.forms[0].password.value='';
		document.forms[0].passworded.value='';
		show('pass','passerror','密码不能为空！');
		document.forms[0].password.focus();
	}else if(partSpace(user_password)){
		show('pass','passerror','密码中不允许有不可见字符！');
		document.forms[0].password.focus();
	}else if(user_password.length*1<4||user_password.length*1>16){ 
		show('pass','passerror','密码长度在4-16位之间的字符或者数字组成！');
		document.forms[0].password.focus(); 
	}else if(user_password!=document.forms[0].passworded.value){
		show('pass','passerror','确认密码不正确！');
		document.forms[0].passworded.focus();
	}else{
		noshow('pass','passerror');
	}
	if(user_email==""){ 
		show('mail','mailerror','电子邮箱不能为空！');
		document.forms[0].email.focus();
	}else if(user_email.length>50){ 
		show('mail','mailerror','电子邮箱长度不能大于50位！');
		document.forms[0].email.focus();
	}else if(!isEmail(user_email)){
		show('mail','mailerror','电子邮箱格式错误！');
		document.forms[0].email.focus(); 
	}else{
		noshow('mail','mailerror');
	}
	if(user_rand==""){
		show('code','codeerror','验证码不能为空！');
		document.forms[0].Rand.focus(); 
	}else{
		noshow('code','codeerror');
	}
	if(sub==true){
	  document.forms[0].subform.disabled="disabled";
	  document.forms[0].submit();
	}else{
		var alertinfo=document.getElementById("alert-info");
		alertinfo.style.display="block";
	}
}
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function valname(path){
	errormessage = "<h3><img id='alert-icon' src='"+path+"/web/img/alert-icon.gif' alt='错误' />请确认下面黄色高亮区内是否有未填写、填写不完全等错误</h3><ul>";
	sub = true;
    var user_name=document.forms[0].username.value;
    user_name = trim(user_name);
    document.forms[0].username.value = user_name;
    head = user_name.substr(0,1);
    var nameerror=document.getElementById("usernameerror");
    nameerror.style.color='red';
	if(user_name==""){
		document.forms[0].username.value='';
		show('user','usernameerror','用户名不能为空！');
		document.forms[0].username.focus();
	}else if(partSpace(user_name)){
		show('user','usernameerror','用户名中不允许有不可见字符！');
		document.forms[0].username.focus();
	}else if(user_name.length*1>16||user_name.length*1<4){
		show('user','usernameerror','用户名由4-16位之间的字符或者数字组成！');
		document.forms[0].username.focus();
	}else if(!isname(user_name)){
		show('user','usernameerror','用户名由字符或者数字组成！');
		document.forms[0].username.focus();
	}else if(isdigits(user_name)){
		show('user','usernameerror','用户名不能用纯数字！');
		document.forms[0].username.focus();
	}else if(isdigits(head)){
		show('user','usernameerror','用户名不能用数字开头！');
		document.forms[0].username.focus();  
	}else if(ischina(user_name)){ 
		show('user','usernameerror','用户名不能用中文！');
		document.forms[0].username.focus(); 	 
	}else{
		noshow('user','usernameerror');
	}
	if(sub==false){
		var alertinfo=document.getElementById("alert-info");
		alertinfo.style.display="block";
	}
}
function read(){
	if(document.forms[0].lost.checked==true)
		document.forms[0].subform.disabled="";
	else
		document.forms[0].subform.disabled="disabled";
}
//=============================修改密码
//验证修改密码
function valpw(){
	//return true;
    var oldPassword=document.forms[0].oldPassword.value;
    oldPassword = trim(oldPassword);
    var password=document.forms[0].password.value;
    password = trim(password);
    var passworded=document.forms[0].passworded.value;
    passworded = trim(passworded);
    var user_name=document.forms[0].username.value;
    user_name = trim(user_name);
	if(user_name==""){
		alert('用户名不能为空！');
		document.forms[0].username.focus();
		return false;
	}else if(partSpace(user_name)){
		alert('用户名中不允许有不可见字符！');
		document.forms[0].username.focus();
		return false;
	}else if(checkSpecial(user_name)){
		alert('用户名中不允许有特殊字符！');
		document.forms[0].username.focus();
		return false;
	}else if(partSpace(oldPassword)){
		alert('原始密码中不允许有不可见字符！');
		document.forms[0].oldPassword.focus();
		return false;
	}else if(oldPassword==''){
		alert("原始密码不能为空！");
		document.forms[0].oldPassword.focus(); 
		return false;
	}else if(oldPassword.length*1<4||oldPassword.length*1>16){ 
		alert('密码由4-16位之间的字符或者数字组成！');
		document.forms[0].oldPassword.focus(); 
		return false;
	}else if(partSpace(password)){
		alert('新密码中不允许有不可见字符！');
		document.forms[0].password.focus();
		return false;
	}else if(password==''){
		alert("新密码不能为空！");
		document.forms[0].password.focus(); 
		return false;
	}else if(password.length*1<4||password.length*1>16){ 
		alert('密码由4-16位之间的字符或者数字组成！');
		document.forms[0].password.focus(); 
		return false;
	}else if(password!=passworded){
		alert('重复密码不正确');
		document.forms[0].passworded.focus(); 
		return false;
	}else{
		return true;
	}
}
//验证修改密码_MD5
function valpwMD5(){
	//return true;
    var oldPassword=document.forms[0].oldPassword.value;
    oldPassword = trim(oldPassword);
    var password=document.forms[0].password.value;
    password = trim(password);
    var passworded=document.forms[0].passworded.value;
    passworded = trim(passworded);
    var user_name=document.forms[0].username.value;
    user_name = trim(user_name);
	if(user_name==""){
		alert('用户名不能为空！');
		document.forms[0].username.focus();
		return false;
	}else if(partSpace(user_name)){
		alert('用户名中不允许有不可见字符！');
		document.forms[0].username.focus();
		return false;
	}else if(checkSpecial(user_name)){
		alert('用户名中不允许有特殊字符！');
		document.forms[0].username.focus();
		return false;
	}else if(partSpace(oldPassword)){
		alert('原始密码中不允许有不可见字符！');
		document.forms[0].oldPassword.focus();
		return false;
	}else if(oldPassword==''){
		alert("原始密码不能为空！");
		document.forms[0].oldPassword.focus(); 
		return false;
	}else if(partSpace(password)){
		alert('新密码中不允许有不可见字符！');
		document.forms[0].password.focus();
		return false;
	}else if(password==''){
		alert("新密码不能为空！");
		document.forms[0].password.focus(); 
		return false;
	}else if(password.length*1<4||password.length*1>16){ 
		alert('密码由4-16位之间的字符或者数字组成！');
		document.forms[0].password.focus(); 
		return false;
	}else if(password!=passworded){
		alert('重复密码不正确');
		document.forms[0].passworded.focus(); 
		return false;
	}else{
		return true;
	}
}

var DeBase64Chars=new Array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);
  function getUserName(){
  		var bokie="bokie";
  		var content=GetCookie(bokie);
  		if(content==null||content==""){
  			window.location = "http://reg.bokee.com";
  		}
  		var tempStr=DeBase64(content);
  		var temp = tempStr.split(",");
  		var vf = document.getElementById("username");
		vf.innerHTML = ""+temp[0];
		document.forms[0].userID.value=""+temp[2];
  }
	function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
  }
  function GetCookie (name) {
  	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
	      return getCookieVal (j);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	  }
	  return null;
  }
   function DeBase64(str){
        var out,i,len;
        var c1,c2,c3;
        len=str.length;
        i=0;
        out="";
        tmp="";
        while(i<len)
        {
                c1=str.charCodeAt(i++)&0xff;
                if (c1=='=')
                {
                        return out;
                }
                c2=str.charCodeAt(i++)&0xff;
                if (c2=='=')
                {
                        return out;
                }
                c3=str.charCodeAt(i++)&0xff;
                if (c3==61)
                {
                        t1= DeBase64Chars[c1];
                        t2= DeBase64Chars[c2];
                        k1= ((t1&0x3F)<<2)|((t2&0x30)>>4);
                        out+=String.fromCharCode(k1);
                        return out;
                }
                c4=str.charCodeAt(i++)&0xff;
                if (c4==61)
                {
                        t1= DeBase64Chars[c1];
                        t2= DeBase64Chars[c2];
                        t3= DeBase64Chars[c3];
                        k1= ((t1&0x3F)<<2)|((t2&0x30)>>4);
                        k2= ((t2&0x0F)<<4)|((t3&0x3D)>>2);
                        out+=String.fromCharCode(k1,k2);
                        return out;
                }
                t1= DeBase64Chars[c1];
                t2= DeBase64Chars[c2];
                t3= DeBase64Chars[c3];
                t4= DeBase64Chars[c4];
                k1= ((t1&0x3F)<<2)|((t2&0x30)>>4);
                k2= ((t2&0x0F)<<4)|((t3&0x3D)>>2);
                k3= ((t3&0x03)<<6)|(t4&0x3F);
                out+=String.fromCharCode(k1,k2,k3);
        }
        return out;
}
function ResizeImg(ImgID0,Pic){
  var Img=new Image();
  Img.src=Pic;
  var ImgID=document.images[ImgID0];
  if(Img){
    if(Img.width > 500){
		Img.height=Img.height/(Img.width/500);
		Img.width=500;
	}
 /**if(Img.height > 150){
   Img.width=Img.width/(Img.height/150);
   Img.height=150;
 }*/
 ImgID.width=Img.width;
 ImgID.height=Img.height;
  }else{
    setTimeout(ResizeImg(ImgID0,Pic),500);
  }
}
function ResizeImg1(ImgID0,Pic,width){
  var Img=new Image();
  Img.src=Pic;
  var ImgID=document.images[ImgID0];
  if(Img){
    if(Img.width > width){
		Img.height=Img.height/(Img.width/width);
		Img.width=width;
	}
 ImgID.width=Img.width;
 ImgID.height=Img.height;
  }else{
    setTimeout(ResizeImg(ImgID0,Pic),width);
  }
}
function ShowImgAll(ImgID0,Pic){
  document.getElementById("imagediv").style.left=0;
  document.getElementById("imagediv").style.top=0;
  document.getElementById("imagediv").style.display="block";
}

function hideImageDiv(ImgID0){
  document.getElementById("imagediv").style.display="none";
}