Zapatec.Form.Validator.addDataType(
	'zpFormEMail',	  
	'EMail',    
	/(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.(([A-Za-z]{2,3})|(aero|coop|info|museum|name))$)/,
	" ",    
	"L'email deve essere nel formato nomeutente@nomedominio.abc",  
	null  
);

Zapatec.Form.Validator.addDataType(
	'zpFormUsername',	  
	'Nome utente',    
	/(^([0-9]|[A-Z]|[a-z]){1}([\@]|[0-9]|[A-Z]|[a-z]|[_\.\-]){7,32}$)/,
	"Nome utente non valido, da 8 a 32 caratteri",    
	"lunghezza minima 8 caratteri, massima 32; sono ammessi lettere, numeri e i caratteri @ _ . - (non all'inizio)",  
	null  
);	

Zapatec.Form.Validator.addDataType(
	'zpFormPassword',	  
	'Password',    
	/(^([0-9]|[A-Z]|[a-z]|[_\.\-\@*!$#]){8,32}$)/,
	"Password non valida",    
	"lunghezza minima 8 caratteri, massima 32; sono ammessi lettere, numeri e i caratteri _ . - @ * ! $ #",  
	null  
);	

Zapatec.Form.Validator.addDataType(
	'zpFormConsensoObbligato',	  
	'Consenso al trattamento',    
	null,
	"Il consenso al trattamento dei dati &egrave; obbligatorio",    
	"Il consenso al trattamento dei dati &egrave; obbligatorio",    
	testVal  
);	

function testVal(id) {
	return document.getElementById('consenso').checked
}

Zapatec.Form.Validator.addDataType(
	'zpFormData',	  
	'Data',    
	null,
	"Data non valida",    
	"La data indicata non è valida",    
	testData  
);	

Zapatec.Form.Validator.addDataType(
	'zpFormScadenza',	  
	'Data',    
	null,
	"Scadenza non valida: massimo 30 giorni<br>dalla data odierna, minimo 1",    
	"Scadenza non valida: massimo 30 giorni<br>dalla data odierna, minimo 1",    
	testScadenza  
);	

Zapatec.Form.Validator.addDataType(
	'zpFormScadenzaAdmin',	  
	'Data',    
	null,
	"Scadenza non valida: massimo 90 giorni<br>dalla data odierna, minimo 1",    
	"Scadenza non valida: massimo 90 giorni<br>dalla data odierna, minimo 1",    
	testScadenzaAdmin
);	

Zapatec.Form.Validator.addDataType(
	'zpFormCheckHiddenLoc',	  
	'Loc',    
	null,
	"Area geografica non valida",    
	"Area geografica non valida",    
	checkHiddenLoc  
);	
Zapatec.Form.Validator.addDataType(
	'zpFormCheckHiddenSet',	  
	'Loc',    
	null,
	"Settore merceologico non valido",    
	"Settore merceologico non valido",    
	checkHiddenSet  
);

function testData(e) {
	var now = new Date();
	var giorno=e.substr(0,2)*1
	var mese=e.substr(3,2)*1-1
	var anno=e.substr(6,4)*1
	var x = new Date(anno,mese,giorno)
	window.status= giorno+ ' ' +x.getDate() + ' ' + mese +' ' + x.getMonth() + ' ' + anno + ' ' + x.getFullYear()
	if (anno<1900) return false;
	if (anno>now.getFullYear()) return false;
	return giorno==x.getDate() && mese==x.getMonth() && anno==x.getFullYear()
}

function checkHiddenLoc(e) {
	var obj=document.getElementById('locID')
	if (obj.value == '') {
		return false;
	}
	return true;
}

function checkHiddenSet(e) {
	var obj=document.getElementById('setID')
	if (obj.value == '') {
		return false;
	}
	return true;
}

function testScadenza(e) {
	var giorno=e.substr(0,2)*1
	var mese=e.substr(3,2)*1-1
	var anno=e.substr(6,4)*1
	var x = new Date(anno,mese,giorno)
	var y = new Date()
	y.setHours(0,0,0,0)
	var diffdays = (x.getTime()-y.getTime())/(24*60*60*1000)
	if (diffdays > 30) {return false}
	if (diffdays < 1) {return false}
	window.status= diffdays
	return giorno==x.getDate() && mese==x.getMonth() && anno==x.getFullYear()
}

function testScadenzaAdmin(e) {
	var giorno=e.substr(0,2)*1
	var mese=e.substr(3,2)*1-1
	var anno=e.substr(6,4)*1
	var x = new Date(anno,mese,giorno)
	var y = new Date()
	y.setHours(0,0,0,0)
	var diffdays = (x.getTime()-y.getTime())/(24*60*60*1000)
	if (diffdays > 90) {return false}
	if (diffdays < 1) {return false}
	window.status= diffdays
	return giorno==x.getDate() && mese==x.getMonth() && anno==x.getFullYear()
}

Zapatec.Form.Validator.addDataType(
	'zpFormCAP',	  
	'CAP',    
	/(^([0-9]){5}$)/,
	"Cap non valido",    
	"Il CAP deve eassere di 5 caratteri",  
	null  
);	

Zapatec.Form.addDataType(
    'zpFormImageFile',
    'File immagine',
    /\.((g|G)(i|I)(f|F)|(p|P)(n|N)(g|G)|(j|J)(p|P)(g|G)|(j|J)(p|P)(e|E)(g|G))$/,
    "Sono accettati file immagine .gif .png .jpg .jpeg",
    "Sono accettati file immagine .gif .png .jpg .jpeg",
    null
);

Zapatec.Form.addDataType(
    'zpFormTextFile',
    'Documento di testo',
    /\.((d|D)(o|O)(c|C)|(p|P)(d|D)(f|F)|(d|D)(o|O)(c|C)(x|X)|(t|T)(x|X)(t|T))$/,
    "Sono accettati file .doc, .docx, .pdf, .txt",
    "Sono accettati file .doc, .docx, .pdf, .txt",
    null
);

Zapatec.Form.addDataType(
    'zpFormURL',
    'Indirizzo Web',
    /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/,
    "Inserire un indirizzo web valido, completo di http:// o https://",
    "Inserire un indirizzo web valido, completo di http:// o https://",
    null
);


if (typeof theme_form == 'undefined') { theme_form=''; }
Zapatec.Form.setupAll({
	showErrors: "afterField",
	showErrorsOnSubmit: true,
	//startupFocusPosition: "firstField",
	submitErrorFunc: showErrOutput,
	submitValidFunc: hideErrOutput,
	theme: theme_form,
	lang: "ita_it",
	langEncoding: "utf8"
	});
