{% load i18n l10n static %}
{% load static %}

{% block center_content %}
{% get_current_language as LANGUAGE_CODE %}
<div id="{{view_name}}_refresh_time" class="refresh_time_container"> <!-- refresh -->
	
	<p id="{{view_name}}_refresh_span">
		<!--<img src="{{STATIC_URL}}{% get_static_prefix %}img/loading.gif" height="15px" width="15px">-->
		<span>Refreshing in</span>
		<span id="{{view_name}}_time_left_refresh" class="time_left_span"></span>
		<span>seconds</span>
	</p>

	<input id="{{view_name}}_timer_refresh_btn" class="timer_refresh_btn" type="button" value="Stop" role="button" onclick="{{view_name}}_refresh()">
</div>
<!--<p class="clear-fix"> </p> -->
{% endblock center_content %}


<script type="text/javascript" lang="text/javascript">

//IMPORTANT: in base_.html global variable INTERVAL_{{view_name}} =NULL
if(typeof(INTERVAL_{{view_name}})=="undefined")
{	
	global_time('INTERVAL_{{view_name}}');
}
$('#{{view_name}}_timer_refresh_btn').button();

$('#{{view_name}}_timer_refresh_btn').attr('value', 'Stop');


$('#{{view_name}}_time_left_refresh').html({{refresh_time}});

// Clear interval if already running
window.clearInterval(INTERVAL_{{view_name}});

// Starts or stops the authomatic refreshing
function {{view_name}}_refresh() {
	if ($('#{{view_name}}_timer_refresh_btn').val()=='Stop')
	{
		$('#{{view_name}}_timer_refresh_btn').attr('value', 'Start');
		window.clearInterval(INTERVAL_{{view_name}});
	}  
	else {
		$('#{{view_name}}_timer_refresh_btn').attr('value', 'Stop');
		INTERVAL_{{view_name}} = window.setInterval("{{view_name}}_refreshCount()",1000);
	}
}

// Carries the authomatic refreshing
function {{view_name}}_refreshCount(){
	tabs_actual = $(".ui-tabs-active > a").attr("title"); 

	//console.log('INTERVAL {{view_name}}',INTERVAL_{{view_name}});
	//console.log('TIME {{view_name}}',$('#{{view_name}}_time_left_refresh').html());
	if($('#{{view_name}}_timer_refresh_btn').val()=='Stop') {
		if ($('#{{view_name}}_time_left_refresh').html()!=1){
		  $('#{{view_name}}_time_left_refresh').html($('#{{view_name}}_time_left_refresh').html()-1);
		}
		else
		{
			if (tabs_actual == '{{view_name}}') {
				$('#{{view_name}}_time_left_refresh').html( {{refresh_time}});
				//console.log('refresh',tabs_actual,'{{view_name}}')
				{{view_name}}_callback('refresh_time');
			}
		}
	}
}

$('#{{view_name}}_container').click(function(){
	$('#{{view_name}}_time_left_refresh').html({{refresh_time}})
});

$('.select2-default').click(function(){
    $('#{{view_name}}_time_left_refresh').html({{refresh_time}})
});

$('.slider-button').click(function(){
    $('#{{view_name}}_time_left_refresh').html({{refresh_time}})
});

INTERVAL_{{view_name}}= window.setInterval("{{view_name}}_refreshCount()",1000);



</script>