function codificaascii(valore)//per convertire i caratteri in formato #numero# per poterli passare ad eventuali pagine ajax e viene utilizzata per l'invio di moduli)
{ 
	valore = valore.replace(/#/g,"valorecancelletto");
	valore = valore.replace(/\r/g,"valoreaccapo");
	valore = valore.replace(/0/g,"valorezero");
	valore = valore.replace(/1/g,"valoreuno");
	valore = valore.replace(/2/g,"valoredue");
	valore = valore.replace(/3/g,"valoretre");
	valore = valore.replace(/4/g,"valorequattro");
	valore = valore.replace(/5/g,"valorecinque");
	valore = valore.replace(/6/g,"valoresei");
	valore = valore.replace(/7/g,"valoresette");
	valore = valore.replace(/8/g,"valoreotto");
	valore = valore.replace(/9/g,"valorenove");
	valore = valore.replace(//g,"#1#");
	valore = valore.replace(//g,"#2#");
	valore = valore.replace(//g,"#3#");
	valore = valore.replace(//g,"#4#");
	valore = valore.replace(//g,"#5#");
	valore = valore.replace(//g,"#6#");
	valore = valore.replace(//g,"#7#");
	valore = valore.replace(//g,"#8#");
	valore = valore.replace(/	/g,"#9#");
	valore = valore.replace(//g,"#11#");
	valore = valore.replace(//g,"#12#");
	valore = valore.replace(//g,"#14#");
	valore = valore.replace(//g,"#15#");
	valore = valore.replace(//g,"#16#");
	valore = valore.replace(//g,"#17#");
	valore = valore.replace(//g,"#18#");
	valore = valore.replace(//g,"#19#");
	valore = valore.replace(//g,"#20#");
	valore = valore.replace(//g,"#21#");
	valore = valore.replace(//g,"#22#");
	valore = valore.replace(//g,"#23#");
	valore = valore.replace(//g,"#24#");
	valore = valore.replace(//g,"#25#");
	valore = valore.replace(//g,"#27#"); //il carattere 26 non permette di vedere oltre
	valore = valore.replace(//g,"#27#");
	valore = valore.replace(//g,"#28#");
	valore = valore.replace(//g,"#29#");
	valore = valore.replace(//g,"#30#");
	valore = valore.replace(//g,"#31#");
	valore = valore.replace(/ /g,"#32#");
	valore = valore.replace(/!/g,"#33#");
	valore = valore.replace(/"/g,"#34#");
	valore = valore.replace(/\$/g,"#36#");
	valore = valore.replace(/%/g,"#37#");
	valore = valore.replace(/&/g,"#38#");
	valore = valore.replace(/'/g,"#39#");
	valore = valore.replace(/\(/g,"#40#");
	valore = valore.replace(/\)/g,"#41#");
	valore = valore.replace(/\*/g,"#42#");
	valore = valore.replace(/\+/g,"#43#");
	valore = valore.replace(/\,/g,"#44#");
	valore = valore.replace(/\-/g,"#45#");
	valore = valore.replace(/\./g,"#46#");
	valore = valore.replace(/\//g,"#47#");
	valore = valore.replace(/:/g,"#58#");
	valore = valore.replace(/;/g,"#59#");
	valore = valore.replace(/</g,"#60#");
	valore = valore.replace(/=/g,"#61#");
	valore = valore.replace(/>/g,"#62#");
	valore = valore.replace(/\?/g,"#63#");
	valore = valore.replace(/@/g,"#64#");
	valore = valore.replace(/A/g,"#65#");
	valore = valore.replace(/B/g,"#66#");
	valore = valore.replace(/C/g,"#67#");
	valore = valore.replace(/D/g,"#68#");
	valore = valore.replace(/E/g,"#69#");
	valore = valore.replace(/F/g,"#70#");
	valore = valore.replace(/G/g,"#71#");
	valore = valore.replace(/H/g,"#72#");
	valore = valore.replace(/I/g,"#73#");
	valore = valore.replace(/J/g,"#74#");
	valore = valore.replace(/K/g,"#75#");
	valore = valore.replace(/L/g,"#76#");
	valore = valore.replace(/M/g,"#77#");
	valore = valore.replace(/N/g,"#78#");
	valore = valore.replace(/O/g,"#79#");
	valore = valore.replace(/P/g,"#80#");
	valore = valore.replace(/Q/g,"#81#");
	valore = valore.replace(/R/g,"#82#");
	valore = valore.replace(/S/g,"#83#");
	valore = valore.replace(/T/g,"#84#");
	valore = valore.replace(/U/g,"#85#");
	valore = valore.replace(/V/g,"#86#");
	valore = valore.replace(/W/g,"#87#");
	valore = valore.replace(/X/g,"#88#");
	valore = valore.replace(/Y/g,"#89#");
	valore = valore.replace(/Z/g,"#90#");
	valore = valore.replace(/\[/g,"#91#");
	valore = valore.replace(/\\/g,"#92#");
	valore = valore.replace(/]/g,"#93#");
	valore = valore.replace(/\^/g,"#94#");
	valore = valore.replace(/_/g,"#95#");
	valore = valore.replace(/`/g,"#96#");
	valore = valore.replace(/a/g,"#97#");
	valore = valore.replace(/b/g,"#98#");
	valore = valore.replace(/c/g,"#99#");
	valore = valore.replace(/d/g,"#100#");
	valore = valore.replace(/e/g,"#101#");
	valore = valore.replace(/f/g,"#102#");
	valore = valore.replace(/g/g,"#103#");
	valore = valore.replace(/h/g,"#104#");
	valore = valore.replace(/i/g,"#105#");
	valore = valore.replace(/j/g,"#106#");
	valore = valore.replace(/k/g,"#107#");
	valore = valore.replace(/l/g,"#108#");
	valore = valore.replace(/m/g,"#109#");
	valore = valore.replace(/n/g,"#110#");
	valore = valore.replace(/o/g,"#111#");
	valore = valore.replace(/p/g,"#112#");
	valore = valore.replace(/q/g,"#113#");
	valore = valore.replace(/r/g,"#114#");
	valore = valore.replace(/s/g,"#115#");
	valore = valore.replace(/t/g,"#116#");
	valore = valore.replace(/u/g,"#117#");
	valore = valore.replace(/v/g,"#118#");
	valore = valore.replace(/w/g,"#119#");
	valore = valore.replace(/x/g,"#120#");
	valore = valore.replace(/y/g,"#121#");
	valore = valore.replace(/z/g,"#122#");
	valore = valore.replace(/{/g,"#123#");
	valore = valore.replace(/\|/g,"#124#");
	valore = valore.replace(/}/g,"#125#");
	valore = valore.replace(/~/g,"#126#");
	valore = valore.replace(//g,"#127#");
	valore = valore.replace(//g,"#128#");
	valore = valore.replace(//g,"#129#");
	valore = valore.replace(//g,"#130#");
	valore = valore.replace(//g,"#131#");
	valore = valore.replace(//g,"#132#");
	valore = valore.replace(//g,"#133#");
	valore = valore.replace(//g,"#134#");
	valore = valore.replace(//g,"#135#");
	valore = valore.replace(//g,"#136#");
	valore = valore.replace(//g,"#137#");
	valore = valore.replace(//g,"#138#");
	valore = valore.replace(//g,"#139#");
	valore = valore.replace(//g,"#140#");
	valore = valore.replace(//g,"#141#");
	valore = valore.replace(//g,"#142#");
	valore = valore.replace(//g,"#143#");
	valore = valore.replace(//g,"#144#");
	valore = valore.replace(//g,"#145#");
	valore = valore.replace(//g,"#146#");
	valore = valore.replace(//g,"#147#");
	valore = valore.replace(//g,"#148#");
	valore = valore.replace(//g,"#149#");
	valore = valore.replace(//g,"#150#");
	valore = valore.replace(//g,"#151#");
	valore = valore.replace(//g,"#152#");
	valore = valore.replace(//g,"#153#");
	valore = valore.replace(//g,"#154#");
	valore = valore.replace(//g,"#155#");
	valore = valore.replace(//g,"#156#");
	valore = valore.replace(//g,"#157#");
	valore = valore.replace(//g,"#158#");
	valore = valore.replace(//g,"#159#");
	valore = valore.replace(//g,"#160#");
	valore = valore.replace(//g,"#161#");
	valore = valore.replace(//g,"#162#");
	valore = valore.replace(//g,"#163#");
	valore = valore.replace(//g,"#164#");
	valore = valore.replace(//g,"#165#");
	valore = valore.replace(//g,"#166#");
	valore = valore.replace(//g,"#167#");
	valore = valore.replace(//g,"#168#");
	valore = valore.replace(//g,"#169#");
	valore = valore.replace(//g,"#170#");
	valore = valore.replace(//g,"#171#");
	valore = valore.replace(//g,"#172#");
	valore = valore.replace(//g,"#173#");
	valore = valore.replace(//g,"#174#");
	valore = valore.replace(//g,"#175#");
	valore = valore.replace(//g,"#176#");
	valore = valore.replace(//g,"#177#");
	valore = valore.replace(//g,"#178#");
	valore = valore.replace(//g,"#179#");
	valore = valore.replace(//g,"#180#");
	valore = valore.replace(//g,"#181#");
	valore = valore.replace(//g,"#182#");
	valore = valore.replace(//g,"#183#");
	valore = valore.replace(//g,"#184#");
	valore = valore.replace(//g,"#185#");
	valore = valore.replace(//g,"#186#");
	valore = valore.replace(//g,"#187#");
	valore = valore.replace(//g,"#188#");
	valore = valore.replace(//g,"#189#");
	valore = valore.replace(//g,"#190#");
	valore = valore.replace(//g,"#191#");
	valore = valore.replace(//g,"#192#");
	valore = valore.replace(//g,"#193#");
	valore = valore.replace(//g,"#194#");
	valore = valore.replace(//g,"#195#");
	valore = valore.replace(//g,"#196#");
	valore = valore.replace(//g,"#197#");
	valore = valore.replace(//g,"#198#");
	valore = valore.replace(//g,"#199#");
	valore = valore.replace(//g,"#200#");
	valore = valore.replace(//g,"#201#");
	valore = valore.replace(//g,"#202#");
	valore = valore.replace(//g,"#203#");
	valore = valore.replace(//g,"#204#");
	valore = valore.replace(//g,"#205#");
	valore = valore.replace(//g,"#206#");
	valore = valore.replace(//g,"#207#");
	valore = valore.replace(//g,"#208#");
	valore = valore.replace(//g,"#209#");
	valore = valore.replace(//g,"#210#");
	valore = valore.replace(//g,"#211#");
	valore = valore.replace(//g,"#212#");
	valore = valore.replace(//g,"#213#");
	valore = valore.replace(//g,"#214#");
	valore = valore.replace(//g,"#215#");
	valore = valore.replace(//g,"#216#");
	valore = valore.replace(//g,"#217#");
	valore = valore.replace(//g,"#218#");
	valore = valore.replace(//g,"#219#");
	valore = valore.replace(//g,"#220#");
	valore = valore.replace(//g,"#221#");
	valore = valore.replace(//g,"#222#");
	valore = valore.replace(//g,"#223#");
	valore = valore.replace(//g,"#224#");
	valore = valore.replace(//g,"#225#");
	valore = valore.replace(//g,"#226#");
	valore = valore.replace(//g,"#227#");
	valore = valore.replace(//g,"#228#");
	valore = valore.replace(//g,"#229#");
	valore = valore.replace(//g,"#230#");
	valore = valore.replace(//g,"#231#");
	valore = valore.replace(//g,"#232#");
	valore = valore.replace(//g,"#233#");
	valore = valore.replace(//g,"#234#");
	valore = valore.replace(//g,"#235#");
	valore = valore.replace(//g,"#236#");
	valore = valore.replace(//g,"#237#");
	valore = valore.replace(//g,"#238#");
	valore = valore.replace(//g,"#239#");
	valore = valore.replace(//g,"#240#");
	valore = valore.replace(//g,"#241#");
	valore = valore.replace(//g,"#242#");
	valore = valore.replace(//g,"#243#");
	valore = valore.replace(//g,"#244#");
	valore = valore.replace(//g,"#245#");
	valore = valore.replace(//g,"#246#");
	valore = valore.replace(//g,"#247#");
	valore = valore.replace(//g,"#248#");
	valore = valore.replace(//g,"#249#");
	valore = valore.replace(//g,"#250#");
	valore = valore.replace(//g,"#251#");
	valore = valore.replace(//g,"#252#");
	valore = valore.replace(//g,"#253#");
	valore = valore.replace(//g,"#254#");
	valore = valore.replace(//g,"#255#");
	return valore;
}

function setEqual(a,b,c,d) {
	// a,b,c sono le due colonne interne al corpo mentre d  il div del corpo che va regolato in base al valore massimo
    if (document.getElementById) {
        var divs = new Array(document.getElementById(a), document.getElementById(b), document.getElementById(c),document.getElementById(d));
        var CHeight = 0;
        var BHeight = 0;
		var AHeight = 0;
		AHeight = divs[0].offsetHeight; // salvo l'altezza della prima colonna
        BHeight = divs[1].offsetHeight; // salvo l'altezza della seconda colonna
        CHeight = divs[2].offsetHeight; // salvo l'altezza della terza colonna
		altezzamassima = 0;
		if (AHeight > BHeight) {
			if (AHeight > CHeight) {
				altezzamassima = AHeight
			} 
			else {
				altezzamassima = CHeight
			}
		}
		else {
			if (BHeight > CHeight) {
				altezzamassima = BHeight
			} 
			else {
				altezzamassima = CHeight
			}
		}
		// bisogna stabilire quale dei tre div  il pi grande e settare il quarto con tale valore!!!
		
        divs[3].style.height = altezzamassima + 'px';
    }
}

//funzione per il caricamento esterno di un css ( server per hack particolari in irefox)
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

function avvio() {
	versionebrowser = navigator.userAgent
	if (versionebrowser.indexOf('Firefox') > -1 ) //richiamiamo l'hack per firefox
	{
	//loadjscssfile("/css/style_firefox_20100604.css", "css") ////dynamically load and add this .css file
	} 
	//setEqual('corpo-colonna1','corpo-colonna2','corpo-colonna3','corpo');
	if ( document.getElementById("q") ) {
		//document.cerca.q.focus();
	}
	}
function nascondi(id){
	if ( document.getElementById(id) ) {
	document.getElementById(id).style.display = 'none';
	}
}
function visualizza(id){
	if ( document.getElementById(id) ) {
	document.getElementById(id).style.display = 'block';
	}
}
function cambia(formmodulo,modulo,formmoduloid,id) {
	var nuovovalore;
	eval("nuovovalore=document."+formmodulo+"."+modulo+".value");
	nuovovalore = nuovovalore.replace(/\n/g,"<br>");
	//nuovovalore = nuovovalore.replace(/\r/g,"<br>");
	if (formmoduloid == '') {
	document.getElementById(id).innerHTML = nuovovalore;
	} else {
	eval("document."+formmoduloid+"."+id+".value='"+nuovovalore+"'");
	}
}
function cambiavalore(id,testo){
	if ( document.getElementById(id) ) {
	document.getElementById(id).innerHTML = testo;
	}
}
function vai(id){
	location.href = id;
}
function azzeraricerca() {
    if (document.getElementById("q")) {
         if (document.getElementById("q").value == "Cosa stai cercando?") {
        	document.getElementById("q").value = "";
    	}
    }
}
function cerca() {
	if (document.getElementById("q") && document.getElementById("urlbase")) {
		ricerca = document.cerca.q.value;
		if (ricerca != "") {
			ricerca = ricerca.replace(/ /g,"_");
			ricerca = document.getElementById("urlbase").value + "q/" + ricerca
			location.href = ricerca;
		}
	}
}
function cambiaimmagine(foto,numerofoto) {
	if (document.getElementById('contenitorefoto')) {
		elencofoto = foto.split("|")
		//clearTimeout(document.getElementById('valoretempoarticolihome').value);
		numero = numerofoto;
		massimo = (elencofoto.length);
		numero = numero*1+1
		if (numero*1>=massimo*1) {
			numero = 1
			}
		fotodamostrare = foto.split("|")
		for (i=numerofoto; i<=numerofoto; i++ ) {   //istruzioni } 
		document.getElementById('contenitorefoto').innerHTML = "<a href='/img/galleriasfondi/" + fotodamostrare[i] + "' target='_blank'><img src='/img/galleria/" + fotodamostrare[i] + "' width='504' height='302'/></a>";
		g = setTimeout("cambiaimmagine('"+foto+"',"+numero+")",5000) //5000 millisecondi cio 5 secondi/
		}
	}
}

function svuotavideo() {
	if (document.getElementById('contenitorevideo')) {
		nascondi('contenitorevideo');
		visualizza('contenitorefoto');
		document.getElementById('contenitorevideo').innerHTML = "";
	}
}
function caricavideo(video,titolo,testo) {
	if (document.getElementById('contenitorevideo')) {
		nascondi('contenitorefoto');
		visualizza('contenitorevideo');
		document.getElementById('contenitorevideo').innerHTML = "<object width='504' height='302'><param name='movie' value='http://www.youtube.com/v/" + video + "?fs=1&amp;hl=it_IT&amp;rel=0&amp;autoplay=1&amp;loop=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + video + "?fs=1&amp;hl=it_IT&amp;rel=0&amp;autoplay=1&amp;loop=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='504' height='302' background='transparent'></embed></object>";
	}
}

function addcart(id) {
	eval("quantita = document.addcart"+id+".quantita.value");
	eval("codice = document.addcart"+id+".prodotto.value");
	//eval("testo = document.addcart"+id+".submit.value");
	//window.alert(testo);
	if(window.XMLHttpRequest)
	{
	   richiestaricerca = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
	}
	richiestaricerca.open("POST", "/ajax/addcart.asp", true);
	richiestaricerca.onreadystatechange = function() 
	{
		if(richiestaricerca.readyState == 4)
		{	
			if(richiestaricerca.status == 200)
			{
				rispostaricerca = richiestaricerca.responseText
				var mySplitResultb = rispostaricerca.split("###");
				errore = mySplitResultb[0];
				nomeimmagine = mySplitResultb[1];
				totalecarrello =  mySplitResultb[2];
				//lingua = mySplitResultb[2];
				if (errore != "" && errore != undefined) {
					document.getElementById('testoseleziona').innerHTML = "Errore: " + errore + " - Riprovare";
					} else {
						if (nomeimmagine != "" && nomeimmagine != undefined) {
							//window.alert(quantitacarrello)
							visualizza('carrellodx');
							eval("document.addcart"+id+".submit.value='Aggiunto'");
							eval("document.addcart"+id+".submit.style.background = 'url(/layout/bottoni_acquista.png) 0 -44px no-repeat'");
							//document.addcart1.submit.style.background = "url(/layout/bottoni_acquista.png) 0 -88px no-repeat";
							document.getElementById('carrellodx').innerHTML = nomeimmagine;
							document.getElementById('carrellodx').innerHTML = "<a href='/p/t/carrello'>"+totalecarrello+" &euro;</a>";
							//visualizza('erroretaglia');
						} else {
							//nascondi('erroretaglia')
						}
				}
			}
		}
	}
	richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	richiestaricerca.send("q="+quantita+"&c="+codice);
	
	
	//location.href = "/ajax/addcart.asp?q="+quantita+"&c="+codice
	//window.alert(codice + quantita)
}

//genera nuova serp
function serp(tp,lk) { //
	if(window.XMLHttpRequest)
	{
	   richiestaricerca = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
	}
	richiestaricerca.open("POST", "/ajax/filtraserp/", true);
	richiestaricerca.onreadystatechange = function() 
	{
		if(richiestaricerca.readyState == 4)
		{	
			if(richiestaricerca.status == 200)
			{
				vai("/it_it/v/ricerca/");
			}
			else
			{
				//document.getElementById('statocaricamento').innerHTML = "Errore Server " + richiestaricerca.status;
			}
		}
		else
		{
				//document.getElementById('statocaricamento').innerHTML = "Loading...";
		}
	}
	richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	richiestaricerca.send("tp="+tp+"&lk="+lk);
}


////apre in target_blankl
////apertura link balnk sennza target
/*
addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
*/
function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

/*
Create the new window
*/
function openInNewWindow() {
	// Change "_blank" to something like "newWindow" to load all links in the same new window
    var newWindow = window.open(this.getAttribute('href'), '_blank');
    newWindow.focus();
    return false;
}

/*
Add the openInNewWindow function to the onclick event of links with a class name of "new-window"
*/
function getNewWindowLinks() {
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Change this to the text you want to use to alert the user that a new window will be opened
		//var strNewWindowAlert = "" //" (opens in a new window)";
		var strNewWindowAlert = "";
		// Find all links
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var strWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\btargetblank\b/.exec(link.className)) {
				// Create an em element containing the new window warning text and insert it after the link text
				objWarningText = document.createElement("em");
				strWarningText = document.createTextNode(strNewWindowAlert);
				objWarningText.appendChild(strWarningText);
				link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);////fine apre target blank//////////////

//////FORM REGISTRAZIONE
//registrazione utente
function mostracampiperdestinatario() {
	tipodestinatario = document.getElementById('tiporegistrazione').value;
	if (tipodestinatario == 1) {
		nascondi('bloccodatiaziendali');
		nascondi('bloccorivenditore')
		visualizza('bloccodatipersonali');
		visualizza('bloccoregistrazionebase');
		visualizza('bloccoindirizzo');
		visualizza('tipopagamento');
		visualizza('bloccoinvia')
		visualizza('bloccocodfiscpersona')
	} else if (tipodestinatario == 2 ) {
		visualizza('bloccodatiaziendali');
		nascondi('bloccorivenditore')
		visualizza('bloccodatipersonali');
		visualizza('bloccoregistrazionebase');
		visualizza('bloccoindirizzo');
		visualizza('tipopagamento');
		visualizza('bloccoinvia')
		nascondi('bloccocodfiscpersona')
	} else if (tipodestinatario == 3 ) {
		visualizza('bloccodatiaziendali');
		visualizza('bloccorivenditore')
		visualizza('bloccodatipersonali');
		visualizza('bloccoregistrazionebase');
		visualizza('bloccoindirizzo');
		visualizza('tipopagamento');
		visualizza('bloccoinvia')
		nascondi('bloccocodfiscpersona')
	} else if (tipodestinatario == 4 ) {
		visualizza('bloccodatiaziendali');
		visualizza('bloccorivenditore')
		visualizza('bloccodatipersonali');
		visualizza('bloccoregistrazionebase');
		visualizza('bloccoindirizzo');
		visualizza('tipopagamento');
		visualizza('bloccoinvia')
		nascondi('bloccocodfiscpersona')
	} else {
		nascondi('bloccodatiaziendali');
		nascondi('bloccorivenditore')
		nascondi('bloccodatipersonali');
		nascondi('bloccoregistrazionebase');
		nascondi('bloccoindirizzo');
		nascondi('tipopagamento');
		nascondi('bloccoinvia')
		nascondi('bloccocodfiscpersona')
	}
	if ( document.getElementById('id2utente').value != '') {
		nascondi('bloccoregistrazionebase');
	}
}
function prendisolonumeri(id) {
	var solonumeri = '';
	for(var n=0; n<id.length; n++) {
		var i = id.substring(n,n+1);
		if (i=='1'||i=='2'||i=='3'||i=='4'||i=='5'||i=='6'||i=='7'||i=='8'||i=='9'||i=='0') {
			solonumeri += i;
			}
		}
		//return parseInt(solonumeri);
		return solonumeri;
		
	}
	
function colora(id) {
	if (document.getElementById(id) && document.getElementById('valore'+id)) {
		if (document.getElementById('valore'+id).value == document.getElementById(id).value) {
			document.getElementById(id).style.color = "#000000";
			document.getElementById(id).value = "";
			}
		}
	}
function controllazero(id) {
	if (document.getElementById(id) && document.getElementById('valore'+id)) {
		if (document.getElementById(id).value == "") {
			document.getElementById(id).style.color = "#999999";
			document.getElementById(id).value = document.getElementById('valore'+id).value;
			}
		}
	}
function controllocap() {
	var regexpcapitalia = /^(V-|I-)?[0-9]{4,5}$/
	if (document.getElementById('cap') && document.getElementById('spancap')) {
		document.getElementById('cap').style.color = "#000000"
		document.getElementById('spancap').innerHTML = "";
		cap = document.getElementById('cap').value.toUpperCase()
		if (!regexpcapitalia.test(cap)) {
			document.getElementById('cap').style.color = "#cc0000"
			document.getElementById('spancap').innerHTML = "C.A.P. non valido";
			}
		}
	}
function controllapartitaiva(nomeblocco,tipopartitaiva) {
	var errorepiva = 0;
	if (document.getElementById(nomeblocco)) {
	document.getElementById(nomeblocco).style.color = "#000000"
	document.getElementById(nomeblocco).style.border = "1px solid #7F9DB9"
	}
	if (document.getElementById('span'+nomeblocco)) {
	document.getElementById('span'+nomeblocco).style.display = "none";
	}
	var regexpcodfisc = /^[A-Za-z]{6}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{3}[A -Za-z]{1}$/ 
	var regexpivaita = /^(IT){0,1}[0-9]{11}$/
	if (document.getElementById(nomeblocco) && document.getElementById('stato')) {
		partitaiva = document.getElementById(nomeblocco).value
		partitaiva = partitaiva.toUpperCase()
		stato = document.getElementById('stato').value
		stato = stato.toUpperCase()
		if (stato == 'IT') { //in questo caso la partita iva pu essere composta da IT + 11 umeri o da 11 numeri o potrebbe essere uguale ad un codice fiscale
			if (!regexpivaita.test(partitaiva)) {
				stato = "" //importante per il controllo finale per aggiungere le due lettere se la partita iva non  in formato partita iva nojn aggiungiamo nulla
				if (!regexpcodfisc.test(partitaiva)) {
					errorepiva = 1
				}
			}
		}  else if (stato == 'DK' || stato == 'FI' || stato == 'HU' || stato == 'LU' || stato == 'MT' || stato == 'SI' || stato == 'BE' || stato == 'EE' || stato == 'DE' || stato == 'GR' || stato == 'LT' || stato == 'PT' || stato == 'PL' || stato == 'SK' || stato == 'LV' || stato == 'LT' || stato == 'SE' || stato == 'AT' || stato == 'CY' || stato == 'CZ' || stato == 'FR' || stato == 'IE' || stato == 'NL' || stato == 'ES' || stato == 'GB') {
			errorepiva = 0
			if (stato == 'BE') {
				regexpiva = /^(BE){0,1}[0]{0,1}[0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'CY') {
				regexpiva = /^(CY){0,1}[0-9]{8}[A-Z]$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'CZ') {
				regexpiva = /^(CZ){0,1}[0-9]{8,10}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'DK') {
				regexpiva = /^(DK){0,1}([0-9]{2}\ ){3}[0-9]{2}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'EE') {
				regexpiva = /^(EE){0,1}[0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'FI') {
				regexpiva = /^(FI){0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'FR') {
				regexpiva = /^(FR){0,1}[0-9A-Z]{2}\ [0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'DE') {
				regexpiva = /^(DE){0,1}[0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'GR') {
				stato = "EL" //importante per il controllo finale per aggiungere le due lettere
				regexpiva = /^(EL){0,1}[0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'HU') {
				regexpiva = /^(HU){0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'IE') {
				regexpiva = /^(IE){0,1}[0-9][0-9A-Z\+\*][0-9]{5}[A-Z]$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'IT') {
				regexpiva = /^(IT){0,1}[0-9]{11}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'LV') {
				regexpiva = /^(LV){0,1}[0-9]{11}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'LT') {
				regexpiva = /^(LT){0,1}([0-9]{9}|[0-9]{12})$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'LU') {
				regexpiva = /^(LU){0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'MT') {
				regexpiva = /^(MT){0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'NL') {
				regexpiva = /^(NL){0,1}[0-9]{9}B[0-9]{2}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'PL') {
				regexpiva = /^(PL){0,1}[0-9]{10}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'PT') {
				regexpiva = /^(PT){0,1}[0-9]{9}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'SK') {
				regexpiva = /^(SK){0,1}[0-9]{10}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'SI') {
				regexpiva = /^(SI){0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'ES') {
				regexpiva = /^(ES){0,1}([0-9A-Z][0-9]{7}[A-Z])|([A-Z][0-9]{7}[0-9A-Z])$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'SE') {
				regexpiva = /^(SE){0,1}[0-9]{12}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'UK') {
				stato = "GB" //importante per il controllo finale per aggiungere le due lettere
				regexpiva = /^(GB){0,1}([1-9][0-9]{2}\ [0-9]{4}\ [0-9]{2})|([1-9][0-9]{2}\ [0-9]{4}\ [0-9]{2}\ [0-9]{3})|((GD|HA)[0-9]{3})$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			} else if (stato == 'AT') {
				regexpiva = /^(AT){0,1}[U]{0,1}[0-9]{8}$/
				if (!regexpiva.test(partitaiva)) {
					errorepiva = 1
				}
			}
			
		}
		if (errorepiva == 1) {
			if (document.getElementById(nomeblocco)) {
			document.getElementById(nomeblocco).style.color = "#ff0000"
			document.getElementById(nomeblocco).style.border = "1px solid #ff0000"
			}
			if (document.getElementById('span'+nomeblocco)) {
			document.getElementById('span'+nomeblocco).style.color = "#000000"
			document.getElementById('span'+nomeblocco).style.display = "block";
			}
			return true;
		} else  {
			if (tipopartitaiva == 1) { // allora  una partita iva e non un codice fiscale
				if (partitaiva.slice(0,2) != stato ) {
					partitaiva = stato + partitaiva
					}
				}
			document.getElementById(nomeblocco).value = partitaiva
			return false;
		} 
	}
}


function controllaobbligo(nomeblocco,valore,regexp) {
	if (document.getElementById(nomeblocco)) {
	document.getElementById(nomeblocco).style.color = "#000000"
	document.getElementById(nomeblocco).style.border = "1px solid #7F9DB9"
	}
	if (document.getElementById('span'+nomeblocco)) {
	document.getElementById('span'+nomeblocco).style.display = "none";
	}
	regexpemail = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+/
	regexpusr = /^([1-zA-Z0-1_.\-\s]{6,32})/
	regexpsms = /^([+]39)?((38[{8,9}|0])|(34[{6-9}|0])|(39[{2-3}|0])|(37[{7-9}|0])|(36[6|8|0])|(33[{3-9}|0])|(32[{8,9}]))([\d]{6,7})$/ //sms italia
	regexpsitoweb = /^(http\:\/\/|www.)+[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}/
	regexpnome = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/
	regexpskype = /^([1-zA-Z0-1_.\-\s]{6,32})/
	regexptelefono = /^([+|])?([1-9]*\-?\ ?\/?[0-9\.\-\ \/]*)$/
	regexpcapitaliano = /^(V-|I-)?[0-9]{5}$/
	regexpcodfiscita = /^[A-Za-z]{6}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{2}[A-Za-z]{1}[0-9LMNPQRSTUV]{3}[A -Za-z]{1}$/
	regexpcampoobbligatorio = /.{1,100}/
	regexpdatanascita = /^\d{1,2}[-\/\.]\d{1,2}[-\/\.]\d{2,4}$/
	
	espressione = eval(regexp)
	if (!espressione.test(valore)) {
		if (document.getElementById(nomeblocco)) {
		document.getElementById(nomeblocco).style.color = "#ff0000"
		document.getElementById(nomeblocco).style.border = "1px solid #ff0000"
		}
		if (document.getElementById('span'+nomeblocco)) {
		document.getElementById('span'+nomeblocco).style.color = "#000000"
		document.getElementById('span'+nomeblocco).style.display = "block";
		}
		return true;
	} else {
		return false;
	}
}

function cambianazione(modulo,t,modulosostituto,campofrazioni) {
	if (document.getElementById('stato').value=="it") {
		visualizza('indirizzoitalia');
		nascondi('indirizzointernazionale');
		document.getElementById('cap').value = ""
		document.getElementById('cap').style.color = "#000000"
		document.getElementById('spancap').innerHTML = "";
		campomodulo = "fieldset"+modulosostituto
		q = document.getElementById(modulo).value
		chiamamenu(q,t,campomodulo,campofrazioni)
	}
	else 
	{
		nascondi('indirizzoitalia');
		visualizza('indirizzointernazionale');
	}
}

function esisteuser(user) {
	document.getElementById('spanusr').style.display = "none";
	document.getElementById('usr').style.color = "#000000"
	if(window.XMLHttpRequest)
		{
		   richiestaricerca = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
		   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
		}
		richiestaricerca.open("POST", "/ajax/controlloesisteuser.asp", true);
		richiestaricerca.onreadystatechange = function() 
		{
			if(richiestaricerca.readyState == 4)
			{	
				if(richiestaricerca.status == 200)
				{
					rispostaricerca = richiestaricerca.responseText
					//window.alert(rispostaricerca)
					if (rispostaricerca == 1)
						{
							errore = 1
							document.getElementById('spanusr').style.display = "block";
							document.getElementById('spanusr').style.color = "#000000"
							document.getElementById('usr').style.color = "#ff0000"
							return true;
						} else {
							return false;
							
						}
				}
			}
		}
		richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		richiestaricerca.send("q="+document.formregistra.usr.value);
		
}
function esisteemail(email) {
	document.getElementById("email").style.border = "1px solid #7F9DB9"
	document.getElementById('spanemail').style.display = "none";
	document.getElementById('email').style.color = "#000000"
	if(window.XMLHttpRequest)
		{
		   richiestaricerca = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{
		   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
		}
		richiestaricerca.open("POST", "/ajax/controlloesisteuser.asp", true);
		richiestaricerca.onreadystatechange = function() 
		{
			if(richiestaricerca.readyState == 4)
			{	
				if(richiestaricerca.status == 200)
				{
					rispostaricerca = richiestaricerca.responseText
					//window.alert(rispostaricerca)
					if (rispostaricerca == 1)
						{
							errore = 1
							document.getElementById('spanemail').style.display = "block";
							document.getElementById('spanemail').style.color = "#000000"
							document.getElementById('email').style.color = "#ff0000"
							document.getElementById("email").style.border = "1px solid #cccccc"
							return true;
						} else {
							return false;
							
						}
				}
			}
		}
		richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		richiestaricerca.send("a="+document.formregistra.email.value);
		
}

function startModificaRegistra() {
	document.getElementById('telefono').style.color = "#999999"
	document.getElementById("telefono").style.border = "1px solid #7F9DB9"
	document.getElementById('prefisso').style.color = "#999999"
	document.getElementById("prefisso").style.border = "1px solid #7F9DB9"
	document.getElementById('telefonoaz').style.color = "#999999"
	document.getElementById("telefonoaz").style.border = "1px solid #7F9DB9"
	document.getElementById('prefissoaz').style.color = "#999999"
	document.getElementById("prefissoaz").style.border = "1px solid #7F9DB9"
	errore = 0;
	document.getElementById("partitaiva").style.color = "#000000"
	document.getElementById("partitaiva").style.border = "1px solid #7F9DB9"
	document.getElementById("codfiscazienda").style.color = "#000000"
	document.getElementById("codfiscazienda").style.border = "1px solid #7F9DB9"
	document.getElementById("codfiscpersona").style.color = "#000000"
	document.getElementById("codfiscpersona").style.border = "1px solid #7F9DB9"
	tiporichiesta = document.getElementById("tiporichiesta").value;
	id2utente = document.getElementById("id2utente").value;
	tiporegistrazione = document.getElementById("tiporegistrazione").value;
	usr = document.getElementById("usr").value;
	email = document.getElementById("email").value;
	cognomeoragsoc = document.getElementById("cognomeoragsoc").value;
	nomeovetrina = document.getElementById("nomeovetrina").value;
	partitaiva = document.getElementById("partitaiva").value;
	codfiscazienda = document.getElementById("codfiscazienda").value;
	emailpec = document.getElementById("emailpec").value;
	prefissoaz = document.getElementById("prefissoaz").value;
	telefonoaz = document.getElementById("telefonoaz").value;
	prefissofaxaz = document.getElementById("prefissofaxaz").value;
	telefonofaxaz = document.getElementById("telefonofaxaz").value;
	categoria1 = document.getElementById("categoria1").value;
	sitoweb = document.getElementById("sitoweb").value;
	//logoaziendale = document.getElementById("logoaziendale").value;
	//visuracamerale = document.getElementById("visuracamerale").value;
	titolopersona = document.getElementById("titolopersona").value;
	nomeovetrinab = document.getElementById("nomeovetrinab").value;
	cognomeoragsocb = document.getElementById("cognomeoragsocb").value;
	sottotitolopersona = document.getElementById("sottotitolopersona").value;
	codfiscpersona = document.getElementById("codfiscpersona").value;
	prefisso = document.getElementById("prefisso").value;
	telefono = document.getElementById("telefono").value;
	prefissocell = document.getElementById("prefissocell").value;
	telefonocell = document.getElementById("telefonocell").value;
	prefissofax = document.getElementById("prefissofax").value;
	telefonofax = document.getElementById("telefonofax").value;
	skype = document.getElementById("skype").value;
	datanascita = document.getElementById("datanascita").value;
	msn = document.getElementById("msn").value;
	//fotopersonale = document.getElementById("fotopersonale").value;
	stato = document.getElementById("stato").value;
	tipoindirizzo = document.getElementById("tipoindirizzo").value;
	indirizzo = document.getElementById("indirizzo").value;
	numerocivico = document.getElementById("numerocivico").value;
	internopianoecc = document.getElementById("internopianoecc").value;
	provincia = document.getElementById("provincia").value;
	comune = document.getElementById("comune").value;
	cap = document.getElementById("cap").value;
	frazione = document.getElementById("frazione").value;
	viaa = document.getElementById("viaa").value;
	viab = document.getElementById("viab").value;
	viac = document.getElementById("viac").value;
	ulterioriinfoindirizzo = document.getElementById("ulterioriinfoindirizzo").value;
	
	
	erroreparlante = "no error";

	if (tiporegistrazione == document.getElementById("valoretiporegistrazione").value) {
		tiporegistrazione = "";
	}
	if (email == document.getElementById("valoreemail").value) {
		email = "";
		//errore = errore+1
		//erroreparlante = erroreparlante + "email mancante\r"
	}
	if (usr == document.getElementById("valoreusr").value) {
		usr = "";
		//errore = errore+1
		//erroreparlante = erroreparlante + "user mancante\r"
	}
	if (cognomeoragsoc == document.getElementById("valorecognomeoragsoc").value) {
		cognomeoragsoc = "";
		//erroreparlante = erroreparlante + "cognome mancante\r"
	}
	if (nomeovetrina == document.getElementById("valorenomeovetrina").value) {
		nomeovetrina = "";
		//erroreparlante = erroreparlante + "nome mancante\r"
	}
	if (partitaiva == document.getElementById("valorepartitaiva").value) {
		partitaiva = "";
		//erroreparlante = erroreparlante + "partitaiva mancante\r"
	}
	if (emailpec == document.getElementById("valoreemailpec").value) {
		emailpec = "";
		//erroreparlante = erroreparlante + "partitaiva mancante\r"
	}
	if (codfiscazienda == document.getElementById("valorecodfiscazienda").value) {
		codfiscazienda = "";
		//erroreparlante = erroreparlante + "codicefiscale mancante\r"
	}
	if (prefissoaz == document.getElementById("valoreprefissoaz").value) {
		prefissoaz = "";
		//erroreparlante = erroreparlante + "prefisso mancante\r"
	}
	if (telefonoaz == document.getElementById("valoretelefonoaz").value) {
		telefonoaz = "";
		//erroreparlante = erroreparlante + "telefono aziendale mancante\r"
	}
	if (prefissofaxaz == document.getElementById("valoreprefissofaxaz").value) {
		prefissofaxaz = "";
		//erroreparlante = erroreparlante + "prefisso fax mancante\r"
	}
	if (telefonofaxaz == document.getElementById("valoretelefonofaxaz").value) {
		telefonofaxaz = "";
		//erroreparlante = erroreparlante + "fax aziendale mancante\r"
	}
	if (categoria1 == document.getElementById("valorecategoria1").value) {
		categoria1 = "";
		//erroreparlante = erroreparlante + "categoria merceologica mancante\r"
	}
	if (sitoweb == document.getElementById("valoresitoweb").value) {
		sitoweb = "";
		//erroreparlante = erroreparlante + "sitoweb mancante\r"
	}
	//if (logoaziendale == document.getElementById("valorelogoaziendale").value) {
		//logoaziendale = "";
	//}
	//if (visuracamerale == document.getElementById("valorevisuracamerale").value) {
	//	visuracamerale = "";
	//}
	if (titolopersona == document.getElementById("valoretitolopersona").value) {
		titolopersona = "";
	}
	if (nomeovetrinab == document.getElementById("valorenomeovetrinab").value) {
		nomeovetrinab = "";
	}
	if (cognomeoragsocb == document.getElementById("valorecognomeoragsocb").value) {
		cognomeoragsocb = "";
	}
	if (sottotitolopersona == document.getElementById("valoresottotitolopersona").value) {
		sottotitolopersona = "";
	}
	if (codfiscpersona == document.getElementById("valorecodfiscpersona").value) {
		codfiscpersona = "";
	}
	if (prefisso == document.getElementById("valoreprefisso").value) {
		prefisso = "";
	}
	if (telefono == document.getElementById("valoretelefono").value) {
		telefono = "";
	}
	if (prefissocell == document.getElementById("valoreprefissocell").value) {
		prefissocell = "";
	}
	if (telefonocell == document.getElementById("valoretelefonocell").value) {
		telefonocell = "";
	}
	if (prefissofax == document.getElementById("valoreprefissofax").value) {
		prefissofax = "";
	}
	if (telefonofax == document.getElementById("valoretelefonofax").value) {
		telefonofax = "";
	}
	if (skype == document.getElementById("valoreskype").value) {
		skype = "";
	}
	if (msn == document.getElementById("valoremsn").value) {
		msn = "";
	}
	if (datanascita == document.getElementById("valoredatanascita").value) {
		datanascita = "";
	}
	//if (fotopersonale == document.getElementById("valorefotopersonale").value) {
	//	fotopersonale = "";
	//}
	if (indirizzo == document.getElementById("valoreindirizzo").value) {
		indirizzo = "";
	}
	if (numerocivico == document.getElementById("valorenumerocivico").value) {
		numerocivico = "";
	}
	if (internopianoecc == document.getElementById("valoreinternopianoecc").value) {
		internopianoecc = "";
	}
	if (cap == document.getElementById("valorecap").value) {
		cap = "";
	}
	if (viaa == document.getElementById("valoreviaa").value) {
		viac = "";
	}
	if (viab == document.getElementById("valoreviab").value) {
		viac = "";
	}
	if (viac == document.getElementById("valoreviac").value) {
		viac = "";
	}
	if (ulterioriinfoindirizzo == document.getElementById("valoreulterioriinfoindirizzo").value) {
		ulterioriinfoindirizzo = "";
	}
	erroreemail = 0
	//if (controllaobbligo('email',email,'regexpemail')) {
	//		errore = errore+1
	//		erroreemail = 1
	//		erroreparlante = erroreparlante + "email non valida\r"
	//	}
	erroreusr = 0
	//if (controllaobbligo('usr',usr,'regexpusr')) {
	//		errore = errore+1
	//		erroreusr = 1
	//		erroreparlante = erroreparlante + "userid non valida\r"
	//	}
	if ((id2utente == "" || id2utente == null) && (erroreusr < 1)) {
			if (esisteuser(usr)) {
				errore = errore+1
				erroreparlante = erroreparlante + "userid registrata\r"
				}
		}
	if ((id2utente == "" || id2utente == null) && (erroreemail < 1)) {
			if (esisteemail(email)) {
				errore = errore+1
				erroreparlante = erroreparlante + "email registrata\r"
				}
		}
		
	//if (controllaobbligo('nomeovetrinab',nomeovetrinab,'regexpcampoobbligatorio')) {
	//		errore = errore+1
	//	}
	//if (controllaobbligo('cognomeoragsocb',cognomeoragsocb,'regexpcampoobbligatorio')) {
	//		errore = errore+1
	//	}
	telefonoaz = prendisolonumeri(telefonoaz)
	document.getElementById("telefonoaz").value = telefonoaz
	telefonofaxaz = prendisolonumeri(telefonofaxaz)
	document.getElementById("telefonofaxaz").value = telefonofaxaz
	
	telefono = prendisolonumeri(telefono)
	document.getElementById("telefono").value = telefono
	
	if (sitoweb != "")  {
			if (controllaobbligo('sitoweb',sitoweb,'regexpsitoweb')) {
				errore = errore+1
			}
		}
	if (datanascita != "")  {
			if (controllaobbligo('datanascita',datanascita,'regexpdatanascita')) {
				errore = errore+1
			}
		}
	if (skype != "")  {
			if (controllaobbligo('skype',skype,'regexpskype')) {
				errore = errore+1
			}
		}
	if (msn != "")  {
			if (controllaobbligo('msn',msn,'regexpemail')) {
				errore = errore+1
			}
		}
	
	telefonocell = prendisolonumeri(telefonocell)
	document.getElementById("telefonocell").value = telefonocell
	
	
	telefonofax = prendisolonumeri(telefonofax)
	document.getElementById("telefonofax").value = telefonofax
	
	
	if (controllaobbligo('stato',stato,'regexpcampoobbligatorio')) {
			//errore = errore+1
		}
	if (stato == "it") { // se siamo in italia controlliamo i campi indirizzo
		document.getElementById("viaa").value = ""
		document.getElementById("viab").value = ""
		document.getElementById("viac").value = ""
		if (controllaobbligo('indirizzo',indirizzo,'regexpcampoobbligatorio')) {
				errore = errore+1
			}
		if (controllaobbligo('numerocivico',numerocivico,'regexpcampoobbligatorio')) {
				errore = errore+1
			}
		if (controllaobbligo('provincia',provincia,'regexpcampoobbligatorio')) {
				errore = errore+1
			}
		if (controllaobbligo('comune',comune,'regexpcampoobbligatorio')) {
				errore = errore+1
			}
		if (controllaobbligo('cap',cap,'regexpcapitaliano')) {
				errore = errore+1
			}
	} else if (stato != "") {
		controllaobbligo('viaa',viaa,'regexpcampoobbligatorio')
		document.getElementById("indirizzo").value = ""
		document.getElementById("numerocivico").value = ""
		document.getElementById("cap").value = ""
	}
	document.getElementById('codfiscpersona').style.border = "1px solid #7F9DB9"
	document.getElementById('codfiscpersona').style.color = "#000000"
	if (tiporegistrazione == 1) { //privato
		if (controllaobbligo('telefono',telefono,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('prefisso',prefisso,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		// controlliamo che il nome utente non sia gi presente
		if (stato == "it") { // se siamo in italia controlliamo il codice fiscale della persona
			if (controllaobbligo('codfiscpersona',codfiscpersona,'regexpcodfiscita')) {
			errore = errore+1
			}
		}
	} else if (tiporegistrazione == 2) { //business
		if (controllaobbligo('cognomeoragsoc',cognomeoragsoc,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('telefonoaz',telefonoaz,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('prefissoaz',prefissoaz,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (stato == "it") { // se siamo in italia controlliamo il codice fiscale della persona
			if (controllaobbligo('codfiscazienda',codfiscazienda,'regexpcodfiscita')) {
				if (controllapartitaiva('codfiscazienda',2)) {
					errore = errore+1
				}
			}
			if (controllapartitaiva('partitaiva',1)) {
				errore = errore+1
			}
		}
	} else if (tiporegistrazione == 3 || tiporegistrazione == 4) { //business
		if (controllaobbligo('cognomeoragsoc',cognomeoragsoc,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('categoria1',categoria1,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('telefonoaz',telefonoaz,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (controllaobbligo('prefissoaz',prefissoaz,'regexpcampoobbligatorio')) {
			errore = errore+1
		}
		if (stato == "it") { // se siamo in italia controlliamo il codice fiscale della persona
			if (controllaobbligo('codfiscazienda',codfiscazienda,'regexpcodfiscita')) {
				if (controllapartitaiva('codfiscazienda',2)) {
					errore = errore+1
				}
			}
			if (controllapartitaiva('partitaiva',1)) {
				errore = errore+1
			}
		}
	}
	if (document.getElementById("listinoforzato")) {
			errore = 0
		}
	errore = 0
	if (errore > 0) {
		//window.alert("errore finale:" + errore)
		//ripristiniamo i valori default
		if (document.getElementById("email").value == "") {
			document.getElementById("email").value = document.getElementById("valoreemail").value
			document.getElementById('email').style.color = "#999999"
			}
		if (document.getElementById("usr").value == "") {
			document.getElementById("usr").value = document.getElementById("valoreusr").value
			document.getElementById('usr').style.color = "#999999"
			}
		if (document.getElementById("cognomeoragsoc").value == "") {
			document.getElementById("cognomeoragsoc").value = document.getElementById("valorecognomeoragsoc").value
			document.getElementById('cognomeoragsoc').style.color = "#999999"
			}
		if (document.getElementById("nomeovetrina").value == "") {
			document.getElementById("nomeovetrina").value = document.getElementById("valorenomeovetrina").value
			document.getElementById('nomeovetrina').style.color = "#999999"
			}
		if (document.getElementById("partitaiva").value == "") {
			document.getElementById("partitaiva").value = document.getElementById("valorepartitaiva").value
			document.getElementById('partitaiva').style.color = "#999999"
			}
		if (document.getElementById("codfiscazienda").value == "") {
			document.getElementById("codfiscazienda").value = document.getElementById("valorecodfiscazienda").value
			document.getElementById('codfiscazienda').style.color = "#999999"
			}
		if (document.getElementById("telefonoaz").value == "") {
			document.getElementById("telefonoaz").value = document.getElementById("valoretelefonoaz").value
			//document.getElementById('telefonoaz').style.color = "#999999"
			}
		if (document.getElementById("prefissoaz").value == "") {
			document.getElementById("prefissoaz").value = document.getElementById("valoreprefissoaz").value
			//document.getElementById('prefissoaz').style.color = "#999999"
			}
		if (document.getElementById("telefonofaxaz").value == "") {
			document.getElementById("telefonofaxaz").value = document.getElementById("valoretelefonofaxaz").value
			document.getElementById('telefonofaxaz').style.color = "#999999"
			}
		if (document.getElementById("prefissofaxaz").value == "") {
			document.getElementById("prefissofaxaz").value = document.getElementById("valoreprefissofaxaz").value
			document.getElementById('prefissofaxaz').style.color = "#999999"
			}
		if (document.getElementById("categoria1").value == "") {
			document.getElementById("categoria1").value = document.getElementById("valorecategoria1").value
			document.getElementById('categoria1').style.color = "#999999"
			}
		if (document.getElementById("cognomeoragsocb").value == "") {
			document.getElementById("cognomeoragsocb").value = document.getElementById("valorecognomeoragsocb").value
			document.getElementById('cognomeoragsocb').style.color = "#999999"
			}
		if (document.getElementById("nomeovetrinab").value == "") {
			document.getElementById("nomeovetrinab").value = document.getElementById("valorenomeovetrinab").value
			document.getElementById('nomeovetrinab').style.color = "#999999"
			}
		if (document.getElementById("indirizzo").value == "") {
			document.getElementById("indirizzo").value = document.getElementById("valoreindirizzo").value
			document.getElementById('indirizzo').style.color = "#999999"
			}
		if (document.getElementById("numerocivico").value == "") {
			document.getElementById("numerocivico").value = document.getElementById("valorenumerocivico").value
			document.getElementById('numerocivico').style.color = "#999999"
			}
		if (document.getElementById("internopianoecc").value == "") {
			document.getElementById("internopianoecc").value = document.getElementById("valoreinternopianoecc").value
			document.getElementById('internopianoecc').style.color = "#999999"
			}
		if (document.getElementById("cap").value == "") {
			document.getElementById("cap").value = document.getElementById("valorecap").value
			document.getElementById('cap').style.color = "#999999"
			}
		if (document.getElementById("ulterioriinfoindirizzo").value == "") {
			document.getElementById("ulterioriinfoindirizzo").value = document.getElementById("valoreulterioriinfoindirizzo").value
			document.getElementById('ulterioriinfoindirizzo').style.color = "#999999"
			}
			
		if (document.getElementById("codfiscpersona").value == "") {
			document.getElementById("codfiscpersona").value = document.getElementById("valorecodfiscpersona").value
			document.getElementById('codfiscpersona').style.color = "#999999"
			}
		if (document.getElementById("telefono").value == "") {
			document.getElementById("telefono").value = document.getElementById("valoretelefono").value
			//document.getElementById('telefono').style.color = "#999999"
			}
		if (document.getElementById("prefisso").value == "") {
			document.getElementById("prefisso").value = document.getElementById("valoreprefisso").value
			//document.getElementById('prefisso').style.color = "#999999"
			}
		if (document.getElementById("telefonocell").value == "") {
			document.getElementById("telefonocell").value = document.getElementById("valoretelefonocell").value
			document.getElementById('telefonocell').style.color = "#999999"
			}
		if (document.getElementById("prefissocell").value == "") {
			document.getElementById("prefissocell").value = document.getElementById("valoreprefissocell").value
			document.getElementById('prefissocell').style.color = "#999999"
			}
		if (document.getElementById("telefonofax").value == "") {
			document.getElementById("telefonofax").value = document.getElementById("valoretelefonofax").value
			document.getElementById('telefonofax').style.color = "#999999"
			}
		if (document.getElementById("prefissofax").value == "") {
			document.getElementById("prefissofax").value = document.getElementById("valoreprefissofax").value
			document.getElementById('prefissofax').style.color = "#999999"
			}
		if (document.getElementById("viaa").value == "") {
			document.getElementById("viaa").value = document.getElementById("valoreviaa").value
			document.getElementById('viaa').style.color = "#999999"
			}
		if (document.getElementById("viab").value == "") {
			document.getElementById("viab").value = document.getElementById("valoreviab").value
			document.getElementById('viab').style.color = "#999999"
			}
		if (document.getElementById("viac").value == "") {
			document.getElementById("viac").value = document.getElementById("valoreviac").value
			document.getElementById('viac').style.color = "#999999"
			}
		//window.alert("errore finale:" + errore)
		//window.alert("errore finale:" + erroreparlante)
		return false;
	} else {
		//window.alert("errore finale:" + errore)
		//nascondi('bottoneinvio');
		//document.getElementById('spancheckboxe').innerHTML = '<img src="/layout/ajax-loader.gif"> <b>Stiamo controllando ed inviando i dati... siete pregati di attendere</b>' ;
		//return true;
		return true;
	}
}

function chiamamenu(q,t,campomodulo,campofrazioni) { //
	if(window.XMLHttpRequest)
	{
	   richiestaricerca = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
	}
	richiestaricerca.open("POST", "/ajax/recuperodoveviaggiare.asp", true);
	richiestaricerca.onreadystatechange = function() 
	{
		if(richiestaricerca.readyState == 4)
		{	
			if(richiestaricerca.status == 200)
			{
				rispostaricerca = richiestaricerca.responseText
				var mySplitResult = rispostaricerca.split("###");
				valorepercampomodulo = mySplitResult[0];
				calorepercampofrazioni = mySplitResult[1];			
				document.getElementById(campomodulo).innerHTML = valorepercampomodulo
				visualizza(campomodulo);
				if (calorepercampofrazioni != '') {
					document.getElementById(campofrazioni).innerHTML = calorepercampofrazioni
					}
				
			}
			else
			{
				//document.getElementById('statocaricamento').innerHTML = "Errore Server " + richiestaricerca.status;
			}
		}
		else
		{
				//document.getElementById('statocaricamento').innerHTML = "Loading...";
		}
	}
	richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	richiestaricerca.send("q="+q+"&t="+t);
}


function cercacategoria(campomodulo) { //
	eval("q = document.getElementById('categoria"+campomodulo+"').value")
	q = codificaascii(q);
	//window.alert (q);
	if(window.XMLHttpRequest)
	{
	   richiestaricerca = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
	}
	richiestaricerca.open("POST", "/ajax/recuperocerchitrovi.asp", true);
	richiestaricerca.onreadystatechange = function() 
	{
		if(richiestaricerca.readyState == 4)
		{	
			if(richiestaricerca.status == 200)
			{
				rispostaricerca = richiestaricerca.responseText
				eval("document.getElementById('divcategoria"+campomodulo+"').innerHTML = rispostaricerca");
				eval("visualizza('divcategoria"+campomodulo+"')");
			}
		}
	}
	richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	richiestaricerca.send("q="+q+"&t="+campomodulo);
}

function inseriscivalore(id,id2) {
	document.getElementById(id).value = id2;
	document.getElementById('divcategoria1').innerHTML = "";
}

function aggiungirigaprodotto() {
	numerorigheprodotto = document.getElementById("numerorigheprodotto").value;
	numerorighevisibili = document.getElementById("numerorighevisibili").value;
	if(numerorighevisibili*1 <= numerorigheprodotto*1) { // allora possiamo mostrare ancora un riga
		numerorighevisibili = numerorighevisibili - 0;
		numerorighevisibili = numerorighevisibili + 1;
		id = "singolarigabolla" + numerorighevisibili;
		document.getElementById(id).style.display = 'block'; // mostriamo una riga per la bolla
		document.getElementById("numerorighevisibili").value = numerorighevisibili; // incrementiamo il contatore delle righe visibili
	}
	if(numerorighevisibili*1 == numerorigheprodotto*1) {
		// nascondiamo il bottone per aggiungere una nuova riga
		document.getElementById("aggiungirigaprodotto").style.display = 'none';
	}
}

function cercaprodotto(nomecampo,numerocampo) {
	eval("q = document.getElementById('" + nomecampo + numerocampo + "').value");
	q = codificaascii(q);
	if(window.XMLHttpRequest)
	{
	   richiestaricerca = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
	   richiestaricerca = new ActiveXObject("Microsoft.XMLHTTP");
	}
	richiestaricerca.open("POST", "/ajax/recuperoarticoli.asp", true);
	richiestaricerca.onreadystatechange = function() 
	{
		if(richiestaricerca.readyState == 4)
		{	
			if(richiestaricerca.status == 200)
			{
				rispostaricerca = richiestaricerca.responseText
				eval("document.getElementById('divarticoli"+numerocampo+"').innerHTML = rispostaricerca");
				eval("visualizza('divarticoli"+numerocampo+"')");
			}
		}
	}
	richiestaricerca.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	richiestaricerca.send("q="+q+"&t="+nomecampo+"&n="+numerocampo);
}

function compila(numerocampo,id2articolo,codice,nomegestionale,prezzo){
	
	eval("document.getElementById('codice"+numerocampo+"').value = codice");
	eval("document.getElementById('descrizione"+numerocampo+"').value = nomegestionale");
	eval("document.getElementById('prezzo"+numerocampo+"').value = prezzo");
	eval("document.getElementById('quantita"+numerocampo+"').value = 1");
	eval("document.getElementById('id2"+numerocampo+"').value = id2articolo");
	
	eval("nascondi('divarticoli"+numerocampo+"')"); // nascondiamo il div con i risultati mostrati
}

function impostafornitore(id2fornitore) {
	window.alert(id2fornitore);
}
