function isDate(rifobj) {
//	return true;
	if ( !isNull(rifobj.value)) {
//		alert ( "inizio" );
		// TODO fare per bene i controlli, il javascript interpreta
		// la data come vuole lui, ma a Oracle poi non gli sta bene
//		alert( "1x" + rifobj.value ) ;
//		alert( "2x" + new Date(rifobj.value).getDate() ) ;

		dTemp = getDate (rifobj.value);
		if (dTemp == "NaN" ) {
			alert ("Date Field is malformed, please correct it");
			rifobj.focus();
			return false;
		}
		dd = dTemp.getDate();
//		alert ( "dd: " + dd ) ;
		if ( dd < 10 ) {
			xTemp = "0" + dd ;
		} else {
			xTemp = dd ;
		}
		mm = dTemp.getMonth()+1; // Leo 24-08-2009 Fix problema mesi
//		alert ( "mm: " + mm ) ;
		if ( mm < 10 ) {
			xTemp = xTemp + "-0" + mm ;
		} else {
			xTemp = xTemp + "-" + mm ;
		}
//		alert ( "yyyy: " + dTemp.getFullYear() ) ;
		xTemp = xTemp+ "-" + dTemp.getFullYear();
//		alert ( xTemp ) ;
		rifobj.value = xTemp;
	}
	return true;
} // fine isDate
function getDate(xDate) {
	// accetta una data nel formato dd/mm/yyyy e restituisce un oggetto "DATE"
	iDay = xDate.substring(0, 2) ;
	iMonth = xDate.substring(3, 5) ;
	iYear = xDate.substring(6, 10) ;
//	alert ( "scompongo " + xDate + ": " + iDay + " " + iMonth + " " + iYear );
	return new Date(iYear, iMonth-1, iDay) ; // Leo 24-08-2009 Fix problema mesi
} // fine getDate
function isNumber(rifobj) {
	// TODO implementare la funzione
	if ( !isNull(rifobj.value)) {
		if ( 1==0 ) {
			alert ("Date Field is malformed, please correct it");
			rifobj.focus();
			return false;
		}
		NULL ;
	}
	return true;
} // fine isNumber

function isEmpty(rifobj) {
	if (isNull(rifobj.value)) {
		alert ("Field is necessary, please fulfil it");
		rifobj.focus();
		return true;
	}
	return false ;
} // fine isEmpty
function isNull(testo) {
	// controllo campi vuoti
	// fa la trim
	var rep = /\s*/;
	var cont = testo.replace(rep,"");

	if (cont=="") {
		return true;
	}
	return false ;
} // fine isNull

function getUrlValue ( pUrl, pKey ) {
	// cerca pxKey nel pUrl passato e ne restituisce il valore
	var xUrl = pUrl.toUpperCase();

	var liStart = xUrl.indexOf("&" + pKey.toUpperCase() + "=");
	if (liStart == -1 ) {
		// guardo se per caso non è proprio la prima chiave
		liStart = xUrl.indexOf("?" + pKey.toUpperCase() + "=");
		if (liStart == -1 ) {
			// non c''è... niente da fare
			return "";
		}
	}
	var liEnd = xUrl.indexOf("&", liStart +1 ) ;
	liStart = liStart + pKey.length + 2 ;
	if ( liEnd == -1 ) {
		xValue = pUrl.substring ( liStart, pUrl.length ) ;
	} else {
		xValue = pUrl.substring ( liStart, liEnd ) ;
	}
	return xValue ;
}
function getNewUrl ( pUrl, pKey, pNewValue ) {
	// cerca pKey nel pUrl passato e al valore sostituisce pNewValue
	// se non lo trova lo aggiunge
	// ritorna il nuovo url così calcolato

	var xUrl = pUrl.toUpperCase();
	var liStart = xUrl.indexOf("&" + pKey.toUpperCase() + "=");
	if (liStart == -1 ) {
		// guardo se per caso non è proprio la prima chiave
		liStart = xUrl.indexOf("?" + pKey.toUpperCase() + "=");
		if (liStart == -1 ) {
			// non c''è... niente da fare
//				return pUrl ;
			// non c''è... aggiungo (Dora 13.02.2007 - prima restituivo il pUrl intatto)
			if ( pUrl.indexOf("?") == -1 ) {
				// sto mettendo proprio il primo parametro
				xUrl = pUrl + "?" + pKey + "=" + pNewValue ;
			} else {
				// il ? c'è
				// prima di aggiungere il parametro vediamo se l'url finisce con ? o &
				if ( pUrl.indexOf("?") == ( pUrl.length -1 ) ) {
					// finisce con ?
					xUrl = pUrl + pKey + "=" + pNewValue ;
				} else {
					if ( pUrl.lastIndexOf("&") == ( pUrl.length -1 ) ) {
						// finisce con &
						xUrl = pUrl + pKey + "=" + pNewValue ;
					} else {
						xUrl = pUrl + "&" + pKey + "=" + pNewValue ;
					}
				}
			}
			return xUrl ;
		}
	}
	// cerco la fine del parametro
	var liEnd = xUrl.indexOf("&", liStart +1 ) ;
	xUrl = pUrl.substring( 0, liStart + 1 + pKey.length + 1) + pNewValue ;
	if ( liEnd > -1 ) {
		xUrl = xUrl + pUrl.substring( liEnd, pUrl.length ) ;
	}
	return xUrl ;
} // fine getNewUrl
function winCenter ( pxUrl, pxWindowName, piWidth, piHeight, pxFeatures ) {
	// calcola le coordinate per aprire una win centrata rispetto ad uno schermo 1024x768
	var xFeatures ;
	if ( pxFeatures ) {
		xFeatures = pxFeatures ;
	} else {
		// se è vuoto metto tutto come il default, lasciando vuoto modificherei il comportamento
		xFeatures = "menubar=yes,resizable=yes,scrollbars=yes,status=yes,location=yes,toolbar=yes,directories=yes" ;
	}
	if (piWidth && piWidth <= 1024 ) {
		iLeft = (1024 - piWidth) / 2 ;
		if ( xFeatures!="" ) {
			xFeatures = xFeatures + ",width="+piWidth+",left="+iLeft;
		}
	}
	if (piHeight && piHeight <= 768 ) {
		iTop = (768 - piHeight) / 2 ;
		if ( xFeatures!="" ) {
			xFeatures = xFeatures + ",height="+piHeight+",top="+iTop;
		}
	}
//	alert ( xFeatures ) ;
	// Commentato perchè così non apre gli indirizzi esterni
//	newWin=window.open(pxUrl,pxWindowName,xFeatures);
	newWin=window.open("",pxWindowName,xFeatures);
	newWin.location = pxUrl ;
	newWin.focus();
	return newWin;
} // fine winCenter

function stringReplace ( pText, pSearchString, pReplacementString ) {
	// rimpiazza in pText le occorrenze di pSearchString con pReplacementString
	// se pReplacementString non passato => elmina da pText le occorrenze di pSearchString
	// NOTA: lasciare le tostring perchè se una delle stringhe che arriva è un numero fa casino con le concatenazioni
	xText = pText ;
	if ( pReplacementString ) {
		xReplacementString = pReplacementString;
	} else {
		xReplacementString = "";
	}
	iStart = xText.toUpperCase().indexOf ( pSearchString.toUpperCase(), 0 ) ;
	while (iStart >= 0 ) {
		xText = xText.substring ( 0, iStart ).toString() + xReplacementString.toString() + xText.substring ( iStart + pSearchString.length, xText.length ) ;
		iStart = xText.toUpperCase().indexOf ( pSearchString.toUpperCase(), iStart + pSearchString.length ) ;
	}
	return xText ;
} // fine stringReplace
function js_set_cookie(c_name,value,expire_seconds) {
	var exdate = new Date();
	var ls_cookie = c_name+ "=" +escape(value);
	if (expire_seconds) {
		exdate.setTime(exdate.getTime()+expire_seconds*1000);
		ls_cookie = ls_cookie +  ";expires="+exdate.toUTCString();
	}
	document.cookie = ls_cookie ;
} // fine js_set_cookie
function js_get_cookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
} // fine js_get_cookie
