var curTable;
var isIE;
var startAjax;
var isHtml;

function AJAXCall(url, tipoRis, Html, async)
{
	startAjax = true;
	DisplayOnLoading(1);
	isHtml=Html;
	isAsync=async;
  var ajax = new AJAXInteraction(url, tipoRis);
	ajax.send(null);
	if (isAsync==false)
  {
		ajax.procReq();
	}
}

function AJAXInteraction(url,caller) 
{
	var tipoRis = caller;
  var url = url;
  
  var req = init();
  
  if (isAsync==true)
  {
  	req.onreadystatechange = processRequest;
  }
  
  function init() 
  {
    if (window.XMLHttpRequest) 
    {
      return new XMLHttpRequest();
    } 
    else if (window.ActiveXObject) 
    {
      isIE = true;
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
    
  function processRequest () 
  {
    if (req.readyState == 4) 
    {
      if (req.status == 200) 
      {
        if (isIE)
        {
        	if (isHtml)
        	{
        		postProcess(req.responseText);
        	}
        	else
        	{
	          var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
			  		xmlDoc.async="false";
			  		xmlDoc.loadXML(req.responseText);
	          postProcess(xmlDoc);
          }
        }
        else
        {
	        if (isHtml)
        	{
        		postProcess(req.responseText);
        	}
        	else
        	{
          	postProcess(req.responseXML);
          }
        }
      }
      else
      {
        alert("Problemi nella risposta "+req.status+"\n"+req.responseText);
      }
    }
  }

  this.send = function() 
  {
    req.open("GET", url, isAsync);
    req.send(null);
  }
  
  this.procReq = function() 
  {
    processRequest();
  }
  
  function postProcess(responseXML)
	{		
		if (tipoRis=="regioni")
		{
			postProcessRegioni(responseXML);
		}
		else if (tipoRis=="provincie")
		{
			postProcessProvincie(responseXML);
		}
	  else if (tipoRis=="comuni")
	  {
	    postProcessComuni(responseXML);
	  }
	  else if (tipoRis=="aree")
	  {
	    postProcessAree(responseXML);
	  }
	  else if (tipoRis=="subaree")
	  {
	    postProcessSubAree(responseXML);
	  }
	  else if (tipoRis=="forecast")
	  {
	    postProcessForecast(responseXML);
	  }
	  else if (tipoRis=="forecastAree")
	  {
	    postProcessForecastAree(responseXML);
	  }
	  else if (tipoRis=="campigolf")
		{
			postProcessCampiGolf(responseXML);
		}
		else if (tipoRis=="forecastGolf")
	  {
	    postProcessForecastGolf(responseXML);
	  }
		DisplayOnLoading(0);
	  startAjax = false;
	}
}

function postProcessSpell(responseXML)
{
	alert(responseXML);
}
function Spelling()
{
	url = "../servlet/action?navigate=SpellAgent&usage=ajax&name=spell&content=chi lo sa";
  AJAXCall(url, tipoRis,false,true);
}


