function PreparaDati(numcliente,ditta,operatore){
  stringa = "";
  stringa +="codcli"+"="+encodeURIComponent(numcliente)+"&"+"ditta"+"="+encodeURIComponent(ditta)+"&"+"op"+"="+encodeURIComponent(operatore);
  //*alert(stringa);
}

function PreparadatiMag(numproduttore,ditta,dataddt,numddt){
  stringa = "";
  //alert(numproduttore+' '+ditta+' '+dataddt+' '+numddt);
  stringa +="codpro"+"="+encodeURIComponent(numproduttore)+"&"+"ditta"+"="+encodeURIComponent(ditta)+"&"+"dataddt"+"="+encodeURIComponent(dataddt)+"&"+"nddt"+"="+encodeURIComponent(numddt);
  //alert(stringa);
}

function AJAXReq(method,url,bool){
  LoadingShow();
  if(window.XMLHttpRequest){
    myReq = new XMLHttpRequest();
  } else
 
  if(window.ActiveXObject){
    myReq = new ActiveXObject("Microsoft.XMLHTTP");
   
    if(!myReq){
      myReq = new ActiveXObject("Msxml2.XMLHTTP");
    }
  }
 
  if(myReq){
    execfunc(method,url,bool);
  }else{
    alert("Impossibilitati ad usare AJAX");
	LoadingHide();
  }
}

function execfunc(method,url,bool){
  myReq.onreadystatechange = handleResponse;
  myReq.open(method,url,bool);
  myReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  myReq.send(stringa);
}

function RicercaUt(){
	//alert('chiamato ricerca giacenze');
	indati = "ricercautenti";
	stringa = "";
	stringa +="dbdata"+'='+encodeURIComponent(dbditta);
	AJAXReq("POST","asp/ricud.asp",true);
}

function modificautid(id){
	//alert('chiamato modifica utenti '+id);
	indati = "modificautid";
	stringa = "";
	stringa +="id"+'='+encodeURIComponent(id);
	AJAXReq("POST","asp/modregon.asp",true);
}

function handleResponse(){
  //alert(indati);
  if(myReq.readyState == 4){
	//alert(indati);
    if(myReq.status == 200){
		if (indati=='logout'){
			//alert('logout');
			window.location.reload();
		}
		if (indati=='entersite'){
			//alert('entersite');
			window.location.reload();
		}
		if (indati=='invioreg'){
		}
		if (indati=='ricercautenti'){
			alert(myReq.responseText);
		}
		if (indati=='modificautid'){
			//alert(myReq.responseText);
			document.getElementById('regon').innerHTML=myReq.responseText;
			VisReg('cral');
		}
		if (indati=='ricercacampi'){
			document.getElementById('campi').innerHTML=myReq.responseText;
			apritask('9');
		}
		if (indati=='pagreg'){
			document.getElementById('regon').innerHTML=myReq.responseText;
		}
		if (indati=='invioreg'){
			//alert(myReq.responseText);
			if (myReq.responseText=='ok'){
				alert('Registrazione avvenuta correttamente!\nControlla la tua email se vuoi convalidare l\'account appena creato');
				ExitReg();
			}else{
				alert('Modifica presa in carico dal sistema');
				ExitReg();
			}
		}
		if (indati=='login'){
			//alert('ciao');
			if (myReq.responseText!=""){
				var separatore = '|';
				var mySplitResult = myReq.responseText.split(separatore);
				//alert(mySplitResult[0]);
				//alert(mySplitResult[1]);
			}else{
				LoadingHide();
				alert('Email o Password non corretta! Riprovare!');
				document.getElementById('login').value='';
				document.getElementById('password').value='password';
				document.getElementById('login').focus();
			}
			if (mySplitResult[0]=='yes'){
				document.getElementById('box-login').innerHTML=mySplitResult[1];
				RicercaCampi();
				alert('Benvenuto!');
				//document.location='index.asp';
			}else{
				if (mySplitResult[0]=='logout'){
					alert('Grazie per aver utilizzato il nostro servizio');
					document.getElementById('box-login').innerHTML=mySplitResult[1];
					RicercaCampi();
					//document.location='index.asp';
				}else{
					if (mySplitResult[0]=='no'){
					alert('Il tuo account non è convalidato, controlla nella tua mail se hai ricevuto il messaggio per la convalida!\nSe non hai ricevuto la mail contatta amministratore del sito.\nGrazie!');
					document.getElementById('box-login').innerHTML=mySplitResult[1];
					}
				}
			}
		}
		if (indati=='inviopren'){
			document.getElementById('rispcampo').innerHTML=myReq.responseText;
			document.getElementById('rispcampo').style.display='';
		}
		if (indati=='changesocio'){
			document.getElementById('changesocio').innerHTML=myReq.responseText;
		}
		if (indati=='prenotazione'){
			alert(myReq.responseText);
			//document.getElementById('frmConfPren').reset();
			RicercaCampi();
		}
		if (indati=='aprinews'){
			//alert(myReq.responseText);
			if (document.getElementById('pansx-tot')){
				var separatore = '|';
				var mySplitResult = myReq.responseText.split(separatore);
				//alert(mySplitResult[0]);
				//alert(mySplitResult[1]);
				document.title = mySplitResult[0];
				document.getElementById('pansx-tot').innerHTML = mySplitResult[1];
				//document.getElementById('pansx-tot').innerHTML=myReq.responseText;
				$("#fotonews").hide('');
				$(".pansx-tot").show('');
				$(".m").show('');
				//$(".pandx").hide('');
				//$("#dispcamp").show('');
			}else{
				alert('non ghe xe');
			}
		}
		if (indati=='apritask'){
			//alert(myReq.responseText);
			document.getElementById('pansx-tot').innerHTML=myReq.responseText;
		}
		if (indati=='contrcamper'){
			//alert(myReq.responseText);
			document.getElementById('campidati').innerHTML=myReq.responseText;
		}
		if (indati=='campiabilita'){
			alert(myReq.responseText);
			//LoadingHide();
			//alert(document.getElementById('datareq').value);
			RicercaCampi(document.getElementById('datareq').value);
		}
		LoadingHide();
	}else{;
	  LoadingHide();
      alert(" Riscontrato un problema nella pagina chiamata\n\nmodulo di risposta:\n"+indati+"\n\ndati inviati metodo post:\n"+stringa+"\n\nrisposta della pagina chiamata:\n"+myReq.responseText);
	  
    }
  }
}



