function alerta_downtime()
{
	$('#alerta-downtime').slideDown( 1000 );
}
//setTimeout( 'alerta_downtime()', 1000 );

function check_alerte()
{
	$.post( 	
		'sources/acts.php' , 
		{ 
			act: 'check_alerte'
		} , 
		function( data )
		{
			if( data.success )
			{
				$('#alert-holder').html( data.alerta );
				$('#alert-holder').slideDown( 1000 );
			}
		}, 
		'json'
	);
	setTimeout( 'check_alerte()', 120000 );
}
setTimeout( 'check_alerte()', 120000 );

function update_epg()
{
	$.post( 	
		'sources/acts.php' , 
		{ 
			act: 'update_epg'
		} , 
		function( data )
		{
			if( data.success )
			{
				// change epg
				if ( data.epg_list )
				{
					$('#epg_list').html( data.epg_list );
					player_ready();
				}
				// change current ems
				$('#program_curent').html( data.program_selectat );
				if ( data.emisiune_curenta )
				{
					$('#emisiune_curenta').html( data.emisiune_curenta_trunc );
					$('#emisiune_curenta').attr( 'title', data.emisiune_curenta );
				}
				else
				{
					$('#emisiune_curenta').html( '...' );
				}
			}
		}, 
		'json'
	);
	setTimeout( 'check_alerte()', 120000 );
}
setTimeout( 'update_epg()', 5000 );


function sterge_alerte( ems_id )
{
	$.post(
		'sources/acts.php' ,
		{
			act: 'sterge_alerte',
			epg_id: ems_id
		} ,
		function( data )
		{
			$('#alert-holder').slideUp( 1000 );
		} ,
		'json'
	);
}

function check_alerta_retea()
{
	$.post(
		'sources/acts.php',
		{
			act: 'check_alerta_retea'
		} ,
		function( data )
		{
			if ( data.success )
			{
				$('#alerta-retea').html( data.alerta );
				$('#alerta-retea').slideDown( 1000 );
			}
		},
		'json'
	);
	setTimeout( 'check_alerta_retea()', 120000 );
}

function sterge_alerta_retea()
{
	$.post(
		'sources/acts.php',
		{
			act: 'sterge_alerta_retea'
		} ,
		function( data )
		{
			$('#alerta-retea').slideUp( 1000 );
		} ,
		'json'
	);
}
check_alerta_retea();

function createCookie_ie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie_ie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

setTimeout( 'check_alerta_inregistrari()', 2000 );
function check_alerta_inregistrari()
{
	if( !readCookie_ie( 'alerta_inregistrari' ) ) 
	{
		$('#alerta-inregistrari').slideDown();
		createCookie_ie( 'alerta_inregistrari', '1', 30 );
	}
}