



// Video clip array
var g_clips= new Array();

var iframe_src_path = '/videocast/include/';

// TC Plugin instance
var g_TrustCastPlugin = new TrustCastPlugin('https://secure5.trustcast.com/tmn_cgi/scripts/client_register.py');

// Content Info:
var g_ProviderName = 'The History Channel'; 
var g_ListName = 'THC_HP';
var g_ListID = '01245cdbfc74b3d0';
//var g_ListID = 'aaa44053ac2b7acc';
var g_ListDesc = 'THC VideoCast';
var g_MinVersion = 'W2.5.40205.1';

// Server Info:b
var g_ServerDesc = 'A&E VideoCast Server';
var g_RegURL = 'https://secure5.trustcast.com/tmn_cgi/scripts/client_register.py'
var g_AddURL = 'http://secure5.trustcast.com/tmn_cgi/scripts/add_subscription.py';
var g_RegSignature = 'wONV9znjk6X+iHoawac4suVJd4haXCXS5mpgHQUCRaFuAQ8z6ny3+jurpuBxdJh/INu15RSdU5Qc/Q2GNmxG5MeD2kluBcrMIdqjTPAsVNNh1hhoA33bEN7PHC9Zch8aBkxstE5px3wTXpa73ox4fmtr2zgYoKW3IfsLfbRAizc=';
var g_SignedURL ='https://secure5.trustcast.com/tmn_cgi/scripts/client_register.py=|='+g_RegSignature;

var installer_dir = 'http://secure5.trustcast.com/history_installers/';
var g_StandAloneInstall = installer_dir+'trustcast_installer.exe';
var g_AutoInstall = installer_dir+'trustcast_installer.dll';
//var g_InstallCompleteURL = "http://www.historychannel.com/index.html?defaultTab=2";
var g_InstallCompleteURL = "";
var g_InstallerLoc = "http://secure5.trustcast.com/history_installers/TrustCast_Installer.dat";
var g_InstallerSig = "tBpl18XQJEgKDPoPZb/ivZs3T4uzm39UqW2k0zeMcYQMsBOzT4ol8XxJFmWOybmYnvCrWoPOR/OuYStwl0hzEbFVseZvuwjoZq37FvbCzbdF+LB2bGfPHBIuBYWK3EavyrBSvdTDGjhExwMpZL2GRImolIQBMtGRhn3sOOSMgCM=";

// VideoClip flashvars container
var clipFlashVars = "";

// Flash inter-domain security file
var domainClip = "";

// Flashvar state vals
var trustcast = "false";
var content = "false";
var issue = "false";

function alertVars(){
	alert('platform: '+platform+'\nis_compliant: '+is_compliant+'\ntrustcast: '+trustcast+'\ncontent: '+content+'\nissue: '+issue);

	alert('clipFlashVars: '+clipFlashVars);

	alert('domainClip: '+domainClip);
}

function startTrust ()
{
//	alert('startTrust called');

	BuildClipArray();
	buildDomainClip();

//	alert('num clips: '+g_clips.length);

	stateDetect();

//	alertVars();
}

function launchVideocastFullScreen(clipTitle){
//	alert("launchVideocastFullScreen called");
//	alert('clipTitle: '+clipTitle);

	var encodedTitle = escape(clipTitle);
//	alert("encodedTitle: "+encodedTitle);


	var windowW=screen.width;
	var windowH=screen.height;
	var windowX=0;
	var windowY=0;


	var urlPOP = "/videocast/fullscreen.jsp?clipTitle="+encodedTitle;

	var s = "width="+windowW+",height="+windowH;

	var beIE = document.all?true:false;

	var NFW = window.open(urlPOP,"popFrameless","fullscreen=1");
	NFW.blur();
	NFW.focus();

	NFW.resizeTo(windowW,windowH);
	NFW.moveTo(windowX,windowY);

	NFW.focus();
}

function doSignup() {
//	alert('signupuser return val: '+g_TrustCastPlugin.SignUpUser(g_ListName, g_ListDesc, g_ListID, g_ServerDesc, g_AddURL, g_SignedURL, ''));
   var sign_up = g_TrustCastPlugin.SignUpUser(g_ListName, g_ListDesc, g_ListID, g_ServerDesc, g_AddURL, g_SignedURL, '')
}

function showHelp() {
   window.open("/videocast/help/help.html","helpWin","width=418,height=450,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no");
}

function BuildClipArray() {



// Videoclip index
var j=1;

//	alert('clip 0: \ntitle: AutoManiac+-+Wednesdays+%40+10%2F9c%21 \nfilename: THC_AUTO2/thc_manic_weds.flv \nlength: 121 \nlink: http://www.history.com/automaniac/');

	var nClip = new clip("AutoManiac+-+Wednesdays+%40+10%2F9c%21", "", "","tmn:/index.tmn?file=/The+History+Channel/THC_AUTO2/thc_manic_weds.flv&type=.tmn","THC_AUTO2/thc_manic_weds.flv","121","http://www.history.com/automaniac/")
	g_clips.push(nClip);

	if (nClip.GetPath() != ""){
		var vTitle = "videoTitle"+j;
		var vURL = "videoURL"+j;
		var vDuration = "videoDuration"+j;
		var vLink = "videoLink"+j;

		clipFlashVars += vTitle+"="+nClip.title+"&amp;";
		clipFlashVars += vURL+"="+nClip.GetPath()+"&amp;";
		clipFlashVars += vDuration+"="+nClip.length+"&amp;";
		clipFlashVars += vLink+"="+escape(nClip.link)+"&amp;";
	
		j++;
	}



	nClip = null;
}

function buildDomainClip() {
	

	var dClip = new clip("Domain+Clip", "Flash+inter-domain+security+clip", "","tmn:/index.tmn?file=/The+History+Channel/CONTROLLER_FLV/accept_domain.swf&type=.tmn","accept_domain.swf","0");

	domainClip = dClip.GetPath();

//	alert('domainClip test: '+domainClip);

	if (domainClip == ""){
//		alert('Flash domain security file does not exist locally! The clips will not play.');
	}
}

function stateDetect() {
//	alert('stateDetect called');

	if (TrustCastAvailable()){
		//alert('TrustCast avail');

		trustcast = "true";

		// CHECK IF UPGRADE NECESSARY
		if (g_TrustCastPlugin.UpgradeRequired(g_MinVersion)){
			//alert('TC client upgrade necessary.');
			trustcast = "false";
		}else{
			//alert('TC client upgrade not necessary.');

			trustcast = "true";

			// CHECK FOR SUBSCRIPTION
			if (g_TrustCastPlugin.IsUserSignedUp(g_ProviderName, g_ListName)){
				//alert('You are signed up.')

				issue = "true";

				if (AnyClipAvailable(g_clips)){
//					alert('clips avail');
					content = "true";
				}else{
//					alert('clips unavail');
					content = "false";
				}
			}else{
//				alert('You are not signed up.');
				issue = "false";
			}
		}
	}else{
//		alert('TrustCast unavail');
		trustcast = "false";
	}
}

function demoPopup(){
	if ((!is_ie4up) && (!is_nav6up) && (!is_moz)){
		// iframes not supported - show popup
		window.open("/videocast/include/demo_popup.html","win1","width=435,height=330,toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no");		
	}
}

// ### Code from handle_install page on aetv HP
g_maxTries = 10;
g_tries = 0;

function doInstall(){
   	DebugOut(g_DebugInfo,"install_trustcast() called.");
   	SetInstTimer();

//	var installer = null;

	try {
      var installer = new ActiveXObject("TrustCast.WebInstaller");
      DebugOut(g_DebugWarn,"Created ActiveX installer object");
	}catch (e){
		CatchError(e);
		return 1;
	}

      if (typeof g_Email == 'undefined' || g_Email == '')
      {
         installer.setProperty("userEmail", "portal");
         DebugOut(g_DebugInfo,"Set installer prop userEmail to 'portal'.");
      }
      else
      {
         installer.setProperty("userEmail", g_Email);
         DebugOut(g_DebugInfo,"Set installer prop userEmail to '" + g_Email + "'.");
      }
      installer.setProperty("productID", g_ListID);
      DebugOut(g_DebugInfo,"Set installer prop productID to '" + g_ListID + "'.");
      installer.setProperty("regURL", g_RegURL);
      DebugOut(g_DebugInfo,"Set installer prop regURL to '" + g_RegURL + "'.");

    // Next-generation installer properties
      if (typeof g_InstallerLoc == 'undefined' || g_InstallerLoc == '')
      {
        installer.setProperty("installerLoc", " ");
      }
      else
      {
        installer.setProperty("installerLoc", g_InstallerLoc);
      	DebugOut(g_DebugInfo,"Set installer prop installerLoc to '" + g_InstallerLoc + "'.");
      }
      if (typeof g_InstallerSig == 'undefined' || g_InstallerSig == '')
      {
        installer.setProperty("installerSig", " ");
      }
      else
      {
        installer.setProperty("installerSig", g_InstallerSig);
      	DebugOut(g_DebugInfo,"Set installer prop installerSig to '" + g_InstallerSig + "'.");
      }


      if (typeof g_InstallCompleteURL == 'undefined' || g_InstallCompleteURL == '')
      {
         installer.setProperty("installedURL", " ");
         DebugOut(g_DebugInfo,"Set installer prop installedURL to ' '.");
      }
      else
      {
         installer.setProperty("installedURL", g_InstallCompleteURL);
         DebugOut(g_DebugInfo,"Set installer prop installedURL to '" + g_InstallCompleteURL + "'.");      }

      installer.setProperty("regSignature",g_RegSignature);
      DebugOut(g_DebugInfo,"Set installer prop regSignature to '" + g_RegSignature + "'.");
      installer.launchInstaller();

      //writeText('status',g_InstallerLaunchedHTML);

}

function CatchError(e)
{
   DebugOut(g_DebugWarn,'Exception launching installer:' + e.description);
	alert('The TrustCast installer could not complete properly. Please try again by clicking "restart your download".');

//   OpenStandAloneInstaller();
   return true;
}
var g_InstTimerID = 0;
var g_InstTimerInterval = 5000; // milliseconds

function SetInstTimer() {
   g_TimerID = setInterval('HandleInstTimer()',g_InstTimerInterval);
}

function EndInstTimer() {
   clearInterval(g_TimerID);
   g_TimerID = 0;
}

function HandleInstTimer() {

   if (TrustCastInstalled() == 2) {
      window.top.location.href = '/index.html?defaultTab=2&issueForce=true';
      EndInstTimer();
   }
}

function OpenStandAloneInstaller() {
//   window.open(g_StandAloneInstall);
   window.location.href = g_StandAloneInstall;
}

function writeText(id, str) {
    if (document.getElementById)
        document.getElementById(id).innerHTML = str;

    else if (document.all)
        document.all[id].innerHTML = str;
}

// ### End code from handle_install

//<!--PAGE DONE-->
