/// <reference path="LanxerLibrary.js" />
/// <reference path="Global_Page.js" />
/// <reference path="Global_AJAX.js" />
/// <reference path="Global.js" />
var f_RingRing_ConferencesDemandingAttention = new Array();

function f_PingIsOnline()
{
    aj_c('PingIsOnline=t',f_PingIsOnline_Callback);
}

function f_PingIsOnline_Callback()
{
    
}

function f_GetLoggedInUserLiteralID()
{
    if(!g('__CURENTUSER'))
        return -1;
    
    return g('__CURENTUSER').value;
}

function f_OpenOrCreateConference(userLiteralID)
{
    var conID = aj_con('NewOrOpenConference=t&ConferenceTo=' + userLiteralID);
    f_OpenConferenceUI(conID);
}

var openConferences = new Array();

function f_OpenConferenceUI(conID)
{
    var args = 'location=0,status=0,scrollbars=0,width=720,height=460,resizable=yes';
    
    if(openConferences[conID] && !openConferences[conID] .closed)
    {
        openConferences[conID].focus();
    }
    else
    {
        var ncw = window.open('/extrn/ConferenceBridge.aspx?conferenceID=' + conID, 'ConUI' + conID, args ,true); 
        ncw.focus();
        openConferences[conID] = ncw;
    }    
    
    GLOBAL_array_removeByVal(conID, f_RingRing_ConferencesDemandingAttention);
    
    if(f_RingRing_ConferencesDemandingAttention.length == 0)
    {
    
        if(f_RingRing_ShowDialog_Interval)
        {
            window.clearInterval(f_RingRing_ShowDialog_Interval);
            var stbl = g('ShellChatEye');
            stbl.style.backgroundColor = '#e3e3e3';
            
            g('con_openConferenceID' + conID).style.backgroundColor = '#e3e3e3';
        }
    }
    // remove from array // if array length is zero then stop all the blinking
}


var f_RingRing_ShowDialog_Interval = false;

function f_RingRing_ShowDialog(conferenceID)
{
  // ShowDialogBox("DB_NewConferenceRequest");
   
   // REFRESH CONFERENCE DATA
   try
   {
        g('Shell_OpenConversations').innerHTML = aj_con('getOpenConferences=' + conferenceID);
        
        f_RingRing_ConferencesDemandingAttention.push(conferenceID);

        // alert(g('con_openConferenceID' + conferenceID).innerHTML);
        // g('DB_NewConferenceRequest_Contents').innerHTML = aj_con('getNewConferenceRequestDB=' + conferenceID)
        // MAKE TOP BLINK AND MAKE CONFERENCE BLINK
        
        f_RingRing_ShowDialog_Interval = window.setInterval("f_RingRing_MakeBlink()" , 250);
   }
   catch(ex)
   {
        alert(ex);
   }
}

var f_RingRing_MakeBlink_State = false;
function f_RingRing_MakeBlink()
{
    var stbl = g('ShellChatEye');

    if(f_RingRing_MakeBlink_State)
        stbl.style.backgroundColor = '#c9eced';
    else
        stbl.style.backgroundColor = '#e3e3e3';
        
    for(var i = 0; i < f_RingRing_ConferencesDemandingAttention.length; i++)
    {
        stbl = g('con_openConferenceID' + f_RingRing_ConferencesDemandingAttention[i]);
        
        if(f_RingRing_MakeBlink_State)
            stbl.style.backgroundColor = '#c9eced';
        else
            stbl.style.backgroundColor = '#e3e3e3';
    }
            
    f_RingRing_MakeBlink_State = !f_RingRing_MakeBlink_State;
}

var reqCound = 0;
function f_NewConferenceAccept(userLiteralID, conferenceID)
{
    ChangePage('Conference_View&d=' + conferenceID);
    //window.open("extrn/ConferenceBridge.aspx?conferenceID=" + conferenceID, "_blank" , "resizable=yes,fullscreen=yes,status=yes,toolbar=no,menubar=no,location=no");
    SkillsTM_Alerter.MakeRequest_NotifyUserThatConferenceWasAccepted(userLiteralID, conferenceID);
}

function f_TheyHaveAcceptedYourConference(conferenceID)
{
    ChangePage('Conference_View&d=' + conferenceID);
    // window.open("extrn/ConferenceBridge.aspx?conferenceID=" + conferenceID, "_blank" , "resizable=yes,fullscreen=yes,status=yes,toolbar=yes,menubar=yes,location=no");
}

function f_NewConferenceReject()
{
    // INVOKE METHOD THAT SENDS MESSAGE BACK TO REQUESTING CLIENT SAYING THAT THE PERSON HAS DENYED THEM
}

function f_ConferenceIDGet()
{
    return g('ConferenceID').value;
}

function f_IsAdminGet()
{
    return g('IsAdmin').value;
}

function f_participantsGet()
{
    return g('Participants').value;
}

function getUserID()
{
    return g('__CURENTUSER').value; 
}

function getScreencastBridgePath()
{
    return g('__SERVERBASEPATH').value + "extrn/ScreencastBridge.aspx";
}

function ParticipantGetName(participantID)
{
    return document.getElementById('Participant' + participantID).innerHTML;
}

function startScreenCap()
{
    document.getElementById("JAPLET").StartScreenCapture();
}

function stopScreenCap()
{
    document.getElementById("JAPLET").StopScreenCapture();
}

function TurnOnWebOrbServer()
{
    document.getElementById("LOADWEBORB").src = IsLocal() ? "http://lanxer/weborb30/" : "http://skillstm.com/weborb30/";
}

function c_ShowOpenConversations()
{
	var oc = g('Shell_OpenConversations');
	oc.style.display = 'block';
	var eyeLeftPos = calcLeftPosition(g('ShellChatTable'));
	oc.style.left = eyeLeftPos;
	document.onmousemove = c_ShowOpenConversationsMM;
	g('ShellChatEye').style.backgroundColor = '#E3E3E3';
	
	HideZIndexHaters();
}

function c_ShowOpenConversationsMM(e)
{
	if(!c_ShowOpenConversationsMM_Class('Shell_OpenConversationsFLAG' , e))
		c_HideOpenConversations()
}

function c_ShowOpenConversationsMM_Class(name , e)
{   
	var startElement = e ? e.target : event.srcElement;
	
	while(true)
	{
		if(startElement && startElement.className && startElement.className.indexOf(name) != -1)
			return true;
		
		if(startElement.parentNode)
			startElement = startElement.parentNode;
		else
			return false;
	}
	
	return true;
}

function c_HideOpenConversations()
{
	g('Shell_OpenConversations').style.display = 'none';
	document.onmousemove = getMousePos;
	g('ShellChatEye').style.backgroundColor = '#ffffff';
	
	ShowZIndexHaters();
}

function c_GetValue(idName)
{
    return g(idName).value;
}

function thisMovie(movieName) 
{                 
    if (navigator.appName.indexOf("Microsoft") != -1) 
    {                         
        return window[movieName];                 
    } 
    else 
    {                 
        return document[movieName];
    }        
}

var ncw;
function wcr_OpenWebCamRecordWindow(usid)
{
    if(ncw)
        ncw.close();
        
    ncw = window.open('/extrn/WebCamRec.aspx?usid=' + usid ,'_blank', 'resizable=0,fullscreen=0,status=0,toolbar=0,menubar=0,location=0,width=346,height=400' ,false); 
    ncw.focus();
}

function wcr_OpenWebCamRecordWindow_ForWorkOrder(workOrderID, usid)
{
    if(ncw)
        ncw.close();
    
    ncw = window.open('/extrn/WebCamRec.aspx?workOrder=' + workOrderID + '&usid=' + usid, '_blank', 'resizable=0,fullscreen=0,status=0,toolbar=0,menubar=0,location=0,width=346,height=400' ,false); 
    ncw.focus();
}

function wcr_DoneRecording(movieID)
{
    // aj_wcr('saveProfileWebCamVideo=' + movieID);
    ChangePage(p_Profile_WebCamVideoManage,true, true);
    ncw.close();
}

function wcr_DoneRecording_FromWorkOrder(movieID, workOrder)
{
    // aj_wcr('saveWorkOrderWebCamVideo=' + movieID + '&workOrder=' + workOrder);
    ChangePage(p_Oppertunity_ApplyOnline + '&d=' + workOrder, true, true);
    ncw.close();
}

function vrdp_LaunchDesktop(cmd)
{
    var launch = 
        '<APPLET style=visibility:hidden codebase=/Graphics/java/RDPLauncher MAYSCRIPT code=com.arachnobase.RDPLauncher.RDPLauncher archive=RDPLauncher.jar width=600 height=150>' + 
        '<param name=tp value="' + cmd + '" />' + 
        '</APPLET>';
        
        
    var body = document.getElementsByTagName("body")[0];
    var d = document.createElement('div');
    d.innerHTML = launch;
    body.appendChild(d);
}