function ajaxCall(url) {
	xmlhttp=null  
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
		xmlhttp=new XMLHttpRequest()
		// code for IE
		} else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}

	if (xmlhttp!=null) {  
		xmlhttp.onreadystatechange=state_Change
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
		} else {
		alert("Your browser does not support XMLHTTP.")
		} 
	}

function state_Change() {
// if xmlhttp shows "loaded"
	if (xmlhttp.readyState==4) {
		// if "OK"
		if (xmlhttp.status==200) {
			xmlDoc=xmlhttp.responseXML;
			x=xmlDoc.documentElement.childNodes;
			opName=xmlDoc.documentElement.getAttribute('name');

			if (opName=='whoisDomain') {
					whoisDomainStatus=xmlDoc.documentElement.getAttribute('status');
					//dominio libero
					
					if (whoisDomainStatus==0) {						
						radio1Input = document.createElement('input');
						radio2Input = document.createElement('input');
						radio3Input = document.createElement('input');

						if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
							radio1Input.type='radio';
							radio2Input.type='radio';
							radio3Input.type='radio';
							} else {
							radio1Input.setAttribute('type','radio');
							radio2Input.setAttribute('type','radio');
							radio3Input.setAttribute('type','radio');
							}						
						while (document.getElementById('whoisDomainResult').firstChild) {
							document.getElementById('whoisDomainResult').removeChild(document.getElementById('whoisDomainResult').firstChild)
							}
						document.getElementById('whoisDomainResult').appendChild(radio1Input);
						document.getElementById('whoisDomainResult').appendChild(radio2Input);
						document.getElementById('whoisDomainResult').appendChild(radio3Input);
						document.getElementById('whoisDomainResult').style.display='block';
						} else if (whoisDomainStatus==1) { 
						while (document.getElementById('whoisDomainResult').firstChild) {
							document.getElementById('whoisDomainResult').removeChild(document.getElementById('whoisDomainResult').firstChild)
							}
						document.getElementById('whoisDomainResult').innerHTML='<h1>spiacente</h1>';
						document.getElementById('whoisDomainResult').style.display='block';
						}
					}

			if (opName=='ajaxRicercaComune') {
				if(xmlDoc.documentElement.getAttribute('return')=='true') {
					pRisultato=document.getElementById('risultato-ricerca-comune');
					if(document.getElementById('select-risultato-ricerca-comune')!=null) {	
						selectElencoComuni=document.getElementById('select-risultato-ricerca-comune');
						selectElencoComuni.parentNode.removeChild(selectElencoComuni);
						}	
					

					selectElencoComuni = document.createElement('select');	
					selectElencoComuni.setAttribute('size',6);	
					selectElencoComuni.setAttribute('id','select-risultato-ricerca-comune');
					functionString="ajaxSearchSave('ricerca-comune');ajaxSearchClose('ricerca-comune')";
					if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
						//purtroppo si tratta di explorer
						selectElencoComuni.onclick=new Function(functionString);
						} else {
						//che bello, non si tratta di explorer
						selectElencoComuni.setAttribute('onclick', "javascript:"+functionString);        
						} 
					for (var i=0;i<x.length;i++) {
        					if ((x[i].nodeType!=3)&&(x[i].nodeType!=8)) {
							optionElencoComuni = document.createElement('option');
							optionElencoComuni.setAttribute('value',x[i].getAttribute('comuni_id'));
							optionElencoComuni.appendChild(document.createTextNode(
	x[i].getAttribute('comuni_cap') + ' ' + 
	x[i].getAttribute('comuni_descrizione') + ' (' + 
	x[i].getAttribute('comuni_sigla_provincia') +')'
	));
							selectElencoComuni.appendChild(optionElencoComuni);
							
							}
						}					
					pRisultato.appendChild(selectElencoComuni);				
					} else {	
					//qualora abbia scritto meno di 3 caratteri
					}
				}

			if (opName=='ajAddRigaArticolo' || opName=='ajDelRigaArticolo') {
				while (document.getElementById('articoliInseritiTBody').firstChild) {
					document.getElementById('articoliInseritiTBody').removeChild(document.getElementById('articoliInseritiTBody').firstChild);
					}				
				while (document.getElementById('totaleImponibileSpan').firstChild) {
					document.getElementById('totaleImponibileSpan').removeChild(document.getElementById('totaleImponibileSpan').firstChild);
					}
				while (document.getElementById('totaleIVASpan').firstChild) {
					document.getElementById('totaleIVASpan').removeChild(document.getElementById('totaleIVASpan').firstChild);
					}
				while (document.getElementById('totaleDocumentoSpan').firstChild) {
					document.getElementById('totaleDocumentoSpan').removeChild(document.getElementById('totaleDocumentoSpan').firstChild);
					}

				txt = document.createTextNode(xmlDoc.documentElement.getAttribute('totaleImponibile'));				
				document.getElementById('totaleImponibileSpan').appendChild(txt);
				txt = document.createTextNode(xmlDoc.documentElement.getAttribute('totaleIVA'));				
				document.getElementById('totaleIVASpan').appendChild(txt);
				txt = document.createTextNode(xmlDoc.documentElement.getAttribute('totaleDocumento'));				
				document.getElementById('totaleDocumentoSpan').appendChild(txt);

				for (var i=0;i<x.length;i++) {
        				if ((x[i].nodeType!=3)&&(x[i].nodeType!=8)) {				
						articoliInseritiTBody=document.getElementById('articoliInseritiTBody');
						articoliInseritiRow = document.createElement('tr');	
				
						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('articoli_codice') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('documenti_righe_descrizione') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('documenti_righe_importo_unitario') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('iva_descrizione') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('documenti_righe_quantita') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('documenti_righe_sconto') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
						txt = document.createTextNode(x[i].getAttribute('totale_riga_imponibile') );
						articoliInseritiCell.appendChild(txt);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiCell = document.createElement('td');
			                        articoliInseritiButton = document.createElement('button');
						articoliInseritiButton.setAttribute('type','button');						
						delFunctionText="delRigaArticolo('"+x[i].getAttribute('documenti_id')+"','"+x[i].getAttribute('documenti_righe_id')+"');";
						if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
							articoliInseritiButton.setAttribute('className','save');
                                                        articoliInseritiButton.onclick=new Function(delFunctionText);
                                                        } else {
                                                        articoliInseritiButton.setAttribute('class','save');
                                                        articoliInseritiButton.setAttribute('onclick',delFunctionText);
                                                        }						
						txt = document.createTextNode('cancella');
						articoliInseritiButton.appendChild(txt);
						articoliInseritiCell.appendChild(articoliInseritiButton);
						articoliInseritiRow.appendChild(articoliInseritiCell);

						articoliInseritiTBody.appendChild(articoliInseritiRow);
						}
					}
				}

			if (opName=='ajRicercaArticoliCodice') {
				if(xmlDoc.documentElement.getAttribute('return')=='true') {
					pRisultato=document.getElementById('risultato-ricerca-articoli-codice');
					if(document.getElementById('select-risultato-ricerca-articoli-codice')!=null) {	
						selectElencoArticoliCodice=document.getElementById('select-risultato-ricerca-articoli-codice');
						selectElencoArticoliCodice.parentNode.removeChild(selectElencoArticoliCodice);
						}	
					

					selectElencoArticoliCodice = document.createElement('select');	
					selectElencoArticoliCodice.setAttribute('size',6);	
					selectElencoArticoliCodice.setAttribute('id','select-risultato-ricerca-articoli-codice');
					functionString="ajaxSearchSave('ricerca-articoli-codice');ajaxSearchClose('ricerca-articoli-codice')";
					if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
						//purtroppo si tratta di explorer
						selectElencoArticoliCodice.onclick=new Function(functionString);
						} else {
						//che bello, non si tratta di explorer
						selectElencoArticoliCodice.setAttribute('onclick', "javascript:"+functionString);        
						} 
					for (var i=0;i<x.length;i++) {
        					if ((x[i].nodeType!=3)&&(x[i].nodeType!=8)) {
							optionElencoArticoliCodice = document.createElement('option');
							optionElencoArticoliCodice.setAttribute('value',x[i].getAttribute('articoli_id'));
							optionElencoArticoliCodice.appendChild(document.createTextNode(
								x[i].getAttribute('articoli_codice') + ' ' + 
								x[i].getAttribute('articoli_descrizione') + ' (' + x[i].getAttribute('articoli_descrizione') +')'));
								selectElencoArticoliCodice.appendChild(optionElencoArticoliCodice);			
								}
							}					
					pRisultato.appendChild(selectElencoArticoliCodice);				
					} else {	
					//qualora abbia scritto meno di 3 caratteri
					}
				}

			if (opName=='ajGetArticolo') {
				if(xmlDoc.documentElement.getAttribute('return')=='true') {					
					document.getElementById('stringa-ricerca-articoli-codice').value=x[0].getAttribute('articoli_codice');
					document.getElementById('stringa-ricerca-articoli-descrizione').value=x[0].getAttribute('articoli_descrizione');
					document.getElementById('documenti-righe-importo-unitario').value=x[0].getAttribute('articoli_importo');
					document.getElementById('documenti-righe-quantita').value=1;
					document.getElementById('documenti-righe-sconto').value=0;					
					}		
				} 

			}	
		}	
	}

function whoisDomain(domain_name)  {
	url='?op=whoisDomainAjax&domain_name='+domain_name;	
	//location.href=url;
	ajaxCall(url);
	}
	






































function ricercaComune(stringa_ricerca_comune) {
	url='/nbitter/?op=ajaxRicercaComune&stringa_ricerca_comune='+stringa_ricerca_comune; 
	ajaxCall(url);
	}

function ajaxSearchSave(asElementName) {
	switch(asElementName) {
		default:
		document.getElementById('stringa-'+asElementName).value=document.getElementById('select-risultato-'+asElementName).options[document.getElementById('select-risultato-'+asElementName).selectedIndex].text;
		//document.getElementById('stringa-'+asElementName).disabled=true;
		document.getElementById('stringa-'+asElementName).readOnly=true;
		document.getElementById('id-'+asElementName).value=document.getElementById('select-risultato-'+asElementName).options[document.getElementById('select-risultato-'+asElementName).selectedIndex].value;	
		if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
			//cartRowCellButton.onclick=new Function(saveFunctionText);
			document.getElementById('stringa-'+asElementName).setAttribute('onkeyup','');
			} else {
			document.getElementById('stringa-'+asElementName).setAttribute('onkeyup','');
			}
		break;

		case 'ricerca-articoli-codice':
		document.getElementById('id-'+asElementName).value=document.getElementById('select-risultato-'+asElementName).options[document.getElementById('select-risultato-'+asElementName).selectedIndex].value;		
		url='?op=ajGetArticolo&articoli_id='+document.getElementById('id-'+asElementName).value; 
		ajaxCall(url);		
		break;
		}
	}
   
function ajaxSearchClose(asElementName) {
	document.getElementById('select-risultato-'+asElementName).style.display='none';
	}

function ajaxSearchReset(asElementName) {
	
	document.getElementById('stringa-'+asElementName).value='';
	document.getElementById('id-'+asElementName).value='';
	//document.getElementById('stringa-'+asElementName).disabled=false;
	document.getElementById('stringa-'+asElementName).readOnly=false;

	if (document.getElementById('stati-codice-iso-3166').value=='IT') {
		if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
			//cartRowCellButton.onclick=new Function(saveFunctionText);
			document.getElementById('stringa-'+asElementName).onkeyup=new Function('ricercaComune(this.value)');
			} else {
			document.getElementById('stringa-'+asElementName).setAttribute('onkeyup','ricercaComune(this.value);');
			}
		} else {
		if (window.navigator.userAgent.indexOf('MSIE')!=-1) {
			document.getElementById('stringa-ricerca-comune').onkeyup=null;
			} else {
			document.getElementById('stringa-ricerca-comune').setAttribute('onKeyUp',null)
			}
		}
	}


