
//LA FUNZIONE VA RICHIAMATA NEL TAG form IN QUESTO MODO:
//<form name="modulo" action="sendmail.asp" method="post" onsubmit="return controllo('modulo', 'nome,email,msg'); return false;">
//INDICANDO NELL' onsubmit= IL NOME DEL FORM STESSO E IL NOME DEI CAMPI DA CONTROLLARE SEPARATI DA VIRGOLA
function controllo(formnome, arr) {
	// Controllo dei campi form (text-textarea-radio-select-checkbox)
	 
	var col_array = arr.split(",");

	var part_num=0;
	
	while (part_num < col_array.length)
	{
		var nomecampo = col_array[part_num];
		//
		var tipocampo = document.forms[formnome].elements[nomecampo].type; 
				
// ############################################################

			// Campo testo
			if (tipocampo ==  'text' || tipocampo == 'password') {
			
				// Se campo testo email
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				//alert(valorecampo.length);
				if (nomecampo.indexOf("email") != -1 && (valorecampo.indexOf("@") == -1 || valorecampo.indexOf(".") == -1 || valorecampo < 8)) {
					alert('Formato email non valido');
					return false;
				
				} else {
					// Se campo testo non email
					if (!valorecampo) {
						if (nomecampo == 'foto') {
							alert('Devi caricare almeno una tua foto per continuare');
						} else {
							alert('Per favore compila il campo ' + nomecampo);
						}
						return false;
					}
				}
						
			}
		

// ############################################################
				
		// Campo textarea
		else if (tipocampo ==  'textarea') {
				
				// Se campo textarea
				var valorecampo = document.forms[formnome].elements[nomecampo].value;
				if (!valorecampo) {
					alert('Per favore compila il campo ' + nomecampo);
					return false;
				}
		
		}

// ############################################################
		
		// Campo checkbox
		else if (tipocampo ==  'checkbox') {
				
				// Se campo checkbox
				var valorecampo = document.forms[formnome].elements[nomecampo].checked;
				if (!valorecampo) {
					alert('Il Campo "' + nomecampo + '" deve essere obbligatoriamente selezionato per continuare');
					return false;
				}
						
		}

	
// ############################################################
		
		// Campo select
		else if (tipocampo ==  'select-one') {
			var valorecampo = document.forms[formnome].elements[nomecampo].value;
			if(!valorecampo){
				alert('Per favore compila il campo ' + nomecampo);
				return false;
			}		
		}

// ############################################################
		
		// Campo radio
		//else {
		//	var valorecampo = document.modulo.sesso.value;
		//	if (!valorecampo) {
		//		alert('Campo ' + nomecampo + ' non selezionato');
		//	}
		
		//}

// ############################################################		


		part_num+=1;
	}
}




function acc_legge() {
	// Controllo accettazione leggi

	var consenso1 = document.forms['modulo'].elements['consenso1'].checked;
	var consenso2 = document.forms['modulo'].elements['consenso2'].checked;
	
	if (!consenso1) {
		alert('Per continuare devi autorizzare la pubblicazione delle foto selezionando la casella accanto al testo');
		return false;
	}
	if (!consenso2) {
		alert('Per continuare devi autorizzare la legge sul trattamento dei dati personali selezionando la casella accanto al testo');
		return false;
	}
}


function show(name, action)
{
	element = document.getElementById(name);
	if(action=="1")
		element.style.display = "block";
	else if(action=="2")
		element.style.display = "none";
}

function roll(mode,nome,over)
{
	if(mode=="over")
	{
		imgOver="imgg/"+nome+"_over.gif";
		document[nome].src=imgOver;
	}

	if(mode=="out")
	{
		imgOut="imgg/"+nome+".gif";
		document[nome].src=imgOut;
	}
}



// Dunzione ajax che scrive completa la domanda/risposta
function ajaxFunction(id)
{
var id;
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
		document.getElementById('d'+id).innerHTML =xmlHttp.responseText;
	  }
    }
  xmlHttp.open("GET","scrivi.php?id="+id,true);
  xmlHttp.send(null);
  }

//##### Funzione ajax che apre in modifica la notizia #####
function ajax(id,tipo)
{
var id;
var tipo;
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
		document.getElementById('modificanotizia').innerHTML =xmlHttp.responseText;
	  }
    }
  xmlHttp.open("GET","ajax"+tipo+".php?id="+id,true);
  xmlHttp.send(null);
  }

// Apertura banner in preview nella gestione banner
function apri(p,w,h)
{
	window.open(p,'Caricamento','left=150,top=150,width='+w+',height='+h+',titlebar=no,menubar=no,toolbar=no');
	return false;
}

//##### Funzione ajax che apre in modifica la notizia #####
function ajaxcopertine()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
		document.getElementById('listacopertine').innerHTML =xmlHttp.responseText;
	  }
    }
  xmlHttp.open("GET","ajaxcopertine.php",true);
  xmlHttp.send(null);
  }

// Ajax fatti della settimana
//##### Funzione ajax che apre in modifica la notizia #####
function ajaxfatti()
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
		document.getElementById('listafatti').innerHTML =xmlHttp.responseText;
	  }
    }
  xmlHttp.open("GET","ajaxfatti.php",true);
  xmlHttp.send(null);
  }


function ajaxpasspersa(email)
{
	var email;
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e)
	{
		alert("Your browser does not support AJAX!");
		return false;
	}
	}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
	document.getElementById('risposta').style.display = 'block';
	document.getElementById('risposta').innerHTML = xmlHttp.responseText;
	document.getElementById('passpersa').style.display = 'none';
	setTimeout("document.getElementById('risposta').style.display='none';",8000);
}
}
xmlHttp.open("GET","passpersa.php?email="+email,true);
xmlHttp.send(null);
}

// FUNZIONE CHE LANCIA APERTURA DIV IN HOMEPAGE CON NOTIZIA IN PRIMA PAGINA DELLE RUBRICHE
function ajaxrubrica(val1,val2,val3,val4,val5,val6,val7,val8,sezione)
{
	document.getElementById(val1).className='segna';
	document.getElementById(val2).className='';
	document.getElementById(val3).className='';
	document.getElementById(val4).className='';
	document.getElementById(val5).className='';
	document.getElementById(val6).className='';
	document.getElementById(val7).className='';
	document.getElementById(val8).className='';

	var sezione;
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e)
	{
		alert("Your browser does not support AJAX!");
		return false;
	}
	}
}
xmlHttp.onreadystatechange=function()
{
	if(xmlHttp.readyState==4)
	{
		document.getElementById('bellezza').innerHTML = xmlHttp.responseText;
	}
}
xmlHttp.open("GET","rand-rubrica.php?sezione="+sezione,true);
xmlHttp.send(null);
}

function ajaxremove(fold,foto,id)
{
	var fold;
	var foto;
	var id;
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	catch (e)
	{
		alert("Your browser does not support AJAX!");
		return false;
	}
	}
}
xmlHttp.onreadystatechange=function()
{
	if(xmlHttp.readyState==4)
	{
		document.getElementById('rimossa').innerHTML = xmlHttp.responseText;
	}
}
xmlHttp.open("GET","ajaxremove.php?fold="+fold+"&foto="+foto+'&id='+id,true);
xmlHttp.send(null);
}
// Segno Zodiacale
function segno_di_oggi () {
var dt = new Date();
var day = dt.getDate();
var month = dt.getMonth()+1;
var sign_name =
['','Ariete','Toro','Gemelli','Cancro','Leone','Vergine','Bilancia','Scorpione','Sagittario','Capricorno','Acquario','Pesci'];
var periodo_segno =
['','21 Marzo - 20 Aprile','21 Aprile - 20 Maggio','21 Maggio - 21 Giugno','22 Giugno - 22 Luglio','23 Luglio - 23 Agosto','24 Agosto - 22 Settembre','23 Settembre - 22 Ottobre','23 Ottobre - 22 Novembre','23 Novembre - 21 Dicembre','22 Dicembre - 20 Gennaio','21 Gennaio - 18 Febbraio','20 Febbraio - 20 Marzo'];

var tresh = [0,19,20,21,22,22,22,22,21,21,19,18,20];
var sign = month-3; // segno: 1=ariete
if (sign<=0) sign += 12;
if (day>tresh[month]) sign += 1;
if (sign>12) sign -= 12;
document.getElementById('text-segno').innerHTML=sign_name[sign];
// Minuscolo
imgsegno = sign_name[sign];
icona = imgsegno.toLowerCase();
document.getElementById("img-segno").src = "oroscopo/segni/" + icona + ".gif"; 
document.getElementById('periodo-segno').innerHTML=periodo_segno[sign];
document.getElementById('link-segno').innerHTML='<a href="/oroscopo/segno.php?segno='+icona+'" onclick="return hs.htmlExpand(this, {objectType: \'iframe\', width: 950, height: 240} )" title="Continua a leggere l\'oroscopo del segno della settimana" class="link_rosso">Leggi l\'oroscopo</a>';
//return sign_name[sign];
}
