/*
'=====================================================================
' Module Name:
' File name: follow.js
' Author: william.lu
' Project : saywo
' Copyright (c) all rights reserved by juuyou.com Co., LTD.
' Create on 2009/09/16
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: 
'
'*********************************************************************
*/


/**  定义juuyou.follow命名空间  **/
juuyou.follow = {};

juuyou.follow.followDivShow = function(){
	$("#j_follow_drift").fadeIn(200);
	$("#j_shadow").show();
}
juuyou.follow.followDivHide = function(){
	$("#j_follow_drift").hide();
	$("#j_shadow").hide();
}

//设置跟随人所属目录
juuyou.follow.setFollowCategory = function(strFollowCategoryId){
	var strFollowId = $("#j_follow_dirft_box_b").attr("fid");
	if(!strFollowCategoryId || !strFollowId){
		alert("设置失败");
		return false;
	}
	
	$.ajax({
 		type:"POST",
		url:"../json/follow/setFollowCategory.php",
		async:false,
		data: {
			fid: strFollowId,
			fcid: strFollowCategoryId
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
				alert("设置失败");
			}else{
				juuyou.follow.followDivHide();
			}
		}
	});
}

juuyou.follow.showCreateFollowCategoryDiv = function(){
	$("#j_follow_category_add").show();
}

juuyou.follow.showCreateFollowCategoryDiv2 = function(){
	$("#j_shadow").show();
	$("#j_follow_drift").fadeIn(200);
}
juuyou.follow.hideCreateFollowCategoryDiv2 = function(){
	$("#j_follow_drift #j_follow_category_name").val("");
	$("#j_follow_drift").hide();
	$("#j_shadow").hide();
}

//添加分类
juuyou.follow.createFollowCategory = function(){
	var strFollowCategoryName = $.trim($("#j_follow_drift #j_follow_category_name").val());
	if(strFollowCategoryName == ""){
		$("#j_follow_drift #j_follow_category_name").val("").focus();
		return;
	}

	$.ajax({
 		type:"POST",
		url:"../../json/follow/createFollowCategory.php",
		async:false,
		data: {
			fcname: strFollowCategoryName
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
				alert("添加失败");
			}else{
				window.location.reload();
			}
		}
	});
}


//添加并设置分类
juuyou.follow.addSetFollowCategory = function(){
	var strFollowCategoryName = $.trim($("#j_follow_category_add #txt_follow_category_name").val());
	var strFollowId = $("#j_follow_dirft_box_b").attr("fid");
	if(!strFollowId || strFollowCategoryName == ""){
		$("#j_follow_category_add #txt_follow_category_name").val("").focus();
		return;
	}

	$.ajax({
 		type:"POST",
		url:"../json/follow/addSetFollowCategory.php",
		async:false,
		data: {
			fid: strFollowId,
			fcname: strFollowCategoryName
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
				alert("设置失败");
			}else{
				juuyou.follow.followDivHide();
			}
		}
	});
}

//删除跟随
$(document).ready(function(){	
	$(".j_follow_delete").live("click", function(){
		var objLi = $(this).parents("li");
		var strFid = objLi.attr("fid");
		
		if(!strFid){
			alert("取消跟随失败");
			return false;
		}
				
		$.ajax({
	 		type:"POST",
			url:"../../json/follow/deleteFollow.php",
			async:false,
			data: {
				fid: strFid
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
					alert("取消跟随失败");
				}else{
					//objLi.hide();
					window.location.reload();
				}
			}
		});
	});
});

//删除被跟随
$(document).ready(function(){	
	$(".j_followed_delete").live("click", function(){
		var objLi = $(this).parents("li");
		var strFid = objLi.attr("fid");
		
		if(!strFid){
			alert("取消被跟随失败");
			return false;
		}
				
		$.ajax({
	 		type:"POST",
			url:"../../json/follow/deleteFollowed.php",
			async:false,
			data: {
				fid: strFid
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
					alert("取消跟随失败");
				}else{
					//objLi.hide();
					window.location.reload();
				}
			}
		});
	});
});

juuyou.follow.showEditFollowCategoryNameDiv = function(){
	$("#j_shadow").show();
	$("#j_follow_category_rename").fadeIn(200);
}
juuyou.follow.hideEditFollowCategoryNameDiv = function(){
	$("#j_follow_category_rename #txt_follow_category_rename").val("");
	$("#j_follow_category_rename").hide();
	$("#j_shadow").hide();
}


//删除跟随目录
juuyou.follow.deleteFollowCategory = function(strFollowCategoryId){
	if(!strFollowCategoryId){
		return;
	}
	
	if(confirm("确认删除该分组？该组用户将被归类到未分组！")){
		$("#frm_delete_follow_category").submit();
	}
}


juuyou.follow.hideAddNoFollowCategoryUserDiv = function(){
	$("#j_no_follow_category_member").html("");
	$("#j_no_follow_category_member_div").hide();
	$("#j_shadow").hide();
}
juuyou.follow.showAddNoFollowCategoryUserDiv = function(){
	$("#j_shadow").show();
	$("#j_no_follow_category_member_div").fadeIn(200);
}

//显示为分组跟随用户列表信息
juuyou.follow.getNoFollowCategoryMemberByNickname = function(){
	var strNickname = $.trim($("#txt_no_follow_category_member_nickname").val());
	if(!strNickname){
		juuyou.follow.getAllNoFollowCategoryMember();
		return;
	}
	
	$.ajax({
 		type:"POST",
		url:"../../json/follow/getNoFollowCategoryUser.php",
		async:false,
		data: {
			strNickname: strNickname
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#j_no_follow_category_member").html(data);
				juuyou.follow.showAddNoFollowCategoryUserDiv();
			}
		}
	});	
	
	
}
juuyou.follow.getAllNoFollowCategoryMember = function(){
	$.ajax({
 		type:"POST",
		url:"../../json/follow/getNoFollowCategoryUser.php",
		async:false,
		data: {},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#j_no_follow_category_member").html(data);
				juuyou.follow.showAddNoFollowCategoryUserDiv();
			}
		}
	});	
}

$(document).ready(function(){	
	$(".j_select_follow_category").live("click", function(){
		if($(this).hasClass("select")){
			$(this).removeClass("select");
			$(this).find("#cbx_users_" + $(this).attr("fid")).attr("checked", "");
			
		}else{
			$(this).addClass("select");
			$(this).find("#cbx_users_" + $(this).attr("fid")).attr("checked", true);
		}
	});
	
	$(".j_follow_change").live("click", function(){
		var strUserNickName = $(this).parents("li").attr("fname");
		strFIDTemp = $(this).parents("li").attr("fid");
		$("#j_change_follow_category_div #j_span_nick_name").html(strUserNickName);
		juuyou.follow.showChangeFollowCategoryDiv();
	});
	
});

//设置为分组用户到改组
juuyou.follow.setNoFollowCategoryUser = function(){
	var obj = document.getElementsByName("cbx_users");
	var strIdxs = "";

	for(var i=0; i<obj.length; i++){
		if(obj[i].checked){
			strIdxs += obj[i].value + ",";
		}
	}
	
	if(strIdxs.length > 0){
		strIdxs = strIdxs.substring(0, strIdxs.length-1);
		$("#frm_no_follow_category_member #fids").val(strIdxs);
		$("#frm_no_follow_category_member").submit();
	}else{
		juuyou.follow.hideAddNoFollowCategoryUserDiv();
	}
}


juuyou.follow.hideChangeFollowCategoryDiv = function(){
	$("#j_change_follow_category_div #txt_follow_category_name").val("");
	$("#j_change_follow_category_div").hide();
	$("#j_shadow").hide();
}
juuyou.follow.showChangeFollowCategoryDiv = function(){
	$("#j_change_follow_category_div").fadeIn(200);
	$("#j_shadow").show();
}

//更改分组
juuyou.follow.changeFollowCategory = function(strFollowCategoryId){
	$("#frm_change_follow_cagetory #fid").val(strFIDTemp);
	$("#frm_change_follow_cagetory #fcid").val(strFollowCategoryId);
	$("#frm_change_follow_cagetory").submit();
}
//更改分组新增
juuyou.follow.addChangeFollowCategory = function(){
	var strFollowCategoryName = $.trim($("#j_follow_category_add #txt_follow_category_name").val());
	$("#j_follow_category_add #hid_fid").val(strFIDTemp);
	alert($("#j_follow_category_add #hid_fid").val() + "  " + strFollowCategoryName);
	
	if(strFollowCategoryName == ""){
		$("#j_follow_category_add #txt_follow_category_name").val("").focus();
		return;
	}
	
	$("#frm_change_follow_cagetory_add").submit();
}
//更改分组为未分组
juuyou.follow.changeFollowCategoryNone = function(strFollowCategoryId){
	$("#frm_change_follow_cagetory_none #hid_fid_none").val(strFIDTemp);
	$("#frm_change_follow_cagetory_none").submit();
}













