var secs
var timerID = null
var timerRunning = false
var delay = 500

function InitializeTimer(type)
{
    // Set the length of the timer, in seconds
    secs = 1
    StopTheClock()
    StartTheTimer(type)
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer(type)
{
    if (secs==0)
    {
        StopTheClock();
        
        if(type == 'login') {
        	xajax_checkLogin(document.getElementById('id').value,document.getElementById('login').value);
        }
        
        if(type == 'grupo') {
        	var search_id = 'nome_utilizador' + document.getElementById('search_id').value;
        	xajax_searchUtilizador(document.getElementById(search_id).value);
        }
        
        if(type == 'terminal') {
        	xajax_searchEquipamento(document.getElementById('endereco_mac').value,document.getElementById('id').value);
        }
        
        if(type == 'numero') {
        	xajax_searchCartao(document.getElementById('numero').value,document.getElementById('id').value);
        }
        	
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer('"+ type +"')", delay)
    }
}
