﻿// JavaScript Document
function buttonswap(tdid,cssname,acount,index){
	var i;
	var buttonid;
	var divid;
	buttonid=tdid+"_button"+index;
	divid=tdid+index;
	document.getElementById(buttonid).className=cssname + "_on";
	document.getElementById(divid).style.display="";
	for(i=1;i<=acount;i++){
		if(i!=index){
        	buttonid=tdid+"_button"+i;
	        divid=tdid+i;
	        document.getElementById(buttonid).className=cssname + "_off";
			document.getElementById(divid).style.display="none";
			}
		}
	}
function gourl(url){
	if(url!=""){
	window.open(url);
	}
	}
// JavaScript Document
function divdisplay(divid,showid,AllCount){
	var i=0;
	document.all(divid+showid).style.display="";
	for(i;i<=AllCount;i++){
		if(i!=showid){
		document.all(divid+i).style.display="none";
		}
	}
}

function checkUnick(unick){
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp==null){
		return false;
		}
	var url="ajax.asp?unick=";
	url=url+escape(unick);
	url=url+"&sid="+Math.random();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
	var ResText=xmlHttp.responseText;
	if(xmlHttp.readyState==4){
			if(ResText=="0"){
			document.all("body_main_form_div1").innerHTML="此用户名已被使用，请更换用户名！";
			document.all("body_main_form_div1").style.display="";
			document.all("body_main_form_div1").className="border_red";
			}
			else{
			document.all("body_main_form_div1").innerHTML="您可以使用此用户名！";
			document.all("body_main_form_div1").style.display="";
			document.all("body_main_form_div1").className="border_gray";
			}
		}
	}	
	xmlHttp.send(null);
	}
	
function form_reg(inputID){
	var returnvale=true;
	var i=0;
	var zhcn = /^[\u4e00-\u9fa5]+$/i; 
	var user_rname=document.getElementById("user_rname").value;
	var user_nick=document.getElementById("user_nick").value;
	var user_pword=document.getElementById("user_pword").value;
	var user_rpword=document.getElementById("user_rpword").value;
	//var user_uid=document.getElementById("user_uid").value;
	var user_address=document.getElementById("user_address").value;
	var user_code=document.getElementById("user_code").value;
	var user_tel=document.getElementById("user_tel").value;
	var user_yzm=document.getElementById("user_yzm").value;
	var user_zyzm=document.getElementById("user_zyzm").value;
//	for(i;i<=8;i++){
//		document.all("body_main_form_div"+i).style.display="none";
//		}
	if(inputID==0 || inputID==10){
		if(!zhcn.test(user_rname) || user_rname.length<=1){
			document.all("body_main_form_div0").style.display="";
			document.all("body_main_form_div0").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div0").style.display="";
			document.all("body_main_form_div0").className="border_gray";
		}
	}
	if(inputID==1 || inputID==10){
		if(user_nick.length<3 || user_nick.length>16){
			document.all("body_main_form_div1").style.display="";
			document.all("body_main_form_div1").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div1").style.display="";
			document.all("body_main_form_div1").className="border_gray";
			checkUnick(user_nick);
		}
	}
	if(inputID==2 || inputID==10){
		if(user_pword.length<6 || user_pword.length>16){
			document.all("body_main_form_div2").style.display="";
			document.all("body_main_form_div2").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div2").style.display="";
			document.all("body_main_form_div2").className="border_gray";
		}
	}
	if(inputID==3 || inputID==10){
		if(user_rpword != user_pword){
			document.all("body_main_form_div3").style.display="";
			document.all("body_main_form_div3").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div3").style.display="";
			document.all("body_main_form_div3").className="border_gray";
		}
	}
	//if(inputID==4 || inputID==10){
	//	if(user_uid.length<16 || user_uid.length>18){
	//			document.all("body_main_form_div4").style.display="";
	//		document.all("body_main_form_div4").className="border_red";
	//		returnvale=false;
    //   }else{
	//		document.all("body_main_form_div4").style.display="";
	//		document.all("body_main_form_div4").className="border_gray";
	//   }
	//}
	if(inputID==5 || inputID==10){
		if(user_address.length<4){
			document.all("body_main_form_div5").style.display="";
			document.all("body_main_form_div5").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div5").style.display="";
			document.all("body_main_form_div5").className="border_gray";
		}
	}
	if(inputID==6 || inputID==10){
		if(user_code.length != 6){
			document.all("body_main_form_div6").style.display="";
			document.all("body_main_form_div6").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div6").style.display="";
			document.all("body_main_form_div6").className="border_gray";
		}
	}
	if(inputID==7 || inputID==10){
		if(user_tel.length < 8 || user_tel.length >=14){
				document.all("body_main_form_div7").style.display="";
				document.all("body_main_form_div7").className="border_red";
				returnvale=false;
		}else{
			document.all("body_main_form_div7").style.display="";
			document.all("body_main_form_div7").className="border_gray";
		}
	}
	if(inputID==8 || inputID==10){
		if(user_yzm != user_zyzm){
			document.all("body_main_form_div8").style.display="";
			document.all("body_main_form_div8").className="border_red";
			returnvale=false;
		}else{
			document.all("body_main_form_div8").style.display="";
			document.all("body_main_form_div8").className="border_gray";
		}
	}
	return returnvale;
}

function form_login(){
	var i=0;
	var returnvale=true;
	var user_nick=document.getElementById("user_nick").value;
	var user_pword=document.getElementById("user_pword").value;
	var user_yzm=document.getElementById("user_yzm").value;
	var user_zyzm=document.getElementById("user_zyzm").value;
	for(i;i<=2;i++){
		document.all("body_main_form_div"+i).style.display="none";
		}
	if(user_nick.length<3 || user_nick.length>16){
		document.all("body_main_form_div0").style.display="";
		document.all("body_main_form_div0").className="border_red";
		returnvale=false;
		}
	if(user_pword.length<6 || user_pword.length>16){
		document.all("body_main_form_div1").style.display="";
		document.all("body_main_form_div1").className="border_red";
		returnvale=false;
		}
	if(user_yzm != user_zyzm){
		document.all("body_main_form_div2").style.display="";
		document.all("body_main_form_div2").className="border_red";
		returnvale=false;
		}
	return returnvale;
}

function form_submitnews(){
	var i=0;
	var returnvale=true;
	var user_rname=document.getElementById("user_rname").value;
	var SubmitNews_ActionPlace=document.getElementById("SubmitNews_ActionPlace").value;
	var SubmitNews_Title=document.getElementById("SubmitNews_Title").value;
	var SubmitNews_Cotent=document.getElementById("SubmitNews_Cotent").value;
	var SubmitNews_Tel=document.getElementById("SubmitNews_Tel").value;
	var SubmitNews_yzm=document.getElementById("SubmitNews_yzm").value;
	var SubmitNews_zyzm=document.getElementById("SubmitNews_zyzm").value;
	for(i;i<=4;i++){
		document.all("body_main_form_div"+i).style.display="none";
		}
	if(user_rname.length<2 || user_rname.length>16){
		document.all("body_main_form_div0").style.display="";
		document.all("body_main_form_div0").className="border_red";
		returnvale=false;
		}
	if(SubmitNews_Title.length<7 || SubmitNews_Title.length>20){
		document.all("body_main_form_div2").style.display="";
		document.all("body_main_form_div2").className="border_red";
		returnvale=false;
		}
	if(SubmitNews_ActionPlace.length<4 || SubmitNews_ActionPlace.length>40){
		document.all("body_main_form_div3").style.display="";
		document.all("body_main_form_div3").className="border_red";
		returnvale=false;
		}
	if(SubmitNews_Cotent.length==""){
		returnvale=false;
		}
	if(SubmitNews_Tel.length<8 || SubmitNews_Tel.length>15){
		document.all("body_main_form_div4").style.display="";
		document.all("body_main_form_div4").className="border_red";
		returnvale=false;
		}
	if(SubmitNews_yzm != SubmitNews_zyzm){
		document.all("body_main_form_div5").style.display="";
		document.all("body_main_form_div5").className="border_red";
		returnvale=false;
		}

	return returnvale;
}

function form_change(){
	var returnvale=true;
	var i=0;
	var zhcn = /^[\u4e00-\u9fa5]+$/i; 
	var user_rname=document.getElementById("user_rname").value;
	var user_pword=document.getElementById("user_pword").value;
	var user_address=document.getElementById("user_address").value;
	var user_code=document.getElementById("user_code").value;
	var user_tel=document.getElementById("user_tel").value;
	var user_yzm=document.getElementById("user_yzm").value;
	var user_zyzm=document.getElementById("user_zyzm").value;
		
	if(!zhcn.test(user_rname) || user_rname.length<=1){
		document.all("body_main_form_change_div0").style.display="";
		document.all("body_main_form_change_div0").className="border_red";
		returnvale=false;
	}

	if(user_pword.length<6 || user_pword.length>16){
		document.all("body_main_form_change_div2").style.display="";
		document.all("body_main_form_change_div2").className="border_red";
		returnvale=false;
	}

	if(user_address.length<5){
		document.all("body_main_form_change_div4").style.display="";
		document.all("body_main_form_change_div4").className="border_red";
		returnvale=false;
	}

	if(user_code.length != 6){
		document.all("body_main_form_change_div5").style.display="";
		document.all("body_main_form_change_div5").className="border_red";
		returnvale=false;
	}
		
	if(user_tel.length <= 8 || user_tel.length >=14){
		document.all("body_main_form_change_div6").style.display="";
		document.all("body_main_form_change_div6").className="border_red";
		returnvale=false;
	}

	if(user_yzm=="" || user_yzm != user_zyzm){
		document.all("body_main_form_change_div7").style.display="";
		document.all("body_main_form_change_div7").className="border_red";
		returnvale=false;
	}


	return returnvale;
}

function form_comment(){
	var returnvale=true;
	var context=document.getElementById("Context").value;
	var user_yzm=document.getElementById("user_yzm").value;
	var user_zyzm=document.getElementById("user_zyzm").value;

	if(context.length<6 || context=="文明上网，理性发言"){
		document.getElementById("Context").value="";
		alert("评论内容为空或者内容太过于简单");
		returnvale=false;
		}
	if(user_yzm=="" || user_yzm != user_zyzm){
		alert("验证码不正确");
		returnvale=false;
		}
	return returnvale;
}
