/*
'=====================================================================
' Module Name:
' File name: repaste.js
' Author: william.lu
' Project : 3que1
' Copyright (c) all rights reserved by juuyou.com Co., LTD.
' Create on 2010/03/26
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: interestMusic页JS函数集
'
'*********************************************************************
 */

/** 定义juuyou.interestMusic命名空间 * */
juuyou.repaste = {};


$(document).ready(function(){
	$(".l_like").live("click", function(){
		$.ajax({
	 		type:"POST",
			url:"../json/photo/photoActiveLike.php",
			async:true,
			data: {
				aid: strActiveId,
				act: "like"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$(".j_like_span").hide();
					$(".j_likes").replaceWith(data);
				}
			}
		});
		return false;
	});
});

juuyou.repaste.checkRepasteComment = function(){
	var strComment = $.trim($("#txtAreaComment").val());
	if(strComment == ""){
		$("#txtAreaComment").focus();
		return false;
	}
	
	if(strComment.length > 250){
		alert("字符数最大不得超过250");
		return false;
	}

	$.ajax({
	 	type:"POST",
		url:"../json/repaste/sayingAdd.php",
		async:false,
		data: {
			aid: strActiveId,
			val: strComment,
			type: "repaste"
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#txtAreaComment").val("");
				$("#j_comment_list").prepend(data);
				intSayingCount = 1 + intSayingCount;
				$("#j_comment_count_span").html(intSayingCount);
			}
		}
	});
}


//初始化music saying删除
$(document).ready(function(){
	$(".j_repaste_saying_del").live("click", function(){	
		var objLi = $(this).parents("li");
		var strSID = objLi.attr("sid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/sayingDelete.php",
			async:true,
			data: {
				sid: strSID,
				act: "delete"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objLi.hide();
					intSayingCount = intSayingCount - 1;
					$("#j_comment_count_span").html(intSayingCount);
				}
			}
		});
		return false;
	});
});

$(document).ready(function(){
	$(".f_repaste_tag").live("click", function(){	
		var strAID = $(this).attr("aid");
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/repasteActive.php",
			async:true,
			data: {
			active_id: strAID,
			repaste_id:strRepasteId,
			active_type: "T"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						alert("你已经发表过观点")
					}else{
						alert("发表成功")
						$.ajax({
					 		type:"POST",
							url:"../json/repaste/repaste.php",
							async:true,
							data: {
							user_repaste_id:strUserRepasteId
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
								}else{
									if($.trim(data) == juuyou.common.json.already){
										alert("不能重复转贴")
									}else{
										alert("转贴成功");
										$.ajax({
									 		type:"POST",
											url:"../json/repaste/repasteTag.php",
											async:true,
											data: {
											repaste_id:strRepasteId
											},
											success:function(data){
												if($.trim(data) == juuyou.common.json.failure){
												}else{
													$(".f_repaste_opinion").html(data);
												}
											}
										});										
									}
								}
							}
						});
					}
				}
			}
		});
		return false;
	});
});

$(document).ready(function(){
	$(".f_repaste_vote").live("click", function(){	
		var strAID = $(this).attr("aid");
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/repasteActive.php",
			async:true,
			data: {
			active_id: strAID,
			repaste_id:strRepasteId,
			active_type: "V"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						alert("你已经发表过观点");
					}else{
						alert("发表成功");
						$.ajax({
					 		type:"POST",
							url:"../json/repaste/repaste.php",
							async:true,
							data: {
							user_repaste_id:strUserRepasteId
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
								}else{
									if($.trim(data) == juuyou.common.json.already){
										alert("不能重复转贴")
									}else{
										alert("转贴成功");										
									}
								}
							}
						});						
						$.ajax({
					 		type:"POST",
							url:"../json/repaste/repasteVote.php",
							async:true,
							data: {
							repaste_id:strRepasteId
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
								}else{
									$(".f_repaste_opinion").html(data);
								}
							}
						});						
					}
				}
			}
		});
		return false;
	});
});

$(document).ready(function(){
	$(".f_repaste_repaste").live("click", function(){	
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/repaste.php",
			async:true,
			data: {
			user_repaste_id:strUserRepasteId
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						alert("不能重复转贴")
					}else{
						alert("转贴成功");
					}
				}
			}
		});
		return false;
	});
});


$(document).ready(function(){
	$("#f_more_repaste_tag").live("click", function(){	
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/repasteTag.php",
			async:true,
			data: {
			repaste_id:strRepasteId
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$(".f_repaste_opinion").html(data);
				}
			}
		});
		return false;
	});
});


$(document).ready(function(){
	$("#f_new_repaste_tag_button").live("click", function(){	
		var strTagName = $("#f_new_repaste_tag_txt").val();
		if(strTagName.length > 50){
			alert("字符数最大不得超过50");
			return false;
		}
		$.ajax({
	 		type:"POST",
			url:"../json/repaste/newRepasteTag.php",
			async:true,
			data: {
			repaste_id:strRepasteId,
			tag_name:strTagName
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						alert("您已经发表过观点或观点已存在")
						$("#f_new_repaste_tag_txt").val("");
						$("#f_new_repaste_tag_txt").focus();
					}else{
						alert("发表成功");
						$.ajax({
					 		type:"POST",
							url:"../json/repaste/repaste.php",
							async:true,
							data: {
							user_repaste_id:strUserRepasteId
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
								}else{
									if($.trim(data) == juuyou.common.json.already){
										alert("不能重复转贴")
									}else{
										alert("转贴成功");
									}
								}
							}
						});
						$("#f_new_repaste_tag_txt").val("");
						$.ajax({
					 		type:"POST",
							url:"../json/repaste/repasteTag.php",
							async:true,
							data: {
							repaste_id:strRepasteId
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
								}else{
									$(".f_repaste_opinion").html(data);
								}
							}
						});
					}
				}
			}
		});
		return false;
	});
});


juuyou.repaste.checkSubmitRepaste = function(){
	var strTitle = $.trim($("#txt_repaste_title").val());
	var strContent = $.trim($("#txt_repaste_content").val());
	if(strTitle == ""){
		alert("标题不能为空");
		$("#txt_repaste_title").focus();
		return false;
	}
	if(strTitle.length > 250){
		alert("字符数最大不得超过250");
		return false;
	}
}

$(document).ready(function(){
	  $("#txt_friend_view").bind("focus", function(){
	      if($("#txt_friend_view").val() == "查看好友转贴"){
	          $("#txt_friend_view").val("");
	      }
	    });
});

juuyou.repaste.viewFriendRepaste = function(){
	window.location = "http://saywo.com/repaste/quickRepasteList.php?nickName="+$("#txt_friend_view").val();
}

$(document).ready(function(){
	$(".f_repaste_active_type").live("click", function(){
		var typeVal = $(this).val();
		if(typeVal=="T"){
			$("#f_active_type_tag").show();
			$("#f_active_type_vote").hide();
		}
		if(typeVal=="V"){
			$("#f_active_type_vote").show();
			$("#f_active_type_tag").hide();

		}
		if(typeVal=="N"){
			$("#f_active_type_tag").hide();
			$("#f_active_type_vote").hide();
		}
	});
});












