//news
function Serz() {
	var pachia = document.formx.pachia.value;
	var data = document.formx.data.value;
	if (((pachia == "") || (pachia == "undefined") || (pachia == "Parola chiave")) && ((data == "--") || (data == "undefined"))){
		alert("Per favore riempi almeno uno tra i campi Parola Chiave e Data.");
		document.formx.pachia.focus();
		return false;
	}
	else {
		document.formx.action = "news.php?do=cerca";
		document.formx.submit();
	}
}

//news
function ifEnter(field,event) {
	var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (theCode == 13){
		Serz();
		return false;
	}
	else
		return true;
}

//collezioni
function Ck(dest) {
	var qta = document.formo.qta.value;
	var destfin = dest;	
   	if ((qta == "") || (qta == "undefined")) {
		alert("Inserisci una quantità.");
		document.formo.qta.focus();
	}
	else {
	   document.formo.action = destfin;
	   document.formo.submit();
	}
}

//bottom
function ifEnterx(field,event) {
	var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (theCode == 13){
		document.forms['formx'].submit();
		return false;
	}
	else
		return true;
}

//ares
function Senda() {
	var utente = document.forma.utente.value;
	var password = document.forma.password.value;
	if ((utente == "") || (utente == "undefined") || (password == "") || (password == "undefined")) {
		alert("Riempi correttamente i campi Utente e Password.");
		document.forma.utente.focus();
	}
	else {
		document.forma.action = "ares.php?id=chk";
		document.forma.submit();
	}
  }

//ares
function ifEnterz(field,event) {
	var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (theCode == 13){
		Senda();
		return false;
	}
	else
		return true;
}

//ares
function Sendpw() {
	var email = document.formpw.email.value;
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if ((email == "") || (email == "undefined")) {
		alert("Il campo E-mail è obbligatorio.");
		document.formpw.email.focus();
		return false;
	}
	else if (!email_reg_exp.test(email)) {
		alert("Prego inserisca un'e-mail corretta, grazie.");
		document.formpw.email.focus();
		return false;
	}
	else {
		document.formpw.action = "ares.php?id=pdimok";
		document.formpw.submit();
	}
}

//ares
function Sendnewpw() {
	var pwdx = document.formpwx.pwdx.value;
	if ((pwdx == "") || (pwdx == "undefined")) {
		alert("Il campo Password è obbligatorio.");
		document.formpwx.email.focus();
		return false;
	}
	else {
		document.formpwx.action = "ares.php?id=pwmodok";
		document.formpwx.submit();
	}
}

//admin
function Mandap(dest) {
 var destfin = dest;
 var codice = document.formz.codice.value;
 var nome = document.formz.nome.value;
 var articolo = document.formz.articolo.value;
 var prezzo = document.formz.prezzo.value;
 var myre= /^\d+[,]{1}[0-9]{2}$/;
 var colori = document.formz.colori.value;
 var taglie = document.formz.taglie.value;
   if ((codice == "") || (codice == "undefined") || (codice == "codice modello")) {
	   alert("Il campo Codice modello è obbligatorio.");
	   document.formz.codice.focus();
	   return false;
	}
	else if ((nome == "") || (nome == "undefined") || (nome == "nome prodotto")) {
	   alert("Il campo Nome prodotto è obbligatorio.");
	   document.formz.nome.focus();
	   return false;
	}
	else if ((articolo == "") || (articolo == "undefined") || (articolo == "articolo")) {
	   alert("Il campo Articolo è obbligatorio.");
	   document.formz.articolo.focus();
	   return false;
	}
	else if ((prezzo == "") || (prezzo == "undefined") || (prezzo == "prezzo in euro,centesimi")) {
	   alert("Il campo Prezzo è obbligatorio.");
	   document.formz.prezzo.focus();
	   return false;
	}
	else if (!(myre.test(prezzo))) {
	   alert("Immettere un importo corretto nel formato X,YY");
	   return false;
	}
	else if ((colori == "") || (colori == "undefined") || (colori == "varianti colore")) {
	   alert("Inserire almeno un colore, anche se è l'unico disponibile.");
	   document.formz.colori.focus();
	   return false;
	}
	else if ((taglie == "") || (taglie == "undefined") || (taglie == "taglie disponibili")) {
	   alert("Inserire almeno una taglia disponibile; sì può anche scrivere: unica");
	   document.formz.taglie.focus();
	   return false;
	}
	else {
	   document.formz.action = destfin;
	   document.formz.submit();
	}
}

//admin
function Mandan() {
	 var data = document.formc.data.value;
	 var espressione = /^[0-9]{2}-[0-9]{2}-[0-9]{4}$/;
	 var titolo = document.formc.titolo.value;
	 var testo = document.formc.testo.value;
	   if ((data == "") || (data == "undefined")) {
		   alert("Il campo Data è obbligatorio.");
		   document.formc.data.focus();
		   return false;
		}
	    if (!espressione.test(data)) {
		   alert("Inserire una data corretta nel formato GG/MM/AAAA");
		   document.formc.data.focus();
		   return false;
		}
		else if ((titolo == "") || (titolo == "undefined") || (titolo == "titolo")) {
		   alert("Il campo Titolo è obbligatorio.");
		   document.formc.titolo.focus();
		   return false;
		}
		else if ((testo == "") || (testo == "undefined") || (testo == "testo")) {
		   alert("Il campo Testo è obbligatorio.");
		   document.formc.testo.focus();
		   return false;
		}
		else {
		   document.formc.action = "admin.php?id=newsok";
		   document.formc.submit();
		}
}

//admin
var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
	return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
	var pressedkey=/[a-zA-Z0-9\.\,\/]/
	if (pressedkey.test(String.fromCharCode(e.which)))
	e.stopPropagation()
	}
}

function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
	if (lengthleft<0)
	theform.value=theform.value.substring(0,maxlength)
	placeholderobj.innerHTML=lengthleft
	}
}

function displaylimit(theform,thelimit){
	if (thelimit==10) {thelimit=limite;}
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caratteri rimanenti'
	if (document.all||ns6)
	document.write(limit_text)
	if (document.all){
	eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
	eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
	}
	else if (ns6){
	document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
	document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
	}
}

//admin
function Mandad() {
	 var rag = document.formd.rag.value;
	 var citta = document.formd.citta.value;
	    if ((rag == "") || (rag == "undefined") || (rag == "ragione sociale")) {
		   alert("Il campo Ragione sociale è obbligatorio.");
		   document.formd.rag.focus();
		   return false;
		}
		else if ((citta == "") || (citta == "undefined") || (citta == "cap, città e provincia")) {
		   alert("Inserire almeno la città del punto di distribuzione.");
		   document.formd.citta.focus();
		   return false;
		}
		else {
		   document.formd.action = "admin.php?id=distok";
		   document.formd.submit();
		}
}	

//f_lib
function Mandat(dest) {
 	 var destfin = dest; 	 
	 var rag = document.modreg.rag.value;
	 var ind = document.modreg.ind.value;
	 var nciv = document.modreg.nciv.value;	 
	 var cap = document.modreg.cap.value;
	 var citta = document.modreg.citta.value;
	 var prov = document.modreg.prov.value;	 
	 var tel = document.modreg.tel.value;
	 var mail = document.modreg.mail.value;
	 var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	 var iva = document.modreg.iva.value;
	 var cf = document.modreg.cf.value; 
	 var pri = document.modreg.pri.checked;
	 if ((rag == "") || (rag == "undefined")) {
		alert("Riempi correttamente il campo Ragione Sociale.");
		document.modreg.rag.focus();
	 }
	 else if ((ind == "") || (ind == "undefined")) {
		alert("Riempi correttamente il campo Indirizzo.");
		document.modreg.ind.focus();
	 }
	 else if ((nciv == "") || (nciv == "undefined")) {
		alert("Riempi correttamente il campo N°Civico.");
		document.modreg.nciv.focus();
	 }	 
	 else if ((cap == "") || (cap == "undefined")) {
		alert("Riempi correttamente il campo Cap.");
		document.modreg.cap.focus();
	 }
	 else if ((citta == "") || (citta == "undefined")) {
		alert("Riempi correttamente il campo Città.");
		document.modreg.citta.focus();
	 }
	 else if ((prov == "") || (prov == "undefined")) {
		alert("Riempi correttamente il campo Provincia.");
		document.modreg.prov.focus();
	 }	 
	 else if ((tel == "") || (tel == "undefined")) {
		alert("Riempi correttamente il campo Telefono.");
		document.modreg.tel.focus();
	 }
	 else if ((mail == "") || (mail == "undefined")) {
		alert("Riempi correttamente il campo E-mail.");
		document.modreg.mail.focus();
	 }
     	 else if (!email_reg_exp.test(mail)) {
	        alert("Inserisci un'e-mail corretta, grazie.");
	        document.modreg.mail.focus();
	 }
	 else if ((iva == "") || (iva == "undefined")) {
		alert("Riempi correttamente il campo Partita Iva.");
		document.modreg.iva.focus();
	 }
	 else if ((cf == "") || (cf == "undefined")) {
		alert("Riempi correttamente il campo Codice Fiscale.");
		document.modreg.cf.focus();
	 }
	 else if (pri!=true) {
		alert("Accetta il trattamento dei dati personali.");
		document.modreg.pri.focus();
	 }
	 else {
		document.modreg.action = destfin;
		document.modreg.submit();
	 }
}