// JavaScript Document

function getXMLHTTPRequest(){
var req = false;
	try{
		req= new XMLHttpRequest();
/* Firefox*/
		}
		catch(err1){
					try{
						req= new ActiveXObject("Msxml2.XMLHTTP");
/* alcune versioni Internet Explorer */	
						}
						catch(err2){
									try{
										req= new ActiveXObject("Microsoft.XMLHTTP");
/* alcune versioni Internet Explorer */	
										}
										catch(err3){
													req=false;
								
													}
									}
						}
return req;
}


var myRequest= getXMLHTTPRequest();
	
	
function inviaMail(){
var nome=document.getElementById("nome").value;
var mail=document.getElementById("eMail").value;
var corpoMail=document.getElementById("corpoMail").value;
if(nome!=""){
	if(corpoMail!=""){
					if(verificaMail(mail)){
					//mail nome e corpoMail valido ajax
					var dati="nome="+escape(nome)+"&mail="+escape(mail)+"&corpoMail="+escape(corpoMail);
					var url="php/inviaMail.php";
					myRequest.open("POST",url,true);
					myRequest.onreadystatechange=responseAjax;
					myRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
					myRequest.setRequestHeader("Content-length",dati.length);
					myRequest.send(dati);
					myRequest.setRequestHeader("Connection", "close");
										}
									else{
									alert("Inserire la Propria E-Mail (indirizzo email non valido)");
										}	
					 }
					 else{
					 alert("Inserire il testo della Mail");
						 }
				

}
else{
alert("Inserire il Nome e Cognome");
	}

}



function responseAjax(){
if (myRequest.readyState==4){
		if(myRequest.status==200){
						var risposta = myRequest.responseText;
						alert(risposta);			
									}
		else{
		alert("operazione fallita");
		}							
}

}

function verificaMail(mail){
var espReg= new RegExp("^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$");
if(espReg.test(mail)){
return true;
}
else{
return false;
}
}

//slideDown su slide
$(document).ready(function(){
	$(".navbar").click(function () {
		var $index = $(".navbar").index(this);
		$(".mySlides > *").hide("slow");
		$("#mySlides0"+ $index).slideDown("slow");
	});
});


//div dinamici 4mosse e numverde
$(document).ready(function(){
	$("#pegaso4mosse").click(function () {
		$("#topcontainerquattromosse").show("slow");
		$("#mosseContent").hide("slow");	
		$("#divDinamico").show("slow");
	});
	$(".quattromosse").click(function () {
		var $index = $(".quattromosse").index(this);
		$("#divDinamico").hide("slow");
		$("#divDinamico > *").hide("slow");
		$("#div" + $index).show("slow");
		$("#divDinamico").show("slow");
	});
});


//numverde
$(document).ready(function(){
	$("#pegasonumverde").click(function () {
		$("#topcontainernumverde").show("slow");
		$("#mosseContent").hide("slow");	
		$("#divDinamico2").show("slow");
	});
	$(".numverde").click(function () {
		var $index = $(".numverde").index(this);
		$("#divDinamico2").hide("slow");
		$("#divDinamico2 > *").hide("slow");
		$("#div00" + $index).show("slow");
		$("#divDinamico2").show("slow");
	});
});


//toggle sul menu 
  $(document).ready(function(){	
  	$(".menu").toggle(function () {
	var $index = $(".menu").index(this);
        $("#sottomenu0"+$index).slideDown("slow");
    }, function(){
		var $index = $(".menu").index(this);
		$("#sottomenu0"+$index).slideUp("slow");	
	});
  });

//pagina universita fadeIn fadeOut

$(document).ready(function(){
    
    $(".imgUni > *").click(function () {
	var $index = $(".imgUni > *").index(this);
	  $("#universitaContent > *").fadeOut("slow");
	  $("#divUni0"+$index ).fadeIn("slow");
    });
	

  });
  
//ok

//valutazione toggle	
$(document).ready(function(){
	$(".linkvalutazione").click(function () {
		$("#divcfu").slideDown("slow");
		
	});
});

//funzione controlla formato data
//formato 12/02/2008
function controllaData(stringa){
	
	var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	if (!espressione.test(stringa))
	{
	    return false;
	}
	
else{
		var anno = parseInt(stringa.substr(6),10);
		var mese = parseInt(stringa.substr(3, 2),10);
		var giorno = parseInt(stringa.substr(0, 2),10);
		var today=new Date();
		if(anno<=today.getFullYear() && mese<=12 && giorno<=31)
		{
			if(giorno>28 && mese==2)
			{
				if(giorno==30 || giorno==31)
				{
				return false;	
				}
				else
				{
				if(anno%4==0 && anno%100!=0 || anno%4==400)
				{
				return true;
				}
				else
				{
				return false;	
				}
				}
				
			}
			if(giorno==31 && mese==4 || mese==6 || mese==9 || mese==11)
			{
			return false;	
				}
		return true;
		}
		else
		{
		return false;	
		}
		
	
		
	}
	
	
	
	
	}


//verifica validazione dati anagrafici del form per pagina valutazione cfu 	
$(document).ready(function(){
    $("#inviaForm").click(function() {
      if ($("#nomeForm").val()!="" && isNaN($("#nomeForm").val()) && $("#nomeForm").val().length<20 ) {
		$("#nomeForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Nome non Corretto");
		$("#nomeForm").css({ backgroundColor:"yellow"});
	    return false;
    });
	
	
	
	$("#inviaForm").click(function() {
      if ($("#cognomeForm").val()!="" && isNaN($("#cognomeForm").val()) && $("#cognomeForm").val().length<20 ) {
		$("#cognomeForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Cognome non Corretto");
		$("#cognomeForm").css({ backgroundColor:"yellow"});
	    return false;
    });
	
	
	
	$("#inviaForm").click(function() {
      if ($("#mailForm").val()!="" && verificaMail($("#mailForm").val()) && $("#mailForm").val().length<50 ) {
		$("#mailForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Mail Formato non Corretto");
		$("#mailForm").css({ backgroundColor:"yellow"});
	    return false;
    });
	
	
	$("#inviaForm").click(function() {
      if ($("#telForm").val()!="" && typeof($("#telForm").val())!="String" && $("#telForm").val()<9999999999 ) {
		$("#telForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Telefono Formato non Corretto");
		$("#telForm").css({ backgroundColor:"yellow"});
	    return false;
    });
	
	
	
	
	

  });
//verifica del form campi esame
$(document).ready(function(){
						   
						   
$("#mod_submit2").click(function() {
      if ($("#nomeEsameForm").val()!="" && isNaN($("#nomeEsameForm").val()) && $("#nomeEsameForm").val().length<30 ) {
		$("#nomeEsameForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Denominazione non Corretto");
		$("#nomeEsameForm").css({ backgroundColor:"yellow"});
	    return false;
    });

//espressione regolare per formato data
$("#mod_submit2").click(function() {
      if ($("#dataForm").val()!="" && controllaData(($("#dataForm").val())) ) {
		$("#dataForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Data formato non corretto es: 17/03/2002");
		$("#dataForm").css({ backgroundColor:"yellow"});
	    return false;
    });
//fine data

//voto
$("#mod_submit2").click(function() {
      if ($("#votoForm").val()!="" && typeof($("#votoForm").val())!="String" && $("#votoForm").val()<31 && $("#votoForm").val()>=18) {
		$("#votoForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Voto non Corretto");
		$("#votoForm").css({ backgroundColor:"yellow"});
	    return false;
    });


//ente
$("#mod_submit2").click(function() {
      if ($("#enteForm").val()!="" && isNaN($("#enteForm").val()) && $("#enteForm").val().length<40 ) {
		$("#enteForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Ente non Corretto");
		$("#enteForm").css({ backgroundColor:"yellow"});
	    return false;
    });

//cfu
$("#mod_submit2").click(function() {
 		if ($("#cfuForm").val()!="" && typeof($("#cfuForm").val())!="String" && $("#cfuForm").val()<18) { 
		$("#cfuForm").css({ backgroundColor:"#ffffff"});
        return true;
      }
     
      	alert("Campo Cfu non Corretto");
		$("#cfuForm").css({ backgroundColor:"yellow"});
	    return false;
    });



  });
