// per i dialog di conferma operazione

function go(percorso,f){
	f.method = "post";	
	f.action = percorso;
	return checkForm(f)	
}

function setComboVisibile(tipo) {
	var d = document.getElementsByTagName("SELECT");
	for (var i=0; i < d.length; i++) {
		var obj = d[i];
		obj.style.visibility = String(tipo);
	}
}


function checkAll(f,obj) {
	
	for (var i=0; i<f.length; i++) {
		if (f[i].type=="checkbox") {
			if (obj.checked) { 
				f[i].checked = true;
			} else { 
				f[i].checked = false;
			}
		}
	}	

}

function highlight(cella,stato) {

	var c = document.getElementById(cella);
	if (stato) {
		c.style.color = "#94bede";
	} else {
		c.style.color = "#666666";
	}
	
}

function seleziona(riga,stato) {

	if (stato) {
		//riga.style.cursor="hand";
		riga.className = "rigaHighlight";
	} else {
		riga.className = riga.id;
	}
}

function arap(divObj) {
	var mnu = document.getElementById(divObj);
	var xSource = window.event.x;	
	var ySource = window.event.y;	
	mnu.style.pixelTop = ySource-20;
	mnu.style.pixelLeft = xSource-20;
	mnu.style.visibility = "visible";	
}

function setCitta(f) {
	var prov = f.Provincia[f.Provincia.options.selectedIndex].text;
	if (f.citta.value.length==0)
		f.citta.value = String(prov).substr(0,prov.length-5);
}

function isBlank(campo) {
	if (campo.value!="") {
		return false;
	} return true;
}

//-----------------------
function controllaFormatoNumeroDecimale(e , src){
	if (!e) // NetScape
		var e = window.event;

	var c = '' // tasto premuto

	if (e.which) // NetScape
		c = e.which

	if (e.keyCode) // Explorer
		c = e.keyCode
	
	return caratterePermesso(c , src)
}

function caratterePermesso(c , src){
	if (src.value == "")
		return (c == asciiCode("-") || isDigitOrDecimalSeparator(c));

	if (src.value.indexOf('.') == -1)
		return isDigitOrDecimalSeparator(c)
	return isDigit(c)
}
function svuotaCampiForm(unForm){
	for (var i=0; i < unForm.length; i++){
		unForm[i].value='';
	}

}
function controllaFormatoNumeroIntero(e){

	if (!e) {// NetScape
		var e = window.event;
	}
	
	if (e.which) // NetScape
		return isDigit(e.which)
	
	if (e.keyCode) // Explorer
		return isDigit(e.keyCode)
}

function isDigit(c){		
	return (c >= asciiCode('0') && c <= asciiCode('9') || c == String.fromCharCode(String('9').charCodeAt(0)));
}

function isDigitOrDecimalSeparator(c){
	return (c == asciiCode('.')) || isDigit(c);
}

function asciiCode(c){
	return String(c).charCodeAt(0);
}

function selezionaCombo(idCombo, val) {
	
	var obj = document.getElementById(idCombo);	

	if (obj) {
		obj.value = String(val);
	}
	
}

function setComboVisibile(tipo) {
	var d = document.getElementsByTagName("SELECT");
	for (var i=0; i < d.length; i++) {
		var obj = d[i];
		obj.style.visibility = String(tipo);
	}
}

function setFieldValue(divId, label, valore) {
	document.getElementById(label).value = valore;
	document.getElementById(divId).style.display = "none";
}

function showCombo(fieldId) {
	var e = document.getElementById(fieldId);

	mouseX = e.offsetX;
	mouseY = e.offsetY;
	
	var divId = "div_"+fieldId;

	var allDivs = document.getElementsByTagName("DIV");
	for (var elemento=0; elemento<allDivs.length; elemento++) {
		if (allDivs[elemento].getAttribute("fastidioso")) {
			allDivs[elemento].style.display="none";
		}
	}

	var theDiv = document.getElementById(divId);
	
	theDiv.style.display = "block";
	theDiv.style.position = "absolute";
	if(mouseX) { // mozilla
    	theDiv.style.left = mouseX;
    	theDiv.style.top = mouseY;
	}
}

//----------------------------------
function mettiAlCentroDelloSchermo(unDiv){
	var centroFinestra = getCenterCoordinates();
	
	var wDiv = parseInt(unDiv.style.width);
	var hDiv = 100;

	unDiv.style.left = centroFinestra[0] - parseInt( wDiv / 2 );		
	unDiv.style.top = centroFinestra[1] - (hDiv / 2);
	unDiv.style.display = "block";
	
	return true
}
function mettiInAltoAlCentro(unDiv)
{
	mettiAlCentroDelloSchermo(unDiv);
	unDiv.style.top = 20;
}

function getCenterCoordinates() {
	var wBrowser = document.body.clientWidth;
	var hBrowser = document.body.clientHeight;
	var leftCornerY = getLeftCornerY();
	
	return new Array(wBrowser / 2, (hBrowser / 2) + leftCornerY);
}

function getLeftCornerY(){
	return document.body.scrollTop
}

function nascondiDiv(id) {
	var ilDiv = document.getElementById(id);
	ilDiv.style.display = "none";
}

function mostraDiv(id) {
	var ilDiv = document.getElementById(id);
	ilDiv.style.display = "block";
	mettiAlCentroDelloSchermo(ilDiv);
}
function mostraDivSenzaMettereAlCentroDelloSchermo(id) {
	var ilDiv = document.getElementById(id);
	ilDiv.style.display = "block";
}
function mostraDivInAlto(id)
{
	mostraDivSenzaMettereAlCentroDelloSchermo(id);
	unDiv = document.getElementById(id);
	mettiInAltoAlCentro(unDiv);
}

function copiaDiv(srcDivName, destDivName)
{
	srcDiv = document.getElementById(srcDivName);

	destDiv = document.getElementById(destDivName);
	destDiv.innerHTML = srcDiv.innerHTML;
}

function controllaCheckboxSelezionati(f) {
	var ok = false;
	
    for (var i=0; i<f.length; i++) {
    	if (f[i].type=="checkbox") {
    		ok = ok || f[i].checked;
    	}
    }	

	return ok;
}
