// controllo validit iscrizione newsletter
function checkMail(mail) {
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	if (!espressione.test(mail)) { alert(TEXT_ALERT_EMAIL_NEWSLETTER_NAE);	return false; } 
	else 
	{ 
	//document.newsletter.submit();
		$.post("/isc_newsletter.php", { email: $("#email-newsletter").val(), sito: $("#sito").val(), lingua: $("#lingua").val(), MM_insert: $("#MM_insert").val() },
		   function(data){
			   if (data!='') {
				 alert(TEXT_ALERT_NEWSLETTER_NO);
				 //alert("Data Loaded: " + data);				   
			   } else {
				   alert(TEXT_ALERT_NEWSLETTER_OK);
			   }
		 });
	
	}
}
//MENU PRINCIPALE
function menu_prod(){		   
	$("#category .active").parents("li").children().addClass("on");
	if ($("#category ul").attr("class")!="tutto_aperto") {
		$("#category ul li ul").hide();
		aTimer = setTimeout(function(){
			$("ul.on").slideDown('slow');
		 },500); // fa apparire i sotto men in seguenza dopo mezzo secondo tramite animazione		
	}
}
//MENU A TENDINA ISTITUZIONALE
function menuVert() {
	var stateMenu = new Array(); 
	$('.main_menu > li, .main_menu li ul').mouseenter(function(){
															   stateMenu[$('.main_menu > li').index(this)] = true;
															   $(this).children('ul').show();
															   });
	$('.main_menu > li, .main_menu li ul').mouseleave(function(){ 
															   var correntMenu = $(this).children('ul');
															   var indice = $('.main_menu > li').index(this);
															   stateMenu[indice] = false;
															   Pause= setTimeout(function(){
																  if (!(stateMenu[indice])){ correntMenu.hide(); } },150);
															   });
}
//ICONE IN LINEA
function iconLink(){
 	// Add pdf icons to pdf links
	$("a[href$='.pdf']").filter(function() {
	    return ($(this).css("background-image")!='none') ? false:true;
	  }).addClass("pdf");
 
	// Add txt icons to document links (doc, rtf, txt)
	$("a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").filter(function() {
	    return ($(this).css("background-image")!='none') ? false:true;
	  }).addClass("txt");
 
	// Add zip icons to Zip file links (zip, rar)
	$("a[href$='.zip'], a[href$='.rar']").filter(function() {
	    return ($(this).css("background-image")!='none') ? false:true;
	  }).addClass("zip"); 
 
	// Add email icons to email links
	$("a[href^='mailto:']").filter(function() {
	    return ($(this).css("background-image")!='none') ? false:true;
	  }).addClass("email");
 
	//Add external link icon to external links - 
	$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external");
	//You might also want to set the _target attribute to blank
	$('a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external").attr("target", "_blank");
};

//HIDE - SHOW CONTENUTI DETAILS
function details(){
	$(".details").next().hide();
	$(".details").click(function() {
								 $(this).next().toggle('fast', function(){
									 $("#context").css("height","auto");
									 heightContext();
									 });								
								 }).css("cursor","pointer").attr("title",TITLE_TITOLO_DETAILS);
/*	.mouseover(function(){
									$(this).css("textDecoration","underline"); 
								 }).mouseout(function(){
									$(this).css("textDecoration","none"); 
								 })*/
};

//RIDIMENSIONA #CONTEXT RISPETTO IL MODULO DEL LAYOUT
function heightContext(){
	var hContext = $("#context").height();
	var nMod = parseInt(hContext/144);
	var more = parseFloat(hContext/144);
	if (more!=0) {$("#context").height(((nMod+1)*144)-3);}
};

//ONLOAD PAGE 
$(function(){
	menu_prod(); 	// attivazione menu prodotto
	iconLink();		// attivazione icone in linea
	menuVert();		// attivazione menu tendina istituzionale
	// listner invio iscrizione newsletter	   
	$("#newsletter a").click(function(event){ checkMail($("#email-newsletter").val()); });
	// listner testo default modulo input iscrizione newsletter	   
	$("#email-newsletter").blur(function(event){ if(this.value==''){this.value=this.defaultValue;} });	
	$("#email-newsletter").focus(function(event){ if(this.value==this.defaultValue){this.value='';} });	
	details(); 	// attivazione contenuti details	
	// listner per ridimensionamento altezza #context
	$("#context").resize(heightContext());
});
