/****************************************************
     Author: Pete Mulder
     Url: http://www.feelslikefriday.com
     Copyright 2004 - HITmedia
	 Last update: March 14, 2005
	 Project: Omroep.nl - Universal Mediaplayer - Livestreams
****************************************************/


// ** settings / reading cookies  ** //

  var po_cookie = document.cookie;

  function getCookie(name) { // use: getCookie("name");
    var index = po_cookie.indexOf(name + "=");
    if (index == -1) return null;
    index = po_cookie.indexOf("=", index) + 1;
    var endstr = po_cookie.indexOf(";", index);
    if (endstr == -1) endstr = po_cookie.length;
    return unescape(po_cookie.substring(index, endstr));
  }

  var today = new Date();
  var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days

  function setCookie(name, value) { // use: setCookie("name", value);
    if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/";
    po_cookie = document.cookie; // update po_cookie
  }
  
  
  
// ** reading / converting URL parameters  ** //

function parseQueryString() {
// Initialize and prepare the variables
var q = location.search.substr(1).split('&');

var args = new Array();
args.length = 0;
// Associate each key with its value in the args array
for (i in q) {
// Skip when q[i] is not set
if (!q[i]) continue ;
// Duplicate keys are not stored seperately, so increase the value
// of args.length only when the key doesn't exist already
if ('undefined' == typeof args[q[i].split('=')[0]]) args.length++;
args[q[i].split('=')[0]] = unescape(q[i].split('=')[1]);
}

// Return the array
return args;
}

// var urlvarlist = 'closeOpener,demo,commskip,skin,show,start,end,player,openMenu,isEbedded,bb,dblview,bbview';
var args = parseQueryString();
for (i in args) {
	// Converting URL params to vars [set manually to avoid mixups]
	/*
	for (j in urlvarlist) {
	if (i == j) var something = args[i];
	}
	*/
	
	if (i == 'id') var id = args[i];
	if (i == 'StartExternal') StartExternal = args[i];
	if (i == 'PlayExternal') PlayExternal = args[i];
	if (i == 'closeOpener') closeOpener = args[i];
	if (i == 'demo') demo = args[i];
	if (i == 'commskip') var commskip = args[i];
	if (i == 'stream') var stream = args[i];
	if (i == 'skin') skin = args[i];
	if (i == 'show') show = args[i];
	if (i == 'start') start = args[i];
	if (i == 'end') end = args[i];
	if (i == 'player') urlplayer = args[i];
	if (i == 'bw') urlbw = args[i];
	if (i == 'openMenu') var openMenu = args[i];
	if (i == 'isEmbedded') isEmbedded = args[i];
	if (i == 'bb') bb = args[i];
	if (i == 'dblview') dblview = args[i];
	if (i == 'bbview') bbview = args[i];
}


// toggle view mode of divs
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	// stat(szDivID)
	if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

/* function to show detailed link & status info in statusbar */
function stat(txt) {
	    window.status = txt;
   } 
 

/* function to load links in opener */
function targetopener(mylink, closeme, closeonly)
{
if (! (window.focus && window.opener))return true;
window.opener.focus();
if (! closeonly)window.opener.location.href=mylink.href;
if (closeme)window.close();
self.close();
}

/* this function closes the opener window when requested */
if (typeof(closeOpener) != "string")	{var closeOpener = 0;}
if ((closeOpener == 1) && (opener))	{
	if (opener.history.length > 1) {
	    opener.history.go(1-opener.history.length);
	    setTimeout('opener.close()',1000);
	}
else
   opener.close();
}

  

// open link in opener
function openinopener(url)
{
  if (window.opener)
  {
     window.opener.document.location.href = url;
  }
  else
  {
     open(url, "_blank");
  }
  self.close();
}


function trimString(string,len)	{
	 if (string.length > len)
	    {
	     string = string.slice(0, (len-2));
    	 string += "..";
	  	}
		document.write(string);
	}



if (noRclick == 1)	{
	var message="Function Disabled!";
	///////////////////////////////////
	function clickIE() {if (document.all) {alert(message);return false;}}
	function clickNS(e) {if 
	(document.layers||(document.getElementById&&!document.all)) {
	if (e.which==2||e.which==3) {alert(message);return false;}}}
	if (document.layers) 
		{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
	else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
	
	document.oncontextmenu=new Function("return false")
}	





function getbrowserwidth()    {
    	if (navigator.userAgent.indexOf("MSIE") > 0)
	       	{return(document.body.clientWidth);}
        else
            {return window.outerWidth;}
        }
function getbrowserheight()	{
 if (navigator.userAgent.indexOf("MSIE") > 0)
     	{return(document.body.clientHeight);} 
     else
		 {return(window.outerHeight);}
     }

function CenterPopup()	{
	var ww = screen.availWidth;
	var wh = screen.availHeight;

  	var X = (ww-getbrowserwidth()) / 2
  	var Y = (wh-getbrowserheight()) / 2
	window.moveTo(X,Y)
    }
	
// function moveDiv 
function moveDiv (id, x, y) {

   if (document.layers) {
     document.layers[id].left = x;
     document.layers[id].top = y;
   }
   else if (document.all) {
	  obj = document.all[id].style;
	  obj.xpos = parseInt(obj.left) + parseInt(x);
	  obj.ypos = parseInt(obj.top) + parseInt(y);
	  obj.left = obj.xpos;
	  obj.top = obj.ypos;
   }
   else if (document.getElementById) {
     document.getElementById(id).style.left = x + 'px';
     document.getElementById(id).style.top = y + 'px';
   } 
   
}


/**
 * Ween... What's the freaking point of this!!
 */

function drawScript(which)	{
    document.write('<script language="javaScript" type="text/javascript" src="' + documentRoot + 'js/'+which+'.js"><\/script>')
}


