/*
'=====================================================================
' Module Name:
' File name: group.js
' Author: william.lu
' Project : my_bebo
' Copyright (c) all rights reserved by saywo.com Co., LTD.
' Create on 2009/08/19
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: 
'
'*********************************************************************
*/


/**  定义juuyou.group命名空间  **/
juuyou.group = {};

/**  定义juuyou.group.prototype命名空间  **/
juuyou.group.prototype = {};
juuyou.group.prototype.blTemp = false;
juuyou.group.prototype.holdVal = ",harvard,coca-cola,citigroup,google,benz,wal-mart,microsoft,mcdonalds,ibm,apple,ge,intel,wallstreet,marlboro,hp,time,fox,youtube,thomsonreuters,nationalgeographic,ap,disney,pepsi,nytimes,bmw,yahoo,fortune,mit,hbo,olympic,dell,nokia,amazon,americanexpress,nobelprize,nobel,bloomberg,oracle,louisvuitton,cisco,oscar,stanford,morganstanley,morgan,nike,science,ford,motor,ebay,exxon,mobil,hsbc,facebook,samsung,sap,sony,nature,nestle,budweiser,wikipedia,wiki,gillette,app,post,washington,university,cam,chinamobile,mobile,china,korea,japan,usa,rusia,wrigley,france,italia,cctv,smg,oxford,canon,att,adidas,icrc,royal,philips,dior,volkswagen,carlsberg,shell,boeing,toyota,newsweek,rolex,kodak,loreal,starbucks,xerox,pizzahut,pizz,accenture,goldman,gold,man,girl,love,honda,cool,panasonic,good,nice,msn,saywo,ikea,haan,foundation,sothebys,gucci,chanel,motorola,hnm,levis,news,corp,newscorp,dream,works,dreamworks,haier,mtv,standard,poors,standardpoors,kfc,avon,economist,virgin,porsche,hilton,gap,heinz,read,reader,myspace,christies,sun,ups,satch,audi,lego,kao,7eleven,7-eleven,vogue,absolut,absolutvodka,vodka,diesel,benetton,lenovo,adecco,johnson,jnj,bnq,heineken,guggenheim,dhl,help,lomo,siemens,merck,ideo,rand,foster,mastercard,oma,harley-davidson,kleenex,hennessy,kraft,tiffany,duracell,zara,smirnoff,nintendo,ftv,prada,nivea,fedex,hermes,johnniewalker,jackdaniels,bbc,moet,nasdaq,barbie,burgerking,king,bacardi,carrefour,forbes,becks,total,axa,ntt,ing,deutsche,aig,hitachi,mckesson,unilever,assicurazioni,abc,conocophilips,generali,nissan,pfizer,danone,peugeot,metro,cartire,ubs,bnp,hyundai,vodafone,nbc,fiat,france,telecom,renault,vacheron,tesco,icbc,state,sgcc,versace,business,week,businessweek,lufthansa,toshiba,pemex,tata,dupont,nippon,life,viacom,chevrolet,kelloggs,omega,nec,alcatel,bat,bhp,polo,colgate,electrolux,cbs,princeton,epson,bnb,visa,ericsson,boc,america,marriott,berkeley,edu,gov,police,pwc,kpmg,ricoh,playboy,mckinsey,volvo,fujitsu,allianz,iwc,yale,bearing,mitsubishi,zurich,abb,verizon,service,standardchartered,standard,rwe,deutsche,sharp,juilliard,bandaid,band,emerson,mazda,dow,fortis,deloitte,patek,mars,piaget,kroger,credit-suisse,roche,suzuki,telstra,olympus,accor,maersk,jaguar,united,utc,cadbury,berkshirehathaway,wyeth,baker,lexus,scjohnson,sei,computer,carlson,redbull,cnn,nyse,esteelauder,timewarner,sas,changhong,autodes,toy,toys,ual,metlife,basf,sktelecom,lgtelecom,girard-perregaux,bcg,audemarspigeut,discovery,hersheys,dassault,rio,riotinto,thales,bridgestone,albertsons,lux,jcpenney,daysinn,akzo,akzonobel,suez,remymartin,aegon,triumph,ports,rbs,safeway,edf,bms,cardinal,health,stora,xoxo,starwood,saint-gobain,singaporeair,freshfields,mofo,ogilvy,goodyear,gold,juji,fhi,crec,admworld,columbia,latimes,guerlain,cibc,jwt,ingrammicro,british,walgreens,omnicom,bertelsmann,ponds,isuzu,pulitzer,ito-yokado,secondlife,sysco,chinapetroleum,credit-agricole,hyatt,sixcontinentshotels,skype,conagra,novartis,moodys,lilly,barclays,michelin,vaseline,tyson,kirin,targen,costco,international,paper,company,delphi,abnamro,holiday-inn,bmo,mccann,sas,burberry,bvlgari,bubaiworld,homedepot,comcast,emi,olay,cmb,cmbchina,martell,dunhill,lacoste,orange,sprint,wamu,altria,fujifilm,valero,capital,capitalon,anadarko,delta,sbc,whirlpool,linklaters,abbott,temasek,lehman,ppr,auchan,marathon,johnson,bunge,times,aeon,weyerhaeuse,muji,anglo,mgm,lowes,dentsu,upi,tenet,mobil,freddied,mac,oryx,airchina,air,telefonica,hca,sinopec,usnews,kerr-mcgee,chevron,bouygues,usatoday,ferrai,laposte,heidelberg,hbos,giorgioarmani,armani,givenchy,auto,zipcar,alstom,schwab,weston,chicago,humana,lse,ise,pacific,pacificcare,dove,siegel,msf,bankofny,mscgva,chivas,soniarykiel,caa,cnp,resona,flextronics,bausch,saudi,bain,btm,msu,valentino,skanska,diageo,yslonline,nab,nba,lancome,elizabetharden,apache,kimberly,puma,uhc,universal,music,group,universalmusic,philip,lee,kim,kin,anheuser-busch,tyco,zippo,nikon,tsinghua,beijing,sex,oral,fuck,louisjin,jinguolong,hujintao,jiangzhemin,jinzeyu,guolong,wow,snda,ncsoft,nexon,tencent,the9,9you,kingsoft,neteasy,netdragon,nea,bluerun,idg,gobi,sig,nlightvc,kpcb,profile,movie,photo,video,book,music,blog,food,interest,event,";

/**  页面group列表排序条件更换  **/
juuyou.group.changeIndexOrder = function(){
	var strGroupOrderIndex = $("#sel_group_index_order").val();
	window.location = "index.php?o=" + strGroupOrderIndex;
}

/**  页面group列表搜索  **/
juuyou.group.groupQuickSearch = function(){
	var strGroupSearchVal = $.trim($("#frm_group_quick_search #hid_group_quick_search").val());
/*	if(strGroupSearchVal == ""){
		$("#frm_group_quick_search #hid_group_quick_search").focus();
		return false;
	}*/
	
	$("#frm_group_quick_search").submit();
}


/**  创建group隐私控制  **/
juuyou.group.iniGroupPrivate = function(){
	var strPrivateVal = juuyou.common.getRadioBtnValue("rd_private");
	if(strPrivateVal == "1"){
		$("#frm_group_create #div_private_2").hide();
	}else{
		$("#frm_group_create #div_private_2").show();
		$("#frm_group_create #cbx_private_2_1").attr("checked", true);
		$("#frm_group_create #cbx_private_2_2").attr("checked", true);
	}
}

/**  group创建检查  **/
juuyou.group.checkCreateGroup = function(){

}

/**  验证GroupName是否重复  **/
juuyou.group.ckGroupName = function(){
	var strGroupName = $.trim($("#frm_group_create #txt_group_name").val());
	
	$("#frm_group_create #group_name_false").hide();
	$("#frm_group_create #group_name_true").hide();

	if(strGroupName.length > 80 || strGroupName == ""){
		$("#frm_group_create #group_name_false").show();
		$("#frm_group_create #group_name_true").hide();
		$("#frm_group_create #hid_check_group_name_flag").val("0");
		return;
	}

	if(strGroupNameForEdit && strGroupNameForEdit != strGroupName){
		$.ajax({
	 		type:"POST",
			url:"../json/checkGroupName.php",
			async:false,
			data:"group_name=" + strGroupName,
			success:function(data){
				if($.trim(data) != juuyou.common.json.success){
					$("#frm_group_create #group_name_false").show();
					$("#frm_group_create #group_name_true").hide();
					$("#frm_group_create #hid_check_group_name_flag").val("0");
				}else{
					$("#frm_group_create #group_name_false").hide();
					$("#frm_group_create #group_name_true").show();
					$("#frm_group_create #hid_check_group_name_flag").val("1");
				}
			}
		});
	}else{
		$("#frm_group_create #group_name_true").show();
		$("#frm_group_create #group_name_false").hide();
		$("#frm_group_create #hid_check_group_name_flag").val("1");
	}

	return;  	
}

/**  验证是否保留字  **/
juuyou.group.isHoldGroupId = function(val){
	val = ","+val+",";
	var s = juuyou.group.prototype.holdVal.indexOf(val);
	if(s == -1){
		return false;
	}else{
		return true;
	}
}


/**  验证GroupId是否重复  **/
juuyou.group.ckGroupId = function(){
	var strGroupId = $.trim($("#frm_group_create #txt_group_id").val());

	if(!juuyou.common.isAlphaNumeric(strGroupId) || juuyou.group.isHoldGroupId(strGroupId)){
		$("#frm_group_create #group_id_false").show();
		$("#frm_group_create #group_id_true").hide();
		$("#frm_group_create #hid_check_group_id_flag").val("0");
		//alert("请使用英文字母、数字和下划线");
		return;
	}
	
	$("#frm_group_create #group_id_false").hide();
	$("#frm_group_create #group_id_true").hide();

	if(strGroupId.length < 3 || strGroupId.length > 20 || strGroupId == ""){
		$("#frm_group_create #group_id_false").show();
		$("#frm_group_create #group_id_true").hide();
		$("#frm_group_create #hid_check_group_id_flag").val("0");
		return;
	}
	
	
	$.ajax({
 		type:"POST",
		url:"../json/checkGroupId.php",
		async:false,
		data:"group_id=" + strGroupId,
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
				$("#frm_group_create #group_id_false").show();
				$("#frm_group_create #group_id_true").hide();
				$("#frm_group_create #hid_check_group_id_flag").val("0");
			}else{
				$("#frm_group_create #group_id_false").hide();
				$("#frm_group_create #group_id_true").show();
				$("#frm_group_create #hid_check_group_id_flag").val("1");
			}
		}
	});

	return;  	
}


/**  Group创建提交  **/
juuyou.group.checkCreateGroup = function(){
	var strGroupId = $("#frm_group_create #txt_group_id").val();
	var strGroupName = $("#frm_group_create #txt_group_name").val();
	
	if(!juuyou.common.isAlphaNumeric(strGroupId) || strGroupId.length < 3 || strGroupId.length > 20 || strGroupId == ""){
		$("#frm_group_create #group_id_false").show();
		$("#frm_group_create #group_id_true").hide();
		$("#frm_group_create #hid_check_group_id_flag").val("0");
		//alert("请使用英文字母、数字和下划线");
		return false;
	}

	if(strGroupName.length > 80 || strGroupName == ""){
		$("#frm_group_create #group_name_false").show();
		$("#frm_group_create #group_name_true").hide();
		$("#frm_group_create #hid_check_group_name_flag").val("0");
		return false;
	}
	
	if($("#frm_group_create #hid_check_group_id_flag").val() != "1"){
		alert("请填写正确的群链接ID");
		return false;
	}
	
	if($("#frm_group_create #hid_check_group_name_flag").val() != "1"){
		alert("请填写正确的群名字");
		return false;
	}

	var strGroupDescription = $("#frm_group_create #txt_group_description").val();
	if(strGroupDescription.length > 450){
		alert("群描述最多500个字符");
		return false;
	}
	
	var strGroupWebUrl = $("#frm_group_create #txt_group_web_url").val();
	if(strGroupWebUrl.length > 250){
		alert("群网址最多250个字符");
		return false;
	}
	
	var strGroupCity = $("#frm_group_create #txt_group_city").val();
	if(strGroupCity.length > 25){
		alert("群位置最多25个字符");
		return false;
	}	
	
	return true;
}

/**  Group编辑提交  **/
juuyou.group.checkCreateGroup = function(){
	var strGroupName = $("#frm_group_create #txt_group_name").val();

	if(strGroupName.length > 80 || strGroupName == ""){
		$("#frm_group_create #group_name_false").show();
		$("#frm_group_create #group_name_true").hide();
		$("#frm_group_create #hid_check_group_name_flag").val("0");
		return false;
	}
	
	if($("#frm_group_create #hid_check_group_name_flag").val() != "1"){
		alert("请填写正确的群名字");
		return false;
	}

	var strGroupDescription = $("#frm_group_create #txt_group_description").val();
	if(strGroupDescription.length > 450){
		alert("群描述最多500个字符");
		return false;
	}
	
	var strGroupWebUrl = $("#frm_group_create #txt_group_web_url").val();
	if(strGroupWebUrl.length > 250){
		alert("群网址最多250个字符");
		return false;
	}
	
	var strGroupCity = $("#frm_group_create #txt_group_city").val();
	if(strGroupCity.length > 25){
		alert("群位置最多25个字符");
		return false;
	}	
	
	return true;
}


/**  复制输入框内容保存到剪贴板  **/
juuyou.group.copyToClipboard = function(){
	if(juuyou.common.copyToClipboard($("#txt_group_invite_link").val())){
		alert("复制成功");
	}else{
		alert("复制失败");
	}
}

/**  好友CheckBox全部选中和取消  **/
juuyou.group.selAllFriendCheckBox = function(objChb){
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbFriendsList)){
			if ("undefined" != typeof(document.all.chbFriendsList.length)){
				for (i=0; i<document.all.chbFriendsList.length; i++){
					if(!document.all.chbFriendsList[i].disabled){
						document.all.chbFriendsList[i].checked = objChb.checked;
					}
				}
			}else{
				document.all.chbFriendsList.checked = objChb.checked;
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbFriendsList"))){
			if ("undefined" != typeof(document.getElementsByName("chbFriendsList").length)){
				for (i=0; i<document.getElementsByName("chbFriendsList").length; i++){
					if(!document.getElementsByName("chbFriendsList")[i].disabled){
						document.getElementsByName("chbFriendsList")[i].checked = objChb.checked;
					}
				}
			}else{
				document.getElementsByName("chbFriendsList").checked = objChb.checked;
			}
		}
	}
}

/**  得到选中的好友ID  **/
juuyou.group.getAllFriendCheckedIds = function(){
	var strIds = "";
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbFriendsList)){
			if ("undefined" != typeof(document.all.chbFriendsList.length)){
				for (i=0; i<document.all.chbFriendsList.length; i++){
					if(document.all.chbFriendsList[i].checked){
						strIds += document.all.chbFriendsList[i].value + ",";
					}
				}
			}else{
				if(document.all.chbFriendsList.checked){
					strIds = document.all.chbFriendsList.value + ",";
				} 
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbFriendsList"))){
			if ("undefined" != typeof(document.getElementsByName("chbFriendsList").length)){
				for (i=0; i<document.getElementsByName("chbFriendsList").length; i++){
					if(document.getElementsByName("chbFriendsList")[i].checked){
						strIds += document.getElementsByName("chbFriendsList")[i].value + ",";
					}
				}
			}else{
				if(document.getElementsByName("chbFriendsList").checked){
					strIds = document.getElementsByName("chbFriendsList").value + ",";
				} 
			}
		}
	}
	if(strIds != ""){
		strIds = strIds.substring(0, strIds.length-1);
	}
	
	return strIds;
}

/** 邀请已注册好友 **/
juuyou.group.inviteRegistedFriend = function(){
	$(".j_invite_success").hide();
	$(".j_invite_failure").hide();

	var ids = juuyou.group.getAllFriendCheckedIds();
	if(ids == ""){
		alert("请选择您要提出申请的好友");
		return false;
	}
	
	$.ajax({
 		type:"POST",
		url:"../json/admin/inviteFriends.php",
		async:false,
		data: {
			ids: ids,
			gid: gid
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
				$(".j_invite_success").hide();
				$(".j_invite_failure").show();
			}else{
				$(".j_invite_success").show();
				$(".j_invite_failure").hide();
			}
		}
	});

	return true;	
}


/** 申请加入群组 **/
juuyou.group.applyJoinGroup = function(gid){
	if(gid == ""){
		return false;
	}

	
	$.ajax({
 		type:"POST",
		url:"../json/admin/applyJoinGroup.php",
		async:false,
		data: {
			gid: gid
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
			}else{
				$(".j_apply_join_group").hide();
				$(".j_apply_join_group_send").show();
			}
		}
	});

	return true;	

}

/** 接受邀请加入群组 **/
juuyou.group.inviteJoinGroupAccept = function(id){
	if(id == ""){
		return false;
	}

	
	$.ajax({
 		type:"POST",
		url:"../json/admin/inviteJoinGroupAccept.php",
		async:false,
		data: {
			id: id
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
			}else{
				$(".j_invite_join_group_accept").hide();
				$(".j_welcome").show();
				window.location.reload();
			}
		}
	});

	return true;	

}

/** 接受邀请加入群组 **/
juuyou.group.inviteJoinGroupRefuse = function(id){
	if(id == ""){
		return false;
	}

	
	$.ajax({
 		type:"POST",
		url:"../json/admin/inviteJoinGroupRefuse.php",
		async:false,
		data: {
			id: id
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
			}else{
				$(".j_invite_join_group_accept").hide();
			}
		}
	});

	return true;	

}

var intCkIdNum = 0;
var strCkIdNum = "";
/** 编辑公告板显示 **/
juuyou.group.editNoticFormShow = function(){
	$("#j_group_notice_edit").html($("#j_group_notice_edit_temp").html());
	
	$("#j_group_notice_title").hide();
	$("#j_group_notice_content").hide();
		
	$("#j_group_notice_edit").show();
	
	var strCkIdNum = "txtAreaContent" + intCkIdNum;
	intCkIdNum++;
	$("#j_group_notice_edit #txtAreaContent").attr("id", strCkIdNum);
	$("#j_group_notice_edit #"+strCkIdNum ).ckeditor();

}
/** 编辑公告板取消 **/
juuyou.group.editNoticFormCancel = function(){
	$("#j_group_notice_title").show();
	$("#j_group_notice_content").show();
		
	$("#j_group_notice_edit").html("");
}
/** 编辑公告板检查并提交 **/
juuyou.group.checkEditGroupNotice = function(){
	$("#j_group_notice_edit #frm1").submit();
}

/**  member列表搜索  **/
juuyou.group.memberQuickSearch = function(){
	var strMemberSearchVal = $.trim($("#frm_member_quick_search #txt_member_quick_search").val());
	if(strMemberSearchVal == ""){
		$("#frm_member_quick_search #txt_member_quick_search").focus();
		return false;
	}
	
	$("#frm_member_quick_search").submit();
}

/** 编辑讨论区显示 **/
juuyou.group.editDiscussFormShow = function(){
	$("#j_group_discuss_form_edit").html($("#j_group_discuss_form_edit_temp").html());	
	$("#j_group_discuss_form_edit").show();
}
/** 编辑讨论区显示取消 **/
juuyou.group.editDiscussFormShowCancel = function(){
	$("#j_group_discuss_form_edit").html("");
}
/** 编辑公告板检查并提交 **/
juuyou.group.checkEditDiscussFormShow = function(){
	$("#j_group_discuss_form_edit #frm2").submit();
}

/** 讨论检查并提交 **/
juuyou.group.checkDiscussAddForm = function(){
	var strDiscussTitle = $.trim($("#frm_discuss_add #txt_discuss_title").val());
	if(strDiscussTitle == ""){
		$("#frm_discuss_add #txt_discuss_title").focus();
		return false;
	}
	
	$("#frm_discuss_add").submit();
}

//初始化喜欢动作
$(document).ready(function(){
	$(".l_like").live("click", function(){	
		$.ajax({
	 		type:"POST",
			url:"../json/groupActiveLike.php",
			async:true,
			data: {
				aid: strActiveId,
				act: "like"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$(".j_like_span").hide();
					$(".j_likes").replaceWith(data);
				}
			}
		});
		return false;
	});
});

//group discuss saying提交
juuyou.group.checkDiscussSaying = function(){
	var strSaying = $("#frm_saying #txt_saying").val();
	if(strSaying.length > 300){
		alert("字符数最大不得超过300");
		return false;
	}
	
	$.ajax({
	 	type:"POST",
		url:"../json/groupSayingAdd.php",
		async:false,
		data: {
			aid: strActiveId,
			val: strSaying
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#frm_saying #txt_saying").val("");
				$("#j_saying_list").prepend(data);
				intSayingCnt = intSayingCnt + 1;
				$("#j_saying_count_span").html(intSayingCnt);
			}
		}
	});
}

//初始化group discuss saying删除
$(document).ready(function(){
	$(".j_group_discuss_saying_del").live("click", function(){	
		var objDl = $(this).parents("dl");
		var strSID = objDl.attr("sid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/groupSayingDelete.php",
			async:true,
			data: {
				sid: strSID,
				act: "delete"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objDl.hide();
					intSayingCnt = intSayingCnt - 1;
					$("#j_saying_count_span").html(intSayingCnt);
				}
			}
		});
		return false;
	});
});

//初始化group discuss saying关闭,打开回复
$(document).ready(function(){
	$("#j_group_discuss_saying_close").live("click", function(){
		var objDiv = $(this).parents("div");
		var objCloseP = $("#j_group_discuss_saying_close").parents("p");
		var objOpenP = $("#j_group_discuss_saying_open").parents("p");
		var strDID = objDiv.attr("did");
		
		$.ajax({
	 		type:"POST",
			url:"../json/admin/groupDiscussSayingCloseOpen.php",
			async:true,
			data: {
				did: strDID,
				act: "close"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$("#j_saying_form").hide();
					objCloseP.hide();
					objOpenP.show();
				}
			}
		});
		return false;
	});
	
	$("#j_group_discuss_saying_open").live("click", function(){	
		var objDiv = $(this).parents("div");
		var objCloseP = $("#j_group_discuss_saying_close").parents("p");
		var objOpenP = $("#j_group_discuss_saying_open").parents("p");
		var strDID = objDiv.attr("did");
		
		$.ajax({
	 		type:"POST",
			url:"../json/admin/groupDiscussSayingCloseOpen.php",
			async:true,
			data: {
				did: strDID,
				act: "open"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$("#j_saying_form").show();
					objOpenP.hide();
					objCloseP.show();
				}
			}
		});
		return false;
	});
});


/**  页面group discuss列表搜索  **/
juuyou.group.groupDiscussQuickSearch = function(){
	var strSearchVal = $.trim($("#frm_group_discuss_quick_search #txt_group_discuss_quick_search").val());
/*	if(strSearchVal == ""){
		$("#frm_group_discuss_quick_search #txt_group_discuss_quick_search").focus();
		return false;
	}*/
	
	$("#frm_group_discuss_quick_search").submit();
}

/**  页面group discuss列表排序条件更换  **/
juuyou.group.changeDiscussListOrder = function(){
	var strOrderIndex = $("#sel_group_discuss_order").val();
	window.location = "/discuss/discussList.php?gid=" + strGID + "&o=" + strOrderIndex;
}

// group comment提交
juuyou.group.checkGroupComment = function(strFrom){
	if(strFrom != "index" && strFrom != "list"){
		return false;
	}

	var strComment = $.trim($("#frm_group_comment #txt_group_comment").val());
	if(strComment == ""){
		$("#frm_group_comment #txt_group_comment").focus();
		return false;
	}
	
	if(strComment.length > 300){
		alert("字符数最大不得超过300");
		return false;
	}

	$.ajax({
	 	type:"POST",
		url:"../json/groupSayingAdd.php",
		async:false,
		data: {
			aid: strAID,
			val: strComment,
			from: strFrom
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
			
				$("#frm_group_comment #txt_group_comment").val("");
				$("#j_comment_list").prepend(data);
				intSayingCount = intSayingCount + 1;
				$("#j_comment_count_span").html(intSayingCount);
			
				//window.location.reload();
			}
		}
	});
}

//初始化group saying删除
$(document).ready(function(){
	$(".j_group_saying_del").live("click", function(){	
		var objDl = $(this).parents("dl");
		var strSID = objDl.attr("sid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/groupSayingDelete.php",
			async:true,
			data: {
				sid: strSID,
				act: "delete"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objDl.hide();
					intSayingCount = intSayingCount - 1;
					$("#j_comment_count_span").html(intSayingCount);
				}
			}
		});
		return false;
	});
});



/**  成员管理CheckBox全部选中和取消  **/
juuyou.group.selAllMemberCheckBox = function(objChb){
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbMemberList)){
			if ("undefined" != typeof(document.all.chbMemberList.length)){
				for (i=0; i<document.all.chbMemberList.length; i++){
					if(!document.all.chbMemberList[i].disabled){
						document.all.chbMemberList[i].checked = objChb.checked;
					}
				}
			}else{
				document.all.chbMemberList.checked = objChb.checked;
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbMemberList"))){
			if ("undefined" != typeof(document.getElementsByName("chbMemberList").length)){
				for (i=0; i<document.getElementsByName("chbMemberList").length; i++){
					if(!document.getElementsByName("chbMemberList")[i].disabled){
						document.getElementsByName("chbMemberList")[i].checked = objChb.checked;
					}
				}
			}else{
				document.getElementsByName("chbMemberList").checked = objChb.checked;
			}
		}
	}
}

// 设置管理员
juuyou.group.memberAdminSet = function(strAct){
	if(strAct != "admin" && strAct != "member" && strAct != "quit"){
		return false;
	}

	var strIds = juuyou.group.getAllMemberCheckedIds();
	if(strIds == ""){
		return false;
	}
	
	$("#frm_set #hid_act").val(strAct);
	$("#frm_set #hid_ids").val(strIds);

	$("#frm_set").submit();
}

/**  得到管理中选中的人员ID  **/
juuyou.group.getAllMemberCheckedIds = function(){
	var strIds = "";
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbMemberList)){
			if ("undefined" != typeof(document.all.chbMemberList.length)){
				for (i=0; i<document.all.chbMemberList.length; i++){
					if(document.all.chbMemberList[i].checked){
						strIds += document.all.chbMemberList[i].value + ",";
					}
				}
			}else{
				if(document.all.chbMemberList.checked){
					strIds = document.all.chbMemberList.value + ",";
				} 
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbMemberList"))){
			if ("undefined" != typeof(document.getElementsByName("chbMemberList").length)){
				for (i=0; i<document.getElementsByName("chbMemberList").length; i++){
					if(document.getElementsByName("chbMemberList")[i].checked){
						strIds += document.getElementsByName("chbMemberList")[i].value + ",";
					}
				}
			}else{
				if(document.getElementsByName("chbMemberList").checked){
					strIds = document.getElementsByName("chbMemberList").value + ",";
				} 
			}
		}
	}
	if(strIds != ""){
		strIds = strIds.substring(0, strIds.length-1);
	}
	
	return strIds;
}

// 成员申请管理
juuyou.group.applyAdminSet = function(strAct){
	if(strAct != "Y" && strAct != "N"){
		return false;
	}

	var strIds = juuyou.group.getAllMemberCheckedIds();
	if(strIds == ""){
		return false;
	}
	
	$("#frm_set #hid_act").val(strAct);
	$("#frm_set #hid_ids").val(strIds);

	$("#frm_set").submit();
}

// 获取群组邀请链接
juuyou.group.getNewGroupInviteLink = function(){
	$.ajax({
	 	type:"post",
		url:"../json/admin/getNewGroupInviteLink.php",
		async:false,
		data: {
			gid: gid
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#txt_group_invite_link").val(data);
			}
		}
	});
}

/**  检查邮件邀请信息，并提交  **/
juuyou.group.checkEmailInvite = function(){
	var emails = $("#j_group_invite_email #txt_emails").val();
	var contents = $("#j_group_invite_email #txt_contents").val();
	var emailsVal = "";
	
	var arrEmails = emails.split("\n");
	for(var i in arrEmails){
		if(arrEmails[i].length == 0){
			continue;
		}
		if(!juuyou.common.isEmail(arrEmails[i])){
			alert("请确认输入了正确的EMAIL：" + arrEmails[i]);
			emailsVal = "";
			return false;
		}
		emailsVal += arrEmails[i] + ",";
	}
	if(emailsVal.replace(",", "") == ""){
		alert("请确认输入了正确的EMAIL");
		emailsVal = "";
		return false;
	}

	$.ajax({
	 	type:"post",
		url:"../json/admin/inviteEmail.php",
		async:false,
		data: {
			gid: gid,
			emailsVal: emailsVal,
			contents: contents
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
				$(".j_invite_success").hide();
				$(".j_invite_failure").show();
			}else{
				$("#j_group_invite_email #txt_emails").val("");
				$(".j_invite_success").show();
				$(".j_invite_failure").hide();
			}
		}
	});

}

// 邀请msn好友登录
juuyou.group.inviteMsnLogin = function(){
	strID = $.trim($("#j_invite_group_msn_login #txt_msn").val());
	strPWD = $("#j_invite_group_msn_login #pwd_msn").val();
	
	if(strID == ""){
		$("#j_invite_group_msn_login #txt_msn").focus();
		return;
	}
	
	if(strPWD == ""){
		$("#j_invite_group_msn_login #pwd_msn").focus();
		return;
	}
	
	$.ajax({
	 	type:"post",
		url:"../json/admin/inviteMsnLogin.php",
		async:false,
		data: {
			txt_msn: strID,
			pwd_msn: strPWD
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#j_invite_group_msn_div").html(data);
				$("#j_invite_group_msn_div").show();
				$("#j_invite_group_msn_login").hide();
			}
		}
	});	
}


/**  Msn好友CheckBox全部选中和取消  **/
juuyou.group.selAllMsnFriendCheckBox = function(objChb){
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbMsnFriendsList)){
			if ("undefined" != typeof(document.all.chbMsnFriendsList.length)){
				for (i=0; i<document.all.chbMsnFriendsList.length; i++){
					if(!document.all.chbMsnFriendsList[i].disabled){
						document.all.chbMsnFriendsList[i].checked = objChb.checked;
					}
				}
			}else{
				document.all.chbMsnFriendsList.checked = objChb.checked;
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbMsnFriendsList"))){
			if ("undefined" != typeof(document.getElementsByName("chbMsnFriendsList").length)){
				for (i=0; i<document.getElementsByName("chbMsnFriendsList").length; i++){
					if(!document.getElementsByName("chbMsnFriendsList")[i].disabled){
						document.getElementsByName("chbMsnFriendsList")[i].checked = objChb.checked;
					}
				}
			}else{
				document.getElementsByName("chbMsnFriendsList").checked = objChb.checked;
			}
		}
	}
}

// 跳过邀请msn好友
juuyou.group.skipInviteMsnRegistedFriend = function(){
	$.ajax({
	 	type:"post",
		url:"../json/admin/inviteMsnLogin.php",
		async:false,
		data: {
			txt_msn: strID,
			pwd_msn: strPWD,
			type: "list"
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#j_invite_group_msn_div").html(data);
				$("#j_invite_group_msn_div").show();
			}
		}
	});	
}

/** 邀请已注册Msn好友 **/
juuyou.group.inviteRegistedMsnFriend = function(){
	$(".j_invite_success").hide();
	$(".j_invite_failure").hide();

	var ids = juuyou.group.getAllMsnFriendCheckedIds();
	if(ids == ""){
		alert("请选择您要提出申请的好友");
		return false;
	}

	$.ajax({
 		type:"POST",
		url:"../json/admin/inviteFriends.php",
		async:false,
		data: {
			ids: ids,
			gid: gid
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
				$(".j_invite_success").hide();
				$(".j_invite_failure").show();
			}else{
				$(".j_invite_success").show();
				$(".j_invite_failure").hide();
			}
		}
	});

	return true;	
}

/**  得到选中的好友ID  **/
juuyou.group.getAllMsnFriendCheckedIds = function(){
	var strIds = "";
	if(!juuyou.common.isFirefox()){
		if ("undefined" != typeof(document.all.chbMsnFriendsList)){
			if ("undefined" != typeof(document.all.chbMsnFriendsList.length)){
				for (i=0; i<document.all.chbMsnFriendsList.length; i++){
					if(document.all.chbMsnFriendsList[i].checked){
						strIds += document.all.chbMsnFriendsList[i].value + ",";
					}
				}
			}else{
				if(document.all.chbMsnFriendsList.checked){
					strIds = document.all.chbMsnFriendsList.value + ",";
				} 
			}
		}
	}else{
		if ("undefined" != typeof(document.getElementsByName("chbMsnFriendsList"))){
			if ("undefined" != typeof(document.getElementsByName("chbMsnFriendsList").length)){
				for (i=0; i<document.getElementsByName("chbMsnFriendsList").length; i++){
					if(document.getElementsByName("chbMsnFriendsList")[i].checked){
						strIds += document.getElementsByName("chbMsnFriendsList")[i].value + ",";
					}
				}
			}else{
				if(document.getElementsByName("chbMsnFriendsList").checked){
					strIds = document.getElementsByName("chbMsnFriendsList").value + ",";
				} 
			}
		}
	}
	if(strIds != ""){
		strIds = strIds.substring(0, strIds.length-1);
	}
	return strIds;
}


/**  检查MSN好友邮件邀请信息，并提交  **/
juuyou.group.checkMsnEmailInvite = function(){
	var emails = juuyou.group.getAllMsnFriendCheckedIds();
	if(emails == ""){
		alert("请选择您要邀请的MSN好友");
		return false;
	}
	var contents = $("#j_invite_group_msn_div #txt_contents").val();
	var emailsVal = "";
	
	var arrEmails = emails.split(",");
	for(var i in arrEmails){
		if(arrEmails[i].length != "" && !juuyou.common.isEmail(arrEmails[i])){
			alert("请确认输入了正确的EMAIL：" + arrEmails[i]);
			emailsVal = "";
			return false;
		}
		emailsVal += arrEmails[i] + ",";
	}
	if(emailsVal.replace(",", "") == ""){
		alert("请确认输入了正确的EMAIL");
		emailsVal = "";
		return false;
	}

	$.ajax({
	 	type:"post",
		url:"../json/admin/inviteEmail.php",
		async:false,
		data: {
			gid: gid,
			emailsVal: emailsVal,
			contents: contents
		},
		success:function(data){
			if($.trim(data) != juuyou.common.json.success){
				$(".j_invite_success").hide();
				$(".j_invite_failure").show();
			}else{
				$("#j_group_invite_email #txt_emails").val("");
				$(".j_invite_success").show();
				$(".j_invite_failure").hide();
			}
		}
	});
}




