/**
 * @author Carmelo
 */
function check_fattori_primari(obj, max_checks){
	if (obj.checked == false) {
		if (document.questionario.priorita_1.value == obj.value) 
			document.questionario.priorita_1.value = '';
		if (document.questionario.priorita_2.value == obj.value) 
			document.questionario.priorita_2.value = '';
		if (document.questionario.priorita_3.value == obj.value) 
			document.questionario.priorita_3.value = '';
		obj.checked = false;
		return;
	}
	
	var checked = 0;
	
	if (document.questionario.pri_a.checked == true) 
		checked++;
	if (document.questionario.pri_b.checked == true) 
		checked++;
	if (document.questionario.pri_c.checked == true) 
		checked++;
	if (document.questionario.pri_d.checked == true) 
		checked++;
	if (document.questionario.pri_e.checked == true) 
		checked++;
	if (document.questionario.pri_f.checked == true) 
		checked++;
	if (document.questionario.pri_g.checked == true) 
		checked++;
	if (document.questionario.pri_h.checked == true) 
		checked++;
	if (document.questionario.pri_i.checked == true) 
		checked++;
	if (document.questionario.pri_j.checked == true) 
		checked++;
	if (document.questionario.pri_k.checked == true) 
		checked++;
	if (document.questionario.pri_l.checked == true) 
		checked++;
	
	if (checked > max_checks) {
		obj.checked = false;
		return;
	}
	
	else {
		if (document.questionario.priorita_1.value != '') 
			if (document.questionario.priorita_2.value != '') 
				document.questionario.priorita_3.value = obj.value;
			else 
				document.questionario.priorita_2.value = obj.value;
		else 
			document.questionario.priorita_1.value = obj.value;
		
		obj.checked = true;
		return;
	}
}

function check_form(obj){
	
	var frequenza_utilizzo = obj.frequenza_utilizzo.value;
	
	//variabili radio (binarie)
	var settore = false;
	var soddisfazione_generale = false;
	var efficienza = false;
	var prestazioni_previste = false;
	var comunicazione = false;
	var servizi = false;
	var professionalita = false;
	var qualita_prodotti = false;
	var qualita_prodotti = false;
	var rapidita_intervento = false;
	var documentazione = false;
	var collaborazioni_future = false;
	var pri_qualita = false;
	var pri_consegna = false;
	var pri_costi = false;
	var rapidita_risposta = false;
	var facilita_reperibilita = false;
	var capacita_soddisfare_richieste = false;
	var capacita_professionale = false;
	var celerita_supporto = false;
	var qualita_documentazione = false;
	var rapidita_risposta = false;
	var aggiornamento_prodotti = false;
	var corrispondenza_fornito_previsto = false;
	var supporto_tecnico = false;
	var reperibilita_personale = false;
	var tempi_modi_pagamento = false;
	var facilita_pagamento = false;
	var reclami_facilita_contatti = false;
	var reclami_attenzione_fornita = false;
	var reclami_rapidita = false;
	var reclami_strumenti = false;

	for (counter = 0; counter < obj.settore.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.settore[counter].checked) 
			settore = true;
	}

	for (counter = 0; counter < obj.soddisfazione_generale.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.soddisfazione_generale[counter].checked) 
			soddisfazione_generale = true;
	}
	
	for (counter = 0; counter < obj.efficienza.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.efficienza[counter].checked) 
			efficienza = true;
	}
	
	for (counter = 0; counter < obj.prestazioni_previste.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.prestazioni_previste[counter].checked) 
			prestazioni_previste = true;
	}
	
	
	for (counter = 0; counter < obj.comunicazione.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.comunicazione[counter].checked) 
			comunicazione = true;
	}
	
	
	for (counter = 0; counter < obj.servizi.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.servizi[counter].checked) 
			servizi = true;
	}
	
	
	for (counter = 0; counter < obj.professionalita.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.professionalita[counter].checked) 
			professionalita = true;
	}
	
	
	for (counter = 0; counter < obj.qualita_prodotti.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.qualita_prodotti[counter].checked) 
			qualita_prodotti = true;
	}
	
	
	for (counter = 0; counter < obj.qualita_prodotti.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.qualita_prodotti[counter].checked) 
			qualita_prodotti = true;
	}
	
	
	for (counter = 0; counter < obj.rapidita_intervento.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.rapidita_intervento[counter].checked) 
			rapidita_intervento = true;
	}
	
	
	for (counter = 0; counter < obj.documentazione.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.documentazione[counter].checked) 
			documentazione = true;
	}
	
	
	for (counter = 0; counter < obj.collaborazioni_future.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.collaborazioni_future[counter].checked) 
			collaborazioni_future = true;
	}
	
	
	for (counter = 0; counter < obj.pri_qualita.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.pri_qualita[counter].checked) 
			pri_qualita = true;
	}
	
	
	for (counter = 0; counter < obj.pri_consegna.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.pri_consegna[counter].checked) 
			pri_consegna = true;
	}
	
	
	for (counter = 0; counter < obj.pri_costi.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.pri_costi[counter].checked) 
			pri_costi = true;
	}
	
	
	for (counter = 0; counter < obj.rapidita_risposta.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.rapidita_risposta[counter].checked) 
			rapidita_risposta = true;
	}
	
	
	for (counter = 0; counter < obj.facilita_reperibilita.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.facilita_reperibilita[counter].checked) 
			facilita_reperibilita = true;
	}
	
	
	for (counter = 0; counter < obj.capacita_soddisfare_richieste.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.capacita_soddisfare_richieste[counter].checked) 
			capacita_soddisfare_richieste = true;
	}
	
	
	for (counter = 0; counter < obj.capacita_professionale.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.capacita_professionale[counter].checked) 
			capacita_professionale = true;
	}
	
	
	for (counter = 0; counter < obj.celerita_supporto.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.celerita_supporto[counter].checked) 
			celerita_supporto = true;
	}
	
	
	for (counter = 0; counter < obj.qualita_documentazione.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.qualita_documentazione[counter].checked) 
			qualita_documentazione = true;
	}
	
	for (counter = 0; counter < obj.rapidita_risposta.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.rapidita_risposta[counter].checked) 
			rapidita_risposta = true;
	}
	
	
	for (counter = 0; counter < obj.aggiornamento_prodotti.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.aggiornamento_prodotti[counter].checked) 
			aggiornamento_prodotti = true;
	}
	
	
	for (counter = 0; counter < obj.corrispondenza_fornito_previsto.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.corrispondenza_fornito_previsto[counter].checked) 
			corrispondenza_fornito_previsto = true;
	}
	
	
	for (counter = 0; counter < obj.supporto_tecnico.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.supporto_tecnico[counter].checked) 
			supporto_tecnico = true;
	}
	
	
	for (counter = 0; counter < obj.reperibilita_personale.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.reperibilita_personale[counter].checked) 
			reperibilita_personale = true;
	}
	
	for (counter = 0; counter < obj.tempi_modi_pagamento.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.tempi_modi_pagamento[counter].checked) 
			tempi_modi_pagamento = true;
	}
	
	for (counter = 0; counter < obj.facilita_pagamento.length; counter++) {
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (obj.facilita_pagamento[counter].checked) 
			facilita_pagamento = true;
	}
	
	Tips.remove('settore_id');
	
	if (! settore) {
		location.hash = "#campo_settore";
		enfatize('settore_id');
		tooltip = new Tip('settore_id', 'Selezionare un campo tra Pubblico e Privato', {
			effect: 'appear',
			className: 'toolTip',
			hook: {
				target: 'topRight',
				tip: 'bottomRight'
			},
			offset: {
				x: 4,
				y: 0
			}
		});
		return;
	}
	
	Tips.remove('frequenza_utilizzo_id');
	
	if ((!isNumberString(frequenza_utilizzo)) && (frequenza_utilizzo.length>0)) {
		location.hash = "#campo_frequenza_utilizzo";
		enfatize('frequenza_utilizzo_id');
		tooltip = new Tip('frequenza_utilizzo_id', 'Inserire un valore numerico', {
			effect: 'appear',
			className: 'toolTip',
			hook: {
				target: 'topRight',
				tip: 'bottomRight'
			},
			offset: {
				x: 4,
				y: 0
			}
		});
		return;
	}
	
	obj.submit();
}
	
function enfatize(elementID)
{
	$(elementID).setStyle({
		backgroundColor: '#fdff74'
	});
}

function isNumberString (InString)  {
		if(InString.length==0) return (false);
		var RefString="1234567890";
		for (Count=0; Count < InString.length; Count++)  {
			TempChar= InString.substring (Count, Count+1);
			if (RefString.indexOf (TempChar, 0)==-1)  
				return (false);
		}
		return (true);
	}
