var fullScreenMessage = "To enter full-screen mode using your browser:\n\n1.  Start the video\n2.  Right-click the Windows Media Player with your mouse\n3.  Select 'Zoom'\n4.  Select 'Full Screen'\n\nNOTE:  If the captions still do not appear, you must first configure your Windows Media Player.  Please consult the FAQs page for instructions. \n\nNOTE: Windows Media Player in full-screen mode is not available for Mac users.";
var MEDIA_RELEASES_WM_LOW_BIT_RATE = "1";
var MEDIA_RELEASES_WM_HIGH_BIT_RATE = "2";
var MEDIA_RELEASES_QT_LOW_BIT_RATE = "3";
var MEDIA_RELEASES_QT_HIGH_BIT_RATE = "4";
var MEDIA_RELEASES_WM_600K_BIT_RATE = "5";
var MEDIA_RELEASES_FL_HIGH_BIT_RATE = "11";
var MEDIA_RELEASES_FL_LOW_BIT_RATE = "10";
var MEDIA_RELEASES_FL_1500_BIT_RATE = "12";

var _contentType, _contentID;
var _playBit, _accessMethod;
var _flashXmlCC, _flashMediaFile400, _flashMediaFile700, _flashMediaFile1500, _flashAutoPlay;

function RedirectStdPage(exttitleid , ctype)
{			
	var strURL = '';
	
	if ( ctype == "T" )
		strURL = '/StandardsByTitle.aspx?TitleId=' + exttitleid + "&ctype=" + ctype;
	else
		strURL = '/StandardsByTitle.aspx?LOId=' + exttitleid + "&ctype=" + ctype;
	
	window.open(strURL, 'newwin', 'resizable=no,scrollbars=yes,titlebar=no,toolbar=no,status=yes,screenX='+ (screen.availWidth - 600)/2 + ',screenY='+ (screen.availHeight - 600)/2 +',top='+ (screen.availHeight - 300)/2  +',left='+ (screen.availWidth - 600)/2 +',width=600,height=600');	
	
	return true;
}

function RedirectRelatedResources(titleid)
{
	var strURL = '/RelatedResources.aspx?TitleId=' + titleid;
	window.open(strURL, 'newwin', 'resizable=no,scrollbars=yes,titlebar=no,toolbar=no,status=yes,screenX='+ (screen.availWidth - 800)/2 + ',screenY='+ (screen.availHeight - 800)/2 +',top='+ (screen.availHeight - 800)/2  +',left='+ (screen.availWidth - 800)/2 +',width=520,height=400');	
	
	return true;
}

function RedirectStandards(portalTitleId)
{
    var strURL = '/DigitalStandards.aspx?TitleId=' + portalTitleId + '&ctype=T';
	window.open(strURL, 'newwin', 'resizable=no,scrollbars=yes,titlebar=no,toolbar=no,status=yes,screenX='+ (screen.availWidth - 800)/2 + ',screenY='+ (screen.availHeight - 800)/2 +',top='+ (screen.availHeight - 800)/2  +',left='+ (screen.availWidth - 800)/2 +',width=950,height=400');	
	
	return true;
}

function CreateRedirectRelatedResources(titleid, imgurl) {
try{
var RelatedResourcesLocation = document.getElementById('relatedResrc');	
var mediaHTML = '';
if (titleid != "0")
{

mediaHTML += '<img src="' + imgurl + '" id="relatedResourcesImg" alt="Related Resources"  Style="vertical-align: bottom">'
mediaHTML += '<A class="infotitlename"   href="#" onclick="javascript:RedirectRelatedResources('+ titleid + ');">Related Resources</A>';

	//var strURL = '/RelatedResources.aspx?TitleId=' + titleid;
	//window.open(strURL, 'newwin', 'resizable=no,scrollbars=yes,titlebar=no,toolbar=no,status=yes,screenX='+ (screen.availWidth - 800)/2 + ',screenY='+ (screen.availHeight - 800)/2 +',top='+ (screen.availHeight - 800)/2  +',left='+ (screen.availWidth - 800)/2 +',width=520,height=400');	
}	
RelatedResourcesLocation.innerHTML = mediaHTML;		
} catch (err) { }	
}
function RedirectViewCitations(titleid, title, CopyRightYr, SiteType, fileType, titleURL, DateMLA, DateCMS) {
try{
	var selMediaType = document.getElementById(masterPageInputPrefix + 'ddlPlayer');
	var mediaType = selMediaType.options[selMediaType.selectedIndex].value;
	
    var strURL = '/ViewCitations.aspx?TitleId='+ titleid + "&title=" + title +"&CopyRightYr=" + CopyRightYr + "&SiteType=" + SiteType + "&fileType=" + mediaType + "&titleURL=" + titleURL + "&DateMLA=" + DateMLA + "&DateCMS=" + DateCMS;
	
    var newWindow = window.open(strURL, 'newwin', 'resizable=no,scrollbars=yes,titlebar=no,toolbar=no,status=yes,screenX='+ (screen.availWidth - 800)/2 + ',screenY='+ (screen.availHeight - 800)/2 +',top='+ (screen.availHeight - 800)/2  +',left='+ (screen.availWidth - 800)/2 +',width=520,height=400');	
    newWindow.focus();
    return true;
} catch (err) { }	
}
function CreateRedirectViewCitations(titleid, title, CopyRightYr, SiteType, fileType, titleURL, DateMLA, DateCMS, imgurl)
{
try{
var CitationLocation = document.getElementById('viewCitations');	
var mediaHTML = '';
title = "'" + title + "'";
CopyRightYr = "'" + CopyRightYr + "'";
SiteType = "'" + SiteType + "'";
fileType = "'" + fileType + "'";
titleURL = "'" + titleURL + "'";
DateMLA = "'" + DateMLA + "'";
DateCMS = "'" + DateCMS + "'";
mediaHTML += '<img src="' + imgurl + '" id="citationImg" alt="Citations" Style="vertical-align: bottom">'
mediaHTML += '<A class="infotitlename"   href="#" onclick="javascript:RedirectViewCitations('+ titleid + ',' + title +','+ CopyRightYr + ',' + SiteType + ',' + fileType + ',' + titleURL + ',' + DateMLA + ',' + DateCMS + ');">Citations</A>';
CitationLocation.innerHTML = mediaHTML;
} catch (err) { }	
								
}

//check if all films in playlist include flash format
function CheckPlaylistFlashSupport(playflash)
{
    var allPlaylistHasFlash400 = document.getElementById(masterPageInputPrefix + 'hdnAllPlaylistHasFlash400');
    var allPlaylistHasFlash700 = document.getElementById(masterPageInputPrefix + 'hdnAllPlaylistHasFlash700');
    // alert("playflash: " + playflash + "  allPlaylistHasFlash400:"  + allPlaylistHasFlash400.value + "  allPlaylistHasFlash700:" + allPlaylistHasFlash700.value );
    if (((playflash == "400") && (allPlaylistHasFlash400.value == "false")) || ((playflash == "700") && (allPlaylistHasFlash700.value  == "false")))
    {
        //display notification
        var lblMessage = document.getElementById(masterPageInputPrefix + 'lblMessage');
        lblMessage.innerHTML = 'Some of the segments in your playlist do not currently have Flash available. Please select a different format if you would like all your segments to play together. We apologize for the inconvenience.<br>';
    }
}	
/* 
This function will clear out the bitrate dropdown ddlBitrate.
Then, based on the currently selected media format (WM or QT), this will replace ddlBitrate with 
either bitrates from the windows media hidden bitrate dropdown,
or the quicktime hidden bitrate dropdown.
*/
function LoadBitRate()
{
	var selBitRate = document.getElementById(masterPageInputPrefix + 'ddlBitrate');
	var hMediaBitRate = null;
	var contentBR = "";
	var mBitRate = "";
	
	selBitRate.options.length = 0;
		
	if (GetMediaType() == "WM")
	{		
	    //windows media, get bitrates from hidden wm dropdown
		hMediaBitRate = document.getElementById(masterPageInputPrefix + 'hdnWMBitRates');
		mBitRate = hMediaBitRate.value;
		
	    //while we're here, toggle the full screen options
		if (IsOperatingSystemMac())
		{ 
			document.getElementById(masterPageInputPrefix + "tdFullScreen").style.display = 'none';
		}
		else
		{
			document.getElementById(masterPageInputPrefix + "tdFullScreen").style.display = '';	
		}
		if (document.getElementById(masterPageInputPrefix + "lblCC") != null)
		{
		    document.getElementById(masterPageInputPrefix + "lblCC").style.display = '';
		}

	}
	
	else if(GetMediaType() == "FL") 
	{
	    //flash, get bitrates from hidden qt dropdown
		hMediaBitRate = document.getElementById(masterPageInputPrefix + 'hdnFLBitRates');
		mBitRate = hMediaBitRate.value;
		
		//while we're here, turn OFF the full screen option, since QT doesn't support it.
		document.getElementById(masterPageInputPrefix + "tdFullScreen").style.display = 'none';
		if (document.getElementById(masterPageInputPrefix + "lblCC") != null)
		{
		    document.getElementById(masterPageInputPrefix + "lblCC").style.display = 'none';
		}
		
	}
	
	else
	{
	    //quicktime, get bitrates from hidden qt dropdown
		hMediaBitRate = document.getElementById(masterPageInputPrefix + 'hdnQTBitRates');
		mBitRate = hMediaBitRate.value;
		
		//while we're here, turn OFF the full screen option, since QT doesn't support it.
		document.getElementById(masterPageInputPrefix + "tdFullScreen").style.display = 'none';
		if (document.getElementById(masterPageInputPrefix + "lblCC") != null)
		{
		    document.getElementById(masterPageInputPrefix + "lblCC").style.display = '';
		}
	}
	
	//copy whatever bitrates we found over to the ddlBitrate dropdown
	if (mBitRate.indexOf(',') == -1)
	{
		contentBR = mBitRate.split('-');
		selBitRate.options[selBitRate.options.length] = new Option(contentBR[1], contentBR[0]);
	}
	else
	{				
		var mItem = mBitRate.split(',');
		for (var i = 0; i < mItem.length; i++)
		{
			contentBR = mItem[i].split('-');
			selBitRate.options[selBitRate.options.length] = new Option(contentBR[1],contentBR[0]);
		}
	}
	//reset the dropdown to select the first bitrate
	selBitRate.selectedIndex = 0;	
}

//play movie from the dropdown selection (lblPlayer)
function PlayMovieSelect()
{
    PlayMovie(_contentType, _contentID, _playBit, _accessMethod, _flashXmlCC, _flashMediaFile400, _flashMediaFile700, _flashMediaFile1500, 'true');
}
			
function PlayMovie(contentType, contentID, playBit, accessMethod, flashXmlCC, flashMediaFile400, flashMediaFile700, flashMediaFile1500, autoplayflash)
{
    //alert("PlayMovie! , contentType: " + contentType + " , contentID: " + contentID + " , accessMethod: " + accessMethod + " , cc: " + flashXmlCC +" , flashMediaFile400: " + flashMediaFile400 + " , flashMediaFile700: " + flashMediaFile700);
    
    //set the globals for the PlayMovieSelect (lblPlayer)
    _contentType = contentType;
    _contentID = contentID;
    _playBit =  playBit;
    _accessMethod = accessMethod;
    _flashXmlCC = flashXmlCC;
    _flashMediaFile400 = flashMediaFile400;
    _flashMediaFile700 = flashMediaFile700;
    _flashMediaFile1500 = flashMediaFile1500;
    _flashAutoPlay = autoplayflash;
    
    // Change message on Share tab based on whether the user selected a segment or a full title.
    SetShareTabMessage(contentType);
    // Set segment (learning object) ID if one is playing.
    SetSegmentId(contentType, contentID);
    
    //store the passed params for use with closed captioning restarts
    $(masterPageInputPrefix + 'hdnContentType').value = contentType;
    $(masterPageInputPrefix + 'hdnContentID').value = contentID;
    $(masterPageInputPrefix + 'hdnAccessMethod').value = accessMethod;
    
    //get the rest of the info					
	var selBitRate = document.getElementById(masterPageInputPrefix + 'ddlBitrate');
	var selMediaType = document.getElementById(masterPageInputPrefix + 'ddlPlayer');
	var mediaType = selMediaType.options[selMediaType.selectedIndex].value;
	
	if (selBitRate.options.length == 0)
	{
		return;	
	}
	else
	{
		playBit = selBitRate.value;
	}
	    
    var mediaUrl = "";

	if (accessMethod.indexOf("Playlist") > -1)
	{
	    //Single Playlist clicks, or the PlayAll button, 
	    //will have an AccessMethod starting with "Playlist"							
	    mediaUrl = getReleaseUrlFromPlaylist(contentID);
	}
	else
	{
	    //Playing the whole video
	    mediaUrl = getReleaseUrlFromViewVideo(contentType, contentID);
	}
			
	var strMediaURL = GetMediaURL(mediaType, playBit, mediaUrl, contentID, accessMethod, contentType);
	
	if ((strMediaURL.length > 2057) && ((mediaType == "WM") || (mediaType == "QT")))
    {
        return false;
    }
    	        					
	SelectImageButton(contentID, true, masterPageInputPrefix);					    
	StopMediaPlayers();	
	
	//alert("strMediaURL : " + strMediaURL + " , mediaType: " + mediaType + " , playBit: " + playBit + " , mediaUrl: " + mediaUrl + " , contentID: " + contentID);
	BuildPlayerAndPlayVideo(strMediaURL, mediaType, playBit, mediaUrl, contentID, contentType, accessMethod, flashXmlCC, flashMediaFile400, flashMediaFile700, flashMediaFile1500, autoplayflash);
		
	SetLearnObjPlaylist(contentID);
			
	return true;					
}	

function GetMediaURL(mediaType, selectedBitRate, mediaUrl, contentID, accessMethod, contentType)
{
    //for use with statistics
	var referer = $F(masterPageInputPrefix + 'hdnReferer');
	var ip = $F(masterPageInputPrefix + 'hdnIP');
	var operatingSystem = $F(masterPageInputPrefix + 'hdnOS');
	var browser = $F(masterPageInputPrefix + 'hdnBrowser');
	var browserVersion = $F(masterPageInputPrefix + 'hdnBrowserVersion');
	var eID = $F(masterPageInputPrefix + 'hdnEID');
	var cID = $F(masterPageInputPrefix + 'hdnCID');
	var showCC = $F(masterPageInputPrefix + 'hdnClosedCaptioning');	    	
	var lblMessage = document.getElementById(masterPageInputPrefix + 'lblMessage');

    lblMessage.innerHTML = "";	
				 														
	var strMediaURL = "/PlayMedia.aspx?MediaID=" + escape(mediaUrl)
	    + "&AccessMethod=" + accessMethod
		+ "&contentType=" + contentType + "&contentID=" + contentID
		+ "&Format=" + mediaType + "&cc=" + showCC
		+ "&BitRate=" + selectedBitRate + "&IP=" + escape(ip)
		+ "&Referer=" + escape(referer) + "&OS=" + escape(operatingSystem) 
		+ "&Browser=" + escape(browser) + "&BrowserVersion=" + escape(browserVersion)
		+ "&EID=" + escape(eID) + "&CID=" + escape(cID);

	//get the playlist code, if any, and put in our mediaURL for stats recording			
	var playlistKey = '/play/';
    var playlistPos = window.location.href.indexOf(playlistKey);
    if (playlistPos > -1)
    {	       	    
        //check to see if this is a redirected url
        //this solution is currently not in affect, but I'll leave the js in for now.
        //Sometimes, the redirect code messes up the URL.
        //if so, it could end up looking like /play/id=xxx instead of just xxx
        var playlistCode = window.location.href.substring(playlistPos + playlistKey.length);
        var playlistKey2 = 'AssignmentId=';
        var playlistPos2 = playlistCode.indexOf(playlistKey2);
        	        
        if (playlistPos2 > -1)
        {
            //it's /play/id=xxx
            strMediaURL += "&playID=" + escape(playlistCode.substring(playlistPos2 + playlistKey2.length));
        }
        else
        {	        
            //it's just xxx
            strMediaURL += "&playID=" + escape(playlistCode);
        }
    }
    else
    {
        //check to see if this is from PortalViewAssignment with the querystring
        playlistKey = 'AssignmentId=';
        playlistPos = window.location.href.indexOf(playlistKey);
        
        if (playlistPos > -1)
        {
            strMediaURL += "&playID=" + escape(window.location.href.substring(playlistPos + playlistKey.length));
        }
    }
    return strMediaURL;
}

function BuildPlayerAndPlayVideo(strMediaURL, mediaType, playBit, mediaUrl, contentID, contentType, accessMethod, flashXmlCC, flashMediaFile400, flashMediaFile700, flashMediaFile1500, flAutoPL)
{
	var MediaPlayerLocation = document.getElementById('divMedia');	
	var showCC = "";
	var mediaHTML = '';
	
	if ($(masterPageInputPrefix + 'hdnClosedCaptioning') != null)
	    showCC = $F(masterPageInputPrefix + 'hdnClosedCaptioning');
				
	if (mediaType == "WM")
	{			
        mediaHTML +=PlayWindowsMedia(playBit, strMediaURL);
	}
	else if (mediaType == "QT")//quicktime
	{
	    var videoPlayerClass = "videoPlayerQT";
	    var autoplay = "false";
	    if (showCC == "1") videoPlayerClass += "cc";
	    if (playBit == "1") autoplay = "true";
	
		if (IsBrowserIE())
		{					
			mediaHTML += '<OBJECT id="QTPlayer" CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" class="' + videoPlayerClass + '" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" VIEWASTEXT>' ;
			mediaHTML +='<param name="src" value="' + strMediaURL + '">';
			mediaHTML +='<param name="controller" value="1">';
			mediaHTML +='<param name="KIOSKMODE" value="true">';
			mediaHTML +='<param name="enablejavascript" value="true">';
			mediaHTML +='<param name="pluginpage" value="http://www.apple.com/quicktime/download/">';
			mediaHTML +='<param name="autoplay" value="' + autoplay + '">';
			mediaHTML +='<embed id="QTPlayer" src="' + strMediaURL +'" class="' + videoPlayerClass + '" autoplay="' + autoplay + '" KIOSKMODE="true" enablejavascript="true" loop="false" controller="true"  pluginspage="http://www.apple.com/quicktime/"';
			mediaHTML +='>';
			mediaHTML +='</embed>';
			mediaHTML +='</OBJECT>';									
		}
		else if (navigator.mimeTypes)
		{	
			mediaHTML +='<embed id="QTPlayer" type="video/quicktime" src="' + strMediaURL +'" class="' + videoPlayerClass + '" autoplay="' + autoplay + '" KIOSKMODE="true" enablejavascript="true" loop="false" controller="true" pluginspage="http://www.apple.com/quicktime/"';
			mediaHTML +='>';
			mediaHTML +='</embed>';
		}		
	}
	else
	{   
        var ddlBitrate = document.getElementById(masterPageInputPrefix + 'ddlBitrate');
        var prefix = document.getElementById(masterPageInputPrefix + 'hdnFlashPrefixURL').value;
        var playflash = "";
        var flashCC = "";
        var url = "http://test.digital.films.com/";
        var StartTime = 0;
        var EndTime = 0;
        var titleImg = document.getElementById(masterPageInputPrefix + 'titleImg').value;
        
        
        titleImg = 'http://digital.films.com/' + titleImg;
        
        if (flashXmlCC != null)
        {
            if ((flashXmlCC.length > 0) && (flashXmlCC != 'none'))
            {
                flashCC = url + 'FalshCC/' + flashXmlCC ;
            }
        }
        
        if (accessMethod == "PlaylistAll")
        {
			 StartTime = document.getElementById(masterPageInputPrefix + 'hdnFlashPlaylistStartTime').value;
             EndTime = document.getElementById(masterPageInputPrefix + 'hdnFlashPlaylistEndTime').value;
			 
            if (ddlBitrate.value == MEDIA_RELEASES_FL_LOW_BIT_RATE)
            {
                playflash = document.getElementById(masterPageInputPrefix + 'hdnFlashReleasePlaylist400').value;
                CheckPlaylistFlashSupport("400");
            }
            else if (ddlBitrate.value == MEDIA_RELEASES_FL_1500_BIT_RATE)
            {
                playflash = document.getElementById(masterPageInputPrefix + 'hdnFlashReleasePlaylist1500').value;
                CheckPlaylistFlashSupport("1500");
            }
            else
            {
                playflash = document.getElementById(masterPageInputPrefix + 'hdnFlashReleasePlaylist700').value;
                CheckPlaylistFlashSupport("700");
            }
        }
        else
        {  
			if (document.getElementById('Start' + contentID) != null)
			{
			   StartTime = document.getElementById('Start' + contentID).value/100;

				
		
				
			StartTime = Number(StartTime) + Number(document.getElementById(masterPageInputPrefix + 'flashoffset').value);



			}
			if (document.getElementById('End' + contentID) != null)
            {
              

		 EndTime = document.getElementById('End' + contentID).value/100;


		EndTime = Number(EndTime) + Number(document.getElementById(masterPageInputPrefix + 'flashoffset').value);

            }
            
            if (ddlBitrate.value == MEDIA_RELEASES_FL_LOW_BIT_RATE)
            {
                if (flashMediaFile400.length > 0)
                {
                    playflash = prefix + flashMediaFile400;
                }
            }
            else if (ddlBitrate.value == MEDIA_RELEASES_FL_1500_BIT_RATE)
            {
                if (flashMediaFile1500.length > 0)
                {
                    playflash = prefix + flashMediaFile1500;
                }
            }
            else
            {
                if (flashMediaFile700.length > 0)
                {
                    playflash = prefix + flashMediaFile700;
                }
            }
        }
        
        //alert("playflash: " + playflash + "   StartTime: " + StartTime + "    EndTime: " + EndTime + " flashCC:" + flashCC);

        if (playflash.length > 0)
        {
            mediaHTML +='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="361" id="FLVPlayer" class="videoPlayerFL">' ;
		    mediaHTML +='<param name="movie" value="http://test.digital.films.com/SimpleFlashPlayer.swf" />';
		    mediaHTML +='<param name="allowFullScreen" value="true" />';
		    mediaHTML +='<param name="play" value="true" />';

		    mediaHTML +='<param name="FlashVars" value="&MM_ComponentVersion=1&playerSkin=http://test.digital.films.com/SkinUnderPlayStopSeekFullVol.swf&autoPlay=false&autoRewind=true&flvToPlay=' + playflash + '&startTime=' + StartTime +'&stopTime=' + EndTime + '&url=' + url + '&closeCaption=' + flashCC + '&autoP=' + flAutoPL + '&previewimg=' + titleImg + '"/>';
    		
		    mediaHTML +='<embed src="http://test.digital.films.com/SimpleFlashPlayer.swf" flashvars="&MM_ComponentVersion=1&playerSkin=http://test.digital.films.com/SkinUnderPlayStopSeekFullVol.swf&autoPlay=true&autoRewind=true&flvToPlay=' + playflash + '&startTime=' + StartTime + '&stopTime=' + EndTime + '&url=' + url + '&closeCaption=' + flashCC + '&autoP=' + flAutoPL +  '&previewimg=' + titleImg + '" quality="high"  play="true" width="480" height="361" name="FLVPlayer" salign="LT" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="true"/>';
		    mediaHTML +='</OBJECT>';
		    
		    //hide the closed caption and full screen icons for the flash
		    document.getElementById(masterPageInputPrefix + "tdFullScreen").style.display = 'none';
		    if (document.getElementById(masterPageInputPrefix + "lblCC") != null)
		    {
		        document.getElementById(masterPageInputPrefix + "lblCC").style.display = 'none';
		    }
		    
		    //call PlayMedia to AddStatistics
		    new Ajax.Request( strMediaURL, {method: 'post'} )
		}
		else //flash format is not available
		{
		    //play the film by default with WM
		    SetMediaType("WM");
		    var selBitRate = document.getElementById(masterPageInputPrefix + 'ddlBitrate');
		    playBit = selBitRate.value;
		    var strMediaURLWM = GetMediaURL("WM", playBit, mediaUrl, contentID, accessMethod, contentType);
		    mediaHTML +=PlayWindowsMedia(playBit, strMediaURLWM);
		     
		    //display notification
		    var lblMessage = document.getElementById(masterPageInputPrefix + 'lblMessage');
    	    lblMessage.innerHTML = 'This segment does not currently have Flash available, and a different format will be automatically selected for you. We apologize for the inconvenience.<br>';
		}
	}
	MediaPlayerLocation.innerHTML = mediaHTML;												
}

//check if all films in playlist include flash format
function CheckPlaylistFlashSupport(playflash)
{
    var allPlaylistHasFlash400 = document.getElementById(masterPageInputPrefix + 'hdnAllPlaylistHasFlash400');
    var allPlaylistHasFlash700 = document.getElementById(masterPageInputPrefix + 'hdnAllPlaylistHasFlash700');
    // alert("playflash: " + playflash + "  allPlaylistHasFlash400:"  + allPlaylistHasFlash400.value + "  allPlaylistHasFlash700:" + allPlaylistHasFlash700.value );
    if (((playflash == "400") && (allPlaylistHasFlash400.value == "false")) || ((playflash == "700") && (allPlaylistHasFlash700.value  == "false")))
    {
        //display notification
        var lblMessage = document.getElementById(masterPageInputPrefix + 'lblMessage');
        lblMessage.innerHTML = 'Some of the segments in your playlist do not currently have Flash available. Please select a different format if you would like all your segments to play together. We apologize for the inconvenience.<br>';
    }
}

function PlayWindowsMedia(playBit, strMediaURL)
{
    var mediaHTML = '';
    //sniff browser								
	if (IsBrowserIE())
	{				
		mediaHTML += '<object id="WMPlayer" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" class="videoPlayerQT" VIEWASTEXT>';
		mediaHTML += '<param name="autoStart" value="' + playBit + '" />';
		mediaHTML += '<param name="stretchToFit" value="true" />';
		mediaHTML += '<param name="ShowStatusBar" value="1" />';
		mediaHTML += '<param name="showControls" value="1" />'	;
		mediaHTML += '<param name="enablejavascript" value="true" />';			
		mediaHTML += '<param name="pluginspage" value="http://www.microsoft.com/Windows/MediaPlayer/" />';
		mediaHTML += '<param name="URL" value="'+ strMediaURL +'" />';
		mediaHTML += '<param name="captioningID" value="closedCaptioningText" />';		
		mediaHTML += 'Your browser does not support the ActiveX Windows Media Player';
		mediaHTML += '</object>';			
	}
	else if (navigator.mimeTypes)
	{
	    //the baseURL is needed for the mediaURL in firefox
        //var baseURL = 'http://www.fmgondemand.com';
        var baseURL = 'http://test.digital.films.com';
        var urlPos = window.location.href.indexOf('/', 8);
        if (urlPos > -1) baseURL = window.location.href.substring(0, urlPos);

		mediaHTML +='<embed type="video/x-ms-wvx" src="' + baseURL + strMediaURL + '" id="WMPlayer" name="WMPlayer" height="100%" width="100%"  ShowDisplay="0" ShowControls="1" stretchToFit="true" class="videoPlayerWM" AutoStart=' + playBit + ' ShowStatusBar="1"></embed>';
	}
	return mediaHTML;				
}

function ToggleClosedCaptioning(showMessage)
{	
    if (GetMediaType() == "WM")
    {
        if (IsBrowserIE())
        { 
            //closed captioning for WM/IE will play in the div text
            toggleElement("closedCaptioningText");
        }
        else if (navigator.mimeTypes && showMessage) //firefox
        {        
            //closed captioning for WM will NOT play in the div text,
            //because the user's browser does not support ActiveX.  
            //CC will only work in full-screen mode
            alert("Your browser only supports closed captioning for Windows Media Player in full-screen mode.\n\n" + fullScreenMessage);
        }
    }
    else //quicktime
    {
        //for quicktime, we use this hidden field to tell us the current CC state
        //these additional hidden fields hold the values of the last played video
        var hdnCC = $(masterPageInputPrefix + 'hdnClosedCaptioning');
        var contentType = $F(masterPageInputPrefix + 'hdnContentType');
        var contentID = $F(masterPageInputPrefix + 'hdnContentID');
        var accessMethod = $F(masterPageInputPrefix + 'hdnAccessMethod');        
    
        if (hdnCC.value == "1")
        {
            //cc is already playing, turn it off
            if (confirm("In order to turn off QuickTime closed captioning, the video will need to restart.\r\n\r\nDo you wish to continue?"))
            {
                hdnCC.value = "0";
                hideElementByID("closedCaptioningText");
                PlayMovie(contentType, contentID, "1", accessMethod);
            }
        }
        else
        {        
            //cc is not playing, turn it on
            if (confirm("In order to view QuickTime closed captioning, the video will need to restart.\r\n\r\nDo you wish to continue?"))
            {
                hdnCC.value = "1";              
                hideElementByID("closedCaptioningText");
                PlayMovie(contentType, contentID, "1", accessMethod);                
            }
        }
    }
}

function IsBrowserIE()
{
    return (window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1);
}

function IsOperatingSystemMac()
{
    var hdnOS = document.getElementById(masterPageInputPrefix + 'hdnOS');
            
    return (hdnOS != null && hdnOS.value.toLowerCase().indexOf('mac') > -1);
}

function GetMediaType()
{
	var selMediaType = document.getElementById(masterPageInputPrefix + 'ddlPlayer');
	var mediaType = selMediaType.options[selMediaType.selectedIndex].value;
    
    return mediaType;
}
function SetMediaType(value)
{
    var selMediaType = document.getElementById(masterPageInputPrefix + 'ddlPlayer');
    selMediaType.value = value;
    LoadBitRate();
}

//set the selected learning objects (listbox) in the playlist tab
function SetLearnObjPlaylist(contentId)
{//alert("SetLearnObjPlaylist contentId: " + contentId);
    var ddlLearnObjPlaylist = document.getElementById(masterPageInputPrefix + 'ddlLearnObjPlaylist');
    if (ddlLearnObjPlaylist != null)
    {
        var loIDs = ddlLearnObjPlaylist.options;
        for (i=0; i< loIDs.length; i++)
        { 
            if (loIDs[i].value == contentId)
            {
                ddlLearnObjPlaylist.selectedIndex = i;
            }
        }
    }
}

/* used to set either media player to full screen */
function SetFullScreen(player)
{			
	if (player == 'WMP')
	{
	    if (IsBrowserIE())
	    {
		    try
		    {
			    document.WMPlayer.fullscreen = true;
		    }
		    catch (fullscreenExcep)
		    {
		    }
		}
		else
		{
            alert(fullScreenMessage);		
		}
	}
	else if (player == 'QTP')
	{
		try
		{
			qtp = document.getElementById('QTPlayer');
			qtp.fullscreen = 'full';		
		}
		catch (exc)
		{
		}
	}
}

function PlayEntirePlaylist()
{
    //alert('PlayEntirePlaylist');
    var contentIDs = $F(masterPageInputPrefix + 'hdnContentIDs');
    var contentTypes = $F(masterPageInputPrefix + 'hdnContentTypes');
    var descriptions = $F(masterPageInputPrefix + 'hdnDescriptions');
    
    //play the entire movie.  The Start/End Times will contain a list of all objects
    //Here, the AccessMethod is specifically different for reporting purposes
    var success = PlayMovie(contentTypes, contentIDs, "1", "PlaylistAll"); 
    
    if (success)
    {    
        //show the descriptions for ALL video objects
        var description = "";
        
        //build up the description from each video object
        var descriptionArray = descriptions.split('|');
        for (var i = 0; i < descriptionArray.length; i++)
        {
            //separate them with some sort of line break
            description += descriptionArray[i] + "<hr>";     
        }      
        
        //ready to go, display the complete list of descriptions
        ShowDescription("", description);
            
        //highlight the PlayAll image button
        var imagePlayEntirePlaylist = document.getElementById('imgPlayEntirePlaylist');
        if (imagePlayEntirePlaylist)
        {
            imagePlayEntirePlaylist.src = '/common/image/playAllActive.jpg';
        }
    }
    else
    {
    	var lblMessage = document.getElementById(masterPageInputPrefix + 'lblMessage');
    	lblMessage.innerHTML = 'The "Play All" option is not available because there are too many segments to load in your playlist. You can still watch each segments segment by clicking on the individual "Play" icons.<br>';
    }    
}

function getReleaseUrlFromViewVideo(contentType, contentID)
{
    var encryptedMediaID = "";

    if (contentType == 'T')
    {
        //get the title value
        encryptedMediaID = document.getElementById(masterPageInputPrefix + 'hdnTitleRelease').value;
    }
    else
    {
        //get it from the learning object
        encryptedMediaID = document.getElementById('hdnReleases' + contentID).value;    
    }
	return encryptedMediaID;
}

function getReleaseUrlFromPlaylist(contentIDs)
{
    var contentIDArray = contentIDs.split(',');
    var mediaURL = "";       
    var previousURL = "";
    var nextURL = "";    

    for (var i = 0; i < contentIDArray.length; i++)
    {
        //prepend the comma delimiter for use with the querystring
        if (mediaURL != "") mediaURL += ",";
        
        //hold onto the last URL we got, you'll see why below
        previousURL = nextURL;

        //now get the releaseURL for this playlist item
        nextURL = document.getElementById('hdnReleases' + contentIDArray[i]).value;
        
        //if it's the same URL, just leave it empty as a comma-separated placeholder.  
        //we need to do this to shorten the final URL to avoid the 2057 character limit for the Play All button
        if (previousURL != nextURL)
        {
            mediaURL += nextURL;
        }
    }    	               	
	return mediaURL;    
}
					
function ValidateViewDetails()
{
	var titleCB = document.getElementsByName('chkT');
	var loCB = document.getElementsByName('chkLO');
	var count = 0;
	var TitleIds = '';
	var LOIds = '';
	var collectionItemID = '';
	
	for (i = 0; i < titleCB.length; i++)
	{
	    collectionItemID = titleCB[i].value;
		if(titleCB[i].checked)
		{
			TitleIds = titleCB[i].id.replace('T','') + ",";
			count++;
		}
	}
	
	for (i = 0; i < loCB.length; i++)
	{
		if(loCB[i].checked)
		{
			LOIds += loCB[i].value + ",";
			count++;
		}
	}
	
	var divPlaylistError = document.getElementById('divPlaylistError');

	if (count == 0)
	{
		if (divPlaylistError)
		{
			divPlaylistError.innerHTML = '*You must select at least one item to perform this operation.<br />';
		}
		return false;
	}
	else
	{
		divPlaylistError.innerHTML = '<br />';
        
        if (TitleIds.length > 0)
        {
		    TitleIds = TitleIds.substring(0,TitleIds.length-1);	
		}
		if (LOIds.length > 0)
		{
		    LOIds = LOIds.substring(0,LOIds.length-1);	
		}
		
		var strURL = '/PortalPopCreatePlaylist.aspx?ciid=' + collectionItemID + '&tids=' + TitleIds + '&loids=' + LOIds;
		window.open(strURL , 'newwin', 
			'resizable=no,scrollbars=no,titlebar=no,toolbar=no,status=yes,screenX=' +
			(screen.availWidth - 600)/2 + ',screenY='+ (screen.availHeight - 300)/2 +
			',top='+ (screen.availHeight - 300)/2  +',left='+
			(screen.availWidth - 300) / 2 + ',width=620,height=390');	
		return false;
	}
}
					
function ShowDescription(TitleId, description) {
    try {
        SelectImageButton(TitleId, false, masterPageInputPrefix);

        var displayDisc = document.getElementById('txtVideoDesc');

        description = replaceSubstring(description, '&#8217;', '\'');
        description = replaceSubstring(description, '&#8218;', '\"');
        description = replaceSubstring(description, '&#8219;', '\n');
        description = replaceSubstring(description, '&#8220;', '\r');
        displayDisc.innerHTML = "";
        displayDisc.innerHTML = description;
    } catch (err) { }
}

function GetElementByIdEndsWith(tagName, endsWith) {
    var elements =
             document.getElementsByTagName(tagName);

    for (var i = 0; i < elements.length; i++) {
        if (elements[i].id.endsWith(endsWith)) {
            return elements[i];
        }
    }

    return null;
}

String.prototype.endsWith = function(txt, ignoreCase) {
    var rgx;

    if (ignoreCase) {
        rgx = new RegExp(txt + "$", "i");
    }
    else {
        rgx = new RegExp(txt + "$");
    }

    return this.match(rgx) != null;
}



function ShowSegmentURL(aid, xtid, loid, platform, prepend) {

    var EmbedProxy = '';

    if (prepend != '') {
        EmbedProxy = prepend;
    }

    var Plt = 'FOD';
    var ImagePath = '/common/image/button_help2.gif';

    var CVOD = platform.toString().match('streaming');
    if (CVOD != null) {
        Plt = 'CVOD';
        ImagePath = '/common/image/HSCollection/button_help2.gif';
    }
    var AVOD = platform.toString().match('avod');
    if (AVOD != null) {
        Plt = 'AVOD';
    }

    var TitleURL = document.getElementById('TitleURLdiv');
    TitleURL.innerHTML = "";
    var SegmentURL = document.getElementById('ShowSegmentURL');
    var SegmentURLhtml = '';

    //SegmentURLhtml = '<table><tr><td><span id="SegmentText"><a href="javascript:launchPopUpHELP(' + "'" + 'PopPlayListURLhelp' + "'" + ')"><img src="' + ImagePath + '" alt="URL Info" /></a><b>Segment URL</b></span></td></tr><tr><td>';
    SegmentURLhtml = '<table><tr><td><span id="SegmentText"><b>Segment URL</b></span></td></tr><tr><td>';
    SegmentURLhtml = SegmentURLhtml + '<input type="text" readonly class="recurl"  value="';
    SegmentURLhtml = SegmentURLhtml + platform + aid + '&xtid=' + xtid + '&loid=' + loid + '"';
    SegmentURLhtml = SegmentURLhtml + '/></td></tr></table>';
    SegmentURL.innerHTML = "";
    SegmentURL.innerHTML = SegmentURLhtml;
    
    var EmbedURL = document.getElementById('EmbedURL');
    if (EmbedURL) {
        EmbedURL.innerHTML = "";
        var EmbedURLhtml = '';
        //EmbedURLhtml = '<table><tr><td><span id="SegmentText"  style="margin-left: 10px;"><a href="javascript:launchPopUpHELP(' + "'" + 'PopEmbedhelp' + "'" + ')"><img src="' + ImagePath + '" alt="Embed Info" /></a><b>Embed Code</b></span></td></tr><tr><td>';
        EmbedURLhtml = '<h6>Embed Code</h6>';
        //EmbedURLhtml = EmbedURLhtml + '<input type="text" readonly  class="recurl" value="';

        EmbedURLhtml = EmbedURLhtml + '<div style="width:580px; height:105px; padding:5px; font-size:x-small; font-weight:bold; background-color:white; background-repeat:no-repeat">';

        EmbedURLhtml = EmbedURLhtml + '&lt;div id=' + "'emb" + loid + "'" + '&gt;&lt;/div&gt;';

        EmbedURLhtml = EmbedURLhtml + '&lt;script type=' + "'" + 'text/javascript' + "'" + '&gt;function addLoadEvent(func){var oldonload = window.onload;if (typeof window.onload != ' + "'" + 'function' + "'" + ') {window.onload = func} else {window.onload = function() {if (oldonload) {oldonload()}func()}}}&lt;/script&gt;';

        EmbedURLhtml = EmbedURLhtml + '&lt;script type=' + "'" + 'text/javascript' + "'" + '&gt;addLoadEvent(function S' + loid + '(){document.getElementById(' + "'" + 'emb' + loid + "'" + ').innerHTML=' + "\"";

        EmbedURLhtml = EmbedURLhtml + '&lt;iframe height=' + "'" + '310' + "'" + ' frameborder=' + "'" + '0' + "'" + " width='348' " + "src=" + "'" + 'http://digital.films.com/OnDemandEmbed.aspx?Token=' + xtid + '&aid=' + aid + '&loid=' + loid + '&Plt=' + Plt + '&w=320&h=240&ref=' + "\"" + ' + window.location.href + ' + "\"'" + '&gt;&amp;nbsp;&lt;/iframe&gt;';

        EmbedURLhtml = EmbedURLhtml + "\"" + ';});&lt;/script&gt;';

        EmbedURLhtml = EmbedURLhtml + '</div>';

        //EmbedURLhtml = EmbedURLhtml + '"/>';

        EmbedURLhtml = EmbedURLhtml + '<strong><br /><br /></strong><a href="javascript:launchPopUpHELP(' + "'" + 'PopEmbedhelp' + "'" + ')"><img src="' + ImagePath + '" alt="Embed Info" /></a>&nbsp;&nbsp;<a href="javascript:toggleFAQ(' + "'" + 'oemb' + "'" + ');">Use Old Embed Code</a><br />';

        EmbedURLhtml = EmbedURLhtml + '<div id="oemb" class="Helphiddenfaq" >';

        EmbedURLhtml = EmbedURLhtml + '<div style="width:580px; height:45px; padding:5px; font-size:x-small; font-weight:bold; background-color:white; background-repeat:no-repeat">';

        EmbedURLhtml = EmbedURLhtml + '&lt;iframe height=' + "'" + '310' + "'" + ' frameborder=' + "'" + '0' + "'" + " width='348' " + "src=" + "'" + EmbedProxy + 'http://digital.films.com/OnDemandEmbed.aspx?Token=' + xtid + '&aid=' + aid + '&loid=' + loid + '&Plt=' + Plt + '&w=320&h=240' + "'" + '&gt;&amp;nbsp;&lt;/iframe&gt;';

        EmbedURLhtml = EmbedURLhtml + '</div>';

        EmbedURLhtml = EmbedURLhtml + '</div>';

        EmbedURL.innerHTML = "";
        EmbedURL.innerHTML = EmbedURLhtml;
    }

    var shareMessage = document.getElementById('shareMessage');
    if (shareMessage) {shareMessage.innerHTML = "Share Segment By Email";}

    var SegmentUrlTxtBox = GetElementByIdEndsWith("input", "SegmentUrlTxtBox");
    if (SegmentUrlTxtBox) { SegmentUrlTxtBox.value = platform + aid + '&xtid=' + xtid + '&loid=' + loid; }

    var HiddenLOID = GetElementByIdEndsWith("input", "HiddenLOID");
    if (HiddenLOID) { HiddenLOID.value = loid; }

    var emailSubject = GetElementByIdEndsWith("input", "emailSubject");
    if (emailSubject) { emailSubject.value = "View a Segment from Films On Demand" }
    
    
    var ShareTitle = $get('ShareTitleDIV');
    if (ShareTitle) { ShareTitle.style.display = 'none'; }
    var ShareSegment = $get('ShareSegmentDIV');
    if (ShareSegment) { ShareSegment.style.display = ''; }
}

function ShowTitleURL(aid, xtid, platform, togo) {
    var Plt = 'FOD';
    var ImagePath = '/common/image/button_help2.gif';

    var CVOD = platform.toString().match('streaming');
    if (CVOD != null) {
        Plt = 'CVOD';
        ImagePath = '/common/image/HSCollection/button_help2.gif';
    }
    var AVOD = platform.toString().match('avod');
    if (AVOD != null) {
        Plt = 'AVOD';
    }

    var SegmentURL = document.getElementById('ShowSegmentURL');
    SegmentURL.innerHTML = "";
    var TitleURL = document.getElementById('TitleURLdiv');
    var TitleURLhtml = '';

    //<a href="javascript:launchPopUpHELP(PopPlayListURLhelp)"><asp:Image ID="popImage" runat="server" AlternateText="URL Info"/></a>
    //TitleURLhtml = '<table><tr><td><span id="TitleURLText" style="margin-left: 10px;"><a href="javascript:launchPopUpHELP(' + "'" + 'PopPlayListURLhelp' + "'" + ')"><img src="' + ImagePath + '" alt="URL Info" /></a><b>Title URL</b></span></td></tr><tr><td>';
    TitleURLhtml = '<table><tr><td><span id="TitleURLText"><b>Title URL</b></span></td></tr><tr><td>';
    TitleURLhtml = TitleURLhtml + '<input type="text" readonly    class="recurl"  value="';
    TitleURLhtml = TitleURLhtml + platform + aid + '&xtid=' + xtid + '"';
    TitleURLhtml = TitleURLhtml + '/></td></tr></table>';
    TitleURL.innerHTML = "";
    TitleURL.innerHTML = TitleURLhtml;
    
    var EmbedURL = document.getElementById('EmbedURL');
    if (EmbedURL) {
        EmbedURL.innerHTML = "";
        var EmbedURLhtml = '';
        //EmbedURLhtml = '<table><tr><td><span id="SegmentText"><a href="javascript:launchPopUpHELP(' + "'" + 'PopEmbedhelp' + "'" + ')"><img src="' + ImagePath + '" alt="Embed Info" /></a><b>Embed Code</b></span></td></tr><tr><td>';
        EmbedURLhtml = '<h6>Embed Code</h6><br /><br />';
        //EmbedURLhtml = EmbedURLhtml + '<input type="text" readonly class="recurl" value="';

        EmbedURLhtml = EmbedURLhtml + '<div style="width:580px; height:105px; padding:5px; font-size:x-small; font-weight:bold; background-color:white; background-repeat:no-repeat">';

        EmbedURLhtml = EmbedURLhtml + '&lt;div id=' + "'emb" + xtid + "'" + '&gt;&lt;/div&gt;';

        EmbedURLhtml = EmbedURLhtml + '&lt;script type=' + "'" + 'text/javascript' + "'" + '&gt;function addLoadEvent(func){var oldonload = window.onload;if (typeof window.onload != ' + "'" + 'function' + "'" + ') {window.onload = func} else {window.onload = function() {if (oldonload) {oldonload()}func()}}}&lt;/script&gt;';

        EmbedURLhtml = EmbedURLhtml + '&lt;script type=' + "'" + 'text/javascript' + "'" + '&gt;addLoadEvent(function T' + xtid + '(){document.getElementById(' + "'" + 'emb' + xtid + "'" + ').innerHTML=' + "\"";

        EmbedURLhtml = EmbedURLhtml + '&lt;iframe height=' + "'" + '310' + "'" + ' frameborder=' + "'" + '0' + "'" + " width='348' " + "src=" + "'" + togo.toString() + "&ref=" + "\"" + ' + window.location.href + ' + "\"" + "'" + '&gt;&amp;nbsp;&lt;/iframe&gt;';

        EmbedURLhtml = EmbedURLhtml + "\"" + ';});&lt;/script&gt;';

        EmbedURLhtml = EmbedURLhtml + '</div>';

        //EmbedURLhtml = EmbedURLhtml + '"/>';

        EmbedURLhtml = EmbedURLhtml + '<strong><br /><br /></strong><a href="javascript:launchPopUpHELP(' + "'" + 'PopEmbedhelp' + "'" + ')"><img src="' + ImagePath + '" alt="Embed Info" /></a>&nbsp;&nbsp;<a href="javascript:toggleFAQ(' + "'" + 'oemb' + "'" + ');">Use Old Embed Code</a><br />';

        EmbedURLhtml = EmbedURLhtml + '<div id="oemb" class="Helphiddenfaq" >';
        
        EmbedURLhtml = EmbedURLhtml + '<div style="width:580px; height:45px; padding:5px; font-size:x-small; font-weight:bold; background-color:white; background-repeat:no-repeat">';

        EmbedURLhtml = EmbedURLhtml + '&lt;iframe height=' + "'" + '310' + "'" + ' frameborder=' + "'" + '0' + "'" + " width='348' " + "src=" + "'" + togo.toString() + "'" + '&gt;&amp;nbsp;&lt;/iframe&gt;';

        EmbedURLhtml = EmbedURLhtml + '</div>';

        EmbedURLhtml = EmbedURLhtml + '</div>';
        
        EmbedURL.innerHTML = "";
        EmbedURL.innerHTML = EmbedURLhtml;
    }

    var shareMessage = document.getElementById('shareMessage');
    if (shareMessage) {shareMessage.innerHTML = "Share Full Title By Email";}
    

    var ShareTitle = $get('ShareTitleDIV');
    if (ShareTitle) { ShareTitle.style.display = ''; }
    var ShareSegment = $get('ShareSegmentDIV');
    if (ShareSegment) { ShareSegment.style.display = 'none'; }
}

function SelectImageButton(titleID, isPlayButton,Prefix)
{
    //loop thru each contentID to find the correct image to highlight
    var isImageFound = false;
    var contentIDs = $F(Prefix + 'hdnContentIDs').split(',');
    var imageNameTitle = (isPlayButton) ? 'imgPlayTitle' : 'imgShowInfo';
    var imageSourceSelected = (isPlayButton) ? '/common/image/playActive.gif' : '/common/image/iOver.jpg';
    var imageSourceNotSelected = (isPlayButton) ? '/common/image/play.gif' : '/common/image/i.gif';
    
        
    for (var i = 0; i < contentIDs.length; i++)
    {
        var thisTitleID = contentIDs[i];
        var imgName = (isPlayButton) ? 'L' + thisTitleID : 'i' + thisTitleID;
        var img = document.getElementById(imgName);
        
        if (img)
        {         
            //only toggle visible images...for use with preview center
            if (img.src.indexOf("spacer.gif") < 0)
            {    
                if (titleID == thisTitleID)
                {
                    isImageFound = true;
                    img.src = imageSourceSelected;
                }
                else
                {                
                    img.src = imageSourceNotSelected;
                }
            }
        }
    }
    
    //turn off the play-all button for all these individal video clicks
    if (isPlayButton)
    {
        var imagePlayEntirePlaylist = document.getElementById('imgPlayEntirePlaylist');
        if (imagePlayEntirePlaylist)
        {
            imagePlayEntirePlaylist.src = '/common/image/playAll.jpg';
        }
    }
        
    //check to see if we have a title image
    var imgTitle = document.getElementById(imageNameTitle);
                            
    if (imgTitle)
    {
        //only toggle visible images...for use with preview center
        if (imgTitle.src.indexOf("spacer.gif") < 0)
        {    
            if (isImageFound)
            {
                //an image is already selected, so don't select this one
                imgTitle.src = imageSourceNotSelected;
            }
            else
            {
                //no images were selected, so it must be this one
                imgTitle.src = imageSourceSelected;
            }
        }
    }
}

function replaceSubstring(inputString, fromString, toString) 
{
	// Goes through the inputString and replaces every occurrence of fromString with toString
	var temp = inputString;
	if (fromString == "") 
	{
		return inputString;
	}
	
	if (toString.indexOf(fromString) == -1) 
	{ 
	    // If the string being replaced is not a part of the replacement string (normal situation)
		while (temp.indexOf(fromString) != -1) 
		{
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} 
	else 
	{ 
	    // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
		var midStrings = new Array("~", "`", "_", "^", "#");
		var midStringLen = 1;
		var midString = "";
		
		// Find a string that doesn't exist in the inputString to be used
		// as an "inbetween" string
		while (midString == "") 
		{
			for (var i=0; i < midStrings.length; i++) 
			{
				var tempMidString = "";
				for (var j=0; j < midStringLen; j++) 
				{ 
				    tempMidString += midStrings[i]; 
				}
				
				if (fromString.indexOf(tempMidString) == -1) 
				{
				    midString = tempMidString;
				    i = midStrings.length + 1;
				}
			}
		} 
		
		// Keep on going until we build an "inbetween" string that doesn't exist
		// Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
		while (temp.indexOf(fromString) != -1) 
		{
			var toTheLeft = temp.substring(0, temp.indexOf(fromString));
			var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
			temp = toTheLeft + midString + toTheRight;
		}
		
		// Next, replace the "inbetween" string with the "toString"
		while (temp.indexOf(midString) != -1) 
		{
			var toTheLeft = temp.substring(0, temp.indexOf(midString));
			var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
			temp = toTheLeft + toString + toTheRight;
		}
	} 
	
	// Ends the check to see if the string being replaced is part of the replacement string or not
	// Send the updated string back to the user
	return temp; 			
} 

// Sets a different message on the Share tab if a segment is selected.
function SetShareTabMessage(contentType)
{
    var shareTab = document.getElementById('shareMessage');
    var message = contentType == "L" ? "Share Full Title By Email" : "Share Full Title By Email"; // L = learning object, T = title
    if(shareTab != null)
    {
        if(shareTab.innerText) 
        {
            shareTab.innerText = message;
        }
        else if(shareTab.textContent) 
        {
            shareTab.textContent = message;
        }
    }    
}

// Sets the segment (learning object) ID if one is playing. This is used to add the segment in the database for Add to Playlist.
// This is done in JavaScript because the video segment is changed with JavaScript.
function SetSegmentId(contentType, contentID)
{
    var loidElement = document.getElementById(masterPageInputPrefix + 'LOID');
    if(loidElement != null && contentType == "L")
    {
        loidElement.value = contentID;
    }
}

