
function popupPage(URL,w,h) {
  var windowprops =
  "location=no,menubars=no,scrollbars=yes,resizable=yes"
  + ",left=" + 100 + ",top=" + 100 + ",width=" + w + ",height=" + h;

  popup = window.open(URL,"help",windowprops);
}


function notvalidnum(field) {
 var valid = "0123456789" ;
 var ok = "yes";
 var temp;
 for (var i=0; i<field.value.length; i++) {
  temp = "" + field.value.substring(i, i+1);
  if (valid.indexOf(temp) == "-1") ok = "no";
   }
  if (ok == "no") {
     return(true)
   }
  else {
     return(false)
   }
}


function chklength(textarea,counter) {
 var nchar = textarea.value.length;
 var maxchar = 400;

  if (nchar > maxchar ) {
    textarea.value = textarea.value.substring(0,maxchar);
   charfree = 0;
   } else {
    charfree = maxchar-nchar;
   }
  counter.value = charfree;

}

function notvalidtxt(field) {

 var valid = "+-=/òàèìùABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,;:?!'`()\n\r " ;
 var ok = "yes";
 var temp;
 for (var i=0; i<field.value.length; i++) {
  temp = "" + field.value.substring(i, i+1);
  if (valid.indexOf(temp) == "-1") ok = "no";
   }
  if (ok == "no") {
     return(true)
   }
  else {
     return(false)
   }
 
  //if (ok == "no") {
  // alert("Inserimento non valido! Solo caratteri, numeri e + - = / ò à è ì ù ( ) . , ; : ? ! ' `  sono accettati!");
  // field.focus();
  // field.select();
  //  return(false);
  // }
}



function FormValidator(theForm)
{
 
 if (theForm.CONTATTO.value == "" )
  {
    alert("Inserire un nome in \"Nome:\"");
    theForm.CONTATTO.focus();
    return (false);
  }

 if (theForm.TPREF.value == "" || notvalidnum(theForm.TPREF)  )
  {
    alert("Inserire un prefisso telefonico senza separatori in \"Telefono:\"");
    theForm.TPREF.focus();
    return (false);
  }


 if (theForm.TNUM.value == "" || notvalidnum(theForm.TNUM) )
  {
    alert("Inserire un numero di telefono senza separatori in \"Telefono:\"");
    theForm.TNUM.focus();
    return (false);
  }

 if (theForm.PWD1.value == "" )
  {
    alert("Inserire una password in \"Password:\"");
    theForm.PWD1.focus();
    return (false);
  }

 if (theForm.PWD2.value == "" )
  {
    alert("Inserire una password in \"Password:\"");
    theForm.PWD2.focus();
    return (false);
  }


 if (theForm.PWD1.value != theForm.PWD2.value  )
  {
    alert("La password differisce nei 2 campi in \"Password:\"");
    theForm.PWD1.focus();
    return (false);
  }

 if (theForm.VENDOCERCO.selectedIndex == 0 )
  {
    alert("Selezionare un valore in \"Vendo/Cerco:\"");
    theForm.VENDOCERCO.focus();
    return (false);
  }

 if (theForm.COSA.selectedIndex == 0 )
  {
    alert("Selezionare un valore in \"Cosa:\"");
    theForm.COSA.focus();
    return (false);
  }


 if ( notvalidnum(theForm.PREZZO)  )
  {
    alert("Inserire un valore numerico senza separatori in \"Prezzo:\"");
    theForm.PREZZO.focus();
    return (false);
  }

 if ( notvalidnum(theForm.VOLUME)  )
  {
    alert("Inserire un valore numerico senza separatori in \"Volume:\"");
    theForm.VOLUME.focus();
    return (false);
  }

 if ( notvalidnum(theForm.LUNG)  )
  {
    alert("Inserire un valore numerico senza separatori in \"Lunghezza:\"");
    theForm.LUNG.focus();
    return (false);
  }



 if (theForm.ANNUNCIO.value == "" )
  {
    alert("Selezionare un valore in \"Annuncio:\"");
    theForm.ANNUNCIO.focus();
    return (false);
  }

 if ( notvalidtxt(theForm.ANNUNCIO) )
  {
    alert("Inserimento non valido! Solo caratteri, numeri e + - = / ò à è ì  ( ) . , ; : ? ! ' `  sono accettati in \"Annuncio:\"!");
    theForm.ANNUNCIO.focus();
    return (false);
  }


    return (true);
}
// End validator.



