var ts=0;
function ajaxSimplAlert(url,corr,err,funzioneDaEseguire,elthis,elthis2,chkclr,okmusic,funzioneDaEseguireNo){
var xmlHttpReq = false;
try{
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (err){
try{
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (err2){}
}
if(!xmlHttpReq && window.XMLHttpRequest){
xmlHttpReq=new XMLHttpRequest();
}

if(url.search(/\?/)>=0)
    nocache = '&nc='+Math.random();
else
    nocache = '?nc='+Math.random();


var originalClass
if(chkclr!=null){
originalClass=chkclr.className.split("ajax")[0]
chkclr.className=originalClass+" ajaxA";
}


xmlHttpReq.open("GET", url+nocache, true);
xmlHttpReq.send(null)
xmlHttpReq.onreadystatechange = function() {
if(xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {
if(url.search("ts=")>0){
    tsr=url.split("ts=")[1].split("&")[0]*1
    if(tsr>ts){
        ts=tsr
    }else{
        return false
    }
}
var value=xmlHttpReq.responseText.split("ç")[0].replace("\n","")
var message=xmlHttpReq.responseText.split("ç")[1]
var corretto=isResultCorrect(xmlHttpReq.responseText)
if (corretto>=0){
if(chkclr!=null){
chkclr.className=originalClass+" ajaxS";
}
if(corr!=null)
alert(corr+xmlHttpReq.responseText.split("ç")[0])
if(funzioneDaEseguire!=null)
eval(funzioneDaEseguire)
if(okmusic!=null)
    playMusic("oksound");
}else{
if(err==null)
	err=""
alert(err+displayError(xmlHttpReq.responseText.split("ç")[1]));
if(chkclr!=null){
chkclr.className=originalClass+" ajaxE";
}
if(funzioneDaEseguireNo!=null)
eval(funzioneDaEseguireNo)
}

if (corretto>=0){
	if(xmlHttpReq.responseText.split("ç")[1].split("~").length>1){
		if (eval("typeof " + ("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0]) + " == 'function'")) {
				eval("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0])
		}
	}
}
}
}
}


function ajaxSimpl(url,funzioneDaEseguire,elthis,elthis2){
var xmlHttpReq = false;
try{
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (err){
try{
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (err2){}
}
if(!xmlHttpReq && window.XMLHttpRequest){
xmlHttpReq=new XMLHttpRequest();
}

if(url.search(/\?/)>=0)
    nocache = '&nc='+Math.random();
else
    nocache = '?nc='+Math.random();
    
xmlHttpReq.open("GET", url+nocache, true);
xmlHttpReq.send(null)
xmlHttpReq.onreadystatechange = function() {
if(xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {

if(funzioneDaEseguire!=null)
eval(funzioneDaEseguire)
	
var corretto=isResultCorrect(xmlHttpReq.responseText)
if (corretto>=0){
	if(xmlHttpReq.responseText.split("ç")[1].split("~").length>1){
		if (eval("typeof " + ("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0]) + " == 'function'")) {
				eval("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0])
		}
	}
}
}
}
}

function ajaxInsertInTag(url,tagToChange,ajx,funzioneDaEseguire,elthis,sigalert,fdaerr){
	
var xmlHttpReq = false;
try{
xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (err){
try{
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}catch (err2){}
}
if(!xmlHttpReq && window.XMLHttpRequest){
xmlHttpReq=new XMLHttpRequest();
}

if(url.search(/\?/)>=0)
    nocache = '&nc='+Math.random();
else
    nocache = '?nc='+Math.random();


var originalClass
if(elthis!=null){
originalClass=elthis.className.split("ajax")[0]
elthis.className=originalClass+" ajaxA";
}

xmlHttpReq.open("GET", url+nocache, true);
xmlHttpReq.send(null)
xmlHttpReq.onreadystatechange = function() {
if(xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {

if(elthis!=null){
var corretto=isResultCorrect(xmlHttpReq.responseText)
if (corretto>=0){
elthis.className=originalClass+" ajaxS";
elthis.title="";
}else{
elthis.className=originalClass + " ajaxE";
elthis.title=("-Errore nell'operazione-\n"+displayError(xmlHttpReq.responseText.split("ç")[1]));
if(sigalert!=null)
alert("-Errore nell'operazione-\n"+displayError(xmlHttpReq.responseText.split("ç")[1]))
}
}


if (ajx==null || ajx==false){

    if(xmlHttpReq.responseText.search(/<form/)<0){
        tagToChange.innerHTML=xmlHttpReq.responseText
    }else{
        tagToChange.innerHTML=''
        var newdiv = document.createElement("div");
        newdiv.innerHTML = xmlHttpReq.responseText;
        tagToChange.appendChild(newdiv);
    }
if(funzioneDaEseguire!=null){
	eval(funzioneDaEseguire)
}
}else{
var corretto=isResultCorrect(xmlHttpReq.responseText)

	if(fdaerr==null || corretto>=0){
	    if(xmlHttpReq.responseText.search(/<form/)<0){
		tagToChange.innerHTML=xmlHttpReq.responseText.split("ç")[0];
	    }else{
		tagToChange.innerHTML=''
		var newdiv = document.createElement("div");
		newdiv.innerHTML = xmlHttpReq.responseText.split("ç")[0];
		tagToChange.appendChild(newdiv);
	    }
        }


    
if (corretto>=0){
    if(funzioneDaEseguire!=null)
       eval(funzioneDaEseguire)
}else{
    if(sigalert!=null)
    alert("-Errore di aggiornamento-\n"+displayError(xmlHttpReq.responseText.split("ç")[1]))
    if(fdaerr!=null)
       eval(fdaerr)
    
}
}
if (corretto>=0){
	if(xmlHttpReq.responseText.split("ç")[1].split("~").length>1){
		if (eval("typeof " + ("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0]) + " == 'function'")) {
				eval("PushFunction"+xmlHttpReq.responseText.split("ç")[1].split("~")[0])
		}
	}
}
}
}
}


function isResultCorrect(res){
var n=res.length;
while(n>=0 && (res.charAt(n-1)=="\n" || res.charAt(n-1)==" ")){
n--;
}
if(n>=0 && res.charAt(n-1)!="0")
return -1;
else
return n-1;
}

function displayError(res){
var n=res.length;
while(n>=0 && (res.charAt(n-1)=="\n" || res.charAt(n-1)==" ")){
n--;
}
if(n>=0)
n--
if(n>=0){
while(n>=0 && (res.charAt(n-1)=="\n" || res.charAt(n-1)==" ")){
n--;
}
}
return res.substring(0,n);
}

function ajaxriattribuisci(from,to,called,info,forceext){
    
    if(forceext){
        ajaxInsertInTag(info,document.getElementById(to));
    }else{
        if(document.getElementById(from)){
        ajaxInsertInTag(info,document.getElementById(from));
        }else{
        ajaxInsertInTag(called,document.getElementById(to),null,'ajaxInsertInTag("'+info+'",document.getElementById("'+from+'"));');
        };
    }
}


function ajaxSimplAlertPost(url,lab1,funzioneDaEseguire,elthis){
var xmlHttpReq;
var originalClass;
xmlHttpReq=new XMLHttpRequest();
var params = lab1;
xmlHttpReq.open("POST", url, true);
xmlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttpReq.setRequestHeader("Content-length", params.length);
xmlHttpReq.setRequestHeader("Connection", "close");
xmlHttpReq.onreadystatechange = function() {
}
xmlHttpReq.send(params);
}
