// JavaScript Document

function submitForm(formName, onSuccess){
	
	var option = { 		   
		dataType : 		'json',			
		success:      onSuccess
	};
	
	$('#' + formName).ajaxForm(option);
	$('#' + formName).submit();
	
}

function contraiTracked (idLayer) {
	if (idLayer!=Opened){
		if (Opened!="") $("#" + Opened).slideToggle("fast");
		$("#" + idLayer).slideToggle("fast");
		Opened = idLayer;
	}else {
		$("#" + idLayer).slideToggle("fast");
		Opened = "";
	}
}

function loadFaceBox(page, onSuccess){
	
	jQuery.facebox(function() {
	
		$.get(page,
			   
		function(data){
	
			jQuery.facebox(data);
			if (onSuccess !='') eval(onSuccess + '()');
	
		});
	
	}) 
	
}

function sendSubscribe (){
	
	var valido = $("#frmIscrizione").valid();
	
	if (valido) {
	
		if (document.frmIscrizione.privacy.checked){
			
			$('#msg').html("Attendere mentre eseguo l'iscrizione");
			submitForm ('frmIscrizione', onSendedIscrizione);
	
		} else alert ("Accettare il trattamento dei dati");
	} else alert ("Controlla gli errori di compilazione");
	
}

function onSendedIscrizione(responseText, statusText){
	
		$('#frmIscrizione').resetForm();
		$('#msg').html('<input type="button" name="invio" value="ISCRIVI" class="inputText" onclick="sendSubscribe();" /><br><br>' + responseText.msg);

}

function toggleLogin () {
	
	$("#loginDiv").slideToggle("fast");
	
}

function ctrlLogin () {
	
	$('#msgAlert').html("Attendere metre controllo le credenziali");
	$('#msgAlert').fadeIn();
	
	submitForm ('loginFrm', onSentLogin);
	
}

function onSentLogin(responseText, statusText){
	
	$('#msgAlert').html(responseText.msg);
	
	if (responseText.result == "true") {
	
		c = setInterval(function() { document.location.reload(); clearInterval(c);}, 1500);
		
	} else c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 1500);

}

function notEnabled () {
	
	$('#msgAlert').html("Non sei abilitato al download delle schede<br><br>Iscriviti e logati per il download");
	$('#msgAlert').fadeIn();
	c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 3500);
	
}
