function selectcheck(entered, alertbox)
{
	with (entered)
	if (entered.value=="nn")
	{
		if (alertbox!="") 
		{
			alert(alertbox);
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function radiocheck(entered, alertbox)
{
	with (entered)
	if (!(entered)[0].checked) 
	{
		if (alertbox!="") 
		{
			alert(alertbox);
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function checkme(entered, alertbox) 
{
	with (entered)
	if (!entered.checked) 
	{
		if (alertbox!="") 
		{
			alert(alertbox);
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function EmptyValidation(entered, alertbox)
{
	with (entered)
	{
		if (value==null || value=="")
		{
			if (alertbox!="") 
			{
				alert(alertbox);
			} 
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function EmailValidation(entered, alertbox)
{
	with (entered)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) 
		{
			if (alertbox) 
			{
				alert(alertbox);
			} 
			return false;
		}
		else 
		{
			return true;
		}
	}
}


function CharacterValidation(entered,permessi)
{
	var strtmp;	
	var nIndex;

	strtmp=entered.value.toLowerCase();

  	for (nIndex=0;nIndex < strtmp.length; nIndex++)
	{ 

		if (permessi.indexOf(strtmp.charAt(nIndex)) < 0)
		 { 
	        entered.value=entered.value.substring(0,nIndex)
		    return false;
	     }
	}
	return true;

}

function IsNumber(entered, alertbox)
{
	var Numero = entered.value
	var parseNumero
	
	if (Numero.substr(0,1)=='0')
	{
		if (Numero.length==1)
		{
			return true;
		}else
		{   Numero=Numero.substr(1,Numero.length)	
			parseNumero=parseInt(Numero)
		  
		}
	}else
	{ parseNumero=parseInt(Numero)
	}
	
	if (Numero!=parseNumero)
    { 
    	alert(alertbox);
	  	return false;	
    }
	 return true;
}

function IsSelected(entered, alertbox)
{
	var Numero = entered.value
	if (Numero==0)
    {
    	alert(alertbox);
	  	return false;
    }
   return true;
}

function DateValidation(dateStr,alertbox) 
{

	// Controlla la data nei seguenti formati:
	// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
	// Separa la data nelle variabili month, day, e year

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	// Per obbligare l'immissione dell'anno di 4 cifre, usare la linea seguente
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // il formato è corretto?
	if (matchArray == null) 
	{
		alert(alertbox);
		return false;
	}
	day = matchArray[1]; // parse date nelle variabili
	month = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) 
	{ 	// controlla il range dei mesi
		alert("Attenzione, i mesi vanno da 1 a 12")
		return false;
	}
	if (day < 1 || day > 31) 
	{
		alert("Attenzione, i giorni vanno da 1 a 31.");
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		alert("Month "+month+" doesn't have 31 days!")
		return false
	}
	if (month == 2) 
	{ 	// controllo del 29 febbraio
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			alert("Febbraio " + year + " non ha " + day + " giorni!");
			return false;
   		}
	}
	return true;  // la data è valida
}

//Di seguito le routine per la gestione della stampa
var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage(frame, arg) {

  if (frame == window) {
    printThis();
  } else {
    link = arg; // a global variable 
    printFrame(frame);
  }
  return false;
}

function printThis() {
  if (pr) { // NS4, IE5
    window.print();
  } else if (da && !mac) { // IE4 (Windows)
    vbPrintPage();
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

function printFrame(frame) {
  if (pr && da) { // IE5
    frame.focus();
    window.print();
    link.focus();
  } else if (pr) { // NS4
    frame.print();
  } else if (da && !mac) { // IE4 (Windows)
    frame.focus();
    setTimeout("vbPrintPage(); link.focus();", 100);
  } else { // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  }
}

//Attenzione: chiamare questa funzione nel BODY del documento
function InitNavigator()
{
	if (da && !pr && !mac) with (document) 
	{
		writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
		writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
		writeln('Sub window_onunload');
		writeln('  On Error Resume Next');
		writeln('  Set WB = nothing');
		writeln('End Sub');
		writeln('Sub vbPrintPage');
		writeln('  OLECMDID_PRINT = 6');
		writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
		writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
		writeln('  On Error Resume Next');
		writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
		writeln('End Sub');
		writeln('<' + '/SCRIPT>');
	}
}	


