// *******************************************************************************************
// Javascript function to add videos to the website, if the video is hosted on Akamai.
// function sendVideoCode - Tag the video to the source code- to be done by PGM
// function sendCode      - Add the page url that will do video tracking- to be done by PGM
// function showVideo     - Chnage the foll path rtmp://cp47618.edgefcs.net/ondemand/hepcfight/ 
//                        - to the path where the video is hosted on the Akamai server
//						  - To be done by vendor.
// function showVideoSSL  - Chnage the foll path rtmp://cp47618.edgefcs.net/ondemand/hepcfight/ 
//                        - to the path where the video is hosted on the Akamai server
//						  - To be done by vendor.



// *******************************************************************************************

var currentVideo = '';
var video = ''; 
var video_code = ''; 

function sendVideoCode(video) {
	//if(video == 'dennis_animation') video_code = '0036'; // Will be done by PGM for source code tracking.
	sendCode(video_code);

}

function sendCode(video_code) {
	var serverSideURL = "/utilities/videoview.asp?vdid=" + video_code; // Needs to be modofied by PGM.
	var couldProcess = false;

	if (!couldProcess && httpRequester) {
		httpRequester.open("GET", serverSideURL+"&"+Math.random(), true);
//		httpRequester.onreadystatechange = processTestAjax; //UNCOMMENT TO RUN TEST
		couldProcess = true;
		httpRequester.send(null);
	}
	return false;
}


// Function used only to test AJAX functionality
function processTestAjax() {
  if ( httpRequester.readyState == 4 ) {
    if ( httpRequester.responseText.indexOf('invalid') == -1 ) {
	  var results = httpRequester.responseText;
	  alert(results);      	  
      couldProcess = false;
    }
  }
}

function getHTTPRequestObject() {
  var xmlHttpRequest;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (exception1) {
      try {
        xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (exception2) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttpRequest = false;
  @end @*/
  if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlHttpRequest = new XMLHttpRequest();
    } catch (exception) {
      xmlHttpRequest = false;
    }
  }
  return xmlHttpRequest;
}

var httpRequester = getHTTPRequestObject(); // Create the xml http object on the page load




function showVideo (video,URL) {
	bgcolor = '#cccccc'; // BACKGROUND color of movie
	//HIDE current video if one is open
	if (currentVideo) document.getElementById('video_'+currentVideo).innerHTML = '<a href="#" onclick="return showVideo(\''+ currentVideo + '\');"><img src="'+ currentVideo + '.jpg" /></a>';
	
	//UPDATE which video is going to be played
	currentVideo = video;

	//AJAX Code to record hit:
	sendVideoCode(video);
	
	//PLAY selected video
    htmlCode='<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="304" height="228" id="RochePlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/hcp/includes/js/AkamaiPlayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="videoPath=rtmp://cp47622.edgefcs.net/ondemand/flufacts/' + video + '&autoStart=true" /><embed src="/includes/js/AkamaiPlayer.swf" flashVars="videoPath=rtmp://cp47622.edgefcs.net/ondemand/flufacts/' + video + '&autoStart=true" quality="high" bgcolor="#ffffff" width="304" height="228" name="RochePlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	document.getElementById('video_'+video).innerHTML = htmlCode;
	
	// ATLAS Tag code
	var TrackTag = "http://switch.atdmt.com/action/"


	if (URL != null) {
		actionTag = document.getElementById('action_tag');
		if(actionTag) {
			actionTag.src = TrackTag + URL;
		}
	}
	
	return false;
	
}


function showVideoSSL (video) {
	
	if(MM_FlashCanPlay)
	{
	bgcolor = '#cccccc'; // BACKGROUND color of movie
	
	//HIDE current video if one is open
	if (currentVideo) document.getElementById('video_'+currentVideo).innerHTML = '<a href="#" onclick="return showVideo(\''+ currentVideo + '\');"><img src="'+ currentVideo + '.jpg" /></a>';
	
	//UPDATE which video is going to be played
	currentVideo = video;

	//AJAX Code to record hit:
	sendVideoCode(video);
	
	//PLAY selected video
	htmlCode='<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="" height="180" id="RochePlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="/hcp/includes/js/AkamaiPlayer.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashVars" value="videoPath=rtmp://cp47622.edgefcs.net/ondemand/flufacts/' + video + '&autoStart=true" /><embed src="/includes/js/AkamaiPlayer.swf" flashVars="videoPath=rrtmp://cp47622.edgefcs.net/ondemand/flufacts/' + video + '&autoStart=true" quality="high" bgcolor="#ffffff" width="240" height="180" name="RochePlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	document.getElementById('video_'+video).innerHTML = htmlCode;
	}
	return false;
	
}
