var xmlHttp = getXmlHttpObject();
var waiting = false;
function validate(fldId, fldVal) 
{
	if (xmlHttp && !waiting) 
	{
		var data = "fldid=" + fldId + "&fldval=" + encodeURIComponent(fldVal);
		xmlHttp.open("POST", 'lc_validate.php', true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = stateChanged;
		xmlHttp.send(data);
		waiting = true;
	}
}

function stateChanged() 
{
	if(xmlHttp.readyState == 4) {
		//Stato OK
		if (xmlHttp.status == 200) 
		{
			var resp = xmlHttp.responseText;
			var p = resp.indexOf(';',0);
			if(p > 0) 
			{
				var fld = resp.substr(0,p);
				var msg = resp.substr(p+1);
				var cont = document.getElementById(fld + '_msg');
				if(msg) 
				{
					cont.className= 'error';
				} else {
					msg = '&nbsp;';
				}
				cont.innerHTML = msg;
			}
		}
		waiting = false;
	}
}

function getXmlHttpObject()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function toggleMe(id,valore) 
{
   var e = document.getElementById(id);
   if(id == 'divatt')
   	if(valore == 'Altro')
   		e.style.display = 'block';
   	else
   		e.style.display = 'none';
   else
   e.style.display = 'block';
}

function disabilitaInvio(id) 
{
   var e = document.getElementById(id);
   if(id == 'divinvio')
   	e.style.display = 'none';
   else
   	e.style.display = 'block';
}

function SwitchDiv(id) 
{
   var e = document.getElementById(id);
   if(e.style.display == 'block')
	e.style.display = 'none';
   else
	e.style.display = 'block';
}

