function Inserisci() {
	document.esegui.OP.value = 1;
	document.esegui.submit();
}

function Modifica(Valore) {
	document.esegui.ID.value = Valore;
	document.esegui.OP.value = 2;
	document.esegui.submit();
}

function Cancella(Valore) {
	var risposta = confirm("Confermare la cancellazione dell'elemento? L'operazione non potrà essere annullata!");
	if (risposta) {
		document.esegui.ID.value = Valore;
		document.esegui.OP.value = 3;
		document.esegui.submit();
	}
}

function Dettaglio(Valore) {
	window.location.href = Valore;
}

function CancellaImmagine(Valore, Campo) {
	var risposta = confirm("Confermare la cancellazione del file? L'operazione non potrà essere annullata!");
	if (risposta) {
		document.getElementById("PATH" + Campo).value = '';
		document.getElementById("VIS" + Campo).style.visibility = 'hidden';
		document.getElementById("DEL" + Campo).style.visibility = 'hidden';
	}
}

function ApriFinestra(Valore) {
	window.open(Valore, '_blank');
}

function ConfermaStato() {
	var risposta = confirm("Confermare il cambio di stato del sito?");
	if (risposta) {
		window.location.href = 'changestate.asp';
	}
}

function daysinmonth(lnMonth,lnYear) {
	var dt1, cmn1, cmn2, dtt, lflag, dycnt, lmn;
	lmn = lnMonth-1;
	dt1 = new Date(lnYear,lmn,1);
	cmn1 = dt1.getMonth();
	dtt=dt1.getTime()+2332800000;
	lflag = true;
	dycnt=28;
	while (lflag) {
		dtt = dtt + 86400000;
		dt1.setTime(dtt);
		cmn2 = dt1.getMonth();
		if (cmn1!=cmn2) {
			lflag = false;
		} else {
			dycnt = dycnt + 1;
		}
	}
	if (dycnt > 31) {dycnt = 31};
	return dycnt;
}

function setdays(sobjname, datemode) {

	var dobj = eval(sobjname + "d");
	var mobj = eval(sobjname + "m");
	var yobj = eval(sobjname + "y");
	var hobj = eval(sobjname);
	var monthdays = daysinmonth(mobj.options[mobj.selectedIndex].value,yobj.options[yobj.selectedIndex].value);
	var selectdays = dobj.length;
	var curdy = dobj.options[dobj.selectedIndex].value;
	if (curdy.length==1) {curdy = "0"+curdy};
	var curmn = mobj.options[mobj.selectedIndex].value;
	if (curmn.length==1) {curmn = "0"+curmn};
	var curyr = yobj.options[yobj.selectedIndex].value;
	if (selectdays > monthdays) {
   		for (var dlp=selectdays; dlp > monthdays; dlp--) {
       			dobj.options[dlp-1] = null;
		}
	}
	else if (monthdays > selectdays) {
   		for (var dlp=selectdays; dlp < monthdays; dlp++) {
       			dobj.options[dlp] = new Option(dlp+1,dlp+1);
		}
	}       
	if (curdy > monthdays) {
  		dobj.options[monthdays-1].selected = true;
   		curdy = monthdays;
	}
	if (datemode==1) {
   		var curdate = curmn+"/"+curdy+"/"+curyr;
	}
	else if (datemode==2) {
   		var curdate = curdy+"/"+curmn+"/"+curyr;
	}
	else if (datemode==3) {
   		var curdate = curyr+curmn+curdy;
	}
	else if (datemode==4) {
   		var cdate = new Date(curyr,curmn-1,curdy);
   		var curdate = cdate.toGMTString();
	}
	hobj.value = curdate;
}

function selTab(name, tsel, tot) {
	
	for (var i=1;i<=tot;i++) {
		if (i == tsel) {
			document.getElementById(name + i).className = 'TabGray';
		} else {
			document.getElementById(name + i).className = 'Tab';
		}
	}
}

function changeServizio(idServizio, id) {

	for (var i=1;i<=7;i++) {
		if (document.getElementById('Menu' + i) != null) {
			if (i == id) {
				if (document.getElementById('Menu' + i).className == 'Tab') {
					document.getElementById('Menu' + i).className = 'TabGray';
					document.getElementById('Img' + i).className = 'IcoMenu';
					makeRequestRet('servizi_inner.asp?IDS=' + idServizio,'DivCent');
				}
			} else {
				if (document.getElementById('Menu' + i).className != 'NoTab') {
					document.getElementById('Menu' + i).className = 'Tab';
					document.getElementById('Img' + i).className = 'IcoMenuBW';
				}
			}
		}
	}
}

function changeNews(idNews, id, tot) {
	
	for (var i=1;i<=tot;i++) {
		if (document.getElementById('News' + i) != null) {
			if (i == id) {
				if (document.getElementById('News' + i).className == 'BloccoM') {
					document.getElementById('News' + i).className = 'BloccoMImg';
					makeRequestRet('news_inner.asp?IDN=' + idNews,'DivCent');
				}
			} else {
				document.getElementById('News' + i).className = 'BloccoM';
			}
		}
	}
}

function getElementHeight(Elem) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(Elem);
    } else if (document.all) {
        elem = document.all[Elem];
    }
    xPos = elem.offsetHeight;
    return xPos;
}

function getElementWidth(Elem) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(Elem);
    } else if (document.all) {
        elem = document.all[Elem];
    }
    xPos = elem.offsetWidth;
    return xPos;
}

function getElementTop(Elem) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(Elem);
    } else if (document.all) {
        elem = document.all[Elem];
    }
    xPos = elem.offsetTop;
    return xPos;
}

function getElementLeft(Elem) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(Elem);
    } else if (document.all) {
        elem = document.all[Elem];
    }
    xPos = elem.offsetLeft;
    return xPos;
}
