﻿var vpFrame = null;
var blPhoneReady = false;

function InitVideoPhone()
{
    //alert("Begin InitVideoPhone()");
    vpFrame = d('main_vpFrame');
    vpFrame.src = '/vp/VideoPhone.aspx';
    setTimeout("RegisterVPFrame();", 3000);           
}

function EndVideo(strMessage)
{
    if(GetBrowserInfo() == "IE") //IE
    {
        ShowVideo(false);
    }
    else                        //FF
    {
        d('main_divVideo').style.visibility = 'hidden';
    }
    
    InitVideoPhone();
    
    alert(strMessage);
}

function LaunchVideo(fromUserGuid, toUserGuid, fromUserNick, toUserNick, sessionID)
{
    //check that this click was not on the user's own name in the list
    if(fromUserGuid == toUserGuid)
    return;
    
    //check logged in state
    if(!getCookieValue('AppUsername'))
    {        
        SH_LR('main_login', false);
        return;
    }
    
    //Initializing, please wait.   
    if(!blPhoneReady)
    {
        alert("Initializing...please try again!");
        return;
    }
    
    vpFrame = d('main_vpFrame');  

    if(GetBrowserInfo() == "IE") //IE
    {
        ShowVideo(true);
    }
    else
    {
        d('main_divVideo').style.visibility = 'visible';
    }

    if(self.vpFrame) 
    {
        self.vpFrame.contentWindow.MakeCallRequest(toUserGuid, toUserNick);            
    }
    else                       
    {        
        window.frames.vpFrame.contentWindow.MakeCallRequest(toUserGuid, toUserNick);        
    }        
}

function ShowVideo(blShow)
{        
    if(blShow)
    {
        d("main_divVideo").style.top = "40px";
        d("main_divVideo").style.left = "550px";
        d("main_divVideo").style.width = "385px";
        d("main_divVideo").style.height = "485px";
    }
    else
    {
        d("main_divVideo").style.top = "0px";
        d("main_divVideo").style.left = "0px";
        d("main_divVideo").style.width = "1px";
        d("main_divVideo").style.height = "1px";    
    }
}

function GetBrowserInfo()
{
    //Detecting FireFox 1.0+
    if(navigator.userAgent.indexOf("Firefox")!=-1)
    {
        var versionindex=navigator.userAgent.indexOf("Firefox")+8;
        if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
            return 'FF';
    }

    //Detect IE5.5+
    var version=0;
    if (navigator.appVersion.indexOf("MSIE")!=-1)
    {   
        return 'IE';
    }
                  
    return 'OTHER';
}

function RegisterVPFrame()
{    
    try
    {        
        clearTimeout(watchMsgStackTO);
        vpFrame = d('main_vpFrame');        
        if(self.vpFrame) 
        {
            hostAppMsgStack = self.vpFrame.contentWindow.MSGSTACK;
            hostAppMsgStack2 = self.vpFrame.contentWindow.TweeboSTACK;   
            
            self.vpFrame.contentWindow.srcUserGUID = guid;    
            self.vpFrame.contentWindow.srcUserNick = nick;
            self.vpFrame.contentWindow.skrblSessionID = ga_sessionID;  
            self.vpFrame.contentWindow.Init();   
        }
        else 
        {
            hostAppMsgStack = window.frames.vpFrame.contentWindow.MSGSTACK;
            hostAppMsgStack2 = window.frames.vpFrame.contentWindow.TweeboSTACK;  
            
            window.frames.vpFrame.contentWindow.srcUserGUID = guid;    
            window.frames.vpFrame.contentWindow.srcUserNick = nick; 
            window.frames.vpFrame.contentWindow.skrblSessionID = ga_sessionID;  
            window.frames.vpFrame.contentWindow.Init();     
        }
        watchMsgStackTO = setTimeout("watchMsgStack();", 500);
        blPhoneReady = true;
    }
    catch(e){}
}





