﻿ //=============== popup slide =====================================
var onmouseOverpopup=0;
var popup_height = 0;
var step = 4;
var time = 30;
var frmshow="divpopup";
var htmldiv = "<div style='width:296px;right:0px;border:1px solid #999;background-color:#fff;vertical-align:bottom;padding:2px;' onmouseover='setmouseover()' onmouseout='setmouseout()'><div style='background-color:#F0F1F2;height:95px;'><div style='text-align:center;font-weight:bold;padding:10px 0px 3px 0px;'>Ginger<span class='asia'>Chat</span> Alert!</div><div style='text-align:center;vertical-align:top;padding-bottom:5px;'>|data|</div></div></div>";

function showMSNPopup(visible){
    var objPopup = document.getElementById(frmshow);
    if (objPopup) {
        var height = parseInt(objPopup.style.height);
        if(visible){
            objPopup.style.display = "";
            setTimeout("slide(true)", time);
        }else{
            if(onmouseOverpopup==0){
                setTimeout("slide(false)", time);
            }else{
                setTimeout("showMSNPopup(false)",4000);
            }
        }
    }
}

function slide(isUp){
    var mystep = (!isUp)? -step: step;
    var objPopup = document.getElementById(frmshow);
    //alert(objPopup.style.bottom);
    if(isUp && parseInt(objPopup.style.bottom) >= 0) {
        objPopup.style.bottom = "15px";
        return;
    }else if(!isUp && parseInt(objPopup.style.bottom) <= -parseInt(objPopup.style.height)){
        objPopup.style.display = "none";
        objPopup.style.bottom = "-"+objPopup.style.height;
        return;
    }
    objPopup.style.bottom = (parseInt(objPopup.style.bottom) + mystep)+"px";
    setTimeout("slide("+isUp+")", time);
}

function showballon(n,t){
    frmshow="divpopup";
    var countnewmsn=n;
    var boxsetheight=(85*countnewmsn)+5;
    var objPopup = document.getElementById(frmshow);
    //setdiv()
    objPopup.style.height=boxsetheight+"px";
    objPopup.style.bottom="-"+(boxsetheight)+"px";
    //objPopup.style.bottom = "20px";
    objPopup.innerHTML=t;
    showMSNPopup(true);
    setTimeout("showMSNPopup(false)",20000);
    return false;
}

var stlogin=1;
var mNewOn ="";
var nowmsg =0;
var touser=0;
var timerefreshmsg=1;   // fix delay First evnt refreshmsg in msgbox //*1
var setIntervalId = 0;

function newcontact(){
    var qry = 'showall=1&Status=7&nowmsg='+nowmsg; //Status=4
    jQuery.ajax({
        type: "POST",
        url: "memberchat/genIconChat.ashx",
        data: qry,
 
        success: function(msg){
            //if (msg != "")
            if (msg != ""){
                //msg=-1 >> Not Login
                mNewOn="";
                if(msg=="-1"){
                    stlogin=0;
                    if(stlogin==0){
                        clearInterval( setIntervalId );
                    }
                    
                    /* Clear number friends chat */
                    var divTotalChat = jsget('num_f_chat_online');
                    var divAhefTotalChat = jsget('a_num_f_chat_online');
                    if(divTotalChat && divAhefTotalChat){
                       var ValNumChat = divTotalChat.html();
                       if(ValNumChat!=''){
                            divTotalChat.html("");
                            divAhefTotalChat.attr("title", 'Click to Open GingerChat');
                       }
                    }
                }else{
                    var datax=msg;
                    // ==== show ballon ====
                    if(datax==undefined || datax==""){}else{
                        var txtmsg=datax.split("|(aa*|)");
                        var dataallnewon ="";
                        var ctxt=0;
                        for(i=0;i<txtmsg.length;i++){
                            var alldata=txtmsg[i];
                            var datarow=alldata.split("|@@*|");
                            var msgid= parseInt(datarow[0]);
                            var uid=datarow[3];
                            var uname=datarow[1];
                            var totaltochat = datarow[4];
                            
                            nowmsg=msgid;
                            /* start mNewOn.indexOf(uname)==-1 && */
                            if(mNewOn.indexOf(uname)==-1 && uname!=undefined){
                                mNewOn +=","+uname;
                                
                                ctxt=ctxt+1;
                                var msgd=uname+" wants to chat with you!<br/>"+uname+" says: "+datarow[2];
                                var lnkmsg=htmldiv.replace("|data|",msgd+"<br/><a style='cursor:pointer;' onclick='openpopup("+uid+");return false;' onMouseOver='setmouseover()' onMouseOut='setmouseout()'>Click here to open Ginger<span class='asia'>Chat</span> window</a>");
                                // 
                                dataallnewon=dataallnewon+lnkmsg;
                            }
                            /* End */
                            
                            /* Set number friend want to chat with us */
                            var divTotalChat = jsget('num_f_chat_online');
                            var divAhefTotalChat = jsget('a_num_f_chat_online');
                            if(divTotalChat && divAhefTotalChat){
                               if(totaltochat!='' && totaltochat!=undefined && parseInt(totaltochat) > 0){
                                    divTotalChat.html(" (" + totaltochat + ")");
                                    divAhefTotalChat.attr("title", '' + totaltochat + ' GingerFriends wants to chat with you!');
                               }else{
                                    divTotalChat.html(" (0)");
                                    divAhefTotalChat.attr("title", 'Click to Open GingerChat');
                               } 
                            }
                        }
                       if(dataallnewon!=""){
                            showballon(ctxt,dataallnewon);   
                       } 
                    }
                    // ==== end show ballon ====
                }
                //end msg=-1
             }
             //end if (msg != "")
        },
        fail: function(msg){
            alert('failed');
        }
    });
}

function openpopup(x){
    win = window.open("MemberChat/GingerChat.aspx?touser="+x+"",'ginger_chat','height=630,width=570,left='+(screen.width-570)/2+',top='+(screen.height-630)/2+',resizable=yes,scrollbars=no,toolbar=no,status=no'); 
    win.focus();
}

function setmouseover(){
    onmouseOverpopup=1;
}

function setmouseout(){
    onmouseOverpopup=0;
}

function startTimerslide()
{
    setIntervalId =setInterval("newcontact()",30000);
} 

//============= end popup slide ===========================
// getsizePage
/*
var w = 0;
var h = 0;
function getsize(){
    //IE
    if(!window.innerWidth)
    {
	    //strict mode
	    if(!(document.documentElement.clientWidth == 0))
	    {
		    w = document.documentElement.clientWidth;
		    h = document.documentElement.clientHeight;
	    }
	    //quirks mode
	    else
	    {
		    w = document.body.clientWidth;
		    h = document.body.clientHeight;
	    }
    }
    //w3c
    else
    {
	    w = window.innerWidth;
	    h = window.innerHeight;
    }
}
	
function setdiv(){
    getsize();
	var divx=document.getElementById(frmshow);
	if(!window.innerWidth){
	    divx.style.left=w-305+"px";
	}else{
	    divx.style.left=w-323+"px";
	}
}*/