/*
 * 通用脚本（只需包含jquery.js及对应的显示层即可）
 */
/**
 * 展示提示信息的层
 * @param {} divId 层ID
 * @param {} closeId 关闭层按钮ID
 */
showDiv = function(divId,closeId){
	var sHeight,sWidth;
	var divHeigh=$("#"+divId).height();
	var divWidth=$("#"+divId).width();
	
	
	sHeight =(document.documentElement.clientHeight-divHeigh)/2+document.documentElement.scrollTop;
	sWidth=(document.documentElement.clientWidth-divWidth)/2+document.documentElement.scrollLeft;
	$("#"+divId).show();
	$("#"+divId).css('top',sHeight+'px');
	$("#"+divId).css('left',sWidth+'px');
	$("#"+closeId).click(function(){
		$("#"+divId).hide();
		//$("#erbigBox").css({height:'0',width:'0'});
	});	
}

showDivError = function(divId,closeId){
	var sHeight,sWidth;
	var divHeigh=$("#"+divId).height();
	var divWidth=$("#"+divId).width();
	
	
	sHeight =(document.documentElement.clientHeight-divHeigh)/2+document.documentElement.scrollTop;
	sWidth=(document.documentElement.clientWidth-divWidth)/2+document.documentElement.scrollLeft;
	
	$("#"+divId).show();
	$("#"+divId).css('top',sHeight+'px');
	$("#"+divId).css('left',sWidth+'px');
	$("#"+closeId).click(function(){
		$("#"+divId).hide();
		//$("#erbigBox").css({height:'0',width:'0'});
	});	
}

//展示错误信息
showErrors = function(errors){
	var errorHtml = "";
	$.each (eval(errors),function(index,error){
		errorHtml +=  error.error;
	});
	$("#error dd").html(errorHtml);
	showDivError("error","error_close");

	$("#error").css({top:sHeight+'px',left:sWidth+'px'});
	$("#error").animate({opacity: 1.0}, 3000).fadeOut("slow");
	$("#postProgress").fadeOut("slow",function(){
		$("#fancybox-overlay").hide();		
	});
}
//系统消息提示
showMsg = function(msg){
	var msgHtml = "";
	$.each (eval(msg),function(index,msg){
		msgHtml += msg.msg;
	});
	$("#success dd").html(msgHtml);
	showDiv("success","success_close");
	$("#success").animate({opacity: 1.0}, 3000).fadeOut("slow");
}

showMsg_all = function(msg, href){
	var msgHtml = "";
	$.each (eval(msg),function(index,msg){
		msgHtml += msg.msg;
	});
	$("#success dd").html(msgHtml);
	showDiv("success","success_close");
	$("#success").animate({opacity: 1.0}, 3000).fadeOut("slow");
	window.location.href=href;
}

/**
 * 展示酷贝标识
 */
function showKubei(level){
	if(level == 10)
		document.write("<a href=\"http://www.duanqu.com/help/help_3.html\" title=\"酷贝\" class=\"k\"  target=\"_blank\"><img src=\"http://www.duanqu.com/images/index201105/K.png\" style=\"margin-left:-2px;\" /></a>");
}

/**
 * 显示提示层(带背景，用于前台展示)
 */
alertShow = function(divId,closeId){
	var sHeight,sWidth;
	var divHeigh=$("#"+divId).height()/2;
	var divWidth=$("#"+divId).width()/2;
	sHeight =document.documentElement.clientHeight/2-divHeigh+document.documentElement.scrollTop;
	sWidth=document.documentElement.clientWidth/2-divWidth+document.documentElement.scrollLeft;
	$("#"+divId).show();
	$("#"+divId).css({top:sHeight+'px',left:sWidth+'px'});
	$("#erbigBox").css({height:document.body.scrollHeight +'px',width:document.body.scrollWidth+'px'});
	//alert(divHeigh);
	
	$("#"+closeId).click(function(){
		$("#"+divId).hide();
		$("#erbigBox").css({height:'0',width:'0'});
	});
}

/**
 * 添加订阅用户(需导入层文件)
 * 时间：2010-10-20
 * @param followid:被订阅用户编号;
 */
function com_addAttention(followid){
	$("#res_followid").attr("value",followid);
	alertShow('addRes','resClose');
}

/*
 * 添加好友，如果未登录，则提示登录
 */
function addFriend(friendid) {
	$.post("/commonaction.jhtml?method=showfriend&friendid=" + friendid,function(xml) {
		$(xml).find("resultXml").each(function() {
			var isLogin = $(this).children("isLogin").text();
			if (isLogin == 'false') {
				alertLogin();
			} else {
				var param = $(this).children("param").text();
				if (param == 'true') {
					var isSccc = $(this).children("isSccc").text();
					var isFriend = $(this).children("isFriend").text();
					if (isSccc == 'true' && isFriend == 'true') {
						showMsg("[{msg:'该用户已经是你的好友了！'}]");
					} else {
						var isSelf = $(this).children("isSelf").text();
						if (isSelf == 'true') {
							showErrors("[{error:'自己不能加自己为好友！'}]");
						}else{
							var userId = $(this).children("userId").text();
							var userName = $(this).children("userName").text();
							$("#f_userName").attr("value", userName);
							$("#f_userId").attr("value", userId);
							//$("#addFriendDiv").show();
							alertShow('addFriend','fridenClose');
							$("#addFriend").click();
						}
					}
				} else {
					showErrors("[{error:'系统出错！参数错误'}]");
				}
			}
		});
	});
}

//验证加好友消息
function checkAddFriendMsg(){
	var f_msgText = jQuery.trim($("#f_msgText").val());
	if(f_msgText=="" || f_msgText.length<1 ){
		showErrors("[{'error':'消息内容不能为空！'}]");
		return false;
	}else if(f_msgText.length>200){
		showErrors("[{'error':'消息内容不能超过200字！'}]");
		return false;
	}else{
		return true;
	}
}

//加好友返回消息展示一
showFriendMeg =function(msg){
    showMsg(msg);
}

//加好友返回消息展示二
showAddFriendSucc =function(msg){
    showMsg(msg);
    $("#f_msgText").attr("value", "");
    $(".alertDiv").hide();
	$("#erbigBox").css({height:'0',width:'0'});
}

//正确消息提示
showSuccMsg = function(msg){
	$("#titleStr").attr("value", "");
	$("#title").attr("value", "");
	$("#msgText").attr("value", "");	
	showMsg(msg);
    $.fancybox.close();
	//$.fancybox.parent.close();
}

//错误消息提示
showErrorMsg = function(msg){
	$("#titleStr").attr("value", "");
	$("#title").attr("value", "");
	$("#msgText").attr("value", "");	
	showErrors(msg);
    $.fancybox.close();
	//$.fancybox.parent.close();
}

////展示错误信息
//showErrors = function(errors){
//	var errorHtml = "";
//	$.each (eval(errors),function(index,error){
//		errorHtml +=  error.error;
//	});
//	$("#error dd").html(errorHtml);
//	showDiv("error","error_close");
//	$("#error").animate({opacity: 1.0}, 3000).fadeOut("slow");
//	$("#postProgress").fadeOut("slow",function(){
//		$("#fancybox-overlay").hide();		
//	});
//}
////系统消息提示
//showMsg = function(msg){
//	var msgHtml = "";
//	$.each (eval(msg),function(index,msg){
//		msgHtml += msg.msg;
//	});
//	$("#success dd").html(msgHtml);
//	showDiv("success","success_close");
//	$("#success").animate({opacity: 1.0}, 3000).fadeOut("slow");
//}
