var nn4;
var wmpV;
GetCaps();

function GetCaps() {
	var agt = navigator.userAgent.toLowerCase();
    var nn = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
		&& (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
	var major = parseInt(navigator.appVersion);
	nn4 = nn && (major == 4);
}

/*function GetWM() {
	var wm = 0;
	var uastr = navigator.userAgent.toLowerCase();
	var uaver = navigator.appVersion.toLowerCase();
	var iePos = uastr.indexOf("msie");
	var isIE = ((iePos != -1) && (uastr.indexOf("opera") == -1) && (uastr.indexOf("safari") == -1) && (uastr.indexOf("konqueror") == -1));
	var isWin =((uastr.indexOf("win") != -1) || (uastr.indexOf("16bit") != -1));
	if(isIE && isWin){
		var uv = parseInt(uaver.substring(iePos + 5, uaver.indexOf(';', iePos)));
		if(uv >= 5){
			document.body.insertAdjacentHTML("afterBegin", "<span id=\"cc\" style=\"behavior:url(#default#clientCaps)\"></span>");
			function GetVer(ID){
				var v;
				if(cc){
					v = cc.getComponentVersion(ID,"componentid");
					if (v) {
						v = v.replace(/,/g, ".");
					}
					else {
						v = "";
					}
				}
				else v = "";
				return v;
			}
			wm = GetVer("{6BF52A52-394A-11D3-B153-00C04F79FAA6}");
			if (!wm) {
				wm = GetVer("{22D6F312-B0F6-11D0-94AB-0080C74C7E95}");
			}
		}
		else wm = VbGetWM();
	}
	else{
		var Ps = navigator.plugins;
		var MTs = navigator.mimeTypes;
		if (Ps && MTs) {
			for(var i=0; i < Ps.length; i++) {
				var P = Ps[i];
				if (P) {
					var PN = P.name;
					var PD = P.description;
					if (PN && PD) {
						if ((PN.indexOf("Windows Media") != -1) && (PN.indexOf("Plug") != -1)) {
							wm = 1;
							var WM7 = MTs[isWin ? "application/x-drm-v2" : "application/x-ms-wmd"];
							if (WM7 && WM7.enabledPlugin) {
								wm = "7";
							}
							else if (MTs["video/x-ms-wm"] && MTs["video/x-ms-wmv"]) {
								wm = "6.4";
							}
							else if (MTs["video/x-ms-asf"]) {
								wm = "6.3";
							}
							else {
								var MP2 = MTs["application/x-mplayer2"];
								if (MP2 && MP2.enabledPlugin) {
									wm = "5.2";
								}
							}
						}
					}
				}
			}
		}
    }
    return wm;
}
*/
function GenericLoad()
{
    if (self.LocalOnload)
        LocalOnload();
}

function GenericUnLoad()
{
    if (self.LocalOnunload)
        LocalOnunload();
}

function OpenMeetingInfo(meeting) {
	var url = "MeetingInfo.aspx?Meeting=" + meeting;
	window.open(url, "ParliamentLiveMeetingInfo", "width=480,height=400,scrollbars=yes");
}

function OpenNotes(meeting) {
	var s = new String(meeting);
	var sLength = s.length;
	for(var i = 0; i < 8 - sLength; i++){
		s = "0" + s;
	}
	var url = "../notes/" + s + ".pdf";
	window.open(url, "ParliamentLiveNotes", "width=700,height=550,resizable=yes");
}

var baseTime = null;
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
function InitClock(time) {
	if ((arguments.length > 0) && (time != null)) {
		baseTime = new Date(time);
	}
	else {
		window.setInterval("UpdateClock()", 30000);
	}
	UpdateClock();
}
function UpdateClock() {
	var content = "";
	var time = baseTime;
	if (time == null) {
		time = new Date();
		var hrs = time.getHours();
		var ampm = "am";
		if (hrs > 11) {
			if (hrs > 12) {
				hrs = hrs - 12;
			}
			ampm = "pm";
		}
		var mins = new String(time.getMinutes());
		if (mins.length < 2) {
			mins = "0" + mins;
		}
		content = "&nbsp;&nbsp;" + hrs + ":" + mins + ampm;
	}
	content = days[time.getDay()] + " " + time.getDate() + " " +  months[time.getMonth()] + " " + time.getFullYear() + content + "&nbsp;&nbsp;";
	SetSpan("clockSpan", content);
}

function StyleDisplay(id, d) {
	HtmlObject(id).style.display = d ? "inline" : "none";
}
function SwapId(id, newidd) {
	HtmlObject(id).id = newidd;
}
function HtmlObject(id) {
	var obj = null;
	if (document.getElementById) {
		obj = document.getElementById(id);
	}
	else if (document.all) {
		obj = document.all[id];
	}
	return obj;
}
function SetSpan(id, content) {
	var span = HtmlObject(id);
	if (span != null) 
	{
		span.innerHTML = content;
	}
	//else
	//   alert ("Object NOT found"); 
	    
	    
	/*else if (document.layers != null) {
		var layer = document.layers[id];
		if (layer != null) {
			var layerDoc = layer.document;
			if (layerDoc != null) {
				//content = "<html><head></head><body><p>" + content + "</p></body></html>";
				window.alert(content);
				layerDoc.open();
				layerDoc.writeln(content);
				layerDoc.close();
			}
		}
	}*/
}

//Console functions
function OpenIAConsole(url) {
	window.open(unescape(url), "ParliamentLiveIAConsole", "width=486,height=377");
}
/*
function OpenIAConsole(meeting, IsParliamentProxy) {
	window.open(IAConsoleUrl(meeting, IsParliamentProxy), "ParliamentLiveIAConsole", "width=486,height=377");
}
function IAConsoleUrl (meeting, IsParliamentProxy)
{
	var url = "Console.aspx?Meeting=" + meeting;
	if ((arguments.length > 1) && (typeof(IsParliamentProxy) != "undefined") && (IsParliamentProxy != null)) {
		url = url + "&IsParliamentProxy=" + IsParliamentProxy;
	}
	return url;
}
*/
function OpenBroadcastConsole(encoding, IsParliamentProxy) {
	window.open(BroadcastConsoleUrl(encoding, IsParliamentProxy), "ParliamentArchiveConsole", "width=486,height=377");
}
function BroadcastConsoleUrl(encoding, IsParliamentProxy) {
	var url = "Console.aspx?Encoding=" + encoding;
	if ((arguments.length > 1) && (typeof(IsParliamentProxy) != "undefined") && (IsParliamentProxy != null)) {
		url = url + "&IsParliamentProxy=" + IsParliamentProxy;
	}
	return url;
}
function OpenConsole(encoding, startAt) {
	window.open(ConsoleUrl(encoding, startAt), "ParliamentLiveConsole", "width=486,height=377");
}
function ConsoleUrl(encoding, startAt) {
	var url = "Console.aspx?Encoding=" + encoding;
	if ((arguments.length > 1) && (typeof(startAt) != "undefined") && (startAt != null)) {
		url = url + "&StartAt=" + startAt;
	}
	return url;
}
function SwitchConsole(encoding) {
	var consoleWindow = null;
	switch (channelsType) {
		case "Popup":
			consoleWindow = window.opener;
			break;
		case "Embed":
			consoleWindow = window.parent;
			break;
	}
	if (consoleWindow != null) {
		consoleWindow.document.location.href = ConsoleUrl(encoding);
	}
}
var feed = null;
var controlsHeight = -1;
var playerHeight = -1;
function ConsoleLoad(t, f, cH, pH) {
	feed = f;
	controlsHeight = cH;
	playerHeight = pH;
	if (nn4) {
		document.appObs.setByProxyDSScriptCommandObserver(document.wmpEmbed, true);   
	}
	InitClock(t);
}
function Animate(a) 
{
	if ((controlsHeight != -1) && (playerHeight != -1)) 
	{ 
		if (feed == "Audio") 
		{
		    //HtmlObject("WMP").height = a ? controlsHeight : playerHeight;
		    //alert ("Animate, feed = Audio, a = " + a);
			StyleDisplay("audioScreen", !a);
		}
		else 
		{
		    var ht = a ? controlsHeight : playerHeight;
             
            if (ht == 0)
                HtmlObject("WMP").height = 1;
            else
                HtmlObject("WMP").height = ht; //a ? controlsHeight : playerHeight;
 		}
		StyleDisplay("swf", a);
	}
}
function OnScript(t, p) {
	if (t == "CAPTION") {
		if (nn4) {
			p = new String(p);
		}
		p = p.replace(/\n/g,"<br>");
		SetSpan("captionsSpan", p);
	}
}
var channelsWindow = null;
var channelsType = nn4 ? "Popup" : "Embed";
function OpenChannels() {
	var url = "Channels.aspx?Type=" + channelsType;
	if (channelsType == "Popup") {
		channelsWindow = window.open(url, "Channels", "width=192,height=144");
	}
	else {
		var channels = HtmlObject("channelsFrame");
		var f = (channels.style.display == "none");
		StyleDisplay("captionsSpan", !f);
		StyleDisplay("channelsFrame", f);
		channels.src = f ? url : "";
	}
}
function ConsoleUnload() {
	if ((channelsWindow != null) && (!channelsWindow.closed)) {
		channelsWindow.close();
	}
}

function URLParameterKeysContains(skey) 
{
    var retval = false;
    
    var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			if (arrParamNames[i] == skey)
			{
			    retval = true;
			    break;
			}
		}
	}
    
    return retval;
}


function getURLParameters() 
{
	var sURL = window.document.URL.toString();
	
	if (sURL.indexOf("?") > 0)
	{
		var arrParams = sURL.split("?");
			
		var arrURLParams = arrParams[1].split("&");
		
		var arrParamNames = new Array(arrURLParams.length);
		var arrParamValues = new Array(arrURLParams.length);
		
		var i = 0;
		for (i=0;i<arrURLParams.length;i++)
		{
			var sParam =  arrURLParams[i].split("=");
			arrParamNames[i] = sParam[0];
			if (sParam[1] != "")
				arrParamValues[i] = unescape(sParam[1]);
			else
				arrParamValues[i] = "No Value";
		}
		
		for (i=0;i<arrURLParams.length;i++)
		{
			alert(arrParamNames[i]+" = "+ arrParamValues[i]);
		}
	}
	else
	{
		alert("No parameters.");
	}
}

