function setUrlWithParams(url, paramArray, valueArray, theWindow) {
	if ( $type(theWindow) != 'object' || !$type(theWindow.location) ) {
		theWindow = self;
	}
	
	var newUrl = buildUrlWithParams(url, paramArray, valueArray);
	theWindow.location.href=newUrl;
	return false;
}

function setUrlWithParam(url, param, value, theWindow) {
	setUrlWithParams(url, new Array(param), new Array(value), theWindow);
}

function buildUrlWithParams(url, paramArray, valueArray) {
	var newUrl = url;
	var oldUrl;
	for (i=0; i<paramArray.length; i++) {
		oldUrl = newUrl;
	    var param = paramArray[i];
	    var value = valueArray[i];
	    
		var idxOfParam = oldUrl.indexOf(param+'=');
		if ( idxOfParam > 0 ) {
			newUrl = oldUrl.substring(0,idxOfParam) + param + '=' + value;
			var idxOfNext = oldUrl.indexOf('&',idxOfParam);
			if ( idxOfNext > 0 ) {
				newUrl += oldUrl.substring(idxOfNext); 
			}			
		} 
		else {
			var idxOfQM = oldUrl.indexOf("?");
			if ( idxOfQM > 0 ) {
				newUrl = oldUrl + "&" + param + "=" + value;
			} else {
				newUrl = oldUrl + "?" + param + "=" + value;
			}
		}
	}
	return newUrl;
}

var selectMode=0;

function selectAllOrNone(form, checkBoxFieldName)
{
  if (document.getElementsByName)
    var checkBoxField = document.getElementsByName(checkBoxFieldName);
  else
    var checkBoxField = form.elements[checkBoxFieldName];
  
  if ( !checkBoxField ) return;
  var length = checkBoxField.length;
  
  // 1 CheckBox
  if ( !length || length == 0)
  {
    if (selectMode == 0)
    {
      checkBoxField.checked=true;
      selectMode=1;
    }
    else
    {
      checkBoxField.checked=false;
      selectMode=0;
    }
  }
  else // mehrere
  {
    if (selectMode == 0)
    {
      selectMode=1;
      for (i=0; i<length; i++)
        checkBoxField[i].checked=true;
    }
    else
    {
      selectMode=0;
      for (i=0; i<length; i++)
        checkBoxField[i].checked=false;
    }
  }
}

function anyChecked(form,checkBoxFieldName)
{
  if (document.getElementsByName)
    var checkBoxField = document.getElementsByName(checkBoxFieldName);
  else
    var checkBoxField = form.elements[checkBoxFieldName];
      
  if ( !checkBoxField )
    return false;
    
  if ( !checkBoxField.length )
  {
    return checkBoxField.checked;
  }
  else
  {
    var noneChecked=true;
    for (i=0; i<checkBoxField.length; i++)
    {
      if (checkBoxField[i].checked)
      {
        noneChecked=false;
        break;
      }
    }
  }
  
  return !noneChecked;
}

/* START OF JAVASCRIPT CONTROLS */
/*
USAGE OF ACTIVATExy AND CHECKPLAYER FOR PLAYER CONTROLS

To use these javascript-controls, mootools.js and system.js have to be included before this file.

Buttons should be declared as follows:

<a id="frew" class="frew" href="javascript:void(0)" onclick="system.player_freverse()" >
	<img src="http://pic.tv1.de/media/iptv/visitberlintv/sp.gif" alt="" title="" width="30" height="24" border="0" />
</a>
The important things are "id", "class" and the transparent .gif file. 
Rollovers and pressed-states are shown via background-images and class-changes.

Also important for this to work is the correct css-declaration, 
mostily display:inline; for the transparent gif's and display: block; for the links:
#controls img { margin:0px; padding:0px; display:inline; }
#controls a { display: block; float: left;}
 

To start background-monitoring of correct states define handler like this: 


statusHandler = new WACTimerEvalHandler('playerStatus', 100, window, 'checkPlayer("play", "ffwd", "frew", "mute", "_active", "_hover", "pause", "play")');
if (system.timer && statusHandler)
	system.timer.registerHandler(statusHandler);


Parameters are in the following order:
- id for play/pause button
- id for fast forward button
- id for fast rewind button
- id for mute button
- extension for file showing active graphic
- extension for file showing hover graphic
- css-class name for pause
- css-class name for play

Activate rollovers und pressed-states: (onmouseover, onmouseout,...  will be added to buttons)
parameters are
- id for button
- extension for file showing active graphic
- extension for file showing hover graphic
- css-class name for pause (only for activatePlay)
- css-class name for play (only for activatePlay)


activateFast(		'frew', 	'_active', '_hover');
activatePlay(		'play', 	'_active', '_hover', 'play', 'pause');
activateMuteFfwd(	'ffwd', 	'_active', '_hover');
activateVolFull(	'voldec', 	'_active', '_hover');
activateVolFull(	'volinc', 	'_active', '_hover');
activateMuteFfwd(	'mute', 	'_active', '_hover');
activateVolFull(	'full', 	'_active', '_hover');
activateUpDown(		'up', 		'_active', '_hover');
activateUpDown(		'down',		'_active', '_hover');



USAGE OF ROLL AND ROLLOVER FOR CATEGORIES/TABS/ETC.

functions roll and rollout may also be used for categories, tabs, etc. as follows:

<td id="main_help" class="main" onmouseover="$('main_help').toggleClass('hovermain');" onmouseout="$('main_help').toggleClass('hovermain')">
	<a href="javascript:void(0)" onclick="window.open('<macro:out ref="helpLink" />','help','width=500,height=500,resizable=yes,scrollbars=yes')">
		<macro:if locale="de">Hilfe<macro:else />Help</macro:if>
	</a>
</td>

With categories and tabs, an added css.class for active state has to be defined, to show the pressed/active-state. 
Rollover will then override the active-background with rollover-background. 

Define category classes something like this (notice "height" in .tab):
td.tab { height:24px; background:url(http://pic.tv1.de/media/iptv/visitberlintv/programm/programmbuttons_bg.jpg) repeat-x; }
td.activetab { background:url(http://pic.tv1.de/media/iptv/visitberlintv/programm/programmbuttons_bg_active.jpg) repeat-x; }
td.hovertab { background:url(http://pic.tv1.de/media/iptv/visitberlintv/programm/programmbuttons_bg_hover.jpg) repeat-x; }

*/

function roll(elementId, activeExt, hoverExt) {
	var oldClassName, newClassName, activeStr, hoverStr;
	oldClassName = $(elementId).className;
	activeRegExp = new RegExp(activeExt); 
	hoverRegExp = new RegExp(hoverExt);
	if (!activeRegExp.test(oldClassName) && !hoverRegExp.test(oldClassName)) {
		newClassName = oldClassName + hoverExt;
	} else {
		return false;
	}
	$(elementId).className=newClassName;
}

function rollout(elementId, hoverExt) {
	var oldClassName, newClassName, hoverStr;
	oldClassName = $(elementId).className;
	hoverRegExp = new RegExp(hoverExt); 
	if(hoverRegExp.test(oldClassName)) {
		newClassName = oldClassName.replace(hoverRegExp,"");
	} else {
		return false;
	}
	$(elementId).className=newClassName;
}

function pressed(elementId, onoff, activeExt) {
  var oldClassName, newClassName, activeStr;
  oldClassName = $(elementId).className;
  activeRegExp = new RegExp(activeExt);
  if(onoff && !activeRegExp.test(oldClassName))
  {
    newClassName = oldClassName + activeExt;
    $(elementId).className = newClassName;
  }
  else if(!onoff && activeRegExp.test(oldClassName))
  {
    newClassName = oldClassName.replace(activeRegExp, "");
    $(elementId).className = newClassName;
  }
}

function togglePlayPause(elementId, playClassName, pauseClassName) {
	var oldClassName, newClassName, playClassStr, pauseClassStr;
	oldClassName = $(elementId).className;
	playClassRegExp = new RegExp(playClassName);
	pauseClassRegExp = new RegExp(pauseClassName);
	if(playClassRegExp.test(oldClassName)) {
		newClassName = oldClassName.replace(playClassRegExp, pauseClassName);
	}
	if(pauseClassRegExp.test(oldClassName)){
		newClassName = oldClassName.replace(pauseClassRegExp, playClassName);
	}
	$(elementId).className=newClassName;
}

function showPause(elementId, hoverExt, pauseClassName){
	var oldClassName = $(elementId).className;
	var hoverStr, pauseClassStr;
	hoverRegExp = new RegExp(hoverExt);
	pauseClassRegExp = new RegExp(pauseClassName);
	if (!hoverRegExp.test(oldClassName) && !pauseClassRegExp.test(oldClassName) ) {
		$(elementId).className = pauseClassName;
	}
}

function showPlay(elementId, hoverExt, playClassName){
	var oldClassName = $(elementId).className;
	var hoverStr, playClassStr;
	hoverRegExp = new RegExp(hoverExt);
	playClassRegExp = new RegExp(playClassName);
	if (!hoverRegExp.test(oldClassName) && !playClassRegExp.test(oldClassName) ) {
 		$(elementId).className = playClassName;
	}
}

function checkPlayer(playId, ffwdId, frewId, muteId, activeExt, hoverExt, pauseClassName, playClassName){
	if(!system.playerConfig.jsControls){
		return;
	}
	if ( !system.fastPlay && !system.fastRev ) {
		if(system.player != null && system.player != undefined && system.player.isPlaying()){
			showPause(playId, hoverExt, pauseClassName);
		} else {
			showPlay(playId, hoverExt, playClassName);
		}
	}
	if(system.fastPlay){
		pressed(ffwdId,true, activeExt);
	} else {
		pressed(ffwdId,false, activeExt);
	}
	if(system.fastRev){
		pressed(frewId, true, activeExt);
	} else {
		pressed(frewId, false, activeExt);
	}
	if(!system.isSoundOn){
		pressed(muteId, true, activeExt);
	} else {
		pressed(muteId, false, activeExt);
	}
}

function activateFast(elementId, activeExt, hoverExt){
	activateFrew(elementId, activeExt, hoverExt);
}
function activatePlay(elementId, activeExt, hoverExt, playClassName, pauseClassName){
	if(elementId != undefined && $(elementId) != undefined){
		if($(elementId).hasClass(playClassName)){
			togglePlayPause(elementId, playClassName, pauseClassName);
		}
		$(elementId).onmouseover=function(){roll(elementId, activeExt, hoverExt);};
		$(elementId).onmouseout=function(){rollout(elementId, hoverExt);};
		$(elementId).onblur=function(){rollout(elementId, hoverExt);};
		$(elementId).onfocus=function(){roll(elementId, activeExt, hoverExt);};
		$(elementId).onmousedown=function(){pressed(elementId,true, activeExt);};
		$(elementId).onmouseup=function(){pressed(elementId,false, activeExt);
		togglePlayPause(elementId, playClassName, pauseClassName);};
		
	}
}
function activateMuteFfwd(elementId, activeExt, hoverExt){
	if(elementId != undefined && $(elementId) != undefined){
		if (/mute/.test(elementId)) {
			$(elementId).onmouseover=function(){roll(elementId, activeExt, hoverExt);};
			$(elementId).onmouseout=function(){rollout(elementId, hoverExt);};
			$(elementId).onblur=function(){rollout(elementId, hoverExt);};
			$(elementId).onfocus=function(){roll(elementId, activeExt, hoverExt);};
		} else {
			activateFfwd(elementId, activeExt, hoverExt);
		}
	}
}
function activateVolFull(elementId, activeExt, hoverExt){
	if(elementId != undefined && $(elementId) != undefined){
		$(elementId).onmouseover=function(){roll(elementId, activeExt, hoverExt);};
		$(elementId).onmouseout=function(){rollout(elementId, hoverExt);};
		$(elementId).onblur=function(){pressed(elementId, false, activeExt); rollout(elementId, hoverExt);};
		$(elementId).onfocus=function(){roll(elementId, activeExt, hoverExt);};
		$(elementId).onmousedown=function(){pressed(elementId, true, activeExt);};
		$(elementId).onmouseup=function(){pressed(elementId, false, activeExt); };
	}
}

function activateUpDown(elementName, activeExt, hoverExt){
	if(elementName != undefined && $(elementName) != undefined){
		$(elementName).onmouseover=function(){roll(elementName, activeExt, hoverExt);};
		$(elementName).onmouseout=function(){rollout(elementName, hoverExt);};
		$(elementName).onblur=function(){pressed(elementName,false, activeExt); rollout(elementName, hoverExt);};
		$(elementName).onfocus=function(){roll(elementName, activeExt, hoverExt);};
		$(elementName).onmousedown=function(){pressed(elementName,true, activeExt);};
		$(elementName).onmouseup=function(){pressed(elementName,false, activeExt);};
	}
}
/* new ffwd / frwd */
function activateFrew(elementId, activeExt, hoverExt){
	if(elementId != undefined && $(elementId) != undefined){
		$(elementId).onmouseover=function(){ roll(elementId, activeExt, hoverExt);
		};
		$(elementId).onmouseout=function(){  rollout(elementId, hoverExt);
			if ($defined(system.player)) system.player.stopFastReverse();
		};
		$(elementId).onblur=function(){      rollout(elementId, hoverExt);
			system.fastRev = false;// pressed(elementId, false, activeExt);
		};
		$(elementId).onfocus=function(){     roll(elementId, activeExt, hoverExt);};
		$(elementId).onmousedown=function(){ 
			system.fastRev = true;// pressed(elementId, true, activeExt);
			if ($defined(system.player)) system.player.fastReverse();};
		$(elementId).onmouseup=function(){
			system.fastRev = false;// pressed(elementId, false, activeExt);
			if ($defined(system.player)) system.player.stopFastReverse();};
	}
}
function activateFfwd(elementId, activeExt, hoverExt){
	if(elementId != undefined && $(elementId) != undefined){
		$(elementId).onmouseover=function(){ roll(elementId, activeExt, hoverExt);
		};
		$(elementId).onmouseout=function(){  rollout(elementId, hoverExt);
			if ($defined(system.player)) system.player.stopFastForward();};
		$(elementId).onblur=function(){      rollout(elementId, hoverExt);
			system.fastPlay = false;// pressed(elementId, false, activeExt);
		};
		$(elementId).onfocus=function(){     roll(elementId, activeExt, hoverExt);
		};
		$(elementId).onmousedown=function(){
			system.fastPlay = true;// pressed(elementId, true, activeExt);
			if ($defined(system.player)) system.player.fastForward();};
		$(elementId).onmouseup=function(){
			system.fastPlay = false;// pressed(elementId, false, activeExt);
			if ($defined(system.player)) system.player.stopFastForward();};
	}
}
/* END OF JAVASCRIPT CONTROLS */

var resizeWindow = function(w,h) {
	if ( w == null || w < 0 ) w = 600;
	if ( h == null || h < 0 ) h = 460;
	if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
		var diffW = w - parseInt(document.documentElement.clientWidth);
		var diffH = h - parseInt(document.documentElement.clientHeight);
		if (diffW != 0 || diffH != 0) {
			window.resizeBy(diffW,diffH);
			window.scrollTo(0,0);
		} 
	} else if (window.innerHeight) {
		window.innerHeight = h;
		window.innerWidth  = w;
		window.scrollTo(0,0);
	} else if (document.body && document.body.clientHeight && document.body.clientWidth) {
		var diffW = w - parseInt(document.body.clientWidth);
		var diffH = h - parseInt(document.body.clientHeight);
		if (diffW != 0 || diffH != 0) {
			window.resizeBy(diffW,diffH);
			window.scrollTo(0,0);
		}
	} else {	
	}
}

var ping = function(elementId, timeout, url) {
	if (timeout == undefined ) {
		timeout = 300000;
	}
	if (url == undefined ) {
		url = "/iptv/admin/home";
	}
	if(elementId != undefined && $(elementId) != undefined){
		var ajx = new Ajax(url, {method:'get', update: $(elementId)}).request();
		window.setTimeout('ping("'+elementId+'",'+timeout+',"'+url+'")',timeout);
	}
};