// JavaScript Document
function assegnaXMLHttpRequest() {
var
 XHR = null,
 browserUtente = navigator.userAgent.toUpperCase();
 
if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {

  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }
 return XHR;

}

function ParentAjaxGet(url,layer){
	var ajax = assegnaXMLHttpRequest();
	var r=Math.floor(Math.random()*10000)
	if(ajax) {
		ajax.open("get", url + "&r="+r, false);
 		ajax.send(null);
 		top.document.getElementById(layer).innerHTML=ajax.responseText;
 	}
 	else{
 		alert('Attenzione! Ajax non inizializzato');
 	}
}

function AjaxGet(url,layer){
	var ajax = assegnaXMLHttpRequest();
	var r=Math.floor(Math.random()*10000)
	if(ajax) {
		ajax.open("get", url + "&r="+r, false);
 		ajax.send(null);
 		document.getElementById(layer).innerHTML=ajax.responseText;
 	}
 	else{
 		alert('Attenzione! Ajax non inizializzato');
 	}
}

function AjaxGetWait(url, layer) {
	u = url;
	l = layer;

	setTimeout("AjaxGet(u,l);",0);
	document.getElementById(layer).innerHTML='<div id="attendere" style="text-align:center;width:90px;margin-top:'+((document.getElementById(layer).offsetHeight/2)-10)+'px;margin-left:'+((document.getElementById(layer).offsetWidth/2)-45)+'px;font-size:11px;"><br><p>Attendere prego</p></div>';
}

function AjaxGetAsync(url,layer,sort,js,wait){
	var ajax = assegnaXMLHttpRequest();
	var r=Math.floor(Math.random()*10000)
	if(ajax) {
	
		if(wait != 0){
			document.getElementById('body').style.cursor='wait';
	
			layerY = (Math.ceil(document.getElementById(layer).offsetHeight/2))-9;
			waitText = '<div id="attendere" style="text-align:center;margin-top:'+layerY+'px;font-size:11px;">Attendere prego</div>'
			if(document.getElementById(layer).offsetHeight > 50) {
				layerY-=20;
				waitText='<div id="attendere" style="text-align:center;margin-top:'+layerY+'px;font-size:11px;"><img alt="Spinner" src="images/spinner.gif" width="37" height="39" /></div>'
			}
			document.getElementById(layer).innerHTML=waitText;
		}
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if (js == 1) {
					setAndExecute(layer,ajax.responseText);
				}
				else {
					document.getElementById(layer).innerHTML=ajax.responseText;
				}
				if (sort == 1) $("#SortTable").tablesorter();
				document.getElementById('body').style.cursor='default';
			}
		}
		ajax.open("get", url + "&r="+r, true);
 		ajax.send(null);
 	}
 	else{
 		alert('Attenzione! Ajax non inizializzato');
 	}
}


function RepForm (valore) {
	var valore = valore;

	valore = valore.replace(/&/g,"___");
	valore = valore.replace(/'/g,"^^^");
	valore = valore.replace(/\n/g,"***");
	valore = valore.replace(/&acute;/g,"^^^");
	valore = valore.replace(/´/g,"^^^");
	valore = valore.replace(/[\"]/g,"|||");
	valore = valore.replace(/è/g,"(egrave)");
	valore = valore.replace(/é/g,"(eacute)");
	valore = valore.replace(/ì/g,"(igrave)");
	valore = valore.replace(/à/g,"(agrave)");
	valore = valore.replace(/ò/g,"(ograve)");
	valore = valore.replace(/ù/g,"(ugrave)");

	return valore;
}
