function enableHighlight(a) {
	$(a).hover(
		function() {
			if(!$(this).hasClass("sel")) {
				$(this).removeClass("bt-state-default");
				$(this).addClass("bt-state-selected");
			}
		},function(){
			if(!$(this).hasClass("sel")) {
				$(this).removeClass("bt-state-selected");
				$(this).addClass("bt-state-default");
			}
		}
	);
}

function olink(a) {
	h=$("#sbCategorie option:selected").val();	
	window.location="schede.php?prod=" + h + "-" + a.options[a.selectedIndex].value;
}
		
function getProdotti(h) {
	if(h!="--") {
		window.location="schede.php?getprod=" + h;
	}
}
		
function getCordoni(h) {
	if(h!="--") {
		window.location="alimentazione.php?getprod=" + h;
	}
}
		
function checkpdf() {		
	$("#pdf_box input:checked").each(function () {
  	$("#pdf_box a").attr("href",$("#pdf_box a").attr("href") + "&" + $(this).val() + "=y");
	});  	
}

function indexTextImage() {
	$(".container .flying-text").css({opacity:0}); //set all text opacity to 0
	$(".container .active-text").animate({opacity:1, marginLeft: "-200px"}, 4000); //animate first text

  var int = setInterval(changeText, 5000); // call changeText function every 5 seconds
}

function changeText(){
	var $activeText = $(".container .active-text"); //get current text
	var $nextText = $activeText.next();  //get next text
	if($activeText.next().length == 0) {
		$nextText = $(".container .flying-text:first"); //if it is last text, loop back to first text
	}
  $activeText.animate({opacity:0}, 1000); //set opacity 0 to animated text
  $activeText.animate({marginLeft: "-200px"}); //set animated text position to default
  //animate next text
	$nextText.css({opacity: 0}).addClass("active-text").animate({opacity:1, marginLeft: "200px"}, 4000,
		function(){
			$activeText.removeClass("active-text");
  	}
	);
}

function checkLength(o,n,min,max) {
	if (o.val().length > max||o.val().length < min) {
		o.addClass('ui-state-error');
		updateTips("Length of " + n + " must be between " + min + " and " + max + ".");
		return false;
	}
	else {
		return true;
	}
}

function checkRegexp(o,regexp,n) {
	if(!(regexp.test(o.val()))) {
		o.addClass('ui-state-error');
		updateTips(n);
		return false;
	}
	else {
		return true;
	}
}

function updateTips(n) {
	alert(n);
}

function dialogAggiungiCampo_old() {
	$("#AggiungiCampo").dialog({
		modal: true,
		height: 480,
		width: 600,
		buttons: {
			'Aggiungi Campo': function() {
				var bValid = true;
				
				nome=$(this).find('input:text').eq(1);
				//lingua=$(this).find('select').eq(0);
				lingua=$(this).find('input:text').eq(0);
				
				$(this).find('input').removeClass('ui-state-error');
				$(this).find('select').removeClass('ui-state-error');
				
				/*
				if($(nome).val().length>0) {
					bValid = bValid && checkRegexp(nome,/^[a-z]([0-9a-z_\!\.\-\ \?\°\@\$\%\&\#])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
				}
				
				
				if($(lingua).val().length>0) {
					bValid = bValid && checkRegexp(lingua,/^[a-z]{2}$/i,"Lingua non valida");
				}
				*/
				
				if (bValid) {
					$(this).find('form').append("<input type='hidden' name='aggiungi' value='campo'").submit();
				}
			},
			'Annulla': function() {
					$(this).dialog('close');
					$(this).dialog('destroy');
				}
		}
	});
}

