

	// salva il cookie che conserva il nome del navigatore
	function SetNavigatorCookie( )
	{  var d = new Date();
	
		// legge la data corrente posposta al prossimo anno	
		d.setYear(d.getYear()+1);
		// dichiara un cookie pari al nome del browser e setta la scadenza al prossimo anno
		SetCookie("PMF_Nav", navigator.appName+" "+navigator.appVersion, d );
		// per un bug di Explorer 4 di Win95
		if ( GetCookie("PMF_Nav") == null )
			SetCookie("PMF_Nav", navigator.appName);
		//alert(navigator.appName+" "+navigator.appVersion);
	}


	// siamo in Internet Explorer?
	function inExplorer( )
	{ 		
		return( ( navigator.appName.indexOf("Explorer") > -1 ) ? true : false );
	}

	// siamo in Netscape?
	function inNetscape( )
	{
		return( ( navigator.appName.indexOf("Netscape") > -1 ) ? true : false );
	}


	// no Operation
	function nOp( )
	{	
	}


	// apre una finestra generica e la centra sullo schermo (se in Explorer)
	// il quarto parametro opzionale definisce il nome della finestra
	function winOpen( psLink, plDimX, plDimY )
	{ var idw;
		// parametri di funzione
	  var argv = winOpen.arguments;
	  var argc = winOpen.arguments.length;

		// dimensione della viewport area
		var lsdx = screen.width;
		var lsdy = screen.height;
		// dimensioni correnti della client area
		var lfdx = inExplorer() ? plDimX : lsdx;
		var lfdy = inExplorer() ? plDimY : lsdy;
		// se ho specificato il secondo parametro legge il nome della finestra
		var sname = (3 < argc) ? argv[3] : "winNew";
		// se siamo in Netscape lascia il form dimensionabile
  		var sapp = "width=" + lfdx + ",height=" + lfdy + ",toolbar=no,menubar=no,status=no,scrollbars=no,directories=no,resizable=" + ( inNetscape() ? "yes" : "no" );

		// apre la finestra
		idw = window.open(psLink, sname, sapp);
		// la centra sullo schermo	
		//idw.resizeTo( lfdx, lfdy );
		//idw.moveTo( (lsdx-lfdx)/2, (lsdy-lfdy)/2 );

		// ritorna l'handle di finestra
		return( idw );
	}


	// centra sullo schermo la finestra passata
	// le dimensioni passate si riferiscono alla finestra
	function winCentre( idw, lfdx, lfdy )
	{
		// dimensione della viewport area
		var lsdx = screen.availWidth;
		var lsdy = screen.availHeight;

		idw.moveTo( (lsdx-lfdx)/2, (lsdy-lfdy)/2 );		
	}


	// chiude la finestra passata: se non ci sono parametri chiude quella corrente
	function winClose( )
	{ 		
		// parametri di funzione
	  var argv = winClose.arguments;
	  var argc = winClose.arguments.length;

		var idw = (0 < argc) ? argv[0] : self;

		idw.close( );
	}


function Test()
{
	alert("Sono qui");
}


function validateValue( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.
    
PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.
      
RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp(strMatchPattern);
 
 //check if string matches pattern
 return objRegExp.test(strValue);
}


// ritorna lo stato di validazione di una stringa alfanumerica
function validateAlphaNumeric( strValue ) {
var objRegExp = new RegExp("^[a-zA-Z0-9]+$");
 
 //check if string matches pattern
 return objRegExp.test(strValue);
}


function  validateNumeric( strValue ) {
/******************************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
 
  //check for numeric characters 
  return objRegExp.test(strValue);
}


function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid email pattern. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) and optionally,
  a valid country suffix.  Since email has many
  forms this expression only tests for near valid
  address.  Some additional validation may be
  required.
*************************************************/
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
  //check for valid email
  return objRegExp.test(strValue);
}


function rightTrim( strValue ) {
/************************************************
DESCRIPTION: Trims trailing whitespace chars.
    
PARAMETERS:
   strValue - String to be trimmed.  
      
RETURNS:
   Source string with right whitespaces removed.
*************************************************/
var objRegExp = /^([\w\W]*)(\b\s*)$/;
 
      if(objRegExp.test(strValue)) {
       //remove trailing a whitespace characters
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}


function leftTrim( strValue ) {
/************************************************
DESCRIPTION: Trims leading whitespace chars.
    
PARAMETERS:
   strValue - String to be trimmed
   
RETURNS:
   Source string with left whitespaces removed.
*************************************************/
var objRegExp = /^(\s*)(\b[\w\W]*)$/;
 
      if(objRegExp.test(strValue)) {
       //remove leading a whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}


function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/ 
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}


function removeCharacters( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Removes characters from a source string
  based upon matches of the supplied pattern.

PARAMETERS: 
  strValue - source string containing number.
  
RETURNS: String modified with characters
  matching search pattern removed
  
USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd', 
                                '\s*')
				Es. per rimuovere spazi:
				s=removeCharacters(field.value,'[ ]');
*************************************************/
 var objRegExp =  new RegExp( strMatchPattern, 'gi' );
 
 //replace passed pattern matches with blanks
  return strValue.replace(objRegExp,'');
}


  // ---------------------------------------------------------------------------------
 // funzioni standard per l'interrogazione e il setting di cookies
// ---------------------------------------------------------------------------------

function GetCookie (name) 
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while (i < clen) 
      {
      var j = i + alen;

      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);

      i = document.cookie.indexOf(" ", i) + 1;

      if (i == 0) 
         break; 
      }

   return null;
}

function getCookieVal (offset) 
{
   var endstr = document.cookie.indexOf (";", offset);

   if (endstr == -1)
      endstr = document.cookie.length;

   return unescape(document.cookie.substring(offset, endstr));
}


function SetCookie (name, value) 
{
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;

   document.cookie = name + "=" + escape (value) + 
	 ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	 ((path == null) ? "" : ("; path=" + path)) + 
	 ((domain == null) ? "" : ("; domain=" + domain)) + 
	 ((secure == true) ? "; secure" : "");
}

// ---------------------------------------------------------------------------------





