/*
'=====================================================================
' Module Name:
' File name: profileEdit.js
' Author: william.lu
' Project : saywo
' Copyright (c) all rights reserved by juuyou.com Co., LTD.
' Create on 2009/01/06
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: 
'
'*********************************************************************
*/


/**  定义juuyou.profile命名空间  **/
juuyou.profile = {};


/**  修改基本信息页面初始化脚本  **/
juuyou.profile.initProfileEdit = function(strRegionCode, strSidoCode){
	juuyou.cityList.initAreaCity($obj("sel_region"), $obj("sel_city"));
	juuyou.cityList.defaultSelect($obj('sel_region'), $obj('sel_city'), strRegionCode, strSidoCode);		
}

/**  验证并提交  **/
juuyou.profile.checkSubmit = function(){
	return juuyou.common.validWordLength('txt_user_introduce', 'txt_word_cnt', 1000);
}


/**  验证上传并提交视频编辑 **/
juuyou.profile.CheckVideoEdit = function(){	
	if(juuyou.common.trim($obj("txt_title").value) == ""){
		alert("标题不能为空");
		return false;
	}
	
	if(juuyou.common.trim($obj("txt_description").value) == ""){
		alert("描述不能为空");
		return false;
	}
	
	if($obj("txt_description").value.length > 1000){
		alert("描述不能超过1000个字符");
		return false;
	}
	
	return true;
}


/**  初始化Saying功能  **/
$(document).ready(function(){
    $(".l_comment").live("click", function(){
    		blSmallFlashKey = true;
			var objDd = $(this).parents("li");
			var objDiv = $(this).parents(".j_action_div");
			if(!objDd.find(".j_commentform").length){
				var divNewCommentAdd = $('<div class="commentform j_commentform"><form method="post"><div class="text"><input type="text" id="txt_saying_content" value="" maxlength="280"/></div><div class="buttons"><input value="发布" type="submit"><a href="#" class="">取消</a><img src="http://img.saywo.com/images/fixed/loading.gif" width="16" height="16" alt="" style="display:none;"/></div></form></div>');
    			objDd.append(divNewCommentAdd);
				var objAddCommentForm = objDd.find(".j_commentform");
				objAddCommentForm.find("#txt_saying_content").focus();
				
   				objAddCommentForm.find("form a").click(
    				function(){
    					objAddCommentForm.remove();
    					blSmallFlashKey = false;
    					return false;
    				}
    			);
    			
    			
    			objAddCommentForm.find("form").submit(
    				function(){
    					var strVal = objAddCommentForm.find("#txt_saying_content").val();
    					var strActiveId = objDiv.attr("aid");
    					var strActiveType = objDiv.attr("atype");
    					strVal = $.trim(strVal);
    					if(strVal == ""){
    						alert("不能发布空的信息");
    						return false;
    					}
    					
    					objAddCommentForm.find("input").attr("disabled", "disabled");

						objAddCommentForm.find("img").show();
						
						$.ajax({
					 		type:"POST",
							url:"../json/home/homeSayingAdd.php",
							async:true,
							data: {
								aid: strActiveId,
								val: strVal,
								atype: strActiveType
							},
							success:function(data){
								if($.trim(data) == juuyou.common.json.failure){
									alert("提交失败");
									objAddCommentForm.find("img").hide();
								}else{
									objAddCommentForm.remove();
									objDd.append(data);
									blSmallFlashKey = false;
								}
							}
						});
    					
    					return false;
    				}
    			);
			}else{
				objDd.find(".j_commentform #txt_saying_content").focus();
			}
    		return false;
    	}
    );
});


//绑定自己所发的Saying编辑和删除动作
$(document).ready(function(){
	$(".l_deletecomment").live("click", function(){
		var objOwner = $(this).parents(".owner");
		var divDeleteForm = $('<div class="home_comment deleted"><i>评论已删除</i> - <a href="#" class="l_undeletecomment">撤销</a></div>');
		var strSayingId = objOwner.attr("sid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingDelete.php",
			async:true,
			data: {
				sid: strSayingId,
				act: "delete"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
				}
			}
		});
		
		objOwner.hide().after(divDeleteForm);
		var objCommentDeleteForm = objOwner.next();
		var strSayingId = objOwner.attr("sid");
		objCommentDeleteForm.find(".l_undeletecomment").click(
			function(){	
				$.ajax({
			 		type:"POST",
					url:"../json/home/homeSayingDelete.php",
					async:true,
					data: {
						sid: strSayingId,
						act: "undelete"
					},
					success:function(data){
						if($.trim(data) == juuyou.common.json.failure){
						}else{
						}
					}
				});
		
				objCommentDeleteForm.remove();
				objOwner.show();
				return false;
			}
		);
		return false;
	});
});

//绑定自己所发的Saying编辑和删除动作
$(document).ready(function(){	
	$(".l_editcomment").live("click", function(){
		blSmallFlashKey = true;
		var objOwner = $(this).parents(".owner");
		var strSayingId = objOwner.attr("sid");
		var divCommentEdit = $('<div class="commentform j_editCommentForm"><form method="post"><div class="text"><textarea cols="55" rows="2" wrap="virtual" id="txt_saying_content"></textarea></div><div class="buttons"><input value="发布" type="submit"><a href="#" class="">取消</a><img src="http://img.saywo.com/images/fixed/loading.gif" width="16" height="16" alt="" style="display:none;"/></div></form></div>');
		var strVal = objOwner.attr("v");	

		objOwner.hide().after(divCommentEdit);
		var objCommentEditForm = divCommentEdit.find("form");
		objCommentEditForm.find("#txt_saying_content").val(strVal);
		objCommentEditForm.find("a").click(
			function(){
				divCommentEdit.remove();
				objOwner.show();
				blSmallFlashKey = false;
				return false;
			}
		);
		
		objCommentEditForm.submit(
			function(){
				var strVal = objCommentEditForm.find("#txt_saying_content").val();
				var strSayingId = objOwner.attr("sid");
				var strActiveType = objOwner.attr("atype");
				strVal = $.trim(strVal);
				if(strVal == ""){
					alert("不能发布空的信息");
					return false;
				}
				
				if(strVal.length > 300){
					alert("字数不能大于300");
					return false;					
				}
				
				objCommentEditForm.find("input").attr("disabled", "disabled");
				objCommentEditForm.find("img").show();

				$.ajax({
			 		type:"POST",
					url:"../json/home/homeSayingEdit.php",
					async:true,
					data: {
						sid: strSayingId,
						val: strVal,
						atype: strActiveType
					},
					success:function(data){
						if($.trim(data) == juuyou.common.json.failure){
							alert("提交失败");
							objCommentEditForm.find("img").hide();
						}else{
							divCommentEdit.remove();
							objOwner.replaceWith(data);
							blSmallFlashKey = false;
						}
					}
				});
    					
    			return false;
    		}
    	);
		return false;
	});
});

//初始化Saying喜欢动作
$(document).ready(function(){
	$(".l_like").live("click", function(){
		var objDd = $(this).parents("li");
		var objActiveDiv = $(this).parents(".j_action_div");
		var objLikeSpan = $(this).parents(".j_like");
		var objLikeDiv = objDd.find(".j_likes");
		var strActiveId = objActiveDiv.attr("aid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingLike.php",
			async:true,
			data: {
				aid: strActiveId,
				act: "like"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objLikeSpan.hide();
					objLikeDiv.replaceWith(data);
				}
			}
		});
		return false;
	});
});

//初始化Saying扩展显示所有喜欢人的动作
$(document).ready(function(){
	$(".l_expandlikes").live("click", function(){
		var objDd = $(this).parents("li");
		var objActiveDiv = objDd.find(".j_action_div");
		var objLikeDiv = objDd.find(".j_likes");
		var strActiveId = objActiveDiv.attr("aid");

		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingLikeAll.php",
			async:true,
			data: {
				aid: strActiveId
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objLikeDiv.replaceWith(data);
				}
			}
		});

		return false;
	});
});

//初始化Saying关注动作
$(document).ready(function(){
	$(".l_focus").live("click", function(){
		var objDd = $(this).parents("li");
		var objActiveDiv = $(this).parents(".j_action_div");
		var objFocusSpan = $(this).parents(".j_focus");
		var objFocusDiv = objDd.find(".j_likes");
		var strActiveId = objActiveDiv.attr("aid");
		
		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingFocus.php",
			async:true,
			data: {
				aid: strActiveId,
				act: "focus"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objFocusSpan.hide();
					objFocusDiv.replaceWith(data);
				}
			}
		});
		return false;
	});
});


//初始化Saying扩展显示所有关注人的动作
$(document).ready(function(){
	$(".l_expandfocus").live("click", function(){
		var objDd = $(this).parents("li");
		var objActiveDiv = objDd.find(".j_action_div");
		var objLikeDiv = objDd.find(".j_likes");
		var strActiveId = objActiveDiv.attr("aid");

		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingFocusAll.php",
			async:true,
			data: {
				aid: strActiveId
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objLikeDiv.replaceWith(data);
				}
			}
		});

		return false;
	});
});


//初始化Saying显示隐藏的回复内容动作
$(document).ready(function(){
	$(".j_show_hide_saying").live("click", function(){
		var objDd = $(this).parents("li");
		objDd.find(".j_other_saying").show();
		$(this).parents(".expandcomment").hide();
		return false;
	});
});

//绑定know的同意动作
$(document).ready(function(){	
	$(".j_answer_up").live("click", function(){
		var objOwner = $(this).parents(".owner");
		var strSayingId = objOwner.attr("sid");
		var strKnowId = objOwner.attr("kid");
		
		objOwner.find("img").show();

		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingAnswerVote.php",
			async:true,
			data: {
				sid: strSayingId,
				kid: strKnowId,
				act: "U"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
					objOwner.find("img").hide();
					objOwner.find(".j_answer_up").hide();
					objOwner.find(".j_answer_down").hide();
				}else{
					objOwner.find("img").hide();
					objOwner.find(".j_answer_up").hide();
					objOwner.find(".j_answer_down").hide();
				}
			}
		});

	});
});

//绑定know的不同意动作
$(document).ready(function(){	
	$(".j_answer_down").live("click", function(){
		var objOwner = $(this).parents(".owner");
		var strSayingId = objOwner.attr("sid");
		var strKnowId = objOwner.attr("kid");
		
		objOwner.find("img").show();

		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingAnswerVote.php",
			async:true,
			data: {
				sid: strSayingId,
				kid: strKnowId,
				act: "D"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
					objOwner.find("img").hide();
					objOwner.find(".j_answer_up").hide();
					objOwner.find(".j_answer_down").hide();
				}else{
					objOwner.find("img").hide();
					objOwner.find(".j_answer_up").hide();
					objOwner.find(".j_answer_down").hide();
				}
			}
		});

	});
});



//绑定know的选中动作
$(document).ready(function(){	
	$(".j_know_select").live("click", function(){
		var objOwner = $(this).parents(".owner");
		var strSayingId = objOwner.attr("sid");
		var strKnowId = objOwner.attr("kid");
		var strActiveId = objOwner.attr("aid");

		objOwner.find("img").show();

		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingAnswerVote.php",
			async:true,
			data: {
				sid: strSayingId,
				kid: strKnowId,
				aid: strActiveId,
				act: "B"
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
					objOwner.find("img").hide();
				}else{
					objOwner.find("img").hide();
					objOwner.find(".j_know_select").hide();
				}
			}
		});

	});
});


//绑定关注视频点击播放动作
$(document).ready(function(){	
	$(".j_video_url_a").live("click", function(){
		var strVideoUrl = $(this).attr("videoUrl");
		var strActiveId = $(this).parents("li").attr("id");
		var strVideoTitleHtml = $(this).parents("li").find(".j_video_title_html_a").html();
		var objVideoHtml = $("<div style='display:none;' class='drift home_video j_video_drag_div' vaid='" + strActiveId + "'><div class='drift_title' style='cursor:move;'><span><a href='javascript:void(0);' title='关闭' class='close j_video_close_a'><img src='http://img.saywo.com/images/fixed/blank.gif' width='14' height='15' alt='关闭' /></a><h4 class='j_video_title'>" + strVideoTitleHtml + "</h4></span></div><div class='clear'></div><div class='drift_box'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' align='middle' height='374' width='450'><param name='movie' value='" + strVideoUrl + "'><param name='allowFullScreen' value='true'><param name='allowScriptAccess' value='always'><param name='quality' value='high'><param name='wmode' value='transparent'><embed lk_media='yes' lk_mediaid='lk_juiceapp_mediaPopup_1245305230619' allowscriptaccess='always' wmode='transparent' allowfullscreen='true' type='application/x-shockwave-flash' src='" + strVideoUrl + "' height='374' width='450'></object></div></div>");
		$("body").append(objVideoHtml);
		var objI=$(this).offset();
		if(blIsIE){
			var strCss={left:objI.left-2,top:objI.top};
		}else{
			var strCss={left:objI.left-2,top:objI.top-80};
		}
		objVideoHtml.css(strCss).draggable({ cancel: 'object' });
		objVideoHtml.fadeIn(300);
		
		//$(this).hide();
	});	
});	
$(document).ready(function(){	
	$(".j_video_close_a").live("click", function(){
		//$(this).parents(".j_video_drag_div").fadeOut(300);
		$(this).parents(".j_video_drag_div").html("");
		$(this).parents(".j_video_drag_div").remove();
		//var strActiveId = $(this).parents(".j_video_drag_div").attr("vaid");
		//$("#" + strActiveId).find(".j_video_url_a").fadeIn();
	});	
});	


//跟随功能
juuyou.profile.follow = function(){
	$.ajax({
 		type:"POST",
		url:"../json/follow/profileFollowDivShow.php",
		async:false,
		data: {
			mid: strMemberID
		},
		success:function(data){
			if($.trim(data) == juuyou.common.json.failure){
			}else{
				$("#j_follow_drift").html(data);
				juuyou.profile.followDivShow();
				$("#j_follow_btn").hide();
			}
		}
	});
}
juuyou.profile.followDivShow = function(){
	$("#j_follow_drift").fadeIn(200);
	$("#j_shadow").show();
}
juuyou.profile.followDivHide = function(){
	$("#j_follow_drift").hide();
	$("#j_shadow").hide();
}


// 获取个人群组列表
juuyou.profile.flashUserGroupList = function(strUID){
	var url = "http://g.saywo.com/json/profileInfoGroupList.php?uid=" + strUID + "&jsonCallback=?";  
	$.getJSON(url,function(json){
		var data = $.trim(json.msg);
		if(data == juuyou.common.json.failure){			
		}else{
			var strTemp = data.substr(0, 11);
			if(strTemp == "Bad Request"){
				return;
			}
			$("#j_ul_mygroup").html(data);
		}
	});  
}



//初始化Saying扩展显示所有愿望天使人的动作
$(document).ready(function(){
	$(".j_expandhopers").live("click", function(){
		var objDd = $(this).parents("li");
		var objActiveDiv = objDd.find(".j_action_div");
		var objHopersDiv = objDd.find(".j_hopers");
		var strActiveId = objActiveDiv.attr("aid");
		var strGiftId = objHopersDiv.attr("gid");
		var strUID = objHopersDiv.attr("uid");
		$.ajax({
	 		type:"POST",
			url:"../json/home/homeSayingHoperAll.php",
			async:true,
			data: {
				aid: strActiveId,
				gid: strGiftId,
				uid: strUID
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					objHopersDiv.replaceWith(data);
				}
			}
		});

		return false;
	});
});








