﻿//全局变量

var IsLogined = false;
var QingRenID = 0;
var NickName = "";
var LetterNum =0;
function GetUserCookie() {
    var MyCookie = document.cookie.toLowerCase();
    re = /qingrenid=(\d+)&/g;
    if (re.test(MyCookie)) {
        IsLogined = true;
        QingRenID = RegExp.$1; 
        re2 = /nickname=([^&]+)/g;
        re2.test(MyCookie);
        NickName = unescape(RegExp.$1).replace("+", " ").replace("+", " ");
        return QingRenID;
    }
}
function ShowTopLogined() {
    var LoginedDiv = document.getElementById("LoginedTopDiv");
    var UnLoginedDiv = document.getElementById("UnLoginedTopDiv");
    if (IsLogined) {
        var str = "<dl id='popWin' style='width:264px;  height:0; overflow:hidden; display:none; border:1px solid #E42C98; position:absolute; z-index:99999; background-color:#fff; right:0; bottom:0;'> <dt style='height:28px; background:url(/images/float_title_bg.jpg) no-repeat; border-bottom:1px solid #E42C98;'>";
        str += "<a href='javascript:tips_pop();' style='float:right; margin:6px; cursor:pointer;'><img src='/images/float_close.jpg' /></a></dt>";
        str += "<dd id='btCommand' style='margin:0; font-size:12px; '></dd></dl>";
        document.write(str);
        (new Ajax()).GetData("/Control/LoginJson.ashx?action=top", FillResInfo);
        LoginedDiv.style.display = "block";
        UnLoginedDiv.style.display = "none";
    } else {
        LoginedDiv.style.display = "none";
        UnLoginedDiv.style.display = "block";
    }
}
GetUserCookie();
ShowTopLogined();

var g_blinkid = 0;
var g_blinkswitch = 0;
var g_blinktitle = document.title;
var g_newmsg_sound = null;

var g_check =0;
function FillResInfo(info) {
    var userinfo = eval("(" + info + ")");
    LetterNum = userinfo.letternum;
    var loginedHtml = "欢迎 "
    loginedHtml += "<a href='/User/usercenter.aspx' class='green'>" + NickName + "</a> 来到玫瑰情人网，";

    loginedHtml += "你有站内信: <a href='/User/Message/GetMsg.aspx' class='red1' target='_top'><span id='InBox'>" + userinfo.letternum + "</span>条新</a>";
    loginedHtml += "，你可通过<a href='/User/pay/pay.aspx'  target='_blank' class='blue'>充值</a>来兑换情人豆查看联系方式，<a href=\"javascript:window.external.AddFavorite('http://www.qingrenw.com/', '玫瑰情人网')\" target='_self' class='blue'>收藏情人网</a>方便下次登录！<span id='head_msgsound'></span>";
    loginedHtml += " <a href='/control/loginout.ashx' class='blue'>退出</a>";
    $("LoginedTopDiv").innerHTML = loginedHtml;
    setInterval(checkNewMsg, 60000);
}
function checkNewMsg()
{
    (new Ajax()).GetData("/Control/UserRes.ashx?q="+Math.random(),GetNewMsgRes);
}
function GetNewMsgRes(info)
{   
    if(info=="") return;
    var newmsg = eval("(" + info + ")");
    if(newmsg.letternum>0)
    {
        checkNewMsgShow(newmsg.letternum);
    } 
    if(newmsg.userid>0)
    { 
        $('popWin').style.height='0px';
        var thesex = unescape(newmsg.sex);
        var photo  = newmsg.photo;
        if(photo == '')
        {
            if(newmsg.sex=='她') this.photo ='default_girl.jpg';
            else if(newmsg.sex=='他') this.photo ='default_man.jpg';
        }
        var str = "<div style='width:72px; height:88px;  background:url(/images/img_frame.jpg) no-repeat; padding:7px 9px 9px 7px; margin:7px 5px; float:left; _margin:7px 5px 0 3px;'>";
            str += "<a href='http://www.qingrenw.com/user1/"+ newmsg.userid +".html' target='_blank' onclick='tips_pop()' style='width:72px; height:88px; font-size:76px; display:block; overflow:hidden;' ><img style='width:72px; vertical-align:middle; border:0;' src='http://image.qingrenw.com/qingrenw.com/Userimage/Small/" + photo+"' /></a></div>";
            str += "<div style='margin-top:8px; line-height:24px; color:#153D6E;'> <a href='http://www.qingrenw.com/user1/"+ newmsg.userid +".html' target='_blank' onclick='tips_pop()' style='color:#09f; text-decoration:underline;'>"+ unescape(newmsg.nickname) +"</a>正在浏览你的资料";
            str += "<p style='line-height:18px; margin:0;'>"+ thesex +"可能对你很感兴趣，遇到缘分千万不要错过，马上主动出击吧！ </p>";
            str += "<a href='http://www.qingrenw.com/user1/"+ newmsg.userid +".html'  target='_blank'  onclick='tips_pop()' style='width:90px; height:22px; line-height:24px; background:url(http://www.qingrenw.com/images/btn_lookInfo.jpg) no-repeat; display:block; text-align:center; float:right; margin-right:5px; text-decoration:none; color:#153D6E; '>浏览"+ thesex +"的资料</a></div>";
        $("btCommand").innerHTML = str;
        setTimeout("tips_pop()",6000);
    }
}

var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
function IeTest() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body; 
}
function MoveObj(obj, x, y) {
    obj.style.left = x + "px";
    obj.style.top = y + "px";
    if (arguments.length >= 4) {
        obj.style.width = arguments[3] + "px";
        obj.style.height = arguments[4] + "px";
    }
}
function GetClientInfo(x) {
    switch (x) {
        case "w":
            return ns ? innerWidth : IeTest().clientWidth;
        case "h":
            return ns ? innerHeight : IeTest().clientHeight;
        case "x":
            return ns ? pageXOffset : IeTest().scrollLeft;
        case "y":
            return ns ? pageYOffset : IeTest().scrollTop;
    } 
 }
function Pose(x, y) { this.x = x; this.y = y; }


function ObjShow() {
    if(IsLogined)
    {
        var thisObj =$("popWin");
        thisObj.W = 264;
        thisObj.H = 146;
        var nBody = new Pose(GetClientInfo("w"), GetClientInfo("h"));
        var nLeft = new Pose(GetClientInfo("x"), GetClientInfo("y"));
        var mLeft = new Pose((nBody.x - thisObj.W - 5) + nLeft.x, (nBody.y - thisObj.H - 5) + nLeft.y);
        MoveObj(thisObj, mLeft.x, mLeft.y);
    }
}
window.onscroll = function ScrollWindow() { ObjShow();}
window.onresize = function ResizeWindow() { ObjShow(); }


function tips_pop(){
  var MsgPop=document.getElementById("popWin");
  var popH=parseInt(MsgPop.style.height);
   if (popH==0){
    MsgPop.style.display="block";
    show=setInterval("changeH('up')",2);
   }
  else { 
   hide=setInterval("changeH('down')",2);
  }
}
function changeH(str) {
 var MsgPop=document.getElementById("popWin");
 var popH=parseInt(MsgPop.style.height);
 if(str=="up"){
  if (popH<=146){
  MsgPop.style.height=(popH+4).toString()+"px";
  }
  else{  
  clearInterval(show);
  }
 }
 if(str=="down"){ 
  if (popH>=4){  
  MsgPop.style.height=(popH-4).toString()+"px";
  }
  else{ 
  clearInterval(hide);   
  MsgPop.style.display="none";
  }
 }
}
function checkNewMsgShow(req)
{
    stopBlinkNewMsg();
    g_blinkid = setInterval(blinkNewMsg, 1000);
    $("head_msgsound").innerHTML = showflash("/images/newmsg.swf",0,0,false);
    $("InBox").innerText =  parseInt(req); 
}
function stopBlinkNewMsg()
{
	if (g_blinkid)
	{
		clearInterval(g_blinkid);
		g_blinkid = 0;
		document.title = g_blinktitle;
	}
}
function blinkNewMsg()
{
	document.title = g_blinkswitch % 2 ? "【　　　】 - " + g_blinktitle : "【新消息】 - " + g_blinktitle;
	g_blinkswitch++;
}
function showflash(url, w, h, t) {
    var obj  ="";
    obj += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">';
    obj += '<param name="movie" value="'+url+'">';
    obj += '<param name="quality" value="high">';
    if(t) obj += '<param name="wmode" value="transparent">';
    obj += '<param name="menu" value="false">';
    obj += '<embed src="'+url+'" width="'+w+'" height="'+h+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>';
    obj += '</object>';
    return obj;
}
