//  
//  Copyright (C) 1998,1999 TechnoTrend Systemtechnik GmbH
//	              2000,2001 TechnoTrend AG

// $Logfile: /DVB-PC/BIN/Base/HTML/TTDVBscript.js $
// $Revision: 9 $
// $Modtime: 21.12.04 11:21 $

// Globals

var ARGUS_S = '*';
var ARGUS_A = '*';

var AllowVideoControl = false;

var prgIndex = 0xFFFF;
var prgalpha = '*';
var bHostStarted = 0;
var Flg_Index = '01';
var bCAena = false;
var glbFEtype = 1;

var bRecordActive = false;
var gFreeMem = 0;

var glbb;
var glbMatrixFlag = false;

var glbFilter	= 0x00;

var glbCurProgNum = 0;
var glbHlpCurNumber = false;
var prgLastIndex = 0xFFFF;

var bMute = false;
var bPIvisible = true;
var ScrollPos = 0;

var bTvPic = false;
var m_bSubPic = false;
var m_bMHPPic = false;
var m_iCiStatus = 0;
var bSleepTimerPic = false;
var m_iAudioMode = 2;

var glbIsPause = false;

window.onresize=resizeWindow;
document.onmousedown=dragLayer;
document.onmouseup=new Function("dragMe=false");

function resizeWindow()
{
	ResizeView(false);
}

function LogoOn(logoname)
{
	document.all.ToolBarHorz.style.paddingLeft = 1;
	document.all.ToolBarHorz.style.paddingTop = 1;

	var lg='<img src=\"pic\\' + logoname + '\"></img>';
	document.all.ToolBarHorz.innerHTML = lg;
}

function LogoVideoOn(logoname)
{

//	var lg='<img src=\"pic\\' + logoname + '\" width=100% height=100%></img>';
	var lg='<table id=MYMYTABLE_ID style=\"background-image:url(pic\\' + logoname + '); background-repeat:no-repeat; background-position:50% 50%; background-color:rgb(0,0,12);\" width=100% height=100%><tr><td>&nbsp;</td></tr></table>';

	document.all.VideoFrame.innerHTML = lg;

}

function ChanceBackgroundPic(logoname)
{
	document.all.MYMYTABLE_ID.style.backgroundImage = "url(pic\\" + logoname + ")";
}

function EnableCAprogs(ena)
{
	bCAena = ena == 1 ? true : false;
}

function SetCountryFlag(flgnum)
{
//###	Flg_Index = flgnum;
//###	SetImageFlag(document.all.Cmd5);
}

function SetImageFlag(elem)
{
//###	elem.src = 'pic\\flg_' + Flg_Index + '.gif';
}

function SetImageFlag_a(elem)
{
//###	elem.src = 'pic\\flg_' + Flg_Index + '_a.gif';
}

function ExecHostCommand(hostcmd)
{
	document.body.style.cursor = 'wait';
	if(bHostStarted == 1)
		window.navigate(hostcmd);
	else
		window.status = hostcmd;
	document.body.style.cursor = 'auto';
}

function ExecHostCommand2(hostcmd)
{
	document.body.style.cursor = 'wait';
	if(AllowVideoControl == true)
	{
		if(bHostStarted == 1)
			window.navigate('tdcmd:' + hostcmd);
		else
			window.status = 'tdcmd:' + hostcmd;
	}
	document.body.style.cursor = 'auto';
}

var bScroll = false;
var sFirstLetters;
var ncGesamt = '';

function prgRemoveAll()
{
	sFirstLetters = '';
	ncGesamt = '';
}

var glbItemCnt;

function Mw(a,b,itemCnt)
{
	glbb = b;
	glbItemCnt = itemCnt;

	if( (a < 3) && ((glbFilter & 0x02) == 0x00) )
	{
		a = 1;
		if( sFirstLetters.length == 1 )
		{
			if( document.all.CE.className == "cF" )
			{
				a = 0;
			}
		}
		else
		{
			if( document.all.CE[itemCnt].className == "cF" )
			{
				a = 0;
			}
		}
	}
	if(a == 1)
	{
		ExecHostCommand('tdmed:' + glbFilter + ',0,' + b);
	}
	else if(a == 0)
	{
		ExecHostCommand('tdmed:' + glbFilter + ',1,' + b);
	}
	else if(a == 3)
	{
		if( (glbFilter & 0x04) == 0x00 )
			ExecHostCommand('tdmed:' + glbFilter + ',3,' + b);
	}
}

function ChangeSatellite(obj)
{
	ARGUS_S = obj.value;

	if( (glbFilter >> 2) == 1)
	{
		HideMatrix();
		ResetButtons();
	}
	else
	{
		document.all.DynList.style.display = "none";
		document.body.style.cursor = "wait";
	}
	
	setTimeout('GetProgList()',200);

	if( (glbFilter >> 2) == 0 )
	{
		document.all.DynList.style.display = 'inline';
		document.body.style.cursor = 'auto';
		document.all.DynList.focus();
	}
}

function prgArgusAlpha()
{
	prgalpha = ARGUS_A;
	
	ScrollToLetter(prgalpha);
	document.all.DynList.focus();
}


function prgResetSat()
{
	var imx=document.all.Fltalpha0.options.length;
	var i;
	for (i=imx; i > 0; i--)
	{
		document.all.Fltalpha0.options.remove(i);
	}
}

function prgInitFilter(b)
{
	document.all.Fltalpha0.value = b;
	ARGUS_S = b;
}

function prgAddSatellite(a,b)
{
	var oOption = document.createElement("OPTION"); 
	oOption.text=a; oOption.value=b; 
	document.all.Fltalpha0.add(oOption); 
}

function prgOneSatellite(bOneSat, sSatName)
{
	if(bOneSat == true)
	{
		document.all.Fltalpha0.style.visibility = "hidden";
		document.all.OneSatDisplay.innerHTML = "<nobr>" + sSatName + "</nobr>";
		document.all.OneSatDisplay.style.display = "inline";
	}
	else
	{
		document.all.OneSatDisplay.style.display = "none";
		document.all.Fltalpha0.style.visibility = "visible";
	}
}

var PID = new Array();
var TXT = new Array();
var numPIDs = 0;
var glbAPID = 0;

function prgAddAudio()
{
	var oOption;
	var i;

	if(numPIDs == 1)
	{
		document.all.DisplayAudio.innerHTML = "<span class=\"cssInfoAudio\"><nobr>" + TXT[0] + "</nobr></span>";
	}
	else if(numPIDs > 1)
	{
		document.all.DisplayAudio.innerHTML = "<select id=\"selAudioListbox\" class=\"cssDivBtn\" tabindex=3 onchange=\"ChangeAudio(this);\" style=\"width:113px;\"></select>";

		for( i = 0; i < numPIDs; i++ )
		{
			oOption = document.createElement("OPTION"); 
			oOption.text = TXT[i];
			oOption.value = PID[i];
			document.all.selAudioListbox.add(oOption);
			if(glbAPID == oOption.value)
				oOption.selected = true;
		}
	}
	else
	{
		document.all.DisplayAudio.innerHTML = "";
	}
}

function ChangeAudio(obj)
{
	glbHlpCurNumber = true;
	ExecHostCommand('tdaud:' + obj.value);
}

function GetProgList()
{
	prgLastIndex = 0xFFFF;
	document.all.ButtonLastProg.style.display = "none";
	document.all.ButtonPrevProg.style.display = "none";
	document.all.ButtonNextProg.style.display = "none";

	ExecHostCommand('tdflt:' + glbFilter + ',' + ARGUS_S);

	if ( !(glbFilter & 0x04) )
	{
		if( (glbFilter & 0x02) == 0x02 )
			prgCurProgNum();
		document.all.DynList.scrollTop = ScrollPos;
	}
}

function OnButtonNextProg()
{
	glbHlpCurNumber = true;
	if(++glbCurProgNum >= document.all.CE.length)
		glbCurProgNum = 0;
	document.all.CE[glbCurProgNum].click();

}

function OnButtonPrevProg()
{
	glbHlpCurNumber = true;
	--glbCurProgNum;
	if(glbCurProgNum < 0 || glbCurProgNum >= document.all.CE.length)
		glbCurProgNum = document.all.CE.length - 1;
	document.all.CE[glbCurProgNum].click();
}

function OnButtonLastProg()
{
	ExecHostCommand('tdtun:' + prgLastIndex);
}

function OnScrollList()
{
	if(sFirstLetters.length < 1)
		return;
	if(bScroll && document.all.CE.length > 0)	
		document.all.Fltalpha1.value = ' ';

	ScrollPos = document.all.DynList.scrollTop;
	bScroll = true;
}

function ScrollToLetter(a)
{
	var i;
	if(sFirstLetters.length < 1)
		return;
	var imax = document.all.CE.length;

	a = a.toLowerCase();
	bScroll = false;

	if(((a == '*') || (a == ' ')) && imax > 0)
	{
		document.all.DynList.scrollTop = 0;
		bScroll = false;
		return;
	}
	bScroll = false;

	for(var i=0;i < imax;i++)
	{
		if(sFirstLetters.substr(i,1) >= a )
		{
			document.all.DynList.scrollTop =
			document.all.CB[i].offsetTop;
			break;
		}
	}
	bScroll = false;
}



function prgDisplayListAdd(nc)
{
	ncGesamt += nc;
}

function prgDisplayListFinal(nc,sFL)
{
	document.all.DynList.innerHTML = ncGesamt + nc;
	sFirstLetters = sFL;
	ncGesamt = '';
	ARGUS_A = '*';
	document.all.Fltalpha1.value = '*';
	prgalpha = ARGUS_A;
	ScrollToLetter(prgalpha);
	document.all.MainWnd.style.visibility = 'visible';
}

var glbIxHTML = 0xFFFF;

function prgIxHTML(ixHTML,bGetList)
{	
	if( (glbIxHTML != ixHTML) || (bGetList == 1) )
	{
		if( document.all.CB )
		{
			if(document.all.CB.length > 1)
			{
				document.all.ButtonPrevProg.style.display = "inline";
				document.all.ButtonNextProg.style.display = "inline";

				if( document.all.CB[ixHTML].ix == prgIndex )
				{
					glbCurProgNum = glbIxHTML = ixHTML;
					glbHlpCurNumber = false;
				}
			}
			else if(document.all.CB.length > 0)
			{
				if( document.all.CB.ix == prgIndex )
				{
					glbCurProgNum = glbIxHTML = ixHTML;
					glbHlpCurNumber = false;
				}
			}
		}
	}
}

function prgSetProgram(prname,ix,cnt)
{
	document.all.PrgName.innerHTML = prname;

	if( ix != prgIndex )
	{
		prgLastIndex = prgIndex;
		if(document.all.ButtonPrevProg.style.display != "none")
			document.all.ButtonLastProg.style.display = "inline";
	}
	prgIndex = ix;

	if( !(glbFilter & 0x04) )
	{
		if( (glbFilter & 0x02) )
		{
			if(glbHlpCurNumber == false)
				prgCurProgNum();
			else							
				glbHlpCurNumber = false;
		}
	}
}

function prgCurProgNum()
{
	if( document.all.CB )	
	{
		if( document.all.CB.length > 1 )
		{
			document.all.ButtonPrevProg.style.display = "inline";
			document.all.ButtonNextProg.style.display = "inline";

			for( var i = 0; i < document.all.CB.length; i++ )
			{
				if( document.all.CB[i].ix == prgIndex )
				{
					glbCurProgNum = i;
					break;
				}
			}
		}
		else if( document.all.CB.length > 0 )
		{
			glbCurProgNum = 0;
		}
	}

}

function prgNextProg()
{
	if( document.all.next.style.display != "none" )
	{
		SwitchNext();
	}
	else
	{
		if( document.all.ButtonNextProg.style.display != "none" )
		{
			OnButtonNextProg();
		}
		else if(sFirstLetters.length > 1)
		{
			document.all.CE[0].click();
		}
		else if(sFirstLetters.length > 0)
		{
			document.all.CE.click();
		}
	}
}

function prgPrevProg()
{
	if( document.all.back.style.display != "none" )
	{
		SwitchBack();
	}
	else
	{
		if( document.all.ButtonPrevProg.style.display != "none" )
		{
			OnButtonPrevProg();
		}
		else if(sFirstLetters.length > 1)
		{
			document.all.CE[0].click();
		}
		else if(sFirstLetters.length > 0)
		{
			document.all.CE.click();
		}
	}
}

function prgLastProg()
{
	if( document.all.ButtonLastProg.style.display != "none" )
	{
		OnButtonLastProg();
	}
	else if( document.all.last.style.display != "none" )
	{
		SwitchLast();
	}
}

function VolumeMute()
{
	SetMuteState();
	SetImageMute(document.images["MuteBox"]);
}

function StartStopRecord()
{
	if( document.all.BtnRecordImg.style.visibility != 'hidden' )
	{
		ExecHostCommand('tdcmd:999');
		SetImageRec(document.all.BtnRecordImg);
	}
}
				
function InitToolTips()
{
	//if(glbFEtype > 1)
	document.all.Cmd1.title = document.all.Cmd1c.title;

	if(bRecordActive)
	{
		document.images["BtnRecordImg"].src = "pic\\r_qrec_c.gif";
		document.images["BtnRecordImg"].title = document.all.DummyStopRec.title;
	}
	else
	{
		document.images["BtnRecordImg"].src = "pic\\r_qrec.gif";
		document.images["BtnRecordImg"].title = document.all.DummyStartRec.title;

		if(gFreeMem)
		{
			document.all.mem_gruen.title = gFreeMem + " MB " + document.all.DummyMemGruen.title;
		}
	}
}

function InitPage(fetype,mfg,brandname,nVol,nBal,bShowProgInfo,nNTSC)
{
	glbFEtype = fetype;
	switch (fetype)
	{	
		case 1:
//			document.all.FeType.innerHTML = 'DVB-S';
//			document.all.Fltalpha0.style.display = 'none';
			break;
		case 2:
//			document.all.Cmd2.style.visibility = 'hidden';
//			document.all.Fltalpha0.style.display = 'none';
//			document.all.FeType.innerHTML = 'DVB-C';
			break;
		case 3:
//			document.all.Cmd2.style.visibility = 'hidden';
//			document.all.Fltalpha0.style.display = 'none';
//			document.all.FeType.innerHTML = 'DVB-T';
			break;
		default: 	
			document.all.Cmd1.style.visibility = 'hidden';
			document.all.Cmd2.style.visibility = 'hidden';
			document.all.Cmd3.style.visibility = 'hidden';
			document.all.CaptionFS1.style.display = 'none';
			document.all.CaptionFS2.style.display = 'none';
//			document.all.Fltalpha0.style.display = 'none';
//			document.all.FeType.innerHTML = 'DVB-?';
			break;
	}

	document.all.sleeptime.innerHTML = "";
//S.H.??
document.all.Fltalpha0.style.display = 'none';

	document.all.MfgName.innerHTML = mfg;
	document.all.BrandName.innerHTML = brandname;
	
	bHostStarted = 1;

	InitProgInfo(bShowProgInfo);
}

function InitProgInfo(bShowProgInfo)
{
	/*
	if (bShowProgInfo == false)
	{
		ShowProgInfo(false);
	}
	else
	{
		ShowProgInfo(true);
		//SetImage(document.all.pi ,'pic\\p_info_c.gif');
	}
	*/
	ShowProgInfo(bShowProgInfo);
}

function RetrieveToolbars(nUI1)
{
	if(document.all.ProgInfo.style.pixelHeight == document.all.ProgInfo.myY1)
		nUI1 |= 0x01;

	//ExecHostCommand('tduif:' + nUI1);
}


function SetImage(elem,imgname)
{
	elem.src = imgname;
}

function SetImageRec(elem)
{
	if(bRecordActive)
	{
		if(glbIsPause)
			SetImage(elem,'pic\\r_qrec_c1.gif');
		else
			SetImage(elem,'pic\\r_qrec_c.gif');
	}
	else
	{
		SetImage(elem,'pic\\r_qrec.gif');
	}
}

function SetImagePause(elem)
{
	if(glbIsPause)
	{
		SetImage(elem,'pic\\r_qpause_c.gif');
	}
	else
	{
		SetImage(elem,'pic\\r_qpause.gif');
	}
}

function SetImageRec2(elem)
{
	if(bRecordActive)
		SetImage(elem,'pic\\r_qrec_d.gif');
	else
		SetImage(elem,'pic\\r_qrec_a.gif');
}

function SetImageMute(elem)
{
	if(bMute)
		SetImage(elem,'pic\\p_mute_c.gif');
	else
		SetImage(elem,'pic\\p_mute.gif');
}

function SetMuteState()
{
	bMute = !bMute;
}

function CheckX(el,xMax,nRand)
{
	var ns = document.body.clientWidth - el.style.pixelLeft - nRand;
	if(ns > xMax)
		ns = xMax;
	if(ns > 1)
		el.style.pixelWidth = ns;
}

function CheckY(el,yMax,nRand)
{
	var ns = document.body.clientHeight - el.style.pixelTop - nRand;
	if(ns > yMax)
		ns = yMax;
	if(ns > 1)
		el.style.pixelHeight = ns;
}

function ResizeView(bCenter)
{
	ResizeLeft();
	ResizeRight();

	CheckX(document.all.CaptionBar,1600,0);
	{
		var nW = document.all.CaptionBar.style.pixelWidth - 2;
		document.all.CaptionClose.style.pixelLeft = nW - 27;

		document.all.CaptionMaxi.style.pixelLeft = nW - 27 - 25;
		document.all.CaptionRestore.style.pixelLeft = nW - 27 - 25;
		document.all.CaptionMini.style.pixelLeft = nW - 27 - 25 - 25;

		document.all.CaptionOnTopOff.style.pixelLeft = nW - 27 - 25 - 25  - 25;
		document.all.CaptionOnTopOn.style.pixelLeft = nW - 27 - 25 - 25 - 25;

		document.all.CaptionFS2.style.pixelLeft = nW - 27 - 25 - 25 - 50;
		document.all.CaptionFS1.style.pixelLeft = nW - 27 - 25 - 25 - 50 - 25;

		document.all.PanScan.style.pixelLeft = nW - 27 - 25 - 25 - 50 - 25 - 25;
	}
	CheckX(document.all.VideoScreen,1600,3);
	CalcVideoPosition(bCenter);
	setTimeout("RefreshIt()", 10);
}


var nRatioX = 4;
var nRatioY = 3;
var nRATIO_EDGE = (10000 * 3) / 4;

function SetRatio(x,y)
{
	nRatioX = x;
	nRatioY = y;
	nRATIO_EDGE = (10000 * nRatioY) / nRatioX;
}

function CalcVideoPosition(bCenter)
{
	var elem;
	var nBorderX; 
	var nBorderY; 
	var vFrame = document.all.VideoFrame;

	elem = document.all.VideoScreen;
	nBorderX = 6;
	nBorderY = 6;

	var nLeft	= elem.style.pixelLeft		+ nBorderX
	var nTop	= elem.style.pixelTop		+ nBorderY;
	var nWidth	= elem.style.pixelWidth		- (nBorderX * 2);
	var nHeight	= elem.style.pixelHeight	- (nBorderY * 2);

	var nOrWidth = nWidth;
	var nOrHeight = nHeight;

	var nRatio = ((10000 * nHeight) / nWidth);

	if(nRatio < nRATIO_EDGE)
		nWidth = Math.round((nHeight * nRatioX) / nRatioY);
	else if(nRatio > nRATIO_EDGE)
		nHeight = Math.round((nWidth * nRatioY) / nRatioX);

	var nDiff = nOrWidth - nWidth;

	if(nDiff > 0)
		nLeft = Math.round(nLeft + (nDiff/2));

	nDiff = nOrHeight - 12 - nHeight;

	if(nDiff > 0)
		nTop = Math.round(nTop + (nDiff/2));

	var nAll;

	if(bCenter == true)
	{
		vFrame.style.pixelWidth = nWidth + 4;
		vFrame.style.pixelHeight = nHeight + 4;
		vFrame.style.pixelLeft = nLeft + 4;
		vFrame.style.pixelTop = nTop + 4;
		
		nAll = nLeft.toString() + ',' + nTop.toString() + ',' + nWidth.toString() + ',' + nHeight.toString();
	}
	else
	{
		nLeft = elem.style.pixelLeft + nBorderX;
		nTop = elem.style.pixelTop + nBorderY;

		vFrame.style.pixelWidth = nWidth + 4;
		vFrame.style.pixelHeight = nHeight + 4;
		vFrame.style.pixelLeft = nLeft;
		vFrame.style.pixelTop = nTop;

		nAll = nLeft.toString() + ',' + nTop.toString() + ',' + nWidth.toString() + ',' + nHeight.toString();
	}

	ExecHostCommand('tdpos:' + nAll);
}

function ShowProgInfo(show)
{
	if(show == true)
	{
		document.all.ProgInfo.style.pixelHeight = document.all.ProgInfo.myY2;
		document.all.ProgInfo.style.display = "inline";
	}
	else
	{
		document.all.ProgInfo.style.pixelHeight = document.all.ProgInfo.myY1;
		document.all.ProgInfo.style.display = "none";
	}
	bPIvisible = show;

	setTimeout("ResizeView(false)",10);
	RetrieveToolbars();
}

function Panel_OnOff(elemCAP,colix,bRetrieve)
{
	var elem, elemCNT;
	var elemID = elemCAP.id;
	elem = document.all(elemID);
	elemCNT = elem;

	if(elem.style.pixelHeight == elem.myY2)
	{
		elem.style.pixelHeight = elem.myY1;

		bPIvisible = false;
		//SetImage(document.all.pi, 'pic\\p_info.gif');

		elemCNT.style.display = 'none';
	}
	else
	{	
		bPIvisible = true;
		//SetImage(document.all.pi, 'pic\\p_info_c.gif');

		elem.style.pixelHeight = elem.myY2;
		elemCNT.style.display = 'inline';
	}

	if(colix == 2)
	{
		setTimeout("ResizeView(false)",10);
	}
	else if(colix == 1)
	{
		ResizeLeft();
	}
	if(bRetrieve) 
	   RetrieveToolbars();
}

function ResizeRight()
{
	var elems = new Array();
	var elcnt = 2;

	elems[0] = document.all.VideoScreen;
	elems[1] = document.all.ProgInfo;

	elems[0].style.pixelHeight = 
			  document.body.clientHeight 
			- 1
			- elems[1].style.pixelHeight 
			- elems[0].style.pixelTop;

	var cultop = elems[0].style.pixelTop;

	CheckX(document.all.ProgInfo,document.body.clientWidth - 244,0);

	for(var i=0; i < elcnt; i++)
	{
		elems[i].style.pixelTop = cultop;
		cultop += elems[i].style.pixelHeight-2;
	}
}

function ResizeLeft()
{
		var elems = new Array();
		var elcnt = 6;
		if(document.all.RecPlayView.style.display == 'none')
			elcnt--;

		elems[0] = document.all.ToolBarHorz;
		elems[1] = document.all.SysToolView;
		elems[2] = document.all.PreSel;
		elems[3] = document.all.DynListView;
		elems[4] = document.all.BelowList;
		elems[5] = document.all.RecPlayView;

		elems[3].style.pixelHeight = 
						  document.body.clientHeight - elems[0].style.pixelTop + 7
						- elems[0].style.pixelHeight 
						- elems[1].style.pixelHeight
						- elems[2].style.pixelHeight
						- elems[4].style.pixelHeight
						- elems[5].style.pixelHeight;
		if(document.all.RecPlayView.style.display == 'none')
			elems[3].style.pixelHeight += elems[5].style.pixelHeight -2;
		
		document.all.DynList.style.pixelHeight = 
						  document.all.DynListView.style.pixelHeight - 7;

		document.all.Matrix.style.pixelHeight = 
						  document.all.DynListView.style.pixelHeight - 7;

		var cultop = elems[0].style.pixelTop;

		for(var i=0; i < elcnt; i++)
		{
			elems[i].style.pixelTop = cultop;
			cultop += elems[i].style.pixelHeight-2;
		}
}

// Slider
var dragMe=false, Knobi,xPos, yPos,direction;

function IncrementSlider(slid,val)
{
	var a = document.all.item("SliderKnob");

	if (a!=null) 
	{
		if (a.length!=null) 
		{
			for (i=0; i < a.length; i++) 
			{
				if(slid == a(i).SliderID)
				{
					a(i).style.pixelLeft += val;
					if(a(i).style.pixelLeft > a(i).SliderMax)
						a(i).style.pixelLeft = a(i).SliderMax;
					if(a(i).style.pixelLeft < 0)
						a(i).style.pixelLeft = 0;
					OnSliderChange(slid,a(i).style.pixelLeft)
				}
			}
		} 
		else
		{ 
			if(slid == a.SliderID)
			{
				a.style.pixelLeft += val;
				if(a.style.pixelLeft > a.SliderMax)
					a.style.pixelLeft = a.SliderMax;
				if(a.style.pixelLeft < 0)
					a.style.pixelLeft = 0;
				OnSliderChange(slid,a.style.pixelLeft)
			}
		}
	}
}

function InitSlider(slid,val)
{
	var a = document.all.item("SliderKnob");

	if (a!=null) 
	{
		if (a.length!=null) 
		{
			for (i=0; i < a.length; i++) 
			{
				if(slid == a(i).SliderID)
				{
					a(i).style.pixelLeft = val;
					OnSliderChange(slid,val)
				}
			}
		} 
		else
		{ 
			if(slid == a.SliderID)
			{
				a.style.pixelLeft = val;
				OnSliderChange(slid,val)
			}
		}
	}
}

function OnSliderChange(a,b)
{
	ExecHostCommand(a + ':' + b);
	if(bMute)
	{
		bMute = false;
		SetImage(document.images["MuteBox"],'pic\\p_mute.gif');
	}
}

function moveLayer_V() 
{
	if (event.button==1 && dragMe) 
	{
		oldY = Knobi.style.pixelTop; 
		Knobi.style.pixelTop=temp2+event.clientY-yPos; 

		if (Knobi.style.pixelTop > oldY) 
			direction="dn"; 
		else 
			direction="up";
		if (Knobi.style.pixelTop < Knobi.SliderMin && direction=="up") 
		{
			Knobi.style.pixelTop=Knobi.SliderMin; 
			direction="dn";
		}
		if (Knobi.style.pixelTop > Knobi.SliderMax && direction=="dn") 
		{
			Knobi.style.pixelTop=Knobi.SliderMax; 
			direction="up";
		}
		sPosition=Knobi.style.pixelTop; 
		OnSliderChange(Knobi.SliderID,sPosition-Knobi.SliderMin);
		return false; 
	}
}

function moveLayer_H() 
{
	if (event.button==1 && dragMe) 
	{
		oldX = Knobi.style.pixelTop; 
		Knobi.style.pixelLeft=temp2_H+event.clientX-xPos; 

		if (Knobi.style.pixelLeft > oldX) 
			direction="rt"; 
		else 
			direction="lt";
		if (Knobi.style.pixelLeft < Knobi.SliderMin && direction=="lt") 
		{
			Knobi.style.pixelLeft=Knobi.SliderMin; 
			direction="rt";
		}
		if (Knobi.style.pixelLeft > Knobi.SliderMax && direction=="rt") 
		{
			Knobi.style.pixelLeft=Knobi.SliderMax; 
			direction="lt";
		}
		sPosition=Knobi.style.pixelLeft; 
		OnSliderChange(Knobi.SliderID,sPosition-Knobi.SliderMin);
		return false; 
	}
}

function dragLayer() 
{
	if (!document.all) 
		return;
	if (event.srcElement.className=="drag_V")	
	{
		dragMe=true; 
		Knobi=event.srcElement; 
		temp2=Knobi.style.pixelTop; 
		yPos=event.clientY; 
		document.onmousemove=moveLayer_V; 
	}
	if (event.srcElement.className=="drag_H")	
	{
		dragMe=true; 
		Knobi=event.srcElement; 
		temp2_H=Knobi.style.pixelLeft; 
		xPos=event.clientX; 
		document.onmousemove=moveLayer_H; 
	}
}
// End Slider 

function PrintEvent(nCurrNext,evtTime,evtName,evtText)
{
	if(nCurrNext == 0)
	{
		document.all.info_0_time.innerHTML = evtTime;
		document.all.info_0_name.innerHTML = evtName;
		document.all.info_0_text.innerHTML = evtText;
	}
	else
	{
		document.all.info_1_time.innerHTML = evtTime;
		document.all.info_1_name.innerHTML = evtName;
		document.all.info_1_text.innerHTML = evtText;
	}
}

function SetTitleAndText(elem,t1,t2)
{
	if(t1 !='')
		elem.title = t1;
	if(t2 !='')
		elem.innerHTML = t2;
}

function EnableVideoControls(enable, bShowPanScanAllways)
{
	//bShowPanScanAllways = TRUE --> Für Budget wird der 16:9 Button immer angezeigt

	if( enable == true )
	{
		document.all.CaptionFS1.style.display = "inline";
		document.all.CaptionFS2.style.display = "inline";
		document.all.PanScan.style.visibility = "visible";
//Dec_04	document.all.BtnTimeshiftImg.style.display = "inline";
	}
	else
	{
		document.all.CaptionFS1.style.display = "none";
		document.all.CaptionFS2.style.display = "none";
		
		if (bShowPanScanAllways == false)
			document.all.PanScan.style.visibility = "hidden";

//Dec_04	document.all.BtnTimeshiftImg.style.display = "none";
	}
	AllowVideoControl = enable;
}

function EnableVT(enable)
{
	if( enable == true )
		document.all.Cmd6.style.visibility = "visible";
	else
		document.all.Cmd6.style.visibility = "hidden";
}

function EnableCIDisplay(enable)
{
	if(enable == true)
		document.all.Cmd7.style.visibility = "visible";
	else
		document.all.Cmd7.style.visibility = "hidden";
}


function DisableRecordPlayBack()
{
	document.all.RecPlayView.style.display = "none";
}

function ShowButScan(show)
{
	if(show == true)
		document.all.PanScan.style.display = "inline";
	else
		document.all.PanScan.style.display = "none";
}

function SetTimeShift(bTimeShiftOnOff)
{
	if(bTimeShiftOnOff == true)
	{
		document.all.Cmd3.style.visibility = 'hidden';
		document.all.Cmd1.style.visibility = 'hidden';
		document.all.Cmd2.style.visibility = 'hidden';
		document.all.Cmd4.style.visibility = 'hidden';
		document.all.Cmd6.style.visibility = 'hidden';
		document.all.BtnTimeshift.style.visibility = 'hidden';
		document.all.BtnRecord.style.visibility = 'hidden';
		document.all.BtnPause.style.visibility = 'hidden';
		document.all.AudioMode.style.visibility = 'hidden';
		
	}
	else
	{
		document.all.Cmd3.style.visibility = 'visible';
		document.all.Cmd1.style.visibility = 'visible';
		document.all.Cmd2.style.visibility = 'visible';
		document.all.Cmd4.style.visibility = 'visible';
		document.all.Cmd6.style.visibility = 'visible';
		document.all.BtnTimeshift.style.visibility = 'visible';
		document.all.BtnRecord.style.visibility = 'visible';
		document.all.BtnPause.style.visibility = 'visible';
		document.all.AudioMode.style.visibility = 'visible';
	}
}

function SetRecordOnOff(bRA,sFileName,sFormat)
{
	bRecordActive = bRA;
	if(bRecordActive)
	{
		document.all.Cmd3.style.display = 'none';
		document.all.Cmd999.style.display = 'none';
		document.all.Cmd1.style.display = 'none';
		document.all.Cmd2.style.display = 'none';
		document.all.Cmd4.style.display = 'none';
		document.all.Cmd6.style.display = 'none';
		document.images["BtnRecordImg"].src = "pic\\r_qrec_c.gif";
		document.images["BtnRecordImg"].title = document.all.DummyStopRec.title;
////15.April_03 ##-- document.all.BtnTimeshiftImg.style.display = 'none';
		document.all.BtnPauseImg.style.display = 'inline';
		document.all.AudioMode.style.visibility = 'hidden';


		glbTimeCount = true;
		document.all.rectime.innerHTML = "00:00";
		document.all.recformat.innerHTML = sFormat;
		document.all.recformat.title = sFileName;
		document.all.rectime.title = document.all.TimeCountA1.text;
		setTimeout('TimeCount(glbTimeCount)',1000);

	}
	else
	{
		document.images["BtnRecordImg"].src = "pic\\r_qrec.gif";
		document.images["BtnRecordImg"].title = document.all.DummyStartRec.title;

		document.all.BtnPauseImg.style.display = 'none';
		//Dec_04 document.all.BtnTimeshiftImg.style.display = 'inline';
		document.images["BtnPauseImg"].src = "pic\\r_qpause.gif";
		document.images["BtnPauseImg"].title = document.all.DummyStartPause.title;
		glbIsPause = false;

		mem_startfree = 0;
		document.all.mem_gruen.title = "Free harddisk space";
		document.all.mem_rot.title="Size of file";

		document.all.Cmd3.style.display = 'inline';
		document.all.Cmd2.style.display = 'inline';
		document.all.Cmd1.style.display = 'inline';
		document.all.Cmd999.style.display = 'inline';
		document.all.Cmd4.style.display = 'inline';
		document.all.Cmd6.style.display = 'inline';
		document.all.AudioMode.style.visibility = 'visible';

		glbTimeCount = false;
		jump = false;
		TimeCount(false);
	}
}

function SetTimeShiftOff()
{
	glbIsPause = false;
	mem_startfree = 0;
	document.all.mem_gruen.title = "Free harddisk space";
	document.all.mem_rot.title="Size of file";
	glbTimeCount = false;
	jump = false;
	TimeCount(false);
}

function SetPause(bIsPause)
{
	if(!glbIsPause)
	{
		glbIsPause = true;
		document.images["BtnRecordImg"].src = "pic\\r_qrec_c1.gif";
		document.images["BtnPauseImg"].src = "pic\\r_qpause_c.gif";
		document.images["BtnPauseImg"].title = document.all.DummyEndPause.title;
	}
	else
	{
		glbIsPause = false;
		document.images["BtnRecordImg"].src = "pic\\r_qrec_c.gif";
		document.images["BtnPauseImg"].src = "pic\\r_qpause.gif";
		document.images["BtnPauseImg"].title = document.all.DummyStartPause.title;
	}
}

function StartTimeShift()
{
	if( (document.all.BtnTimeshiftImg.style.display != 'none')	&&
	(document.all.BtnTimeshiftImg.style.visibility != 'hidden') )
		ExecHostCommand('tdcmd:997');
}
 
var mem_startfree = 0;

function SetRecordMem_StartFree(freemem)
{
	mem_startfree = freemem;
	document.all.mem_gruen.title = freemem.toString;
}

function SetRecordMem_FileSize(actsize)
{
	var actfreemem;
	if (mem_startfree > 0)
	{
		actfreemem = mem_startfree - actsize;
		SetRecordMem_FreeAndSize(actfreemem, actsize);
	}
	else
	{
		document.all.mem_rot.style.pixelWidth = 0;
	}
}

function SetRecordMem_ActFree(actfreemem)
{
	var actsize;
	if (mem_startfree > 0)
	{
		actsize = mem_startfree - actfreemem;
		SetRecordMem_FreeAndSize(actfreemem, actsize);
	}
	else
	{
		document.all.mem_rot.style.pixelWidth = 0;
	}
}

function SetRecordMem_FreeAndSize(actfreemem, actsize)
{
	if (actfreemem > 0)
	{
		document.all.mem_rot.style.pixelWidth = Math.round(
		document.all.mem_gruen.style.pixelWidth / (actfreemem + actsize) * actsize);
		document.all.mem_gruen.title = actfreemem.toString() + " MB " + document.all.DummyMemGruen.title;
		document.all.mem_rot.title = actsize.toString() + " MB " + document.all.DummyMemRot.title;
	}
	else
	{
		document.all.mem_rot.style.pixelWidth = 0;
	}
	gFreeMem = actfreemem;
}

function KeyHandler_Down()
{
	var wKeyCode = event.keyCode;
	//alert("Keycode: " + wKeyCode);
	if (wKeyCode == 116)
	{
		event.returnValue=false;
		event.keyCode=0;
		return event.keyCode;
	}
	else if (wKeyCode == 16 || wKeyCode == 17 || wKeyCode == 78 || wKeyCode == 111)
	{
		event.returnValue=true;
		return event.keyCode;
	}
	else
	{	
		ExecHostCommand('keydn:' + wKeyCode);
		event.returnValue=false;
		event.keyCode=0;
		return event.keyCode;
	}
}

function StartMove()
{
	if(event.srcElement == document.all.CaptionBar || event.srcElement == document.all.CaptionText || event.srcElement == document.all.PrgName)
		ExecHostCommand('tdcmd:990'); 
}

function RefreshView()
{
	document.all.imgcmd_tb1.style.display = 'none';
	document.all.imgcmd_tb1.style.display = 'inline';
	SetImageRec(document.images['BtnRecordImg']);
	SetImagePause(document.images['BtnPauseImg']);

	document.all.CaptionBar.focus();//11.03.03 ##-- wegen Fehlermeldung 	
}

function RefreshIt()
{
	document.all.imgcmd_tb1.style.display = 'none';
	document.all.imgcmd_tb1.style.display = 'inline';
	document.all.Fltalpha0.style.display = 'none';
	document.all.Fltalpha0.style.display = 'inline';
	if(document.all.Fltalpha1.style.display != 'none')
	{
		document.all.Fltalpha1.style.display = 'none';
		document.all.Fltalpha1.style.display = 'inline';
	}
	document.all.DisplayAudio.style.display = 'none';
	document.all.DisplayAudio.style.display = 'inline';
	document.all.CaptionBar.focus();	
}

function SetCaption(szCaption)
{
	document.all.CaptionText.innerText = szCaption;
}

function WindowMaxi(IsMaxi)
{
	if(IsMaxi)
	{
		document.all.CaptionMaxi.style.visibility='hidden';
		document.all.CaptionRestore.style.visibility='visible';
	}
	else
	{
		document.all.CaptionMaxi.style.visibility='visible';
		document.all.CaptionRestore.style.visibility='hidden';
	}
}

function OnCaptionDblClick()
{
	if(document.all.CaptionMaxi.style.visibility == "visible" )
	{
		ExecHostCommand('tdcmd:202');
	}
	else
	{
		ExecHostCommand('tdcmd:203');
	}
	setTimeout("RefreshIt()", 10);
}

function WindowOnTop(IsOnTop)
{
	if(IsOnTop)
	{
		document.all.CaptionOnTopOn.style.visibility='hidden';
		document.all.CaptionOnTopOff.style.visibility='visible';
	}
	else
	{
		document.all.CaptionOnTopOff.style.visibility='hidden';
		document.all.CaptionOnTopOn.style.visibility='visible';
	}
}

function VolumeDown()
{
	IncrementSlider('tdvol',-1);
}

function VolumeUp()
{
	IncrementSlider('tdvol',1);
}

function VolumeDownDown()
{
	IncrementSlider('tdvol',-2);
}

function VolumeUpUp()
{
	IncrementSlider('tdvol',2);
}

function rpShowSomething(show, all)
{
	if(show == false)
	{
		document.all.Cmd3.style.display = 'none';
		document.all.Cmd999.style.display = 'none';
		document.all.Cmd1.style.display = 'none';
		document.all.Cmd2.style.display = 'none';
		document.all.CmdPZS.style.display = 'none';
		document.all.Cmd4.style.display = 'none';
		if(all)
		{
			document.all.BtnRecordImg.style.display = 'none';
			document.all.BtnTimeshiftImg.style.display = 'none';
			document.all.Cmd6.style.display = 'none';
		}
	}
	else
	{
		document.all.Cmd4.style.display = 'inline';
		document.all.Cmd6.style.display = 'inline';
		document.all.Cmd3.style.display = 'inline';
		document.all.Cmd999.style.display = 'inline';
		document.all.Cmd1.style.display = 'inline';
		document.all.Cmd2.style.display = 'inline';
		document.all.CmdPZS.style.display = 'inline';
		document.all.BtnRecordImg.style.display = 'inline';
		//Dec_04 document.all.BtnTimeshiftImg.style.display = 'inline';
	}
}

function ShowTVRadioList(param)
{
	var paramMem = (glbFilter & 0x01);

	if( (param != paramMem) )
	{
		OnButtonProgDisplay('A');
		OnMouseoutProgDisplay(document.images["but_tvrad"], 'A');
	}
	
	if( (glbFilter & 0x01) == paramMem )
	{
		if( (glbFilter & 0x02) == 0x00 )
		{
			OnButtonProgDisplay('F');
		}
		else if( (glbFilter & 0x04) == 0x00 )
		{
			OnButtonProgDisplay('M');
		}
		else
		{
			OnButtonProgDisplay('M');
			OnButtonProgDisplay('F');
		}
		
		OnMouseoutProgDisplay(document.all.but_favo, 'F');
		OnMouseoutProgDisplay(document.all.but_mat, 'M');
	}
}

function ShowTVFavoriteList()
{
	var paramMem = (glbFilter & 0x01);

	if( (paramMem != 0) )
	{
		OnButtonProgDisplay('A');
		OnMouseoutProgDisplay(document.images["but_tvrad"], 'A');
	}
	
	if( (glbFilter >> 2) == 1)
		HideMatrix();

	glbFilter = 0;
	glbMatrixFlag = false;
	OnButtonProgDisplay('F');

	OnMouseoutProgDisplay(document.all.but_favo, 'F');
	OnMouseoutProgDisplay(document.all.but_mat, 'M');

//	alert("Filter B:"+ glbFilter);

}

function remSetProgNr(index)
{
	if( ( (glbFilter & 0x04) == 0x04 )
		&& ( document.all.place[index].disabled == false ) )
	{
		SwitchProg(index);
	}
}


var NUM_BUTTONS = 100;
var bgColorFree = "";
var bgColorOcc = "#FF5533";
var bgColorCur = "#ffffff";
var textColorFree = "#000000";
var textColorOcc = "#ffffff";
var textColorCur = "#000000";
var bgColorCurOcc = "#ffffff";
var bgColorCurFree = "#ffffff";
var textColorCurOcc = "#000000";
var textColorCurFree = "#000000";
var bgColorTuned = "#ffff00";
var textColorTuned = "#000000";
var prgItemColorOcc = "#FFaa99";
var textColorCur = "#000000";

var glbIndex = 0xFFFF;
var glbLastIndexTuned = 0xFFFF;
var glbIndexTuned = 0xFFFF;
var glbCurProg = 0;
var contextInProgress = false;
var glbMode = 0;
var glbStoreBgColor;
var glbStoreTextColor;
var hlpvar = false;
var glbInfoText = "";
var glbCurProgName = "";
var NumOcc = 0;
var state = new Array(NUM_BUTTONS);

if(NUM_BUTTONS > 100) NUM_BUTTONS = 100;
for(var buti = 0; buti < NUM_BUTTONS; buti++)
{
	state[buti] = 0;
}

function MouseOverButton(index)
{
	if(contextInProgress == true)
		return;
	if(document.all.place[index].disabled == true)
		return;

	document.all.place[index].style.color = textColorCur ;

	if( state[index] > 0 )
	{
		document.all.ProgNameDisplay.innerHTML = "<b>" + index + "</b>&nbsp;&nbsp;<b><span style=\"color:#FFaa99;\">" + document.all.place[index].title + "</span></b>";
		document.all.place[index].style.backgroundColor = bgColorCurOcc;
	}
	else if( state[index] == 0 )
	{
		document.all.ProgNameDisplay.innerHTML = "<b>" + index + "</b>&nbsp;&nbsp;(" + document.all.ProgNameDisplayA1.text + ")";
		document.all.place[index].style.backgroundColor = bgColorCurFree;
	}
}

function MouseOutButton(index)
{
	var i, j;

	document.all.place[index].style.color = "";

	if(contextInProgress == false)
	{
		i = NUM_BUTTONS - 1;
		j = i - NumOcc;

		{
			document.all.ProgNameDisplay.innerHTML = "&nbsp;";
		}

		if( state[index] == 0 )
		{
			document.all.place[index].style.backgroundColor = bgColorFree;
			document.all.place[index].style.color = textColorFree;
		}
		else if( state[index] == 2 )
		{
			document.all.place[index].style.backgroundColor = bgColorTuned;
			document.all.place[index].style.color = textColorTuned;
		}
		else if( state[index] >= 1 )
		{
			document.all.place[index].style.backgroundColor = bgColorOcc;
			document.all.place[index].style.color = textColorOcc;
		}
	}
}

function UpdateProgList(LinkClass)
{
	if( sFirstLetters.length > 1 )
	{
		document.all.CE[glbItemCnt].className = LinkClass;
	}
	else if( sFirstLetters.length > 0 )
	{
		document.all.CE.className = LinkClass;
	}
}

function SaveProgAtButton(index)
{
	var ret = 0xFFFFFFFF;

	ret = index << 16;
	ret |= glbb;

	UpdateProgList('cF');
	ExecHostCommand('tdfon:' + ret);
	ShowMatrix(false);
}

function DeleteProgFromButton(index)
{
	ExecHostCommand('tdfof:' + document.all.place[index].name);
}

function DeleteAllProgs()
{
	ExecHostCommand('tdfoa:' + glbFilter);
	GetProgList();
}

function OnLeftMouseButton(index)
{
	if(contextInProgress == true)
		return;

	if(glbMode == 0)
	{
		if( state[index] > 0)
		{
			glbIndex = index;
			ShowConfirmStoreMenu(true,index);
		}
		else
			SaveProgAtButton(index);
	}
	else
	{
		SwitchProg(index);
	}
}

function OnRightMouseButton(index)
{
	if(contextInProgress == true)
		return;

	if( (state[index] > 0) && (glbMode == 0) )
	{
		glbIndex = index;
		ShowConfirmStoreMenu(true,index);
	}
}

function ConfirmStore(sel)
{
	var m, lastOcc;

	if(sel == 1)
	{
		DeleteProgFromButton(glbIndex);
		GetProgList();
		SaveProgAtButton(glbIndex);
	}
	else if(sel == 2)
	{	
		for( m = glbIndex + 1; m < NUM_BUTTONS; m++ )
		{
			if( state[m] == 0 )
			{
				lastOcc = m - 1;
				break;
			}
		}

		lastOcc <<= 8;
		lastOcc += glbIndex;

		ExecHostCommand('tdshp:'  + glbFilter + ',0,' + lastOcc);
		SaveProgAtButton(glbIndex);
	}
	else if(sel == 3)
	{
		ShowMatrix(false);
		Mw(1, glbb,glbItemCnt);
	}
}


function ConfirmDelete(sel)
{
	var m, lastOcc;
	
	if(sel < 3)
	{
		if(sel == 1)
		{
			if( state[glbIndex] == 3 )
			{
				glbLastIndexTuned = 0xFF;		
			}
			else if( state[glbIndex] == 2 )
			{
				glbIndexTuned = 0xFF;
				document.all.tunedProg.id = "";	
			}
			DeleteProgFromButton(glbIndex);
		}
		else if(sel == 2)
		{	
			if( state[glbIndex] == 3 )
			{
				glbLastIndexTuned = 0xFF;
			}
			else if( state[glbIndex] == 2 )
			{
				glbIndexTuned = 0xFF;
				document.all.tunedProg.id = "";	
			}
			DeleteProgFromButton(glbIndex);

			for( m = glbIndex + 1; m < NUM_BUTTONS; m++ )
			{
				if( state[m] == 0 )
				{
					lastOcc = m - 1;
					break;
				}
			}

			if( m == NUM_BUTTONS )
			{
				lastOcc = m - 1;
			}

			lastOcc <<= 8;
			lastOcc += (glbIndex + 1);
			
			ExecHostCommand('tdshp:' + glbFilter + ',1,' + lastOcc);
		}

		if( (glbFilter & 0x02) == 0x00 )
		{
			UpdateProgList('');
		}
		else
		{
			GetProgList();
		}
	}
	else if(sel == 3)
	{
		if( state[glbIndex] == 3 )
		{
			glbLastIndexTuned = 0xFF;
			
		}
		else if( state[glbIndex] == 2 )
		{
			glbIndexTuned = 0xFF;
			document.all.tunedProg.id = "";	
		}

		DeleteAllProgs();
	}
	ShowMatrix(false);
	setTimeout("ResetButtons()",5);
}

function ShowConfirmStoreMenu(show, index)
{
	var m = 0;
	var prog = "";

	if(show == true)
	{
		prog = document.all.place[index].title;
		document.all.InfoText.innerHTML = document.all.InfoTextA1.text + " <b>" + index + "</b> " + document.all.InfoTextA2.text + " <b><nobr>" + prog + "</nobr></b><br>" + document.all.InfoTextA3.text;
		glbInfoText = document.all.InfoText.innerHTML;

		for( m = NUM_BUTTONS - 1; m > glbIndex; m-- )
		{
			if( state[m] == 0 )
			{
				document.all.confirmStore2.style.display = "inline";
				break;
			}
		}
		if( m == glbIndex )
			document.all.confirmStore2.style.display = "none";

		contextInProgress = true;

		for( m = 1; m < NUM_BUTTONS; m++ )
		{
			document.all.place[m].disabled = true;
		}
		document.all.ConfirmStore.style.display = "inline";
		document.all.ProgNav.style.display = "none";
	}
	else if(show == false)
	{
		document.all.ConfirmStoreMenu.style.display = "none";
		document.all.ProgNav.style.display = "inline";
	}
}

function ShowConfirmDeleteAllMenu(show)
{
	if(show == true)
	{
		document.all.InfoText.innerHTML = "<b>" + document.all.InfoTextB1.text + "</b>";
		glbInfoText = document.all.InfoText.innerHTML;

		document.all.ConfirmDeleteAllMenu.style.display = "inline";
		document.all.ProgNav.style.display = "none";
		document.all.ContextMenu.style.display = "inline";
	}
	else
	{
		document.all.ConfirmDeleteAllMenu.style.display = "none";
		document.all.ProgNav.style.display = "inline";
	}
}

function ShowConfirmDeleteMenu(show, index)
{
	var m = 0;
	var prog = "";

	if(show == true)
	{
		if( index >= NUM_BUTTONS )
		{
			return;
		}

		prog = document.all.place[index].title;
		document.all.InfoText.innerHTML = document.all.InfoTextC1.text + "<br><br>";
		glbInfoText = document.all.InfoText.innerHTML;

		if( (index != NUM_BUTTONS) && (state[index + 1] > 0) )
			document.all.confirmDelete2.style.display = "inline";
		else
			document.all.confirmDelete2.style.display = "none";

		glbIndex = index;
		document.all.ConfirmDeleteMenu.style.display = "inline";

		document.all.ProgNav.style.display = "none";
		document.all.ContextMenu.style.display = "inline";
	}
	else
	{
		document.all.ConfirmDeleteMenu.style.display = "none";
		document.all.ProgNav.style.display = "inline";
	}
}


function SetInfoText(obj, sel)
{
	switch(sel)
	{
	case 0:
		document.all.InfoText.innerHTML = glbInfoText;
		break;
	case 1:
		document.all.InfoText.innerHTML = document.all.InfoTextD1.text + " <b><nobr>" + document.all.place[glbIndex].title + "</nobr></b> " + document.all.InfoTextD2.text + " <b><nobr>" + glbCurProgName + "</nobr></b> " + document.all.InfoTextD3.text;
		break;
	case 2:
		document.all.InfoText.innerHTML = document.all.InfoTextE1.text + " <b>" + glbCurProgName + "</b> " + document.all.InfoTextE2.text + " <b><nobr>" + document.all.place[glbIndex].title + "</nobr></b> " + document.all.InfoTextE3.text;
		break;
	case 3:
		document.all.InfoText.innerHTML = document.all.InfoTextF1.text + " <b><nobr>" + glbCurProgName + "</nobr></b> " + document.all.InfoTextF2.text;
		break;
	case 4:
		document.all.InfoText.innerHTML = document.all.InfoTextG1.text;
		break;
	case 5:
		document.all.InfoText.innerHTML = document.all.InfoTextH1.text + " <b><nobr>" + document.all.place[glbIndex].title + "</nobr></b> " + document.all.InfoTextH2.text;
		break;
	case 6:
		document.all.InfoText.innerHTML = document.all.InfoTextI1.text + " <b><nobr>" + document.all.place[glbIndex].title + "</nobr></b> " + document.all.InfoTextI2.text;
		break;
	case 7:
		document.all.InfoText.innerHTML = "<b>" + document.all.InfoTextJ1.text + "</b>";
		break;
	default:
		break;
	}
}

function ShowSwitchMenu(show, mode)
{
	if(show == true)
	{
		if( (NumOcc > 1) && (mode == 1) )
		{
			document.all.next.style.display = "inline";
			document.all.back.style.display = "inline";
		}
		document.all.SwitchMenu.style.display = "inline";
	}
	else if(show == false)
	{
		document.all.back.style.display = "none";
		document.all.next.style.display = "none";
		document.all.last.style.display = "none";
		document.all.SwitchMenu.style.display = "none";
		glbIndexTuned = 0xFFFF;
	}
}

function SwitchProg(index)
{
	if( document.all.place[glbIndexTuned] && ( glbIndexTuned != index) )
	{
		document.all.place[glbIndexTuned].style.backgroundColor = bgColorOcc;
		document.all.place[glbIndexTuned].style.color = textColorOcc;
		state[glbIndexTuned] = 3;
		glbLastIndexTuned = glbIndexTuned;
		document.all.last.style.display = "inline";
	}

	ExecHostCommand('tdtun:' + document.all.place[index].name);

	document.all.place[index].style.backgroundColor = bgColorTuned;
	document.all.place[index].style.color = textColorTuned;
	state[index] = 2;

	if(NumOcc > 1)
	{
		document.all.back.style.display = "inline";
		document.all.next.style.display = "inline";
	}
	glbIndex = glbIndexTuned = index;
}

function SwitchBack()
{
	var j = glbIndexTuned - 1;
	while(1)
	{
		if( j < 1 )
			j = NUM_BUTTONS - 1;
		if( state[j] > 0 )
		{
			break;
		}
		j--;
	}
	SwitchProg(j);
}

function SwitchNext()
{
	var j = glbIndexTuned + 1;
	while(1)
	{
		if( j >= NUM_BUTTONS )
			j = 1;
		if( state[j] > 0 )
		{
			break;
		}
		j++;
	}
	SwitchProg(j);
}

function SwitchLast()
{
	SwitchProg(glbLastIndexTuned);
}

function InitGlbFilter(par)
{
	var bild1, bild2;
	glbFilter = par;

	if( (par & 0x01) == 0x00)
	{
		SetImage(document.images["but_tvrad"], 'pic/g_tv_c.gif');
	}
	else
	{
		SetImage(document.images["but_tvrad"], 'pic/g_radio_c.gif');
	}
	if( (par & 0x01) == 0x01)
	{
		bild1 = "g_tv";
		bild2 = "g_radio_c";
	}
	else
	{
		bild1 = "g_tv_c";
		bild2 = "g_radio";
	}

	if( (par & 0x02) == 0x02)
	{
		document.all.Fltalpha1.style.display = "none";
		bild1 = "g_fav_c";
	}
	else
	{
		document.all.Fltalpha1.style.display = "inline";
		document.all.but_mat.style.display = "none";
		bild1 = "g_fav";
	}
	document.images["but_favo"].src = "pic\\" + bild1 + ".gif";

	if( (par & 0x04) == 0x04 )
	{
		bild1 = "g_mat_c";
		glbMatrixFlag = true;
	}
	else
	{
		glbMatrixFlag = false;
		bild1 = "g_mat";
	}
	document.images["but_mat"].src = "pic\\" + bild1 + ".gif";
}

function OnButtonProgDisplay(whichButton)
{
	var gF = glbFilter;
	if(whichButton == "A")
	{
		if( (glbFilter & 0x01) == 0x01 )
			glbFilter &= 0xFE;
		else
			glbFilter |= 0x01;
		ShowSwitchMenu(false);
		ResetButtons();
	}
	else if(whichButton == "F")
	{
		if(	(glbFilter & 0x02) == 0x02)	
		{
			document.all.but_mat.style.display = "none";
			document.all.Fltalpha1.style.display = "inline";
			if( (glbFilter & 0x04) == 0x04 )
			{
				glbMatrixFlag = true;
			}
			else
			{
				glbMatrixFlag = false;
			}
			glbFilter &= 0xF9;
		}
		else
		{
			document.all.Fltalpha1.style.display = "none";
			document.all.but_mat.style.display = "inline";
			if(glbMatrixFlag == true)
			{
				glbMatrixFlag = false;
				glbFilter |= 0x06;
			}
			else
			{
				glbFilter |= 0x02;
			}
		}
	}
	else if(whichButton == "M")
	{
		if( (glbFilter & 0x02) == 0x00)
		{
			return;
		}
		else if( (glbFilter & 0x04) == 0x04)
		{
			glbFilter &= 0xFB;
		}
		else
		{
			glbFilter |= 0x04;
		}
	}

	if( (gF >> 2) == 1)
	{
		HideMatrix();
	}
	else
	{
		document.all.DynList.style.display = 'none';
	}

	GetProgList();

	if( (glbFilter >> 2) == 0 )
	{
		document.body.style.cursor = 'auto';
		document.all.DynList.style.display = 'inline';
		document.all.DynList.focus();
	}
}

function OnMouseoutProgDisplay(obj, whichButton)
{
	var bild = "";
	switch(whichButton)
	{
	case "A":
		if( (glbFilter & 0x01) == 0x00 )
			bild = "g_tv_c";
		else
			bild = "g_radio_c";
		break;
	case "F":
		if( (glbFilter & 0x02) == 0x02 )
			bild = "g_fav_c";
		else
			bild = "g_fav";
		break;
	case "M":
		if( (glbFilter & 0x04) == 0x04 )
			bild = "g_mat_c";
		else
			bild = "g_mat";
		break;
	default:
		break;
	}
	bild = "pic\\" + bild + ".gif";
	SetImage(obj, bild);
}

function MouseDownTVRad(elem)
{
	if( (glbFilter & 0x01) == 0x00 )
	{
		SetImage(elem, 'pic/g_radio_b.gif');
	}
	else
	{
		SetImage(elem, 'pic/g_tv_b.gif');
	}
}

function MouseOverTVRad(elem)
{
	if( (glbFilter & 0x01) == 0x00 )
	{
		SetImage(elem, 'pic/g_radio_a.gif');
	}
	else
	{
		SetImage(elem, 'pic/g_tv_a.gif');
	}
}

function ShowMatrix(show, mode, curProg)
{
	glbMode = mode;
	var i, j, k;
	var TVRad = "";

	document.body.style.cursor = 'wait';
	if(mode == 1)
	{
		glbCurProg = curProg;
		glbStoreBgColor = document.all.place[curProg].style.backgroundColor;
		glbStoreTextColor = document.all.place[curProg].style.color;
	}

	if(show == true)
	{
		i = NUM_BUTTONS - 1;
		k = i - NumOcc;

		if ( (glbFilter & 0x01) == 0x00 )
			TVRad = "tv";
		else
			TVRad = "radio";

		for( j = 1; j < NUM_BUTTONS; j++ )
		{
			if( state[j] == 0 )
			{
				document.all.place[j].style.backgroundColor = bgColorFree;
				document.all.place[j].style.color = textColorFree;
				if(mode == 0)
				{
					document.all.place[j].disabled = false;
				}
				else
				{
					document.all.place[j].disabled = true;
				}
			}
			else
			{
				document.all.place[j].style.backgroundColor = bgColorOcc;
				document.all.place[j].style.color = textColorOcc;
				if((mode & 0x01) == 0)
				{
					document.all.place[j].disabled = false;
				}
				else
				{
					document.all.place[j].disabled = true;
				}
			}
		}
		if(mode == 0)
		{
			glbInfoText = document.all.InfoText.innerHTML = document.all.InfoTextK1.text + " <b><nobr>" + curProg + "</nobr></b><br>(" + document.all.InfoTextK2.text + " " + k + ")";
			document.all.infooben1.innerHTML = "<img src='pic\\a_fav.gif'><img src='pic\\a_" + TVRad + ".gif'>";
			document.all.infooben2.innerHTML = "<b>" + curProg + "</b>";
			glbCurProgName = curProg;
			document.all.AboveList.style.display = "none";
			document.all.infooben.style.display = "inline";

			document.all.ContextMenu.style.display = "inline";
			document.all.ProgNav.style.display = "none";
			document.all.ConfirmStoreMenu.style.display = "inline";
			
		}
		else if(mode == 1)
		{
			contextInProgress = true;

			document.all.infooben1.innerHTML = "<img src='pic\\a_fav_a.gif'><img src='pic\\a_" + TVRad + ".gif'>";
			document.all.infooben2.innerHTML = "<b>" + document.all.place[curProg].title + "</b>";

			document.all.place[curProg].style.backgroundColor = bgColorCurOcc;
			document.all.place[curProg].style.color = textColorCurOcc;

			ShowConfirmDeleteMenu(true, curProg);
			document.all.AboveList.style.display = "none";
			document.all.infooben.style.display = "inline";

		}
		else if(mode == 2)
		{
			mode = 0;
			for( j = 1; j < NUM_BUTTONS; j++ )
			{
				if( document.all.place[j].name == prgIndex )
				{
					document.all.place[j].style.backgroundColor = bgColorTuned;
					document.all.place[j].style.color = textColorTuned;
					state[j] = 2;
					glbIndexTuned = j;
					mode = 1;
					break;
				}
			}
			ShowSwitchMenu(true, mode);
		}
		else if(mode == 3)
		{
			var k = 0;
			for( j = 1; j < NUM_BUTTONS; j++ )
			{
				if( state[j] > 0 )
					k++;
			}
			if(k == 0)
				return;

			contextInProgress = true;

			document.all.infooben1.innerHTML = "<img src='pic\\a_fav_a.gif'><img src='pic\\a_" + TVRad + ".gif'>";
			document.all.infooben2.innerHTML = "<b> . . . </b>";

			
			ShowConfirmDeleteAllMenu(true);
			document.all.AboveList.style.display = "none";
			document.all.infooben.style.display = "inline";
		}

		document.all.DynList.style.display = "none";
		document.all.Matrix.style.display = "inline";
	}
	else if(show == false)
	{
		ShowSwitchMenu(false);
		ShowConfirmDeleteMenu(false);
		ShowConfirmStoreMenu(false);

		ShowConfirmDeleteAllMenu(false);

		contextInProgress = false;

		document.all.infooben.style.display = "none";
		document.all.AboveList.style.display = "";
		document.all.Matrix.style.display = "none";
		document.all.DynList.style.display = "inline";

		document.all.ProgNameDisplay.innerHTML = "&nbsp;";
		document.all.InfoText.innerHTML = glbInfoText = "";

		document.all.ContextMenu.style.display = "none";
		document.all.ProgNav.style.display = "inline";
		document.all.ConfirmStore.style.display = "none";
	}
	document.body.style.cursor = 'auto';
}

function ResetButtons()
{
	for( j = 1; j < NUM_BUTTONS; j++ )
	{
		document.all.place[j].title = "";
		document.all.place[j].name = "";
		state[j] = 0;
	}
}

function HideMatrix()
{
	document.body.style.cursor = 'wait';
	document.all.Matrix.style.display = "none";
	ShowSwitchMenu(false);
	document.body.style.cursor = 'auto';
}

function OnButtonPI()
{
	ShowProgInfo(!bPIvisible);
}

function SetImagePi(elem)
{
	//if(bPIvisible)
	//	SetImage(elem,'pic\\p_info_c.gif');
	//else
	//	SetImage(elem,'pic\\p_info.gif');
}

function PaintButtons()
{
	var butcount;
	var zelle = "<button type=\"button\" class=\"matrix\" id=\"place\" title=\"\" name=\"\" ";
	if(hlpvar == false)
	{
		for (butcount = 0 ; butcount < NUM_BUTTONS ; butcount++)
		{
			document.write(zelle + "value=\"" + butcount + "\" onmouseover=\"MouseOverButton(" + butcount + ");  return false;\"  onmouseout=\"MouseOutButton(" + butcount + "); return false;\" onClick=\"OnLeftMouseButton(" + butcount + "); \"  onfocus=\"this.blur();\" oncontextmenu=\"OnRightMouseButton(" + butcount + "); return false;\" style=\"background-color:");
			document.write(bgColorFree + "; color:" + textColorFree + ";\">");
			document.write("<p>" + butcount + "</p></button>");
			if( ((butcount + 1) % 10) == 0 )
				document.write("<br>");
		}
		document.all.place[0].style.visibility = "hidden";
		document.all.place[0].disabled == true;
	}
	hlpvar = true;
}

var hour = 0;
var min = 0;
var sec = 0;
var sHour, sMin, sSec;
var glbTimeCount = false;
var jump = false;
function TimeCount(on)
{
	if(on == false)
	{	
		hour = min = sec = 0;
		ResetRecStatus();
		return;
	}
if(!glbIsPause)
{
	if(jump == false)
	{
		if(++sec == 60)
		{
			++min;
			sec = 0;
		}
	}
	else
	{
		if(++min == 60)
		{
			++hour;
			min = 0;
		}
	}
}	
	sMin = "" + ((min < 10) ? "0" + min : min);

	if(min < 20 && jump == false)
	{
		sSec = "" + ((sec < 10) ? "0" + sec : sec);
		document.all.rectime.innerHTML = sMin + ":" + sSec;
		setTimeout('TimeCount(glbTimeCount)', 995);
	}
	else
	{
		sHour = "" + ((hour < 10) ? "0" + hour : hour);
		document.all.rectime.innerHTML = sHour + ":" + sMin;
		document.all.rectime.title = document.all.TimeCountA2.text;
		jump = true;
		setTimeout('TimeCount(glbTimeCount)', 59995);
	}
}

// * * * Sleep Timer * * *
var m_hour		= 0;
var m_min		= 0;
var m_sec		= 0;
var m_sHour		= 0;
var m_sMin		= 0;
var m_sSec		= 0;
var m_TimeCount	= false;
var m_jump		= false;

function UpdateSleepTime(sTime)
{
	document.all.sleeptime.innerHTML = sTime;
}

function SetSleepTimeStatus(bOn)
{
	if (bOn == false)
	{
		document.all.sleeptime.style.color = "#FFFFFF";
		document.all.sleeptime.innerHTML = "";
		SetSleepTimerPictureImage(false);
	}
	else
	{
		document.all.sleeptime.style.color = "#FF0000";
		SetSleepTimerPictureImage(true);
	}

}

function SetSleepTimerPicture()
{
	if (bSleepTimerPic == true)
		SetImage(document.all.SleepTimer, 'pic\\p_sleep_c.gif');
	else
		SetImage(document.all.SleepTimer, 'pic\\p_sleep.gif');
}

function SetSleepTimerPictureImage(bOn)
{
	if (bOn == false)
	{
		SetImage(document.all.SleepTimer, 'pic\\p_sleep.gif');
		bSleepTimerPic = false;
	}
	else
	{
		SetImage(document.all.SleepTimer, 'pic\\p_sleep_c.gif');
		bSleepTimerPic = true;
	}
}

function SetAudioStateImg(iAudioMode, bSendFromHtml)
{
	if (bSendFromHtml == false)
	{
		m_iAudioMode = iAudioMode;
	}

	switch (m_iAudioMode)
	{
	case 0://Left
		SetImage(document.all.AudioMode, 'pic\\p_audio_c.gif');
		break;
	case 1://Right
		SetImage(document.all.AudioMode, 'pic\\p_audio_d.gif');
		break;
	case 2://Stereo
		SetImage(document.all.AudioMode, 'pic\\p_audio_e.gif');
		break;
	case 3://AC3
		SetImage(document.all.AudioMode, 'pic\\p_audio_f.gif');
		break;
	}
}

function SetCIState()
{
	switch (m_iCiStatus)
	{
	case 0:SetImage(document.all.Cmd7, 'pic\\g_ci.gif');
		break;
	case 1:SetImage(document.all.Cmd7, 'pic\\g_ci_c.gif');
		break;
	}
}

function SetCIStateImg(iMode)
{
	switch (iMode)
	{
	case 0:
		{
			SetImage(document.all.Cmd7, 'pic\\g_ci.gif');
			m_iCiStatus = 0;
		}
		break;
	case 1:	
		{
			SetImage(document.all.Cmd7, 'pic\\g_ci_c.gif');
			m_iCiStatus = 1;
		}
		break;
	}
}

function ResetRecStatus()
{
	document.all.rectime.innerHTML = "";
	document.all.rectime.title = "";
	document.all.recformat.innerHTML = "";
	document.all.recformat.title = "";
}

function RefrEPG()
{
	ExecHostCommand('tdcmd:80');
}

function SetTvPicture()
{
	if (bTvPic == true)
	{
		SetTvPictureImage(false);
	}
	else
	{
		SetTvPictureImage(true);
	}
}

function SetTvPictureStatus()
{
	bTvPic = !bTvPic;
}

function SetTvPictureImage(bOn)
{
	if (bOn == false)
	{
		SetImage(document.all.tvpic, 'pic\\p_tvpic_b.gif');
		bTvPic = true;
		
	}
	else
	{
		SetImage(document.all.tvpic, 'pic\\p_tvpic.gif');
		bTvPic = false;
		
	}
}

function SetSubpicture()
{
	if (m_bSubPic == true)
	{
		SetSubpictureImage(false);
	}
	else
	{
		SetSubpictureImage(true);
	}
}

function SetSubpictureStatus()
{
	m_bSubPic = !m_bSubPic;
}

function SetSubpictureImage(bOn)
{
	if (bOn == false)
	{
		SetImage(document.all.subpic, 'pic\\p_subpic_b.gif');
		m_bSubPic = true;
		
	}
	else
	{
		SetImage(document.all.subpic, 'pic\\p_subpic.gif');
		m_bSubPic = false;
		
	}
}

function SetMHPImage(bOn)
{
	if (bOn == false)
	{
		SetImage(document.all.Cmd_mhp, 'pic\\g_mhp.gif');		
		
	}
	else
	{
		SetImage(document.all.Cmd_mhp, 'pic\\g_mhp_b.gif');
	}
	m_bMHPPic = bOn;
}

function SetMHPState()
{
	if (m_bMHPPic == false)
	{
		SetImage(document.all.Cmd_mhp, 'pic\\g_mhp.gif');		
		
	}
	else
	{
		SetImage(document.all.Cmd_mhp, 'pic\\g_mhp_b.gif');
	}	
}

function BeginWaitCursor()
{
	/*
	document.body.style.cursor = "wait";
	document.CaptionBar.style.cursor = "wait";
	document.PrgName.style.cursor = "wait";
	document.ToolBarHorz.style.cursor = "wait";
	document.AboveList.style.cursor = "wait";
	document.SysToolView.style.cursor = "wait";
	*/	
}

function EndWaitCursor()
{
	/*
	document.body.style.cursor = "default";
	//document.CaptionBar.style.cursor = "default";
	document.PrgName.style.cursor = "default";
	document.ToolBarHorz.style.cursor = "default";
	document.AboveList.style.cursor = "default";
	document.SysToolView.style.cursor = "default";
	*/
}
