/*****************************************/
//MoCS.js 1.0b
// Modular Contacts Suite - Javascript gear
// by DWJ 2006 (CC-GNU GPL)
// dwjack/at/tin.it
//Published under CC-GNU GPL
//http://creativecommons.org/licenses/GPL/2.0/
/*****************************************/
//
//Form Verifier 3.1b
/**********************************************/
var errors = 0;
var formparser = "";
function checkmail (mail) {
var x = document.getElementsByName(mail)[0];
if (x.value !="") {
filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
if (filtro.test(x.value)) {
x.className ="validate";
	  } else {
x.className ="errore";
errors++;
}}}
function checkphone (phonefield) {
var x = document.getElementsByName(phonefield)[0];
if (x.value !="") {
if (x.value.indexOf("8")+x.value.indexOf("0")==-2) {
x.className ="errore";
errors++; }
else {
x.className ="validate";
}}}
function checknumbers (field,limit) {
var x = document.getElementsByName(field)[0];
var ren =new RegExp("[0-9]{"+limit+"}");
if (ren.test(x.value)==false && x.value !="") {
x.className ="errore";
errors++;
} else if (ren.test(x.value) && x.value !=""){
x.className ="validate";
}}
function checkletters (field,limit) {
var x = document.getElementsByName(field)[0];
var ren =new RegExp("[a-zA-Z]{"+limit+"}");
if (ren.test(x.value)==false && x.value !="") {
x.className ="errore";
errors++;
} else if (ren.test(x.value) && x.value !=""){
x.className ="validate";
}}
function checkbox (checkbox) {
var x = document.forms[0].elements;
for (i=0;i<x.length;i++) {
if (x[i].type == "checkbox" && x[i].name == checkbox && x[i].checked == false) {
x[i].className ="errore";
errors++;
} else if (x[i].type == "checkbox" && x[i].name == checkbox && x[i].checked == true) {
x[i].className ="validate";
}}}
function checkradio (radio)    {
var x = document.forms[0].elements;
var radiobuttons = 0;
for (i=0;i<x.length;i++) {
if (x[i].type == "radio" && x[i].name ==radio && x[i].checked==true ){
radiobuttons++;
}}
if (radiobuttons == 0){
}}
function redhighlight () {
var x = document.forms[0].elements;
for (i=0;i<x.length;i++) {
var classe = x[i].className;
var valore = document.forms[0].elements[i].value;
var stato = document.forms[0].elements[i].title;
var tipo = document.forms[0].elements[i].type;
var stile = document.forms[0].elements[i].style;
if (classe == "errore") {
x[i].style.background = "#FF5656";
} else if (classe == "validate") {
x[i].style.background = "#FFFFFF";
}}}
function verify() {
var x = document.forms[0].elements;
for (i=0;i<x.length;i++) {
var valore = x[i].value;
var campo = x[i].name;
var stato = x[i].title;
var tipo = x[i].type;
var stile = x[i].style;
if (stato=="obbligatorio") {
if (tipo == "text" && valore == '') {
x[i].className ="errore";
errors++;
} else if (tipo == "select-one" && valore == '') {
x[i].className ="errore";
errors++;
} else if (tipo == "textarea" && valore=="") {
x[i].className ="errore";
errors++;
} else {
x[i].className ="validate";
}}}}
function errorcheck (){
if (errors !=0){
redhighlight ();
alert ("Attenzione i campi in rosso sono mancanti o errati!");
errors = 0;
return false;
} else {
document.forms[0].action = formparser+"?check=1";
}}
