/* PARTI AJAX */

var req;
var area;


function loadXMLDoc_refAz(url) {
   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozilla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

	
   // Call the processChange() function when the page has loaded
   if (req != null) {
	  req.onreadystatechange = processChange_refAz;
	  req.open("GET", url, true);
      req.send(null);
   }
}

function processChange_refAz() {

	if ((req.readyState == 4) && (req.status == 200))
		{
				// Write the contents of this URL to the searchResult layer
				if (document.getElementById("hid_denominazione")) {
					document.getElementById("hid_denominazione").value = req.responseText;
					var strValues = document.getElementById("hid_denominazione").value;
	//document.getElementById("temp").innerHTML = document.getElementById("hid_denominazione").value;
					
					
					var arrValues = strValues.split('|');
					// partita IVA
					document.getElementById("IDaz").value = arrValues[0];
					document.getElementById("piva").value = arrValues[1];
						document.getElementById("piva").readOnly = true;
						document.getElementById("piva").style.fontWeight = 'bold'
						document.getElementById("piva").style.backgroundColor = '#ededed';
						document.getElementById("piva").style.color = '#000';
						
						document.getElementById("gestione_piva").value = arrValues[17]; // gestione_piva
						document.getElementById("codice_fiscale").value = arrValues[18]; // CF
						document.getElementById("forma_giuridica").value = arrValues[19]; // F giuridica
						document.getElementById("forma_giuridica_altro").value = arrValues[20]; // F giuridica ALTRO
					
					
					for (a = 1; a <= 5; a++) {
							document.getElementById("ateco_generale_" + a).value = 0;
							if (document.getElementById("ateco_generale_sub_" + a)) {
								document.getElementById("ateco_generale_sub_" + a).value = 0;
							}
						}
					var at = 1;
					var d = 31;
					for (q = 21; q <= 25; q++) {

						arrValues[q] = parseInt(arrValues[q]);
						if ((arrValues[q] != '') && (arrValues[q] != 0) && (arrValues[q] > 696)) { // E' UN SUB-ATECO!
							document.getElementById("ateco_generale_" + at).value = arrValues[d]; // ATECO 1
							loadXMLDoc('ateco_generaleResult_' + at, 'http://database.centroestero.org/amministra/inside/include/inclusioni/find_ateco.php?label=ateco_generale&i=' + at + '&lang=ita&counter=5&q=' + arrValues[d] + '&selected=' + arrValues[q]);
							
							if (document.getElementById("ateco_generale_sub_" + at)) {
								document.getElementById("ateco_generale_sub_" + at).value = arrValues[q]; // ATECO SUB 1
							}
							
						}
						else {
							document.getElementById("ateco_generale_" + at).value = arrValues[q]; // ATECO 1
						}
					spec_ateco('sub_' +at, '5');
					at++;
					d++;
					}
												
						var bio = arrValues[26]; // BIO
							if (bio == 1) {
								document.getElementById("BIO_alimentare_radio_1").checked = true;
							} else {
								document.getElementById("BIO_alimentare_radio_0").checked = true;
							}
							
						// AUTO 
						var arrAuto= new Array(2359, 2360);
							for (c = 0; c < arrAuto.length; c++) {
								document.getElementById("settore_auto_check_" + arrAuto[c]).checked = false;
							}
							
							var arrAu = arrValues[27].split('{}');
							var flg_auto = 0;
							for (c = 0; c <= arrAu.length; c++) {
								if (document.getElementById("settore_auto_check_" + arrAu[c])) {
									document.getElementById("settore_auto_check_" + arrAu[c]).checked = true;
									flg_auto++;
								}
							}
							if (flg_auto > 0) {
									document.getElementById("div-settore_auto").style.display = 'block';
									document.getElementById("lab_settore_auto").innerHTML = '<span style=\"color:#be0503"\>* Specificazione settore Auto</span>';
													
								}
						
						// DOMANDE MASS MEDIA
						document.getElementById("media_testata").value = arrValues[36]; // Testata media
						
						// @@AC NOTA BENE AMBITO MASS-MEDIA: non precarico perché è riferito al referente...
						
//						var arrAmbito = new Array(416, 428, 429, 456, 430, 417, 431, 432, 457, 433, 418, 434, 419, 435, 420, 436, 437, 438, 439, 440, 458, 441, 421, 442, 443, 459, 444, 422, 445, 446, 460, 447, 423, 448, 424, 449, 461, 450, 425, 449, 461, 450, 426, 454, 455, 427);
//						for (c = 0; c < arrAmbito.length; c++) {
//								document.getElementById("media_ambito_check_" + arrAmbito[c]).checked = false;
//							}
//						var arrAmb = arrValues[37].split('{}');
//						for (c = 0; c <= arrAmbito.length; c++) {
//								if (document.getElementById("media_ambito_check_" + arrAmb[c])) {
//									document.getElementById("media_ambito_check_" + arrAmb[c]).checked = true;
//									if (arrAmb[c] == '468') { // apro il div del campo altro
//										document.getElementById("div-media_ambito_altro").style.display = 'block';
//									}
//								}
//							}
						
						// DOMANDE Turismo
						document.getElementById("turismo_tipo").value = arrValues[28]; // Tipo op Tur
						if (arrValues[28] == 462) { // OP ITALIANO
							document.getElementById("div-opitaliano").style.display = 'block';
							
							// rende obbligatorio il tipo di operatore italiano
							document.getElementById("lab_turismo_tipo_italia").style.color =  "#be0503";
							document.getElementById("lab_turismo_tipo_italia").innerHTML = "* Tipologia operatore italiano";
					
							
						}
						else {
							document.getElementById("div-opitaliano").style.display = 'none';
							// TOGLIE obbligatorio il tipo di operatore italiano
							document.getElementById("lab_turismo_tipo_italia").style.color = "#545454";
							document.getElementById("lab_turismo_tipo_italia").innerHTML = "Tipologia operatore italiano";
					
						}
						// tipo italia
						var arrTipoTur = new Array(464, 465,466,467,468, 469); // ALTRO == 468
							for (c = 0; c < arrTipoTur.length; c++) {
								document.getElementById("turismo_tipo_italia_check_" + arrTipoTur[c]).checked = false;
							}
							var arrTur = arrValues[29].split('{}');
							for (c = 0; c <= arrTur.length; c++) {
								if (document.getElementById("turismo_tipo_italia_check_" + arrTur[c])) {
									document.getElementById("turismo_tipo_italia_check_" + arrTur[c]).checked = true;
									if (arrTur[c] == '468') { // apro il div del campo altro
										document.getElementById("div-turismo_tipo_italia_altro").style.display = 'block';
									}
								}
							}

						document.getElementById("turismo_tipo_italia_altro").value = arrValues[30]; // Altro tipo Italia
						
					
					document.getElementById("IDsede").value = arrValues[3];
					document.getElementById("localizzazione").value = arrValues[4];
					document.getElementById("indirizzo").value = arrValues[5];
					document.getElementById("comune").value = arrValues[6];
					document.getElementById("CAP").value = arrValues[7];
					document.getElementById("provincia").value = arrValues[8];
					// campi da evidenziare se sede già presente
					document.getElementById("telefono").style.backgroundColor = '#FFFE9F';
					document.getElementById("telefono").value = arrValues[9];
					document.getElementById("fax").style.backgroundColor = '#FFFE9F';
					document.getElementById("fax").value = arrValues[10];
					document.getElementById("email").style.backgroundColor = '#FFFE9F';
					document.getElementById("email").value = arrValues[11];
					
					// gestione tipologia
					var arrTipologie = new Array(240, 241, 242, 587);
					for (c = 0; c < arrTipologie.length; c++) {
						document.getElementById("tipologia_check_" + arrTipologie[c]).checked = false;
					}
					var arrTipo = arrValues[2].split('{}');
					for (c = 0; c <= arrTipo.length; c++) {
						if (document.getElementById("tipologia_check_" + arrTipo[c])) {
							document.getElementById("tipologia_check_" + arrTipo[c]).checked = true;
						}
					}
					
					// eventualmente apro le sezioni specifiche...
					// massMedia
					if (document.getElementById("tipologia_check_240").checked == true) {
						document.getElementById("media_section").style.display = 'block';
					}
					else {
						document.getElementById("media_section").style.display = 'none';
					}
					
					// Turismo
					if (document.getElementById("tipologia_check_241").checked == true) {
						document.getElementById("turismo_section").style.display = 'block';
						
						
					}
					else {
						document.getElementById("turismo_section").style.display = 'none';
					}
					
					// Ente
					if (document.getElementById("tipologia_check_242").checked == true) {
						document.getElementById("ente_section").style.display = 'block';
					}
					else {
						document.getElementById("ente_section").style.display = 'none';
					}
					
					// Intermediario
					if (document.getElementById("tipologia_check_587").checked == true) {
						document.getElementById("intermediario_section").style.display = 'block';
					}
					else {
						document.getElementById("intermediario_section").style.display = 'none';
					}
					
				// GESTIONE PRIVACY
				var flg_privacy = arrValues[12];
				
				
				var privacySection = document.getElementById("PrivacySection").innerHTML;
				
				document.getElementById("PrivacySection").style.display = 'block';
				
				if (flg_privacy == '1')
					{// trasformo l'area privacy in sola lettura e la apro
					// var g = "#545454"; // => grigio label
					var n =  "#000"; // => nero
					
					var data_privacy = arrValues[13];
					var arrData = data_privacy.split('-');
					data_privacy = arrData[2] + "." + arrData[1] + "." + arrData[0]; 
					var num_protocollo = arrValues[14];
					var modo_rilascio = arrValues[15];
						switch (modo_rilascio)
							{
							case "2336":
								modo_rilascio = "Da operatore";
							break;
							case "385":
								modo_rilascio = "Mail";
							break;
							case "2361":
								modo_rilascio = "FAX";
							break;
							case "2362":
								modo_rilascio = "Cartaceo";
							break;
							case "2363":
								modo_rilascio = "Verbale";
							break;
							case "383":
								modo_rilascio = "Registrazione sito";
							break;
							}
					var operatore = arrValues[16];
					String.prototype.trim = function() {
							return this.replace(/^\s+|\s+$/g,"");
						}
					operatore = operatore.trim();
					
					
					var privacySection = "<div id=\"ZZZ_div-flg_privacy\" class=\"linea\">" +
																				"<label for=\"flg_privacy\" id=\"ZZZ_lab_flg_privacy\">Espressione del consenso privacy</label>"+
																				"<span id=\"ZZZ_lov-flg_privacy\">"+
																					"<ul class=\"annida\" id=\"ZZZ_ul-flg_privacy\">"+
																					"<li> <span class=\"valore\">Sì</span></li></ul>"+
																				"</span>"+
																			"</div>"+
																			"<div style=\"display: block;\" class=\"linea\" id=\"ZZZ_div-privacy_data\">"+
																				"<label for=\"privacy_data_d\" id=\"ZZZ_lab_privacy_data\">Data privacy</label>"+
																				"<span class=\"spazio_select\" id=\"ZZZ_spazio_select_privacy_data\">"+
																					" <span class=\"valore\">"+ data_privacy +"</span>"+
																				"</span>"+
																			"</div>"+
																			"<div style=\"display: block;\" id=\"ZZZ_div-privacy_modo_rilascio\" class=\"linea\">"+
																				"<label for=\"privacy_modo_rilascio\" id=\"ZZZ_lab_privacy_modo_rilascio\">Modalit&agrave; rilascio</label>"+
																				"<span id=\"ZZZ_lov-privacy_modo_rilascio\">"+
																					" <span class=\"valore\">"+modo_rilascio+"</span>"+
																				"</span>"+
																			"</div>"+
																			"<div style=\"display: block;\" id=\"ZZZ_div-privacy_num_protocollo\" class=\"linea\">"+
																				"<label for=\"privacy_num_protocollo\" id=\"ZZZ_lab_privacy_num_protocollo\">Numero di protocollo</label>"+
																				"<span id=\"ZZZ_text-privacy_num_protocollo\">"+
																					" <span class=\"valore\">"+num_protocollo+"</span>"+
																				"</span>"+
																			"</div>";
																			
															if (operatore != '') {
																privacySection += "<div id=\"ZZZ_contRilascioPrivacy\">" +
																	"<div style=\"display: block;\" id=\"ZZZ_div-privacy_ID_oper\" class=\"linea\">" +
																		"<label for=\"privacy_ID_oper\" id=\"ZZZ_lab_privacy_ID_oper\">Incaricato privacy</label>" +
																		"<span id=\"ZZZ_lov-privacy_ID_oper\">" +
																			" <span class=\"valore\">" +
																			operatore +
																			"</span>" +
																		"</span>" +
																	"</div>" +
																"</div>";
															}
					document.getElementById("contentPrivacy").style.display = 'none';
					document.getElementById("replace_privacy").innerHTML = privacySection;
					
					
				
					
					}
				else
					{
					document.getElementById("replace_privacy").innerHTML = '';
						
					document.getElementById("contentPrivacy").style.display = 'block';
					}
				
				}
		document.getElementById("loading_denominazione").innerHTML = '';
		if (document.getElementById("scheda_privacy")) {
							document.getElementById("scheda_privacy").innerHTML = '';
						}
		}
}

	function posizioneGenerica(type,i) {
//		if (type == 'hide') {
//			document.getElementById("div-posizione_generica").value = '0';
//			document.getElementById("div-posizione_generica").style.display = 'none';
//		}
//		else {
//			// devo valutare se gli altri check ci sono ancora
//			if (
//				(document.getElementById("tipologia_check_240").checked == false)
//					&& (document.getElementById("tipologia_check_241").checked == false) 
//					&& (document.getElementById("tipologia_check_242").checked == false) 
//					&& (document.getElementById("tipologia_check_587").checked==false))
//				{
//					document.getElementById("div-posizione_generica").style.display = 'block';
//				}
//		}
		
	}


function loadXMLDoc(IDarea, url) {
area = IDarea;

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozilla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

	
   // Call the processChange() function when the page has loaded
   if (req != null) {
    
	  req.onreadystatechange = processChange;
      req.open("GET", url, true);
      req.send(null);
   }
}

function processChange() {

	if ((req.readyState == 4) && (req.status == 200))
		{
			
				// Write the contents of this URL to the searchResult layer
				getObject(area).innerHTML = req.responseText;
		}
}

function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}



function chiudi_menu() {
	
	var menu = document.getElementById("menu");
	menu.className = "menuClosed";
	
}

function apri_menu() {
	
	var menu = document.getElementById("menu");
	menu.className = "menuOpen";
	

}

function seleziona_radio_mailing(cosa, numRef) {
	
	for (i=1;i<=numRef;i++)
		{
		id = cosa + "_" + i;
		//alert(id);
		document.getElementById(id).checked = true;	
		}
	
	
	}



/* DEMO DA CANCELLARE*/

function aprichiudi(what) {
	
	var elem = document.getElementById(what+"Data");
	
	if (elem.className == "closed")
		{
			elem.className = "";
		}
	else
		{
			elem.className = "closed";
		}
	

}
/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
/*
	Written by Jonathan Snook, http://www.snook.ca/jonathan
	Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}



var arrSection = getElementsByClassName(document,"div","section");
for (var i = 0; i< arrSection.length; i++)
		{
			arrSection[i].style.display = 'none';
		}
		
function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
		 
         if (charCode > 31 && (charCode < 45 || charCode > 57))
            return false;

         return true;
      }
	  
function isNumberKey_Tel(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
     
		 if (((charCode > 31 && (charCode < 48 || charCode > 57)) && (charCode != 32) && (charCode != 43))) {
		 	return false;
		 }

         return true;
      }	  

/* TASK 4 */	  
function spec_ateco(num, counter){

	if (num == 10) // se passo il valore di default esco subito
		{return false;}
	
			if (counter == 'undefined') {
				counter = 5;
			}
	
		var patt = new RegExp("sub_");
		if (patt.test(num) == false) {
			//		var arr = num.split("_");
			
			document.getElementById("ateco_generaleResult_" + num).innerHTML = '';
			
		}
		
		var at_sub = new Array();
		var at = new Array();
		
		for (i = 1; i <= counter; i++) {
			if (document.getElementById("ateco_generale_" + i)) {
				at[i] = document.getElementById("ateco_generale_" + i).value;
				
				if (document.getElementById("ateco_generale_sub_" + i)) {
					at_sub[i] = document.getElementById("ateco_generale_sub_" + i).value;
				}
			}
		}
		 
		// AUTOMOTIVE, modificato nel task 4
		var auto = 0;
		var arrAuto = new Array(1072,1073,1074);
		
		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrAuto) || in_array(parseInt(at_sub[i]),arrAuto))
				{
					
				if (document.getElementById("div-settore_auto")) {
					document.getElementById("div-settore_auto").style.display = 'block';
					document.getElementById("lab_settore_auto").innerHTML = '<span style=\"color:#be0503"\>* Specificazione settore Auto</span>';
					auto++;
				}
			}
			
		}
		if (auto == 0) {
			if (document.getElementById("div-settore_auto")) {
				document.getElementById("div-settore_auto").style.display = 'none';
				document.getElementById("lab_settore_auto").innerHTML = 'Specificazione settore Auto';
			}
		}
		
		// BIO ALIMENTARE
		var b = 0;
		for (i = 1; i <= counter; i++) {
		
			if ((at[i] == '609') || (at[i] == '617') || (at[i] == '618')) {
				if (document.getElementById("div-flg_BIO_alimentare")) {
					document.getElementById("div-flg_BIO_alimentare").style.display = 'block';
					document.getElementById("lab_flg_BIO_alimentare").innerHTML = '<span style=\"color:#be0503"\>* Settore BIO-Alimentare?</span>';
					b++;
				}
			}
		}
		
		if (b == 0) {
			if (document.getElementById("div-flg_BIO_alimentare")) {
				document.getElementById("div-flg_BIO_alimentare").style.display = 'none';
				document.getElementById("flg_BIO_alimentare_radio_0").checked = 'checked';
				
				document.getElementById("lab_flg_BIO_alimentare").innerHTML = '* Settore BIO?';
			}
		}
		
		// TASK 4
		
		// AMBIENTE
		var amb = 0;
		var arrAmbiente = new Array(610,734, 735,736, 737, 616, 768 ,
							769 ,770, 771 ,964 ,984 ,986 ,987 ,988, 1013, 
							634, 1026, 1027, 1028, 1029 ,1030, 1031, 1032, 
							1033 ,1034 ,1036, 1041, 635,1042,1043 ,1044 ,1045 ,
							1046 ,1047 ,1048 ,1049 ,1050 ,1053 ,1058 ,1118 ,641 ,
							1119 ,1120 ,1121 ,1122 ,1123 ,1124 ,1125 ,1126 ,1127 ,
							1128 ,1129 ,642 ,1130 ,1131 ,643 ,1132,1133,644 ,1134 ,
							1135 ,1136 ,1137 ,1138 ,1139 ,1140 ,1141 ,1142 ,645 ,1143 ,
							1144 ,1154 ,1155 ,1157 ,1158 ,1162 ,1164 ,1188 ,1237 ,1239 ,
							1297 ,1300 ,1426 ,1427 ,1428 ,672, 
							1431,
							621,
							631,
							633,
							636,
							639,
							648,
							663,
							674);
							
		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrAmbiente) || in_array(parseInt(at_sub[i]),arrAmbiente))
				{
				if (document.getElementById("div-ambiente")) {
					document.getElementById("div-ambiente").style.display = 'block';
					document.getElementById("lab_ambiente").innerHTML = '<span style=\"color:#be0503"\>* L\'azienda opera nel settore ambiente e/o energia?</span>';
					amb++;
				}	
				}
		}
		if (amb == 0) {
			if (document.getElementById("div-ambiente"))
				{
				document.getElementById("div-ambiente").style.display = 'none';
					// nascondo anche settori ambiente
					document.getElementById("div-settore_ambiente").style.display = 'none';
				document.getElementById("ambiente_radio_0").checked = 'checked';
				
				document.getElementById("lab_ambiente").innerHTML = '* L\'azienda opera nel settore ambiente e/o energia?';
				
				}
		}
			// NB: l'evento che fa apparire la domanda 
			// sui settori ambiente e energia è definito in aziende.js
		 
		// SUBF METALLURGIA
		var subf_met = 0;
		var arrSubf_met = new Array('631');
		
		for (i = 1; i <= counter; i++) {
			
			if (in_array(parseInt(at[i]),arrSubf_met) || in_array(parseInt(at_sub[i]),arrSubf_met))
				{
				if (document.getElementById("div-metallurgia")) {
					document.getElementById("div-metallurgia").style.display = 'block';
					document.getElementById("lab_metallurgia").innerHTML = '<span style=\"color:#be0503"\>* Subfornitura - metallurgia?</span>';
					subf_met++;
				}	
				}
		}
		if (subf_met == 0) {
			if (document.getElementById("div-metallurgia")) {
				document.getElementById("div-metallurgia").style.display = 'none';
				// nascondo anche settori ambiente
				document.getElementById("div-settore_metallurgia").style.display = 'none';
				document.getElementById("metallurgia_radio_0").checked = 'checked';
				
				document.getElementById("lab_metallurgia").innerHTML = '* Subfornitura - metallurgia?';
			}
		}
			// NB: l'evento che fa apparire la domanda 
			// sui settori SUBF_MET è definito in aziende.js
			
			
		// SUBF PLASTICA E GOMMA
		var subf_plg = 0;
		var arrSubf_plg = new Array('629');

		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrSubf_plg) || in_array(parseInt(at_sub[i]),arrSubf_plg))
				{
				if (document.getElementById("div-plasticagomma")) {
					document.getElementById("div-plasticagomma").style.display = 'block';
					document.getElementById("lab_plasticagomma").innerHTML = '<span style=\"color:#be0503"\>* Subfornitura - plastica e gomma?</span>';
					subf_plg++;
				}	
				}
		}
		if (subf_plg == 0) {
			if (document.getElementById("div-plasticagomma")) {
				document.getElementById("div-plasticagomma").style.display = 'none';
				// nascondo anche settori ambiente
				document.getElementById("div-settore_plasticagomma").style.display = 'none';
				document.getElementById("plasticagomma_radio_0").checked = 'checked';
				
				document.getElementById("lab_plasticagomma").innerHTML = '* Subfornitura - plastica e gomma?';
			}
		}
			// NB: l'evento che fa apparire la domanda 
			// sui settori SUBF_PLG è definito in aziende.js
		
		// SUBF PRODOTTI
		var subf_prod = 0;
		var arrSubf_prod = new Array('878','1031','1006');

		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrSubf_prod) || in_array(parseInt(at_sub[i]),arrSubf_prod))
				{
				if (document.getElementById("div-prodotti")) {
					document.getElementById("div-prodotti").style.display = 'block';
					document.getElementById("lab_prodotti").innerHTML = '<span style=\"color:#be0503"\>* Subfornitura - prodotti?</span>';
					subf_prod++;
				}
				}
		}
		if (subf_prod == 0) {
			if (document.getElementById("div-prodotti")) {
				document.getElementById("div-prodotti").style.display = 'none';
				// nascondo anche settori ambiente
				// document.getElementById("div-settore_prodotti").style.display = 'none';
				document.getElementById("prodotti_radio_0").checked = 'checked';
				
				document.getElementById("lab_prodotti").innerHTML = '* Subfornitura - prodotti?';
			}
		}
			// NB: l'evento che fa apparire la domanda 
			// sui settori SUBF_PROD è definito in aziende.js
		
		
		
		// BIOTECNOLOGIE
		var biotec = 0;
		var arrBiotec = new Array('878', '879', '628' ,'918' ,'919' ,'920' ,'921' ,'1020' ,'1021' ,'1118' ,'1194' ,'1217' ,'1430' ,'1486' ,'1537','1104',
									'621','631','633','635','636','639','644','648','663','674');
	
		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrBiotec) || in_array(parseInt(at_sub[i]),arrBiotec))
				{
				if (document.getElementById("div-biotecnologie")) {
					document.getElementById("div-biotecnologie").style.display = 'block';
					document.getElementById("lab_biotecnologie").innerHTML = '<span style=\"color:#be0503"\>* L\'azienda opera nel settore delle biotecnologie?</span>';
					biotec++;
				}
				}
		}
		if (biotec == 0) {
			if (document.getElementById("div-biotecnologie")) {
				document.getElementById("div-biotecnologie").style.display = 'none';
				// nascondo anche settori ambiente
				document.getElementById("div-settore_biotecnologie").style.display = 'none';
				document.getElementById("biotecnologie_radio_0").checked = 'checked';
				
				document.getElementById("lab_biotecnologie").innerHTML = '* L\'azienda opera nel settore delle biotecnologie?';
			}
		}
			// NB: l'evento che fa apparire la domanda 
			// sui settori biotecnologie è definito in aziende.js
		
		// TENDER
		var tender = 0;
		
		var arrTender = new Array('613' , '752', '753', '754', '755','616' , '768' , '769' , '770' , '771',
									'628', '918', '919', '920', '921','1078', '1079','1103', '1104','640', '1117', '1118',
									'641', '1119','1120', '1121', '1122', '1123', '1124', '1125', '1126', '1127', '1128', '1129', 
									'642', '1130', '1131','643', '1132', '1133','644', '1134', '1135', '1136', '1137', 
									'1138', '1139','1140', '1141', '1142', '645', '1143', '1144','646', '1145', '1146', '1147', '1148', 
									'647', '1149', '1150', '1151', '1152', '1153', '1154', '1155', '1156', '1157', '1158',
									'648', '1159', '1160', '1161', '1162', '1163', '1164', '1165', '1166', '671', '1424', '1425', '1426', '1427', '1428');
	
		for (i = 1; i <= counter; i++) {
		
			if (in_array(parseInt(at[i]),arrTender) || in_array(parseInt(at_sub[i]),arrTender))
				{
				if (document.getElementById("div-tender")) {
					document.getElementById("div-tender").style.display = 'block';
					document.getElementById("lab_tender").innerHTML = '<span style=\"color:#be0503"\>* Vi interessa usufruire dei servizi di supporto alla partecipazione alle gare d\'appalto pubbliche internazionali (progetto Tender)?</span>';
					tender++;
				}
				}
		}
		if (tender == 0) {
			if (document.getElementById("div-tender")) {
				document.getElementById("div-tender").style.display = 'none';
				document.getElementById("tender_radio_0").checked = 'checked';
				
				document.getElementById("lab_tender").innerHTML = '* Vi interessa usufruire dei servizi di supporto alla partecipazione alle gare d\'appalto pubbliche internazionali (progetto Tender)?';
			}
		}
			 
		
		
		// AEROSPACE
		var asp = 0;
		for (i = 1; i <= counter; i++) {
		
			if ((at_sub[i] == "1080") || (at_sub[i] == '1081')) {
				if (document.getElementById("div-settore_asp")) {
				document.getElementById("div-settore_asp").style.display = 'block';
				document.getElementById("lab_settore_asp").innerHTML = '<span style=\"color:#be0503"\>* Aerospace capabilities</span>';
				asp++;
				}
			}
			
		}
		if (asp == 0) {
			if (document.getElementById("div-settore_asp")){
				document.getElementById("div-settore_asp").style.display = 'none';
			}
			
//			document.getElementById("div-settore_asp").innerHTML = '';
//			document.getElementById("lab_settore_asp").innerHTML = 'Aerospace capabilities';
			
		}
		
		// ICT
		var ict = 0;
		for (i = 1; i <= counter; i++) {
		
			if (
				(at[i] == '633') || (at[i] == '634') || (at[i] == '660') || (at[i] == '662') || (at[i] == '663') ||
				(at[i] == '664') ||      
				
				(at_sub[i] == "1067") || (at_sub[i] == '1072') || (at_sub[i] == '1073') || (at_sub[i] == '1074') ||
				(at_sub[i] == "1080") || (at_sub[i] == '1081') ||
				(at_sub[i] == "1221") || (at_sub[i] == '1222') || (at_sub[i] == "1223") ||
				(at_sub[i] == "1347") || (at_sub[i] == '1348') || (at_sub[i] == "1349") ||
				(at_sub[i] == "1478") || (at_sub[i] == '1493')
				) {
				if (document.getElementById("div-settore_ict")) {
					document.getElementById("div-settore_ict").style.display = 'block';
					document.getElementById("lab_settore_ict").innerHTML = '<span style=\"\">A quale/i delle seguenti filiere/cluster ritiene che la sua azienda appartenga o possa appartenere (come core business)?</span>';
					ict++;
				}
			}
			
		}
		if (ict == 0) {
			if (document.getElementById("div-settore_ict")) {
				document.getElementById("div-settore_ict").style.display = 'none';
			}
			
//			document.getElementById("div-settore_ict").innerHTML = '';
//			document.getElementById("lab_settore_ict").innerHTML = 'ICT cluster';
			
		}
		
		
		// DES
		var des = 0;
		for (i = 1; i <= counter; i++) {
		
			if (
				(at_sub[i] == '1439') || (at_sub[i] == '1440')   
				) {
				if (document.getElementById("div-settore_des")) {
					document.getElementById("div-settore_des").style.display = 'block';
					document.getElementById("lab_settore_des").innerHTML = '<span style=\"color:#be0503"\>* Settore design</span>';
					des++;
				}
			}
			
		}
		
		if (des == 0) {
			if (document.getElementById("div-settore_des")) {
				document.getElementById("div-settore_des").style.display = 'none';
			}		
//			document.getElementById("div-settore_des").innerHTML = '';
//			document.getElementById("lab_settore_des").innerHTML = 'Settore design';
			
		}
		
	 
	// rifo?
	
	
		
}


function in_array (needle, haystack, argStrict) {
    // Checks if the given value exists in the array  
    // 
    // version: 911.718
    // discuss at: http://phpjs.org/functions/in_array    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: vlado houba
    // +   input by: Billy
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);    // *     returns 1: true
    // *     example 2: in_array('vlado', {0: 'Kevin', vlado: 'van', 1: 'Zonneveld'});
    // *     returns 2: false
    // *     example 3: in_array(1, ['1', '2', '3']);
    // *     returns 3: true    // *     example 3: in_array(1, ['1', '2', '3'], false);
    // *     returns 3: true
    // *     example 4: in_array(1, ['1', '2', '3'], true);
    // *     returns 4: false
    var key = '', strict = !!argStrict; 
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {                return true;
            }
        }
    }
     return false;
}

