var xmlHttp;
var url="";
var strDaPas="";
var controllo;
var colonnaSelezionata="";
var tabella="";
var colonna="";
var azione="";
var suggerimento="";
var inputModificaPrec="hostIncaricato-0";
var mioForm="";
var questoDiv='';
var divPrec='chiSiamo';
var indiceScroll=0;
var indirizzo="";
//-----------------------COPIA-NASCONDI-------------

function mostra(azione,mioDiv)
{
if	(azione=='articoli')
	{
//	alert(mioDiv);
	indirizzo = './estraiArticoli.php'+ creaStrDaForm('moduloEstrazione')+'&';
	}
if	(azione=='articoliShopping')
	{
//	alert(mioDiv);
	indirizzo = './estraiArticoliShopping.php'+ creaStrDaForm('moduloEstrazione')+'&';
	}
else if	(azione=='nuovoArticolo')
	{
	//alert(mioDiv);
	indirizzo = './nuovoArticolo.php'+ creaStrDaForm('moduloEstrazione')+'&';
	}
else if	(azione=='inserisciArticolo')
	{
	//alert(mioDiv);
	indirizzo = './estraiArticoli.php'+ creaStrDaForm('moduloInserisci')+'&';
	}
else if	(azione=='invioRichiesta')
	{
indirizzo = './invioRichiesta.php?messaggio='+document.getElementById('areaTestoRichiesta')+'&';
	}
else 
	{
	//alert(mioDiv);
	indirizzo = azione +'&'; //caso dettaglioShop
	}
controllo=mioDiv;	

//alert(mioDiv);
//alert(indirizzo);
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 


indirizzo=indirizzo+"sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",indirizzo,true);
xmlHttp.send(null);

} 

function stateChanged() 
{ 
			if (xmlHttp.readyState==4)
			{ 
			
			stringa=xmlHttp.responseText;
			//alert(stringa);
			//alert(controllo);
			
			if(controllo=='dettaglioShopping')
				{
				nascondi('articoliShopping');
				esponi('dettaglioShopping');
				$(controllo).innerHTML=stringa;
				}
			else
				{
				//alert(controllo + stringa);
				$(controllo).innerHTML=stringa;
				}
			}
			
}






function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

 

function creaStrDaForm(unForm)
{
var identificativo;
var valore;
var segno;
var elemento;	
var ultimo;
var stringa='';
var pos=0;
var volta=1;
//crea la stringa da passare alla GET 
elemento=document.getElementById(unForm).elements;
ultimo=document.getElementById(unForm).elements.length -1;
//alert(ultimo);
for (i=0;i<=ultimo;i++)
	{
	
	i==0?segno='?':segno='&';	
	valore=elemento[i].value;	
	identificativo=elemento[i].id;		
	
	if((identificativo=='sessoM'||identificativo=='sessoF')&& volta==1 )
			{
			if (document.getElementById('sessoM').checked==true)
				{
				identificativo='sesso';
				 valore='M';
				}
			if (document.getElementById('sessoF').checked==true)
				{
				identificativo='sesso';
				 valore='F';
				}
			volta=2;
			}
	else if((identificativo=='sessoM'||identificativo=='sessoF')&& volta==2 )
		{
		continue;
		}	

	pos=identificativo.indexOf('-');
	//alert(valore);
	//alert(identificativo);
	//>=1 perchè voglio che ci sia almeno un carattere prima del -
	if (pos >= 1)
		{
		identificativo=left(identificativo,pos);
		}
	stringa+=segno+identificativo +'='+valore;
	}
	//alert(stringa);
	return stringa;
}


function intercetta()
{
if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4 ))
     {
	document.getElementById('corpo').scroll='no';
	} 

}


function $(identificativo)
{
return document.getElementById(identificativo);

}

function attiva(identificativo)
{
$('scelta').style.visibility='hidden';
$('spiegazione').style.visibility='visible';
$('contratto').style.visibility='visible';
$('pulsanti').style.visibility='visible';
if(identificativo=='campi')
	{
	$('campiImprese').style.visibility='hidden';
	$(identificativo).style.visibility='visible';
	}
if(identificativo=='campiImprese')
	{
	$('campi').style.visibility='hidden';
	$(identificativo).style.visibility='visible';
	}
}

function faiControlli()
{

var controllo=false;
//alert('qui');
if($('contrattoSI').checked==true)
	{
//alert('si');
	controllo=true;
	}
if (controllo==true)
	{
	$('modulo').submit();
	}
else
	{
//alert('no');
	alert('non possiamo proseguire con la registrazione spiacenti');
	}

if ($('meseDiNascita').value.length < 2)
	{
	$('meseDiNascita').value='0'+$('meseDiNascita').value;
	}
if ($('giornoDiNascita').value.length < 2 )
	{
	$('giornoDiNascita').value='0'+$('giornoDiNascita').value;
	}
if ($('annoDiNascita').value.length < 4)
	{
	alert('Abbiate cura di inserire nel campo anno di nascita un valore di quattro cifre (es. 1970)');
	}
}



function controllaSelect(valore)
{
if(valore=='nuovo')
{
$('nuovo').disabled=false;
}
else
{
$('nuovo').disabled=true;
}


}


function $(valore)
{

return document.getElementById(valore);
}

function doSubmit(pagina)
{
$('modulo').action=pagina;
$('modulo').submit();
}


function cancellaPrima(oggetto)
{
if(oggetto.value.substr(0,30) =='Inserisci qui la tua richiesta')
	{
	oggetto.value='';
	}

}

function esponi(valore)
{
$(valore).style.visibility='visible';
}
function nascondi(valore)
{
$(valore).style.visibility='hidden';
}
