var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  try {
    // Firefox, Opera 8.0+, Safari
    xmlhttp=new XMLHttpRequest();
  }catch (e)  {
    // Internet Explorer
    try  {
     xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        xmlhttp = false;
      }
    }
  }
}


if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

function StreamRead(text) {
	this.text = text;
	this.pos=0;
	this.nextnl=0;
	this.readln = function() {

		// su Windows a capo = \r\n, su Unix invece solo \n
		var barraR = this.text.indexOf('\r', this.pos) == -1 ? 0 : 1;
		
		this.nextnl=this.nextnl == -1 ? -1 : this.text.indexOf('\n', this.pos);
		if (this.nextnl != -1) {
			var r=this.text.substr(this.pos, this.nextnl - this.pos - barraR);
			this.pos = this.nextnl + 1;
			return r;
		}		
		return '';
	}
	this.eos = function() {
		return (this.nextnl == -1);		
	}
}

function loadFill(url, target) {
  if (!xmlhttp) {
   alert("AJAX request unsupported!");
   return false;
  }
  try{
    
	  xmlhttp.open("POST", url, true);
  	if (typeof target == "object"){
 	  	var divToBeFilled = target;
 	  } else {
  		var divToBeFilled = document.getElementById(target);
  	}
  	var lingua = document.getElementById("codicelingua");
 	  
    if (lingua && "ENG" == lingua.value){
        divToBeFilled.innerHTML = "Please wait...";
    } else {
        divToBeFilled.innerHTML = "Attendere prego...";
	  }

    xmlhttp.onreadystatechange=function() {
      	if (xmlhttp.readyState==4) {
         	// alert(xmlhttp.responseText)
         	if (typeof target == "object")
         		var divToBeFilled = target;
         	else
         		var divToBeFilled = document.getElementById(target);

         	var t=xmlhttp.responseText;
         	divToBeFilled.innerHTML = t;         	
  	    }
  	};
    xmlhttp.send(null);
    
  } catch (e){
      alert(e);
      target.innerHTML = e;
  }
}

