function nascondiStato()
{
	document.getElementById('tabella_stato').style.display='none';
}

var Checked;

function evidence(id)
{
    Checked = document.getElementById(id).className
	document.getElementById(id).className="alternatahover";
}

function notevidence(id)
{
    document.getElementById(id).className = Checked;
}

var annulla_controllo;

function faiSubmitForm(theForm)
{
	if (theForm.onsubmit())
	{
		$.blockUI({ message: 'Elaborazione in corso...' });
		$('.blockOverlay').attr('title','').click($.unblockUI);
		theForm.submit();
	}
}

function eseguiComando(comando,verifica,theForm,interrogazione,sottocomando)
{
	var ck = 'no';

	theForm.cmd.value=comando;
	if (verifica == 'A') annulla_controllo = 'si';
	else annulla_controllo = 'no';
	if (verifica == 'V')
	{
		if (confirm("L'elemento selezionato sta per essere eliminato\nContinuare?"))
		{
			ck = 'si';
		}
	}
	else if (verifica == 'I')
	{
		if (confirm(interrogazione))
		{
			ck = 'si';
		}
	}
	else
	{
		ck = 'si';
	}
	if (ck == 'si')
	{
		if (sottocomando != undefined)
		{
			theForm.sottocomando.value=sottocomando;
		}
		faiSubmitForm(theForm);
	}
}

function VerificaCampi(theForm)
{
    var ck = '';
    var out = '';
    var rc = true;
    
	if  (annulla_controllo == 'si')
	{
		return true;
	}
    for (i=0; i<theForm.elements.length; i++)
    {
		el = theForm.elements[i];
		if((el.getAttribute('rule') != null) && (el.style.visibility != 'hidden'))
		{
		    regEx = new RegExp(el.getAttribute('rule'), "");
		    regEx.compile(el.getAttribute('rule'));
		    var r = regEx.test(el.value);
		
		    if (!r)
		    {
                ck = 1;
                el.style.backgroundColor = "#FF0000";
                el.onfocus = resetColore;
                
                if (el.getAttribute('error') != null)
                {
                	out += el.getAttribute('error') + '\n';
                }
                else
                {
                	out += 'Errori nel campo ' + el.getAttribute('name') + '\n';
                }
		    }
		}
    }
    if (ck)
    {
    	if (out != '')
    	{
    		alert(out);
    	}
        return false;
	}
    else return true;
}

function resetColore()
{
	this.style.backgroundColor = "#FFFFFF";
	this.onfocus = '';
}
