﻿//全局变量

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) {
        (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)
    { 
        var MSG1 = new CLASS_MSN_MESSAGE(newmsg.userid,unescape(newmsg.nickname),newmsg.photo,unescape(newmsg.sex)); 
        MSG1.show();  
    }
}
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;
}
function CLASS_MSN_MESSAGE(id,nickname,photo,sex){  
    this.userid  = id;  
    this.photo  = photo;
    if(this.photo == '')
    {
    if(sex=='她') this.photo ='default_girl.jpg';
    else if(sex=='他') this.photo ='default_man.jpg';
    } 
	this.nickname  = nickname;
	this.sex = sex;
    this.timeout = 500;  
    this.speed    = 12; 
    this.step    = 5; 
	this.width    = 264;  
    this.height = 146;  
    this.right    = screen.width -16;  
    this.bottom = screen.height; 
    this.left    = this.right - this.width; 
    this.top    = this.bottom - this.height; 
    this.timer    = 0; 
    this.pause    = false;
    this.close    = false;
    this.autoHide    = true;
}
CLASS_MSN_MESSAGE.prototype.hide = function(){  
    if(this.onunload()){  
        var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top; 
        var me  = this;  
        if(this.timer>0){   
            window.clearInterval(me.timer);  
        }  
        var fun = function(){  
            if(me.pause==false||me.close){
                var x  = me.left; 
                var y  = 0; 
                var width = me.width; 
                var height = 0; 
                if(me.offset>0){ 
                    height = me.offset; 
                } 
                y  = me.bottom - height; 
     
                if(y>=me.bottom){ 
                    window.clearInterval(me.timer);  
                    me.Pop.hide();  
                } else { 
                    me.offset = me.offset - me.step;  
                } 
                me.Pop.show(x,y,width,height);    
            }             
        }  
        this.timer = window.setInterval(fun,this.speed)      
    }  
}  
CLASS_MSN_MESSAGE.prototype.onunload = function() {  
    return true;  
}
CLASS_MSN_MESSAGE.prototype.oncommand = function(){ 
    this.hide(); 
}
CLASS_MSN_MESSAGE.prototype.show = function(){  

    var oPopup = window.createPopup(); //IE5.5+  
    this.Pop = oPopup; 
  	var str = "<dl id='popWin' style='width:264px; height:146px; border:1px solid #E42C98; position:absolute; top:0; z-index:99999;'> <dt style='height:28px; background:url(http://www.qingrenw.com/images/float_title_bg.jpg) no-repeat; border-bottom:1px solid #E42C98;'>";
str += "<a id='btSysClose' style='float:right; margin:6px; cursor:pointer;'><img src='http://www.qingrenw.com/images/float_close.jpg' /></a></dt><dd id='btCommand' tag='"+ this.userid +"' style='margin:0; cursor:pointer; font-size:12px; '><div style='width:72px; height:88px;  background:url(http://www.qingrenw.com/images/img_frame.jpg) no-repeat; padding:7px 9px 9px 7px; margin:7px 5px; float:left; _margin:7px 5px 0 3px;'>";
str += "<a 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/" + this.photo+"' /></a></div>";
str += "<div style='margin-top:8px; line-height:24px; color:#153D6E;'> <a  style='color:#09f; text-decoration:underline;'>"+ this.nickname +"</a>正在浏览你的资料";
str += "<p style='line-height:18px; margin:0;'>"+ this.sex +"可能对你很感兴趣，遇到缘分千万不要错过，马上主动出击吧！ </p>";
str += "<a 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; '>浏览"+ this.sex +"的资料</a></div></dd></dl>";
    oPopup.document.body.innerHTML = str;   
    this.offset  = 0; 
    var me  = this;  
    oPopup.document.body.onmouseover = function(){me.pause=true;}
    oPopup.document.body.onmouseout = function(){me.pause=false;}
    var fun = function(){  
        var x  = me.left; 
        var y  = 0; 
        var width    = me.width; 
        var height    = me.height; 
            if(me.offset>me.height){ 
                height = me.height; 
            } else { 
                height = me.offset; 
            } 
        y  = me.bottom - me.offset; 
        if(y<=me.top){ 
            me.timeout--; 
            if(me.timeout==0){ 
                window.clearInterval(me.timer);  
                if(me.autoHide){
                    me.hide(); 
                }
            } 
        } else { 
            me.offset = me.offset + me.step; 
        } 
        me.Pop.show(x,y,width,height);    
    }
    this.timer = window.setInterval(fun,this.speed)      
    var btClose = oPopup.document.getElementById("btSysClose");  
    btClose.onclick = function(){  
        me.close = true;
        me.hide();  
    }
	var btCommand = oPopup.document.getElementById("btCommand"); 
        btCommand.onclick = function(){ 
        me.oncommand(); 
        window.location.href="http://www.qingrenw.com/user1/"+me.userid +".html";
    }
} 
