/*Funzioni Per Jquery*/
$(document).ready(
	function () {
		applicaAlLoad();
	}
);

//Funzioni richiamate direttamente al loading
function applicaAlLoad(idElemento){
	if(idElemento!=null&&idElemento!=undefined){
		if(idElemento.substr(0,1)!="#") idElemento="#"+ idElemento;
		idElemento+=" ";
	}
	else
		idElemento="";

	//Funzione per lo scroll top
	$(".gotop").click(function(){
		$().scrollTo($("#colonnaDue"), 800);					   
	});
	
	//Funzione per la stampa della pagina
	$(".print").click(function(){
		window.open('print.asp','_new');
	});
	
	if($("body").is(".stampa")){
		window.print();
	}

	//Verifico i form
	$("form.verificaForm").verificaForm({tipoVisualizzazione:3});
	
	$("input[class^='styled']").custCheckBox();
	
	
	$("#internoLogin .input").bind("focus",function(){
		$(this).css("background-image","url(../images/assets/bg-inputSel.jpg)");
	}).bind("blur",function(){
		$(this).css("background-image","url(../images/assets/bg-input.jpg)");
	});
	
	$(".chiediConferma").click(function(){
		return chiediConferma(this);
	});
	
	altezzaBase=$(".espandibile").css("height");
	$(".linkEspandi").click(function(){
		if($(".espandibile").css("height")==altezzaBase){
			var currentHeight = $(".espandibile").height();
			$(".espandibile").css('height', 'auto');
			var height = $(".espandibile").height();
			$(".espandibile").css('height', currentHeight + 'px');
			
			$(".espandibile").animate({'height': height}, "slow");
			$(this).html("<span>Riduci</span>");
		}
		else{
			$(".espandibile").animate({'height': altezzaBase}, "slow");
			$(this).html("<span>Espandi</span>");
		}
	});
	
	animaInput('');
}

function animaInput(idElemento){
	$(idElemento +"div.anima").each(function(index){
		input=$(this).children("input");
		margine=$(input).css("marginBottom").replace("px","");
		bordo=$(input).css("borderBottomWidth").replace("px","");
		margine=Number(margine)+Number(bordo)+"px";
		value=$(input).attr("alt");
		
		span=$("<span>"+ value +"</span>").appendTo(this).css("bottom",margine);
		if($(input).val()=='')	$(span).show();
	});
	
	$(idElemento +"div.anima span").hover(function(){
		$(this).addClass("inputhover");
	},
	function(){
		$(this).removeClass("inputhover");
	});
	
	$(idElemento +"div.anima span").click(function(){
		$(this).stop(true, true).fadeOut("slow");
		input=$(this).closest("div.anima").children("input");
		$(input).addClass("inputselected").focus();
	});
	$(idElemento +"div.anima input").focus(function(){
		span=$(this).closest("div").children("span");
		$(span).stop(true, true).fadeOut("slow");
		$(this).addClass("inputselected");
	});
	
	$(idElemento +"div.anima input").blur(function(){
		span=$(this).closest("div").children("span");
		$(this).removeClass("inputselected");
		if($(this).val()=='')	$(span).fadeIn("slow");
	});
}

function chiediConferma(anchor){
	if (confirm("Sei sicuro? L'operazione non potra' essere annullata")){
		anchor.href += '&conferma=1';
		return true;
	}
	return false;
}
