function gfTrunc(lrValue) {
	lsStr	= new String(lrValue);
	if (lsStr.indexOf(',') >= 0) {
		return	parseInt(lsStr.substr(0, lsStr.indexOf(',')));
	} else {
		if (lsStr.indexOf('.') >= 0) {
			return	parseInt(lsStr.substr(0, lsStr.indexOf('.')));
		} else {
			return parseInt(lsStr);
		}		
	}
}

function gfArrotonda(lrValue, liDigits) {
	return( Math.round(parseFloat(lrValue * Math.pow(10, liDigits))) / Math.pow(10, liDigits) );
}

function gfFormattaNumero(lrNumber, liDigits){
	var lsRet		= "";
	var liDots		= 0;
	var liInt		= 0;
	var lsDecimal	= "";
	var	laBuff;
	var lsNumber	= new String(gfArrotonda(lrNumber, liDigits));

	laBuff	= lsNumber.split('.');
	liInt	= parseFloat(laBuff[0]);
	while (liInt >= 1000) {
		liInt /= 1000;
		liDots++;
	}
	
	while (liDots > 0) {
		lsRet		= '.' + laBuff[0].substr(laBuff[0].length - 3, 3) + lsRet;
		laBuff[0]	= laBuff[0].substr(0, laBuff[0].length - 3);
		liDots--;
	}
	
	if (laBuff[0] != '') {
		lsRet	= laBuff[0] + lsRet;
	}
	if (laBuff.length > 1) {
		lsDecimal	= laBuff[1];
	}
	while (lsDecimal.length < liDigits) {
		lsDecimal += '0';
	}
	if (liDigits > 0) {
		lsRet	+= ',' + lsDecimal;
	}
		
	return lsRet;
}

function gfStrIn(lsValue, laArray) {
	for (var liPos = 0; liPos < laArray.length; liPos++) {
		if (String(laArray[liPos]) == String(lsValue)) {
			return true;
		}
	}
	return false;
}

function gfValidateMail(lsMail) {
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	return email_reg_exp.test(lsMail);
}

function lsGetCurDateAccessFMT() {
	var	ldDate	= new Date();
	return '#' + (ldDate.getMonth() + 1) + '/' + ldDate.getDate() + '/' + ldDate.getFullYear() + ' ' + ldDate.getHours() + ':' + ldDate.getMinutes() + ':' + ldDate.getSeconds() + '#';
}

function lsGetCurDate() {
	var	ldDate	= new Date();
	return ldDate.getDate() + '/' + (ldDate.getMonth() + 1) + '/' + ldDate.getFullYear() + ' ' + ldDate.getHours() + ':' + ldDate.getMinutes();
}

function lsGetCurDateLog() {
	var	ldDate	= new Date();
	return ldDate.getFullYear() + '/' + (ldDate.getMonth() + 1) + '/' + ldDate.getDate() + ' ' + ldDate.getHours() + ':' + ldDate.getMinutes() + ':' + ldDate.getSeconds();
}

function lsGetCurYear() {
	var	ldDate	= new Date();
	return ldDate.getFullYear();
}
	
function gfOpenCenterWindow(lsUrl, liWidth, liHeight) {
	wndNew	= window.open(lsUrl, "_blank", "scrollbars=yes,height=" + liHeight + ", width=" + liWidth + ", top=" + ((window.screen.height - liHeight) / 2) + ", left=" + ((window.screen.width - liWidth) / 2));
}

function gfOpenCenterWindowWithNoBars(lsUrl, liWidth, liHeight) {
	wndNew	= window.open(lsUrl, "_blank", "scrollbars=yes,height=" + liHeight + ", width=" + liWidth + ", top=" + ((window.screen.height - liHeight) / 2) + ", left=" + ((window.screen.width - liWidth) / 2) + ",location=no,statusbar=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no");
}

function gfOpenCenterModalWindow(lsUrl, liWidth, liHeight) {
	wndNew	= window.showModalDialog(lsUrl, window, "status=no;scroll=yes;dialogheight=" + liHeight + "px; dialogwidth=" + liWidth + "px; dialogtop=" + ((window.screen.height - liHeight) / 2) + "px; dialogleft=" + ((window.screen.width - liWidth) / 2)) + "px";
}

function gfCheckFormEntry(lsValue) {
	var lsVal	= new String(lsValue);
	if ((lsVal == null) || (lsVal == undefined) || (lsVal == "undefined") || (lsVal == "null")) {
		return "";
	} else {
		return lsValue;
	}
}

function gfControllaApici(lsValue) {
	var lsStr	= new String(lsValue);
	var lsTmp	= new String("");
	
	for (li = 0; li < lsStr.length; li++) {
		if (lsStr.charAt(li) == "'") {
			lsTmp += "''";
		} else {
			lsTmp += lsStr.charAt(li);
		}
	}
	return lsTmp;
}

function gfControllaEscape(lsValue) {
	var lsStr	= new String(lsValue);
	var lsTmp	= new String("");
	// apici
	for (li = 0; li < lsStr.length; li++) {
		if (lsStr.charAt(li) == "'") {
			lsTmp += "\\'";
		} else {
			lsTmp += lsStr.charAt(li);
		}
	}
	// doppi apici
	lsStr	= lsTmp;
	lsTmp	= "";
	for (li = 0; li < lsStr.length; li++) {
		if (lsStr.charAt(li) == '"') {
			lsTmp += '&quot;';
		} else {
			lsTmp += lsStr.charAt(li);
		}
	}
	return lsTmp;
}

function gfStrCommaSep(lsStr, i)
{
	lsTmp	= new String(lsStr);
	if (lsTmp.indexOf(',', i) == -1)
	{
		return -1;
	}
	else
	{
		return lsTmp.indexOf(',', i);
	}
}

function gfAggiungiAPreferiti(lsUrl, lsDescrizione)
{
	if ((navigator.appName.indexOf("Microsoft", 0) >= 0) && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(lsUrl, lsDescrizione);
	}
	else
	{
		alert("Premi CTRL + D per aggiungere '" + lsDescrizione + "' ai Preferiti.")
	}
}