/////////////////////////////////////////////////////////////////////////////////////
// PC Dependencies
/////////////////////////////////////////////////////////////////////////////////////

function openPlayerWM(url, streamType,timeIndx)
{
//      Arguments:
//          url         - URL to be sent to player
//          streamType  - video type (MP1, MP2...)
//          timeIndx    - where to start playing asset
//
//  Called from:
//      PC Live
//      PC Stored
//
//      1. opens the player
//      2. ? Does something with the record button 
//      3. Sets cc on linux 
    try
    {
		// using preview window
		if (!extPlayer || extPlayer.closed || "Thumbnail" == streamType)
		{	
			if(timeIndx==null)
			{
			    qtplayer.Play(url,streamType);
			}
			else
			{
				if(timeIndx>0)
					qtplayer.Play2(url,streamType,timeIndx);
				else
					qtplayer.Play(url,streamType);
			}
	    }
		// reopen external player
		else
		{
			externalPlayWM();	// reset seek time due to restart a new stream
			extPlayer.focus();
		}
    }
	catch (error)
    {
		LogPlayerStop();
    
		alert("The Program  is Currently Not Available or Not Accessible.");
	}
		
}


///////////////////////////////////////////////////////////
//New Methods to support Player Control Separation - Start
//

//Used by SetXxxxPlayerButtons
var PlayerButtons_enumNonWindows=
{
	PLAY_BUTTON:1,
	PAUSE_BUTTON:2,
	STOP_BUTTON:4,
	REWIND_BUTTON:8,
	FORWARD_BUTTON:16,
	FULL_BUTTON:32,
	REC_BUTTON:64,
	CLOSE_BUTTON:128,
	ALL_BUTTONS_USABLE:255
}

//var PlayerButtons_enumWindows=
//{
//	PLAY_BUTTON:1,
//	PAUSE_BUTTON:2,
//	STOP_BUTTON:4,
//	REWIND_BUTTON:8,
//	FORWARD_BUTTON:16,
//	FULL_BUTTON:32,
//	REC_BUTTON:64,
//	ALL_BUTTONS_USABLE:127
//}

function SetPlayerButtons(szRec)
{
//  Arguments:
//      szRec   - action value of recording state, blank when no record perm
//
//  Called from:
//      PC Live
//      PC Stored
//      Linx Live
//      Linx Stored
//      Mac Live
//      Mac Stored
//
	var canRecord = false;
	if (szRec != null && szRec != "")
		canRecord = true;
		
	if (viewer == "linux") {
		SetLinuxPlayerButtons(canRecord);
	} else if (viewer == "MAC") {
		SetMACPlayerButtons(canRecord);
	}
}

function SetLinuxPlayerButtons(canRecord)
{
//  Arguments:
//      canRecord   - bool indicating whether user has record permission
//
//  Called from:
//      Linx Live
//      Linx Stored
//
	var i=PlayerButtons_enumNonWindows.FULL_BUTTON;
	if (ThisPage==enumPage.VideoLibrary) {
		i+=PlayerButtons_enumNonWindows.REC_BUTTON;
	} else {
		if (!canRecord) {
			i+=PlayerButtons_enumNonWindows.REC_BUTTON;
		}
	}
	if (!parent.IsExtPlyr)
		i+=PlayerButtons_enumNonWindows.CLOSE_BUTTON;
		
	qtplayer.document.getElementById("oVBPlayer").HideButtons(i); 
}

function SetMACPlayerButtons(canRecord)
{
//  Arguments:
//      canRecord   - bool indicating whether user has record permission
//
//  Called from:
//      Mac Live
//      Mac Stored
//
	var i=PlayerButtons_enumNonWindows.CLOSE_BUTTON;
	if (ThisPage==enumPage.VideoLibrary) {
		i+=PlayerButtons_enumNonWindows.REC_BUTTON;
	} else {
		if (!canRecord) {
			i+=PlayerButtons_enumNonWindows.REC_BUTTON;
		}
		i+=PlayerButtons_enumNonWindows.FORWARD_BUTTON;
		i+=PlayerButtons_enumNonWindows.REWIND_BUTTON;
	}
	
	if (qtplayer.document.getElementById("oVBPlayer") != null)
		qtplayer.document.getElementById("oVBPlayer").HideButtons(i);
}

function setupPlayerLinux(szURL, szType, szRec)
{
	display_cc_btn(true);
	if(qtplayer.location.href.indexOf("qtplayer.aspx")==-1)
	{
		qtplayer.location.href="qtplayer.aspx";
	}
	window.setTimeout('MCastMPEGSetup("'+szURL+'","'+szRec+'","'+szType+'")',500);

	if(document.getElementById("ExternalPlayer"))
		document.getElementById("ExternalPlayer").style.visibility = "visible";
}

function setupPlayer(szURL, szType, szRec)
{
	if(szType=="WM")
	{
		if (Browser==enumBrowser.FireFox)
			display_cc_btn(false);
		else
			display_cc_btn(true);
		if(qtplayer.location.href.indexOf("wmplayer.aspx")==-1)
		{
			qtplayer.location.href="wmplayer.aspx";

		    window.setTimeout('openPlayerWM("'+szURL+'","'+streamType+'")',500);
		}
		else
		{
			openPlayerWM(szURL,streamType);
		}
	
		if(szRec=="Stop")
		{ 
		    //szRec=="Stop" means recording is inprogress
			if(extPlayer)
			{
				window.setTimeout('extPlayer.SetButtonPressed(3,true)',1000);
			}
			else
			{
				window.setTimeout('qtplayer.SetButtonPressed(3,true)',500); //turn record button red, ie been pressed
			}
		}
	}
	else
	{
		display_cc_btn(true);
		if(qtplayer.location.href.indexOf("qtplayer.aspx")==-1)
		{
			qtplayer.location.href="qtplayer.aspx";
		}
		window.setTimeout('MCastMPEGSetup("'+szURL+'","'+szRec+'","'+szType+'")',500);
	}
	if(document.getElementById("ExternalPlayer"))
		document.getElementById("ExternalPlayer").style.visibility = "visible";
}


function resetCC(url)
{

//  Called from:
//      PC Live
//      Linx Live
//      Mac Live

  var szURL = url;
  
  if ("MSIE" == viewer)
  {
		var cb=document.getElementById('oChkCCOn')
		if(cb)
		{
			if (cb.checked)
				url = url.replace("&cc=off", "&cc=on_ovl");
			else
				url = url.replace("&cc=on_ovl", "&cc=off");
        }
  }
  return szURL;
}    

function record()
{	
if(!isFullScreen && numStreams == 0)
	return;
	
	var obj;
	var url = window.location.href;
	if (url.indexOf("FullScreen.aspx") == -1)
		obj = ("MAC"==viewer)?postBack:document.getElementById("postBack").contentWindow;
	else
		obj = self;
	
	var szRec = getRecordState("Action", obj.document.getElementById("recState").value);
	var bRecord = true;
	
	// confirm to stop record
	if ("Stop" == szRec)
	{
		if(viewer=="linux" || viewer=="MAC"){
			if(extPlayer){
				if (extPlayer.qtplayer.document.getElementById('oVBPlayer') != null)
					extPlayer.qtplayer.document.getElementById('oVBPlayer').RecButtonUsable=2;
			}else{
				if (qtplayer.document.getElementById('oVBPlayer') != null)
					qtplayer.document.getElementById('oVBPlayer').RecButtonUsable=2;
			}
		}
		var msg = getRecordState("Message", obj.document.getElementById("recState").value);
		msg += "\nDo you want to stop this recording?";
		bRecord = confirm(msg);
		if((viewer=="linux" || viewer=="MAC") && bRecord){
			if (qtplayer.document.getElementById('oVBPlayer')!= null)
				qtplayer.document.getElementById('oVBPlayer').RecButtonUsable=1;	//set to recording state
		}
	}
	
	// start/stop record
	if (bRecord)
	{
		obj.document.getElementById("postAction").value = "Record";
		if(obj.document.getElementById("volumeLevel2")){
			obj.document.getElementById("volumeLevel2").value=sound_GetMainVolume();
			obj.document.getElementById("isMute2").value=obj.document.getElementById("isMute").value;
		}
   		if(viewer=="linux" || viewer=="MAC"){
			if(extPlayer){
			    turnOffRecordButtonMAC();
		    }
	    }
		obj.document.getElementById("oForm").submit();
    }
	return bRecord;
}


//
//New Methods to support Player Control Separation - End
///////////////////////////////////////////////////////////
