$().ready(function(){
	$(".comment-list").each(function(){
		var tag = $(this).attr("tag");
		if(tag >0){
			var html = $(this).html();
			$("#comment-"+tag+"-0-ol").append("<li>"+html+"</li>");
			$(this).remove();
		}
	});
	var time = $("#search-time").text()*1;
	if(time==0){
		$("#search-time").text("今天");
	}else if("172800"==time){
		$("#search-time").text("两天内");
	}else if("604800"==time){
		$("#search-time").text("一周内");
	}else if("2592000"==time){
		$("#search-time").text("一个月内");
	}
	/*$("#formtechNew").submit( 
		function() {
			return createtech();
		}
	);*/
});
function createtech() { 
	if($.trim($("#techname").val()).length < 2){
		$("#techname").addClass("p2008-10-8ub-error");
		$("#techname").focus();
		return false;
	}
	if($.trim($("#starttime").val()).length < 2){
		$("#starttime").addClass("pub-error");
		$("#starttime").focus();
		return false;
	}
	if($.trim($("#endtime").val()).length < 2){
		$("#endtime").addClass("pub-error");
		$("#endtime").focus();
		return false;
	}
	if($.trim($("#jionendtime").val()).length < 2){
		$("#jionendtime").addClass("pub-error");
		$("#jionendtime").focus();
		return false;
	}
	return true;
} 


//日志留言
function postComment(obj,posturl,rrid){
	//var content = $("#cmt-body").val();
	var content = $(obj).parent().prev().find("textarea").val();
	if ($.trim(content).length < 4){
		msg(obj,"内容不能少于4个字符");
		return false;
	}else{
		//ajax方式post数据
		$(obj).attr("disabled", "disabled");
		$(obj).val("数据发送中...");
		$.post(APP+"/tech/"+posturl, {ajax:1,techid: $("#techid").val(),classid: $("#classid").val(),photoid: $("#photoid").val(), userid: $(obj).prev().prev().val(), reid: $(obj).prev().val(), rrid:rrid,content: content },
			function(data){
				//alert(data);
				if("need_login" == data){
					$.facebox('<p>需<a href="'+APP+'/login/?msg=3&url='+encode64(location.href)+'">登录</a>才能继续操作</p>',"需登录才能操作");
					$(obj).removeAttr("disabled");
					$(obj).val("发表");
					return;
				}else if("error" == data){
					msg(obj,"留言失败，你可以重试");
					$(obj).removeAttr("disabled");
					$(obj).val("发表");
				}else{
					showComment(obj,data,content,posturl,rrid);
				}
		});
	}
}

//回复留言
function reComment(obj,rid,uid,pid,posturl,rrid){
	if(pid ==0){
		var _pid = rid;
	}else{
		var _pid = pid;
	}
	var html = '<div>';
	html += '	<form action="'+APP+'/tech/'+posturl+'" method="post" class="replyparent" id="cmt-frm">';
	html += '		<p>';
	html += '			<textarea onkeydown="ctrlEnter(event, \'re-cmt-sbm-btn-'+_pid+'\');" name="content" maxlength="1000" id="re-cmt-body-'+_pid+'" style="width:300px;height:8em;">回复:'+$(obj).parent().prev().prev().text()+'</textarea>';
	html += '		</p>';
	html += '		<p class="act">';
	html += '			<input type="hidden" value="'+uid+'" name="userid"/>';
	html += '			<input type="hidden" value="'+_pid+'" name="reid"/>';
	html += '			<input type="button" onclick="postComment(this,\''+posturl+'\','+rrid+')" class="f-button" value="回复" id="re-cmt-sbm-btn-'+_pid+'"/>';
	html += '			<input type="button" value="取消" class="f-alt btn-cancel" onclick="cancelPost(this)"/>';
	html += '		</p>';
	html += '	</form>';
	html += '</div>';
	if($("#re-cmt-body-"+_pid).attr("id") == "re-cmt-body-"+_pid){
		$("#re-cmt-body-"+_pid).focus();
	}else{
		if(pid == 0){
			$(obj).parent().parent().next().append(html);
		}else{
			$(obj).parent().parent().parent().parent().parent().parent().append(html);
		}
		$("#re-cmt-body-"+pid).focus();
	}
}

//隐藏留言区
function cancelPost(obj){
	$(obj).parent().parent().parent().remove();
}
//显示留言
function showComment(obj,data,content,posturl,rrid){
	var s = data.split(",");
	var html = '<li id="comment-'+s[0]+'">';
	html +=	'<div class="post parent-post">';
	html +=	'		<p class="image">';
	html +=	'			<a href="'+APP+'/home/'+s[1]+'"><img src="'+IMAGE+'/face/small/'+USERFACE+'"/></a>';
	html +=	'		</p>';
	html +=	'		<div class="info">';
	html +=	'			<span class="author"><a href="'+APP+'/home/'+s[1]+'">'+s[2]+'</a></span>';
	html +=	'			<span class="time">刚刚</span>';
	html +=	'			<span class="actions"><a href="javascript:void(0)" class="thread-reply" onclick="reComment(this,'+s[0]+','+s[1]+','+$(obj).prev().val()+',\''+posturl+'\','+rrid+')">回复</a>';
	html +=	'			</span>';
	html +=	'			<span class="delete">';
	html +=	'				<a href="javascript:void(0)" rel="'+APP+'/tech/deleteguest/id/'+s[0]+'" class="thread-del" onclick="delComment(this,'+s[0]+')">删除</a>';
	html +=	'			</span>';
	html +=	'		</div>';
	html +=	'		<div class="content">'+content;
	html +=	'			<ol>';
	html +=	'			</ol>';
	html +=	'		</div>';
	html +=	'	</div>';
	html +=	'</li>';
	$(obj).parent().parent().parent().prev().append(html);
	$(obj).parent().prev().find("textarea ").val("")
	$(obj).removeAttr("disabled");
	$(obj).val("发表");
}

//删除留言提示
function delComment(obj,id){
	alertMessage(obj,"确定删除该记录嘛");
	$(".msgOk").bind("click",function(){delCommentAction(obj,id);});
}

//删除留言操作
function delCommentAction(obj,id){
	$.get($(obj).attr("rel"), {ajax:1,revertid: id} , 
	function(data){
		if("success"==data){
			$(obj).parent().parent().parent().parent().fadeOut(2000); 
			$("#messageBox").remove();
		}else{
			$("#messageBox").remove();
			msg(obj,"操作失败");
		}
	});
}

function jointech(obj){
	var url = $(obj).attr("rel");
	alertMessage(obj,"确定报名参加?");
	$(".msgOk").bind("click",function(){
		$.get(url,{ajax:1},
			function(data){
				$("#messageBox").remove();
				if("need_login" == data){
					$.facebox('<p>需<a href="'+APP+'/login/?msg=3&url='+encode64(location.href)+'">登录</a>才能继续操作</p>',"需登录才能操作");
					$("#messageBox").remove();
					return;
				}else if("isrequest" == data){ //操作成功，但需要管理
					msg($(".jointech"),"操作成功，但需要管理验证");
					$(".jointech").parent().text("成功发送请求，正等待验证");
				}else if("success" == data){ //直接加入
					$("#messageBox").remove();
					msg($(".jointech"),"成功报名");
					$(".jointech").parent().text("报名成功");
					//$(".jointech").attr("rel",url.replace("jointech","exittech"));
				}else if("error" == data){
					msg($(".jointech"),"操作失败");
				}else if("isuser" == data){
					msg($(".jointech"),"你已经是该课程成员");
				}
			}
		);
	});
}

function exittech(obj){
	var url = $(obj).attr("rel");
	alertMessage(obj,"确定退出此课程?");
	$(".msgOk").bind("click",function(){
		$.get(url,{ajax:1},
			function(data){
				$("#messageBox").remove();
				if("success" == data){ //操作成功，但需要管理
					$(obj).parent().text('成功退出');
				}else if("error" == data){
					msg($(".jointech"),"操作失败");
				}else if("isnouser" == data){
					msg($(".jointech"),"你已经不是该课程成员");
				}
			}
		);
	});
}

function editPhoto(obj,id){
	var html = '<div style="padding:20px;"><p><textarea onkeydown="ctrlEnter(event, \'cmt-sbm-btn-desc\');" name="content" rows="6" cols="50" maxlength="1000" id="cmt-photo-desc-body"></textarea></p>';
	html += '<br/><p><input type="button" onclick="updatePhoto(this,'+id+')" class="f-button" value="修改" id="cmt-sbm-btn-desc"/> <input type="button" class="f-alt" value="取消" onclick="$.facebox.close();"/></p></div>';
	$.facebox(html,"编辑相片描述");
}
function editVedio(obj,id){
	var html = '<div style="padding:20px;"><p><textarea onkeydown="ctrlEnter(event, \'cmt-sbm-btn-desc\');" name="content" rows="6" cols="50" maxlength="1000" id="cmt-photo-desc-body"></textarea></p>';
	html += '<br/><p><input type="button" onclick="updateVedio(this,'+id+')" class="f-button" value="修改" id="cmt-sbm-btn-desc"/> <input type="button" class="f-alt" value="取消" onclick="$.facebox.close();"/></p></div>';
	$.facebox(html,"编辑相片描述");
}
function updatePhoto(obj,id){
	var content = $("#cmt-photo-desc-body").val();
	if ($.trim(content).length < 4){
		msg(obj,"内容不能少于4个字符");
		return false;
	}else{
		$.get(APP+"/tech/updatephotodesc",{ajax:1,id:id,content:content},
			function(data){
				if("success"==data){
					$("#photo-desc").html(content);
					$.facebox.close();
				}else{
					msg(obj,"编辑失败，你可以重试");
				}
			}
		);
	}
}

function updateVedio(obj,id){
	var content = $("#cmt-photo-desc-body").val();
	if ($.trim(content).length < 4){
		msg(obj,"内容不能少于4个字符");
		return false;
	}else{
		$.get(APP+"/tech/updatevediodesc",{ajax:1,id:id,content:content},
			function(data){
				if("success"==data){
					$("#photo-desc").html(content);
					$.facebox.close();
				}else{
					msg(obj,"编辑失败，你可以重试");
				}
			}
		);
	}
}

function delPhoto(obj,nid){
	alertMessage(obj,"确定删除该相片?<br/>其相关评论也将被删除");
	$(".msgOk").bind("click",function(){
		$.get($(obj).attr("rel"), {ajax:1} , 
		function(data){
			if("success"==data){
				window.location.href=APP+"/tech/showphoto?id="+nid; 
				$("#messageBox").remove();
			}else{
				$("#messageBox").remove();
				msg(obj,"操作失败");
			}
		});
	});
}

function deltech(obj,techid){
	alertMessage(obj,"确定取消该课程?<br/>其相关所有资源也将被删除");
	$(".msgOk").bind("click",function(){
		$.get($(obj).attr("rel"), {ajax:1} , 
		function(data){
			if("success"==data){
				window.location.href=APP+"/tech/classlist?id="+techid; 
				$("#messageBox").remove();
			}else{
				$("#messageBox").remove();
				msg(obj,"操作失败");
			}
		});
	});
}

function attendtech(obj){
	alertMessage(obj,"确定对这个课程感兴趣?");
	$(".msgOk").bind("click",function(){
		$.get($(obj).attr("rel"), {ajax:1} , 
		function(data){
			if("success"==data){
				$("#messageBox").remove();
				$(obj).val("已标记感兴趣");
				$(obj).unbind( "click" );
			}else{
				$("#messageBox").remove();
				msg(obj,"操作失败");
			}
		});
	});
}

//ajax上传
function ajaxFileUpload(obj){
	$(".loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	var callback = $(obj).attr("callback");
	$.ajaxFileUpload
	(
		{
			url:APP+'/tech/savephoto4ajax/techid/'+$("#techid").val()+'/classid/'+$("#classid").val(),
			secureuri:false,
			fileElementId:'fileToUpload',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.type) != 'undefined')
				{
					if(data.type == 'error')
					{
						$.facebox(msginfo.msg,'信息提示',data.type);
					}else if(data.type == 'success')
					{
						$("#fileToUpload").val("");
						eval(callback+"("+data.param+")");
					}
				}
			},
			error: function (data, status, e)
			{
				alert(e);
			}
		}
	)
	return false;

}

function showphoto(param){
	var html = '<li>'
	html += '		<img src="'+IMAGE+'/all/small/'+param.photoname+'" alt="'+IMAGE+'/all/small/'+param.photoname+'"/>';
	html += '		<a class="bimg-ins" href="javascript:void(0)" onclick="insertPic2(this,\''+IMAGE+'/all/big/'+param.photoname+'\')">插图</a>';
	html += '		<a class="bimg-del" href="javascript:void(0)" rel="'+APP+'/tech/deletephoto/id/'+param.id+'" onclick="delPhoto2(this,\''+param.photoname+'\')">删除</a>';
	html += '		<input type="hidden" name="photolist[]" value="'+param.id+'"/>';
	html += '	</li>'
	$("#blog-pics").find("ul").append(html);
	insertPic2(this,IMAGE+'/all/big/'+param.photoname);
	$("#lastphoto").val(param.photoname);
	$("#fileToUpload").val("");
}

function delPhoto2(obj,photoname){
	alertMessage(obj,"内容框里的这张图片是否删除了？");
	$(".msgOk").bind("click",function(){
		$.get($(obj).attr("rel"),{ajax:1},function(data){
			if("success" == data){
				$(obj).parent().remove();
				$("#messageBox").remove();
				var blogpic = $("#blogpic").val();
				if( blogpic == photoname){
					$("#blogpic").val("");
				}
			}else{
				msg(obj,"删除失败,你可以重试");
				$("#messageBox").remove();
			}
		});
	});
}

//编辑主题
function editTopic(obj,id){
	location.href = APP+'/tech/edittopic/id/'+id;
	/*if($("#topiccontent").attr("id") == "topiccontent"){
		var content = $("#topiccontent").val();
		$("#topiccontent").parent().parent().html(content);
		$("#topiccontent").parent().remove();
	}
	if($("#revertcontent").attr("id") == "revertcontent"){
		var content = $("#revertcontent").val();
		$("#revertcontent").parent().parent().html(content);
		$("#revertcontent").parent().remove();
	}
	var title = $("#topic-title").text();
	var cobj = $("#topic-content");
	var content = $(cobj).html();
	var	 html =	'<div><p style="padding:5px;"><input id="topictitle" name="topictitle" value="'+ title +'" size="50"/></p>';
	html += '	<p style="padding:5px;"><textarea id="topiccontent" name="topiccontent" cols="30" rows="6">'+ content +'</textarea></p>';
	html += '	<p style="padding:5px;"><input type="button" class="editpost f-button" value="完成编辑" onclick="postEdit(this,'+id+')"/>';
	html += '	<input type="button" class="editcancel f-alt" value="取消编辑"/>';
	html += '	</p</div>';
	$(cobj).html(html);
	tinyMCE.init({
		// General options
		mode : "textareas",
		elements : "topiccontent",
		theme : "advanced",
		language : "zh",
		plugins : "",

				// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,image,media,|,forecolor,fontsizeselect",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",


		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
	$('.editcancel').click(function() {
			postCancel(this,content);
	});*/
}

//保存编辑
function postEdit(obj,id){
	var content = getContents("topiccontent")
	if($.trim(content) == ""){
		msg(obj,"内容不能为空");
		return false;
	}else{
		$(obj).val("保存数据中...");
		$(obj).attr("disabled", "disabled");
		$(obj).next().attr("disabled", "disabled");
		$.post(APP+"/tech/updatetopic", {ajax:1 , id: id, title: $("#topictitle").val(), content: content },
			function(data){ 
				if("success" == data){
					$("#topic-title").html($("#topictitle").val());
					$(obj).parent().parent().after(content);
					$(obj).parent().parent().remove();
				}else{
					$(obj).val("编辑");
					$(obj).attr("disabled", "");
					$(obj).next().attr("disabled", "");
					msg(obj,"编辑失败，你可以重试");
				}
			}  
		);
	}
}

//编辑回复
function editRevert(obj,id){
	location.href = APP+'/tech/editrevert/id/'+id;
	/*
	if($("#topiccontent").attr("id") == "topiccontent"){
		var content = $("#topiccontent").val();
		$("#topiccontent").parent().parent().html(content);
		$("#topiccontent").parent().remove();
	}
	if($("#revertcontent").attr("id") == "revertcontent"){
		var content = $("#revertcontent").val();
		$("#revertcontent").parent().parent().html(content);
		$("#revertcontent").parent().remove();
	}
	var content = $("#revert-content-"+id).html();
	var	 html =	'<div><p><textarea id="revertcontent" name="revertcontent" cols="30" rows="6">'+ content +'</textarea></p>';
	html += '<p><input type="button" class="editpost f-button" value="完成编辑" onclick="postRevertEdit(this,'+id+')"/>';
	html += ' <input type="button" class="editcancel f-alt" value="取消编辑"/>';
	html += '</p</div>';
	$("#revert-content-"+id).html(html);
	tinyMCE.init({
		// General options
		mode : "textareas",
		elements : "revertcontent",
		theme : "advanced",
		language : "zh",
		plugins : "",

				// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,image,media,|,forecolor,fontsizeselect",
		theme_advanced_buttons2 : "",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",


		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
	$('.editcancel').click(function() {
			postCancel(this,content);
	});
	*/
}

//保存回复编辑
function postRevertEdit(obj,id){
	var content = getContents("revertcontent")
	if($.trim(content) == ""){
		return false;
	}else{
		$(obj).val("发送数据中...");
		$(obj).attr("disabled", "disabled");
		$(obj).next().attr("disabled", "disabled");
		$.post(APP+"/tech/updaterevert", {rid: id, ajax: 1, content: content },
			function(data){ 
				if("success" == data){
					$(obj).parent().parent().after(content);
					$(obj).parent().parent().remove();
				}else{
					$(obj).val("编辑");
					$(obj).attr("disabled", "");
					$(obj).next().attr("disabled", "");
					msg(obj,"编辑失败，你可以重试");
				}
			}  
		);
	}
}

//取消编辑
function postCancel(obj,content){
	alertMessage(obj,"确定取消编辑？");
	$(".msgOk").bind("click",function(){
		$(obj).parent().parent().after(content);
		$(obj).parent().parent().remove();
		$("#messageBox").remove();
	});
}

//回复主题
function reTopic(obj){
	var html = "<strong>回复楼主</strong><br/>";
	html += $("#topic-content").html();
	$("#orig-post").html(html);
	$("#orig-post").css("display","block");
	$("#revertid").val(0);
	$("#reuserid").val(0);
}

//回复回复
function reRevert(obj,id,ruid){
	var html = "<strong>回复"+$(obj).parent().prev().text()+"</strong><br/>";
	html += $("#revert-content-"+id).html();
	$("#orig-post").html(html);
	$("#orig-post").css("display","block");
	$("#revertid").val(id);
	$("#reuserid").val(ruid);
}

//删除回复
function delRevert(obj){
	alertMessage(obj,"确定删除该回复？");
	$(".msgOk").bind("click",function(){
		delRevertAction(obj);
	});
}

//删除回复操作
function delRevertAction(obj){
	$.get($(obj).attr("rel"), {ajax: 1},
		function(data){ 
			if("success" == data){
				$(obj).parent().parent().parent().parent().slideToggle("slow",function(){ $(this).remove(); }); 		
			}
			$("#messageBox").remove(); 
		} 
	);
}

//主题置顶/取消置顶
function topTopic(obj){
	if("top" == $(obj).attr("title")){
		alertMessage(obj,"确定要置顶本主题？");
	}else if("untop" == $(obj).attr("title")){
		alertMessage(obj,"确定要取消置顶本主题？");
		
	}
	$(".msgOk").bind("click",function(){topTopicAction(obj);});
	return false;
}

//置顶/取消置顶操作
function topTopicAction(obj){
	var url = $(obj).attr("rel");
	if("top" == $(obj).attr("title")){
		var url2 = url.replace("toptopic","untoptopic");
		var text = "取消置顶";
		var title = "untop";
	}else{
		var url2 = url.replace("untoptopic","toptopic");
		var text = "置顶本主题";
		var title = "top";
	}
	$.get(url, {ajax: 1},function(data){ 
		if("success" == data){
			$(obj).attr("rel",url2);
			$(obj).attr("title",title);	
			$(obj).text(text);
			$("#messageBox").remove();
			msg(obj,"操作成功");
		}else{
			$("#messageBox").remove();
			msg(obj,"操作失败");
		}
	});

}

/**********settechuser********/
function setFriend(obj){
	$("#friendlist").append('<li><input type="hidden" name="friends[]" value="'+$(obj).attr("id")+'"/> <a href="'+APP+'/user/index/u/'+$(obj).attr("id")+'">'+ $(obj).text() +' </a><span class="deletefriend'+$(obj).attr("id")+'"><a href="#">删除</a></span></li>');
	$(obj).css("display","none");
	$(".deletefriend"+$(obj).attr("id")).bind("click",function(){
		var id = $(this).prev().prev().val();
		$("#"+id).css("display","block");
		$(this).parent().remove();
	});
}

function deleteUser(obj){
	alertMessage(obj,"确定要删除此用户?");
	$(".msgOk").bind("click",function(){deleteUserAction(obj);});
	
}

function deleteUserAction(obj){
	$("#messageBox").remove();
	$.get($(obj).attr("rel"),{ajax:1},function(data){
		if("success" == data){
			$(obj).parent().parent().fadeOut("slow",function(){ $(this).remove(); });
		}else{
			msg(obj,"操作失败");
		}
	});
}
function cancelManager(obj){
	alertMessage(obj,"确定撤消其管理员身份?");
	$(".msgOk").bind("click",function(){cancelManagerAction(obj);});
}

function cancelManagerAction(obj){
	var url = $(obj).attr("rel");
	var url2 = url.replace("CancelManager","SetManager");
	var _class = $(obj).attr("class");
	var _class2 = _class.replace("cancelmanager","setmanager");
	$("#messageBox").remove();
	$.get(url,{ajax:1},function(data){
		if("success" == data){
			$(obj).attr("rel",url2);
			$(obj).attr("class",_class2);
			$(obj).text("升为管理员");
			msg(obj,"设置成功");
			$("."+_class2).bind("click",function(){setManager(this);return false;});
		}else{
			msg(obj,"操作失败");
		}
	});
}
function setManager(obj){
	alertMessage(obj,"确定升其为管理员?");
	$(".msgOk").bind("click",function(){setManagerAction(obj);});
}
function setManagerAction(obj){
	var url = $(obj).attr("rel");
	var url2 = url.replace("SetManager","CancelManager");
	var _class = $(obj).attr("class");
	var _class2 = _class.replace("setmanager","cancelmanager");
	$("#messageBox").remove();
	$.get(url,{ajax:1},function(data){
		if("success" == data){
			$(obj).attr("rel",url2);
			$(obj).attr("class",_class2);
			$(obj).text("撤消管理员");
			msg(obj,"操作成功");
			$("."+_class2).bind("click",function(){cancelManager(this);return false;});
		}else{
			msg(obj,"操作失败");
		}
		
	});
}

function addActive(obj,uid){
	$(obj).after('<p class="loading">数据读取中...</a>');
	$.get(APP+"/actives/"+uid,{ajax:1,type:2},function(data){
		$(".loading").remove();
		$.facebox(data,"相关活动");
	});
}

function setActive(obj,aid){
	$.get(APP+"/tech/saverelate",{ajax:1,type:"t-a",tid:$("#techid").val() , aid:aid },function(data){
		if("success" == data){
			$("#activerelate").append('<li><p><a href="'+APP+'/showactive/'+aid+'">'+$(obj).next().text()+'</a></p></li>');
			$(obj).parent().parent().parent().remove();
		}else{
			msg(obj,"设置失败,稍后重试");
		}
	});
}

function deleteActive(obj,aid){
	alertMessage(obj,"确定移除？");
	$(".msgOk").bind("click",function(){
		$.get(APP+"/tech/deleterelate",{ajax:1,type:"t-a", tid:$("#techid").val() ,aid:aid},function(data){
			if("success" == data){
				$(obj).parent().parent().remove();
			}else{
				msg(obj,"删除失败,请稍后重试");
			}
		});
	});
}

function addGroup(obj,uid){
	$(obj).after('<p class="loading">数据读取中...</a>');
	$.get(APP+"/groups/"+uid,{ajax:1,type:2},function(data){
		$(".loading").remove();
		$.facebox(data,"相关群组");
	});
}

function setGroup(obj,gid){
	$.get(APP+"/tech/saverelate",{ajax:1,type:"t-g",tid:$("#techid").val() , gid:gid },function(data){
		if("success" == data){
			$("#grouprelate").append('<li><p><a href="'+APP+'/showgroup/'+gid+'">'+$(obj).next().text()+'</a></p></li>');
			$(obj).parent().parent().parent().remove();
		}else{
			msg(obj,"设置失败,稍后重试");
		}
	});
}

function deleteGroup(obj,gid){
	alertMessage(obj,"确定移除？");
	$(".msgOk").bind("click",function(){
		$.get(APP+"/tech/deleterelate",{ajax:1,type:"t-g",tid:$("#techid").val() ,gid:gid},function(data){
			if("success" == data){
				$(obj).parent().parent().remove();
				$("#messageBox").remove();
			}else{
				msg(obj,"删除失败,请稍后重试");
				$("#messageBox").remove();
			}
		});
	});
}

function setStar(obj){
	$.get($(obj).attr("rel"),{ajax:1,techid:$("#techid").val()},function(data){
		if("success"==data){
			alertMessage(obj,"评分成功");
			$(".msgOk").bind("click",function(){$("#messageBox").remove()});
		}else if("isstar"==data){
			alertMessage(obj,"你已经评过分了");
			$(".msgOk").bind("click",function(){$("#messageBox").remove()});
		}else{
			alertMessage(obj,"评分失败，请稍后重试");
			$(".msgOk").bind("click",function(){$("#messageBox").remove()});
		}
	});
}

function addVedio(obj){
	var url = $("#vediourl").val();
	if(!isUrl(url)){
		msg(obj,"无效链接");
		return ;
	}
	var utype = checkurl(url);
	if(utype == "wmusic"){
		utype = "music";
	}
	var shtml = '<div class="dialog-2" id="shareobj">';
	shtml += '		<div class="hd">';
	shtml += '			<h3>添加一个课程';
	if("vedio" == utype){
		shtml += "视频";
	}else if("pic" == utype){
		shtml += "图片";
	}else if("url" == utype){
		shtml += "网址";
	}else{
		shtml += "音乐";
	}
	shtml += '			</h3>';
	shtml += '		</div>';
	shtml += '		<div class="bd">';
	shtml += '			<div id="stp">';
	shtml += '				<table class="form-layout">';
	shtml += '					<tbody>';
	if("music" == utype){
		shtml += '						<tr>';
		shtml += '							<th>歌曲名：</th>';
		shtml += '							<td><input class="f-text" type="text" name="title" id="stp-music-name" value=""</td>';
		shtml += '						</tr>';
		shtml += '						<tr>';
		shtml += '							<th>歌手：</th>';
		shtml += '							<td><input class="f-text" type="text" name="actor" id="stp-music-actor" value=""</td>';
		shtml += '						</tr>';
	}else{
		shtml += '						<tr>';
		shtml += '							<th>标题：</th>';
		shtml += '							<td><input class="f-text" type="text" name="title" id="stp-title" value=""</td>';
		shtml += '						</tr>';
	}
	shtml += '						<tr>';
	shtml += '							<th>描述：</th>';
	shtml += '							<td><textarea maxlength="200" id="stp-tarea" name="cmt"/><p class="maxlength-hint warning" style="display: none;"><span/></p></td>';
	shtml += '						</tr>';
	shtml += '						<tr>';
	shtml += '							<th/>';
	shtml += '							<td class="act">';
	shtml += '								<input type="hidden" id="shareurl" value="'+url+'"/>';
	shtml += '	 							<input type="hidden" value="'+utype+'"/>';
	shtml += '								<input type="hidden" value="0"/>';
	shtml += '								<input type="button" value="添加"  id="saveshare" class="f-button share-submit" onclick="saveVedio(this)"/>';
	if("music" == utype){
		shtml += '								<input type="hidden" value="music"/>';
	}else{
		shtml += '								<input type="hidden" value="url"/>';
	}
	shtml += '								<input type="button" value="取消" class="f-button f-alt share-cancel close" onclick="$.facebox.close();"/>';
	shtml += '								</td>';
	shtml += '							</tr>';
	shtml += '						</tbody>';
	shtml += '					</table>';
	shtml += '				</div>';
	shtml += '				<div class="share-content">';
	shtml += getHtml(utype,url,300,260);
	shtml += '					</div>';
	shtml += '				</div>';
	shtml += '			</div>';
	shtml += '			<div class="ft">';
	shtml += '			</div>';
	$.facebox(shtml,"添加视频");
	$("#vediourl").val("");
}

function saveVedio(obj){
	if("" == $.trim($("#stp-title").val()) ){
		msg($("#stp-title"),"标题不能为空");
		return false;
	}else{
		$.post(APP+"/tech/savevedio",{ajax:1,techid:$("#techid").val(),title:$("#stp-title").val(),content:$("#stp-tarea").val(),url:$("#shareurl").val()},function(data){
			if("success"==data){
				msg(obj,"添加成功");
				$.facebox.close();
			}else{
				msg(obj,"添加失败");
			}
		});
	}
}

function delVedio(obj,techid,id){
	alertMessage(obj,"确定删除这个视频");
	$(".msgOk").bind("click",function(){
		$.get($(obj).attr("rel"), {ajax:1} , 
		function(data){
			if("success"==data){
				next(techid,id);
				$("#messageBox").remove();
			}else{
				$("#messageBox").remove();
				msg(obj,"操作失败");
			}
		});
	});
}


function prev(techid,id){
	$.get(APP+'/tech/prev/techid/'+techid+'/id/'+id,function(data){
			if(0 == parseInt(data)){
				window.location.href=APP+'/tech/vedios?id='+techid;
			}else{
				window.location.href=APP+'/tech/showvedio?id='+data;
			}
		});
}

function next(techid,id){
	$.get(APP+'/tech/next/techid/'+techid+'/id/'+id,function(data){
			if(0 == parseInt(data)){
				window.location.href=APP+'/tech/vedios?id='+techid;
			}else{
				window.location.href=APP+'/tech/showvedio?id='+data;
			}
		});
}

//删除主题
function delTopic(obj){
	alertMessage(obj,"确定删除该主题<br/>将导致该主题所有的回复被删除。");
	$(".msgOk").bind("click",function(){delTopicAction(obj);});
}

//删除主题操作
function delTopicAction(obj){
	window.location.href=$(obj).attr("rel");
}

