//
//  Copyright (C) 2002 TechnoTrend AG
//


function ShowDataProgPaper(sProgName, sURL, activeWin)
{

    var	sTime = top.Fr_Control.document.getElementById("TimSel").value;

	top.Fr_void.document.getElementById("idPeriod").from = sTime;

    var	nTime = parseInt(sTime,10);

	if( nTime < 10 )
	  sURL += ("#0" + sTime);
	else
	  sURL += ("#" + sTime);


	switch(activeWin)
	{
	case 0: top.Fr_data.nifp0.document.getElementById("CurPrg").innerHTML = "<span oncontextmenu='PrintIt(0)' onclick='PrintIt(0)'>" + sProgName + "</span>";
	        top.Fr_data.nifd0.document.location.href=sURL;
            break;
	case 1:
	        top.Fr_data.nifp1.document.getElementById("CurPrg").innerHTML = "<span oncontextmenu='PrintIt(1)' onclick='PrintIt(1)'>" + sProgName + "</span>";
	        top.Fr_data.nifd1.document.location.href=sURL;
	        break;
	case 2:
	      	top.Fr_data.nifp2.document.getElementById("CurPrg").innerHTML = "<span oncontextmenu='PrintIt(2)' onclick='PrintIt(2)'>" + sProgName + "</span>";
			top.Fr_data.nifd2.document.location.href=sURL;
	        break;
	}

}

function Reveal(elem, sEvID)
{
	var RefElem = document.getElementById(sEvID);
	if( RefElem && (RefElem.className == "tree") )
	{
		if(	RefElem.style.display != "inline" )
		{
			elem.title = "";
			RefElem.style.display = "inline";
		}
		else
		{
			RefElem.style.display = "none";
		}
	}
}

function SetCursor(elem, sEvID)
{
	var RefElem = document.getElementById(sEvID);
	if( RefElem && (RefElem.className == "tree") )
	{
		elem.style.cursor = "hand";
		if( RefElem.style.display != "inline" )
		{
			//elem.title = document.getElementById(sEvID).lastChild.firstChild.data;
		}
		else
		{
			elem.title = "";
		}
	}
}

function recTimer(node)
{
	var num = node.num;
	window.navigate("recTimer:" + num);
}




function ChangeTimePaper()
{

	var sURL = "";
	var saURL = "";
	var sTime = top.Fr_Control.document.getElementById("TimSel").value;

	top.Fr_void.document.getElementById("idPeriod").from = sTime;

	if( parseInt(sTime,10) < 10 )
		sTime = "0" + sTime;

	sURL = top.Fr_data.nifd2.document.URL;
	saURL = sURL.split("#");
	saURL[0] += "#" + sTime;
	top.Fr_data.nifd2.location.href=decodeURI(saURL[0]);

	if(parent.Fr_data.document.nifd2.document.all.idif)
		parent.Fr_data.document.nifd2.document.all.idif.scrollTop -= 38;


	sURL = top.Fr_data.nifd1.document.URL;
	saURL = sURL.split("#");
	saURL[0] += "#" + sTime;
	top.Fr_data.nifd1.location.href=decodeURI(saURL[0]);

	if(parent.Fr_data.document.nifd1.document.all.idif)
		parent.Fr_data.document.nifd1.document.all.idif.scrollTop -= 38;


	sURL = top.Fr_data.nifd0.document.URL;
	saURL = sURL.split("#");
	saURL[0] += "#" + sTime;
	top.Fr_data.nifd0.location.href=decodeURI(saURL[0]);

	if(parent.Fr_data.document.nifd0.document.all.idif)
		parent.Fr_data.document.nifd0.document.all.idif.scrollTop -= 38;


}

function SetCurTimePaper()
{
	var Now = new Date();
    var sHours = Now.getHours();
	var i;

	top.Fr_void.document.getElementById("idPeriod").from = sHours;

	for( i = 0; i < 25; i++ )
	{
		oOption = document.createElement("OPTION");
		oOption.text = i.toString() + ":00";
		oOption.value = i.toString();
		top.Fr_Control.document.all.TimSel.add(oOption);
		if(sHours == oOption.value)
			oOption.selected = true;
	}
}


function changePage(d)
{
	window.navigate("EPGpaper:" + d);

	var page;
	page = parseInt(document.getElementById("page").page,10);

	if (d =="next") page++;

	if (d =="back")
	{
		if (page == 1 )
			page = 1;
		else
			page--;
	}

	switch (page)
	{
	case 1:
		document.getElementById("back").style.visibility = "hidden";
		document.getElementById("next").style.visibility = "visible";
		break;

	default:
		document.getElementById("back").style.visibility = "visible";
		document.getElementById("next").style.visibility = "visible";
		break;
	}
	document.getElementById("page").page = page;
}

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

function PageCountInit(sAnz)
{
	top.Fr_Control.document.all.PageCounter.innerText = sAnz;
	top.Fr_Control.document.all.PageCounter.style.visibility = "visible";
	top.Fr_Control.document.all.next.style.visibility = "visible";
	top.Fr_Control.document.all.back.style.visibility = "visible";
}

function PrintAll()
{
	var bOK = false;

	var i;

	var objects = new Array(3);

	nCols = objects.length;

	for(i = 0; i < nCols; i++ )
	{
		objects[i] = new Array(5);
	}

	objects[0][0] = parent.Fr_data.nifp0;
	objects[0][1] = parent.Fr_data.nifd0;
	objects[0][2] = top.Fr_void.document.all.progname0;
	objects[0][3] = parent.Fr_data.document.all.PN0;
	objects[0][4] = top.Fr_void.document.all.idday_0;

	objects[1][0] = parent.Fr_data.nifp1;
	objects[1][1] = parent.Fr_data.nifd1;
	objects[1][2] = top.Fr_void.document.all.progname1;
	objects[1][3] = parent.Fr_data.document.all.PN1;
	objects[1][4] = top.Fr_void.document.all.idday_1;

	objects[2][0] = parent.Fr_data.nifp2;
	objects[2][1] = parent.Fr_data.nifd2;
	objects[2][2] = top.Fr_void.document.all.progname2;
	objects[2][3] = parent.Fr_data.document.all.PN2;
	objects[2][4] = top.Fr_void.document.all.idday_2;

	var nSpans = 0;
	var nTrs = 0;
	var nTds = 0;

	var sContent = "";
	var sTime = "";

	var TRcount = 1;	// ohne Datum

	var nTime = 0;
	var nLastTime = 0;

	var sId = "";

	var nTdtims = 0;
	var nTdtimsCnt = 0;

	var nObj = 0;

	var sIdPre = "";

	var obj_ifp = objects[nObj][0];
	var obj_ifd = objects[nObj][1];
	var obj_prn = objects[nObj][2];
	var obj_col = objects[nObj][3];
	var obj_day = objects[nObj][4];

	var nFrom = parseInt( top.Fr_void.document.getElementById("idPeriod").from, 10 );

	for( nObj = 0; nObj < nCols; nObj++ )
	{
		obj_ifp = objects[nObj][0];
		obj_ifd = objects[nObj][1];
		obj_prn = objects[nObj][2];
		obj_col = objects[nObj][3];
		obj_day = objects[nObj][4];

		sIdPre = nObj + "_";

		//if( !(obj_ifp.document.all.dis) )
		{
			nSpans = 0;
			nTrs = 0;
			nTds = 0;

			sContent = "<table style=\"width:100%\" width=\"100%\">";
			sTime = "";

			TRcount = 1;	// ohne Datum

			nTime = 0;
			nLastTime = 0;

			sId = "";

			nTdtims = 0;
			nTdtimsCnt = 0;

			bOK = true;

			if( !(obj_ifp.document.all.dis) )
			{
				obj_prn.innerHTML =
					obj_ifp.document.getElementById("CurPrg").innerHTML;
				obj_prn.className = "cssPrN";

				obj_day.innerHTML =
					obj_ifd.document.getElementById("idday").firstChild.nodeValue;
			}
			else
			{
				obj_prn.innerHTML = " ";
				obj_prn.className = "";
				obj_day.innerHTML = " ";
			}

			nSpans = obj_ifd.document.getElementsByTagName("span").length;

			nTds = obj_ifd.document.getElementsByTagName("td").length;

			for( i = 0; i < nTds; i++ )
			{
				if( obj_ifd.document.getElementsByTagName("td")[i].className == "tdtim" )
					nTdtims++;
			}

			nTrs = obj_ifd.document.getElementsByTagName("tr").length;

			if( nSpans )
				sTime = obj_ifd.document.getElementsByTagName("span")[0].firstChild.nodeValue;
			else
				sTime = "0";

			nTime = parseInt(sTime,10);
			if( nTime == 0 )
			{
				nTime = 24;
			}
			nLastTime = nTime;

			i = 2;
			for( nTdtimsCnt = 0 ; nTdtimsCnt <= nTdtims; nTdtimsCnt++, i += 2 )
			{
				if( nTdtimsCnt < nTdtims )
				{
					if( TRcount < nTrs )
					{
						sContent += obj_ifd.document.getElementsByTagName("tr")[TRcount].outerHTML;
						TRcount++;
					}

					if( (TRcount < nTrs) && (obj_ifd.document.getElementsByTagName("tr")[TRcount].className == "tree") )
					{
						sContent += obj_ifd.document.getElementsByTagName("tr")[TRcount].outerHTML;
						TRcount++;
					}
				}

				if( nTdtimsCnt < (nTdtims - 1) )
				{
					sId = sIdPre + nTime.toString(10);
					sTime = obj_ifd.document.getElementsByTagName("span")[i].firstChild.nodeValue;
					nTime = parseInt(sTime,10);
					if( nTime == 0 )
					{
						nTime = 24;
					}
				}

				if( (nLastTime != nTime) || ( nTdtimsCnt == nTdtims ) )
				{
					if( nTdtimsCnt == nTdtims )
					{
						sId = sIdPre + nTime.toString();
					}
					sContent += "</table>";

					if(	nFrom < nTime )
					{
						if( !(obj_ifp.document.all.dis) )
						{
							top.Fr_void.document.getElementById(sId).innerHTML = sContent;
						}
						else
						{
							top.Fr_void.document.getElementById(sId).innerHTML = " ";
						}
					}
					sContent = "<table style=\"width:100%\" width=\"100%\">";
					nLastTime = nTime;
				}
			}
		}//if
	}//for

	if( bOK == true )
	{
		top.Fr_void.focus();
		top.Fr_void.print();
	}

	for( i = 0; i < nCols; i++ )
	{
		objects[i][2].className = "";
		objects[i][2].innerHTML = " ";
		objects[i][4].innerHTML = " ";
	}
}

function KeyHandler_Down()
{
	var kc = event.keyCode;

	if( (kc == 116) || (kc == 78) )
	{
		event.returnValue=false;
		event.keyCode=0;
		return event.keyCode;
	}
	else
	{
		if( (kc > 112) && (kc <= 123) )
		{
			event.returnValue=true;
			return event.keyCode;
		}
		else
		{
			switch(kc)
			{
			case 37:
			case 109:
				if( top.Fr_data.document.all.back.style.visibility == "visible" )
				{
					top.Fr_data.document.all.backarrow.click();
				}
				break;
			case 39:
			case 107:
				if( top.Fr_data.document.all.next.style.visibility == "visible" )
				{
					top.Fr_data.document.all.nextarrow.click();
				}
				break;
			case 85:
				if( (top.Fr_data.document.all.next.style.visibility != "hidden")
					&& (top.Fr_data.document.all.next.style.display != "none") )
				{
					top.Fr_data.document.all.refresh.click();
				}
				break;
			case 112:
				if( (top.Fr_data.document.all.help.style.visibility != "hidden")
					&& (top.Fr_data.document.all.help.style.display != "none") )
				{
					top.Fr_data.document.all.help.click();
				}
				break;
			case 80:
				PrintAll();
				break;

			default:
				event.returnValue=true;
				return event.keyCode;
				break;
			}
			event.returnValue=false;
			event.keyCode=0;
			return event.keyCode;
		}
	}
}


function TimeView()
{
	var currentView = top.document.getElementById("Fr_data").src;

	if (currentView == "./EPGPaper.htm")
	{
		var sTime = top.Fr_Control.document.getElementById("TimSel").value;

		if( sTime < 10 )
		  sTime = ("0" + sTime);

		window.navigate("EPGpaper:" + sTime + "time");


	}
	else
	{
		top.document.getElementById("Fr_data").src = "./EPGPaper.htm";
		top.document.getElementById("Fr_Control").src = "./EPGPaperControls.htm";
	}
}

function CreateTimeView()
{
	top.document.getElementById("Fr_data").src = "./EPGPaper_time.htm";

	var temp = top.Fr_Control.location.href;
	var control = temp.substr(temp.length - 25, 25);

	if (control != "EPGPaperControls_time.htm")
	{
		top.document.getElementById("Fr_Control").src = "./EPGPaperControls_time.htm";
	}
}

function ChangeTimePaper_time()
{
	var sTime = top.Fr_Control.document.getElementById("TimSel").value;
        if( sTime < 10 )
	  sTime = ("0" + sTime);

        window.navigate("EPGpaper:" + sTime + "time");
}

function ShowRefreshButton(bShow)
{
	//document.all.refresh.style.visibility = "hidden";
	//if (bShow == true)
	//	top.document.getElementById("refresh").style.display = "none";
	//else
	//	top.document.getElementById("refresh").style.display = "inline";
}