var CheckFieldsCode="";
if ( typeof(String.prototype.trim)=="undefined" )
{
	String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '')};
}
function CheckForm(Action, ShowLoading)
{
	if ( typeof(ShowLoading)=="undefined" || ShowLoading!=false )
		ShowLoading=true;
	if ( CheckFieldsCode.length )
	{
		eval("function CheckFields(){"+CheckFieldsCode+"return true;}");
		if  ( CheckFields() )
			if ( ShowLoading )
				FormSubmit(Action);
			else
				FormSubmit(Action, false);
	}
	else
		if ( ShowLoading )
			FormSubmit(Action);
		else
			FormSubmit(Action, false);
}
function FormSubmit(Action, ShowLoading)
{
	if ( typeof(ShowLoading)=="undefined" || ShowLoading!=false )
		ShowDivLoading();
	Form.action=Action;
	Form.target="_self";
	Form.submit();
}
function ShowDivLoading()
{
	if ( navigator.userAgent.indexOf("Gecko")==-1 && navigator.userAgent.indexOf("Netscape")==-1 )
	{
		hideLayer(getLayer("divForm"));
		setPageScrollY(0);
		showLayer(getLayer("divProgress"));
	}
}
function PopupImage(File, Title)
{
	Popup=window.open("about:blank", "image_window", "width=400,height=300,toolbar=0,scrollbars=0,resizable=1");
	document.forms["FormPopup"].elements["F"].value=File;
	if ( typeof(Title)!="undefined" )
		document.forms["FormPopup"].elements["T"].value=Title;
	document.forms["FormPopup"].target="image_window";
	document.forms["FormPopup"].submit();
	return false;
}
function PopupVideo(File)
{
	Popup=window.open("about:blank", "video_window", "width=600,height=400,toolbar=0,scrollbars=0,resizable=0");
	document.forms["FormPopup"].elements["F"].value=File;
	document.forms["FormPopup"].target="video_window";
	document.forms["FormPopup"].submit();
	return false;
}
function PopupDocument(File)
{
	Popup=window.open("about:blank", "document_window", "width=700,height=500,toolbar=1,scrollbars=1,resizable=1");
	Popup.focus();
	Popup.location.href=File;
	return false;
}
function NumChar(Nome, MaxLen)
{
	document.forms[0].elements['Resto_'+Nome].value=(MaxLen-document.forms[0].elements[Nome].value.length);
	if ( parseInt(document.forms[0].elements['Resto_'+Nome].value)<0 )
		document.forms[0].elements['Resto_'+Nome].value+=" (MAX "+MaxLen+"!)";
}
function MaxNumChar(Nome, MaxLen, Descrizione)
{
	document.forms[0].elements[Nome].value=document.forms[0].elements[Nome].value.trim();
	if (document.forms[0].elements[Nome].value.length>MaxLen)
	{
		alert("Non è possibile superare i "+MaxLen+" caratteri nel campo: "+Descrizione+"!");
		document.forms[0].elements[Nome].focus();
	}
}
function InitDate(Form, ElementBase)
{
	Oggi=new Date();
	Form.elements[ElementBase+"_day"].selectedIndex=Oggi.getDate();
	Form.elements[ElementBase+"_month"].selectedIndex=Oggi.getMonth()+1;
	CountValues=Form.elements[ElementBase+"_year"].options.length;
	for (i=0; i<CountValues; i++)
		if ( Form.elements[ElementBase+"_year"].options[i+1].value==Oggi.getFullYear() )
		{
			Form.elements[ElementBase+"_year"].selectedIndex=i+1;
			break;
		}
	if ( typeof(Form.elements[ElementBase+"_hour"])=="object" )
		Form.elements[ElementBase+"_hour"].selectedIndex=Oggi.getHours()+1;
	if ( typeof(Form.elements[ElementBase+"_minute"])=="object" )
		Form.elements[ElementBase+"_minute"].selectedIndex=Oggi.getMinutes()+1;
	if ( typeof(Form.elements[ElementBase+"_second"])=="object" )
		Form.elements[ElementBase+"_second"].selectedIndex=1;
	return false;
}
function ClearDate(Form, ElementBase)
{
	Form.elements[ElementBase+"_day"].selectedIndex=0;
	Form.elements[ElementBase+"_month"].selectedIndex=0;
	Form.elements[ElementBase+"_year"].selectedIndex=0;
	if ( typeof(Form.elements[ElementBase+"_hour"])=="object" )
		Form.elements[ElementBase+"_hour"].selectedIndex=0;
	if ( typeof(Form.elements[ElementBase+"_minute"])=="object" )
		Form.elements[ElementBase+"_minute"].selectedIndex=0;
	if ( typeof(Form.elements[ElementBase+"_second"])=="object" )
		Form.elements[ElementBase+"_second"].selectedIndex=0;
	return false;
}
function CheckDateAlways(Giorno, Mese, Anno)
{
	if ( Giorno.length<1 || Giorno.length>2 || Mese.length<1 || Mese.length>2 || Anno.length<1 || Anno.length>4 )
		return false;
	if ( Giorno.substr(0, 1)=="0" )
		Giorno=Giorno.substr(1, 1);
	if ( Mese.substr(0, 1)=="0" )
		Mese=Mese.substr(1, 1);
	Giorno=parseInt(Giorno);
	Mese=parseInt(Mese);
	Anno=parseInt(Anno);
	if ( Giorno<1 || Giorno>31 || Mese<1 || Mese>12 )
		return false;
	if ( Mese==2 )
	{
		if ( Giorno>29 || ( Giorno==29 && Anno%4!=0 ) )
			return false;
	}
	else if ( Mese==4 ||  Mese==6 ||  Mese==9 ||  Mese==11 )
	{
		if ( Giorno>30 )
			return false;
	}
	return true;
}
function CheckTime(Ora, Minuti)
{
	if ( Ora.length<1 || Ora.length>2 || Minuti.length<1 || Minuti.length>2 )
		return false;
	if ( Ora.substr(0, 1)=="0" )
		Ora=Ora.substr(1, 1);
	if ( Minuti.substr(0, 1)=="0" )
		Minuti=Minuti.substr(1, 1);
	Ora=parseInt(Ora);
	Minuti=parseInt(Minuti);
	if ( Ora<0 || Ora>23 || Minuti<0 || Minuti>59 )
		return false;
	return true;
}
function DeleteFile(File)
{
	if ( confirm("Sicuri di voler eliminare questo file?\n\n(Eventuali modifiche agli altri dati andranno perse)") )
	{
		document.forms["FormDeleteFile"].elements["File"].value=File;
		document.forms["FormDeleteFile"].submit();
	}
	return false;
}
function Annulla(ID, Start, TotalCount, Params, Go)
{
	location.replace(Go+"?ID="+ID+"&S="+Start+"&T="+TotalCount+"&P="+Params);
	return false;
}
function Chiudi(ID, Start, TotalCount, Params, Go)
{
	if ( window.opener!=null && typeof(window.opener)=="object" && !window.opener.closed )
		window.close();
	else
		window.location.replace(Go+"?ID="+ID+"&S="+Start+"&T="+TotalCount+"&P="+Params);
	return false;
}

