var ie7=null;
var ie6=null;
var currentXML;
var currentUserXML;
var openLayer=false;


gkeys = {
coppie : [
{dominio : 'cqavanziholding.domino.it',chiave : 'ABQIAAAAD3aVixwpMlkUOE7rYecUgxQVa_ZcSpS2nMejJKFE5igmAxjlpRRdDt9gHoGNGxhR7K97_eC-4fYdqg'},
{dominio : 'www.avanziholding.com',chiave : 'ABQIAAAAD3aVixwpMlkUOE7rYecUgxRfnZ-kmdpdBFU85fpOFTqdIqUyMBSEzaXo_iJXyh2lo5y1EULka8rO_w'},
{dominio : 'www.avanzi.com',chiave : 'ABQIAAAAD3aVixwpMlkUOE7rYecUgxTFDqrUIxWblDSzmoDBNVewYmr2tBQOxR-qtJ_4s2J1725Sayy0ZOHfqA'},
{dominio : 'cqavanzi.domino.it',chiave : 'ABQIAAAAkM0UN5wA6iMeaHnPFFNubhQFA_vWY9DgQYCkzu9Pan73nPeYghSj8WNDJ3apNZ1iToxvF2jeBEJfZg'}
]
};

var currentHost=location.hostname;
for(i=0;i<gkeys['coppie'].length;i++){
   if(gkeys['coppie'][i].dominio==currentHost){
       createScript(gkeys['coppie'][i].chiave);
       break;
       }
   }

function createScript(key){
var source="http://maps.google.com/maps?file=api&amp;v=2.73&amp;key="+key;
document.write("\<script type=\"text/javascript\" src=\""+source+"\"\>\</script\>");
}



function resultStore(id) {
	$('#listresult').empty();

	var liststorehtml = '';


	$.ajax({
		 type: "GET",
		 url: "/avanzi/serv/search?entity=Store&condition=City:" + id,
		 dataType: 'xml',
		 success: function(msg){
				   $(msg).find("Item").each(function(){
				   					var id = $(this).attr('id');
								   	var label = $("value", this).text();

									var denominazione = $("value:eq(1)", this).text();
									var via = $("value:eq(2)", this).text();
									var citta = $("value:eq(3)", this).text();
									var cap = $("value:eq(4)", this).text();
									var tel = $("value:eq(6)", this).text();
									var fax = $("value:eq(7)", this).text();
									var orari = $("value:eq(8)", this).text();
									var straordinari = $("value:eq(9)", this).text();
									var foto = $("value:eq(10)", this).text();
									var prov = $("value:eq(15)", this).text();
									var lat = $("value:eq(11)", this).text();
									var long = $("value:eq(12)", this).text();

									  liststorehtml = liststorehtml + '<div class="negozio">';
							          liststorehtml = liststorehtml + '<div><img src="/www.avanziholding.com/img/negoziTop.jpg" /></div>';
							          liststorehtml = liststorehtml + '<div class="listBody">';
							          liststorehtml = liststorehtml + '<div class="wrapper">';
							          liststorehtml = liststorehtml + '<div class="title"><span class="citta">' + citta + '</span><span class="nome">' + denominazione + '</span><input type="hidden" class="map_lat" value="'+lat+'"/><input type="hidden" class="map_long" value="'+long+'"/></div>';
							          liststorehtml = liststorehtml + '<div class="dati">';
							          liststorehtml = liststorehtml + '<ul><li><span class="figure lfl"><img src="' + foto +'" /></span></li>';
							          liststorehtml = liststorehtml + '<li><span class="indirizzo lfl"><p>' + via + '<br />' + cap +' ' + citta +'<br />Tel.  ' + tel + '</p><a href="#" class="open_map"><img src="/www.avanziholding.com/img/mappa_btn.jpg" class="mappa_btn rfl" /></a></span></li></ul>';
							          liststorehtml = liststorehtml + '<span class="clear"></span>';
							          liststorehtml = liststorehtml + '</div><!-- dati -->';
							          liststorehtml = liststorehtml + '<div class="apertura">';
							          liststorehtml = liststorehtml + '<div class="title"><span class="orari">Orari di apertura</span></div>';
							          liststorehtml = liststorehtml + '<div class="list close">';

							          liststorehtml = liststorehtml + orari;

							          //liststorehtml = liststorehtml + '<div class="note"><em>NOTE:</em>' + straordinari + ' </div>';

							          liststorehtml = liststorehtml + '</div><!-- list -->';
							          liststorehtml = liststorehtml + '</div><!-- apertura -->';
							          liststorehtml = liststorehtml + '</div><!-- wrapper -->';
							          liststorehtml = liststorehtml + '</div><!-- listBody -->';
							          liststorehtml = liststorehtml + '<div><img src="/www.avanziholding.com/img/negoziBottom.jpg" /></div>';
							          liststorehtml = liststorehtml + '</div><!-- negozio -->';

								   })

					$('#listresult').append(liststorehtml);

					negoziListInit();
					openMap();

			}
	   });
}


function writeLavoraConNoi() {

	xmlurl = '/Lavora_con_noi_-_Sede_Centrale/data.xml';

	$('#ricerca_lavora_con_noi').empty();

	if ($('#ricerca_lavora_con_noi').attr('class') == 'centrale') {
		xmlurl = '/Lavora_con_noi_-_Sede_Centrale/data.xml';
	}
	if ($('#ricerca_lavora_con_noi').attr('class') == 'sedi') {
		xmlurl = '/Lavora_con_noi_-_Punti_Vendita/data.xml';
	}

	var page = GetUrlParam('page');
	if (page.length == 0) {
		page = 1;
	}
	var maxNewsPage = 3;
	var liststorehtml = '';
    var i = 0;
	page = page * 1;
	var html = '';
	var maxNews = page * maxNewsPage;
	var minNews = maxNews - maxNewsPage;
	$.ajax({
		 type: "GET",
		 url:sRootPath+langXml+xmlurl,
		// url: "/data.xml",
		 dataType: 'xml',
		 success: function(msg){
				   $(msg).find("Item").each(function(){
									i++;
				   					var id = $(this).attr('id');
								   	var luogo = $("luogo", this).text().replace(/(<([^>]+)>)/ig,"");
								   	var profilo = $("profilo", this).text().replace(/(<([^>]+)>)/ig,"");
								   	var descrizione_b = $("descrizione_breve", this).text();
								   	var descrizione_lunga = $("descrizione_lunga", this).text();
   							  	 	var rif = $("riferimento_email", this).text().replace(/(<([^>]+)>)/ig,"");
   							   		var immagine = $("immagine", this).text();

									if ((i<=maxNews) && (i>minNews)) {
												  liststorehtml = liststorehtml + '<div class="punti">';
								          liststorehtml = liststorehtml + '<div class="listBody">';
								          liststorehtml = liststorehtml + '<div class="wrapper">';
								          liststorehtml = liststorehtml + '<div class="dati"> ';
								          liststorehtml = liststorehtml + '<div class="title"><ul><li>' + luogo + '</li><li class="t">' + profilo + '</li></ul></div>';
								          if(immagine!='/filemanager/cms_avanzi/.BlankImage.jpg'){
								          liststorehtml = liststorehtml + ' <img src="'+immagine+'" class="lfl" />	';
								          	}

								          liststorehtml = liststorehtml + '<p class="indirizzo">'+descrizione_b + '</p>';
								          liststorehtml = liststorehtml + '<a href="#" class="c_'+i+'" onclick="javascript:openLayerPuntoVendita(xmlurl,'+(i-1)+');"><img src="/www.avanziholding.com/img/inviaCV_btn.jpg" class="mappa_btn rfl" /></a>  <span class="clear"></span>';


								          liststorehtml = liststorehtml + '</div></div></div></div>';
								          liststorehtml = liststorehtml +  '<img src="/www.avanziholding.com/img/spacer.jpg" />';
							          }
								   })
			if (i>maxNewsPage) {
							var numPages = Math.ceil(i / maxNewsPage);

				var strhost=""+window.location;
				var ext=".html";
				if(strhost.indexOf(".html?")>0){
					strhost=strhost.substring(0,strhost.indexOf(".html?"));
					ext=".html";
					strhost=strhost+ext;
				}
	strhost=strhost.replace('#','');
							html = html + '<div class="newsPager rfl"><ul><li><a hreF="'+strhost+'?page=1"><img src="/www.avanziholding.com/img/newsPagerFirst.jpg" /></a></li>';
							if (page>1) {
								html = html + '<a href="'+strhost+'?page=' + (page - 1) + '"><li><img src="/www.avanziholding.com/img/newsPagerLeft.jpg" /></a></li>';
							} else {
								html = html + '<li><img src="/www.avanziholding.com/img/newsPagerLeft.jpg" /></li>';
							}

							var j=1;
							for (j=1;j<=numPages;j++) {
								if ((j) == (page)) {
									html = html + '<li class="selected">' + j + '</li>';
								} else {
									html = html + '<li>' + j + '</li>';
								}
							}

							if (page<numPages) {
								html = html + '<li><a href="'+strhost+'?page=' + (page + 1) + '"><img src="/www.avanziholding.com/img/newsPagerRight.jpg" /></a></li>';
							} else {
								html = html + '<li><img src="/www.avanziholding.com/img/newsPagerRight.jpg" /></li>';
							}
							html = html + '<li><a href="'+strhost+'?page=' + numPages + '"><img src="/www.avanziholding.com/img/newsPagerLast.jpg" /></a></li>';
							html = html + '</ul></div><!-- newsPager -->';

						}
					$('#ricerca_lavora_con_noi').append(liststorehtml);
					$('#ricerca_lavora_con_noi').append(html);



			}
	   });
}
function clearAnnuncio(){
		$('#annuncio').addClass("close");
}

function openLayerPuntoVendita(xmlurl, idc){
//	$("."+"c_"+i).find("p").removeClass("close");
$('#annuncio').removeClass("close");
	$('#annuncio').html('<a class="rfl" id="close" href="javascript:clearAnnuncio();">Loading...</a>');


	var html="";
	//$('div.punti').each(function(){
	//		$(this).find('.mappa_btn').click(function(){
					//var idc=	$(this).parent().attr('class');
					$.ajax({

			 					type: "GET",
		 						url:sRootPath+langXml+xmlurl,
		 						//url: "/data.xml",
								dataType: 'xml',
			 					success: function(msg){
				 		    	var news = $(msg).find("Item").get(idc);
								//$(msg).find("Item").filter("[@id="+idc+"]")


			   					var id = $(this).attr('id');
							  	var luogo = $("luogo", news).text().replace(/(<([^>]+)>)/ig,"");
								var profilo = $("profilo", news).text().replace(/(<([^>]+)>)/ig,"");
								var descrizione_lunga = $("descrizione_lunga", news).text();
	   							var rif = $("riferimento_email", news).text().replace(/(<([^>]+)>)/ig,"");
								   	var immagine = $("immagine", news).text();

//									html+='<div class="close" id="annuncio">';
								  html+='<a class="rfl" id="close" href="javascript:clearAnnuncio();">chiudi</a>';
								  html+='<div class="dati">';
									html+='<div class="title"><ul><li>'+luogo+'</li><li class="t">'+profilo+'</li></ul></div>';
							      //html+='<ul>';
							    if(immagine!='/filemanager/cms_avanzi/.BlankImage.jpg'){
							          html = html + ' <img src="'+immagine+'" class="figure lfl"/> ';
							          	}

						      html+='<p class="indirizzo">'+descrizione_lunga+'</p>';
						      //html+='</ul>';
						      html+='<span class="clear"/>';
						      html+='</div><!-- dati -->';
							  html+='<div class="disclaimer">';
							  html+='<p>La informiamo, ai sensi dell\'art. 10 della Legge 31 dicembre 1996 n. 675 e succesive modifiche, recante disposizioni a tutela delle persone e di altri soggetti rispetto al trattamento dei dati personali, che Avanzi Holding proceder&agrave; al trattamento dei dati personali da Lei forniti nel rispetto della citata normativa. Il titolare del trattamento &egrave; Avanzi Holding presso la sede amministrativa di Via della Liberazione, 5 - 40128 Bologna. I dati personali da Lei forniti all\'interno del sito www.avanzi.com, sono raccolti con modalit? telematiche e trattati, anche con l?ausilio di mezzi elettronici o comunque automatizzati, direttamente e/o tramite terzi per le seguenti finalit?: - finalit&agrave; connesse all?utilizzo dei servizi offerti dal sito. In mancanza del consenso, tali servizi non potranno essere erogati. Ai sensi dell?art. 13 della Legge n. 675/96, Lei ha il diritto in qualsiasi momento di conoscere i Suoi dati e le modalit? di utilizzo; ed inoltre di ottenere: 1. la conferma 2. l?aggiornamento, la rettifica e di opporsi al loro trattamento 3. la cancellazione, il blocco, la trasformazione in forma anonima, per i dati trattati in violazione di legge. Per esercitare i diritti previsti all\'art. 13 della Legge n. 675/96 dovr&agrave; scrivere a AVANZI HOLDING s.r.l. Via della Liberazione, 5 - 40128 Bologna</p>';
							  html+='<div class="accept"><a href="mailto:avanzi.recruiting@avanzi.com?subject='+rif+'"><img class="inviaCV_btn rfl close" src="/www.avanziholding.com/img/inviaCV_btn.jpg"/></a>';
							  html+='<input type="checkbox" class="lfl" id="esprimo"/>';
							  html+='	<h4 class="lfl">Esprimo il consenso</h4></div>';
							  html+='</div>';
								//html+='</div>';

											$('#annuncio').html(html);
											$("#content").css({"min-height":$('#annuncio').height()+100+"px"});
											$('#annuncio').removeClass("close");
											$('#annuncio #esprimo').toggle(function() {$('#annuncio .inviaCV_btn').removeClass('close')},function() {$('#annuncio .inviaCV_btn').addClass('close')});
											//$("."+"c_"+i).find("p").addClass("close");

			  }//succes
		   });//ajax



	 //  });//click
	//});//punti
}



function openMap(){
	$('div.negozio').each(function(){
		$(this).find('.open_map').click(function(){
			if(!openLayer){
				var store = $(this).parent().parent().parent().parent().parent().find('span.nome').html();
				var city = $(this).parent().parent().parent().parent().parent().find('span.citta').html();
				var top = ($(this).offset().top)-320;
				var lat=$(this).parent().parent().parent().parent().parent().find('input.map_lat').val().replace(/(<([^>]+)>)/ig,"");;
				var long=$(this).parent().parent().parent().parent().parent().find('input.map_long').val().replace(/(<([^>]+)>)/ig,"");;
				$('#main').append('<div id="map_wrap"><p id="close_map"><a href="#">close X</a></p><p id="location"><span class="store">'+store+'</span><span>-</span><span class="city">'+city+'</span></p><div id="map">qui la mappa</div></div>');
				openLayer=true;
				$('#map_wrap').css({'top':top});
				$('#close_map a').click(function(){
					$('#map_wrap').remove();
					openLayer=false;
					return false;
				})
				loadMap(long,lat);

			}
			return false;
		})
	})
}

function loadMap(long,lat){
	 if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map"));
			map.addControl(new GSmallMapControl());
			map.setCenter(new GLatLng(lat,long), 15);
	 }

	var point = new GLatLng(lat,long);
	map.addOverlay(new GMarker(point));
}


function changeCity(id, oldRegion, oldCity) {

	var selectcittahtml = '';

	if (oldRegion>0 && id!=oldRegion ) {
		id = oldRegion;
	}

	$.ajax({
			 type: "GET",
			 url: "/avanzi/serv/search?entity=City&condition=Region:" + id,
			 dataType: 'xml',
			 success: function(msg){
					   $(msg).find("Item").each(function(){
					   					id = $(this).attr('id');
									   	label = $("value:eq(0)", this).text();

										selectcittahtml = selectcittahtml + '<option value="' + id + '" >' + label + '</option>';

									   })

						$('#citta').empty();
						$('#citta').append(selectcittahtml);

						if (oldCity>0) {
					   		resultStore(oldCity);
					   		$('#regione option[@value=' + oldRegion+ ']').attr('selected','selected');
					   		$('#citta option[@value=' + oldCity+ ']').attr('selected','selected');
					   }
				}
		   });
}

$(document).ready(function(){
	
	if($('#iframeaziende').is('iframe')){
		if(GetUrlParam("op")!='' && GetUrlParam("op")=='success' && GetUrlParam("code")!=''){
			$("#content .rightCol").hide();
				$("#variable").html("");
				$("#content .centCol").css({"width":"730px"});
			$("#variable").load("/avanzidiscounts/checkRegisterAziende.do?code="+GetUrlParam("code"));
		}else{
			
			var strhost=""+window.location;
			if(strhost.indexOf("#")>0){
				strhost=strhost.substring(0,strhost.indexOf("#"));
			}
			if(strhost.indexOf("?")>0){
				strhost=strhost.substring(0,strhost.indexOf("?"));
			}		
		/*	if(strhost.indexOf("http://")>=0){
				strhost=strhost.replace("http://","");
				strhost=strhost.substring(strhost.indexOf("/"),strhost.length);	
			}		*/
	
			$('#iframeaziende').attr("src",$('#iframeaziende').attr("src")+"?op="+GetUrlParam("op")+"&page="+strhost);
		}
		
		
		}
	
	
	((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? (ie7=true) : (ie7=false);
	((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? (ie6=true) : (ie6=false);

	if(ie6) {$(document).pngFix()}
	//http://cqavanziholding.domino.it/avanzi/serv/search?entity=City&condition=Region:3
	// http://cqavanziholding.domino.it/avanzi/serv/search?entity=Region

	// Correzzione per Contentino Old
	if((ie6)||(ie7)) {
            $(document).find("img").each(function(){
                    $(this).attr('alt','');
            })
    }
	//
	if($('#ricerca_lavora_con_noi').is('div')){
		writeLavoraConNoi();
	}

	$('.accept #esprimo').toggle(function() {$('.accept .inviaCV_btn').removeClass('close')},function() {$('.accept .inviaCV_btn').addClass('close')});

	if($('#store').is('form')){
		var selecregionhtml = '';

		var oldRegion = GetUrlParam('Region');
		var oldCity = GetUrlParam('City');

		$.ajax({
			 type: "GET",
			 url: "/avanzi/serv/search?entity=Region&reset=True",
			 dataType: 'xml',
			 success: function(msg){
					   $(msg).find("Item").each(function(){
					   					id = $(this).attr('id');
									   	label = $("value", this).text();

										selecregionhtml = selecregionhtml + '<option value="' + id + '" >' + label + '</option>';

									   })

						$('#regione').empty();
						$('#regione').append(selecregionhtml);

						$('#regione').change(function(){

							changeCity($(this).val(), oldRegion, oldCity);

							return false;
						});

						changeCity($('#regione').find('option:eq(0)').val(), oldRegion, oldCity);

						// Reset
						if (oldRegion>0) {
							oldRegion = 0;
							oldCity = 0;
						}
				}
		   });



		   // Find ....
		   $('#findstore').click(function(e){
				var idcitta = $('#citta').val();

				resultStore(idcitta);

				return false;
			});

			$('#gotostore').click(function(e){
				var idselectcitta = $('#citta').val();
				var idselectregione = $('#regione').val();

				window.location="/it/negozi/list_negozi.html?Region=" + idselectregione + "&City=" + idselectcitta;

				return false;
			});

	}

	if($('#list-gallery').is('ul')){
		 var gallery = new Array();
		 var thumb = new Array();
		 var tempUrl = "";
		 var i = 0;

		 $('#list-gallery').find("li").each(function(){
			gallery[i] = "" + $(this).find('img').attr('src');

			var ext = gallery[i].lastIndexOf('.');
			
			var uri = gallery[i].lastIndexOf('/');

			thumb[i] = gallery[i].substring(0,uri) +'/.' + gallery[i].substring(uri+1, ext) + '.'+gallery[i].substring(ext+1 ,gallery[i].length) ;

			i++;
		 });

		 if (i>0) {
		 	$('#gallery').find('div:eq(0)').html('<img src="' + gallery[0] + '" id="bigImg" />')
		 	var j = 0;
		 	var html = '';
		 	for (j==0;j<i;j++) {
		 		html = html + '<li><div><img width="60" height="45" class="thumbnail" src="' + thumb[j]+ '" alt="' + gallery[j] + '" /></div></li>';
		 	}
		 	$('#thumbnailappend').html(html);
		 }
	};


	// Inizializza Utility ...
	pageInit();

	// Modifica colori
	if($('#color-style').is('div')){
		var style = $('#color-style').text();
		$('#variable').addClass(style);
		$('#color-style').remove();
	};

	if($('#sticker').is('div')){
		$('#sticker').click(function(){
			$('#videoLayer').addClass('show');
			$('#hp-spot').flash({
								width:     620,
								height:    320,
								autoplay:  true,
								params:    {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
								attrs:     {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
								swf:       '/www.avanziholding.com/swf/player.swf',
								flashvars:  {file: '/filemanager/cms_avanzi/img/video/video.flv', image: '/www.avanziholding.com/img/frame_hp_spot.jpg', height : 620, width :320,frontcolor :"ffffff",backcolor : "000000",lightcolor : "FFFFFF",overstretch : false,bufferlength : 5,usefullscreen : true},
								caption:   false
			});
		});
		$('#close_btn').click(function(){
			$('#videoLayer').removeClass('show');
		});
	}

	if($('#show-video').is('div')){
		var videoUrl = $('#show-video').find('a').attr('href');
		var imageUrl = $('#show-video').find('img').attr('src');

		$('#show-video').flash({
								width:     170,
								height:    127,
								autoplay:  true,
								params:    {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
								attrs:     {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
								swf:       '/www.avanziholding.com/swf/player.swf',
								flashvars:  {file: videoUrl, image: imageUrl, height : 170, width :127,frontcolor :"ffffff",backcolor : "000000",lightcolor : "FFFFFF",overstretch : false,bufferlength : 5,usefullscreen : true},
								caption:   false
						});
		//$('#show-video').find('a').remove();
		//$('#show-video').find('img').remove();
	}
	
	

	if($('.custom-swf').is('div')){
		$(document).find(".custom-swf").each(function(){
			var swfUrl = $(this).find('a').attr('href');
			var x = $(this).find('.x-value').html();
			var y = $(this).find('.y-value').html();

			$(this).flash({
				swf: swfUrl,
				width: x,
				height: y,
				params : {  quality : 'high' },
				caption:   false
			});

		 });
	}

	if($('.boxnews').is('div')){

		var html = '';
   		var i = 0;

		$(document).find(".boxnews").each(function(){
			var obj = $(this);

			$.ajax({
						 type: "GET",
						 url: "/it/News/data.xml",
						 dataType: 'xml',
						 success: function(msg){
								   $(msg).find("Item").each(function(){
								   					i++;
								   					var id = $(this).attr('id');
												   	var titolo = $("Titolo", this).text();
												   	var thumbnail = $("Thumbnail", this).text();
												   	var data = $("Data", this).text();
													var testobreve = $("TestoBreve", this).text();

													if (i<3) {
														html = html + '<h3>' + data + '</h3>';
														html = html + testobreve;
													}

												   })

									$(obj).append(html);

							 }

					   });

		 });
	}


	if($('.smoothSlide ').is('div')){
		carouselVetrina();
	}
	
	if($('#form_coupon').is('form')){
		controlloCoupon();
	}
		if($('#form_azienda').is('form')){
		controlloAzienda();
	}

	if($('#homeMenu').is('div')){	layerNonGuidare();	}

});

	function layerNonGuidare(){
		$('body').append('<div id="fdr">&nbsp;</div>');
		$('#fdr').css({'height': getDocHeight() });
		$('body').append('<div id="layer_content"><a href="#" id="layer_close"><img src="/www.avanziholding.com/img/chiudi_blu.gif" alt="chiudi" /></a><div id="hp-non_guidare">&nbsp;</div></div>');
		
		$('#hp-non_guidare').flash({
			width:     496,
			height:    340,
			autoplay:  true,
			params:    {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
			attrs:     {bgcolor : '#000000',scale:'noscale', allowfullscreen:'true', wmode: 'transparent'},
			swf:       '/www.avanziholding.com/swf/non_guidare.swf',
			//swf:       'swf/non_guidare.swf',
			flashvars: {width:496, height:340, frontcolor :"ffffff", backcolor:"000000",lightcolor : "FFFFFF",overstretch : false,bufferlength : 5,usefullscreen : true},
			caption:   false
		});
		
		$('#layer_close').click(function(){
			$('#fdr').remove();
			$('#layer_content').remove();
		});
		
	}

	function getDocHeight(){
  return Math.max(
			$(document).height(),
			$(window).height(),
			document.documentElement.clientHeight
  );
	};

		function controlloCoupon() {
			var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
			var validNumber = /^\d+$/;
			
			$('#form_coupon').submit(function() {
			
				if (
					($('#form_coupon input[name=nome]').val() == '') ||
					($('#form_coupon input[name=cognome]').val() == '') ||
					($('#form_coupon input[name=email]').val() == '') ||
					($('#form_coupon input[name=gg]').val() == '') ||
					($('#form_coupon input[name=mm]').val() == '') ||
					($('#form_coupon input[name=yyyy]').val() == '') ||
					(!$("#form_coupon input[name=privacy]").attr("checked"))
					) {
							alert('Attenzione ai campi obbligatori');
							return false;
							}
				if (!validEmail.test($('#form_coupon input[name=email]').val())) {
								alert('Attenzione: inserire un indirizzo email valido');
								return false;
				}
				if (
								($('#form_coupon input[name=gg]').val() != '') && !validNumber.test($('#form_coupon input[name=gg]').val()) ||
								($('#form_coupon input[name=mm]').val() != '') && !validNumber.test($('#form_coupon input[name=mm]').val()) ||
								($('#form_coupon input[name=yyyy]').val() != '') && !validNumber.test($('#form_coupon input[name=yyyy]').val())
							)
								{
												alert('Attenzione: inserire solo numeri per indicare la data');
												return false;
								}				
			});

		}
	function controlloAzienda() {
			var validEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
			var validNumber = /^\d+$/;
			
			$('#form_azienda').submit(function() {
			
				if (
					($('#form_azienda input[name=nome]').val() == '') ||
					($('#form_azienda input[name=cognome]').val() == '') ||
					($('#form_azienda input[name=email]').val() == '') ||
					($('#form_azienda input[name=gg]').val() == '') ||
					($('#form_azienda input[name=mm]').val() == '') ||
					($('#form_azienda input[name=yyyy]').val() == '') ||
					($('#form_azienda input[azienda=yyyy]').val() == '') ||
					($('#form_azienda input[codazienda=yyyy]').val() == '') ||
					(!$("#form_azienda input[name=privacy]").attr("checked"))
					) {
							alert('Attenzione ai campi obbligatori');
							return false;
							}
				if (!validEmail.test($('#form_azienda input[name=email]').val())) {
								alert('Attenzione: inserire un indirizzo email valido');
								return false;
				}
				if (
								($('#form_azienda input[name=gg]').val() != '') && !validNumber.test($('#form_azienda input[name=gg]').val()) ||
								($('#form_azienda input[name=mm]').val() != '') && !validNumber.test($('#form_azienda input[name=mm]').val()) ||
								($('#form_azienda input[name=yyyy]').val() != '') && !validNumber.test($('#form_azienda input[name=yyyy]').val())
							)
								{
												alert('Attenzione: inserire solo numeri per indicare la data');
												return false;
								}				
			});

		}

  function carouselVetrina() {

			/* var contatore=$("#marchi ul li").length;
			//alert(contatore);
			for (i=0; i<contatore; i++){
				//alert ("Siamo arrivati all'indice "+i+" di un totale di "+contatore);
				$("#sliding ul").append("<li><img src='img/TopSlide.gif' class='freccia_"+i+"' /></li>");

			}; */

			var contatore=0;
			var html = '<ul>';
			$('#marchi ul').find('li').each(function(){
				$(this).addClass('indice_'+contatore);
				html = html + "<li><img src='/www.avanziholding.com/img/TopSlide.gif' class='indice_"+contatore+"' /></li>";
				contatore++;
   			});
   			html = html + '</ul>';
			$("#sliding").html(html);//creo tante frecce quante sono le immmagini; lo faccio prima di applicare jcarousel perche il plugin replica gli elementi lista e si perderebbe il conto

			$('#sliding ul li img.indice_0').show();

			$("#marchi").jCarouselLite({
				btnNext: "#arrowRight",
				btnPrev: "#arrowLeft",
				visible: 6
			});

			$("#sliding").jCarouselLite({
				btnNext: "#arrowRight",
				btnPrev: "#arrowLeft",
				visible: 6
			});

			$('#marchi ul li a').click(function(){

				var preview_cliccata = $(this).attr('href');
				//alert("hai cliccato l'immagine "+preview_cliccata+"!");
				$('#bigImg img').attr( {'src': preview_cliccata} );

				var selezionato = $(this).parent().attr('class');//memorizzo l'indice dell'immagine cliccata
				//alert(selezionato);

	 		$('#sliding ul li').find('img').each(function(){
					$(this).hide();
				});
				$('#sliding ul li img.'+selezionato).show();

				return false;
			});

  }


/******* UTILS GET URLPARAM *********/
function GetUrlParam( paramName )
{
	var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
	var oMatch = oRegex.exec( window.top.location.search ) ;

	if ( oMatch && oMatch.length > 1 )
		return decodeURIComponent( oMatch[1] ) ;
	else
		return '' ;
}

/********************** UTILS ************************/
//pngfix
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s($){3.1s.1k=s(j){j=3.1a({12:\'1m.1j\'},j);8 k=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 5.5")!=-1);8 l=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 6.0")!=-1);o(3.17.16&&(k||l)){3(2).L("1r[@m$=.M]").z(s(){3(2).7(\'q\',3(2).q());3(2).7(\'p\',3(2).p());8 a=\'\';8 b=\'\';8 c=(3(2).7(\'K\'))?\'K="\'+3(2).7(\'K\')+\'" \':\'\';8 d=(3(2).7(\'A\'))?\'A="\'+3(2).7(\'A\')+\'" \':\'\';8 e=(3(2).7(\'C\'))?\'C="\'+3(2).7(\'C\')+\'" \':\'\';8 f=(3(2).7(\'B\'))?\'B="\'+3(2).7(\'B\')+\'" \':\'\';8 g=(3(2).7(\'R\'))?\'1d:\'+3(2).7(\'R\')+\';\':\'\';8 h=(3(2).1c().7(\'1b\'))?\'19:18;\':\'\';o(2.9.y){a+=\'y:\'+2.9.y+\';\';2.9.y=\'\'}o(2.9.t){a+=\'t:\'+2.9.t+\';\';2.9.t=\'\'}o(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}8 i=(2.9.15);b+=\'<x \'+c+d+e+f;b+=\'9="13:11;1q-1p:1o-1n;O:W-V;N:1l;\'+g+h;b+=\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\';b+=\'J:I:H.r.G\'+\'(m=\\\'\'+3(2).7(\'m\')+\'\\\', D=\\\'F\\\');\';b+=i+\'"></x>\';o(a!=\'\'){b=\'<x 9="13:11;O:W-V;\'+a+h+\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\'+\'">\'+b+\'</x>\'}3(2).1i();3(2).1h(b)});3(2).L("*").z(s(){8 a=3(2).T(\'N-S\');o(a.E(".M")!=-1){8 b=a.X(\'1g("\')[1].X(\'")\')[0];3(2).T(\'N-S\',\'1f\');3(2).Q(0).Y.J="I:H.r.G(m=\'"+b+"\',D=\'F\')"}});3(2).L("1e[@m$=.M]").z(s(){8 a=3(2).7(\'m\');3(2).Q(0).Y.J=\'I:H.r.G\'+\'(m=\\\'\'+a+\'\\\', D=\\\'F\\\');\';3(2).7(\'m\',j.12)})}1t 3}})(3);',62,92,'||this|jQuery||||attr|var|style|||||||||||||src|navigator|if|height|width|Microsoft|function|padding|px|appVersion|margin|span|border|each|class|alt|title|sizingMethod|indexOf|scale|AlphaImageLoader|DXImageTransform|progid|filter|id|find|png|background|display|appName|get|align|image|css|parseInt|block|inline|split|runtimeStyle|Explorer|Internet|relative|blankgif|position|MSIE|cssText|msie|browser|hand|cursor|extend|href|parent|float|input|none|url|after|hide|gif|pngFix|transparent|blank|line|pre|space|white|img|fn|return'.split('|'),0,{}));
/* jquery.swfobject */
(function(A){A.flashPlayerVersion=function(){var D,B=null,I=false,H="ShockwaveFlash.ShockwaveFlash";if(!(D=navigator.plugins["Shockwave Flash"])){try{B=new ActiveXObject(H+".7")}catch(G){try{B=new ActiveXObject(H+".6");D=[6,0,21];B.AllowScriptAccess="always"}catch(F){if(D&&D[0]===6){I=true}}if(!I){try{B=new ActiveXObject(H)}catch(E){D="X 0,0,0"}}}if(!I&&B){try{D=B.GetVariable("$version")}catch(C){}}}else{D=D.description}D=D.match(/^[A-Za-z\s]*?(\d+)(\.|,)(\d+)(\s+r|,)(\d+)/);return[D[1]*1,D[3]*1,D[5]*1]}();A.flashExpressInstaller="expressInstall.swf";A.hasFlashPlayer=(A.flashPlayerVersion[0]!==0);A.hasFlashPlayerVersion=function(C){var B=A.flashPlayerVersion;C=(/string|integer/.test(typeof C))?C.toString().split("."):C;return(C)?(B[0]>=(C.major||C[0]||B[0])&&B[1]>=(C.minor||C[1]||B[1])&&B[2]>=(C.release||C[2]||B[2])):(B[0]!==0)};A.flash=function(M){if(!A.hasFlashPlayer){return false}var C=M.swf||"",K=M.params||{},E=document.createElement("body"),B,L,H,D,J,I,G,F;M.height=M.height||180;M.width=M.width||320;if(M.hasVersion&&!A.hasFlashPlayerVersion(M.hasVersion)){A.extend(M,{id:"SWFObjectExprInst",height:Math.max(M.height,137),width:Math.max(M.width,214)});C=M.expressInstaller||A.flashExpressInstaller;K={flashvars:{MMredirecturl:window.location.href,MMplayerType:(A.browser.msie&&A.browser.win)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}if(M.flashvars&&typeof K==="object"){A.extend(K,{flashvars:M.flashvars})}for(J in (I=["swf","expressInstall","hasVersion","params","flashvars"])){delete M[I[J]]}B=[];for(J in M){if(typeof M[J]==="object"){L=[];for(I in M[J]){L.push(I.replace(/([A-Z])/,"-$1").toLowerCase()+":"+M[J][I]+";")}M[J]=L.join("")}B.push(J+'="'+M[J]+'"')}M=B.join(" ");if(typeof K==="object"){B=[];for(J in K){if(typeof K[J]==="object"){L=[];for(I in K[J]){if(typeof K[J][I]==="object"){H=[];for(G in K[J][I]){if(typeof K[J][I][G]==="object"){D=[];for(F in K[J][I][G]){D.push(F.replace(/([A-Z])/,"-$1").toLowerCase()+":"+K[J][I][G][F]+";")}K[J][I][G]=D.join("")}H.push(G+"{"+K[J][I][G]+"}")}K[J][I]=H.join("")}L.push(window.escape(I)+"="+window.escape(K[J][I]))}K[J]=L.join("&amp;")}B.push('<PARAM NAME="'+J+'" VALUE="'+K[J]+'">')}K=B.join("")}if(!(/style=/.test(M))){M+=' style="vertical-align:text-top;"'}if(!(/style=(.*?)vertical-align/.test(M))){M=M.replace(/style="/,'style="vertical-align:text-top;')}if(A.browser.msie){M+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';K='<PARAM NAME="movie" VALUE="'+C+'">'+K}else{M+=' type="application/x-shockwave-flash" data="'+C+'"'}E.innerHTML="<OBJECT "+M+">"+K+"</OBJECT>";return A(E.firstChild)};A.fn.flash=function(C){if(!A.hasFlashPlayer){return this}var B=0,D;while((D=this.eq(B++))[0]){D.html(A.flash(A.extend({},C)));if(D[0].firstChild.getAttribute("id")==="SWFObjectExprInst"){B=this.length}}return this}}(jQuery));
