// JavaScript Document

// For siteCatalyst code from testserver.pgs.com, used in video_frame_noflash_pgs_sitecatalyst.htm
var parentTestserver = '';
if(document.referrer.length > 0 && document.referrer.indexOf("http://testserver.pgs.com") != -1) {
	parentTestserver = '&testserver=true';
}



// Browser sniff -- the following code does a very simple browser check and rates the 
//     browser as either Internet Explorer on a Win32 platform or not, so that we 
//     know to use the ActiveX model, or the plug-in Model.
var sBrowser = navigator.userAgent;
var randomnumber=Math.round(Math.random()*1000);
var randomtext=String(randomnumber)+"";
if ((sBrowser.indexOf("IE") > -1) && (navigator.platform == "Win32"))
{	//document.write("IE");
	sBrowser = "IE";
} else {
	sBrowser = "nonIE";
	//document.write("not IE");
}
// end browser sniff
function QueryString(key)
{ 
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		};
	};
	
	//alert(value);
	return value;
};
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
	var query = window.location.search.substring(1);
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		};
	};

};
QueryString_Parse();
function checkLink(){
if(QueryString('id')!=null){


	var queries = '?id='+QueryString('id');
	var width = '910';
	var height = '166';
	var src = 'http://www.smartcom.no/pgs/PGSMENU.swf';
	// assemble flash obj
	var l1 = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
	var l2 = '<param name="movie" value="'+src+queries+'" />';
	var l3 = '<param name="quality" value="high" />';
	var l4 = '<embed src="'+src+queries+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
	var l5 = '</object>';
	
	document.getElementById('mainMenu').innerHTML=l1+l2+l3+l4+l5;
};
};

function liveevent(tittel, goaltime, runthis,image){
var height="378";
var width="600";
	var queries="?tittel="+tittel+"&goaltime="+goaltime+"&runthis="+runthis+"&image="+image+"&random="+randomtext;
	var src="liveevent.swf";
	var l1 = '<object ID="MediaPlayer1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
	var l2 = '<param name="movie" value="'+src+queries+'" />';
	var l3 = '<param name="quality" value="high" />';
	var l4 = '<embed ID="MediaPlayer1" src="'+src+queries+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
	var l5 = '</object>';
	var allLines=l1+l2+l3+l4+l5;
	document.getElementById('videoPlayer').innerHTML=allLines;
	
}
function newURL(selectedVideo){
var selectedVideo=selectedVideo+"";
//alert("selectedVideo "+selectedVideo);
//document.MediaPlayer1.Stop();
//alert(selectedVideo+":"+selectedVideo.length);
if(selectedVideo!=null){
if(selectedVideo.length>=5){
//document.MediaPlayer1.URL=selectedVideo;
//document.MediaPlayer1.SRC=selectedVideo;
//document.MediaPlayer1.Play();
//alert(selectedVideo)
var l1='<div><iframe marginwidth="0" marginheight="0"  leftmargin="0" topmargin="0" frameborder="0" scrolling="no" id="estreamframe" width="910" height="434" src="'+selectedVideo+parentTestserver+'"></iframe></div>';
document.getElementById('videoPlayer').innerHTML=l1;
};
if(selectedVideo.length<5){
//alert("selectedVideo<5 "+selectedVideo);
var width ="910";
var height= "405";
var src = 'http://www.smartcom.no/pgs/videoplayer2.swf';
var queries='?flid='+selectedVideo+"&autostart=true";
var l1 = '<object ID="MediaPlayer1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">';
	var l2 = '<param name="movie" value="'+src+queries+'" />';
	var l3 = '<param name="quality" value="high" /><param name="allowFullScreen" value="true" />';
	var l4 = '<embed ID="MediaPlayer1" src="'+src+queries+'" quality="high" allowfullscreen="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
	var l5 = '</object>';
var allLines=l1+l2+l3+l4+l5;
document.getElementById('videoPlayer').innerHTML=allLines;
};
}
};
if(QueryString('id')!=0){
	newURL(QueryString('id'));
	//var queries = '?id='+QueryString('id')+'&cookie='+checkcookie()+'&location1='+window.location;
}else if(QueryString('id')!=0){
newURL(QueryString('id'));
}

function showClick() // This function is called by the btnShowControls button.
                     // It sets the ShowControls property of Media Player to true.
{
	if (sBrowser == "IE") {
		document.MediaPlayer1.ShowControls = true;
	} else {
		document.MediaPlayer1.SetShowControls(true);
	}
}

function hideClick() // This function is called by the btnHideControls button.
                     // It sets the ShowControls property of Media Player to false.
{
	if (sBrowser == "IE") {
		document.MediaPlayer1.ShowControls = false;
	} else {
		document.MediaPlayer1.SetShowControls(false);
	}
}
function stopPlaying(){
document.MediaPlayer1.Stop();
}
function startPlaying(){
document.MediaPlayer1.Play();
}
function pausePlaying(){
document.MediaPlayer1.Pause();
}
function muteClick() // This function is called by the "Mute" button.
                     // It toggles the state of the Mute property of the Media Player.
{
	var bMuteState;

	if (sBrowser == "IE") {
		bMuteState = document.MediaPlayer1.Mute;
	} else {
		bMuteState = document.MediaPlayer1.GetMute();
	}

	if (bMuteState == true) {
		//document.myButtons.btnMute.value="Mute";
		if (sBrowser == "IE") {
			document.MediaPlayer1.Mute = false;
		} else {
			document.MediaPlayer1.SetMute(false);
		}
	} else {
		//document.myButtons.btnMute.value="Un-Mute";
		if (sBrowser == "IE") {
			document.MediaPlayer1.Mute = true;
		} else {
			document.MediaPlayer1.SetMute(true);
		}
	}
}

// queries -- type in the variables you want to send to flash here



