// Inizio document.ready
$("document").ready ( function (){

	$(function(){
		$(".date_format").mask("99/99/9999");
		
	});
	bindCommentiFunctions(false);
	
});// Fine document.ready

// ************************************************ Gestione commenti utente
function bindCommentiFunctions(visible){
	var expanded=visible;
	
	$("#inviaCommento").hide();
	if(visible){
		$("#inviaCommento").slideDown("slow");
	}

	$("#msgCom").hide();

	$("#boxScrivici").click(function(){
		$("#msgCom").fadeOut("fast");
		if(expanded){
			$("#inviaCommento").slideUp("slow");
			expanded=false;
		}else{
			$("#inviaCommento").slideDown("slow");
			expanded=true;
		}
	});
	
	$("#formCommento").submit(function(){
		var dominioLength="http://www.tramontana.it/".length;
		var urlDoc=""+window.location;
		var sezione=urlDoc.substring(dominioLength).split("/")[0];
		var dataToPost="titolo="+$("#titoloCommento").val()+"&testo="+$("#testoCommento").val()
			+"&idDocumento="+$("#idDocumento").text()+"&titoloDocumento="
				+$("#titoloDocumento").text()+"&sezioneDocumento="+sezione+"&urlDocumento="+urlDoc;
		
		$.ajax({
			  type: "POST",
			  url: "/as/commento.do",
			  dataType:"text",
			  data:dataToPost,
			  success:function(data, textStatus){
				$("#msgCom").html(""+data);
				$("#inviaCommento").slideUp("slow",function(){
					$("#titoloCommento").val("");
					$("#testoCommento").val("")
				});
				$("#msgCom").fadeIn("slow");
			  }
			});
			expanded=false;
		return false;

	});
}
	
// ************************************************ Fine gestione commenti utente

// ************************************************ Form gestione commenti utente
function MaxCaratteri(Object, MaxLen){
	  if (Object.value.length > MaxLen){
	Object.value = Object.value.substring(0,MaxLen);
  }
}
// ************************************************ Paginazione testi commenti
function movePage(page, numPage) {
	$("#msgCom").hide();
	for (var indice=1;indice<=numPage;indice++) {
		var corrente=document.getElementById("commentoPag"+indice);
		var link=document.getElementById("link"+indice);
		if (indice==page) {
			if (corrente.style.display!="block"){
				corrente.style.display="block";
			}
			link.style.textDecoration="none";
		}	else {
			if (corrente.style.display!="none"){
				corrente.style.display="none";
			}
			link.style.textDecoration="underline";
		}
	}
}
