function rollOver(element) 
	{
	for( var x = 0; element.childNodes[x]; x++ )
		{
		if( element.childNodes[x].tagName == 'UL' )
				element.childNodes[x].style.display = 'block';
		}
	}

function rollOut(element)
	{
	for( var x = 0; element.childNodes[x]; x++)
		{
		if(element.childNodes[x].tagName == 'UL')
			element.childNodes[x].style.display = 'none';
		}
	}

function cookie_create(name, value, dominio)
	{
	var date = new Date();
	date.setTime(date.getTime() + (24*60*60*365));
	var expires = "; expires=" + date.toGMTString();

	var gaotd_host = dominio;
	var domain = "; domain=" + gaotd_host;
	document.cookie = name + "=" + value + expires + domain + "; path=/";
	}

function cookie_read(name)
	{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
		{
		var c = ca[i];
		while (c.charAt(0)==' ') 
			c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length,c.length);
		}
	return null;
	}

function set_lang_cookie(url, dominio)
	{
	var lang = cookie_read("dominio");
	if (lang == null)
		{
		cookie_create("dominio", url, dominio);
		}
	else if (lang != url)
		{
		cookie_create("dominio", "", -1);
		cookie_create("dominio", url, 10);
		}
	window.location = 'http://' + url + '.' + dominio;
	}


function apriChiudi(div, id)
	{
	var parent1 = div.parentNode.parentNode.childNodes;
	var parent1_length = div.parentNode.parentNode.childNodes.length;
	//alert(div.className);
	if(/apri/i.test(div.className))
		{
		for(i = 0; i < parent1_length; i++)
			{
			if(parent1[i].tagName == 'DIV')
				{
				if(parent1[i].id.match(/id_\d+/))
					parent1[i].style.display = 'none';
				var parent2 = parent1[i].childNodes;
				var parent2_length = parent2.length;
				for(x = 0; x < parent2_length; x++)
					{
					if(parent2[x].tagName == 'DIV')
					if(parent2[x].id.match(/id_\d+/))
						parent2[x].style.display = 'none';
					
					var parent3 = parent2[x].childNodes;
					var parent3_length = parent3.length;
					for(n = 0; n < parent3_length; n++)
						if(parent3[n].className == 'spazio chiudi')
							parent3[n].className = 'spazio apri';
					if(parent2[x].className == 'spazio chiudi')
						parent2[x].className = 'spazio apri';
					}
				}
			}
		div.className = 'spazio chiudi';
		document.getElementById('id_' + id).style.display = 'block';
		}
	else
		{
		div.className = 'spazio apri';
		document.getElementById('id_' + id).style.display = 'none';
		}
//	alert(div.className);
	}
	
function verificaForm()
	{
	Invia = true;
	
	if(trim(document.getElementById('azienda').value) == '')
		{
		document.getElementById('azienda').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('azienda').className = 'input';
		}
		
	if(trim(document.getElementById('nome').value) == '')
		{
		document.getElementById('nome').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('nome').className = 'input';
		}
		
	if(trim(document.getElementById('cognome').value) == '')
		{
		document.getElementById('cognome').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('cognome').className = 'input';
		}
		
	if(!document.getElementById('email').value.match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/))
		{
		document.getElementById('email').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('email').className = 'input';
		}
		
/*		
	if(!/^(?:https?:\/\/[\-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]|)$/i.test(document.getElementById('web').value))
		{
		document.getElementById('web').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('web').className = 'input';
		}
	
	if(trim(document.getElementById('indirizzo').value) == '')
		{
		document.getElementById('indirizzo').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('indirizzo').className = 'input';
		}
*/		
	if(trim(document.getElementById('oggetto').value) == '')
		{
		document.getElementById('oggetto').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('oggetto').className = 'input';
		}
		
	countDestinatario = document.getElementById('form2mail').destinatario.length;
	checked = false;
	for(i = 0; i < countDestinatario; i++)
		if(document.getElementById('form2mail').destinatario[i].checked)
			checked = true;
	if(checked == false)
		{
		document.getElementById('destinatario').style.color = '#DF5E00';
		document.getElementById('destinatario').style.fontWeight = 'bold';
		Invia = false;
		}
	else
		{
		document.getElementById('destinatario').style.color = '';
		document.getElementById('destinatario').style.fontWeight = '';
		}
			
	if(trim(document.getElementById('testo').value) == '')
		{
		document.getElementById('testo').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('testo').className = 'textarea';
		}
		
	if(document.getElementById('privacy').checked == false)
		{
		Invia = false;
		document.getElementById('accettoPrivacy').style.color = '#DF5E00';
		document.getElementById('accettoPrivacy').style.fontWeight = 'bold';
		}
	else
		{
		document.getElementById('accettoPrivacy').style.color = '';
		document.getElementById('accettoPrivacy').style.fontWeight = '';
		}

	

	if(trim(document.getElementById('captcha').value) == '')
		{
		document.getElementById('captcha').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('captcha').className = 'input';
		}
	
	if(Invia == false)
		document.getElementById('paragrafoErrori').style.visibility = 'visible';
	else
		document.getElementById('form2mail').submit();
	}
	
function trim(stringa)
	{
	while (stringa.substring(0,1) == ' ')
		{
		stringa = stringa.substring(1, stringa.length);
		}
	while (stringa.substring(stringa.length-1, stringa.length) == ' ')
		{
		stringa = stringa.substring(0,stringa.length-1);
		}
	return stringa;
	}

function selezionaTutto(bottone, array, deseleziona, seleziona)
	{
	if(bottone.innerHTML == seleziona)
		{
		for(i = 0; i < array.length; i++)
			array[i].checked = true;
		bottone.innerHTML = deseleziona;
		}
	else
		{
		for(i = 0; i < array.length; i++)
			array[i].checked = false;
		bottone.innerHTML = seleziona;
		}
	}
	
function categorieDownload(id)
	{
	var stringa = '';
	var lingue = '';
	var i = 0;
	lingue = document.getElementsByName('linguaDownload[]');
	for(i = 0; i < lingue.length; i++)
		if(lingue[i].checked == true)
			stringa += '&l[]=' + lingue[i].value;
	window.location.href = '?action=categoria&cat=5&cd=' + id + stringa;
	}
	
function fileDownload(cat, subcat)
	{
	var stringa = '';
	var lingue = '';
	var i = 0;
	lingue = document.getElementsByName('linguaDownload[]');
	for(i = 0; i < lingue.length; i++)
		if(lingue[i].checked == true)
			stringa += '&l[]=' + lingue[i].value;
	window.location.href = '?action=categoria&cat=5&cd=' + cat + '&sc=' + subcat + stringa;
	}
	
function verificaFormInfo()
	{
	Invia = true;

	if(trim(document.getElementById('nome').value) == '')
		{
		document.getElementById('nome').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('nome').className = 'input';
		}
		
	if(trim(document.getElementById('cognome').value) == '')
		{
		document.getElementById('cognome').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('cognome').className = 'input';
		}

	if(trim(document.getElementById('paese').value) == '')
		{
		document.getElementById('paese').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('paese').className = 'input';
		}
		
	document.getElementById('telefono').className = 'input';
	document.getElementById('mail').className = 'input';
	contatto = document.getElementById('info').contatto.length;
	checked = true;
	for(i = 0; i < contatto; i++)
		if(document.getElementById('info').contatto[i].checked)
			checked = false;

	if(checked == true)
		{
		document.getElementById('testoContatto').className += ' paragrafoErrori';
		Invia = false;
		}
	else
		{
		document.getElementById('testoContatto').className = 'testoContatto';
		
		if(document.getElementById('info').contatto[0].checked)
			if(trim(document.getElementById('mail').value) == '')
				{
				document.getElementById('mail').className += ' errori';
				Invia = false;
				}
			else
				{
				document.getElementById('mail').className = 'input';
				}
		
		if(document.getElementById('info').contatto[1].checked)
			if(trim(document.getElementById('telefono').value) == '')
				{
				document.getElementById('telefono').className += ' errori';
				Invia = false;
				}
			else
				{
				document.getElementById('telefono').className = 'input';
				}
		}

	if(document.getElementById('privacy').checked == false)
		{
		Invia = false;
		document.getElementById('accettoPrivacy').style.color = '#DF5E00';
		document.getElementById('accettoPrivacy').style.fontWeight = 'bold';
		}
	else
		{
		document.getElementById('accettoPrivacy').style.color = '';
		document.getElementById('accettoPrivacy').style.fontWeight = '';
		}

	

	if(trim(document.getElementById('captcha').value) == '')
		{
		document.getElementById('captcha').className += ' errori';
		Invia = false;
		}
	else
		{
		document.getElementById('captcha').className = 'input';
		}
	if(Invia == false)
		document.getElementById('paragrafoErrori').style.visibility = 'visible';
	else
		document.getElementById('info').submit();
	}
	
function registra(erroreAccept)
	{
	if(document.getElementById('accept').checked == true)
		return true;
	else
		{
		document.getElementById('errori').innerHTML = erroreAccept;
		return false;
		}
	}
	
function verificaDownload()
	{
	invia = false;
	file = document.getElementsByName('file[]').length;
	for(i = 0; i < file; i++)
		if(document.getElementById('file' + i).checked)
			invia = true;
	if(invia == true)
		return true;
	else
		return false;
	}
