//                ((( Paolo Marson email: p.marson@centroexpo.com  İ 2010  All Rights reserved )))
//ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

function initDate(dateType){ // imposta la data odierna come data inizio validità
	// İ 2010 Paolo Marson All Rights reserved
	var theForm = document.forms[document.nomeForm];
	var daySelect = theForm.elements['giorno'+dateType];
	var monthSelect = theForm.elements['mese'+dateType];
	var yearSelect = theForm.elements['anno'+dateType];

	var today = new Date();

	var dateElements = document.today.split('/');
	today.setDate(dateElements[0]);
	today.setMonth(parseInt(dateElements[1])-1);
	today.setFullYear(dateElements[2]);

	var day = today.getDate();
	var month = today.getMonth() + 1;
	var year = today.getFullYear()%2000 - 2;

	daySelect.selectedIndex = day;
	monthSelect.selectedIndex = month;
	yearSelect.selectedIndex = year;
}

//-------------------------------------------------------------------------------------------------------------

function datesManager(formName,startDaySelectName,startMonthSelectName,startYearSelectName,finishDaySelectName,finishMonthSelectName,finishYearSelectName){
	// İ 2010 Paolo Marson All Rights reserved
	var startDate = checkDate(formName,startDaySelectName,startMonthSelectName,startYearSelectName);
	if(!startDate){
		return false;
	}

	var finishDate = checkDate(formName,finishDaySelectName,finishMonthSelectName,finishYearSelectName);
	if(!finishDate){
		return false;
	}

	var compDates = compareDates(formName,startDaySelectName,startMonthSelectName,startYearSelectName,finishDaySelectName,finishMonthSelectName,finishYearSelectName);
	if(!compDates){
		return false;
	}

	return true;
}

//-------------------------------------------------------------------------------------------------------------

function validate(formName,mode){ /* valori per mode: 'required' o 'toVerify' */
	// İ 2010 Paolo Marson All Rights reserved
	var prefix = (mode=='required')?'obbl':'verif';
	var okForm = true;
	var report = '';
	var tempVal;
	var tempObj;
	var theForm = document.forms[formName];
	var okVerify = false;
	var okRequired = (mode=='required')?true:false;

	var req = eval(mode+'[\''+formName+'\']');

	if(req[prefix+'Testi']){
		var verTesti = req[prefix+'Testi'];
		var numVerTesti = verTesti.length;
		for(i=0; i<numVerTesti; i++){
			tempObj = theForm.elements[verTesti[i].split('|')[0]];
			if(!tempObj.disabled){
				tempVal = tempObj.value;
				if(mode=='toVerify'){
					okVerify = (tempVal=='')?false:true;
				}else{
					okVerify = false;
				}
				if(okVerify || okRequired){
					if(tempVal == ''){
						report = 'il campo\n' + verTesti[i].split('|')[1] + '\nnon è stato compilato correttamente';
						alert(report);
						if(!document.noFocusOggetto)
						{
							tempObj.focus();
						}
						okForm = false;
						if(mode=='required'){
							return false;
						}
					}
				}
			}
		}
	}

	if(req[prefix+'Email']){
		var verEmail = req[prefix+'Email'];
		var numVerEmail = verEmail.length;
		var re_Email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

		for(i=0; i<numVerEmail; i++){
			tempObj = theForm.elements[verEmail[i].split('|')[0]];
			if(!tempObj.disabled){
				tempVal = tempObj.value;
				if(mode=='toVerify'){
					okVerify = (tempVal=='')?false:true;
				}else{
					okVerify = false;
				}
				if(okVerify || okRequired){
					if(!re_Email.test(tempVal)){
						report = 'il campo\n' + verEmail[i].split('|')[1] + '\nè vuoto o non è stato compilato correttamente';
						alert(report);
						tempObj.focus();
						okForm = false;
						return false;
					}
				}
			}
		}
	}

	if(req[prefix+'Telefonici']){
		var verTelefonici = req[prefix+'Telefonici'];
		var numVerTelefonici = verTelefonici.length;
		var re_Telefonici = /^([0-9]+)$/;
//		var re_Telefonici = /^[\+]+([0-9]{2,3})+[\-]+([0-9]+)+[\-]+([0-9]+)$/;

		for(i=0; i<numVerTelefonici; i++){
			tempObj = theForm.elements[verTelefonici[i].split('|')[0]];
			if(!tempObj.disabled){
				tempVal = tempObj.value;
				if(mode=='toVerify'){
					okVerify = (tempVal=='')?false:true;
				}else{
					okVerify = false;
				}
				if(okVerify || okRequired){
					if(!re_Telefonici.test(tempVal)){
						report = 'il campo\n' + verTelefonici[i].split('|')[1] + '\nnon è stato compilato correttamente\ninserire solo le cifre numeriche senza separarle con spazi bianchi, trattini o altro';
						alert(report);
						tempObj.focus();
						okForm = false;
						return false;
					}
				}
			}
		}
	}

	if(req[prefix+'Menu']){
		var verMenu = req[prefix+'Menu'];
		var numVerMenu = verMenu.length;
		for(i=0; i<numVerMenu; i++){
			tempObj = theForm.elements[verMenu[i].split('|')[0]];
			if(tempObj.type=='select-one'){
				tempSelInd = tempObj.selectedIndex;
				tempVal = tempObj.options[tempSelInd].value;
				if(tempVal == 'void'){
					report = 'il campo\n' + verMenu[i].split('|')[1] + '\nnon è stato compilato correttamente';
					alert(report);
					tempObj.focus();
					okForm = false;
					if(mode=='required'){
						return false;
					}
				}
			}
		}
	}

	if(req[prefix+'Euro']){
		var verEuro = req[prefix+'Euro'];
		var numVerEuro = verEuro.length;
		var re_Euro = /^[0-9]+,[0-9]{2}$/;

		for(i=0; i<numVerEuro; i++){
			tempObj = theForm.elements[verEuro[i].split('|')[0]];
			if(!tempObj.disabled){
				tempVal = tempObj.value;
				if(mode=='toVerify'){
					okVerify = (tempVal=='')?false:true;
				}else{
					okVerify = false;
				}
				if(okVerify || okRequired){
					if(!re_Euro.test(tempVal)){
						report = 'il campo\n' + verEuro[i].split('|')[1] + '\nnon è stato compilato o i dati non sono stati inseriti correttamente.\nIl formato corretto richiede l\'inserimento del valore in euro\nseguito da una virgola e da due cifre indicanti i centesimi';
						alert(report);
						tempObj.focus();
						okForm = false;
						return false;
					}
				}
			}
		}
	}

	return okForm;
}

//-------------------------------------------------------------------------------------------------------------

function okPrivacy(nomeForm,nomeRadio){
	// İ 2010 Paolo Marson All Rights reserved
	var radioAccetta = document.forms[nomeForm].elements[nomeRadio];

	var numeroScelte = radioAccetta.length;
	for(i=0; i<numeroScelte; i++){
		if(radioAccetta[i].checked){
			if(radioAccetta[i].value == 'si'){
				return true;
			}
		}
		alert('per poter procedere con la registrazione è necessario accettare le condizioni sulla privacy');
		return false;
	}
}

