function create(str){
	$("#creates").attr('disabled',true);
    var present = encodeURIComponent($("#present").val());
	if($("#verify").length>0){
		var verify = $("#verify").val();}
	else{verify = "0";}
	$.ajax({
		   type: "post", 
		   url : "create.php?action=submit",
		   dataType: "html",
		   data: 'barname='+str+'&present='+present+'&verify='+verify,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   $("#creates").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，请将信息填写完整</span>';}
			   else if(data==1){
				   $("#creates").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，验证码错误</span>';}
               else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 创建成功</span>';
				   window.location.href = "create.php?barname="+str;
				   return false;}
           }
    });
}
function addsbm(str){
	var addsm = $("#addsm").val();
	$.ajax({
		   type: "post", 
		   url : "bar_manage.php?bid="+str+"&action=addsm",
		   dataType: "html",
		   data: 'addsm='+addsm,
		   timeout: 30000,
		   success: function(data){
			   if($("#addsm").val()==""){
				   sAlert("对不起，请将信息填写完整");}
			   else if(data==0){
				   sAlert("对不起，该用户不存在");}
			   else if(data==1){
				   sAlert("对不起，该用户已是小吧主");}
			   else if(data==3){
				   sAlert("对不起，小吧主已达到最高人数");}
               else if(data==2){
				   window.location.href = "bar_manage.php?bid="+str+"&action=basic";
				   return false;}
           }
    });
}
function addfbb(str){
	var addfb = $("#addfb").val();
	$.ajax({
		   type: "post", 
		   url : "bar_manage.php?bid="+str+"&action=addfb",
		   dataType: "html",
		   data: 'addfb='+addfb,
		   timeout: 30000,
		   success: function(data){
			   if($("#addfb").val()==""){
				   sAlert("对不起，请将信息填写完整");}
			   else if(data==0){
				   sAlert("对不起，该贴吧不存在");}
			   else if(data==1){
				   sAlert("对不起，不能添加本贴吧");}
			   else if(data==2){
				   sAlert("对不起，该贴吧已是友情贴吧");}
               else if(data==3){
				   window.location.href = "bar_manage.php?bid="+str+"&action=basic";
				   return false;}
           }
    });
}
function addpc(str){
	var addpc = encodeURIComponent($("#addpc").val());
	$.ajax({
		   type: "post", 
		   url : "bar_manage.php?bid="+str+"&action=addpc",
		   dataType: "html",
		   data: 'addpc='+addpc,
		   timeout: 30000,
		   success: function(data){
			   if($("#addpc").val()==""){
				   sAlert("对不起，贴子分类不能为空");}
               else if(data==1){
				   window.location.href = "bar_manage.php?bid="+str+"&action=postclass";
				   return false;}
           }
    });
}
function loginjs(url){
	var username = encodeURIComponent($("#username").val());
	var passwd = $("#passwd").val();
	var long = "0";
	if($("#long").attr("checked")==true){
	    long = "1";}
	var url = url;
	url = url.replace("=and=","&");
	var verify ="0";
	if($("#verify").length>0){
	     verify = $("#verify").val();}
	$.ajax({
		   type: "post", 
		   url : "login.php?action=submit",
		   dataType: "html",
		   data: 'username='+username+'&passwd='+passwd+'&verify='+verify+'&long='+long,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">&nbsp;&nbsp;* ID不存在、未被审核或已被关闭</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">&nbsp;&nbsp;* 对不起，请将信息填写完整</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">&nbsp;&nbsp;* 对不起，验证码错误</span>';}
			   else if(data==3){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">&nbsp;&nbsp;* 对不起，用户名或密码错误</span>';}
               else if(data==4){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">&nbsp;&nbsp;* 登陆成功</span>';				   
				   window.location.href = url;
				   return false;}
           }
    });
}
function lostpwjs(str){
	var username = $("#username").text();
	if($("#answer").length>0){
		var answer = encodeURIComponent($("#answer").val());}
	else{var answer ="0";}
	if($("#safemail").length>0){
		var safemail = $("#safemail").val();}
	else{var safemail ="0";}
	var passwd = $("#passwd").val();
	var passwdy = $("#passwdy").val();
	if($("#verify").length>0){
	    var verify = $("#verify").val();}
	else{var verify ="0";}
	$.ajax({
		   type: "post", 
		   url : "lostpw.php?action=submit&way="+str+"&un="+username,
		   dataType: "html",
		   data: 'answer='+answer+'&safemail='+safemail+'&passwd='+passwd+'&passwdy='+passwdy+'&verify='+verify,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码保护答案错误</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，安全邮箱错误</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码长度不符合系统要求</span>';}
			   else if(data==3){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，两次输入的密码不同</span>';}
			   else if(data==4){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，验证码错误</span>';}
               else if(data==5){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 操作成功</span>';
				   window.location.href = "login.php?action=basic";
				   return false;}
           }
    });
}
function regjs(){
	var username = encodeURIComponent($("#username").val());
	var passwd = $("#passwd").val();
	var passwdy = $("#passwdy").val();
	var email = $("#email").val();
	var safemail = $("#safemail").val();
	var question = encodeURIComponent($("#question").val());
	var answer = encodeURIComponent($("#answer").val());
	if($("#verify").length>0){
		var verify = $("#verify").val();}
	else{var verify ="0";}
	$.ajax({
		   type: "post", 
		   url : "reg.php?reg=submit",
		   dataType: "html",
		   data: 'username='+username+'&passwd='+passwd+'&passwdy='+passwdy+'&email='+email+'&safemail='+safemail+'&question='+question+'&answer='+answer+'&verify='+verify,
		   timeout: 100000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，用户名包含系统不允许的字符</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，请将信息填写完整</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，用户名长度不符合要求</span>';}
			   else if(data==3){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，用户名已被占用</span>';}
			   else if(data==4){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码长度不符合要求</span>';}
               else if(data==5){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，二次输入的密码不同</span>';}
			   else if(data==6){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，请输入正确的邮箱地址</span>';}
			   else if(data==7){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，验证码错误</span>';}
               else if(data==8){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 注册成功</span>';
				   window.location.href = "user.php?action=basic";
				   return false;}
			   else if(data==9){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 注册成功,请等待审核</span>';
				   window.location.href = "index.php";
				   return false;}
           }
    });
}
function postjs(str,str1,str2){
	$("#posts").attr('disabled',true);
	var theme = encodeURIComponent($("#theme").val());
	var content = encodeURIComponent($("#content").val());
	var namexs = $('input[name=namexs]:checked').val();
	var file = $("#file").val();
	if($("#verify").length>0){
	    var verify = $("#verify").val();
	    var verifyopen ="1";	
	}
	else{
		var verify ="0";
		var verifyopen ="0";
	}
	$.ajax({
		   type: "post", 
		   url : "post.php?action="+str+"&belong="+str1+'&bid='+str2,
		   dataType: "html",
		   data: 'theme='+theme+'&content='+content+'&file='+file+'&namexs='+namexs+'&verify='+verify+'&verifyopen='+verifyopen,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   $("#posts").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您目前被禁止在本吧发贴</span>';}
			   else if(data==1){
				   $("#posts").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您发布的文章含有系统禁止的内容</span>';}
			   else if(data==2){
				   $("#posts").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您的主题长度不符合系统要求</span>';}
			   else if(data==3){
				   $("#posts").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您的内容长度不符合系统要求</span>';}
			   else if(data==4){
				   $("#posts").attr('disabled',false);
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，验证码错误</span>';}
               else if(data==5){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 回贴发布成功</span>';
				   window.location.href = "read.php?id="+str1;
				   return false;}
			   else if(data==6){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 主题发布成功</span>';
				   window.location.href = "list.php?bid="+str2;
				   return false;}
			   else if(data==7){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 回贴发布成功，审核后显示</span>';
				   window.location.href = "error.php?id=10&last=read.php?id="+str1;
				   return false;}
			   else if(data==8){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 主题发布成功，审核后显示</span>';
				   window.location.href = "error.php?id=10&last=list.php?bid="+str2;
				   return false;}
           }
    });
}
function votejs(str){
	var theme = encodeURIComponent($("#theme").val());
	var content = encodeURIComponent($("#content").val());
	var type = $("#type").val();
	var state = $("#state").val();
	var qita = $("#qita").val();
	var zdhf = $("#zdhf").val();
	var url = 'theme='+theme+'&content='+content+'&type='+type+'&state='+state+'&num='+$("#optionnum").val()+'&qita='+qita+'&zdhf='+zdhf;
	var i=1;
	var option=new Array(); 
    for (i=1;i<=$("#optionnum").val();i++)
	{
	  option[i] = encodeURIComponent($("#option"+i).val());
	  url = url+"&option"+i+"="+option[i] 
	}
	$.ajax({
		   type: "post", 
		   url : "vote.php?action=submit&bid="+str,
		   dataType: "html",
		   data: url,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，选项至少填写2项</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您发布的文章含有系统禁止的内容</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您的主题长度不符合系统要求</span>';}
			   else if(data==3){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，您的内容长度不符合系统要求</span>';}
			   else if(data==4){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 投票发布成功</span>';
				   window.location.href = "list.php?bid="+str;
				   return false;}
			   else if(data==5){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 投票发布成功，审核后显示</span>';
				   window.location.href = "error.php?id=10&last=list.php?bid="+str;
				   return false;}
           }
    });
}
function votejss(str,str1,str2){
	var qita='';
	if(str2!=2){
		var votec=Number($("#votec").val())-1;
		if(str1==0){
	  		var option = $('input[name="options"]:checked').val();
	  		optionrs=$('input[name="options"]:checked').val();
	  	}
		else{
        	var option='';
			var optionrs='';
        	$('input[name="options"]:checked').each(function(){
		    if(option=='')
                option+=$(this).val();
		    else
			    option+='|'+$(this).val();
			optionrs=$(this).val();
        	});
    	}
		if(str2==1 && optionrs==votec){
	  		sAlert('请输入相关内容：<br><textarea id="contentqt" name="contentqt" cols="50" rows="3"></textarea><input type=hidden value="'+option+'" id="option" name="option"><br><div id="tishi"></div><br><input type="button" onclick="votejss('+str+','+str1+',2)"  value="确认投票" />');
	  		return false;
		}
	}
	else{
		option=$("#option").val();
		qita=encodeURIComponent($("#contentqt").val());
		if(qita==""){
			document.getElementById("tishi").innerHTML = '<span style="color:#FF0000">* 对不起，内容不能为空</span>';
			return false;
		}
	}
	$.ajax({
		   type: "post", 
		   url : "vote.php?action=vote&bid="+str,
		   dataType: "html",
		   data: 'option='+option+'&qita='+qita,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("warings").innerHTML = '<span style="color:#FF0000">* 对不起，请选择选项</span>';}
			   else if(data==1){
				   document.getElementById("warings").innerHTML = '<span style="color:#FF0000">* 对不起，本投票限制为登陆投票</span>';}
			   else if(data==2){
				   document.getElementById("warings").innerHTML = '<span style="color:#FF0000">* 对不起，您已成功投票</span>';}
			   else if(data==3){
				   document.getElementById("warings").innerHTML = '<span style="color:#00FF00">* 投票成功</span>';
				   window.location.href = "read.php?id="+str;}
           }
    });
}
function userjs(){
	var passwd = $("#passwd").val();
	var picture = encodeURIComponent($("#picture").val());
	var sex = $("#sex").val();
	var qq = $("#qq").val();
	var birthday = $("#birthday").val();
	var zodiac = $("#zodiac").val();
	var school = $("#school").val();
	var mobile = $("#mobile").val();
	var age = $("#age").val();
	var userfrom = $("#userfrom").val();
	var email = $("#email").val();
	var blood = $("#blood").val();
	var constellation = $("#constellation").val();
	var profession = $("#profession").val();
	var phone = $("#phone").val();
	var istyle = $("#istyle").val();
	var userfriendp = $("#userfriendp").val();
	var signature = encodeURIComponent($("#signature").val());
	var introduction = encodeURIComponent($("#introduction").val());
	$.ajax({
		   type: "post", 
		   url : "user.php?action=basicsubmit",
		   dataType: "html",
		   data: 'passwd='+passwd+'&picture='+picture+'&sex='+sex+'&qq='+qq+'&birthday='+birthday+'&zodiac='+zodiac+'&school='+school+'&mobile='+mobile+'&age='+age+'&userfrom='+userfrom+'&email='+email+'&blood='+blood+'&constellation='+constellation+'&profession='+profession+'&phone='+phone+'&istyle='+istyle+'&userfriendp='+userfriendp+'&signature='+signature+'&introduction='+introduction,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码错误</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，个性签名长度超过限制</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 操作成功</span>';
				   window.location.href = "user.php?action=basic";
				   return false;}
           }
    });
}
function usersjs(){
	var passwd = $("#passwd").val();
	var safemail = encodeURIComponent($("#safemail").val());
	var answer = encodeURIComponent($("#answer").val());
	var new_passwd = $("#new_passwd").val();
	var new_passwdy = $("#new_passwdy").val();
	var new_safemail = $("#new_safemail").val();
	var new_question = encodeURIComponent($("#new_question").val());
	var new_answer = encodeURIComponent($("#new_answer").val());
	$.ajax({
		   type: "post", 
		   url : "user.php?action=safetysubmit",
		   dataType: "html",
		   data: 'passwd='+passwd+'&safemail='+safemail+'&answer='+answer+'&new_passwd='+new_passwd+'&new_passwdy='+new_passwdy+'&new_safemail='+new_safemail+'&new_question='+new_question+'&new_answer='+new_answer,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码错误</span>';}
			   else if(data==1){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，安全邮箱或密保答案错误</span>';}
			   else if(data==2){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，密码长度不符合系统要求</span>';}
			   else if(data==3){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，两次输入的密码不相同</span>';}
			   else if(data==4){
				   document.getElementById("waring").innerHTML = '<span style="color:#FF0000">* 对不起，请输入正确邮箱</span>';}
			   else if(data==5){
				   document.getElementById("waring").innerHTML = '<span style="color:#00FF00">* 操作成功</span>';
				   window.location.href = "user.php?action=safety";
				   return false;}
           }
    });
}
function qdtj(){
	var qdtb = encodeURIComponent($("#qdtb").val());
	var qdss = encodeURIComponent($("#qdss").val());
	$.ajax({
		   type: "post", 
		   url : "user.php?action=qiandao",
		   dataType: "html",
		   data: 'qdtb='+qdtb+'&qdss='+qdss,
		   timeout: 30000,
		   success: function(data){
			   if(data==0){
				   document.getElementById("qdxz").style.display = 'block';
				   document.getElementById("qdxz").innerHTML = '<span style="color:#FF0000">* 内容不符合要求或未填写</span>';}
			   else if(data==2){
				   document.getElementById("qdxz").style.display = 'block';
				   document.getElementById("qdxz").innerHTML = '<span style="color:#FF0000">* 内容请不要超过140字</span>';}
			   else if(data==1){
				   document.getElementById("qdxz").style.display = 'block';
				   document.getElementById("qdxz").innerHTML = '<span style="color:#00FF00">* 签到成功</span>';
				   window.location.href = "index.php";
				   return false;}
           }
    });
}