
<%@ Page CodeBehind="myfriend.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.myfriend" %>
<% @ Import Namespace="Webdisk" %>
<link href="<%=xml.GetStyle()%>" type="text/css" rel="Stylesheet"/>
		<script type="text/javascript" language="javascript" src="js/function.js"></script>


    <div class="menuBlock" runat="server" id="divList">
	    <div class="menuHead" style="overflow:hidden;border-bottom: 1px dashed #cfcfcf;">
		    <h2 style="font-size: 18px;color: #1EA7DF;"><img src="pics/menu_file_cut.gif" align="absMiddle"> 我加的好友</h2>
		</div>
	    <br/>
	    <table class="form-table">
		    <tr><td class='label'>查找好友：</td>
			    <td>                    
                    <input type="text" id="key" name="key" runat="server" class="input3" />
				    <label><input name="mo" type="checkbox" id="mo" value="1" runat="server"/> 模糊查找</label>
				    <input class="but1 " id="Button2" type="button" value=" 查 找 " name="Button2" runat="server"/>
			    </td>
		    </tr>
        </table>
	    <div class="menubox">
		    <input class="but5 deleteMsg" id="butdel" type="button" value="删除勾选" name="butdel" runat="server">
		    <input class="but5 sendMsg" id="butmsg" type="button" value="发短消息" name="butmsg">
		    <select name="friendteam" id="friendteam" runat="server"  style="display:none"></select>
		    <INPUT class="but5 transferGroup" id="move" type="button" value="转移分组" name="move" runat="server">
		    <INPUT id="HdnSelectedValues" type="hidden" name="HdnSelectedValues" runat="server">
		</div>
		<div  class="menuBox2">
            <div class="mListT">
                <span class="l1">
                   <input name="" id="codeCheckAll" type="checkbox" value="" />
		        </span>
		        <span class="l5">用户名</span>
                <span class="l3">所属组</span> 
		        <span class="l3">发短消息</span>
                <span class="l6">查看共享</span>
		        <span class="l6">删除</span> 
            </div>
	        <div id="ListC"></div>
	        <div class="pageList" id="page"> 
	        </div>
        </div>
		<input type="hidden" id="hiddenUser" value ='<%=Session["username"]==null?"":Session["username"].ToString() %>'/>
    </div>
<script type="text/javascript">
var MyFriend = {};
MyFriend.iframeDialog = null;
MyFriend.init = function(){
	if($("#hiddenUser").val() == ""){
		location.href = "/login.aspx";
	}
	this.addEvent();
	this.initPage();
}
/**
*添加事件
**/
MyFriend.addEvent = function(){
	var that = this ;
	$("#Button2").click(function(){
		that.initPage();
	});
	//全选反选
	$("#codeCheckAll").click(function(){
		var checked = this.checked ;
		$(".checkItem").each(function(){
			this.checked = checked ;
			$(this).closest("li")[checked ? "addClass":"removeClass"]("checked");
		});
	});
	//删除勾选
	$("#butdel").click(function(){
		var checked = $(".checkItem:checked") ;
		if(checked.size() == 0) {
			var d = dialog({content : "您没有勾选任何内容"}).showModal();
			that.autoClose(d);
		}else{
			that.submitDelete(checked);
		}
	});
	//发送信息
	$("#butmsg").click(function(){
		var checked = $(".checkItem:checked") ;
		if(checked.size() == 0) {
			var d = dialog({content : "您没有勾选任何内容"}).showModal();
			that.autoClose(d);
		}else{
			var send = [];
			checked.each(function(){
				send.push($(this).data("name"));
			});
			that.dialogShow('sms_input.aspx?username='+send.join(","),'发送短信');
		}
	});
	//转移分组
	$("#move").click(function(){
		var checked = $(".checkItem:checked") ;
		if(checked.size() == 0) {
			var d = dialog({content : "您没有勾选任何内容"}).showModal();
			that.autoClose(d);
		}else{
			that.dialogMove(checked);//friendteam
		}
	});
}
MyFriend.dialogMove =function(tag){
	var name = [];
	var that = this;
	tag.each(function(){name.push($(this).data("name"))});
	var _d = dialog({
		title :"转移分组",
		content : "<div style='width:350px;'>选择分组："+$("#friendteam").clone().show().attr("id","fitem")[0].outerHTML+"</div>",
		statusbar: '<span id="errorMy"></span>',
		button: [
        {
            value: '确定转移',
            callback: function () {
               $.ajax({
					url : "OtherHandler.ashx?cmd=MoveFriendTeam",
					data : {friendname:encodeURI(name.join(",")),user:encodeURI($("#hiddenUser").val()) ,team:encodeURI($("#fitem").val())},
					dataType : "json",
					cache:false,
					type : "POST",
					success : function(data){
						if(data.code == "0"){
							$("#errorMy").html('<span style="color: #428BCA;">转移分组成功</span>');
							that.autoClose(_d);
						}else{
							$("#errorMy").html('<span style="  color: #f00;">转移分组成功</span>');
						}
					}
			   });
                return false;
            },
            autofocus: true
        },
        {
            value: '取消',
            callback: function () {
               return true ;
            }
        }]
	}).showModal();
}
MyFriend.autoClose = function(d){
	setTimeout(function(){
		d.close().remove();
	},2000);
}
MyFriend.submitDelete = function(checkedTag){
	var that = this ;
	var _user = $("#hiddenUser").val();
	var _friendname = [];
	checkedTag.each(function(){
		_friendname.push($(this).data("name"));
	});
	var d = dialog().showModal();
	$.ajax({
		url : "OtherHandler.ashx?cmd=DeleteMyFriend",
		type : "POST",
		dataType : "json" ,
		cache:false,
		data : {friendname:encodeURI(_friendname.join(",")),user: encodeURI(_user)},
		success : function(data){
			d.content(data.msg);
			that.autoClose(d);
			if(data.code == 0){
				that.initPage($("#H_currentPage").val());
			}
		}
	});
}
/**
*添加列表事件
**/
MyFriend.addListEvent = function(){
	var that = this ;
	$(".checkItem").click(function(){
		var flag = $(".checkItem").size() == $(".checkItem:checked").size() ;
		var checked = this.checked ;
		$(this).closest("li")[checked ? "addClass":"removeClass"]("checked");
		$("#codeCheckAll")[0].checked = flag ;
	});
	$("#codeList li").click(function(event){
		if(event.target.nodeName.toLowerCase() != "input" && event.target.nodeName.toLowerCase() != "a"){
			$(this).find(".checkItem")[0].click();
		}
	});
	//删除单个
	$("#codeList .delFriend").click(function(){
		var checked = $(this).closest("li").find(".checkItem");
		that.submitDelete(checked);
	});
	//发送信息
	$("#codeList .sengMsg").click(function(){
		that.dialogShow('sms_input.aspx?username='+$(this).data("send"),'发送短信');
	});
	//查看共享
	$("#codeList .share").click(function(){
		getHtml('allshare.aspx?friend='+$(this).data("name"));
	});
}
/**
*初始化列表
**/
MyFriend.initPage = function(current_page){
	var that = this ;
	var _key = $.trim($("#key").val());
	var _islike = $("#mo").is(":checked") ? 1 : 0 ;
	current_page = current_page ? current_page : 0 ;
	function ajax (page,callback){
		$.ajax({
			url : "MyFriendMng.aspx",
			type : "POST",
			cache:false,
			data : {pageIndex:page,key:_key,islike:_islike},
			dataType : "html",
			success : function(data){
				$("#ListC").empty().append(data);
				that.addListEvent();
				typeof callback == "function" && callback();
			}
		});
	}
	ajax(current_page,function(){
		var maxlength = parseInt($("#H_itemtCount").val());
		var pageSize = parseInt($("#H_pagesize").val());
		$("#page").pagination(maxlength, {
			prev_text: '< 上一页',
			next_text: '下一页 >',
			items_per_page: pageSize,
			num_display_entries: 5,
			current_page: 0,
			num_edge_entries: 2,
			link_to: "javascript:void(0);",
			callback: function (page_id, panel) {
				var self = this;
				ajax(page_id, function (vdata) {
					self.maxentries = parseInt($("#H_itemtCount").val());
				});
			}
		});
	});
}
MyFriend.dialogShow = function(href,title){
	var that = this ;
	var d = this.iframeDialog = dialog({
		content: "<iframe src='" +href + "' style='border:none;width:500px;height:350px;'></iframe>",
		title: title
	});
	d.showModal();
}
/**
*关闭模态窗口
*/
MyFriend.closeWindow = function(flag){
	if(this.iframeDialog){
		this.iframeDialog.close().remove();
		this.iframeDialog = null ;
	}
}




MyFriend.init();
</script>
