﻿// JScript File
var player = null;
var streamIndexFormat = new Array(3);
var phoneText;
//Phone numbers are set from the server using this method
function setPhoneText(text)
{
    phoneText = text;
}
function setStreamIndexFormat(arrayIndex,streamIndex,streamFormat,streamURL)
{
    streamIndexFormat[arrayIndex] = new Array(3);
    streamIndexFormat[arrayIndex][0] = streamIndex;
    streamIndexFormat[arrayIndex][1] = streamFormat;
    streamIndexFormat[arrayIndex][2] = streamURL;
}
function getStreamIndex(streamID)
{
    if(streamID != '0000') //Expired
    {
        for (i=0;i<streamIndexFormat.length;i++)
        {
            if (streamIndexFormat[i][0] == streamID)
            {
                return streamIndexFormat[i][1];
            }
        }
    }
    return "0";
}
function getStreamURL(streamID)
{
    if(streamID != '0000') //Expired
    {
        for (i=0;i<streamIndexFormat.length;i++)
        {
            if (streamIndexFormat[i][0] == streamID)
            {
                return streamIndexFormat[i][2];
            }
        }
    }
    return "";
}
function querystring(name)   // returns a named value from the querystring
{
   var tmp = ( location.search.substring(1) );
   var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

   if ( i >= 0 )
   {
      tmp = tmp.substring( name.length+i+1 );
      i = tmp.indexOf("&");
      return unescape( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
   }

   return("");
}

function setAllIndexesInvisible()
{
    for (i=0;i<streamIndexFormat.length;i++)
    {
        if(streamIndexFormat[i])
        {
            var indxObject = document.getElementById(streamIndexFormat[i][0]);
            if(indxObject)
            {
                indxObject.style.visibility = "hidden";
                indxObject.style.display = "none";
            }
        }
    }
}

function drawPlayer(streamID)
{
    var divInnerHTML;
    var streamID = streamID;
    
    if(streamID == 'WM')
    {
        playerCode = "WM";
    }
    else
    {
        playerCode = "REAL";
    }
        
    setAllIndexesInvisible();
    var indxObject = document.getElementById(streamID);
    if(indxObject)
    {
        indxObject.style.visibility = "visible";
        indxObject.style.display = "inline";
    }

    var streamFormat = getStreamIndex(streamID);
    if(player)
    {
        player.stop();
        player = null;
    }
    player = new Player(streamFormat,getStreamURL(streamID));
    player.draw();
    var audioPlayerDiv=document.getElementById("audioPlayer_Player");
    if(audioPlayerDiv)
        disableSelection(audioPlayerDiv);
}

function disableSelection(target)
{
    if (typeof target.onselectstart!="undefined") //IE route
	    target.onselectstart=function(){return false}
    else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	    target.style.MozUserSelect="none"
    else //All other route (ie: Opera)
	    target.onmousedown=function(){return false}
    target.style.cursor = "default"
}