function gfGetStagione() {
	var	ldDate		= new Date();
	var liYearStart;
	if ((ldDate.getMonth() >= 1) && (ldDate.getMonth() <= 8))
	{
		liYearStart	= ldDate.getFullYear() - 1;
	} else {
		liYearStart	= ldDate.getFullYear();
	}
	var liYearEnd	= liYearStart + 1;
	return liYearStart + '-' + liYearEnd;
}

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 lsGetDateAccessFromString(lsData) {
	var liPos	= lsData.indexOf('/');
	var liDay	= 0;
	var liMonth	= 0;
	var liYear	= 0;
	if (liPos > -1)
	{
		var liPos1	= -1;
		liDay		= parseInt(lsData.substring(0, liPos));
		liPos1		= lsData.indexOf('/', liPos + 1);
		if (liPos1 > -1)
		{
			liMonth		= parseInt(lsData.substring(liPos + 1, liPos1));
			liYear		= parseInt(lsData.substring(liPos1 + 1, lsData.length));
			
		}
	}
	var ldDate	= new Date(liYear, liMonth - 1, liDay);
	return '#' + (ldDate.getMonth() + 1) + '/' + ldDate.getDate() + '/' + ldDate.getFullYear() + '#';
}

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 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 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")) {
		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;
}
