var browser_IE;
var browser_NS4;
var browser_W3C;
var platForm;
var isMac;
browser_IE  = (document.all && navigator.appName == 'Microsoft Internet Explorer') ? true : false;
browser_NS4 = (document.layers) ? true : false;
browser_W3C = (!document.all && document.getElementById) ? true : false;

var now = new Date();
var one_year= new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);

platForm=navigator.platform;
isMac=platForm.indexOf("Mac");

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
}

function rand(number) {
	return Math.ceil(rnd()*number);
}

// translate date format from yyyy-mm-dd to Date
function splitDate(inputdate,separator) {
  arrayOfStrings = inputdate.split(separator);
  outputdate= new Date(arrayOfStrings[0],arrayOfStrings[1],arrayOfStrings[2]);
  return outputdate;
}

function framesPopUp(filename,winTitle, winName, winX, winY) {
 winName = "__" + winName;
 var regex = /\W+/;
 if( regex.test(winName) ) {
        winName = winName.replace(/\W+/, '_');
 }
 params = "width="+ winX +",height="+winY;
 winExec = winName +"= window.open('','"+winName+"', params)"
 content = "<html><head><title>"+winTitle+"</title><script>window.onload=function(){}</script></head><frameset rows='0,*' frameborder='NO' border='0' framespacing='0'><frame name='topFrame' scrolling='NO' noresize src='about:blank'><frame name='mainFrame' src='"+ filename +"' scrolling=AUTO></frameset><noframes><body bgcolor='#FFFFFF' text='#000000'></body></noframes></html>"
 eval(winExec);
 eval(winName + ".document.open()")
 eval(winName + ".document.write(content)")
 eval(winName + ".document.close()")
}

function _open_popup_window(w, h, link_url, slug, title){
	var regex = /\W+/;
	if( regex.test(slug) ){
		slug = slug.replace(/\W+/, '_');
	}
	if( w != '' && h != '' ) {
		framesPopUp(link_url, title, slug, w, h);
		return false;
	}
	return true;
}

function openIT(bbLink){
window.open(bbLink,'bctvVideo','width=900,height=646','status=no,scrollbars=no,resizeable=no,toolbar=no,left=1,screenX=1,screenY=0');
}

function playVideo(video_link_high, video_link_low, clip_start, clip_end, clip_caption, archive, slug, sortdate, clip_id, hub){
	var hubcheck;
	if (hub == '') {
			hubcheck = 'TopStories';
	} else {
			hubcheck = hub;
	}
	var w = 755, h = 519; // adjust width and height here.
	var vUrl = "/servlet/HTMLTemplate/!ctvVideo/"
		+ archive + "/"
		+ slug + "/"
		+ sortdate + "/?"
; // the video url
	var qString = 'hub=' + hubcheck + '&'
		+ 'video_link_high=' + video_link_high + '&'
		+ 'video_link_low=' + video_link_low + '&'
		+ 'clip_start=' + clip_start + '&'
		+ 'clip_end=' + clip_end + '&'
		+ 'clip_caption=' + escape(clip_caption) + '&'
		+ 'clip_id=' + clip_id;

	window.open( vUrl + qString
		+'&subhub=video','ctvVideo','width=' + w + ',height=' + h
		+',status=no,scrollbars=no,resizable=no,toolbar=no,left=176,screenX=200,top=0,screenY=0');
}


function format_clip_duration(dur){
	// clip end:   00:02:50.43
	// clip_end     0:02:26
	// clip_end has one of the two above formats.

	var matches, format = "";

	var regexFormat1 = /^(\d{2}):(\d{2}):(\d{2}\.\d{2})$/
	var regexFormat2 = /^(\d+):(\d+):(\d+)$/

	if( regexFormat1.test(dur) ){
		matches = dur.match(regexFormat1);
	}
	else if( regexFormat2.test(dur) ){
		matches = dur.match(regexFormat2);
	}
	if( matches == null ) return ''; // didn't match either pattern.
	var durHours = parseInt(matches[1], 10);
	var durMins  = parseInt(matches[2], 10);
	var durSecs  = Math.floor(parseFloat(matches[3]));
	var durSeconds = durHours*60*60 + durMins*60 + durSecs;
	var one_hour = 60*60;
	var formattedSecs = (durSecs < 10) ? '0' + durSecs : durSecs;
	if( durSeconds > one_hour ){
		format = durHours + ':' + (durMins<10 ? '0'+durMins : durMins) + ':' + formattedSecs;
	}
	else{
		format = durMins + ':' + formattedSecs;
	}
	return format;
}


// Trims a string
function trim(str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

var _thisPopWidth = "";
var _thisPopHeight = "";

/**
  * Used to correct the MAC date bug
  */
function fixCookieDate (date) {
	var base = new Date(0);
	var skew = base.getTime(); // dawn of (Unix) time - should be 0
	if (skew > 0) {  // Except on the Mac - ahead of its time
  	date.setTime (date.getTime() - skew);
	}
}


function setCookie (cookieName, cookieValue, expires, path) {
	fixCookieDate(expires);
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
		+ (path ? '; PATH=' + path : '');
}

function setCookie (cookieName, cookieValue, expires, path, domain) {
	fixCookieDate(expires);
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; EXPIRES=' + expires.toGMTString() : '')
		+ (path ? '; PATH=' + path : '')
		+ (domain? '; DOMAIN=' + domain : '');
}

//Used by search to figure out where we are in the set of returned records.
function UpdateStartRow(theForm, p_start_row, start_row_offset, p_nextPageType){
	var nextRow = eval(p_start_row) + eval(start_row_offset);
	var nextPage;
	if (nextRow < 0) nextRow = 1;
	//When going to a previous page, we must check to see if this is a special case
	//in which we have to return to the initial search results page.
	if ((start_row_offset < 0) &&
	(p_nextPageType == "SearchShows" && nextRow <= 4) ||
	(p_nextPageType == "SearchShowsDyn" && nextRow <= 3) ||
	(p_nextPageType == "SearchNews" && nextRow <= 8) ||
	(p_nextPageType == "SearchSpecials" && nextRow <= 6)) {
		nextPage = "/servlet/HTMLTemplate/!ctv/Search";
	} else {
		switch (p_nextPageType) {
			case "SearchShows"  : nextPage = "/servlet/HTMLTemplate/!ctv/Search/Shows"; break;
			case "SearchShowsDyn"  : nextPage = "/servlet/HTMLTemplate/!ctv/Search/ShowsDyn"; break;
			case "SearchNews"   : nextPage = "/servlet/HTMLTemplate/!ctv/Search/News"; break;
			case "SearchSpecials"   : nextPage = "/servlet/HTMLTemplate/!ctv/Search/Specials"; break;
			default         : nextPage = "/servlet/HTMLTemplate/!ctv/Search"; break;
		}
	}
	theForm.current_row.value = nextRow;
	theForm.start_row.value = theForm.current_row.value;
	theForm.action = nextPage;
	theForm.submit();
}

// programs and local stations select
currentMenu = "none";
if(document.all){
document.onmouseup = showCurrentMenu;
}
else{
window.addEventListener("load",addBodyListener,false);


}

function addBodyListener(){
document.getElementsByTagName('body')[0].addEventListener("mouseup",showCurrentMenu,false);
}

function showMenu(menu){
currentMenu = menu;

showCurrentMenu();
}
function showCurrentMenu(){


        if(currentMenu != "none"){
if(document.getElementById(currentMenu).style.visibility == "visible"){
document.getElementById("programs").style.visibility = "hidden";
document.getElementById("local").style.visibility = "hidden";
currentMenu = "none";

}
else if(currentMenu == "programs"){

document.getElementById("programs").style.visibility = "visible";

document.getElementById("programs").style.height = frames["programs"].document.getElementById("programsBody").offsetHeight + "px";
document.getElementById("local").style.visibility = "hidden";

}
else if(currentMenu == "local"){
document.getElementById("programs").style.visibility = "hidden";
document.getElementById("local").style.visibility = "visible";

document.getElementById("local").style.height = frames["local"].document.getElementById("localBody").offsetHeight + "px";

}
}
else{

}
}

/**
 * SWFObject v1.4.1: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
	if (!document.createElement || !document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion(this.getAttribute('version'), useExpressInstall);
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', useExpressInstall);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "PlugIn");
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) this.addVariable("MMplayerType", "ActiveX");
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(reqVer, xiInstall){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			for (var i=3; axo!=null; i++) {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
				PlayerVersion = new deconcept.PlayerVersion([i,0,0]);
			}
		}catch(e){}
		if (reqVer && PlayerVersion.major > reqVer.major) return PlayerVersion; // version is ok, skip minor detection
		// this only does the minor rev lookup if the user's major version 
		// is not 6 or we are checking for a specific minor or revision number
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		if (!reqVer || ((reqVer.minor != 0 || reqVer.rev != 0) && PlayerVersion.major == reqVer.major) || PlayerVersion.major != 6 || xiInstall) {
			try{
				PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
			}catch(e){}
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = parseInt(arrVersion[0]) != null ? parseInt(arrVersion[0]) : 0;
	this.minor = parseInt(arrVersion[1]) || 0;
	this.rev = parseInt(arrVersion[2]) || 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param){
		var q = document.location.search || document.location.hash;
		if(q){
			var startIndex = q.indexOf(param +"=");
			var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
			if (q.length > 1 && startIndex > -1) {
				return q.substring(q.indexOf("=", startIndex)+1, endIndex);
			}
		}
		return "";
	}
}

/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

var detectableWithVB = false;
var pluginFound = false;

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
// WMPObject
function WMVWriter(videoWidth,videoHeight,video_link, video_hub, clip_start, clip_end, linkSpd,adsFlag){
isWMV = false;
isIE = false;
isFlip4Mac = detectPlugin('Flip4Mac');
pluginFound = detectPlugin('Windows Media');
// if not found, try to detect with VisualBasic
if(!pluginFound && detectableWithVB) {
isIE=true;
isWMV= detectActiveXControl('WMPlayer.OCX.7');	
// alert('test');
}
else if(pluginFound && !detectableWithVB){
isIE=false;
isWMV=true;
}

// alert("isWMV = "+isWMV+" and isIE = "+isIE);
MediaPlayerText ="";
if(isIE && isWMV && !isFlip4Mac){

	MediaPlayerText += '<OBJECT ID="MediaPlayer" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" WIDTH="'+videoWidth+'" HEIGHT="'+(videoHeight - 27)+'">';
	MediaPlayerText += '<PARAM NAME="AutoStart" VALUE="True" >';
	MediaPlayerText += '<PARAM NAME="URL" VALUE="http://www.ctv.ca/servlet/HTMLTemplate/nocompress?content_type=video/x-ms-asf&brand=generic&tf=/ctv/generic/video/videoplayer.asx&cf=/ctv/generic/video/player.cfg&url=' + video_link + '&start=' + clip_start + '&end=' + clip_end + '&spd=' + linkSpd + '&hub='+video_hub+'&ads='+adsFlag+'">';
	MediaPlayerText += '<PARAM NAME="uiMode" VALUE="none">';
	
		MediaPlayerText += '</OBJECT>';
document.getElementById('playerContainer').style.display = "block";
if(document.getElementById('VideoPlayer').innerHTML !=""){
PlayerObj.URL = 'http://www.ctv.ca/servlet/HTMLTemplate/nocompress?content_type=video/x-ms-asf&brand=generic&tf=/ctv/generic/video/videoplayer.asx&cf=/ctv/generic/video/player.cfg&url=' + video_link + '&start=' + clip_start + '&end=' + clip_end + '&spd=' + linkSpd + '&hub='+video_hub+'&ads='+adsFlag;
}

else{
document.getElementById('VideoPlayer').innerHTML = MediaPlayerText;
PlayerObj = document.getElementById('MediaPlayer');
}

oldVolume = ((((PlayerObj.settings.volume)*(0.83)) + 39));
document.getElementById('volumeButton').style.left = oldVolume  + "px";
newVolume = oldVolume;
newPointerPosition = 10;
oldPointerPosition = newPointerPosition;

}
else if(isWMV && !isFlip4Mac){
		MediaPlayerText += '<object id="MediaPlayer"  name="MediaPlayer" ';
		MediaPlayerText +='	classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"';
		      	MediaPlayerText +='codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701"';
			MediaPlayerText +='standby="Loading Microsoft Windows Media Player components..."';
			MediaPlayerText +=' type="application/x-oleobject"';
			MediaPlayerText +=' width="'+videoWidth + '"';
		     	MediaPlayerText +='height="'+videoHeight+'">';

			MediaPlayerText +='<param name="FileName" value="http://www.ctv.ca/servlet/HTMLTemplate/nocompress?content_type=video/x-ms-asf&brand=generic&tf=/ctv/generic/video/videoplayer.asx&cf=/ctv/generic/video/player.cfg&url=' + video_link + '&start=' + clip_start + '&end=' + clip_end + '&spd=' + linkSpd + '&hub='+video_hub+'&ads='+adsFlag+'">';
MediaPlayerText +='<param name="AnimationatStart" value="1">';
			MediaPlayerText +='<param name="TransparentatStart" value="1">';
			MediaPlayerText +='<param name="AutoStart" value="1">';
			MediaPlayerText +='<param name="ShowControls" value="1">';
			MediaPlayerText +='<param name="ShowAudioControls" value="1">';
			MediaPlayerText +='<param name="EnableFullScreenControls" value="1">';
			MediaPlayerText +='<param name="ShowDisplay" value="0">';
			MediaPlayerText +='<param name="ShowGotoBar" value="0">';
			MediaPlayerText +='<param name="ShowPositionControls" value="1">';
			MediaPlayerText +='<param name="ShowStatusBar" value="0">';
			MediaPlayerText +='<param name="ShowTracker" value="0">';
			MediaPlayerText +='<param name="AllowChangeDisplaySize" value="1">';
			MediaPlayerText +='<param name="AutoSize" value="0">';
			MediaPlayerText +='<param name="DisplaySize" value="0">';
	       	MediaPlayerText +='<embed type="application/x-mplayer2"';
	       	MediaPlayerText +='pluginspage="http://www.microsoft.com/windows/windowsmedia/en/download/plugin.asp"';
	       	MediaPlayerText +='src="http://www.ctv.ca/servlet/HTMLTemplate/nocompress?content_type=video/x-ms-asf&brand=generic&tf=/ctv/generic/video/videoplayer.asx&cf=/ctv/generic/video/player.cfg&url=' + video_link + '&start=' + clip_start + '&end=' + clip_end + '&spd=' + linkSpd + '&hub='+video_hub+'&ads='+adsFlag+'"';
	       	MediaPlayerText +='name="MediaPlayer"';
		MediaPlayerText +='height="'+videoHeight + '" width="'+videoWidth+'" AnimationatStart="1" TransparentatStart="1" AutoStart="1" ShowControls ="1" ShowAudioControls="1" EnableFullScreenControls="1" ShowDisplay="0" ShowGotoBar="0" ShowPositionControls="1" ShowStatusBar="0" ShowTracker="0" AllowChangeDisplaySize="1" AutoSize="0" DisplaySize="0" ></embed>';
		MediaPlayerText +=' </object>';
	document.getElementById('VideoPlayer').innerHTML = MediaPlayerText;
}
else {
 document.getElementById('VideoPlayer').innerHTML = "<div id='playerError'><p> <a href='http://www.microsoft.com/windows/windowsmedia/' target='_blank'>Windows Media Player</a> could not be found. You may need to upgrade to the latest version.  </p></div>";

}
simpleAd();	
}

function getElementsByClass(node,searchClass,tag)
{
    var classElements = new Array();
    var els = node.getElementsByTagName(tag); // use "*" for all elements
    var elsLen = els.length;
    var pattern = new RegExp("\\b"+searchClass+"\\b");

    for (i = 0, j = 0; i < elsLen; i++)
    {
        if ( pattern.test(els[i].className) )
        {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?"));
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

