
// IMPOSTAZIONI GENERALI
// Colore selezione campi
var SEL_COLOR = '#ffff99';
// Colore DEFAULT campi
var DEF_COLOR = '#FFFFFF';

// CAMPO MAIUSCOLO
function setUcase(Campo)
{
	Campo.value = Campo.value.toUpperCase();
}


// SELEZIONA LA RIGA
function setPointer(theRow, theAction, Color)
{
    var theCells = null;
	var theDefaultColor;
	var thePointerColor = SEL_COLOR;
	// COLORE CHIARO
	if (Color == 0) theDefaultColor = '#dddddd';
	// COLORE SCURO
	if (Color == 1) theDefaultColor = '#cccccc';
	
    // 1. Pointer and mark feature are disabled or the browser can't get the row -> exits
	if (typeof(theRow.style) == 'undefined') return false;

    // 2. Recupera la riga corrente... 
    if (typeof(document.getElementsByTagName) != 'undefined')
        theCells = theRow.getElementsByTagName('td');
    else if (typeof(theRow.cells) != 'undefined') 
		theCells = theRow.cells;
	else
		return false;
	
    // 3. Recupera il colore corrente...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect = false;
    }

	// 4. Definisce il nuovo colore
    // 4.1 Current color is the default one
    //if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 1 && thePointerColor != '') newColor = thePointerColor;
    //}
    // 4.1.2 Current color is the pointer one
    //else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 0) newColor = theDefaultColor;
    //}
		
    // 5. Imposta il nuovo colore (e il puntatore) ...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
				theCells[c].style.cursor = "hand";
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
				theCells[c].style.cursor = "hand";
            }
        }
    } // end 5
	return true;
} 

// SELEZIONA IL CAMPO DI UN FORM
function setField(theField, theAction)
{
	var theDefaultColor = DEF_COLOR;
	var thePointerColor = SEL_COLOR;
	if (theAction == 0)	theField.style.backgroundColor = theDefaultColor;
	if (theAction == 1)	theField.style.backgroundColor = thePointerColor;
	return true;
}

// CAMBIA L'IMMAGINE DI UN LINK
function flipImage(theButton, theAction) 
{
	//alert (theButton.src);
	var NewImage;
	var N;
	
	NewImage = theButton.src;
	N = NewImage.lastIndexOf("_");
	NewImage = NewImage.substring(0,N);
	if (theAction == 0) theButton.src = NewImage + "_off.gif";
	if (theAction == 1) theButton.src = NewImage + "_on.gif";
	return true;
}

// EFFETTO PULSANTE SU TABELLA
function setButton(theRow, theAction)
{
    var theCells = null;
	var Color1;
	var Color2;

	if (theAction == 0) 
	{
		theRow.style.backgroundColor = '#EEEEEE';
		theRow.style.borderLeft = '2px solid #EEEEEE';
		theRow.style.borderTop = '2px solid #EEEEEE';
		theRow.style.borderRight = '2px solid #BBBBBB';
		theRow.style.borderBottom = '2px solid #BBBBBB';
	}
	if (theAction == 1) 
	{
		theRow.style.backgroundColor = '#CCCCCC';
		theRow.style.borderLeft = '2px solid #BBBBBB';
		theRow.style.borderTop = '2px solid #BBBBBB';
		theRow.style.borderRight = '2px solid #EEEEEE';
		theRow.style.borderBottom = '2px solid #EEEEEE';
	}
	return true;
}

// EFFETTO PULSANTE PREMUTO
function pressButton(theCell, theAction)
{
	var NewStr;
	var N;
	
	NewStr = theCell.getAttribute('id');
	N = NewStr.lastIndexOf("_");
	NewStr = NewStr.substring(0,N);
	if (theAction == 0) theCell.setAttribute('id',NewStr + "_n", 0);
	if (theAction == 1) theCell.setAttribute('id',NewStr + "_s", 0);
	return true;
}

var lastMouseX;
var lastMouseY;

// Recupera la posizione del mouse per aprire la finestra popup subito sotto
function setLastMousePosition(e) {
    if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
    lastMouseX = e.screenX;
    lastMouseY = e.screenY;
}

// MOSTRA LA DESCRIZIONE DELLE FUNZIONI DEL BOTTONE
function popupButton(theCell, Msg)
{
	document.writeln('<div id="barra" style="position:absolute; width:100px; height:20px; background-color:#123466; left:100px; top:100px; visibility:hidden"><table width="100" border="1" cellspacing="1" cellpadding="1" height="20"><tr><td><b>Segnalazioni tecniche</b></a></td></tr></table></div>');
	alert(document.getElementById("barra").style.visibility);
	alert(document.getElementById("barra").zIndex);
}