function disabilitacampi(form)
{
    for(i=0; i < form.elements.length; i++){
      if(form.elements[i].type!="hidden") {
       form.elements[i].disabled="true";
      }
    }
}

function riabilitacampi(form)
{
    for(i=0; i < form.elements.length; i++){
      if(form.elements[i].type!="hidden") {
       form.elements[i].disabled=false;
      }
    }
}

function MM_swapImgRestore() 
{
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() 
{
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function verify( msg, url )
{
if ( confirm( msg ) )
{
    this.location = url;
}
}

function popup ( url, target, w, h, scroll, resize, x, y ) 
{
    if( !x ) x=4;
    if( !y ) y=4;
    if( !h ) h=500;
    if( !w ) w=400;
	if( !scroll ) scroll=1;
	if( !resize ) resize=1;
    numbers = "width="+w+", height="+h+", left="+x+", top="+y+",toolbar=no,menubar=no,personalbar=no,scrollbars="+scroll+",resizable="+resize+"";
    newWin = window.open ( url, target, numbers );
    return false;
}

function SwitchCharset()
{
    CharsetSwitch.submit();
}

function totalup(campo){
beta = document.getElementsByTagName('input')(campo);
	for(i = 0; i < beta.length; i++) {
		document.getElementsByTagName('input')(campo)[i].value++;
	}
}

function totaldown(campo){
beta = document.getElementsByTagName('input')(campo);
	for(i = 0; i < beta.length; i++) {
		document.getElementsByTagName('input')(campo)[i].value--;
	if ( document.getElementsByTagName('input')(campo)[i].value < 0 ) {
		document.getElementsByTagName('input')(campo)[i].value=0;
	}
}
}

function Votoup(campo){
document.getElementsByName(campo)[0].value++;
}

function Votodown(campo){
document.getElementsByName(campo)[0].value--;
if ( document.getElementsByName(campo)[0].value < 0 ) {
document.getElementsByName(campo)[0].value=0;
}
}

function controlNum(campo){
if ( isNaN(document.getElementsByName(campo)[0].value) == true ) {
document.getElementsByName(campo)[0].value=0;
}
}

function GetValue( CONTROL, gruppi, label){
	var VarValue = "";
	var ArrValues;
		for(var i = 0;i < document.getElementById(CONTROL).length; i++){
			if (document.getElementById(CONTROL).options[i].selected == true)
			{
				VarValue += ( document.getElementById(CONTROL).options[i].id + '  ');
			}
		}
	if ( VarValue == "" ) VarValue = ( label ) ? label : "";
	document.getElementById(gruppi).firstChild.data = VarValue;
}

function controlread( campo, gruppi ){
	if ( document.getElementById(campo).value == '') document.getElementById(campo).options[0].selected = true;
	GetValue( campo, gruppi)
}

/////////////controllo validità date
function isDate(DateToCheck){
if(DateToCheck==""){return true;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
} 
else{
return false;
}
}//end function

function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;	
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function
function CheckDate(CONTROL){ 
//var strFormat = theForm.DateFormats.options[theForm.DateFormats.selectedIndex].value; 
//if(!isDate(CONTROL.value)){ 
if(!isDate(CONTROL)){ 
//alert("Invalid Date") 
return true; 
} 
//CONTROL.value = FormatDate(CONTROL.value,strFormat); 
} 


