function getCalendar(month){
	var dataOdierna = new Date()
	var splitData = new Array();
	var splitdataLink = new Array();
	var monthName = new Array("", "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre");
	var i,day,dayConf,linkBuf;
	
	
	
	for (i = 0; i<=56; i++){
		$("#day"+i).html("");
	}
	
	if (month == undefined){
		currentMonth = dataOdierna.getMonth() + 1;
	}else{
		currentMonth = month;
	}
	
	nextMonth = currentMonth +1;
	prevMonth = currentMonth -1;
	$("#mese").html(monthName[currentMonth]);
	$.post("/site/calendarLib.php?act=1", { month: currentMonth},
		function(data){
			
			splitdata = data.split(";");
			day = 1;
			i = parseInt(splitdata[1]);
			dayCount = parseInt(splitdata[2]);
			
			while (i < dayCount) {
				$("#day"+i).html(day);
				
				$.post("/site/calendarLib.php?act=2&i="+i, { month: currentMonth, dayEvent:day},
					function(data){
						splitdataLink = data.split("#");
						if (splitdataLink[0] != ""){
							linkBuf = '<a href="'+splitdataLink[0]+'">'+$("#day"+splitdataLink[1]).html()+'</a>';
							$("#day"+splitdataLink[1]).html(linkBuf);
						}
					});
				day = day + 1;
				i++;
			}
		});
		

}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function addML(){
	var errore = 0;
	var email = $('#mail').val();
	if (email.length==0) {  
            errore = 1;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        errore = 1;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        errore = 1;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        errore = 1;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        errore = 1;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
		errore = 1;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
		errore = 1;
    }
    
	
	if (errore == 0){
		$.post("/act_penati.php?act=1", { 
			mail: $('#mail').val()
			},function(data){
				if (data == 1){
					$('#mail').val("");
					$("#errorMsg").html("Iscrizione avvenuta con successo");
				}else{
					$("#errorMsg").html("Il servizio non &egrave; momentaneamente attivo.<br />Riprovare in un secondo momento.");
				}
			});
	}else{
		$("#errorMsg").html("Campo E-Mail non valido");
	}
	
}

var currentMonth,nextMonth,prevMonth;