﻿var __regUtenteDipendenze = Array();

function sendemail(encodedEmail)
{
  // do the mailto: link
  location.href = "mailto:" + decodeEmail(encodedEmail);
}

// return the decoded email address
function decodeEmail(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;
}

function sendEmail(encodedEmail)
{
  // do the mailto: link
  location.href = "mailto:" + decodeEmail(encodedEmail);
}

function paging( sFormID, nPage )
{
    var oForm = document.getElementById(sFormID);
    var oPage = document.getElementById('PaginaCorrente');
    var oSubmitPaging = document.getElementById('SubmitPaging');
    if (oSubmitPaging) oSubmitPaging.value='1';
    if (oPage) oPage.value=nPage;
    if (oForm) oForm.submit();
}

function autoPostSelect( oSelect )
{
    if (oSelect)  {
        var oForm = oSelect.form;
        if (oForm) {
            var oHidden = document.getElementById(oSelect.id + '_autopost');
            if (oHidden) oHidden.value='1';
            oForm.submit();
                }
            }
}

function SelezionaMeseCalendario(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;
              }
       }   
    }
  }
  
function votaArticolo( shRef )
{
	$.ajax({
		  url: shRef,
		  success: function(data) {
					if(data.length > 0){
						var aData = data.split(',');
						var sSel = '';
						if (aData[1]=='-1') alert('E\' possibile votare solamente una volta al giorno.');
						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;
								}
							}
					}
		  }
		});
}

var ____regUtente_dipendeDa = new Array();
function regUtente_sistemaElencoServizi() {
	jQuery(function($){ 
		$('#elencoservizi').find(':input').each(function(i) {	
			if ((this.type!='hidden')&&(this.name.indexOf('-disabled')<0)&&(!this.checked))  {
				jQuery('#servizio-' + this.value).hide();	
				jQuery('.notelegali-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]);
					$('#elencoservizi input:checkbox[value=' + ____regUtente_dipendeDa[$(this).val()][0] + ']').attr('checked','checked');
					$("#servizio-" + ____regUtente_dipendeDa[$(this).val()][0]).show('fast'); 
					$('.notelegali-servizio-' + ____regUtente_dipendeDa[$(this).val()][0]).show('fast'); 
					}
				}
			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'); 
						$('.notelegali-servizio-' + sKey).hide('fast'); 
						};
					};
				};	
			$("#servizio-" + $(this).val()).toggle('fast'); 
			$('.notelegali-servizio-' +  $(this).val()).toggle('fast'); 
			return true;
		});
		$('#concorso-la-musica-libera-libera-la-musica_0002_0').click( function() { return regUtente_verificaConcorso(); } );
		$('#concorso-la-musica-libera-libera-la-musica_0002_1').click( function() { return regUtente_verificaConcorso(); } );
		$('#concorso-la-musica-libera-libera-la-musica_0003_0').click( function() { return regUtente_verificaConcorso(); } );
		$('#concorso-la-musica-libera-libera-la-musica_0003_1').click( function() { return regUtente_verificaConcorso(); } );
		regUtente_verificaConcorso();
	});
};

function regUtente_verificaConcorso() {

	$('#servizio-4 .fai-parte-di-un-associazione-di-emiliano-romagnoli-nel-mondo').hide();
	$('#servizio-4 ol li.combo').hide();
	$('#servizio-4 ol>li.ultimo').hide();
	
	if ( ($('#concorso-la-musica-libera-libera-la-musica_0002_1').is(':checked')) || ($('#concorso-la-musica-libera-libera-la-musica_0002_1').attr('type')=='hidden' && ($('#concorso-la-musica-libera-libera-la-musica_0002_1').val().toLowerCase()=='no')) ) {
		$('#servizio-4 .fai-parte-di-un-associazione-di-emiliano-romagnoli-nel-mondo').show();			
	}	
	else {	
		$('#concorso-la-musica-libera-libera-la-musica_0003_0').removeAttr('checked');
		$('#concorso-la-musica-libera-libera-la-musica_0003_1').removeAttr('checked');
		$('#servizio-4 ol li.combo option:[selected]').removeAttr('selected');
	};

	if ( ($('#concorso-la-musica-libera-libera-la-musica_0003_0').is(':checked')) || ($('#concorso-la-musica-libera-libera-la-musica_0003_0').attr('type')=='hidden' && ($('#concorso-la-musica-libera-libera-la-musica_0003_0').val().toLowerCase()=='si')) ) {
		$('#servizio-4 ol li.combo').show();			
	};	

	if ($('#concorso-la-musica-libera-libera-la-musica_0003_1').is(':checked')) {
		$('#servizio-4 ol li.combo option:[selected]').removeAttr('selected');
		$('#servizio-4 ol>li.ultimo').show();			
	};	

};
