function over(immagine, imgLocation) {
	immagine.src = imgLocation + immagine.id + "_over.${user.lang}.gif";
}

function out(immagine, imgLocation) {
	immagine.src = imgLocation + immagine.id + ".${user.lang}.gif";
}

function isBisestile (anno) {
	return (anno % 4 == 0 && (anno % 100 != 0 || anno % 400 == 0));
}

// per i dialog di conferma operazione
function go(percorso,f){
	f.method = "post";	
	f.action = percorso;
	f.submit();	
}

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 isBlank(campo) {
	if (campo.value!="") {
		return false;
	} return true;
}


function mostraErroreInLabel(strErr, errorLabelID) {
	if (document.getElementById(errorLabelID)) {
		document.getElementById(errorLabelID).innerText = strErr;
	} else {
		alert("Includi il file error_label.vm  [non trovo "+errorLabelID+"]");
	}
}

function showErr(campo) {
	// uguale a DO_ERR, cambia descrizione - TRANCIARE quanto prima
	var strErr = "Il campo " + (campo.id) + " è in un formato non corretto";
	if (document.getElementById("error")) {
		document.getElementById("error").innerText = strErr;
	} else {
		alert("Includi il file error_label.vm");
	}
	campo.focus();	
}

//-----------------------
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.indexOf('.') == -1)
		return isDigitOrDecimalSeparator(c)
	return isDigit(c)
}

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 controllaFormatoNumeroTelefonicoInternazionale(e){

	if (!e) {// NetScape
		var e = window.event;
	}
	
	if (e.which) // NetScape
		return (isDigit(e.which) ||  e.which == '43')
	
	if (e.keyCode) // Explorer
		return (isDigit(e.keyCode) ||  e.keyCode == '43')
}

function isDigit(c){		
	return (c >= asciiCode('0') && c <= asciiCode('9') || c == 8 || c == 9);
}

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 = ""+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 muoviVicinoAlMouse(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 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 switchBox(checkShell, idName, imagesLocation) {
  var vecchioValore = checkShell.getAttribute("stato");
  var nuovoValore = "true";
	
  if (vecchioValore=="true") {			
    nuovoValore="false";
  }
	
  checkShell.setAttribute("stato", nuovoValore);
  
  document.getElementById(idName).value = nuovoValore;
  checkShell.src = imagesLocation+"check" + nuovoValore + ".gif";
  checkShell.value = nuovoValore;
  return false;
}

function changeBackgroundTDImage(TDID, ImageFile){
	if (document.getElementById(TDID)) {
		document.getElementById(TDID).style.backgroundImage='URL(' + ImageFile + ')';
	} else {
		//alert("non ci sta l'ID: "+ImageFile )
	}
}

//----------------------------------

function controllaCaratteriSeparatori(str){
	var stringa = "";
	for (var i = 0; i<str.length; i++) {
		var c = str.charAt(i);
		if ( (c =='\\') || (c =='-') ){
			c = '/';
		}
		stringa += c;
	}
	return stringa;
}

//----------------------------------

function strToDate(stringa){

	if (stringa == "") return "";
	
	var str = controllaCaratteriSeparatori(stringa);
	var vettore = str.split('/');

	if (vettore.length == 3){
		var giorno = vettore[0];
		var mese = vettore[1];
		var anno = vettore[2];
		
		var laData = new Date(anno , mese-1 , giorno);
		
		var giornoData = laData.getDate();
		var meseData = laData.getMonth();
		var annoData = laData.getFullYear();
		
		if (giorno != giornoData){
			return null;
		}
		
		if (mese != (meseData+1)){
			return null;
		}
		
		if (anno != annoData){
			return null;
		}
		
		return laData;
		
	} else {
		return null;
	}
}

function toggleDisplayRiga(riga) {

	var rigaDaMostrare = document.getElementById(riga);

	try {
		rigaDaMostrare.style.display = rigaDaMostrare.style.display == "none" ? "table-row" : "none";
	} catch (isInternetExplorer) {
		rigaDaMostrare.style.display = rigaDaMostrare.style.display == "none" ? "block" : "none";
	}
}

function submitSuInvio(e, ilCampo) {
	var key = getKeyCode(e);
	
	if (key == 13) {
		return checkForm(ilCampo.form);
	}
	return false;
}

function posizionaVicinoAlClick(unDiv, e) {

	if (!e) {
		var e = window.event
	}
    var tempX = e.clientX + document.body.scrollLeft;
    var tempY = e.clientY + document.body.scrollTop;

	unDiv.style.left = tempX;
	unDiv.style.top = tempY;
	unDiv.style.display = "block";

}

function toggleMostraDiv(ilDiv) {
	ilDiv.style.display = ilDiv.style.display == "block" ? "none" : "block"; 
}

function showScreenshot(immagine, divSc, e) {
	var immagineDaMostrare = new Image();
	immagineDaMostrare.src = immagine;
	
	var ilDiv = document.getElementById(divSc);
	
	toggleMostraDiv(ilDiv);
	posizionaVicinoAlClick(ilDiv, e);
}

function hideScreenshot(divSc) {
	var ilDiv = document.getElementById(divSc);
	toggleMostraDiv(ilDiv);
}


