function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_checked(field,alerttxt)
{
with (field)
  {
  if (! checked)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_email(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="") {return true;}
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}
function validate_select(field,alerttxt)
{
with (field)
  {
  if (value==0)
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function annunci_compat(thisform)
{
with (thisform)
  {
  var compat="";
  
  var str=tipo.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str;
  
  str=cosa.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str; 
 
  str=titolo.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str; 

  str=testo.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str;  

  str=telefono.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str;  

  str=email.value;
  str=str.replace(/#/g,"");
  compat=compat+"#"+str;    
  
  comment.value=compat;
  // alert("compat="+compat);
  }
}

function annunci_post_ID(thisform)
{
with (thisform)
  {
  var postID=comment_post_ID.value;
  var sceltacosa=cosa.value;
  if (sceltacosa == "casa") { postID=3;}
  else if (sceltacosa == "auto/moto") {postID=8;}
  else if (sceltacosa == "bici") {postID=15;}
  else if (sceltacosa == "mobili") {postID=18;}
  else if (sceltacosa == "altro") {postID=20;}
  else if (sceltacosa == "lavoro") {postID=58;}
  comment_post_ID.value=postID;
  // alert("postID="+postID);
  }
}

function validate_form_annunci(thisform)
{
with (thisform)
  {
   if (validate_select(tipo,"Devi scegliere il tipo di annuncio!")==false)
  {tipo.focus();return false;} 
   if (validate_select(cosa,"Devi scegliere la categoria!")==false)
  {cosa.focus();return false;}  
   if (validate_required(titolo,"Hai dimenticato di inserire il titolo dell'annuncio!")==false)
  {titolo.focus();return false;}  
   if (validate_required(testo,"Hai dimenticato di inserire il testo dell'annuncio!")==false)
  {testo.focus();return false;}  
  if (validate_email(email,"Inserisci un contatto e-mail valido!")==false)
  {email.focus();return false;}
  
  if (validate_checked(disclaimer_accept,"Per pubblicare l'annuncio devi accettare l'informativa sulla privacy e le regole del sito. Leggile bene prima di accettare!")==false)
  {disclaimer_accept.focus();return false;}
  }
  annunci_post_ID(thisform);  
  annunci_compat(thisform);  
  return true;
  
}


