{=include-block:Y_Blocks.txt;head=}
<script type="text/javascript" src="/Y_Baselib.js"></script>
<script type="text/javascript">
//<![CDATA[
/*sLog*/
var sLog_body;
var sLog_line_number;
var epg_data;
var epg_data_index=0;
function sLog_init()
{
	sLog_line_number = 0;
	sLog_body=document.getElementById("slog_list");
}
function sLog_clear()
{
	while(sLog_body.childNodes.length > 0){
		aChild=sLog_body.firstChild;
		sLog_body.removeChild(aChild);
	}
	sLog_line_number =  0;
}
function sLog_addRow(_body, _rec, _zapit, _start, _end, _title)
{
	sLog_line_number++;
	var mycurrent_row = y_add_row_to_table(_body, ((sLog_line_number % 2) ==0)?"a":"b" );
	
	y_add_html_cell_to_row(mycurrent_row, "rec", _rec);
	y_add_html_cell_to_row(mycurrent_row, "zap", _zapit);
	y_add_html_cell_to_row(mycurrent_row, "starttime", _start);
	y_add_html_cell_to_row(mycurrent_row, "endtime", _end);
	y_add_html_cell_to_row(mycurrent_row, "epgtitle", _title);
}
function set_timer(_channel_id, _start, _stop)
{
	var rec = "/control/timer?action=new&type=5&alarm="+_start+"&stop="+_stop+"&announce="+_start+"&channel_id="+_channel_id+"&rs=1";
	var res = loadSyncURL(rec);
	alert("Record gesetzt");
}
function set_zapit(_channel_id, _start)
{
	var rec = "/control/timer?action=new&type=3&alarm="+_start+"&channel_id="+_channel_id;
	var res = loadSyncURL(rec);
	alert("Zapping gesetzt");
}
function show_info(_index)
{
	parent.epg_info.show_info(epg_data[_index][0], epg_data[_index][1], epg_data[_index][2]);
}
function check_logo()
{
	{=if-equal:{=ini-get:/var/tuxbox/config/nhttpd.conf;ExtrasDocRoot=}~web~~
	var test = loadSyncURL("{=ini-get:/var/tuxbox/config/nhttpd.conf;ExtrasDocURL=}/logos/{=channel=}.gif");
	if(test != "")
	=}
		show_obj("logo",true);
}
function show_epg()
{
	check_logo();
	sLog_init();
	sLog_clear();

	epg_data = new Array();
	epg_data_index=0;

	var now = new Date();
	var _starttime = Math.round(now/1000);
	var epg_xml = loadSyncURLxml("/control/epg?xml=true&channelid={=channel=}&details=true");
	if(epg_xml){
		var prog_list = epg_xml.getElementsByTagName('prog');
		for(i=0;i<prog_list.length;i++){
			var prog = prog_list[i];
			
			var _stop	= getXMLNodeItemValue(prog, "stop_sec");
			if(_stop > _starttime){
				var _start_t	= getXMLNodeItemValue(prog, "start_t");
				var _start	= getXMLNodeItemValue(prog, "start_sec");
				var _stop_t	= getXMLNodeItemValue(prog, "stop_t");
				var _desc	= epg_de_qout(getXMLNodeItemValue(prog, "description"));
				var _info1	= epg_de_qout(getXMLNodeItemValue(prog, "info1"));
				var _info2	= epg_de_qout(getXMLNodeItemValue(prog, "info2"));
				
				var epg_obj= new Array(_desc, _info1, _info2, _start, _start_t, _stop.toString(), "{=channel=}");
				epg_data.push(epg_obj);
				
				var _rec 	= "<a title=\"record\" href=\"javascript:set_timer('{=channel=}',"+_start+","+_stop+");\">Rec</a>";
				var _zapit 	= "<a title=\"zapping\" href=\"javascript:set_zapit('{=channel=}',"+_start+");\">Zap</a>";
				var _tit 	= "<span onmouseover=\"show_info('"+epg_data_index+"')\">"+_desc+"</span>";
				sLog_addRow(sLog_body, _rec, _zapit, _start_t, _stop_t, _tit);
				epg_data_index++;
			}
		}
	}
	show_waitbox(false);
}
//]]>
</script>
</head>
{=var-set:wait_text=EPG is loaded.=}{=include-block:Y_Blocks.txt;snip_show_wait=}
<body onload="show_epg()">
	<table class="y_invisible_table" cellpadding="4" width="100%">
	<thead align="left">
	<tr>
		<th colspan="2"><img id="logo" src="{=ini-get:/var/tuxbox/config/nhttpd.conf;ExtrasDocURL=}/logos/{=channel=}.gif" style="visibility:hidden">&nbsp;</th>
		<th>From</th><th>to</th><th>Broadcasting</th>
	</tr>
	</thead>
	<tbody id="slog_list">
	<tr><td></td></tr>
	</tbody>
	</table>
	<br />
<script type="text/javascript">
//<![CDATA[
//	show_waitbox(true);
//	window.setTimeout("show_epg()",500);
//]]>
</script>

</body>
</html>