//验证用户名是否存在
//是否只允许中文注册
var regchnonly='<%=RegChnOnly%>'=='True'?true:false;
//按钮是否可用
function disbutton()
{
  var name=$('name');
  var password=$('password');
  var verify=$('verification');  
  var button=$('btnLogin');
  
  if(name.value!='' && password.value!='')
  {
     button.disabled=false;
  }
  else
  {
    button.disabled=true;   
  }
}
/*验证是否是中文*/
function IsChinese(str)
{
 var pattern=/^[\u4300-\u9fa5]+$/;
 if(!pattern.test(str))
  {return false;}
  return true;
}
function ShowMess(o) 
{ 
	var check_result = $('resultname');
	var check_result1 = $('resultmail');
	var keyword=$('keyword').value;
	var dvajax = new DvAjax();

    if(o=="name")
    {      
		var str_userID = $('name').value; 	
		if(str_userID=='')
		{
		    check_result.innerHTML='<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;您还没有填写您的用户名!</span>';
		       return;		   
		}	
		var ischinese=IsChinese(str_userID); 
		
		if(regchnonly)
		{		 
		
		    if(ischinese.toString()=="false")
		    {
		       check_result.innerHTML='<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;论坛限制非中文注册!</span>';
		       return;
		    }
		}
		
		chkName(str_userID,keyword,check_result);
		
		check_result.innerHTML = '<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;正在检测用户名合法性!</span>';
		dvajax.Request("get","user_chkname.aspx",'name='+str_userID+'',function(xmlhttp){check_result.innerHTML = xmlhttp.responseText;},true);	
    }
    else if(o=="email")
    {
		var str_email = $('email').value;
		if(str_email=='')
		{
		check_result1.innerHTML = '<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;您还没有填写您的Email地址!</span>';
		return ;		
		}
		else if(str_email.search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi) < 0 ||str_email.length>=45 || str_email.indexOf("..")!=-1)
		{
		  check_result1.innerHTML = '<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;请正确填写您的Email地址!</span>';	
		  return ;
		}
		else
		{
		check_result1.innerHTML = '<span><img src=\"templates/default/images/icon_warning.gif\">&nbsp;正在检测email合法性!</span>';
		dvajax.Request("get","user_chkemail.aspx",'option=email&email='+str_email+'',function(xmlhttp){check_result1.innerHTML = xmlhttp.responseText;},true);
		}
	}
}

function chkName(namevalue,keyword,msgobj)
{
	if (foundSpecialChars(namevalue))
	{
		msgobj.innerHTML='会员名不能包含特殊符号';
		f.name.focus();
		return false;
	}
	if (isRefuse(namevalue,keyword))
	{
		msgobj.innerHTML='会员名不合法，不能使用如下类型的名称 '+keyword;
		f.name.focus();
		return false;
	}
	if (isBadWord(namevalue))
	{
		msgobj.innerHTML='严禁使用不文明字词 !';
		f.name.focus();
		return false;
	}	
}

//检查密码是否一致
 function checkPWD(pwd1,pwd2)
 {
	var obj1 = $(pwd1);
	var obj2 = $(pwd2);
	if(obj1.value!="" && obj2.value!="")
	{
		
		if(obj1.value!=obj2.value)
		{
		   $('pwdmsg').innerHTML='<span><img src=\"templates/default/images/note_error.gif\">&nbsp;您输入的密码不一致，请重新输入!</span>';

		}
		else
		{
		   $('pwdmsg').innerHTML='<span><img src=\"templates/default/images/note_ok.gif\">&nbsp;输入正确!</span>';			
		}	
	}
 }
  //检查密码提示问题
 function checkQ()
 {	
	if($('question').value=="")
	{
		$('Q').style.display="none";
		$('pwdQ').style.display="block";
		return false;
	}
	else
	{
		$('pwdQ').style.display="none";
		$('Q').style.display="block";
		return true;
	}
 }
 //检查问题答案
  function checkA()
 {
	if($('answer').value=="")
	{
		$('A').style.display="none";
		$('pwdA').style.display="block";
		return false;
	}
	else
	{
		$('A').style.display="block";
		$('pwdA').style.display="none";
		return true;
	}
 }
 //检查Email是否填写正确
 function chkEmail(email)
 {
	var objEmailMsg = $('emailmsg');
	var objEmailErr = $('emailErr');
	var objEmailOK = $('emailOK');
	var objEmail = $('email');
	objEmailMsg.style.display="none";
	var arr = objEmail.value.split('.');
	if(objEmail.value.search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi) < 0 || objEmail.value.length>=45 || objEmail.value.indexOf("..")!=-1 || arr[arr.length-1].replace(/(^\s*)|(\s*$)/g, "")=="")
	{
		objEmailErr.style.display="block";
		objEmailOK.style.display="none";
	}
	else
	{
		objEmailErr.style.display="none";
		objEmailOK.style.display="block";
	}
 }
 
 function chkhomepage(homepage)
{
/*	if(homepage.value=='')
	{
		$('PagErr').className="HintMsg";
		$('PagOK').className="HintMsg";
	}
	else
	{
	
		if(homepage.value != '' && chkUrl(homepage.value))
		{
			$('PagErr').className="WarningMsg";
			$('PagOK').className="HintMsg";
		}
		else	
		{
			$('PagErr').className="HintMsg";
			$('PagOK').className="WarningMsg";
		}
	}*/
}
//验证电话号码是否填写正确
function chkTel(tel)
{
	if(tel.value=='')
	{
		$('TelErr').style.display="none";
		$('TelOK').style.display="none";
	}
	else
	{
		if(tel.value != '' && tel.value.search(/^\+?[0-9]+\-?[0-9]+$/gi) < 0)
		{
			$('TelErr').style.display="block";
			$('TelOK').style.display="none";
		}
		else
		{
			$('TelErr').style.display="none";
			$('TelOK').style.display="block";
		}
	}
}
//验证手机号码是否正确
function chkmobile(mobile)
{
	if(mobile.value=='')
	{
		$('MobileErr').style.display="none";
		$('MobileOK').style.display="none";
	}
	else
	{
		if(mobile.value != '' && mobile.value.search(/^(13\d{9}|15[3|8|9]\d{8})$/gi) < 0)
		{
			$('MobileErr').style.display="block";
			$('MobileOK').style.display="none";
		}
		else
		{
			$('MobileErr').style.display="none";
			$('MobileOK').style.display="block";
		}
	}
}
//验证QQ是否填写正确
function chkQQ(qq)
{
	if(qq.value=='')
	{
		$('QQErr').style.display="none";
		$('QQOK').style.display="none";
	}
	else
	{
		if (qq.value != '' && (qq.value.length<5 || qq.value.length>15 || isNaN(qq.value)))
		{
			$('QQErr').style.display="block";
			$('QQOK').style.display="none";
		}
		else
		{
			$('QQErr').style.display="none";
			$('QQOK').style.display="block";
		}
	}	
}
//验证MSN
function chkMSN(msn)
{
	if(msn.value=='')
	{
		$('MSNErr').style.display="none";
		$('MSNOK').style.display="none";
	}
	else
	{
		if ((msn.value != '' && msn.value.search(/^[^\s@:"'<>,&]{2,}@[^\[\.]+\.[^\[]{2,}$/gi) < 0) || msn.value.length>=35)
		{
			$('MSNErr').style.display="block";
			$('MSNOK').style.display="none";
		}
		else
		{
			$('MSNErr').style.display="none";
			$('MSNOK').style.display="block";
		}
	}
}

 function sel(f)
 {
	var i = f.selectedIndex;
	var imgsrc = f.options[i].value;
	var objImg = $('imgface');
	var objA = $('faceLink');
	objA.href= "<%=Dvbbs.Utils.Config.uploadfaces%>"+imgsrc;
	objImg.src = "<%=Dvbbs.Utils.Config.uploadfaces%>"+imgsrc;
	$('face').value=imgsrc;
 }

var bV=parseInt(navigator.appVersion); 
var IE4=((document.all)&&(bV>=4))?true:false;                      
var IsFireFox = ($ && !document.all)?true:false
var NS4=(document.layers)?true:false; 
var z=0; 
function LayerV(LayerName,V){ 
	
   E=eval('document.'+LayerName); 
   if(IE4){E=eval('document.all.'+LayerName);}
   if(IsFireFox){ E=$(LayerName);}
   E.style.visibility=(V?'visible':'hidden'); 
} 
////////////////////////////////////////////////////////// 
//下面这个函数实现了当点击图片时，把图片选上 
function select(image1){ 
var html,url1
url1=image1.src 
$("face").value = "userface"+url1.substring(url1.lastIndexOf('/'));
html="<img src="+url1+" width=70 height=70 onclick='javascript:select(this)'>" 
html=html+"<a href=javascript:LayerV('Zhong',z=1-z)><font style='font-family: Webdings;'>6</font></a>" 
$("pic").innerHTML=html 
LayerV('Zhong',z=1-z) 
} 

function chkUrl(str)
{
	if (str.search(/^(http|https):\/\/[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]{2,}[A-Za-z0-9\.\/=\?%\-&_~`@[\]:+!;]*$/gi) >= 0)
	{
		return true;
	}
	return false;
}
function foundSpecialChars(str)
{
	var chars = "~!@#$%^&*()+=|\/?<>,.:;'\"`[]{} ";
	for (var i=0; i<chars.length; i++)
	{
		if ( str.indexOf(chars.substring(i, i+1)) != -1 )
		{
			return true;
		}
	}
	return false;
}

function isRefuse(name,keyword)
{
	
	var refuseString = keyword;
	if (refuseString.indexOf('|') == -1)
	{
		return false;
	}
	var refuseString = refuseString.split('|');
	for(i=0; i<=refuseString.length; i++)
	{
		if (name.toLowerCase().indexOf(refuseString[i]) != -1)
		{
			return true;
		}
	}
	return false;
}

function isBadWord(name)
{
	var badwords = '妈的|你妈|妈b|妈比|fuck|shit|我日|法轮';
	if (badwords.indexOf('|') != -1)
	{
		return false;
	}
	var badword = badwords.split('|');
	for(i=0; i<=badword.length; i++)
	{
		if (name.toLowerCase().indexOf(badword[i]) != -1)
		{
			return true;
		}
	}
	return false;
}



function chkReg()
{
	var obj = document.getElementById('keyword');
	var f = document.forms[0];
	
	if (foundSpecialChars(f.name.value))
	{
		alert('会员名不得包含特殊符号');
		f.name.focus();
		return false;
	}
	if (isRefuse(f.name.value,obj.value))
	{
		alert('会员名不合法，不能使用如下类型的名称 '+obj.value);
		f.name.focus();
		return false;
	}
	if (isBadWord(f.name.value))
	{
		alert('严禁使用不文明字词 !');
		f.name.focus();
		return false;
	}
	if (f.password.value == '' || f.password.value.trim() != f.password.value || f.password.value.length < 6 || f.password.value.length > 20)
	{
		alert('密码不得为空或包含空格，长度6-20');
		f.password.focus();
		return false;
	}
	if (f.password.value != f.chkpwd.value)
	{
		alert('两次密码填写不一致');
		f.password.focus();
		return false;
	}
	if(f.question.value.replace(/(^s*)|(s*$)/g, "")=="")
	{
		alert("请填写密码提示问题");
		f.question.focus();
		return false;
	}
	if(f.answer.value.replace(/(^s*)|(s*$)/g, "")=="")
	{
		alert("请填写问题答案");
		f.answer.focus();
		return false;
	}
	if (f.email.value.search(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/gi) < 0)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	if (f.email.value.length>=45)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	if (f.verification)
	{
		if (!f.verification.disabled && f.verification.value.length == '')
		{
			alert('请正确输入验证码');
			f.verification.focus();
			return false;
		}
	}
	return true;
}

function displayToggle(chkbox)
{
	if (chkbox.checked)
	{
		$('optionInputs').style.display='';
		//$('toggletext').innerText='隐藏以下选填内容';
	}
	else
	{
		$('optionInputs').style.display='none';
		//$('toggletext').innerText='显示更多选填内容';
	}
}

function selectFace()
{
	var f = document.forms[0];
	if (
			f.face.value == ''
			|| f.face.value == 'http://'
	   )
	{
		f.face.value = 'files/uploadfaces/' + (f.male.checked ? 1 : 2) + '.gif';
	}
	f.face.readOnly	= true;
	$('size').style.visibility ='hidden';
	window.open(
		'choose_face.aspx',
		'chooseface',
		'left=190px, top=110px, width=537px, height=425px, resizable=no, scrolls=no'
	);
}

function manualInputFace()
{
	var f = document.forms[0];
	f.face.value	= 'http://';
	f.face.readOnly	= false;
	$('size').style.visibility ='visible';
}

function setDefaultFace(i)
{
	var j = (i == '1' ? '2' : '1');
	var faceInput = $('face');
	if (faceInput.value == ("templates/"+getCookie(getCookie('app_prefix') + 'tplname')+"/skins/" + getCookie(getCookie('app_prefix') + 'tplskin') + "/userface/" + j + '.gif') || faceInput.value == '' || faceInput.value == 'http://')
	{
		faceInput.value = "templates/"+getCookie(getCookie('app_prefix') + 'tplname')+"/skins/" + getCookie(getCookie('app_prefix') + 'tplskin') + "/userface/" + i +  '.gif';
	}
}

function RegForm(objdiv){
	
	ShadeDiv.Show(objdiv,'600','400');
}

function submit_form()
{
	var obj = document.getElementById('keyword');
	var f = document.forms[0];
	
	if (foundSpecialChars(f.name.value))
	{
		alert('会员名不得包含特殊符号');
		f.name.focus();
		return false;
	}
	if (isRefuse(f.name.value,obj.value))
	{
		alert('会员名不合法，不能使用如下类型的名称 '+obj.value);
		f.name.focus();
		return false;
	}
	if (isBadWord(f.name.value))
	{
		alert('严禁使用不文明字词 !');
		f.name.focus();
		return false;
	}
	if (f.password.value == '' || f.password.value.trim() != f.password.value || f.password.value.length < 6 || f.password.value.length > 20)
	{
		alert('密码不得为空或包含空格，长度6-20');
		f.password.focus();
		return false;
	}
	if (f.password.value != f.chkpwd.value)
	{
		alert('两次密码填写不一致');
		f.password.focus();
		return false;
	}
	if(f.question.value.replace(/(^s*)|(s*$)/g, "")=="")
	{
		alert("请填写密码提示问题");
		f.question.focus();
		return false;
	}
	if(f.answer.value.replace(/(^s*)|(s*$)/g, "")=="")
	{
		alert("请填写问题答案");
		f.answer.focus();
		return false;
	}
	if (f.email.value.search(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/gi) < 0)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	if (f.email.value.length>=45)
	{
		alert('请正确填写你的邮件地址');
		f.email.focus();
		return false;
	}
	if (f.verification)
	{
		if (!f.verification.disabled && f.verification.value.length == '')
		{
			alert('请正确输入验证码');
			f.verification.focus();
			return false;
		}
	}
	if(!($('IsAllow').checked))
	{
		alert('请您查看注册条款,并同意条款方可注册!');
		collapse($('rule'), 'rules');
		return false;
	}
	return true;
	
}

function RegFormClose(getcode)
{
	ShadeDiv.Close();
	if ($('pgetcode')){$('pgetcode').src=getcode+'?t='+Math.random();}
	
}

function RemoveText(obj)
{
	if(obj.value.length > 0)
	{
		outtips();
	}
}
