	window.addEvent('domready', function()	{

        var url = window.location.href;
        var re = /#vantaggi$/ ;

        if( url.match(re) )
        {
            var top = $('vantaggi').getTop() ;
			top -= 150 ;
			window.scrollTo( false , top ) ;
        }

		var listFisso = $$('#idList li.menuFisso') ;
		listFisso.each( function( element )	{

			var fx = new Fx.Styles( element, {duration:200, wait:false} ) ;

			element.addEvent('mouseenter', function()	{
				fx.start(	{
					'margin-left': 1,
					'background-color': '#200055',
					'color': '#fff'
				} ) ;
			} ) ;

			element.addEvent( 'mouseleave' , function() {
				fx.start(	{
					'margin-left': 11,
					'background-color': '#6B78B3',
					'color': '#888'
				} ) ;
			} ) ;
		} ) ;

	    if( $('selectMarche') )
		$('selectMarche').addEvent('change', function(e) {
			e = new Event(e).stop();

			var idMarca = document.getElementById( 'selectMarche' ).value ;
			if( idMarca != '0' )
			{
				var url = "/admin/opzioni/getModelli.php?idMarca=" + idMarca ;

				//alert( url ) ;

				/**
				 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
				 * to do add your own Ajax depended code.
				 */
				new Ajax(url, {
					method: 'get',
					update: $('selectModello1')
				}).request();
			}
			else
			{
				var selectToRemove = document.getElementById('modello');
				selectToRemove.parentNode.removeChild(selectToRemove);
			}
		});
		
		if( $('selectMarche') )
		$('selectMarche').addEvent('change', function(e) {
			e = new Event(e).stop();

			var idMarca = document.getElementById( 'selectMarche' ).value ;
			if( idMarca != '0' )
			{
				var url = "/admin/opzioni/getModelli.php?idMarca=" + idMarca ;

				//alert( url ) ;

				/**
				 * The simple way for an Ajax request, use onRequest/onComplete/onFailure
				 * to do add your own Ajax depended code.
				 */
				new Ajax(url, {
					method: 'get',
					update: $('selectModello1')
				}).request();
			}
			else
			{
				var selectToRemove = document.getElementById('modello');
				selectToRemove.parentNode.removeChild(selectToRemove);
			}
		});

	if( $('selectGaranzia') != null )
		$('selectGaranzia').addEvent('update', function(e) {
			e = new Event(e).stop();

			var idGaranzia = document.getElementById( 'selectGaranzia' ).value ;
			if( idGaranzia != '0' )
			{
				var url = "/admin/opzioni/getGaranzia.php?idGaranzia="+idGaranzia ;

				new Ajax(url, {
					method: 'get',
					update: $('garanziaValue')
				}).request();
			}
			else
			{
				document.getElementById( 'garanziaValue' ).innerHTML = "" ;}
	});
	if( $('selectVantaggi') != null )
		$('selectVantaggi').addEvent('change', function(e) {
			e = new Event(e).stop();

			var idVantaggi = document.getElementById( 'selectVantaggi' ).value ;
			if( idVantaggi != '0' )
			{
				var url = "/admin/opzioni/getVantaggi.php?idVantaggi="+idVantaggi ;

				new Ajax(url, {
					method: 'get',
					update: $('vantaggi')
				}).request();
			}
			else
				document.getElementById( 'vantaggi' ).innerHTML = "" ;
		});
	if( $('garanzia') != null )
		$('linkGaranzia').addEvent('click', function(e) {
			e = new Event(e).stop();

			var top = $('garanzia').getTop() ;
			top -= 150 ;
			scrollTo( 0 , top ) ;
		});
	if( $('vantaggi') != null )
		$('linkVantaggi').addEvent('click', function(e) {
			e = new Event(e).stop();

			var top = $('vantaggi').getTop() ;
			top -= 150 ;
			window.scrollTo( false , top ) ;
		});

	if( $$('input.DatePicker') != null )
		$$('input.DatePicker').each( function(el){
			new DatePicker(el);
		});

	 blink() ;
	 blink_menu() ;
} ) ;

function viewAppare( i )
{

  var div = document.createElement("div") ;
    div.id = "nonAppare" ;

    switch (i) {
      case 1 :  //garanzia
        div.innerHTML = "<b>LA NOSTRA GARANZIA...</b><br />GARANZIA COME PREVISTO DALLA LEGISLAZIONE VIGENTE";
      break;
      case 2 :  //vantaggi
        div.innerHTML = "<b>VANTAGGI PER TE...</b><br />LE AUTO CON QUESTO LINK USUFRUISCONO DI <br />OFFERTE SOLO PER I CLIENTI ON LINE";
      break;
      case 3 :  //permuta
        div.innerHTML = "<b>PERMUTA IL TUO USATO...</b><br />PROPONI LA TUA PERMUTA , SARA' DA NOI VALUTATA";
      break;
      case 4 : //finanziamento
        div.innerHTML = "<b>I NOSTRI FINANZIAMENTI...</b><br />FINANZIAMENTI SU MISURA CON CONSUMIT <br />GRUPPO MONTE DEI PASCHI DI SIENA";
      break;
      case 5 : //trasporto
        div.innerHTML = "<b>TRASPORTIAMO LA TUA AUTO...</b><br />PENSIAMO NOI AD ORGANIZZARTI LA CONSEGNA IN TUTTA ITALIA AD UN COSTO DI CIRCA 350 EURO";
      break;
      case 6 : //prezzo
	var prezzo = document.getElementById( "prezzo" ).value ;
        div.innerHTML = "<b>PREZZO...</b><br /><p style='font-size:15px; color:#fad607;'> "+prezzo+" EURO </p><br /> ESCLUSO PASSAGGIO DI PROPRIETA' ";
      break;
    }

  var spanWhereInsert = document.getElementById("rootAppare") ;
    spanWhereInsert.parentNode.insertBefore( div , spanWhereInsert ) ;
}

function hideAppare()
{
  var divWhereDelete = document.getElementById("nonAppare") ;
  divWhereDelete.parentNode.removeChild( divWhereDelete ) ;
}

function openPopup(lnk,tg)
{
	if (tg=="s"||tg=="t")
	{
		lnko=lnk;
		tgT=tg;
		setTimeout('rVai()',30);
	}
	else if (tg=="b")
	{
		pp = window.open(lnk,'','width='+BrW+',height='+BrH+',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes');
		pp.focus() ;
	}
	else if (tg=="p" || tg=="psa")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=600,height=550');
	}
	else if (tg=="astaMsg" || tg=="newsletterMsg")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=600,height=500');
	}
	else if (tg=="viewAutoAnnuncio")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=650,height=550');
	}
	else if (tg=="editor")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=600');
	}
	else if (tg=="shortMsg")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=350');
	}
	else if (tg=="FAQ")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=600');
	}
	else if (tg!="" && tg!="s" && tg!="b" && tg!="p" && tg!="t")
	{
		top[tg].location.href=lnk;
	}
}

function Vai(lnk,tg)
{
	if (tg=="s"||tg=="t")
	{
		lnko=lnk;
		tgT=tg;
		setTimeout('rVai()',30);
	}
	else if (tg=="b")
	{
		pp = window.open(lnk,'','width='+BrW+',height='+BrH+',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes');
		pp.focus() ;
	}
	else if (tg=="p" || tg=="psa")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=600,height=550');
	}
	else if (tg=="astaMsg" || tg=="newsletterMsg")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=600,height=500');
	}
	else if (tg=="viewAutoAnnuncio")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=650,height=550');
	}
	else if (tg=="editor")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=600');
	}
	else if (tg=="shortMsg")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=350');
	}
	else if (tg=="FAQ")
	{
		window.open(lnk,'','toolbar=no,location=no,scrollbars=yes,top=80,left=50,width=665,height=600');
	}
	else if (tg!="" && tg!="s" && tg!="b" && tg!="p" && tg!="t")
	{
		top[tg].location.href=lnk;
	}
}

function rVai()
{
	if (tgT=='s')
	{
		self.location.href=lnko;
	}
	else
	{
		top.location.href=lnko;
	}
}

function trim (str) {
	var	str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

var b_timer = null; // blink timer
var b_on = true; // blink state
var blnkrs = null; // array of spans
// #220256 blue
// #fe7e2a arancio

function blink() {
var tmp = document.getElementsByTagName("a");
if (tmp) {
blnkrs = new Array();
var b_count = 0;
for (var i = 0; i < tmp.length; ++i) {
if (tmp[i].className == "blink") {
blnkrs[b_count] = tmp[i];
++b_count;
}
}
// time in m.secs between blinks
// 500 = 1/2 second
blinkTimer(650);
}
}

function blinkTimer(ival) {
if (b_timer) {
window.clearTimeout(b_timer);
b_timer = null;
}
blinkIt();
b_timer = window.setTimeout('blinkTimer(' + ival + ')', ival);
}

function blinkIt() {
for (var i = 0; i < blnkrs.length; ++i) {
if (b_on == true) {
blnkrs[i].style.color = "#fe7e2a";
}
else {
blnkrs[i].style.color = "#220256";
}
}
b_on =!b_on;
}

function blink_menu() {
var tmp = document.getElementsByTagName("a");
if (tmp) {
blnkrs = new Array();
var b_count = 0;
for (var i = 0; i < tmp.length; ++i) {
if (tmp[i].className == "blink_menu") {
blnkrs[b_count] = tmp[i];
++b_count;
}
}
// time in m.secs between blinks
// 500 = 1/2 second
blinkTimer_menu(650);
}
}

function blinkTimer_menu(ival) {
if (b_timer) {
window.clearTimeout(b_timer);
b_timer = null;
}
blinkIt_menu();
b_timer = window.setTimeout('blinkTimer_menu(' + ival + ')', ival);
}

function blinkIt_menu() {
for (var i = 0; i < blnkrs.length; ++i) {
if (b_on == true) {
blnkrs[i].style.color = "#fe7e2a";
}
else {
blnkrs[i].style.color = "#ffffff";
}
}
b_on =!b_on;
}
