jQuery(function($) {
/* 禁用jQuery AjaxLoad缓存 */
$.ajaxSetup ({
	cache:false
});

/* **
 * WebOS
 * -------- -------- --------
 */
 	// Save Weibo
	$('[name=saveweibo]').die('click').live('click',function(e){
		var $this = $(this),
			$href = $this.attr('href');
		$.ajax({
			type    : 'POST',
			url     : $href,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('备份成功',function(){
						fresh();
					});
				}
			}
		});
		e.stopPropagation();
		return false;
	});
	
	// Note Move Drag
	$('.note_list[name=my_note_list] li').notemove();
	
	// Note Move Popup
	$('a.mv').die('click').live('click',function(){
		var	$this = $(this),
			$nid  = $this.parents('li').attr('nid');
		
		$.fn.ipop.popup({
			width : 480,
			height: 200,
			speed : 'fast',
			title : '笔记移动',
			url   : iknowing_domain + '/note/move.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			oc.die('click').live('click',function(){
				var cato = $('#cat_list :checked');
				if( cato.length <= 0 ){
					trace('请选择分类');
					return;
				}
				else if( cato.length > 1 ){
					trace('不能同时选择多个分类哦');
					return;
				}
				else{
					var $cid  = cato.val();
					$.ajax({
						type    : 'POST',
						url     : iknowing_domain + '/note/'+$nid+'/move.html?catId='+$cid,
						data    : '',
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								trace('移动成功',function(){
									$this.parents('li').slideUp('normal',function(){
										$this.parents('li').remove();
										fresh();
									});
									o.close();
								});
							}
						}
					});
				}
			});
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// Note : Edit or Create
	$('#sub').die('click').live('click',function(){
		var	$categoryId = $('.nd_select').val(),
			$noteId = $('#windows_content').attr('nid'),
			$title = $('.nd_text').val(),
			$notecontent = xedit.getSource(),
			$description = $('#edit_des').attr('title'),
			$sourceUrl   = $('#source').attr('title'),
			$privacy     = $('.nd_privacy input:checked').val(),
			$tags        = '',
			$tagObject   = $('#plus_tag a');
			
			for( var i=0 ; i<$tagObject.length ; i++ )
				$tags += $tagObject.eq(i).html().split('<b>&nbsp;</b>')[0] + '|' + $tagObject.eq(i).attr('tagid') + ',';
			
			if($title.length <= 0)
				$title = '创建新笔记';
		
		// Verification
		if( $categoryId == '' ){
			trace('categoryId不能为空');
			return;
		}
		if( $noteId == '' ){
			trace('noteId不能为空');
			return;
		}
		if( $title.length > 128 ){
			trace('文章标题不能超过128个字哟^.^~');
			return;
		}
		if( $notecontent ){
			//return true;
		}
		if( $description == undefined ){
			$description = '';
		}
		if( $description.length > 200 ){
			trace('文章摘要不能超过200字哟^.^~');
			return;
		}
		/*
		if( $sourceUrl != '' && $sourceUrl != undefined && $sourceUrl.indexOf('http://') ){
			trace('请输入正确的源地址');
			return;
		}
		*/
		if( $privacy != 0 && $privacy != 2 ){
			trace('邪恶了哦~居然修改公开权限~你果然不是一般人啊^.^~');
			return;
		}
		if( $tags.split(',').length > 11 ){
			trace('标签最多只能打10个哟^.^~');
			return;
		}
		
		$('#categoryId').val($categoryId);
		$('#noteId').val($noteId);
		$('#title').val($title);
		$('#notecontent').val($notecontent);
		$('#description').val($description);
		$('#sourceUrl').val($sourceUrl);
		$('#privacy').val($privacy);
		$('#tags').val($tags);
		$('#cn_form').submit();
	});
	
	// Note : Ajax Save
	$(function(){
		if( $('#ose_title').length == 1 ){
			var $bind = $.browser.msie ? $bind = window.document.body : $bind = window;
			$bind.onkeydown = function(e){
				e = e || window.event;
				if( e.ctrlKey && e.shiftKey && e.keyCode == 83 ){
					$.fn.ajaxSave();
				}
			}
			var $interval;
			if( $('.mod_save').attr('checked') == 'checked' ){
				$.fn.ajaxSave(function(){
					dosaveanimate();
				});
				$interval = setInterval(function(){
					$.fn.ajaxSave(function(){
						dosaveanimate();
					});
				},30000);
			}
			$('.mod_save').change(function(){
				clearInterval($interval);
				if( $(this).attr('checked') ){
					$.fn.ajaxSave(function(){
						dosaveanimate();
					});
					$interval = setInterval(function(){
						$.fn.ajaxSave(function(){
							dosaveanimate();
						});
					},30000);
				}
				else{
					clearInterval($interval);
				}
			});
			$('[name=quicksave]').die('click').live('click',function(){
				$.fn.ajaxSave(function(){
					o.fadeIn(s,function(){
						dosaveanimate();
					});
				});
			});
			function dosaveanimate(){
				var o = $('.autosavetips b'),
					s = 'slow';
				o.fadeIn(s,function(){
					var timeout = setTimeout(function(){
						o.fadeOut(s,function(){
							clearTimeout( timeout );
						});
					},3000);
				});
			}
		}
	});
	
	// Select Order
	$('[name=semod]').change(function(){
		var	$this = $(this),
			$url  = window.location.href.split('?')[0],
			$val  = $this.val();
		
		$url += '?orderType=' + $val;
		window.location.href = $url;
	});
	$('[name=seabb]').change(function(){
		var	$this = $(this),
			$url  = window.location.href.split('?')[0],
			$val  = $this.val();
		
		$url += '?showDes=' + $val;
		window.location.href = $url;
	});
	
	// System Push Tags
	$('#tags_system').die('click').live('click',function(){
		var	$title = $('.nd_text').val(),
			$tags  = $('#plus_tag').html();
		
		$.fn.ipop.popup({
			width : 480,
			height: 208,
			speed : 'fast',
			title : '系统推荐标签',
			url   : iknowing_domain + '/tag/tokenize.html?title=' + encodeURIComponent($title)
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			var yourTags = $('.your_tags'),
				sysTags  = $('.sys_tags');
			
			yourTags.html($tags);
			
			yourTags.find('b').die('click').live('click',function(){
				$(this).parent().appendTo(sysTags);
			});
			
			sysTags.find('a').die('click').live('click',function(){
				yourTags.find('a').length <= 9 ?
					$(this).appendTo(yourTags):
					alert('太贪心啦！最多只能打10个Tag哦…');
			});
			
			oc.die('click').live('click',function(){
				o.close();
				$('#plus_tag').empty().prepend( yourTags.html() );
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
			
		});
	});
	
	// Edit Description
	$('#edit_des').die('click').live('click',function(){
		var $this = $(this);
		$.fn.ipop.popup({
			width : 480,
			height: 200,
			speed : 'fast',
			title : '摘要编辑',
			url   : iknowing_domain + '/home/note/desc/edit.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			var $deso = $('#ed_textarea');
			$deso.html( $this.attr('title') );
			oc.die('click').live('click',function(){
				if( $deso.val().length > 200 ){
					trace('摘要不能超过200字哟^.^~');
					return;
				}
				else{
					$this.attr('title',$deso.val());
					o.close();
				}
			});
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// Text Create Tag
	$(function(){
		var	$type = true,
			interval;
		$('#tags_text').keydown(function(event){
			if( event.keyCode == 13 ){
				if( interval )
					clearTimeout( interval );
				var $this    = $(this),
					$val     = $this.val(),
					$tago    = $('#plus_tag');
				interval = setTimeout(function(){
					$type = true;
				},1000);
				
				if( $val != '' && $val.length <= 10 && $tago.find('a').length < 10 && $type == true ){
					$this.val(''); $type = false;
					
					$.ajax({
						url      : iknowing_domain + '/tag/id.html',
						type     : 'GET',
						dataType : 'text',
						success  : function( data ){
							data=eval('('+data+')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								var $text = $('<a tagId="'+data.tagId+'" href="javascript:;">'+$val+'<b>&nbsp;</b></a>');
								$tago.append( $text );
								$text.hide(0).fadeIn('normal');
							}
						}
					});
				}
			}
		});
	});
	
	// Normal Delet Tags
	$('#plus_tag b').die('click').live('click',function(){
		var $this = $(this).parent();
		$.ajax({
			url     : iknowing_domain + '/tag/delete/' + $this.attr('tagid') + '.html',
			type    : 'POST',
			data    : '',
			success : function( data ){
				data=eval('('+data+')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.fadeOut('normal',function(){
						$this.remove();
					});
				}
			}
		});
	});
	
	// Tree Node Edit
	$('.tree_info[name=my_lib]').treenEdit();
	
	// Tree Node Delet
	$('.tree_info[name=my_lib] bdo[name=dele]').die('click').live('click',function(){
		var	$obj = $(this).parents('a'),
			$cid = $obj.attr('cid');
		confirm('确定删除此分类吗？',function(){
			$.ajax({
				url     : iknowing_domain + '/category/'+$cid+'/delete.html',
				type    : 'GET',
				data    : '',
				success : function( data ){
					data=eval('('+data+')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$obj.slideUp('normal',function(){
							$obj.remove();
						});
					}
				}
			});
		});
	});
	
	// Tree Node Add
	$('.addcat').die('click').live('click',function(){
		var $fath = $('.tree_info[name=my_lib]').find('.tree_cot');
		$.ajax({
			url     : iknowing_domain + '/category/add.html',
			type    : 'GET',
			data    : '',
			success : function( data ){
				data=eval('('+data+')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					var	$html = $('<a cid="'+data.catId+'" class="cotalist hasmenu"><span name="ja" href="'+iknowing_domain+'/home/category/'+data.catId+'.html"></span><div class="cotalist_menu"><bdo name="dele" class="dele" href="javascript:;"></bdo><bdo name="edit" class="edit" href="javascript:;"></bdo></div></a>'),
						$text = $('<input type="text" maxlength="50" class="tree_text" value="新建分类">');
					$html.find('span').html( $text );
					$fath.append($html);
					$text.focus()
						.focusout(function(){
							oDo( $(this) );
						})
						.keydown(function(event){
							if( event.keyCode == 13 )
								oDo( $(this) );
						});
					function oDo( o ){
						var $this = o,
							$val  = $this.val(),
							$htm  = $('<b class="name">'+$val+'</b><b class="tree_num">0</b>');
						if( $val == '新建分类' || $val == '' ){
							$html.find('span').html( $htm );
							$fath.append($html);
						}
						if( !htmlReg.test($val) ){
							trace('输入字符非法！',function(){
								$htm  = $('<b class="name">新建分类</b><b class="tree_num">0</b>');
								$html.find('span').html( $htm );
								$fath.append($html);
							});
							return;
						}
						else{
							var $data = 'name=' + encodeURIComponent($val);
							$.ajax({
								type    : 'GET',
								url     : iknowing_domain + '/category/'+data.catId+'/update.html',
								data    : $data,
								success : function(data){
									data = eval('(' + data + ')');
									if( data.error == 'true' ) trace( data.msg )
									else{
										$html.find('span').html( $htm );
										$fath.append($html);
									}
								}
							});
						}
					}
				}
			}
		});
	});
	
	// Note Like
	$('a[name=like]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		$this.attr('type') == 'yes' ?
			$.ajax({
				type    : 'GET',
				url     : iknowing_domain + '/note/'+$nid+'/dislike.html',
				data    : '',
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$this.attr('type','no');
						numMenas( $this.find('b') );
						$this.html( $this.html().replace('取消喜欢','喜欢') );
					}
				}
			}):
			$.ajax({
				type    : 'GET',
				url     : iknowing_domain + '/note/'+$nid+'/like.html',
				data    : '',
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$this.attr('type','yes');
						numPlus( $this.find('b') );
						$this.html( $this.html().replace('喜欢','取消喜欢') );
					}
				}
			});
	});
	
	// Note Fav
	$('a[name=fav]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
			$.fn.ipop.popup({
				width : 480,
				height: 430,
				speed : 'fast',
				title : '文档收藏',
				url   : iknowing_domain + '/note/'+$nid+'/collect.html'
			},function( o ){
				var oc = $('.button_green[name=提交]'),
					ox = $('.button_gray[name=取消]');
				
				var yourTags  = $('.your_tags'),
					sysTags   = $('.sys_tags'),
					inputTags = $('#nd_tags_input'),
					$type     = true,
					interval;
					
				inputTags.defaultTxT('添加标签,回车确认');
				
				var oTags = $this.parents('[nid]').find('.tags a').clone();
				oTags.each(function(){
					$(this).attr('href','javascript:;').append('<b>&nbsp;</b>');
				});
				
				yourTags.prepend( oTags );
				
				yourTags.find('b').die('click').live('click',function(){
					$(this).parent().appendTo(sysTags);
				});
				
				sysTags.find('a').die('click').live('click',function(){
					yourTags.find('a').length <= 9 ?
						inputTags.before($(this)):
						alert('太贪心啦！最多只能打10个Tag哦…');
				});

				inputTags.keydown(function(event){
					if( event.keyCode == 13 ){
						if( interval )
							clearTimeout( interval );
						var $this    = $(this),
							$val     = $this.val();
						interval = setTimeout(function(){
							$type = true;
						},1000);
						
						if( $val != '' && $val.length <= 10 && yourTags.find('a').length < 10 && $type == true ){
							$this.val(''); $type = false;
							
							$.ajax({
								url      : iknowing_domain + '/tag/id.html',
								type     : 'GET',
								dataType : 'text',
								success  : function( data ){
									data=eval('('+data+')');
									if( data.error == 'true' ) trace( data.msg )
									else{
										var $text = $('<a tagId="'+data.tagId+'" href="javascript:;">'+$val+'<b>&nbsp;</b></a>');
										inputTags.before( $text );
										$text.hide(0).fadeIn('normal');
									}
								}
							});
						}
					}
				});
				
				oc.die('click').live('click',function(){
					
					var	$noteId = $('#nid_new').val(),
						$noteIdNew = $('#nid_new').val(),
						$noteIdOrigin = $('#oid_new').val(),
						$noteIdFrom = $('#fid_new').val(),
						$title = $('#fav_title').val(),
						$description = $('#fav_des').val(),
						$categoryId = $('#fav_cat').val(),
						$privacy = $('#fav_privacy input:checked').val();
					
					var $data = 'noteId='+$noteId+'&noteIdNew='+$noteIdNew+'&noteIdOrigin='+$noteIdOrigin+'&noteIdFrom='+$noteIdFrom+'&title='+$title+'&description='+$description+'&categoryId='+$categoryId+'&privacy='+$privacy;
					
					$.ajax({
						type    : 'POST',
						url     : iknowing_domain + '/note/'+$noteIdFrom+'/collect.html',
						data    : $data,
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								trace('收藏成功',function(){
									o.close();
								});
							}
						}
					});
				});
				
				ox.die('click').live('click',function(){
					o.close();
				});
			});
	});
	
	// Note Delet
	$('a[name=del]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		confirm('确定要删除此文章吗？',function(){
			$.ajax({
				type    : 'GET',
				url     : iknowing_domain + '/note/'+$nid+'/delete.html',
				data    : '',
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$this.parents('[nid]').slideUp('normal',function(){
							$this.parents('[nid]').remove();
							fresh();
						});
					}
				}
			});
		});
	});
	// Note Delet 批量
	$('a[name=delpl]').die('click').live('click',function(){
		var $check = $('[name=my_note_list] input:checked');
		if( $check.length < 1 ){
			trace('请至少选择一条笔记');
			return;
		}
		else{
			confirm('确定要删除这些文章吗？',function(){
				var $ajaxType = false;
				for( var i=0; i<$check.length; i++ ){
					var $this = $check.eq(i),
						$nid  = $this.parents('[nid]').attr('nid');
					$.ajax({
						type    : 'GET',
						url     : iknowing_domain + '/note/'+$nid+'/delete.html',
						data    : '',
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								if( i == $check.length-1 ){
									$ajaxType = true;
									$check.parents('li').each(function(){
										var $this = $(this);
										$this.slideUp('normal',function(){
											$this.remove();
										});
									});
								}
							}
						}
					});
				}
				var interval = setInterval(function(){
					if( $ajaxType ){
						fresh();
						clearInterval( interval );
					}
				},50);

			});
		}
	});
	
	// Note 邮件
	$('a[title=邮件]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
			$.fn.ipop.popup({
				width : 480,
				height: 300,
				speed : 'fast',
				title : '邮件',
				url   : iknowing_domain + '/note/'+$nid+'/email.html'
			},function( o ){
				var oc = $('.button_green[name=提交]'),
					ox = $('.button_gray[name=取消]');
				
				var $seekmail    = $('#seekmail'),
					$seekadd     = $('#seekadd'),
					$seekcontent = $('#seekcontent'),
					$source      = iknowing_domain + '/note/' + $nid + '.html';
				
				$seekadd.html( $source );
				$seekadd.attr('href',$source);
				
				oc.die('click').live('click',function(){
					var	$data    = $seekmail.val().split(';'),
						$content = $seekcontent.val(),
						$type    = false,
						$emails  = '';
					
					for( var i=$data.length ; i-- ; ){
						/*
						if( !mailReg.test($data[i]) ){
							trace('请输入正确的Email地址');
							$type = false;
							return;
						}
						else{
							$type = true;
							$emails += '&emails=' + $data[i];
						}
						*/
						$type = true;
						$emails += '&emails=' + $data[i];
					}
					
					if( $type == true ){
						$.ajax({
							type    : 'POST',
							url     : iknowing_domain + '/note/'+$nid+'/email.html',
							data    : 'content='+$content+$emails,
							success : function(data){
								data = eval('(' + data + ')');
								if( data.error == 'true' ) trace( data.msg )
								else{
									trace('邮件发送成功',function(){
										o.close();
									});
								}
							}
						});
					}
				});
				
				ox.die('click').live('click',function(){
					o.close();
				});
			});
	});
	
	// 群发邮件 -- 活动+小组
	$('[name=massmail]').die('click').live('click',function(){
		var $utp = '';
		if( $(this).parents('[gid]').length > 0 ){
			var $id  = $(this).parents('[gid]').attr('gid'),
				$url = iknowing_domain + '/group/' + $id + '/pop.html',
				$sub = iknowing_domain + '/group/' + $id + '/massmail.html';
		}
		if( $(this).parents('[actid]').length > 0 ){
			var $id  = $(this).parents('[actid]').attr('actid'),
				$url = iknowing_domain + '/activity/' + $id + '/pop.html',
				$sub = iknowing_domain + '/activity/' + $id + '/massmail.html';
		}
		if( $(this).parents('[commid]').length > 0 ){
			var $id  = $(this).parents('[commid]').attr('commid'),
				$url = iknowing_domain + '/community/' + $id + '/pop.html',
				$sub = iknowing_domain + '/community/' + $id + '/massmail.html';
				$utp = $(this).attr('user_type');
		}
		$.fn.ipop.popup({
			width : 480,
			height: 260,
			speed : 'fast',
			title : '群发邮件',
			url   : $url
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');

			oc.die('click').live('click',function(){
				var $title   = $('#massmail_title').val(),
					$content = $('#massmail_content').val();
				if( $title.length <= 0 ){
					trace('邮件标题不能为空');
					return;
				}
				if( $content.length <= 0 ){
					trace('邮件内容不能为空');
					return;
				}
				
				var ajaxurl;
				$utp == '' ?
					ajaxurl = 'title=' + $title + '&content=' + $content :
					ajaxurl = 'title=' + $title + '&content=' + $content + '&userType=' + $utp;
				
				$.ajax({
					type    : 'POST',
					url     : $sub,
					data    : ajaxurl,
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('邮件发送成功',function(){
								o.close();
							});
						}
					}
				});
			});

			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// Note 推荐
	$('a[title=推荐]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		$.fn.ipop.popup({
			width : 480,
			height: 310,
			speed : 'fast',
			title : '推荐',
			url   : iknowing_domain + '/note/'+$nid+'/recommend.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			var $frd  = $('.frd_list li'),
				$all  = $('#frd_all'),
				$msg  = '';
			
			$all.change(function(){
				$all.attr('checked') ?
					$frd.find(':checkbox').attr('checked',true) :
					$frd.find(':checkbox').attr('checked',false);
			});
			
			oc.die('click').live('click',function(){
				
				if( $frd.find('input:checked').length <= 0 ){
					trace('请选择好友');
					return;
				}
				else{
					var $farr = [],
						$data = 'message='+$msg;
					$frd.find('input:checked').each(function(){
						$farr.push( $(this).val() )
					});
					$msg = $('#rec_msg').val();
					
					for( var i=0 ; i<$farr.length ; i++ )
						$data += '&friendIds=' + $farr[i];
					
					$.ajax({
						type    : 'POST',
						url     : iknowing_domain + '/note/'+$nid+'/recommend.html',
						data    : $data,
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								trace('推荐成功',function(){
									o.close();
								});
							}
						}
					});
				}
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	// Note 推荐 -- 批量
	$('a[name=rcpl]').die('click').live('click',function(){
		var $check = $('[name=my_note_list] input:checked');
		if( $check.length < 1 ){
			trace('请至少选择一条笔记');
			return;
		}
		else{
			$this = $check.eq(0);
			$nid  = $this.parents('[nid]').attr('nid');
		
			$.fn.ipop.popup({
				width : 480,
				height: 310,
				speed : 'fast',
				title : '推荐',
				url   : iknowing_domain + '/note/'+$nid+'/recommend.html'
			},function( o ){
				var oc = $('.button_green[name=提交]'),
					ox = $('.button_gray[name=取消]');
				
				var $frd  = $('.frd_list li'),
					$all  = $('#frd_all'),
					$msg  = '';
				
				$all.change(function(){
					$all.attr('checked') ?
						$frd.find(':checkbox').attr('checked',true) :
						$frd.find(':checkbox').attr('checked',false);
				});
				
				oc.die('click').live('click',function(){
					
					if( $frd.find('input:checked').length <= 0 ){
						trace('请选择好友');
						return;
					}
					else{
						var $farr = [],
							$data = 'message='+$msg;
						$frd.find('input:checked').each(function(){
							$farr.push( $(this).val() )
						});
						$msg = $('#rec_msg').val();
						
						for( var i=0; i<$farr.length; i++ )
							$data += '&friendIds=' + $farr[i];
						
						for( var i=0; i<$check.length; i++ ){
							$.ajax({
								type    : 'POST',
								url     : iknowing_domain + '/note/'+$check.eq(i).parents('[nid]').attr('nid')+'/recommend.html',
								data    : $data,
								success : function(data){
									data = eval('(' + data + ')');
									if( data.error == 'true' ) trace( data.msg )
									else{
										if( i == $check.length-1 ){
											trace('推荐成功',function(){
												o.close(function(){
													fresh();
												});
											});
										}
									}
								}
							});
						}
					}
				});
				
				ox.die('click').live('click',function(){
					o.close();
				});
			});
		}
	});
	
	// Note 分享
	doShare( $('a[title=分享]') );
	doShare( $('a[title=公开]') );
	doShare( $('a[title=私有]') );
	function doShare( $object ){
		var $this = $object;
		
		$this.die('click').live('click',function(){
			var $object = $(this),
				$nid    = $object.parents('[nid]').attr('nid');
			$.fn.ipop.popup({
				width : 480,
				height: 260,
				speed : 'fast',
				title : '分享',
				url   : iknowing_domain + '/note/'+$nid+'/share.html'
			},function( o ){
				var oc = $('.button_green[name=提交]'),
					ox = $('.button_gray[name=取消]');
				
				var $frd      = $('.frd_list li'),
					$all      = $('#frd_all'),
					$topcheck = $('.frd_list_top :radio'),
					$type     = Number( $('.frd_list_top input:checked').val() );
					$farr     = [];
				
				checkType( $type );
				function checkType( $type ){
					$type == 1 ?
					$('.frd_list :checkbox').removeAttr('disabled') :
					$('.frd_list :checkbox').attr('disabled','disabled');
				}
				
				$topcheck.change(function(){
					$type = $(this).val();
					checkType( $type );
				});
				
				$all.change(function(){
					$all.attr('checked') ?
						$frd.find(':checkbox').attr('checked',true) :
						$frd.find(':checkbox').attr('checked',false);
				});
				
				oc.die('click').live('click',function(){
					if( $type == 1 ){
						if( $frd.find('input:checked').length <= 0 ){
							trace('请选择好友');
							return;
						}
						else{
							$frd.find('input:checked').each(function(){
								$farr.push( $(this).val() )
							});
							var $data = 'shareType='+$type;
							for( var i=0 ; i<$farr.length ; i++ )
								$data += '&friendIds=' + $farr[i];
						}
					}
					else{
						var $data = 'shareType='+$type;
					}
					$.ajax({
						type    : 'POST',
						url     : iknowing_domain + '/note/'+$nid+'/share.html',
						data    : $data,
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								trace('分享成功',function(){
									switch( $type ){
										case 0 :
											$object.attr({
												'class' : 'lock',
												'title' : '私有'
											});
											break;
										case 2 :
											$object.attr({
												'class' : 'unlock',
												'title' : '公开'
											});
											break;
										case 1 :
											$object.attr({
												'class' : 'fx',
												'title' : '分享'
											});
											break;
										default : /*trace('Type Error !!');*/ break;
									}
									
									o.close(function(){
										fresh();
									});
								});
							}
						}
					});
				});
				
				ox.die('click').live('click',function(){
					o.close();
				});
			});
		});
	}
	
	// Note 分享到小组
	$('a[title=分享到小组]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
			$.fn.ipop.popup({
				width : 480,
				height: 200,
				speed : 'fast',
				title : '分享到小组',
				url   : iknowing_domain + '/note/'+$nid+'/group.html'
			},function( o ){
				var oc = $('.button_green[name=提交]'),
					ox = $('.button_gray[name=取消]');
				
				oc.die('click').live('click',function(){
					var	$data   = '',
						$object = $('#group_list input:checked');
					if( $object.length > 0 ){
						$object.each(function(){
							$data += '&gids=' + $(this).val();
						});
						$data = $data.substring(1,$data.length);
						
						$.ajax({
							type    : 'POST',
							url     : iknowing_domain + '/note/'+$nid+'/group.html?'+$data,
							data    : '',
							success : function(data){
								data = eval('(' + data + ')');
								if( data.error == 'true' ) trace( data.msg )
								else{
									trace('分享发送成功',function(){
										o.close();
									});
								}
							}
						});
					}
					else{
						trace('请至少选择一个小组');
					}
				});
				
				ox.die('click').live('click',function(){
					o.close();
				});
			});
	});
	// Note 分享到小组 -- 批量
	$('a[name=sgpl]').die('click').live('click',function(){
		var $check = $('[name=my_note_list] input:checked');
		if( $check.length < 1 ){
			trace('请至少选择一条笔记');
			return;
		}
		else{
			var $this = $check.eq(0),
				$nid  = $this.parents('[nid]').attr('nid');
				$.fn.ipop.popup({
					width : 480,
					height: 200,
					speed : 'fast',
					title : '分享到小组',
					url   : iknowing_domain + '/note/'+$nid+'/group.html'
				},function( o ){
					var oc = $('.button_green[name=提交]'),
						ox = $('.button_gray[name=取消]');
					
					oc.die('click').live('click',function(){
						var	$data   = '',
							$object = $('#group_list input:checked');
						if( $object.length > 0 ){
							$object.each(function(){
								$data += '&gids=' + $(this).val();
							});
							$data = $data.substring(1,$data.length);
							
							for( var i=0; i<$check.length; i++ ){
								$.ajax({
									type    : 'POST',
									url     : iknowing_domain + '/note/'+$check.eq(i).parents('[nid]').attr('nid')+'/group.html?'+$data,
									data    : '',
									success : function(data){
										data = eval('(' + data + ')');
										if( data.error == 'true' ) trace( data.msg )
										else{
											if( i == $check.length-1 ){
												trace('分享发送成功',function(){
													o.close(function(){
														fresh();
													});
												});
											}
										}
									}
								});
							}
						}
						else{
							trace('请至少选择一个小组');
						}
					});
					
					ox.die('click').live('click',function(){
						o.close();
					});
				});
		}
	});
	
	// Note 拣回来
	$('a[title=拣回来]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/home/recycle/' + $nid + '/restore.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
						fresh();
					});
				}
			}
		});
	});
	
	// Note 彻底删除
	$('a[name=remove]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/home/recycle/' + $nid + '/remove.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
						fresh();
					});
				}
			}
		});
	});
	
	// 回收站 -- 清空
	$('[name=recycle]').die('click').live('click',function(){
		var $this = $(this),
			$href = $this.attr('href');
		confirm('真的要把废纸篓清空吗？',function(){
			window.location.href = $href;
		});
		return;
	});
	
	// 撤消小组
	$('[name=dismiss]').die('click').live('click',function(event){
		var $this = $(this),
			$href = $this.attr('href'),
			$num  = $this.attr('num');
		if( Number($num) > 1 ){
			trace('请先将全部小组成员移除');
			return;
		}
		else{
			confirm('确定解散该小组吗？',function(){
				trace('解散小组成功',function(){
					window.location.href = $href;
				});
			});
			event = event || window.event;
			event.cancelBubble = true;
			event.stopPropagation();
			return false;
		}
	});
	
	// Note 发布
	$('a[title=发布]').die('click').live('click',function(){
		var $this = $(this),
			$nid  = $this.parents('[nid]').attr('nid');
		$.fn.ipop.operat({
			pond : $this,
			dir  : 'left',
			turn : 0,
			speed: 100,
			url   : iknowing_domain + '/note/'+$nid+'/release.html'
		},function(){
			var $url     = iknowing_domain + '/note/' + $nid + '.html',
				$title   = $('#rel_title').val(),
				$content = $('rel_des').val();
			$('.release a').each(function(){
				var $this = $(this),
					$href;
				switch( $this.attr('tip') ){
					case '新浪' :
						$href = "javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://v.t.sina.com.cn/share/share.php?appkey=576112064',u=z||'"+$url+"',p=['&url=',e(u),'&title=',e(t||'"+$title+"'),'&source=',e(r),'&sourceUrl=',e(l),'&content="+$content+"',c||'gb2312','&pic=',e(p||'')].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();})(screen,document,encodeURIComponent,'','','','','','utf-8'));";
						$this.attr('href',$href);
						break;
					case '腾讯微博' :
						$href = "http://v.t.qq.com/share/share.php?url="+$url+"&title="+$title+"&source=1000014&site=http://www.iknowing.com";
						$this.attr({'href':$href,'target':'_new'});
						break;
					case '开心网' :
						$href = "javascript:window.open('http://www.kaixin001.com/repaste/share.php?rtitle="+$title+"&rurl="+$url+"&rcontent="+$content+"','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0";
						$this.attr('href',$href);
						break;
					case '人人' :
						$href = "http://share.renren.com/share/buttonshare.do?link="+encodeURIComponent($url)+"&title="+$title;
						$this.attr({'href':$href,'target':'_new'});
						break;
					case '搜狐' :
						$href = "javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://t.sohu.com/third/post.jsp?',u=z||'"+$url+"',p=['&url=',e(u),'&title=',e(t||'"+$title+"'),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=660,height=470,left=',(s.width-660)/2,',top=',(s.height-470)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();})(screen,document,encodeURIComponent,'','','','','','utf-8'));";
						$this.attr('href',$href);
						break;
					default : trace('tip is error !!'); break;
				}
			});
		});
	});
	
	// Invite Site
	$('a[name=invite_site]').die('click').live('click',function(){
		$.fn.ipop.popup({
			width : 480,
			height: 300,
			speed : 'fast',
			title : '站外邀请',
			url   : iknowing_domain + '/invite/site.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			oc.die('click').live('click',function(){
				var $mail    = $('#inv_mail').val(),
					$title   = $('#inv_title').val(),
					$content = $('#inv_content').val();
				
				/*
				if( !mailReg.test($mail) ){
					trace('请输入正确的Email地址');
					return;
				}
				*/
				if( $title == '' ){
					trace('请输入邮件标题');
					return;
				}
				if( $content == '' ){
					trace('请输入邮件正文');
					return;
				}
				
				$.ajax({
					type    : 'POST',
					url     : iknowing_domain + '/invite/site.html',
					data    : 'email='+$mail+'&title='+$title+'&content='+$content,
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('邀请发送成功',function(){
								o.close();
							});
						}
					}
				});
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	$('#file').die('change').live('change',function(){
		$('.cosfile').val( $(this).val() );
	});
	
	// File Upload
	$('#osfileupload').die('click').live('click',function(){
		var $img = $('#ofile').val(),
			$nid = $(this).parents('[nid]').attr('nid'),
			$id  = 'ofile';
		$img == '' ?
			trace('请选择文件') :
			$.fn.fileupload( iknowing_domain + '/note/' + $nid + '/upload/attachment.html' , $id , function( data ){
				trace('上传成功');
				var html  = '';
					html += '<li attId="'+data.attId+'">';
					html += '<a name="atta_del" class="atta_close" href="javascript:;"></a>';
					html += '<b class="atta_capacity">'+data.attSize+'k</b>';
					html += '<a class="atta_name">'+data.attName+'</a>';
					html += '</li>';
					html = $(html);
				$('.avacont').after(html);
				html.hide(0).slideDown('normal');
			});
	});
	
	// File Batch Upload
	$('#batch_upload').die('click').live('click',function(){
		$.fn.ipop.popup({
			width : 480,
			height: 320,
			speed : 'fast',
			title : '批量上传附件',
			url   : iknowing_domain + '/attachment/upload/go.html'
		},function( o ){
			var ox = $('.button_gray[name=取消]');
			ox.die('click').live('click',function(){
				o.close();
			});
			
			var upurl = iknowing_domain + '/note/' + $('#windows_content').attr('nid') + '/upload/attachment.html';
			$('#uploadform').attr('action',upurl);
			
			var swfu = new SWFUpload({
				flash_path : iknowing_domain + "/swfupload.swf",
				target : "SWFUploadTarget",
				upload_url : upurl,
				file_post_name : 'Filedata',
				post_params : {"IKNOWING_COOKIE" : $('#getsessionid').val()},
				file_size_limit : "5 MB",
				file_types : "*.*",
				file_types_description : "All Files",
				file_upload_limit : 10,
				file_queue_limit : 10,
				custom_settings : {
					progressTarget : "fsUploadProgress",
					cancelButtonId : "btnCancel"
				},
				debug: false,
				
				// Button settings
				button_image_url: iknowing_domain + "/uploadbutton.png",
				button_width: "61",
				button_height: "22",
				button_placeholder_id: "spanButtonPlaceHolder",
				button_text: '<span class="theFont"></span>',
				button_text_style: ".theFont { font-size: 16; }",
				button_text_left_padding: 12,
				button_text_top_padding: 3,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : fileQueued,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_start_handler : uploadStart,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccessAttach,
				upload_complete_handler : uploadComplete,
				queue_complete_handler : BatchImgCallback	// Queue plugin event
			});
			
			// Callback
			function BatchImgCallback(){
				o.close();
			}
		});
	});
	
	// File Delete
	$('[name=atta_del]').die('click').live('click',function(){
		var $object = $(this).parents('[attId]'),
			$attId  = $object.attr('attId');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/attachment/' + $attId + '/delete.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$object.slideUp('normal',function(){
						$object.remove();
					});
				}
			}
		});
	});
	
/* **
 * Group
 * -------- -------- --------
 */
	// Group Manage Logo Upload
	$('#gm_logo_up').die('click').live('click',function(){
		var $img = $('#gfile').val(),
			$gid = $('[gid]').attr('gid'),
			$id  = 'gfile';
		$img == '' ?
			trace('请选择图片') :
			$.fn.fileupload( iknowing_domain + '/group/' + $gid + '/logo.html' , $id , function( data ){
				trace('上传成功');
				$('#group_img').attr('src',static_logo + '/group/' + data.imageUrl + '?' + new Date().getTime());
			});
	});
	
	// Group Approval Manage - Pass
	$('#ga_pass').die('click').live('click',function(){
		var $this = $(this),
			$mid = $this.parents('[mid]').attr('mid');
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/group/'+$mid+'/pass.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
					});
				}
			}
		});
	});
	
	// Group Approval Manage - Miss
	$('#ga_miss').die('click').live('click',function(){
		var $this = $(this),
			$mid = $this.parents('[mid]').attr('mid');
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/group/'+$mid+'/delete.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
					});
				}
			}
		});
	});
	
	// Group Approval Manage - Delet
	$('#ga_delect').die('click').live('click',function(){
		var $mmi = $('#mmi input:checked'),
			$gid = $('[gid]').attr('gid'),
			$mid = [];
		
		$mmi.each(function(){
			$mid.push( $(this).parents('[mid]').attr('mid') );
		});
		
		if( $mmi.length <= 0 ){
			trace('请选择成员');
			return;
		}
		else{
			$.ajax({
				type    : 'POST',
				url     : iknowing_domain + '/group/member/delete.html',
				data    : 'membershipIds='+$mid+'&groupId='+$gid,
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$mmi.each(function(){
							$(this).parents('[mid]').slideUp('normal',function(){
								$(this).parents('[mid]').remove();
							});
						});
					}
				}
			});
		}
	});
	
	// 小组 -- 加入小组
	$('[name=group_add]').die('click').live('click',function(){
		var $gid = $(this).parents('[gid]').attr('gid');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/group/' + $gid + '/apply.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('申请成功',function(){
						fresh();
					});
				}
			}
		});
	});
	
	// 小组 -- 退出小组
	$('[name=quitgroup]').die('click').live('click',function(){
		var $gid = $(this).parents('[gid]').attr('gid');
		confirm('是否确认退出此小组？',function(){
			$.ajax({
				type    : 'POST',
				url     : iknowing_domain + '/group/' + $gid + '/quit.html',
				data    : '',
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						trace('退出成功',function(){
							fresh();
						});
					}
				}
			});
		});
	});
	
	// 小组 -- 群员查看详细
	$('[name=infodetail]').die('click').live('click',function(){
		var $uid = $(this).parents('[uid]').attr('uid');
		$.fn.ipop.popup({
			width : 720,
			height: 500,
			speed : 'fast',
			title : '查看详细',
			url   : iknowing_domain + '/user/' + $uid + '/info/detail.html'
		},function( o ){
			var ox = $('.button_gray[name=取消]');

			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});

/* **
 * Friend
 * -------- -------- --------
 */
	// 朋友 -- 接受
	$('a[name=frd_acc]').die('click').live('click',function(){
		var $object = $(this).parents('[uid]'),
			$uid    = $object.attr('uid');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/friend/accept.html?rid=' + $uid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('接受好友成功',function(){
						$object.slideUp('normal',function(){
							$object.remove();
							var $frd_my     = $('#frd_my b'),
								$frd_my_num = Number( $frd_my.text() ),
								$frd_qq     = $('#frd_qq b'),
								$frd_qq_num = Number( $frd_qq.text() );
							$frd_my_num++;
							$frd_qq_num--;
							$frd_my.html( $frd_my_num );
							$frd_qq.html( $frd_qq_num );
						});
					});
				}
			}
		});
	});

	// 朋友 -- 拒绝
	$('a[name=frd_rej]').die('click').live('click',function(){
		var $object = $(this).parents('[uid]'),
			$uid    = $object.attr('uid');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/friend/reject.html?rid=' + $uid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$object.slideUp('normal',function(){
						$object.remove();
						var $frd_qq     = $('#frd_qq b'),
							$frd_qq_num = Number( $frd_qq.text() );
						$frd_qq_num--;
						$frd_qq.html( $frd_qq_num );
					});
				}
			}
		});
	});

	// 朋友 -- 添加
	$('a[name=frd_add]').die('click').live('click',function(){
		var $object = $(this).parents('[uid]'),
			$uid    = $object.attr('uid');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/friend/add.html?rid=' + $uid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('请求发送成功');
				}
			}
		});
	});

	// 朋友 -- 删除
	$('a[name=frd_del]').die('click').live('click',function(){
		var $object = $(this).parents('[uid]'),
			$uid    = $object.attr('uid');
		confirm('是否确认解除此好友？',function(){
			$.ajax({
				type    : 'POST',
				url     : iknowing_domain + '/friend/delete.html?fid=' + $uid,
				data    : '',
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						trace('解除好友成功',function(){
							$object.slideUp('normal',function(){
								$object.remove();
								var $frd_my     = $('#frd_my b'),
									$frd_my_num = Number( $frd_my.text() );
								$frd_my_num--;
								$frd_my.html( $frd_my_num );
							});
						});
					}
				}
			});
		});
	});
	
	// 朋友 -- 查询
	$('[name=dofrdsearch]').die('click').live('click',function(){
		var	$this = $(this),
			$searchtype = false,
			$form = $('[name=frdsearchform]');
		$form.find(':text').each(function(){
			if( $(this).val().length > 0 ){
				$searchtype = true;
				return;
			}
		});
		$searchtype ?
			$form.submit():
			trace('请至少选填一项');
		return false;
	});

/* **
 * Community
 * -------- -------- --------
 */

	// Community Manage Logo Upload
	$('#cm_logo_up').die('click').live('click',function(){
		var $img    = $('#cfile').val(),
			$commid = $('[commid]').attr('commid'),
			$id     = 'cfile';
		$img == '' ?
			trace('请选择图片') :
			$.fn.fileupload( iknowing_domain + '/community/' + $commid + '/logo.html' , $id , function( data ){
				trace('上传成功');
				$('#community_img').attr('src',static_logo + '/community/' + data.imageUrl + '?' + new Date().getTime());
			});
	});

	// Community Approval Manage - Pass
	$('#comm_pass').die('click').live('click',function(){
		var $this   = $(this),
			$commid = $this.parents('[commid]').attr('commid'),
			$enid   = $this.parents('[enid]').attr('enid');
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/community/'+$enid+'/pass.html?communityId=' + $commid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
					});
				}
			}
		});
	});
	
	// Community Approval Manage - Miss
	$('#comm_miss').die('click').live('click',function(){
		var $this   = $(this),
			$commid = $this.parents('[commid]').attr('commid'),
			$enid   = $this.parents('[enid]').attr('enid');
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/community/'+$enid+'/delete.html?communityId=' + $commid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.parents('li').slideUp('normal',function(){
						$this.parents('li').remove();
					});
				}
			}
		});
	});

	// Community Approval Manage - Delet
	$('#comm_delect').die('click').live('click',function(){
		var $mmi    = $('#mmi input:checked'),
			$commid = $('[commid]').attr('commid'),
			$enid   = [];
		
		$mmi.each(function(){
			$enid.push( $(this).parents('[enid]').attr('enid') );
		});
		
		if( $enid.length <= 0 ){
			trace('请选择成员');
			return;
		}
		else{
			$.ajax({
				type    : 'POST',
				url     : iknowing_domain + '/community/member/delete.html',
				data    : 'memberIds='+$enid+'&communityId='+$commid,
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$mmi.each(function(){
							$(this).parents('[enid]').slideUp('normal',function(){
								$(this).parents('[enid]').remove();
							});
						});
					}
				}
			});
		}
	});
	
	// 社区 -- 登录验证
	var account  = false;
	
	/* 用户名 -- 焦点移出事件 */
	$('[name=usr]').die('focusout').live('focusout',function(){
		var $usr    = $('[name=usr]').val(),
			$usrverific = $('[name=usrverific]');
		verification({
			'url'  : '/check/login.html',
			'data' : 'usr=' + $usr,
			'vero' : $usrverific,
			'text' : '请核对用户名^-^'
		});
	});
	
	/* 密码 -- 焦点移出事件 */
	$('[name=pwd]').die('focusout').live('focusout',function(){
		var $usr    = $('[name=usr]').val(),
			$pwd    = $('[name=pwd]').val(),
			$pwdverific = $('[name=pwdverific]');
		verification({
			'url'  : '/check/password.html',
			'data' : 'usr=' + $usr + '&pwd=' + $pwd,
			'vero' : $pwdverific,
			'text' : '请核对密码^-^'
		});
	});
	
	$('#communitylogin').die('click').live('click',function(event){
		var	$this   = $(this),
			$usr    = $('[name=usr]').val(),
			$pwd    = $('[name=pwd]').val(),
			$usrverific = $('[name=usrverific]'),
			$pwdverific = $('[name=pwdverific]');
		
		verification({
			'url'  : '/check/login.html',
			'data' : 'usr=' + $usr,
			'vero' : $usrverific,
			'text' : '请核对用户名^-^'
		});
		verification({
			'url'  : '/check/password.html',
			'data' : 'usr=' + $usr + '&pwd=' + $pwd,
			'vero' : $pwdverific,
			'text' : '请核对密码^-^'
		});
		
		if( account ){
			$this.submit();
			return true;
		}
		
		event.stopPropagation();
		return false;
	});
	
	/* 注册 -- 用户名验证 */
	$('#communityregister').die('focusout').live('focusout',function(){
		var	$usr    = $('[name=usr]').val(),
			$usrverific = $('[name=usrverific]');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/check/register.html',
			data    : 'usr=' + $usr,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ){
					$usrverific.removeClass().addClass('red').html('该用户名已被占用');
				}
				else{
					$usrverific.removeClass().addClass('green').html('恭喜!该用户名可以使用~');
				}
			}
		});
	});
	
	/* 验证方法 */
	var verification = function( params ){
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + params.url,
			data    : params.data,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ){
					params.vero.show(0).removeClass().addClass('no').html(params.text);
					account = false;
				}
				else{
					params.vero.hide(0).removeClass().html('');
					account = true;
				}
			}
		});
	}
	
	// 社区 -- 设置专题
	$('[name=setotopics]').die('click').live('click',function(){
		var $this   = $(this),
			$type   = $this.attr('type'),
			$commid = $this.parents('[commid]').attr('commid'),
			$uid    = $this.parents('[uid]').attr('uid');
		
		switch( $type ){
			case 'no' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/feature/subject/' + $uid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','yes').html('取消设为活跃用户');
						}
					}
				});
			break;
			case 'yes' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/unfeature/subject/' + $uid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','no').html('设为活跃校友');
						}
					}
				});
			break;
			default : trace('Type Error !!'); break;
		}
	});
	
	// 社区 -- 置顶到首页 -- 小组
	$('[name=setoindex]').die('click').live('click',function(){
		var $this   = $(this),
			$type   = $this.attr('type'),
			$commid = $this.parents('[commid]').attr('commid'),
			$gid    = $this.parents('[gid]').attr('gid');
		
		switch( $type ){
			case 'no' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/feature/group/' + $gid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','yes').html('取消置顶到首页');
						}
					}
				});
			break;
			case 'yes' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/unfeature/group/' + $gid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','no').html('置顶到首页');
						}
					}
				});
			break;
			default : trace('Type Error !!'); break;
		}
	});

	// 社区 -- 置顶到首页 -- 知识
	$('[name=knowledgetoindex]').die('click').live('click',function(){
		var $this   = $(this),
			$type   = $this.attr('type'),
			$commid = $this.parents('[commid]').attr('commid'),
			$nid    = $this.parents('[nid]').attr('nid');
		
		switch( $type ){
			case 'no' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/feature/note/' + $nid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','yes').html('取消置顶到首页');
						}
					}
				});
			break;
			case 'yes' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/unfeature/note/' + $nid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','no').html('置顶到首页');
						}
					}
				});
			break;
			default : trace('Type Error !!'); break;
		}
	});

	// 社区 -- 置顶到首页 -- 活动
	$('[name=setoindexa]').die('click').live('click',function(){
		var $this   = $(this),
			$type   = $this.attr('type'),
			$commid = $this.parents('[commid]').attr('commid'),
			$actid  = $this.parents('[actid]').attr('actid');
		
		switch( $type ){
			case 'no' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/feature/activity/' + $actid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','yes').html('取消置顶到首页');
						}
					}
				});
			break;
			case 'yes' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/community/' + $commid + '/unfeature/activity/' + $actid + '.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							$this.attr('type','no').html('置顶到首页');
						}
					}
				});
			break;
			default : trace('Type Error !!'); break;
		}
	});
	
	// 社区 -- 知识社区 -- 屏蔽文章
	$('[name=shield]').die('click').live('click',function(){
		//{communityId}/{noteId}/private.html
		var $this   = $(this),
			$nid    = $this.parents('[nid]').attr('nid'),
			$commid = $this.parents('[commid]').attr('commid');
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/community/' + $commid + '/' + $nid + '/private.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('屏蔽文章成功',function(){
						$this.parents('li').slideUp('normal',function(){
							$(this).remove();
						});
					});
				}
			}
		});
	});
	
	// 社区 -- 创建 -- 选择社区关联分类
	$('#asssubject').die('change').live('change',function(){
		var $this   = $(this),
			$commid = $this.val();
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/group/subject.html?communityId='+$commid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					var $sub = data.subjects,
						html = '';
					for( var i=$sub.length ; i-- ; ){
						html += '<option value="'+$sub[i].subjectId+'">'+$sub[i].name+'</option>';
					}
					$('#subjectId').html(html);
				}
			}
		});
	});
	
	// 社区 -- 活跃小组
	$('#commact a').die('click').live('click',function(){
		var $this   = $(this),
			$object = $('#subjectgroup'),
			$subid  = $this.attr('subid');
		$object.load(iknowing_domain + '/community/subject/' + $subid + '/group.html',function(){
			$this.parent().siblings().removeClass('on');
			$this.parent().addClass('on');
		});
	});
	
	// 社区 -- 焦点图
	$(function(){
		var $slider  = $('#slidImg');
		
		if( $slider.length >= 1 ){
			
			var $imag    = $slider.find('ul'),
				$menu    = $slider.find('.slidMenu'),
				$distanc = 250,
				$max     = $imag.find('li').length,
				$time    = 6000,
				$count   = 0,
				interval;
			
			function doSlide( $type ){
				if( !isNaN($type) )
					$type = 'right';
				if( $type==undefined )
					menuHighlight( $count );
				
				if( $type == 'right' )
					$count >= $max-1 ? $count = 0 : $count++;
					
				if( $type == 'left' )
					$count <= 0 ? $count = $max-1 : $count--;
				
				$imag.stop().animate({
					'top' : -($count*$distanc)
				});
				if( $type!=undefined ){
					menuHighlight( $count );
				}
			}
			
			interval = setInterval( doSlide , $time );
				
			for( var i=1 ; i<=$imag.find('li').length ; i++ )
				$menu.append('<a href="javascript:;">'+i+'</a>');
			$menu = $menu.find('a');
			$menu.eq(0).addClass('on');
			
			$menu.hover(
				function(){
					var $this  = $(this),
						$index = $this.index();
					$count = $index;
					menuHighlight( $count );
					clearInterval( interval );
					doSlide();
				},
				function(){
					interval = setInterval( doSlide , $time );
				}
			);
			function menuHighlight( index ){
				$menu.removeClass('on');
				$menu.eq(index).addClass('on');
			}
		}
	});
	
	// 社区 -- 无缝滚动
	$(function(){
		var interval = setInterval( doAnimate , 4000 );
		
		function doAnimate(){
			var $ul = $('#seamless ul'),
				$li = $('#seamless li').eq(0);
			$ul.stop().animate({
				'top' : -$li.height()
			},function(){
				$li.appendTo($ul);
				$ul.css('top',0);
			});
		}
	});

/* **
 * User
 * -------- -------- --------
 */
	// Detail -- 发布到第三方
	$('[name=dfb] a').die('click').live('click',function(){
		var	$this = $(this),
			$url     = iknowing_domain + '/note/' + $this.parents('[nid]').attr('nid') + '.html',
			$title   = $('.nd_title bdo').html(),
			$content = $('.nd_des p').html(),
			$href;
	
		switch( $this.attr('tip') ){
			case '新浪' :
				$href = "javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://v.t.sina.com.cn/share/share.php?appkey=576112064',u=z||'"+$url+"',p=['&url=',e(u),'&title=',e(t||'"+$title+"'),'&source=',e(r),'&sourceUrl=',e(l),'&content="+$content+"',c||'gb2312','&pic=',e(p||'')].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();})(screen,document,encodeURIComponent,'','','','','','utf-8'));";
				$this.attr('href',$href);
				break;
			case '腾讯微博' :
				$href = "http://v.t.qq.com/share/share.php?url="+$url+"&title="+$title+"&source=1000014&site=http://www.iknowing.com";
				$this.attr({'href':$href,'target':'_new'});
				break;
			case '开心网' :
				$href = "javascript:window.open('http://www.kaixin001.com/repaste/share.php?rtitle="+$title+"&rurl="+$url+"&rcontent="+$content+"','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0";
				$this.attr('href',$href);
				break;
			case '人人' :
				$href = "http://share.renren.com/share/buttonshare.do?link="+encodeURIComponent($url)+"&title="+$title;
				$this.attr({'href':$href,'target':'_new'});
				break;
			case '搜狐' :
				$href = "javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://t.sohu.com/third/post.jsp?',u=z||'"+$url+"',p=['&url=',e(u),'&title=',e(t||'"+$title+"'),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=660,height=470,left=',(s.width-660)/2,',top=',(s.height-470)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else a();})(screen,document,encodeURIComponent,'','','','','','utf-8'));";
				$this.attr('href',$href);
				break;
			default : trace('tip is error !!'); break;
		}
	});
	
	// Detail -- 发表评论
	$('#report').die('click').live('click',function(){
		var $object  = $('#report_cont'),
			$content = $object.val(),
			$nid     = $(this).parents('[nid]').attr('nid'),
			$weibo   = false,
			$noteUrl = encodeURIComponent(window.location.href);
		
		if( $content == '' ){
			trace('评论内容不能为空');
			return;
		}
		if( $content.length > 140 ){
			trace('评论至多只能输入140字哟');
			return;
		}
		$('.towb :checked').length == 1 ?
			$weibo = true :
			$weibo = false;
		
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/note/' + $nid + '/comment.html',
			data    : 'content='+$content + '&toWeibo=' + $weibo + '&noteUrl=' + $noteUrl,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$object.empty();
					var $o    = $('.comment_send'),
						$url  = $o.find('.name').attr('href'),
						$name = $o.find('.name').html(),
						$img  = $o.find('img').attr('src'),
						$num  = Number($('[name=comment_num] b').html()); $num++;
					
					var html  = '';
						html += '<li>';
						html += '<div class="avatar">';
						html += '<a href="'+$url+'"><img src="'+$img+'"></a>';
						html += '</div>';
						html += '<div class="avatar_cot">';
						html += '<a href="'+$url+'">'+$name+'</a>：'+$content;
						html += '<div class="time dim">'+data.createTime+'</div>';
						html += '</div>';
						html += '</li>';
						html = $(html);
					
					$object.val('');
					$('[name=comment_num] b').html( $num );
					$('[name=comm_show_list] ul').prepend(html);
					html.hide(0).slideDown('normal',function(){
						fresh();
					});
				}
			}
		});
	});
	
	// Detail -- 删除评论
	$('[name=commclose]').die('click').live('click',function(){
		var $this = $(this);
		confirm('确定删除这条评论吗？',function(){
			var	noteid = $this.attr('noteid'),
				commid = $this.attr('commid');
			$.ajax({
				type    : 'POST',
				url     : iknowing_domain + '/comment/deleteComment.html',
				data    : 'noteId='+noteid+'&commentId='+commid,
				success : function(data){
					data = eval('(' + data + ')');
					if( data.error == 'true' ) trace( data.msg )
					else{
						$this.parents('li').slideUp('normal',function(){
							fresh();
						});
					}
				}
			});
		});
	});
	
	// 评论发邮件
	$('[name=attend]').change(function(){
		var $this  = $(this),
			$nid   = $this.attr('noteid'),
			$type  = $this.attr('checked'), // checked
			$url   = '',
			$hello = '';
		
		switch( $type ){
			case 'checked' :
				$url = iknowing_domain + '/note/' + $nid + '/follow.html';
				$hello = '关注成功!';
				break;
			case undefined :
				$url = iknowing_domain + '/note/' + $nid + '/follow/quit.html';
				$hello = '取消关注成功';
				break;
			default : trace('check type is error !!');
		}
		
		$.ajax({
			type    : 'POST',
			url     : $url,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace( $hello );
				}
			}
		});
	});

/* **
 * Message
 * -------- -------- --------
 */

	// 消息定时器
	//$.fn.imstips();

	// 消息 -- 发送
	$('[name=send_msg]').die('click').live('click',function(){
		var	$$this = $(this),
			$friendId = $$this.parents('[fid]').attr('fid');
		$.fn.ipop.popup({
			width : 480,
			height: 260,
			speed : 'fast',
			title : '消息发送',
			url   : iknowing_domain + '/msg/' + $friendId + '/send.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			// 好友页面 -- 拿User Name判断
			$$this.parent().attr('fid') == undefined ?
				$('#msg_human').attr('fid',$friendId).html( $('[name=usr_name]').html() ) :
				$('#msg_human').attr('fid',$friendId).html( $('.archel_name').html() ) ;

			oc.die('click').live('click',function(){
				var $msg = $('#msg_content').val();
				if( $msg.length <= 0 ){
					trace('消息内容不能为空');
					return;
				}
				if( $msg.length > 140 ){
					trace('消息内容至多140字');
					return;
				}
				
				$.ajax({
					type    : 'POST',
					url     : iknowing_domain + '/msg/' + $friendId + '/send.html',
					data    : 'msg=' + $msg,
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('消息发送成功',function(){
								o.close();
							});
						}
					}
				});
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// 批量给好友发消息
	$('[name=msgtofrd]').die('click').live('click',function(){
		$.fn.ipop.popup({
			width : 640,
			height: 360,
			speed : 'fast',
			title : '消息发送',
			url   : iknowing_domain + '/feed/allfriend.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]'),
				db = $(document.body),
				mask = $('<div class="mtfmask"></div>');
			oc.die('click').live('click',function(){
				var $msg = $('#mtfcont').val();
				if( $msg.length <= 0 ){
					trace('消息内容不能为空');
					return;
				}
				if( $msg.length > 140 ){
					trace('消息内容至多140字');
					return;
				}
				db.prepend(mask);
				var frdarr = $('#frdlist').find('input:checked');
				
				for(var i=frdarr.length; i--;){
					$.ajax({
						type    : 'POST',
						url     : iknowing_domain + '/msg/' + frdarr.eq(i).val() + '/send.html',
						data    : 'msg=' + $msg,
						success : function(data){
							data = eval('(' + data + ')');
							if( data.error == 'true' ) trace( data.msg )
							else{
								if(i==0){
									mask.remove();
									trace('消息发送成功',function(){
										o.close();
									});
								}
							}
						}
					});
				}
				
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// 短信 -- 选择用户发送
	$('[name=dosendsms]').die('click').live('click',function(){
		var $this          = $(this),
			$oid           = $this.attr('oid'),
			$contents      = $('#smscontents').val(),
			$membercheck   = $('#tosmsmember input:checked').not($('#mm_all_check')[0]),
			$mobileNumbers = '',
			$url = iknowing_domain + '/' + $this.attr('sendtype') + '/' + $oid + '/member/managemsg.html';
		
		for( var i=0; i<$membercheck.length; i++ ){
			$mobileNumbers += $membercheck.eq(i).val() + ',';
		}
		
		if( $contents.length <= 0 || $contents.length > 100 ){
			trace('短信内容为1-100个字');
			return;
		}
		if( $membercheck.length <= 0 ){
			trace('请至少选择一位用户');
			return;
		}
		$.ajax({
			type    : 'POST',
			url     : $url,
			data    : 'contents=' + $contents + '&mobileNumbers=' + $mobileNumbers,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('短信发送成功');
				}
			}
		});
	});
	
	// 短信 -- 群发 -- 全选
	$(function(){
		var memberAll = $('[name=memberAll]'),
			checkAll  = memberAll.find('#mm_all_check'),
			checks    = memberAll.find('input:checkbox').not(checkAll);
		checkAll.change(function(){
			$(this).attr('checked') ?
				checks.attr('checked',true):
				checks.attr('checked',false);
		});
		checks.change(function(){
			if($(this).attr('checked')){
				if(memberAll.find('input:checked').not(checkAll).length==checks.length)
					checkAll.attr('checked',true);
			}
			else{
				checkAll.attr('checked',false);
			}
		});
	});
	
	// 短信 -- 群发
	$('[name=dosms]').die('click').live('click',function(){
		var	$this = $(this),
			$commid = $this.parents('[commid]').attr('commid');
		$.fn.ipop.popup({
			width : 480,
			height: 212,
			speed : 'fast',
			title : '短信群发',
			url   : iknowing_domain + '/community/' + $commid + '/msg/pop.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			oc.die('click').live('click',function(){
				var $cont = $('#sms_content').val();
				
				if( $cont.length <= 0 ){
					trace('请填写短信内容');
					return;
				}
				if( $cont.length > 100 ){
					trace('短信内容至多不能超过100字');
					return;
				}
				
				$.ajax({
					type    : 'POST',
					url     : iknowing_domain + '/community/' + $commid + '/member/managemsg.html',
					data    : 'contents=' + $cont,
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('短信发送成功',function(){
								o.close();
							});
						}
					}
				});
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
		});
	});
	
	// 消息 -- 删除
	$('[name=msg_del]').die('click').live('click',function(){
		var $this = $(this).parents('[mid]'),
			$mid = $this.attr('mid');
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/msg/' + $mid + '/delete.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.slideUp('normal',function(){
						$this.remove();
						fresh();
					});
				}
			}
		});
	});
	
	// 消息 -- 回复
	$('[name=msg_reply]').die('click').live('click',function(){
		var $mid = $(this).attr('mid'),
			$msg = $('#msg_content').val();
		if( $msg.length <= 0 ){
			trace('消息内容不能为空');
			return;
		}
		if( $msg.length > 140 ){
			trace('消息内容至多140字');
			return;
		}
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/msg/' + $mid + '/reply.html',
			data    : 'msg=' + $msg,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					fresh();
				}
			}
		});
	});

/* **
 * Activity
 * -------- -------- --------
 */
	// 活动 -- 参加活动
	$('a[name=join]').die('click').live('click',function(){
		var $this  = $(this),
			$actId = $this.parents('[actid]').attr('actid');
		
		switch( $this.attr('type') ){
			case 'no' : 
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/activity/' + $actId + '/join.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('报名成功',function(){
								$this.attr({
									'type'  : 'yes',
									'class' : 'isjoin'
								});
							});
							var $num = Number( $this.find('b').text() ); $num++;
							$this.find('b').html( $num );
							$this.html( $this.html().replace('报名','取消报名') );
						}
					}
				});
				break;
			case 'yes' :
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/activity/' + $actId + '/disjoin.html',
					data    : '',
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('取消报名成功',function(){
								$this.attr({
									'type'  : 'no',
									'class' : 'join'
								});
							});
							var $num = Number( $this.find('b').text() ); $num--;
							$this.find('b').html( $num );
							$this.html( $this.html().replace('取消报名','报名') );
						}
					}
				});
				break;
			default : trace('type error !!'); break;
		}
	});
	
	// 活动 -- 创建の图标上传 /afile
	$('#activity_fileupload').die('click').live('click',function(){
		var	$aid = $('[aid]').attr('aid'),
			$img = $('#afile').val(),
			$id  = 'afile';
		$img == '' ?
			trace('请选择图片') :
			$.fn.fileupload( iknowing_domain + '/activity/' + $aid + '/logo.html' , $id , function( data ){
				trace('上传成功');
				$('#activity_head').attr('src',data.imageUrl + '?' + new Date().getTime());
			});
	});

/* **
 * Setting
 * -------- -------- --------
 */
	// 设置 -- 提醒
	$('[name=doremind]').die('click').live('click',function(){
		var $object = $('#remindform'),
			$data   = '';
		$object.find(':checkbox').each(function(){
			var $this = $(this),
				$name = $this.attr('name');
			
			$this.attr('checked') == 'checked' ?
				$data += '&' + $name + '=true' :
				$data += '&' + $name + '=false';
		});
		$data = $data.replace(/^./,'');
		
		// remindid uid
		$data += '&remindId=' + $('#remindId').val() + '&uid=' + $('#uid').val();
		
		$.ajax({
			type    : 'POST',
			url     : iknowing_domain + '/setting/remind.html',
			data    : $data,
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('设置成功',function(){
						fresh();
					});
				}
			}
		});
		return false;
	});
	
	// 设置 -- 头像上传
	$('#head_fileupload').die('click').live('click',function(){
		var $img = $('#hfile').val(),
			$id  = 'hfile';
		$img == '' ?
			trace('请选择图片') :
			$.fn.fileupload( iknowing_domain + '/setting/avatar.html' , $id , function( data ){
				trace('上传成功');
				$('#user_head').attr('src',data.imageUrl + '?' + new Date().getTime());
			});
	});
	
	// 设置 -- 应用
	$('#setap_select').change(function(){
		var $cid = $(this).val();
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/setting/app/category.html?cid=' + $cid,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					trace('修改成功');
				}
			}
		});
	});
	
	// 设置 -- 自动邮箱
	$('#automail').die('click').live('click',function(){
		var $this = $(this);
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/setting/app/hzmail.html',
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{
					$this.prev().html(data.newAddress);
				}
			}
		});
	});
	
	// 设置 -- 提醒邮件
	$('#remindmail').change(function(){
		var $accept = $(this).attr('checked');
		$accept == 'checked' ? $accept = true : $accept = false;
		$.ajax({
			type    : 'GET',
			url     : iknowing_domain + '/setting/app/accept.html?accept='+$accept,
			data    : '',
			success : function(data){
				data = eval('(' + data + ')');
				if( data.error == 'true' ) trace( data.msg )
				else{}
			}
		});
	});

	// Detail -- 评论 -- 剩余字数
	$('#report_cont').maxTxT($('.surplus'),140);
	
	// Message -- 回复 -- 剩余字数
	$('#msg_content').maxTxT($('.surplus'),140);
	
	// All Node If Has Href
	$('*[name=ja]').die('click').live('click',function(){
		var $this = $(this);
		$this.css({
			'cursor' : 'point'
		});
		if( $this.children(':text').length > 0 ){
			return;
		}
		else{
			window.location.href = $(this).attr('href');
		}
	});

/* **
 * Index
 * -------- -------- --------
 */

	// 找回密码
	$('[name=find_password]').die('click').live('click',function(){
		$.fn.ipop.popup({
			width : 480,
			height: 108,
			speed : 'fast',
			title : '找回密码',
			url   : iknowing_domain + '/password/find/go.html'
		},function( o ){
			var oc = $('.button_green[name=提交]'),
				ox = $('.button_gray[name=取消]');
			
			oc.die('click').live('click',function(){
				var your_username = $('#your_username').val();
				$.ajax({
					type    : 'GET',
					url     : iknowing_domain + '/password/find.html',
					data    : 'login='+your_username,
					success : function(data){
						data = eval('(' + data + ')');
						if( data.error == 'true' ) trace( data.msg )
						else{
							trace('请至<b class="sky">'+data.email+'</b>邮箱查看密码',function(){
								o.close();
							},8000);
						}
					}
				});
			});
			
			ox.die('click').live('click',function(){
				o.close();
			});
			
		});
	});

/* **
 * User
 * -------- -------- --------
 */

	// About User
	$.fn.ipop.marvel();

/* **
 * Picture Wall
 * -------- -------- --------
 */

	if( $('#picwall').length > 0 ){
		var $href = window.location.href;
		$href = $href.replace('image_wall','wall');
		$.fn.picwall({
			'url'    : $href,
			'pondo'  : $('#picwall'),
			'swidth' : 230,
			'size'   : 18
		});
	}
	else if( $('#picwalleseebaby').length > 0 ){
		var $href = window.location.href;
		$href = $href.replace('image_wall','wall');
		$.fn.picwalleseebaby({
			'url'    : $href,
			'pondo'  : $('#picwalleseebaby'),
			'swidth' : 230,
			'size'   : 18
		});
	}
});

/* **
 * 搜索
 * -------- -------- --------
 */
	$('#search_all').autocomplete( iknowing_domain + '/search/auto.html' );
	$('#do_search').autocomplete( iknowing_domain + '/search/auto.html' );

/* **
 * 一些其他的
 * -------- -------- --------
 */

	/* Back Desktop */
	$(function(){
		if( $('[name=login_type]').length == 1 && $('[name=login_type]').val() == 'islogin' ){
			//此为判断非登录状态[返回桌面]按钮是否有显示
		}
		else{
		var $back = $('<a class="backdesktop" href="'+iknowing_domain+'">返回桌面</a>');
			$(document.body).prepend( $back );
			$back.hover(
				function(){
					$back.stop().animate({
						'left' : 0
					},'fast');
				},
				function(){
					$back.stop().animate({
						'left' : -30
					},'fast');
				}
			);
		}
	});
	

/* **
 * Verification
 * -------- -------- --------
 */

	//小组:创建||编辑 -- 验证
	function veri_group(o){
		var $o            = $(o),
			$name         = $o.find('[name=name]'),
			$introduction = $o.find('[name=introduction]'),
			$privacy      = $o.find('[name=privacy]:checked'),
			$communityId  = $o.find('[name=communityId]'),
			$subjectId    = $o.find('[name=subjectId]');
		if( $name.val() == '' ){
			trace('小组名称不能为空!');
			return false;
		}
		if( $name.val() == '请输入小组名称' ){
			trace('小组名称非法');
			return false;
		}
		else if( $name.val().length > 16 ){
			trace('小组名称不能超过16个字');
			return false;
		}
		if( $introduction.val() == '请输入小组介绍' ){
			trace('小组介绍非法');
			return false;
		}
		if( $introduction.val().length > 200 ){
			trace('小组介绍不能超过200个字');
			return false;
		}
		if( $privacy.length != 1 ){
			trace('请设置隐私设置');
			return false;
		}
		trace('创建小组成功');
		return true;
		/*
		if( $communityId.find('option:selected').length != 1 ){
			trace('请选择社区');
			return false;
		}
		if( $subjectId.find('option:selected').length != 1 ){
			trace('请选择分类');
			return false;
		}
		*/
	}
	
	//活动:创建||编辑 -- 验证
	$('[name=activitysubmit]').die('click').live('click',function(){
		if( veri_activity( $('#activityform') ) ){
			$('#activityform').submit();
		}
		return false;
	});
	function veri_activity( o ){
		var $o           = o,
			$title       = $o.find('[name=title]'),
			$startTime   = $o.find('[name=startTimechoose]'),
			$endTime     = $o.find('[name=endTimechoose]'),
			$attendTime  = $o.find('[name=attendTimechoose]'),
			$address     = $o.find('[name=address]'),
			$fee         = $o.find('[name=fee]'),
			$description = $o.find('[name=description]'),
			$timeH       = $o.find('[name=timeH]'),
			$timeM       = $o.find('[name=timeM]');
		
		if( $title.val() == '' || $title.val() == undefined ){
			trace('活动名称不能为空');
			return false;
		}
		if( $title.val() == '请输入活动名称' ){
			trace('活动名称非法');
			return false;
		}
		else if( $title.val().length > 32 ){
			trace('活动名称不能超过32个字');
			return false;
		}
		if( $startTime.val() == '' ){
			trace('请选择开始时间');
			return false;
		}
		if( $endTime.val() == '' ){
			trace('请选择结束时间');
			return false;
		}
		if( $attendTime.val() == '' ){
			trace('请选择截止时间');
			return false;
		}
		/*
		if( toDate( $startTime.val() ) > toDate( $endTime.val() ) ){
			trace('结束时间不能先于开始时间');
			return false;
		}
		*/
		if( $address.val() == '' ){
			trace('活动地点不能为空');
			return false;
		}
		else if($address.val().length > 200){
			trace('活动地点不能超过200个字');
			return false;
		}
		if( $description.val() == '' ){
			trace('活动介绍不能为空');
			return false;
		}
		else if( $description.val().length > 65535 ){
			trace('活动介绍不能超过65535个字');
			return false;
		}
		if( $fee.val() == '' ){
			$fee.val(0);
		}
		else if( !mathReg.test($fee.val()) ){
			trace('活动费用只能填写数字哦^.^~');
			return false;
		}
		for( var i=0; i<$timeH.length; i++ ){
			var $number = $timeH.eq(i);
			if( $number.val().length <= 0 ){
				$number.val('00');
			}
			else if( !mathReg.test($number.val()) ){
				trace('时间只能为数字');
				return false;
			}
			else if( Number($number.val()) < 0 || Number($number.val()) > 23 ){
				trace('时间只能为0至23以内');
				return false;
			}
			else if( $number.val().length == 1 ){
				$number.val( '0' + $number.val() );
			}
		}
		for( var i=0; i<$timeM.length; i++ ){
			var $number = $timeM.eq(i);
			if( $number.val().length <= 0 ){
				$number.val('00');
			}
			else if( !mathReg.test($number.val()) ){
				trace('时间只能为数字');
				return false;
			}
			else if( Number($number.val()) < 0 || Number($number.val()) > 59 ){
				trace('时间只能为0至23以内');
				return false;
			}
			else if( $number.val().length == 1 ){
				$number.val( '0' + $number.val() );
			}
		}
		var startTimeVal = $startTime.val() + ' ' + $('#startTimeH').val() + ':' + $('#startTimeM').val() + ':00';
		$('#startTimehidden').val( startTimeVal );
		
		var endTimeVal = $endTime.val() + ' ' + $('#endTimeH').val() + ':' + $('#endTimeM').val() + ':00';
		$('#endTimehidden').val( endTimeVal );
		
		var attendTimeVal = $attendTime.val() + ' ' + $('#attendTimeH').val() + ':' + $('#attendTimeM').val() + ':00';
		$('#attendTimehidden').val( attendTimeVal );
		
		trace('创建活动成功!')
		return true;
	}
	
	// 设置 -- 基本资料 -- 验证
	function setting_archive(o){
		var $o = $(o),
			$nickName = $o.find('[name=nickName]'),
			$sex = $o.find('[name=sex]:checked'),
			$birthday = $o.find('[name=birthday]'),
			$nationality = $o.find('[name=nationality]'),
			$origin = $o.find('[name=origin]'),
			$userEmail = $o.find('[name=userEmail]'),
			$intro = $o.find('[name=intro]');
		if( $nickName.val() == '' ){
			trace('姓名不能为空');
			return false;
		}
		else if( $nickName.val().length > 16 ){
			trace('姓名不能超过16个字');
			return false;
		}
		if( $sex.length != 1 ){
			trace('请选择性别');
			return false;
		}
		/*
		if( !mailReg.test($userEmail.val()) ){
			trace('请填写正确的邮箱地址');
			return false;
		}
		*/
		if( $intro.val() > 200 ){
			trace('描述不能超过200个字');
			return false;
		}
	}
	
	//设置 -- 密码修改 -- 验证
	function veri_password(o){
		var $o = $(o),
			$oldpwd = $o.find('[name=oldpwd]').val(),
			$newpwd = $o.find('[name=newpwd]').val(),
			$repwd  = $o.find('[name=repwd]').val();
		if( $oldpwd == '' ){
			trace('密码不能为空');
			return false;
		}
		else if( $oldpwd.length < 6 || $oldpwd.length > 16 ){
			trace('密码只能6-16位之间');
			return false;
		}
		if( $newpwd == '' ){
			trace('密码不能为空');
			return false;
		}
		else if( $newpwd.length < 6 || $newpwd.length > 16 ){
			trace('密码只能6-16位之间');
			return false;
		}
		if( $repwd == '' ){
			trace('密码不能为空');
			return false;
		}
		else if( $repwd.length < 6 || $repwd.length > 16 ){
			trace('密码只能6-16位之间');
			return false;
		}
		if( $oldpwd == $newpwd || $oldpwd == $repwd ){
			trace('新密码不能与旧密码相同');
			return false;
		}
		else if( $newpwd != $repwd ){
			trace('两次密码输入不相同');
			return false;
		}
	}
	
	// 社区 -- 管理 -- 验证
	function veri_community(o){
		var $o = $(o),
			$name = $o.find('[name=name]'),
			$introduction = $o.find('[name=introduction]'),
			$privacy = $o.find('[name=privacy]:checked');
		if( $name.val() == '' ){
			trace('社区名称不能为空');
			return false;
		}
		if( $name.val().length > 32 ){
			trace('社区名称不能超过32个字');
			return false;
		}
		if( $introduction.val().length > 200 ){
			trace('社区介绍不能超过200个字');
			return false;
		}
		if( $privacy.length != 1 ){
			trace('请设置隐私设置');
			return false;
		}
	}
	
	// 社区 -- 注册 -- 验证
	function veri_community_apply(o){
		var $o     = $(o),
			$name  = $o.find('[name=name]'),
			$sex   = $o.find('[name=sex]:checked'),
			$email = $o.find('[name=email]');
		if( $name.val() == '' ){
			trace('姓名不能为空');
			return false;
		}
		else if( $name.val().length > 32 ){
			trace('姓名不能超过32个字');
			return false;
		}
		if( $sex.length != 1 ){
			trace('请选择性别');
			return false;
		}
		/*
		if( !mailReg.test($email.val()) ){
			trace('请填写正确的邮箱地址');
			return false;
		}
		*/
	}
