﻿if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=='Netscape')?1:0;
	var isIE=(navigator.appName.indexOf('Microsoft')!=-1)?1:0;
}

/// business function
//ajax成功返回代码
var AJAX_RETURN_SUCC = "TRUE";

// 图片路径
var PIC_FILE_URL = "/pics/";

// 消息中心页面请求时间(秒)
var MSG_CLEAR_TIME = 10;
// 消息中心页面请求开关
var MSG_IS_OPEN = true;

// 缩略图
var PIC_MODE_ICO = 40;
var PIC_MODE_SMALL = 128;
var PIC_MODE_MID = 240;
var PIC_MODE_BIG = 450;

// 访问身份
var USER_IDENT_GUEST = 0;
var USER_IDENT_REG = 1;
var USER_IDENT_FRIEND = 2;
var USER_IDENT_SELF = 3;

// 绝对路径
var WEB_URL = "http://www.gotoloving.cn";

//  打开用户空间 
function openUserSpace(sAccount,sId,sUrl) {
	//Begin get the size of the UserSpace window
    var nNeedWidth = 990;
    var nNeedHeight = 690;
    if(screen.width < 1024){
        nNeedWidth = Math.round(nNeedWidth * 0.78125);
        nNeedHeight = Math.round(nNeedHeight * 0.78125);
    }
    var nCurrentWidth = 0;
    var nCurrentHeight = 0;

    var nCurrentTop = window.screenTop + 10;
    var nCurrentLeft = window.screenLeft + 10;
    if(nCurrentTop > 100 || nCurrentLeft > 100){
        nCurrentTop = 0;
        nCurrentLeft = 0;
    }

    if(nNeedWidth > screen.avilWidth) {
        nCurrentWidth = screen.avilWidth;
    } else {
        nCurrentWidth = nNeedWidth;
    }
    if(nNeedHeight > screen.avilHeight) {
        nCurrentHeight = screen.avilHeight;
    } else {
        nCurrentHeight = nNeedHeight;
    }
    var sFeature = 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizeable=yes';
    sFeature += ',left='+nCurrentLeft+',top='+nCurrentTop;
    sFeature += ',width=' + nCurrentWidth + ',height=' + nCurrentHeight;
    if(nCurrentWidth < nNeedWidth || nCurrentHeight < nNeedHeight) {
        sFeature += ',scrollbars=yes';
    } else {
        sFeature += ',scrollbars=no';
    }
    //End get the size of the UserSpace window

	if ('' == sAccount) {
		return false;
	}
    var sWinName = 'userspace_' + sAccount;
    var sUrlPage = getBlogUrl(sAccount,sId,sUrl);
	oWin = window.open(sUrlPage, '', sFeature);

    oWin.focus();
	return oWin;
}

// 构造博客url
function getBlogUrl(account,id,url)
{
	var check = /^[a-zA-Z0-9\-]+$/;

	if (!check.test(account))
		account = id;
	
	return "http://" + account + ".gotoloving.cn/blog/" + url;
}

// 取得绝对路径
function genWebUrl()
{
	document.write(WEB_URL);
}

// blog中聚会绝对路径
function genBlogMeetUrl(id,title,status)
{ 
	var cla = "";
	if (status == "0") 
	{
		cla = " class=redFont ";
		title += " (召集中...)";
	}
	document.write("<a href='" + WEB_URL + "/Meet/Html/" + id + ".html#ok' target=_blank ><span " + cla + ">" + title + "</span></a>"); 

}

// 登陆数据校验
function verifyLogin(formName)
{
	if (!ValidLen("用户名",formName.iptAccount,2,20)) return false;
	if (!ValidLen("密码",formName.iptPassword,2,30)) return false;
	
	return true;
}

// 日记链接构造
function genTitle(account,userId,divName,title,id)
{
	GetElem(divName).innerHTML = "<a title='浏览该篇日记'  href='javascript:void(0);' onclick=\"javascript:openUserSpace('" + account + "','" + userId + "','index.aspx#sModule=blog&sUrlMain=Article/ArticleView.aspx?id%3D" + id + "');\">" + title + "</a>";
}

// 加为好友的弹出窗口
function popAddFriend(url)
{
	var  iWidth = 350; //模态窗口宽度
	var  iHeight = 250;//模态窗口高度
	var  iTop = (window.screen.height-iHeight)/2;
	var  iLeft = (window.screen.width-iWidth)/2;
	window.open (url, 'popwindow', 'height=' + iHeight + ', width=' + iWidth + ', top=' + iTop + ', left=' + iLeft + ', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
}

// 男女转换
function genSexIco(sex)
{
	var result = "";
	if (sex == 0)
		result = '<IMG align=absmiddle title="::帅哥哦" src="/images/ico/ico_male.gif">';
	else
		result = '<IMG title="::美女哦" align=absmiddle src="/images/ico/ico_female.gif">';
	document.write(result);
}

//校验是否登陆
function checkIsLogin()
{
	return (g_viewUserId > 0) ? true : false;
}

//检验是否VIP
function checkIsVip()
{
	return g_viewUserIsVip;
}

// 取缩略图文件
function getZoomImgFile(path,zoomSize)
{
	var zoomImg;
	path = path.toLowerCase();
	path = path.replace(".jpg","_" + zoomSize + ".jpg");
	path = path.replace(".gif","_" + zoomSize + ".gif");
	return path;
}

var oldLeftMenuBackgroundColor;

// 左侧菜单鼠标效果
function onMouseOverLeftMenu(obj)
{
	oldLeftMenuBackgroundColor = obj.style.backgroundColor;
	obj.style.backgroundColor = "#ffffff";
}

function onMouseOutLeftMenu(obj)
{
	obj.style.backgroundColor = oldLeftMenuBackgroundColor;
}

function highLeftMenu(objName)
{
	$(objName).style.backgroundColor="#ffffff";
}

// 发送站内消息
function sendMsg(account,ownerUserId)
{
	if (g_viewUserId == 0)
	{
		alert("请先登陆,再发站内消息");
		return;
	} 
	if (g_viewUserId == ownerUserId)
	{
		alert("不能给自己发站内消息");
		return;
	}
	popAddFriend(getBlogUrl(account,ownerUserId,'Message/MsgSendPop.aspx?userId=' + g_viewUserId));
}

// 申请好友
function addFriendInvite(ownerUserNickname,ownerUserId,account)
{
	if (g_viewUserId == 0)
	{
		alert("请先登陆,再添加好友");
		return;
	} 
	if (g_viewUserId == ownerUserId)
	{
		alert("不能添加自己为好友");
		return;
	}
	popAddFriend(getBlogUrl(account,ownerUserId,'friend/FriendAdd.aspx?friendName=' + escape(ownerUserNickname) + '&id=' + ownerUserId));
}

// 添加收藏
function addFav(account,ownerUserId)
{
	var url = "/DoAjax.aspx?method=addBlogFav&id=" + ownerUserId;
	AjaxRequest(url,"",addFavCallBack);
}
 
function addFavCallBack(ret, info, bFromServer)
{
	if (ret != "TRUE")
	{
		alert("收藏该博客失败:" + ret);
	}
	else
		alert("收藏该博客成功!");
}

// 取得Top内容
function getTop(id)
{
	var today = new Date();
	var url = "/Html/Top/" + id + ".html?date=" + today.getHours() + today.getMinutes() + today.getSeconds();
	AjaxRequestGet(url,"",getTopCallBack);
}

function getTopCallBack(ret, info, bFromServer)
{
	 $('meetadimg').innerHTML = ret;
}

// 取得Help内容
function getHelp(type)
{
	var today = new Date();
	var url = "/Html/Help/Left_" + type + ".html?date=" + today.getHours() + today.getMinutes() + today.getSeconds();
	AjaxRequestGet(url,"",getHelpCallBack);
}

function getHelpCallBack(ret, info, bFromServer)
{
	 $('divHelpContent').innerHTML = ret;
}

