//去左空格;
function ltrim(s){
 return s.replace(/^(\s*| *)/, "");
}
//去右空格;
function rtrim(s){
 return s.replace(/(\s*| *)$/, "");
}
//去左右空格;
function trim(s){
 return ltrim(rtrim(s));
} 

/* 创建群组第一步 */
function createGroup(permission,grouptype){
	$("#main").fadeOut('slow',function(){
		$("#createGroupH1").html("申请创建"+grouptype+",创建后,你就是酋长!");
		$("#permission").val(permission);
		$("#createGroupStep2").fadeIn();
 	});
}
/* 创建群组的验证 */
function validCreateGroup(paramtype){
	paramval = $("form[name='lzform'] input[name="+paramtype+"]").val();
	paramval = $.trim(paramval);
	if(paramval.length<1){
		$("form[name='lzform'] input[name="+paramtype+"]").focus();
		$("#"+paramtype+"Valid").html("<span style=\"font-size:14px;color:red;\">不能为空</span>");
		$("#"+paramtype+"Valid").show();
	}else{
		/*进行Ajax验证*/
		$.ajax({
			type:"POST",
			url:"/group/group.php",
			data:"act=valid&paramtype="+paramtype+"&paramval="+paramval,
			beforeSend:function(){$("#"+paramtype+"Valid").show();$("#"+paramtype+"Valid").html("<img src=\"/images/group/loader_shor_green.gif\">");},
			success:function(msg){
				//alert(msg);
				if(msg=='exist'){
					status = "<span style=\"font-size:14px;color:red;\">此名称已被占用</span>";
				}else if(msg=='empty'){
					status = "<span style=\"font-size:14px;color:red;\">不能为空</span>";
				}else{
					status = "<span style=\"font-size:14px;color:blue;\">验证通过</span>";
				}
				$("#"+paramtype+"Valid").html(status);
				$("#"+paramtype+"Valid").show();
			}
		});
	}
}
/* 验证别名 */
function validGroupAlias(paramtype,groupid){
	paramval = $("form[name='lzform'] input[name="+paramtype+"]").val();
	paramval = $.trim(paramval);
	if(paramval.length<1){
		$("form[name='lzform'] input[name="+paramtype+"]").focus();
		$("#"+paramtype+"Valid").html("<span style=\"font-size:14px;color:red;\">不能为空</span>");
		$("#"+paramtype+"Valid").show();
	}else{
		/*进行Ajax验证*/
		$.ajax({
			type:"POST",
			url:"/group/group.php",
			data:"act=validAlias&groupid="+groupid+"&paramval="+paramval,
			beforeSend:function(){$("#"+paramtype+"Valid").show();$("#"+paramtype+"Valid").html("<img src=\"/images/group/loader_shor_green.gif\">");},
			success:function(msg){
				if(msg=='exist'){
					status = "<span style=\"font-size:14px;color:red;\">此名称已被占用</span>";
				}else if(msg=='empty'){
					status = "<span style=\"font-size:14px;color:red;\">不能为空或长度不符</span>";
				}else if(msg=='false'){
					status = "<span style=\"font-size:14px;color:red;\">包含非法字符</span>";
				}else if(msg=='exist'){
					status = "<span style=\"font-size:14px;color:red;\">名字已被占用</span>";
				}else if(msg=='nochange'){
					status = "";
				}else{
					status = "<span style=\"font-size:14px;color:blue;\">验证通过</span>";
				}
				$("#"+paramtype+"Valid").html(status);
				$("#"+paramtype+"Valid").show();
			}
		});
	}
}
/* 删除回复 */
function delPost(groupid,topicid,postid){
	var cons = confirm('确定删除吗?');
	if(cons){
		$.get('/group/post.php',{act:'del',groupid:groupid,topicid:topicid,postid:postid},function(data){
			/* window.location.reload(); */
			$("#comment_"+postid).fadeOut(600);
		});
	}
}
/* 置顶话题 */
function sticky(groupid,topicid,sticky){
	$.get('/group/topic.php',{act:'sticky',groupid:groupid,topicid:topicid,sticky:sticky},function(data){
		window.location.href='/group/view.php?groupid='+groupid;
	});
}
/* 删除话题 */
function delTopic(groupid,topicid){
	var cons = confirm('确定删除吗?');
	if(cons){
		$.get('/group/topic.php',{act:'del',groupid:groupid,topicid:topicid},function(data){
			window.location.href='/group/view.php?groupid='+groupid;
		});
	}
}
/* 加入群组 */
function joinGroup(groupid){
	showInfo="我是这个部落的村民 <a style=\"margin-left:6px;\" href=\"#exit\" class=\"j a_confirm_link\" title=\"退出部落\">&gt;退出部落</a>";
	$.ajax({
		type:"POST",url:"/group/view.php",data:"act=join&groupid="+groupid,beforeSend:function(){$("#joinBeforeShow").html("<img src=\"/images/group/loader_shor_green.gif\">");},success:function(msg){$("#joinAfterShow").html(showInfo);$("#joinBeforeShow").hide();}
	});
}