// JavaScript Document
function Controllo(ErrorDiv,OkDiv){
	var Titolo = "";
	var Rivolto = "";
	var Luogo = "";
	var ErrN = 0;
	if(document.getElementById("TitoloCorso").value == ""){
		ErrN++
	Titolo = ErrN+") Inserisci il titolo del corso<br>";}
	if(document.getElementById("Rivolto").options[document.getElementById("Rivolto").selectedIndex].value == "Seleziona"){
		ErrN++
	Rivolto = ErrN+") Seleziona a che è rivolto il corso<br>";}
	if(Titolo!="" || Rivolto!=""){
	var error = Titolo + Rivolto
	Avviso(ErrorDiv,error)
		return false;}else{
				var element = document.createElement("iframe")
				var el = document.createElement("div")
				var img = document.createElement("img")
				img.setAttribute("src","../images/indicator.white.gif")
				img.setAttribute("alt","attesa")
				el.setAttribute("id","attendere");
				el.innerHTML="Attendere prego...";
				element.setAttribute("id","FrameUpload");
				element.setAttribute("name","FrameUpload")
				element.setAttribute("src","editor/pubblicacorso.asp")
				element.setAttribute("frameborder","0")
				element.setAttribute("scrolling","auto")
				element.setAttribute("width","100%")
				element.setAttribute("height","300px")
				el.appendChild(img)
				document.getElementById(OkDiv).appendChild(el)
				document.getElementById(OkDiv).appendChild(element)
			ApriDiv(null,OkDiv)
			}
	}
function Avviso(div,err){
		  var element = document.createElement("div")
				element.setAttribute("id","errorecorsi");
				element.setAttribute("title","Premi qui per chiudere")
				element.onclick=function(){document.getElementById('formaction').style.display='none';document.getElementById('copripagina').style.visibility='hidden';document.getElementById("formaction").removeChild(element)}
				element.innerHTML=err;
				document.getElementById("formaction").appendChild(element)
	  ApriDiv(null,div)
document.getElementById('formaction').focus()
}
/* script disattivato
function ValidaData(imput){
var DD = 0
var Error = "";
var Conferma = "";
var d = new Date(document.getElementById('DataCorsoAA').value,document.getElementById('DataCorsoMM').value-1,document.getElementById('DataCorsoGG').value);
if (!(d.getDate() == document.getElementById('DataCorsoGG').value))DD = 1
else if (!(d.getMonth() == document.getElementById('DataCorsoMM').value-1))DD = 2
//alert(MM)
  var now = new Date();
  var anno = now.getFullYear().toString()
  var mese = (now.getMonth()+1 <=9)? "0"+(now.getMonth()+1) : now.getMonth()+1
  var giorno = (now.getDate() <=9)? "0"+(now.getDate()) : now.getDate()
  var date = giorno+"-"+mese+"-"+anno
  var oggi = document.getElementById("DataCorsoAA").value+document.getElementById("DataCorsoMM").value +document.getElementById("DataCorsoGG").value 
  var valoredefault = ((now.getDate() <=9)? "0"+(now.getDate()+1) : now.getDate()+1)+" - "+mese+" - "+anno
  var dataoggi = anno+mese+giorno
  var datainserita = oggi
  //alert(dataoggi +" "+datainserita)
  var dif = ( dataoggi <= datainserita)? true : false
  //document.getElementById("DataCorsoGG").value=document.getElementById('DataCorsoMM').value
  //document.getElementById('DataCorsoAA').value=document.getElementById("DataCorsoGG").value
  //document.getElementById('DataCorsoMM').value=document.getElementById('DataCorsoAA').value
  if(DD==1){
	  Error = "Il giorno inserito "+document.getElementById("DataCorsoGG").value+" è sbagliato  per il mese inserito "+document.getElementById("DataCorsoMM").value+" <br><a href=\"javascript:;\" onclick=\"document.getElementById('DataCorsoGG').value='';\">Chiudi</a>";}else if(DD==2){
		  Error = "Il mese inserito "+document.getElementById("DataCorsoMM").value+" è sbagliato verificare!! <br><a href=\"javascript:;\" onclick=\"document.getElementById('DataCorsoMM').value='';\">Chiudi</a>";
	  
}
  if(!dif){
	  Error = "Non puoi inserire date antecedenti ad oggi "+date+"<br><a href=\"javascript:;\" onclick=\"document.getElementById('DataCorsoGG').value='';\">Chiudi</a>";}
  else if(dataoggi == datainserita){
  Conferma = "Attenzione!!!\nSicuro di voler inserire la data odierna ["+date+"]?<br><center><a href='#'>Confermo</a> | <a href='javascipt:;' onclick='document.getElementById(\"DataCorsoGG\").value=\"\";document.getElementById(\"DataCorsoGG\").focus();return false;'>Annulla</a></center>";
	  }
  if(Error!="" || Conferma !=""){
	  var err = Error+Conferma
	  Avviso('formaction',err)
	  }
}
*/
function Accesso(){
	Visualizza('?user='+document.getElementById('user').value+'&login='+document.getElementById('login').value,'accesso.asp','ouput','post')
	}
function ApriDiv(Page,Contenitore){		
var copri = document.getElementById("copripagina");
var formlogin = document.getElementById(Contenitore);
var browser_type=navigator.appName
if(browser_type == "Microsoft Internet Explorer"){
copri.style.height = document.body.scrollHeight+"px";
copri.style.visibility='visible';
copri.style.filter = "alpha(opacity=70)";
formlogin.style.display = "block";
}else{
copri.style.height = window.innerHeight+window.scrollMaxY+"px";
copri.style.visibility='visible';
copri.style.opacity = 0.7;
formlogin.style.display = "block";
}
}
	function Action(azione,pag1,pag2,contenitore,invio){
		if(azione == "articoli"){
			var id = document.getElementsByTagName("input")
			var idArticolo = "";
			var action = "?id="
			for(var i = 0; i < id.length; i++){
				if(id[i].type == "checkbox" && id[i].checked){					
				idArticolo += id[i].value+","
					action+=idArticolo
				}
			}
		}
		else{
			action = azione;
			}
	
		ApriDiv(pag1,contenitore)
		Visualizza(action,pag2,contenitore,invio)
		
} 
  function RemoveDisabled(){
	  	var ID = document.getElementsByTagName("input");
		var but = document.getElementById("Elimina")
		var flag = 0;
			for(var i = 0; i < ID.length; i++){
			if(ID[i].type=="checkbox" && ID[i].checked)
				flag++
			if(flag>0){but.removeAttribute("disabled","disabled");
		}else {
			but.setAttribute("disabled","disabled")
			}
		}
}
function VerificaBlog(){
	var title = document.getElementById("titolo");
	var testo = document.getElementById("elm2").value;
	if(title.value == ""){
		alert("Inserire il titolo");
		title.focus();
		return false;
	}
	if(testo.value == ""){
		alert("Inserire il testo");
		testo.focus();
		return false;
	}

	}
function objAjx(){
	    var xmlhttp = null;
    	
	    if(window.XMLHttpRequest) 
	    {
		    xmlhttp = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera, Internet Explorer 7
	    } 
	    else if(window.ActiveXObject) 
	    {
		    try
		    {
			    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer 6 
		    } 
		    catch(e) 
		    {
			    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 4,5 
		    }
		    } 
	    else 
	    {
		    xmlhttp = null;
	    }
	    return xmlhttp;
    };
		function Visualizza(azione,pagina,div,invio){
//alert(azione)

		AjaX = objAjx();
         if(AjaX){
			 //Invio i dati in post 
			if(invio=="post"){
            args = azione.split("?")[1];
            file = azione.split("?")[0];


            AjaX.open("POST", pagina+file, true);
            AjaX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			AjaX.send(args);
			
           //Chiamo la funzione caricoRisultati quando c'è un cambio evento    
           AjaX.onreadystatechange=function(){
   //Se è andato tutto bene faccio vedere il risultato

		  if (AjaX.readyState == 4 && AjaX.status==200){
		  if(AjaX.responseText == "Utente errato o mancante"){
			  document.getElementById(div).innerHTML = AjaX.responseText
			  document.getElementById(div).className='errorlog';
			  setTimeout(function(){
								  document.getElementById(div).innerHTML = '';
								  document.getElementById(div).className=''}
,3000)
	  	  }else if(AjaX.responseText == "admin"){
		document.getElementById(div).innerHTML = AjaX.responseText
		  top.location.href='pannello.asp';
		  }else if(AjaX.responseText.indexOf("Commento inserito grazie")!=-1){
			  setTimeout("location.reload()",3000)
		document.getElementById(div).innerHTML = AjaX.responseText;}
	  	}
      } 
	}
		else{
           //Invio i dati in get
              AjaX.open('GET', pagina+azione+"&noCache="+ Math.floor(Math.random() * (9999)), true)
              AjaX.send(null) 
			  //Chiamo la funzione caricoRisultati quando c'è un cambio evento    
              AjaX.onreadystatechange=function(){
   //Se è andato tutto bene faccio vedere il risultato
//alert(AjaX.responseText)
        if (AjaX.readyState == 4 && AjaX.status==200){
		  if(AjaX.responseText.indexOf("Articolo/i eliminato/i")!=-1){
		  document.getElementById(div).innerHTML = AjaX.responseText
    	  setTimeout("location.reload()",3000)
		  }else if(AjaX.responseText.indexOf("Commento eliminato")!=-1){
		  document.getElementById(div).innerHTML = AjaX.responseText
    	  setTimeout("location.reload()",3000)
		  }else{
		document.getElementById(div).innerHTML = AjaX.responseText;
		if(pagina == "inseriscicommento.asp"){
			Spay()
			document.getElementById("inputTextCod").setAttribute("autocomplete","off");
			document.getElementById("inputTextCod").value='Inserisci qui il risultato';
			document.getElementById("avvisotitolo").innerHTML='(Per leggere l\'articolo clicca sul titolo)';}
			}
	      }
		} 
	  }
	}
}
function Control(){
var salva = (document.getElementById('salva').checked)? "si" : "no";
var salva = "no";
//var cod = 0;
//var TestCod = document.getElementById("Codice").innerHTML;
//var num = TestCod.split(" ")
//var num1 = parseInt(num[0])
//var num2 = parseInt(num[2])
//if(num[1] == "x"){
//'cod += (num1 * num2)
//'}else if(num[1] == "-"){
//cod += (num1 - num2)
//}else if(num[1] == "+"){
//cod += (num1 + num2)
//}
var mail  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var commento = "";
var email = "";
//var codice = "";
if(document.getElementById("mail").value == ""){
email = "Inserisci la tua email\n";
document.getElementById("mail").style.backgroundColor='#990000';
}else if(!mail.test(document.getElementById("mail").value)){
email = "Inserisci una email valida\n";
document.getElementById("mail").style.backgroundColor='#990000';
}
if(document.getElementById("inputAreaCommenti").value == ""){
commento = "Inserisci un commento\n";
document.getElementById("inputAreaCommenti").style.backgroundColor='#990000';
}

//if(document.getElementById("inputTextCod").value != cod){
//codice = "Inserisci la somma corretta\n";
//document.getElementById("inputTextCod").style.backgroundColor='#990000';
//}
var Msg = "Verifica i seguenti campi:\n\n";
if((email!="")||(commento!="")){
return false;
}
commpass=document.getElementById('inputAreaCommenti').value;
commpass=commpass.replace("'","\'");
//Action('?id='+document.getElementById('id').value+'&visitatore='+document.getElementById('visitatore').value+'&email='+document.getElementById('mail').value+'&commento='+escape(commpass)+'&codice='+document.getElementById('inputTextCod').value+'&cod='+document.getElementById('cod').value+'&salva='+salva,'insertcomentajax.asp','insertcomentajax.asp','formaction','post')
document.location.href="insertcomentajax.asp?id="+document.getElementById('id').value+"&visitatore="+document.getElementById('visitatore').value+"&email="+document.getElementById('mail').value+"&commento="+escape(commpass)+"&codice="+document.getElementById('inputTextCod').value+"&cod="+document.getElementById('cod').value+"&salva="+salva
}
function resetta(){
var elm = document.getElementsByTagName("input")
for(var i=0; i<elm.length; i++){
	if(elm[i].type == "text"){
		elm[i].style.backgroundColor='';
		document.getElementById('inputAreaCommenti').style.backgroundColor='';
	}
	}
}
function AntiSpam(){
	var mail = "mail"
	var dom = "simonettabettini.it"
	location.href='mailto:'+mail+'@'+dom
}
