﻿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);
}

// 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 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;
              }
       }   
    }
  }

var datiRegione = {};
var datiProduttore = {};
jQuery(function($) {
  var ShowHideSelect = function(o, s) {
    if (s) o.show().attr('vis', '1').removeAttr('disabled').css('color','menutext');
    else   o.hide().attr('vis', '0').attr('disabled','disabled').css('color','graytext');
  };
  var reg = $('#cmbRegione');
  var azi = $('#cmbAzienda');
  var eti = $('#cmbEtichetta');
  ShowHideSelect(reg.find('option'), true);
  var filterSelect = function(parent, child, dat, pfx) {
    ShowHideSelect(child.find('option'), false);
    ShowHideSelect(child.find('option[value=0]'), true);
    var key = pfx+parent.val();
    if (key == pfx+'0') {
      parent.find('option[vis=1]').each(function(i, v) {
        key = pfx+$(v).val();
        var list = dat[key];
        if (list) $.each(list, function(i, v){
          ShowHideSelect(child.find('option[value='+v+']'), true); });
      });
    } else {
      var list = dat[key];
      if (list) $.each(list, function(i, v){ ShowHideSelect(child.find('option[value='+v+']'), true); });
    }
    //if(child.find('option[value='+child.val()+']').attr('vis') == '0') child.val(0);
    //child.click();
  };
  if (jQuery.browser.msie){
	reg.change(function(){setTimeout(filterSelect(reg,azi,datiRegione,'r'),0)});
	azi.change(function(){setTimeout(filterSelect(azi,eti,datiProduttore,'p'),0)});
  }
  else{
	reg.change(function(){filterSelect(reg,azi,datiRegione,'r')});
	azi.change(function(){filterSelect(azi,eti,datiProduttore,'p')});
  }
});
