﻿function sendEmail(encodedEmail)
{
  // do the mailto: link
  location.href = "mailto:" + decodeEmail(encodedEmail);
}

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 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 writeEditorPlayList( sPlayList )
{
    document.write('<div id="mp3player_mp3playercontent">')
	document.write('</div>')
	var so = new SWFObject("/mp3/ep_player.swf", "ep_player", "246", "115", "9", "#FFFFFF");
	so.addVariable("key", "F82Q5J0NCFI6JLLINI53");
	so.addVariable("skin", "/mp3/skins/mshome/skin.xml");
	so.addVariable("playlist", sPlayList);
	so.addVariable("autoplay", "true");
	so.addVariable("shuffle", "false");
	so.addVariable("repeat", "false");
	so.addVariable("buffertime", "1");
	so.write("mp3player_mp3playercontent");
}

function showModalWindow(title, h, w, contentId) {
    tb_show(title, '#TB_inline?height=' + h + '&width=' + w + '&inlineId=' + contentId + '&modal=true', null);
}

function confermaVotoBranoConcorso(sUrl,sID,sTitolo) {
    sUrlBranoDaVotare = sUrl;
	sIDBranoDaVotare = sID;
	var oSpan = document.getElementById('spannomebrano');
    if (oSpan) oSpan.innerHTML=sTitolo;	
    showModalWindow('Conferma voto brano', 200, 200, 'confermaVotaBrano');
}

function votaArticoloConcorso() {
    jx.load(sUrlBranoDaVotare, cbVotaArticoloConcorso);
}

function cbVotaArticoloConcorso(data) {
    if (data.length > 0) {
        if (data!='-1') {
			if (data=='3') {
	            for (i = 0; i < aIDVotaBrani.length; i++) {
	                var oDiv = document.getElementById(aIDVotaBrani[i]);
	                if (oDiv) oDiv.style.display = 'none';
	            }
			  }
            else {
			  var oDiv = document.getElementById(sIDBranoDaVotare);
	          if (oDiv) oDiv.style.display = 'none';
			  }	
            alert('Grazie per aver dato il tuo voto');
            tb_remove();
        }
        else alert('Si è verificato un errore durante il tentativo di voto.');
    }
    window.location.reload();
}

function confermaSegnalazioneBranoConcorso(sID, sUrl, sTitolo) {
    sIDBranoDaSegnalare = sID;
	sUrlBranoDaSegnalare = sUrl;
	var oSpan = document.getElementById('spannomebrano');
    if (oSpan) oSpan.innerHTML=sTitolo;
    showModalWindow('Conferma segnalazione brano', 200, 200, 'confermaSegnalaBrano');
}

function segnalaBranoConcorso() {
	jx.load(sUrlBranoDaSegnalare, cbSegnalaBranoConcorso);
}

function cbSegnalaBranoConcorso(data) {
    if (data.length > 0) {
        if (data == '1') {
            for (i = 0; i < aIDImgSegnalaBrano.length; i++) {
                var oDiv = document.getElementById('segnalaconcorso' + aIDImgSegnalaBrano[i]);
                if (oDiv) oDiv.innerHTML = '';
            }
			var oDiv = document.getElementById('segnalaconcorso' + sIDBranoDaSegnalare);
			if (oDiv) oDiv.innerHTML = 'Brano segnalato!';
            tb_remove();
        }
        else alert('Si è verificato un errore durante il tentativo di voto.');
    }
}