function checkcampiobbligatori(form, testoallert)
{

  var risultato = true;
  var vuotieobbligatori = new Array();
  $$('input[class^=obbligatorio]', 'select[class^=obbligatorio]', 'textarea[class^=obbligatorio]','checkbox[class^=obbligatorio]','radio[class^=obbligatorio]').each(function(el)
  {
    if (($(el).type == "text")&&($(el).value == ""))
    {
      vuotieobbligatori.push($(el).name);
    }
    if (($(el).type == "textarea")&&($(el).value == ""))
    {
      vuotieobbligatori.push($(el).name);
    }
    if (($(el).type == "select-one")&&($(el).value == ""))
    {
      vuotieobbligatori.push($(el).name);
    }
    if ($(el).type == "radio")
    {
      if (!(controlcheckbox($(el).name))){
        vuotieobbligatori.push($(el).name);
      }
    }
    if ($(el).type == "checkbox")
    {
      if (!(controlcheckbox($(el).name))){
        vuotieobbligatori.push($(el).name);
      }
    }
  })

  if (vuotieobbligatori.length > 0)
  {
    var msg = testoallert;
    for (i=0;i<=vuotieobbligatori.length;i++)
    {
      msg= msg + "-" + vuotieobbligatori[i];
    }
    alert(testoallert);
    return false;
  }
  else{
    return true;
  }
}

function controlcheckbox(x)
{
  var ok = false;
  $$('input[name='+x+']').each(function(ck)
      {
        if (ck.checked == true) ok = true;;
      })
  return ok;
}



function creacampinecessari(form)
{
  $("destinatario1").value = $("field_nazione1").value;
  $("destinatario2").value = $("field_nazione2").value;
  $("destinatarioringraziamento").value = $("field_email").value;
  if ($("riferimento").value != "")
  {
    $("oggetto1").value = $("riferimento").value + " - " + $("field_nome").value + " - " + $("field_cognome").value;
  }
  else{
    if($('field_areainteresse2')=='')
    {
      $("oggetto1").value = $("field_nome").value + " - " + $("field_cognome").value + " - " + $("field_areainteresse1").value;
    }
    else{
      $("oggetto1").value = $("field_nome").value + " - " + $("field_cognome").value + " - " + $("field_areainteresse1").value + " - " + $("field_areainteresse2").value;
    }
  }
  if ($("riferimento").value != ""){
    /*$("oggetto2").value = $("riferimento").value + " - " + $("inviocv").value;
     */
    $("oggetto2").value = $("inviocv").value;
  }
  else{
    $("oggetto2").value = $("inviocv").value;
  }
}

function creacampinecessarisimple(form)
{
   if($chk($('mailTo')))
   {
      if ($("mailTo").value != "")
      {
        var i = $("mailTo").value.indexOf("|");
        var l = $("mailTo").value.length;
        $("destinatario").value = $("mailTo").value.substring(0,i);
        $("oggetto").value = $("mailTo").value.substring(i+1,l);
      }
   }
}
