// JavaScript Document

function popWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars)
	{
		var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
		var int_windowTop = (screen.height - a_int_windowHeight) / 2;
		var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + '';
		var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
		if (parseInt(navigator.appVersion) >= 4) {
			obj_window.window.focus();
		}
	}

	function ValidaDati()
	{

		var vCopie=document.preventivo.copie.value;
		var vPagine=document.preventivo.numeropagine.value;
		var vRilegatura=document.preventivo.rilegatura.value;
		if ((vPagine =='0') || (vPagine == '')) {
			alert( "Immettere un numero pagine corretto." );
			preventivo.numeropagine.focus();
		} else if (vPagine<=15) {
			alert( "Numero di pagine non valido. Minimo 16 pagine, immettere un numero corretto." );
			document.preventivo.numeropagine = '16';
			preventivo.numeropagine.focus();
		} else if (!vCopie || (vCopie<50)) {
			alert( "Numero di copie non valido. Minimo 8 copie, immettere un numero copie corretto." );
			preventivo.copie.value = "8";
			preventivo.copie.focus();
		} else if ((preventivo.rilegatura.value == 24) && (vPagine>64)) {
			alert( "Per la rilegatura a punto metallico sono ammesse al massimo 64 pagine." );
			preventivo.numeropagine.value = '64';
			preventivo.numeropagine.focus();
		} else document.preventivo.submit();
	}
	
	function controllomail(mail)
{	
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;	
	if (!espressione.test(mail))	
		return "La mail inserita non è valida!\n";	
	return '';
}

function ValidaDatiNewsletter() 
{
	var message="";
	var err="";
	var vContattoNome = document.form_news.ContattoNome.value;
	var vContattoCognome = document.form_news.ContattoCognome.value;
	var vContattoIndirizzoEmail = document.form_news.ContattoIndirizzoEmail.value;
	if (vContattoNome=='') {
		message = message + "Il campo nome è obbligatorio:\n";
	}	
	if (vContattoIndirizzoEmail=='') {
		message = message + "Il campo email è obbligatorio:\n";
	}
	if (vContattoIndirizzoEmail != '') 
		err = controllomail(vContattoIndirizzoEmail);
		if (err != '')
			message = message + err; 

	if (message != '') {
		alert(message);
	} else {
		
		document.form_news.submit();
	}	
}

function messaggio(errmsg)
{	
	alert(errmsg);
	document.form_news.ContattoNome.select();
	document.form_news.ContattoNome.focus();
}
