/*
son of suckerfish menu script from:
http://www.htmldog.com/articles/suckerfish/dropdowns/
 */
var newsitems;
var curritem=0;
var iPause=0;


$(document).ready(function(){
    var tickerSelector = "ul#ticker li";
    newsitems = $(tickerSelector).hide().hover(
        function(){
            $(this).addClass("hovered");
            iPause=1;
        },
        function(){
            $(this).removeClass("hovered");
            iPause=0;
        }
    ).filter(":eq(0)").show().add(tickerSelector).size();
    setInterval(ticknews,5000); //time in milliseconds
});


function ticknews() {
  if (iPause==0){
    $("#ticker li:eq("+curritem+")").fadeOut("slow",function(){$(this).hide();});
    curritem = ++curritem%newsitems;
    $("#ticker li:eq("+curritem+")").fadeIn("slow");
    }
}

/*//EFFETTI
function mycarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });

    jQuery('.jcarousel-scroll select').bind('change', function() {
        carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
        return false;
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};

/*
jQuery(document).ready(function() {
    jQuery("#mycarousel").jcarousel({
        scroll: 4,
        initCallback: mycarousel_initCallback,
        // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
*/	
/*
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 4,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });

	
	
});
*/
$(document).ready(function() {
						   
$('.fade').animate( { backgroundColor: '#FFFF97' }, 500).animate( { backgroundColor: '#fffbcc' }, 500).animate( { backgroundColor: '#FFFF97' }, 500).animate( { backgroundColor: '#fffbcc' }, 500);
$('.fade_red').animate( { backgroundColor: '#FF9393' }, 500).animate( { backgroundColor: '#FFBBBB' }, 500).animate( { backgroundColor: '#FF9393' }, 500).animate( { backgroundColor: '#FFBBBB' }, 500);
	
if($('#password').val() != null) {
	
$('#password').keyup(function(){$('#result').html(passwordStrength($('#password').val()))})
$('#password').ready(function(){$('#result').html(passwordStrength($('#password').val()))})

}

});
	$(document).ready( function () {
		
		$('.showstates').each( function () {
			var name = $(this).attr('id');
		 	
			if ($(this).val()!='21') {
		 		$('.statesok').removeAttr('id').hide();
			 }
		});
		
		
		$('.showstates').change(onChange);
		
		function onChange(){
			var desiredName = $(this).attr('id');
			if ($('#'+desiredName).val()=='21') {
				$('.statesok').attr('id',desiredName).fadeIn('slow');
			}
			else {
				$('.statesok').removeAttr('id').fadeOut('slow');
			}
		}

	});
	
	
	$(document).ready( function () {
		
		$('.showregions').each( function () {
			var name = $(this).attr('id');
		 	
			if ($(this).val()!='106') {
		 		$('.showregionsok').removeAttr('id').hide();
			 }
		});
		
		
		$('.showregions').change(onChange);
		
		function onChange(){
			var desiredName = $(this).attr('id');
			if ($('#'+desiredName).val()=='106') {
				$('.showregionsok').attr('id',desiredName).fadeIn('slow');
			}
			else {
				$('.showregionsok').removeAttr('id').fadeOut('slow');
			}
		}

	});
	

function gestioneOrdine() {

		var $id = function(id) {
		return (document.getElementById)? document.getElementById(id) : document.all[id];
		};

		var _tr = $id('traduzioni'); 		// campo numero traduzioni
		var _cu = $id('prezzounitario'); 	// campo costo unitario
		var _ca = $id('canone'); 			// campo canone
		var _pt = $id('prezzototale_2');		// campo prezzo totale

		/* funzione di get/set sul campo */
		var _setValue = function(c, v, f) { c.value = v.toFixed(f); }
		var _getValue = function(c) { return (parseFloat(c.value) || 0); }
		var _incValue = function(c) { c.value = _getValue(c) + 1; }

		/* aggiornamento del prezzo */
		var aggiornaPrezzo = function() {
		var tr = _getValue(_tr); 
		var cu = _getValue(_cu); 
		var ca = _getValue(_ca);
				
		_setValue(_pt, ((tr * cu) + ca), 2); 
		};

		/* aggiornamento del numero delle traduzioni */
		var aggiornaTraduzioni = function() {
		_setValue(_tr, 0, 0);
		var len	= _lt.length;
		while (len--) { if (!!_lt[len].checked) _incValue(_tr); };
		aggiornaPrezzo();		
		};

		/* setta l'evento onchange sulle checkbox */
		
		if($id('trad') != null) {//aggiunta	  
		var _lt 	= null;
			(function() {
				_lt	= $id('trad').getElementsByTagName('input');
				var len	= _lt.length;
				while (len--) { _lt[len].onchange = _lt[len].onclick =  function(l) { 
					return function() { aggiornaTraduzioni(); } 
				}(len); }
			})();
		}//aggiunta	  
	};

	window.onload = gestioneOrdine; /* chiamata alla funzione */
	
	function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function flevToggleCheckboxes() { // v1.1
	// Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
	var sF = arguments[0], bT = arguments[1], bC = arguments[2], oF = MM_findObj(sF);
    for (var i=0; i<oF.length; i++) {
		if (oF[i].type == "checkbox") {if (bT) {oF[i].checked = !oF[i].checked;} else {oF[i].checked = bC;}}} 
}

function toggleDisplay(non_bio, bio) {

	var prod_n_bio = document.getElementById(non_bio);
	var prod_bio = document.getElementById(bio);

	if( prod_n_bio.style.display == "none" ) {
		prod_n_bio.style.display = "";
		prod_bio.style.display = "none";
	}
	else {
		prod_n_bio.style.display = "none";
		prod_bio.style.display = "";
	}
	
}

function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie( name ) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookie( name ) {
	setCookie(name,"",-1);
}