﻿var sendemail;//fn()
var decodeEmail;//fn()
var paging;//fn()
var pagingCalendario;//fn()
var autoPostSelect;//fn()
var SelezionaMeseCalendario;//fn()
var votaArticolo;//fn()
var CaricaMonoSlideShow;//fn()
var regUtente_sistemaElencoServizi;//fn()
var pubblicaCommento;//fn()
var spubblicaCommento;//fn()
var eliminaCommento;//fn()
var ButtonImage; //fn()
var ShowHideAnimated; //fn()
var thisMovie; //Object()
var PFGoLeft; //fn()
var PFGoRight; //fn()
var PRSetSearchFilter; //fn()
var initPictureFlow = function(id,arr){
	// Middle item at start
	var player = document.getElementById(id);
	if (!player || !player.refeed)
		setTimeout("initPictureFlow('" + id + "','" + arr + "')", 500);
	else{
		var iShow = Math.floor(eval(arr).length/2)+1;
		player.refeed(eval(arr),iShow);
	}
};
(function($){
	var ____regUtente_dipendeDa = new Array();
	
	sendemail = function(encodedEmail){
		// do the mailto: link
		location.href = "mailto:" + decodeEmail(encodedEmail);
	};
	// return the decoded email address
	decodeEmail = function(encodedEmail){
		// holds the decoded email address
		var email = "";
		// go through and decode the email address
		for(i=0; i < encodedEmail.length;){
			// holds each letter (2 digits)
			var letter = "";
			letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)
			// build the real email address
			email += String.fromCharCode(parseInt(letter,16));
			i += 2;
		}
		return email;
	};
	paging = function(id,i){
		$('#SubmitPaging').val('1');
		$('#PaginaCorrente').val(i);
		$('#'+id).submit();
	};
	pagingCalendario = function(id,i){
		$('#SubmitPagingCal').val('1');
		$('#PagingCorrenteCal').val(i);
		$('#'+id).submit();
	};
	autoPostSelect = function(oSelect){
		if(oSelect){
			var oForm = oSelect.form;
			if(oForm){
				var oHidden = document.getElementById(oSelect.id + '_autopost');
				if(oHidden)oHidden.value='1';
				oForm.submit();
			}
		}
	};
	SelezionaMeseCalendario = function(id,value){
		if(!document.getElementsByTagName)return;
		var tbf = document.getElementById(id);
		if(!tbf)return;
		for(var i=0;i<tbf.getElementsByTagName('span').length;i++){
			var spa = tbf.getElementsByTagName('span')[i];
			if(spa.className=='mesecorrente'){
				for(var k=0;k<spa.getElementsByTagName('input').length;k++){
					var inp = spa.getElementsByTagName('input')[k];
					if(inp)inp.checked=value;
				}
			}   
		}
	};
	votaArticolo = function(shRef){
		$.ajax({
			url:shRef,
			success:function(data){
				if(data.length > 0){
					var aData = data.split(',');
					var sSel = '';
					if(parseInt(aData[1])==-1) alert('E\' possibile votare solamente una volta al giorno.');
					else if(parseInt(aData[1])>=0)alert('Grazie per aver votato.');
					var ulVoti = document.getElementById('votaarticoloul');
					if(ulVoti)ulVoti.className='sel' + data[0];
					for(i=1;i<=5;i++){
						var liVoto = document.getElementById('votaarticolo'+i);
						if(liVoto){
							sSel = '';
							if(data[0]==i)sSel=' sel';
							liVoto.className='mediavoti'+i+sSel;
						}
					}
				}
			}
		});
	};
	CaricaMonoSlideShow = function(xmlurl,container,width,height){
		var flashvars = {showLogo:'false',dataFile:xmlurl};
		var params = {allowScriptAccess:'sameDomain',allowfullscreen:'true',allowNetworking:'all'};
		var attributes = {id:'monoslideshow',name:'monoslideshow',bgColor:'FFFFFF'};
		swfobject.embedSWF(defaultPath+'swf/monoslideshow.swf', container, (width||"532"), (height||"502"), "9", false, flashvars, params, attributes);
	};
	pubblicaCommento = function(sUrl,sGuid){
		$.post(sUrl,{azione:'pubblica',guid:sGuid},function(data){
			if (data=='1') {
				$('#pubblica-' + sGuid ).hide();
				$('#spubblica-' + sGuid ).show();
				alert('Il commento e\' stato pubblicato');
			}
		});
	};
	spubblicaCommento = function(sUrl,sGuid){
		$.post(sUrl,{azione:'spubblica',guid:sGuid},function(data){
			if (data=='1') {
				$('#spubblica-' + sGuid ).hide();
				$('#pubblica-' + sGuid ).show();
				alert('Il commento e\' stato spubblicato');
			}
		});
	};
	eliminaCommento = function(sUrl,sGuid){
		if(confirm('Cancellare il commento?')){
			$.post(sUrl,{azione:'elimina',guid:sGuid},function(data){
				if(data!='0'){
					$('#commento-'+sGuid).remove();
					$('#quanti-commenti').html(data);
					alert('Commento cancellato')
				}
			});
		}
	};
	regUtente_sistemaElencoServizi = function(){
		$('#elencoservizi').find(':input').each(function(i){
			if((this.type!='hidden')&&(this.name.indexOf('-disabled')<0)&&(!this.checked))$('#servizio-'+this.value).hide();	
		});
		$('#elencoservizi input:checkbox').click(function(){
			if((____regUtente_dipendeDa[$(this).val()])&&($(this).get(0).checked)){
				if(!($('#elencoservizi input:checkbox[value='+____regUtente_dipendeDa[$(this).val()][0] + ']').get(0).checked)){
					alert('E\' necessario iscriversi anche al servizio '+____regUtente_dipendeDa[$(this).val()][1]);
					return false;
				}
			}
			if(!($(this).get(0).checked)){
				for(sKey in ____regUtente_dipendeDa){
					if(____regUtente_dipendeDa[sKey][0]==$(this).val()){
						$('#elencoservizi input:checkbox[value='+sKey+']').attr('checked','');
						$("#servizio-"+sKey).hide('fast'); 
					}
				}
			}	
			$("#servizio-"+$(this).val()).toggle('fast'); 
		});
	};
	ButtonImage = function(id,quale){
		var tbf = $('#'+id);
		if(tbf.length){
			tbf.find('input[type="submit"],input[type="button"]').each(function(i,v){
				$(v).addClass('be-gone').parent().append(
					$('<a/>',{'title':$(v).val(),'href':'#'}).append($('<img/>',{'src':defaultPath+'img/buttons/application_'+$(v).val().toLowerCase()+'.gif','alt':$(v).val()})).click(function(){
						$(v).click()
					})
				)
			})
		}
	};
	history.navigationMode = 'compatible';
	$(function(){
		//run the currently selected effect
		ShowHideAnimated = function (){         
			//run the effect
			$("li.menuconsorzio").toggle("blind",{direction:"horizontal"},500);
			return false;
		};
		PFGoLeft = function(movieName){
			document.getElementById(movieName).navig(-1);
			return false;
		};
		PFGoRight = function(movieName){
			document.getElementById(movieName).navig(+1);
			return false;
		};
		var setClassDisabled = function(o,set){
			if(o.is('input'))o=o.closest('li.radio');
			set?o.addClass('disabled'):o.removeClass('disabled');
		};
		var setFilter = function(sel,arr,col){
			setClassDisabled($(sel+'[value!="0"]').attr('disabled','disabled'),true);
			$.each(arr,function(i,v){setClassDisabled($(sel+'[value="'+v.charAt(col)+'"]').removeAttr('disabled'),false)});
		};
		var filterSearch = function(){
			var portata = $('#frmRicercaRicettaParmigiano .portata select').val();
			var stagionatura = $('#frmRicercaRicettaParmigiano .stagionatura input:checked').val();
			var difficolta = $('#frmRicercaRicettaParmigiano .difficolta input:checked').val();
			
			var tmp = $.grep(PRSearchFilter.elem,function(v,i){
				return ((v.charAt(PRSearchFilter.charindex.portata)==portata||portata=='0')&&(v.charAt(PRSearchFilter.charindex.stagionatura)==stagionatura||stagionatura=='0')&&(v.charAt(PRSearchFilter.charindex.difficolta)==difficolta||difficolta=='0'))
			});
			
			if(portata=='0')setFilter('#frmRicercaRicettaParmigiano .portata select option',tmp,PRSearchFilter.charindex.portata);
			if(stagionatura=='0')setFilter('#frmRicercaRicettaParmigiano .stagionatura input',tmp,PRSearchFilter.charindex.stagionatura);
			if(difficolta=='0')setFilter('#frmRicercaRicettaParmigiano .difficolta input',tmp,PRSearchFilter.charindex.difficolta);
		};
		// Document Ready
		var shadowBoxMimeMap =
		{
			img: ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'aspx'],
			swf: ['swf'],
			flv: ['flv', 'm4v', 'mp4'],
			qt: ['dv', 'mov', 'moov', 'movie', 'mp4'],
			wmp: ['asf', 'wm', 'wmv'],
			qtwmp: ['avi', 'mpg', 'mpeg'],
			iframe: ['asp', 'aspx', 'cgi', 'cfm', 'htm', 'html', 'pl', 'php', 'php3', 'php4', 'php5', 'phtml', 'rb', 'rhtml', 'shtml', 'txt', 'vbs', 'java']
		};
		Shadowbox.init({
			language: 'it',
			continuous: true,
			players: ['img','iframe'],
			ext: shadowBoxMimeMap
		});
		Shadowbox.setup("#areainternational #cinese", {gallery: 'international'});
		$("tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
		$("tr:odd").addClass("odd");
		$("#contenttext .risultato_ricerca ul.elencorisultati li").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
		$("#menutopwrap ul li").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
		$('#menutopparmigiano ul.categorie').superfish({ 
			delay:       1000,                            // one second delay on mouseout 
			animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
			speed:       'fast',                          // faster animation speed 
			autoArrows:  false,                           // disable generation of arrow mark-up 
			dropShadows: false                            // disable drop shadows 
		});
		$('#frmRicercaRicettaParmigiano #txtParolaChiave').attr('placeholder',(codLingua=='it'?'parole chiave':'keywords')).addPlaceholder();
		if($('#newsflash ul').length)$('#newsflash ul').after('<div id="cyclepager">').cycle({fx:'scrollLeft',speed:1000,timeout:8000,pager:'#cyclepager'});
		//Cerca Ricette
		$('#frmRicercaRicettaParmigiano .portata select').change(function(){filterSearch()});
		$('#frmRicercaRicettaParmigiano .stagionatura input').click(function(){filterSearch()});
		$('#frmRicercaRicettaParmigiano .difficolta input').click(function(){filterSearch()});
		$('#frmRicercaRicettaParmigiano li.submit').append($('<button/>',{'id':'reset','class':'reset','type':'button'}).text('Vuota la ricerca').click(function(){
			$('#frmRicercaRicettaParmigiano .portata select option[value="0"]').attr('selected','selected');
			$('#frmRicercaRicettaParmigiano .stagionatura input[value="0"],#frmRicercaRicettaParmigiano .difficolta input[value="0"]').attr('checked','checked');
			filterSearch();
		}));
	});
})(jQuery);

