function localePopUp()
{
  // apre la finestra popup-locale.php per l'elenco dei locali
  open('popup-locale.php','','width=200,height=250,location=no');
}

function bandPopUp()
{
  // apre la finestra popup-band.php per l'elenco delle band
  open('popup-band.php','','width=200,height=250,location=no');
}

function eventoPopUp(year, month, day, a1, a2, a3, a4, a6, b1, c1, c2, c3, c4, c5)
{
  // apre una finestra per visualizzare gli eventi del giorno passato per parametri
  // lo sa veronica
  open('popup-evento.php?y='+year+'&m='+month+'&d='+day+'&a1='+a1+'&a2='+a2+'&a3='+a3+'&a4='+a4+'&a6='+a6+'&b1='+b1+'&c1='+c1+'&c2='+c2+'&c3='+c3+'&c4='+c4+'&c5='+c5,'','width=500,height=250,location=no');
}

function checkAddBandForm()
{
  // controlla all'inserimento dei dati della band che siano presenti e corretti
  with (window.document.forms[0])
  {
    if (window.document.forms[0].nome.value == "")
    {
      alert("Devi inserire il nome della band");
      window.document.forms[0].nome.focus();
      return;
    }
    if (window.document.forms[0].sito.value == "")
    {
      var answer = confirm ("Non hai inserito il sito della band.\nDesideri continuare lo stesso?")
      if (answer)
        submit();
      else
      {
        window.document.forms[0].sito.focus();
        return;
      }
    }
    else
      submit();
  }
}

function checkAddUserForm()
{
  // controlla all'inserimento dei dati per registrarsi, che siano corretti
  with (window.document.forms[0])
  {
    if (window.document.forms[0].nome.value == "")
    {
      alert("Devi inserire lo username");
      window.document.forms[0].nome.focus();
      return;
    }
    else if (window.document.forms[0].pass.value == "")
    {
      alert("Devi impostare una password");
      window.document.forms[0].pass.focus();
      return;
    }
    else if (window.document.forms[0].pass.value != window.document.forms[0].pass2.value)
    {
      alert("Le password non coincidono");
      window.document.forms[0].pass.value = "";
      window.document.forms[0].pass2.value = "";
      window.document.forms[0].pass.focus();
      return;
    }
    else if (window.document.forms[0].mail.value == "")
    {
      alert("Non hai inserito la mail")
      window.document.forms[0].mail.focus();
    }
    else
      submit();
  }
}

function checkAddEventForm()
{
  with (window.document.forms[0])
  {
    if (window.document.forms[0].hour.value == "")
    {
      alert("Non hai selezionato l'ora");
      window.document.forms[0].hour.focus();
    }
    else if (window.document.forms[0].moreHour.checked)
    {
      if (window.document.forms[0].hour_end.value == "")
      {
        alert("Non hai selezionato l'ora di fine");
        window.document.forms[0].hour_end.focus();
      }
      else if (document.getElementById('hour2_start').style.visibility == "visible")
      {
        if (window.document.forms[0].hour2.value == "")
        {
          alert("Non hai selezionato l'ora");
          window.document.forms[0].hour2.focus();
        }
        else if (window.document.forms[0].hour2_end.value == "")
        {
          alert("Non hai selezionato l'ora di fine");
          window.document.forms[0].hour2.focus();
        }
        else
          submit();
      }
      else
        submit();
    }
    else
      submit();
  }
}

function initCalColor()
{
  // inizializza i colori del calendario
  document.color.a1.value = 'ffffcc';
  document.color.a2.value = '336699';
  document.color.a3.value = 'ffcc00';
  document.color.a4.value = 'ffcc00';
  document.color.a5.value = 'ffe680';
  document.color.a6.value = 'ffcc00';
  document.color.fontSel.value = 'Arial';
  document.color.c1.value = 'ffffff';
  document.color.c2.value = '000000';
  document.color.c3.value = '000000';
  document.color.MonthSize.value = '18';
  document.color.WeekSize.value = '12';
  document.color.DaySize.value = '12';
  updateURL();
}

function updateURL()
{
  // crea il l'URL per il calendario
  var url = "http://www.gengisdave.org/evcl/evcl.php?mode=mini";
  url += "&a1=" + document.color.a1.value;
  url += "&a2=" + document.color.a2.value;
  url += "&a3=" + document.color.a3.value;
  url += "&a4=" + document.color.a4.value;
  url += "&a5=" + document.color.a5.value;
  url += "&a6=" + document.color.a6.value;
  url += "&b1=" + document.color.fontSel.value;
  url += "&c1=" + document.color.c1.value;
  url += "&c2=" + document.color.c2.value;
  url += "&c3=" + document.color.c3.value;
  url += "&d1=" + document.color.MonthSize.value;
  url += "&d2=" + document.color.WeekSize.value;
  url += "&d3=" + document.color.DaySize.value;
  document.color.url.value = url;
}

function rgbToHex (value)
{
  // converte il valore value dal formato rgb (xx, xx, xx) al formato web esadecimale
  var result = value.match(/^\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*/);
  var rgb = +result[1] << 16 | +result[2] << 8 | +result[3];
  var hex = "";
  var digits = "0123456789abcdef";
  while (rgb != 0)
  {
    hex = digits.charAt(rgb&0xf) + hex;
    rgb >>>= 4;
  }
  while (hex.length < 6)
  {
    hex = '0' + hex;
  }
  return "#" + hex;
}

function $style(ElementId, CssProperty)
{
  // legge la proprieta' CSS CssProperty dell'oggetto ElementId
  var x = document.getElementById(ElementId);

  if (x.currentStyle)
    return x.currentStyle[CssProperty];
  else if (window.getComputedStyle)
    return document.defaultView.getComputedStyle(x,null).getPropertyValue(CssProperty);
}

function changeA1()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a1.value);
}

function changeA2()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a2.value);
}

function changeA3()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a3.value);
}

function changeA4()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a4.value);
}

function changeA5()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a5.value);
}

function changeA6()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.a6.value);
}

function changeB1()
{
  $('.bg').css('fontFamily', document.color.fontSel.value); 
  updateURL();
}

function changeC1()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.c1.value);
}

function changeC2()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.c2.value);
}

function changeC3()
{
  $('#colorpickerHolder2').ColorPickerSetColor(document.color.c3.value);
}

function changeD1()
{
  $('.bgMonth').css('fontSize', document.color.MonthSize.value + 'px');
  updateURL();
}

function changeD2()
{
  $('.bgWeek').css('fontSize', document.color.WeekSize.value + 'px');
  updateURL();
}

function changeD3()
{
  $('.bgDayNone').css('fontSize', document.color.DaySize.value + 'px');
  $('.bgDay').css('fontSize', document.color.DaySize.value + 'px');
  $('.bgDayLin').css('fontSize', document.color.DaySize.value + 'px');
  updateURL();
}

function changeText()
{
  if (document.form.moreDay.checked)
  {
    document.getElementById('data_start').innerHTML = 'Data inizio spettacolo';
    document.getElementById('data_end_text').style.visibility = 'visible';
    document.getElementById('data_end').style.visibility = 'visible';
  }
  else
  {
    document.getElementById('data_start').innerHTML = 'Data spettacolo';
    document.getElementById('data_end_text').style.visibility = 'hidden';
    document.getElementById('data_end').style.visibility = 'hidden';
  }
}

function ShowMoreHour()
{
  document.getElementById('hour2_start_text').innerHTML = 'Ora inizio spettacolo:';
  document.getElementById('hour2_start').style.visibility = 'visible';
  document.getElementById('hour2_end_text').style.visibility = 'visible';
  document.getElementById('hour2_end').style.visibility = 'visible';
  document.getElementById('ShowHour').innerHTML = '<input type="button" value="-" onclick="HideMoreHour()">';
}

function HideMoreHour()
{
  document.getElementById('hour2_start_text').innerHTML = 'Aggiungi fascia oraria';
  document.getElementById('hour2_start').style.visibility = 'hidden';
  document.getElementById('hour2_end_text').style.visibility = 'hidden';
  document.getElementById('hour2_end').style.visibility = 'hidden';
  document.getElementById('ShowHour').innerHTML = '<input type="button" value="+" onclick="ShowMoreHour()">';
}

function changeHour()
{
  if (document.form.moreHour.checked)
  {
    document.getElementById('hour_start').innerHTML = 'Ora inizio spettacolo';
    document.getElementById('hour_end_text').style.visibility = 'visible';
    document.getElementById('hour_end').style.visibility = 'visible';
    document.getElementById('hour2_start_text').style.visibility = 'visible';
    document.getElementById('ShowHour').style.visibility = 'visible';
  }
  else
  {
    document.getElementById('hour_start').innerHTML = 'Ora spettacolo';
    document.getElementById('hour_end_text').style.visibility = 'hidden';
    document.getElementById('hour_end').style.visibility = 'hidden';
    document.getElementById('hour2_start_text').style.visibility = 'hidden';
    document.getElementById('hour2_start').style.visibility = 'hidden';
    document.getElementById('hour2_end_text').style.visibility = 'hidden';
    document.getElementById('hour2_end').style.visibility = 'hidden';
    document.getElementById('ShowHour').style.visibility = 'hidden';
    HideMoreHour();
  }
}
