$(function(){
	//tab inizializzato di default
	var  tabSelected = 0;
	
	var sPath = window.location.pathname;
	var nomepagina = sPath.substring(sPath.lastIndexOf('/') + 1);
		
	if (nomepagina == "carte.html") {
		tabSelected = 1;
	} else if (nomepagina == "trading.html") {
		tabSelected = 2;
	} else if (nomepagina == "risparmio.html") {
		tabSelected = 3;
	}

	$.ajaxSetup({
	  global: false,
	  cache:false
	}); 
	
	$("#tabs").tabs("div#tabs-1", {
		effect: 'ajax',
		initialIndex: tabSelected,
		onClick: function () {
			$('.accordion').accordion({
				active: 100,
				collapsible: true,
				autoHeight: false,
				header: 'h3',
				changestart: function(event, ui) {
					showHidePopup('popuptrading',0)
				}

			});

			if(!$('ul#tabs li a.current').parent('li').hasClass('liactive')) {
				$('ul#tabs li a').parent('li').removeClass('liactive');	
				$('ul#tabs li a.current').parent('li').addClass('liactive');
			}
				
		}
		
	}).history(); 
	
	$('ul#tabs li a').bind('click',function(){
		$('ul#tabs li a').parent('li').removeClass('liactive');
		$(this).parent('li').addClass('liactive');
	});


//	$('#tabs').tabs({
//		selected: tabSelected,
//		cache: false,
//		load: function(event, ui) {
			/*$(".ui-tabs-panel").css('display','none');*/
	//		$(".accordion").accordion( 'destroy' );
			
			/*$(".ui-tabs-panel").css('opacity',0);
			$(".accordion").css('opacity',0);
			$("#tabellacartebancomat").css('opacity',0);
			$("#calcolatore").css('opacity',0);
			$("#contenutolanding a img").css('opacity',0);*/
//		},
//		show: function(event, ui) {
/*				$(".ui-tabs-panel").css('display','block');
				$('.accordion').accordion({
					active: 100,
					collapsible: true,
					autoHeight: false,
					header: 'h3',
					changestart: function(event, ui) {
						showHidePopup('popuptrading',0)
					}

				});
*/				
				/*$(".ui-tabs-panel").animate({ opacity: 1},2000);
				$(".accordion").animate({ opacity: 1},2000);
				$("#tabellacartebancomat").animate({ opacity: 1},2000);
				$("#calcolatore").animate({ opacity: 1},2000);
				$("#contenutolanding a img").animate({ opacity: 1},2000);*/
/*		}
	})*/
	


	
});



			function AutoUpdate(key,element,type)
			{

				checkValidInput(element,type,key);
				ComputeTotal();
			}
			function checkValidInput(element,type,key)
				{
				if(type=="float")
					{		
					element.value = element.value.replace(/[^\d,.]/g,"");		
					if (isNaN(parseFloat(element.value.replace(/,/g,"."))))
						{
						element.value = "";
						}
					else
						{if ((key!="188")&&(key!="190")&&(key!="48"))
							{
							parseElementAsFloat(element,"N");
							}
						}
					}
				else if(type=="int")
					{
					 element.value = element.value.replace(/\D/g,"");
					}
				}
			function parseElementAsFloat(element,fix)
				{
				
				if (isNaN(parseFloat(element.value.replace(/,/g,"."))))
						{
						element.value = "";
						}
				else
						{
							var newValue;
							newValue = parseFloat(element.value.replace(/,/g,"."))
							if (fix == "Y")
							{
								if (newValue < 1000)
								newValue = newValue.toFixed(2);
							}
							element.value = String(newValue).replace(/[\.]/g,",");
						}
				}
			function ComputeTotal()
				{
				var addImposta;
				addImposta = 34.20 ;
				var total;
				var canone_tot;
				var bonifici_tot;
				var domiciliazioni_tot;
				var bollettini_tot;
				var assegni_tot;
				var bancomat_tot;
				var prelievi_tot;
				var visa_tot;
				var carburante_tot;
				// inizializzo addendi
				canone_tot = 0 ;
				bonifici_tot = 0 ;
				domiciliazioni_tot = 0 ;
				bollettini_tot = 0 ;
				assegni_tot = 0 ;
				bancomat_tot = 0 ;
				prelievi_tot = 0 ;
				visa_tot = 0 ;
				carburante_tot = 0 ;
				
				if ((document.getElementById('canone').value)&&(document.getElementById('canone').value != ""))
				{canone_tot = parseFloat(document.getElementById('canone').value.replace(/,/g,".")); }
				if ((document.getElementById('bonifici').value)&&(document.getElementById('bonifici').value != "")&&(document.getElementById('n1').value)&&(document.getElementById('n1').value != ""))
				{bonifici_tot = parseInt(document.getElementById('n1').value) * parseFloat(document.getElementById('bonifici').value.replace(/,/g,".")); }
				if ((document.getElementById('domiciliazioni').value)&&(document.getElementById('domiciliazioni').value != "")&&(document.getElementById('n2').value)&&(document.getElementById('n2').value != ""))
				{domiciliazioni_tot = parseInt(document.getElementById('n2').value) * parseFloat(document.getElementById('domiciliazioni').value.replace(/,/g,".")); }
				if ((document.getElementById('bollettini').value)&&(document.getElementById('bollettini').value != "")&&(document.getElementById('n3').value)&&(document.getElementById('n3').value != ""))
				{bollettini_tot = parseInt(document.getElementById('n3').value) * parseFloat(document.getElementById('bollettini').value.replace(/,/g,".")); }
				if ((document.getElementById('assegni').value)&&(document.getElementById('assegni').value != ""))
				{assegni_tot = parseFloat(document.getElementById('assegni').value.replace(/,/g,".")); }
				if ((document.getElementById('bancomat').value)&&(document.getElementById('bancomat').value != ""))
				{bancomat_tot = parseFloat(document.getElementById('bancomat').value.replace(/,/g,".")); }				
				if ((document.getElementById('prelievi').value)&&(document.getElementById('prelievi').value != "")&&(document.getElementById('n4').value)&&(document.getElementById('n4').value != ""))
				{prelievi_tot = parseInt(document.getElementById('n4').value) * parseFloat(document.getElementById('prelievi').value.replace(/,/g,".")); }
				if ((document.getElementById('visa').value)&&(document.getElementById('visa').value != ""))
				{visa_tot = parseFloat(document.getElementById('visa').value.replace(/,/g,".")); }
				if ((document.getElementById('carburante').value)&&(document.getElementById('carburante').value != "")&&(document.getElementById('n5').value)&&(document.getElementById('n5').value != ""))
				{carburante_tot = parseInt(document.getElementById('n5').value) * parseFloat(document.getElementById('carburante').value.replace(/,/g,".")); }

				
				total =  (canone_tot + bonifici_tot + domiciliazioni_tot + bollettini_tot +  assegni_tot  + bancomat_tot + prelievi_tot + visa_tot + carburante_tot + addImposta).toFixed(2);
				document.getElementById('totale1').innerHTML = String(total).replace(/[\.]/g,",");
				}

				function showHidePopup (id,show) {
					if(show==1)  $('#'+id).fadeIn("slow");
					if(show==0)  $('#'+id).fadeOut("slow");
				}
				
				function DisplayPopup(popurl,popname,winprops)
{
	winpopup = window.open(popurl,popname,winprops);
	
	if (winpopup==null)
	{
		//##ING_COMMENT alert("Le impostazioni del browser che stai utilizzando non consentono l'apertura\ndei pop-up: per navigare correttamente nel nostro sito, abilita i pop-up\ndel tuo browser (Opzioni Internet / Privacy).");	
		document.location.href='/ErrBlPopup.stm';
  	}
  	else
  	{
		winpopup.window.focus();
	}
	return winpopup;
}
