document.write('<scr'+'ipt type="text/javascript" src="/js/jquery.cookie.js"></scr'+'ipt>');
$(document).ready(function(){

	var COOKIE_NAME = 'formReferrer';
	if( ($.cookie(COOKIE_NAME) == "" || $.cookie(COOKIE_NAME) == null) && (document.referrer || document.referrer != '')  )
		$.cookie(COOKIE_NAME, document.referrer, { path: '/', expires: 0 });


    $('a#bottom_news_button').click(function(){
        $('#bottom_news').slideToggle('slow');
    });

	
	setTimeout("$('#bottom_news').slideToggle('slow')",5000);

	/* Pannello */
	var p = $('#pannello');
	var config = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 200, // number = milliseconds for onMouseOver polling interval    
		 over: apriPannello, // function = onMouseOver callback (REQUIRED)    
		 timeout: 400, // number = milliseconds delay before onMouseOut    
		 out: chiudiPannello // function = onMouseOut callback (REQUIRED)    
	};

	$('#lnk_corsi_lauree_e_master').hoverIntent(config)													   

	
	function apriPannello() {
		p.fadeIn(100);
	}

	function chiudiPannello() {
		p.fadeOut(100);
	}
	
	var config2 = {    
		 sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 150, // number = milliseconds for onMouseOver polling interval    
		 over: apriTendina, // function = onMouseOver callback (REQUIRED)    
		 timeout: 300, // number = milliseconds delay before onMouseOut    
		 out: chiudiTendina // function = onMouseOut callback (REQUIRED)    
	};

	$('li.tendina').hoverIntent(config2)													   

	
	function apriTendina() {
		$(this).children('a.submenu').removeClass('submenu');
		$(this).children('.menu_tendina').fadeIn(100);
	}

	function chiudiTendina() {
		$(this).children('.menu_tendina').fadeOut(100);
		$(this).children('a').addClass('submenu');
	}
	
	/* Ricerca nel sito */
	$('#cerca_sito').click(function(e) {
		var el = $('#ricerca');
		if (el.css('display')=='none') {
			$(this).css('background','transparent url(../immagini/layout/triangolino_su.png) no-repeat right center');			
		} else {
			$(this).css('background','transparent url(../immagini/layout/triangolino_giu.png) no-repeat right center');
		}
		el.toggle();
		$('#cerca').get(0).focus();	
	});
	
	/* Contatti */
	$('#sede').change(function(){
		$('#td_inizio select').attr('disabled','disabled');						   
		var id_sede = $(this).val();	
		$.ajax({
			type: "POST",
			url: "/include/ajax.carica_corsi_sede.php",
			data: {id_sede: id_sede},
			dataType: "html",
			success: function(risposta) {  
				$('#td_corso').html(risposta);
				attivaCorso();
			}
		});	
	});
	
	function attivaCorso() {
		$('#corso').change(function(){
			var id_sede = $('#sede').val();	
			var id_corso = $(this).val();	
			$.ajax({
				type: "POST",
				url: "/include/ajax.carica_corsi_sede_calendario.php",
				data: {id_sede: id_sede,id_corso:id_corso},
				dataType: "html",
				success: function(risposta) {  
					$('#td_inizio').html(risposta);
				}
			});	
		});	
	}
	if ($("#modulo").length>0) {
		$("#modulo").validate({
			invalidHandler: function(form, validator) {
				  var errors = validator.numberOfInvalids();
				  if (errors) {
					var message = errors == 1
					  ? '1 field was not filled correctly. It has been highlighted.'
					  : errors + ' fields were not filled correctly. They have been highlighted.';
					$("div.error span").html(message);
					$("div.error").show();
				  } else {
					$("div.error").hide();
				  }
			},
			highlight: function(element, errorClass) {
				$(element).addClass('error');
				$(element).prev().addClass('error2');
			},
			unhighlight: function(element, errorClass) {
				$(element).removeClass('error');
				$(element).prev().removeClass('error2');
			},
			rules: {
				nome: "required",
				cognome: "required",
				giorno: "required",
				mese: "required",
				anno: "required",				
				nazionalita: "required",				
				sede: "required",				
				prefisso: "required",
				telefono: "required",
				corso: "required",
				email: {
					required: true,
					email: true
				},
				inizio: "required"
			}			
		});
	}
	/* Eventuale photogallery */
	if ($("#photogallery a").length>0) {
		$("#photogallery a").lightBox();
	}
	/* Menu sedi */
	$('a.a_sede').click(function(){

		var div_info_sede = $(this).siblings('div.info_sede');	
		if (div_info_sede.css('display')=='none') {
			$('div.info_sede').hide();
			div_info_sede.show();
		} else {
			$('div.info_sede').hide();
		}
		return false;
	});
});
function CheckMultiple1(frm, name) {
	for (var i=0; i < frm.length; i++)
	{
		fldObj = frm.elements[i];
		fldId = fldObj.id;
		if (fldId) {
			var fieldnamecheck=fldObj.id.indexOf(name);
			if (fieldnamecheck != -1) {
				if (fldObj.checked) {
					return true;
				}
			}
		}
	}
	return false;
}
function CheckForm1(f) {
	if (f.email.value == "") {
		alert("Please enter your email address");
		f.email.focus();
		return false;
	}
		pageTracker._trackEvent("Contact Forms", "Newsletter Signup");
		return true;
	};

function toggleBottomButtons(el){
	if(el.className == "bottom_news_btn_on") 
		el.className="bottom_news_btn_off";
	else 
		el.className="bottom_news_btn_on";
}