// ** ######################################################################### %>
// **                                                                           %>
// **    IncJava.js                                                             %>
// **    Basic Properties Services Internet Site             	                %>
// **    BPSIS ver 2.1                                                          %>
// **                                                                           %>
// **    Copyright (c) 1997-1999 Basic Properties Services S.p.A.               %>
// **                        All rights reserved.                               %>
// **                                                                           %>
// ** ######################################################################### %>
 
	IE4 = document.all;
 
	// *************************************************************************************
	// Nome        : WriteStatus
	// Descrizione : Crea la riga che contiene il titolo principale
	//             : dell'operazione che si effettua.
	// Parametri   : strMessage - messaggio da visualizzare nella StatusBar
	// Ret.Code    : Nessuno
	// *************************************************************************************
	function WriteStatus(strMessage)
	
	{
	//	newstr = strMessage.replace("'", "&#180;")
		window.status = strMessage;
	}
 
	// *************************************************************************************
	// Nome        : WriteMainTitle
	// Descrizione : Crea la riga che contiene il titolo principale
	//             : dell'operazione che si effettua.
	// Parametri   : strTitolo     - Titolo della tabella
	//             : strBgColor    - colore di background della tabella
	//             : strFgColor    - colore di foreground per la scritta del titolo nella tabella
	//             : bNext         - indica se ci sono altre colonne da disegnare
	//             : strTitoloNext - testo della successiva colonna della tabella
	//             : strPathNext   - path della successiva colonna della tabella (href)
	//             : strTitoloNext2- testo della successiva colonna della tabella
	//             : strPathNext2  - path della successiva colonna della tabella (href)
	// Ret.Code    : Nessuno
	// *************************************************************************************
	function WriteMainTitle(strTitolo, strBgColor, strFgColor, bNext, strTitoloNext, strPathNext, strTitoloNext2, strPathNext2)
	{	
		var writestr  = "<TABLE BORDER='0' CELLSPACING='1' WIDTH='100%'>";
		writestr     += "<TR WIDTH='100%' BGCOLOR='" + strBgColor + "'>";
		if (bNext > 0) {
			writestr     += "<TD ALIGN='left' WIDTH='70%'>"
		} else {
			writestr     += "<TD ALIGN='left' WIDTH='100%'>"
		}
		writestr     += "<FONT SIZE='3' FACE='Verdana,Arial'"
		if(strFgColor != "" && strFgColor != null && strFgColor != "undefined") {
			writestr     += " COLOR='" + strFgColor + "'";
		}
		writestr     += "><B>"
		writestr     += strTitolo + "</B>";
		writestr     += "</FONT></TD>";
		if (bNext > 0) {
			writestr     += "<TD ALIGN='right' WIDTH='15%'>"
			writestr     += "<FONT SIZE='1' FACE='Verdana,Arial' ";
			writestr     += " TITLE='" + strTitoloNext + "' "
			writestr     += " onmouseover=\"WriteStatus('" + strTitoloNext + "');return true;\" ";
			writestr     += " onmouseout=\"WriteStatus('');\" ";
			writestr     += ">"
			writestr     += "<A HREF=\"javascript:" + strPathNext + "\">" + strTitoloNext + "</A>";
			writestr     += "</FONT></TD>";
		}
		if (bNext > 1) {
			writestr     += "<TD ALIGN='right' WIDTH='15%'>"
			writestr     += "<FONT SIZE='1' FACE='Verdana,Arial' ";
			writestr     += " TITLE='" + strTitoloNext2 + "' "
			writestr     += " onmouseover=\"WriteStatus('" + strTitoloNext2 + "');return true;\" ";
			writestr     += " onmouseout=\"WriteStatus('');\" ";
			writestr     += ">"
			writestr     += "<A HREF=\"javascript:" + strPathNext2 + "\">" + strTitoloNext2 + "</A>";
			writestr     += "</FONT></TD>";
		}
		writestr     += "</TR>";
		writestr     += "</TABLE>";
		document.write(writestr);
	}
 
	// *********************************************************************************
	// Function    : DateToEng
	// Description : Converte una data in italiano in una data in inglese,
	//             : indipendentemente dal tipo di formato in italiano
	//             : g/m/aaaa o gg/m/aaaa o gg/m/aaaa o gg/mm/aa
	// Parameters  : strDate    - Data nel formato in italiano
	//             : strWhat    - Identifica il nome della data su cui eventualmente
	//             :              c'e' stato un'errore
	// Return Code : strNewDate - Data nel formato in inglese corretta
	//			   : null       - Data non corretta
	// *********************************************************************************
	function DateToEng(strDate, strWhat)
	{
		if(strWhat == null) {
			strWhat = "";
		}
 
		bError = 0;
 
		for (i = 0;  i < strDate.length;  i++) {
			ch = strDate.charAt(i);
			if(ch == "/") {
				break;
			}
		}
		giorno = strDate.substring (0, i)
		if (giorno < 1 || giorno > 31)
			bError = 1;
 
		for (j = i + 1;  j < strDate.length;  j++) {
			ch = strDate.charAt(j);
			if(ch == "/") {
				break;
			}
		}
		mese = strDate.substring (i + 1, j)
		if (mese < 1 || mese > 12)
			bError = 1;
 
		anno = strDate.substring (j + 1, strDate.length)
		if(anno.length > 4)
			bError = 3;
 
		if (anno < 0)
			bError = 1;
 
		if (anno < 1900)
			bError = 2;
 
		if (mese == 4 || mese == 6 || mese == 9 || mese == 11) {
			if (giorno == 31)
				bError = 1;
		}
		if (mese == 2)	{
			var g = parseInt(anno / 4)
			if (isNaN(g)) {
				bError = 1;
			}
			if (giorno > 29) bError =1;
			if (giorno == 29 && ((anno / 4)!= parseInt(anno / 4)))	bError = 1;
		}
 
		//strNewDate = mese + "/" + giorno + "/" + anno;
		strNewDate = anno + "/" + mese + "/" + giorno;
		if (bError == 1) {
			newAlert("Checking date a1", "\nThe " + strWhat + " field is not valid.\n\nPlease enter " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 2) {
			newAlert("Checking date a2", "\nThe " + strWhat + " field is not valid. Date too low.\n\nPlease re-enter " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 3) {
			newAlert("Checking date a3", "\nThe " + strWhat + " field is not valid. Year too great.\n\nPlease re-enter " + strWhat + ".", 1)
			strNewDate = null;
		}
		return strNewDate;
	}
 
 
 	// *********************************************************************************
	// Function    : DateToITA
	// Description : Converte una data in italiano in una data in inglese,
	//             : indipendentemente dal tipo di formato in italiano
	//             : g/m/aaaa o gg/m/aaaa o gg/m/aaaa o gg/mm/aa
	// Parameters  : strDate    - Data nel formato in italiano
	//             : strWhat    - Identifica il nome della data su cui eventualmente
	//             :              c'e' stato un'errore
	// Return Code : strNewDate - Data nel formato in inglese corretta
	//			   : null       - Data non corretta
	//	il messaggio di ritorno &egrave; in italiano
	// *********************************************************************************
	function DateToITA(strDate, strWhat)
	{
		if(strWhat == null) {
			strWhat = "";
		}
 
		bError = 0;
 
		for (i = 0;  i < strDate.length;  i++) {
			ch = strDate.charAt(i);
			if(ch == "/") {
				break;
			}
		}
		giorno = strDate.substring (0, i)
		if (giorno < 1 || giorno > 31)
			bError = 1;
 
		for (j = i + 1;  j < strDate.length;  j++) {
			ch = strDate.charAt(j);
			if(ch == "/") {
				break;
			}
		}
		mese = strDate.substring (i + 1, j)
		if (mese < 1 || mese > 12)
			bError = 1;
 
		anno = strDate.substring (j + 1, strDate.length)
		if(anno.length > 4)
			bError = 3;
 
		if (anno < 0)
			bError = 1;
 
		if (anno < 1900)
			bError = 2;
 
		if (mese == 4 || mese == 6 || mese == 9 || mese == 11) {
			if (giorno == 31)
				bError = 1;
		}
		if (mese == 2)	{
			var g = parseInt(anno / 4)
			if (isNaN(g)) {
				bError = 1;
			}
			if (giorno > 29) bError =1;
			if (giorno == 29 && ((anno / 4)!= parseInt(anno / 4)))	bError = 1;
		}
 
		//strNewDate = mese + "/" + giorno + "/" + anno;
		strNewDate = anno + "/" + mese + "/" + giorno;
		if (bError == 1) {
			newAlert("Checking date a1", "\n Il campo  " + strWhat + " no &egrave; valido.\n\n Reinserire  " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 2) {
			newAlert("Checking date a2", "\n Il campo " + strWhat + " no &egrave; valido.\n\n Reinserire . " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 3) {
			newAlert("Checking date a3", "\n Il campo " + strWhat + " no &egrave; valido.\n\n Reinserire ." + strWhat + ".", 1)
			strNewDate = null;
		}
		return strNewDate;
	}

 
	// *********************************************************************************
	// Function    : DateYYYYMMDD
	// Description : Converte una data in italiano in una data nel formato YYYY/MM/DD
	// Parameters  : strDate    - Data nel formato in italiano
	//             : strWhat    - Identifica il nome della data su cui eventualmente
	//             :              c'e' stato un'errore
	// Return Code : strNewDate - Data nel formato YYYY/MM/DD
	//			   : null       - Data non corretta
	// *********************************************************************************
	function DateYYYYMMDD(strDate, strWhat)
	{
		if(strWhat == null) {
			strWhat = "";
		}
 
		bError = 0;
 
		for (i = 0;  i < strDate.length;  i++) {
			ch = strDate.charAt(i);
			if(ch == "/") {
				break;
			}
		}
		giorno = strDate.substring (0, i)
		if (giorno < 1 || giorno > 31)
			bError = 1;
 
		for (j = i + 1;  j < strDate.length;  j++) {
			ch = strDate.charAt(j);
			if(ch == "/") {
				break;
			}
		}
		mese = strDate.substring (i + 1, j)
		if (mese < 1 || mese > 12)
			bError = 1;
 
		anno = strDate.substring (j + 1, strDate.length)
		if(anno.length > 4)
			bError = 3;
 
		if (anno < 0)
			bError = 1;
 
		if (anno < 1900)
			bError = 2;
 
		if (mese == 4 || mese == 6 || mese == 9 || mese == 11) {
			if (giorno == 31)
				bError = 1;
		}
		if (mese == 2)	{
			var g = parseInt(anno / 4)
			if (isNaN(g)) {
				bError = 1;
			}
			if (giorno > 29) err=1
			if (giorno == 29 && ((anno / 4)!= parseInt(anno / 4)))
				bError = 1;
		}
 
		strNewDate = anno + "/" + mese + "/" + giorno;
 
		if (bError == 1) {
			newAlert("Checking date b1", "\nThe " + strWhat + " field is not valid.\n\nPlease enter " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 2) {
			newAlert("Checking date b2", "\nThe " + strWhat + " field is not valid. Date too low.\n\nPlease re-enter " + strWhat + ".", 1)
			strNewDate = null;
		}
 
		if (bError == 3) {
			newAlert("Checking date b3", "\nThe " + strWhat + " field is not valid. Year too great.\n\nPlease re-enter " + strWhat + ".", 1)
			strNewDate = null;
		}
		return strNewDate;
	}
 
	// *********************************************************************************
	// Function    : IsValidValue
	// Description : Verifica se una stringa contiene solo i valori validi
	//             : passati in input
	// Parameters  : strValue   - stringa da controllare
	//             : strCheckOK - stringa dei valori accettati
	// Return Code : 1 la stringa è corretta / 0 la stringa è scorretta
	// *********************************************************************************
	function IsValidValue(strValue, strcheckOK)
	{
		var allValid = 1;
		for (i = 0;  i < strValue.length;  i++) {
			ch = strValue.charAt(i);
			for (j = 0;  j < strcheckOK.length;  j++)
				if(ch == strcheckOK.charAt(j))
					break;
				if(j == strcheckOK.length) {
					allValid = 0;
					break;
				}
		}
		if(!allValid)
		  return 0;	// FALSE
		else
		  return 1; // TRUE
	}
 
	// *********************************************************************************
	// Pgm	       : Michela
	// Function    : ltrim
	// Description : Toglie gli spazi
	// Parameters  : str   - stringa da controllare
	// ********************************************************************************* 
	 function ltrim (str)
	{
            var lpatt = new RegExp( "^ *(.*)$" );
	    var parse = str.match( lpatt );
	    return parse[1];
	}

	// *********************************************************************************
	// Function    : isEmptyValue
	// Description : Verifica se una stringa e' vuota
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - l'oggetto contiene dei valori
	//             : false - l'oggetto NON contiene dei valori
	// *********************************************************************************
	function isEmptyValue(OBJ, strWhat)
	{
		var str = ltrim(OBJ.value);
 
		if (str == "") {
			newAlert("Verify Value", "\nThe " + strWhat + " field is blank.\n\nPlease enter " + strWhat + ".", 1)
			OBJ.focus();
			return false;
		}
		return true;
	}
	// *********************************************************************************
	// Function    : isSelected
	// Description : Verifica se un option e' selected
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - l'oggetto contiene dei valori
	//             : false - l'oggetto NON contiene dei valori
	// *********************************************************************************
	function isSelected(OBJ, strWhat)
	{
		var str = OBJ.options[strWhat].selected;
 
		if (str ) {
			return true;
		}
		return false;
	} 
	// *********************************************************************************
	// Function    : isNumericValue
	// Description : Verifica se una stringa contiene solo i valori validi
	//             : passati in input
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - l'oggetto contiene solo valori numerici
	//             : false - l'oggetto NON contiene solo valori numerici
	// *********************************************************************************
	function isNumericValue(OBJ, strWhat)
	{
		var str = OBJ.value;
 
		for (var i = 0; i < str.length; i++) {
			var ch = str.substring(i, i + 1);
			if(ch < "0" || "9" < ch) {
				newAlert("Verify Value", "\nThe " + strWhat + " field only accepts numbers. Please re-enter your  " + strWhat + ".", 1);
				OBJ.select();
				OBJ.focus();
				return false;
			}
		}
		return true;
	}
 
	// *********************************************************************************
	// Function    : isAlphabeticValue
	// Description : Verifica se una stringa contiene solo valori alfabetici e spazi
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - l'oggetto contiene solo valori alfabetici e spazi
	//             : false - l'oggetto NON contiene solo valori alfabetici e spazi
	// *********************************************************************************
	function isAlphabeticValue(OBJ, strWhat)
	{
		var str = OBJ.value;
 
		for(var i = 0; i < str.length; i++) {
			var ch = str.substring(i, i + 1);
			if(((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') {
				newAlert("Verify Value", "\nThe " + strWhat + " field only accepts letters & spaces.\n\nPlease re-enter your  " + strWhat + ".", 1);
				OBJ.select();
				OBJ.focus();
				return false;
			}
		}
		return true;
	}
 
	// *********************************************************************************
	// Function    : isEmail
	// Description : Verifica se nel valore dell'oggetto in input e' stato inserito
	//             : un indirizzo di EMail nel formato xx@yyy.zz
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - il valore è un'indirizzo di mail valido
	//             : false - il valore non è un'indirizzo di mail valido
	// *********************************************************************************
	function isEmail(OBJ) {
		emailAddress = OBJ.value;
		if(emailAddress == "") {
			newAlert("Verify Value", "\nThe E-MAIL field is blank.\n\nPlease enter your e-mail address.", 1)
			OBJ.focus();
			return false;
		}else{

			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (! filter.test(emailAddress )){
				alert("Invalid email address.\nPlease re-enter a valid address.");
				OBJ.focus();
				OBJ.select();
				return false;
			}

		}
/*
		if(emailAddress.indexOf ('@',0) == -1 || emailAddress.indexOf ('.',0) == -1) {
			newAlert("Verify Value", "\nThe E-MAIL field requires a \"@\" and a \".\"be used.\n\nPlease re-enter your e-mail address.", 1)
			OBJ.select();
			OBJ.focus();
			return false;
		} else {
			return true;
		}
*/
		return true
	}
 
	// *********************************************************************************
	// Function    : isURL
	// Description : Verifica se nel valore dell'oggetto in input e' stato inserito
	//             : un indirizzo internet nel formato http://askljf.df
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - il valore è un'indirizzo URL valido
	//             : false - il valore non è un'indirizzo URL valido
	// *********************************************************************************
	function isURL(OBJ) {
		strHttp = OBJ.value;
		if(strHttp == "") {
			newAlert("Verify Value", "\nThe URL field is blank.\n\nPlease enter your URL address.", 1)
			OBJ.focus();
			return false;
		}
		if(strHttp.indexOf ('http://', 0) == -1 || strHttp.indexOf ('.', 0) == -1) {
			newAlert("Verify Value", "\nThe URL field requires a \"http://\" and a \".\" be used.\n\nPlease re-enter your URL address.", 1);
			OBJ.select();
			OBJ.focus();
			return false;
		} else {
			return true;
		}
	}
 
	// *********************************************************************************
	// Function    : fCheckQty
	// Description : Verifica se nel valore dell'oggetto in input e' stato inserito
	//             : un indirizzo internet nel formato http://askljf.df
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - il valore è un'indirizzo URL valido
	//             : false - il valore non è un'indirizzo URL valido
	// *********************************************************************************
	function fCheckQty(OBJ)
	{
		bRet = true;
		if(IsValidValue(OBJ.value, "0123456789") == 0) {
			newAlert("Verify Value", "The quantity is not valid! You can insert only numbers!", 1);
			OBJ.focus();
			return false;
		}
		return bRet;
	}
	// *********************************************************************************
	// Function    : isSelected
	// Description : Verifica se una option e' selected
	// Parameters  : OBJ   - oggetto da controllare
	// Return Code : true  - l'oggetto contiene dei valori
	//             : false - l'oggetto NON contiene dei valori
	// *********************************************************************************
	function isSelected(OBJ, strWhat)
	{
		var str = OBJ.options[strWhat].selected;
		
		if (str ) {
			return true;
		} else{
			return false;
		}
	} 
	// *********************************************************************************
	// Function    : Left
	// Description : Simula la funzione Left di vbscript
	// Parameters  : str   - stringa da modificare
	//			   : n   - elementi da estrarre
	// Return Code : nuova stringa
	// *********************************************************************************
     function Left(str, n)
      /***
              IN: str - the string we are LEFTing
                  n - the number of characters we want to return

              RETVAL: n characters from the left side of the string
      ***/
      {
              if (n <= 0)     // Invalid bound, return blank string
                      return "";
              else if (n > String(str).length)   // Invalid bound, return
                      return str;                // entire string
              else // Valid bound, return appropriate substring
                      return String(str).substring(0,n);
      }

	// *********************************************************************************
	// Function    : IsCompleteOp
	// Description : restuisce "1" se la session di operazione conclusa è uguale a "yes"
	// Parameters  : Session  op. closed (vale yes o no)
	// Return Code : "1" = operazione completata "0" = operazione non completata
	// *********************************************************************************

	function IsCompleteOp(StatusOp)
	{		 
		if (StatusOp == "Yes"){
			return  true;
		}
		alert("Operation not Completed.\nPlease wait!");
		return false;
	}