﻿// 消息提示窗口
var enetdivTop,enetdivLeft,enetdivWidth,enetdivHeight,enetdocHeight,enetdocWidth,enetobjTimer,i = 0;
 
function popMsgOnLoad(userId)
{
	try
	{
		if (userId == 0) return;
		requestMsgCenter(userId,"");
	}
	catch(e){}
}

 
// 请求消息中心
function requestMsgCenter(userId,method)
{
	var url = "/MsgDoAjax.aspx?userId=" + userId;
	g_returnMsgBody = PostRequest(url,"",false);
	var msgBodyArray = g_returnMsgBody.split("|||");
	//消息格式:account|||userId|||nickname|||headUrl|||type|||objectId
	if (msgBodyArray.length != 6) return;
	genMsgBox(method,msgBodyArray[0],msgBodyArray[1],msgBodyArray[2],getZoomImgFile(msgBodyArray[3],40),msgBodyArray[4],msgBodyArray[5]);
}

// 取缩略图文件
function getZoomImgFile(path,zoomSize)
{
	var zoomImg;
	path = path.toLowerCase();
	path = path.replace(".jpg","_" + zoomSize + ".jpg");
	path = path.replace(".gif","_" + zoomSize + ".gif");
	return path;
}

function popMsg(userId)
{
	try
	{
		if (userId == 0) return;
		requestMsgCenter(userId,"interval");
	}
	catch(e){}
}

function enetgetMsg()
{
    try
    {
		enetdivTop = parseInt(document.getElementById("enetMeng").style.top,10)
		enetdivLeft = parseInt(document.getElementById("enetMeng").style.left,10)
		enetdivHeight = parseInt(document.getElementById("enetMeng").offsetHeight,10)
		enetdivWidth = parseInt(document.getElementById("enetMeng").offsetWidth,10)
		enetdocWidth = document.body.clientWidth;
		enetdocHeight = document.body.clientHeight;
		document.getElementById("enetMeng").style.top = parseInt(document.body.scrollTop,10) + enetdocHeight + 10;
		document.getElementById("enetMeng").style.left = parseInt(document.body.scrollLeft,10) + enetdocWidth - enetdivWidth
		document.getElementById("enetMeng").style.visibility="visible"
		enetobjTimer = window.setInterval("enetmoveDiv()",10)
    }
    catch(e){}
} 
　
function enetresizeDiv()
{
	i+=1;
	if(i>600) enetcloseDiv();
	try
	{
		enetdivHeight = parseInt(document.getElementById("enetMeng").offsetHeight,10)
		enetdivWidth = parseInt(document.getElementById("enetMeng").offsetWidth,10)
		enetdocWidth = document.body.clientWidth;
		enetdocHeight = document.body.clientHeight;
		document.getElementById("enetMeng").style.top = enetdocHeight - enetdivHeight + parseInt(document.body.scrollTop,10)
		document.getElementById("enetMeng").style.left = enetdocWidth - enetdivWidth + parseInt(document.body.scrollLeft,10)
	}
	catch(e){}
}

function enetmoveDiv()
{
	try
	{
		if(parseInt(document.getElementById("enetMeng").style.top,10) <= (enetdocHeight - enetdivHeight + parseInt(document.body.scrollTop,10)))
		{
     		window.clearInterval(enetobjTimer)
     		enetobjTimer = window.setInterval("enetresizeDiv()",1)
		}
     	enetdivTop = parseInt(document.getElementById("enetMeng").style.top,10)
     	document.getElementById("enetMeng").style.top = enetdivTop - 1
     }
     	catch(e){}
}

function enetcloseDiv()
{
	document.getElementById('enetMeng').style.visibility='hidden';
	if(enetobjTimer) window.clearInterval(enetobjTimer)
}

function genMsgBox(method,account,userId,nickname,headUrl,type,objectId)
{
	var MSG_ARTICLE_COMMENT = 0;
	var MSG_PIC_COMMENT = 1;
	var MSG_BLOG_COMMENT = 2;
	var MSG_SMS = 3;
		
	//消息格式:account|||userId|||nickname|||headUrl|||type|||objectId
	var strType = '';
	var blogUrl = '';
	
	switch(parseInt(type))
	{
		case MSG_ARTICLE_COMMENT :
			strType = "刚刚评论了您的博客日记";
			blogUrl = '<a href="javascript:void(0);"  onclick="javascript:openUserSpace(\'' + g_viewUserAccount + '\',\'' + g_viewUserId + '\',\'index.aspx#sModule=blog&sUrlMain=Article/' + objectId + '.html\');">查看详情....</a>';
			break;
		case MSG_PIC_COMMENT :
			strType = "刚刚评论了您的博客相片";
			blogUrl = '<a href="javascript:void(0);"  onclick="javascript:openUserSpace(\'' + g_viewUserAccount + '\',\'' + g_viewUserId + '\',\'index.aspx#sModule=photo&sUrlMain=Pic/' + objectId + '.html\');">查看详情....</a>';
			break;
		case MSG_BLOG_COMMENT :
			strType = "刚刚给您发了一条评价";
			blogUrl = '<a href="javascript:void(0);"  onclick="javascript:openUserSpace(\'' + g_viewUserAccount + '\',\'' + g_viewUserId + '\',\'index.aspx#sModule=endorsement&sUrlMain=Comment/CommentList.aspx?type=2\');">查看详情....</a>';
			break;
		case MSG_SMS :
			strType = "刚刚给您发了一条站内消息";
			blogUrl = '<a href="javascript:void(0);"  onclick="javascript:openUserSpace(\'' + g_viewUserAccount + '\',\'' + g_viewUserId + '\',\'index.aspx#sModule=message&sUrlMain=Message/InMsgList.aspx\');">查看详情....</a>';
			break;
		default:
			strType = "unkown";
			return;
	}
 
	var result = "";
 
	try
	{
		var div = document.getElementById("enetMeng");
		div.parentNode.removeChild(div); //删除
	}
	catch(e){}

	result += '<DIV  id=enetMeng style="BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; VISIBILITY: visible; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: 200px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: -200px; HEIGHT: 100px">'; 
	result += '<TABLE WIDTH=200 BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor="#DAE6FC">';
	result += '<TR >';
    result += '          <td width="180" valign="middle" height="18" ><b><font color="#FF6600"><img src="/images/ico/ico_advert.gif" align="absmiddle" border="0"> 温馨提示</font></b></td>';
    result += '          <td width="20"  valign="middle" style="cursor:hand" onClick="enetcloseDiv()"  ><font color=red>×</font></td>';
	result += '</TR>';
	result += '<TR>';
    result += ' <TD height="80" valign="middle">';
	result += '<table width="100%" border="0" cellspacing="0" cellpadding="1">';
	result += '<tr> ';
	 result += ' <td width="35%" align="center"><p class="usericon40">	<a href="javascript:void(0);" onclick="javascript:openUserSpace(\'' + account + '\',\'' + userId + '\',\'\');" title="访问' + nickname + '的个人博客">	<img src="' + PIC_FILE_URL + headUrl + '" border="0"></a></p></td>';
    result += ' <td width="60%" align="center"><font  color="#FF6600">' + nickname + strType + '<a href="#">,<br>' + blogUrl + '</font></td>';
	result += '</tr>';
	result += '</table>';
	result += '</TABLE>';
	result += '</div>';

	if (method == "interval")
	{ 
		i = 0;
		document.getElementById("divMsg").innerHTML = result;
		enetgetMsg();
		enetresizeDiv();
	}
	else
	{
		i = 0;
		document.write(result);
		window.onload = enetgetMsg;
		window.onresize = enetresizeDiv;
	}
}
