/*
	getObj
	Nuova versione della findObj.
	http://www.quirksmode.org/js/dhtmloptions.html
*/
function getObj( name )
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
	}
}//getObj
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == name)
			foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}//getObjNN4





/*
	findObj
	Cerca un oggetto nel DOM di un documento. Testato con Internet
	Explorer, Mozilla/Firefox/Netscape, Opera.

	oName:
		ID dell'oggetto da cercare.

	oFrame:
		ID del frame da utilizzare come base della ricerca. Se non
		viene fornito, viene utilizzato il frame corrente.

	oDoc:
		ID del documento da utilizzare come base della ricerca. Se
		non specificato, viene utilizzato il documento corrente.

	returns:
		L'oggetto trovato (se c'è), oppure NULL in caso contrario.
*/
function findObj( oName, oFrame, oDoc )
{
    /* this function is slightly bigger than the DreamWeaver
    function but is more efficient as it can also find
    anchors, frames, variables, functions, and check through
    any frame structure

    if not working on a layer, document should be set to the
    document of the working frame
    if the working frame is not set, use the window object
    of the current document
    WARNING: - cross frame scripting will cause errors if
    your page is in a frameset from a different domain */
    if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else {
        oDoc = window.document; } }

    //check for images, forms, layers
    if( oDoc[oName] ) { return oDoc[oName]; }

    //check for pDOM layers
    if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }

    //check for DOM layers
    if( oDoc.getElementById && oDoc.getElementById(oName) ) {
        return oDoc.getElementById(oName); }

    //check for form elements
    for( var x = 0; x < oDoc.forms.length; x++ ) {
        if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }

    //check for anchor elements
    //NOTE: only anchor properties will be available,
    //NOT link properties!
    for( var x = 0; x < oDoc.anchors.length; x++ ) {
        if( oDoc.anchors[x].name == oName ) {
            return oDoc.anchors[x]; } }

    //check for any of the above within a layer in layers browsers
    for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
        var theOb = findObj( oName, null, oDoc.layers[x].document );
            if( theOb ) { return theOb; } }

    //check for frames, variables or functions
    if( !oFrame && window[oName] ) { return window[oName]; }
    if( oFrame && oFrame[oName] ) { return oFrame[oName]; }

    //if checking through frames, check for any of the above within
    //each child frame
    for( var x = 0; oFrame && oFrame.frames &&
      x < oFrame.frames.length; x++ ) {
        var theOb = findObj( oName, oFrame.frames[x],
          oFrame.frames[x].document ); if( theOb ) { return theOb; } }

    return null;
}//findObj





/*
	getCheckBox
	Legge lo stato di un checkbox.

	checkBox:
		checkbox input da controllare.

	returns:
		TRUE se il checkbox è selezionato, FALSE altrimenti.
*/
function getCheckBox( checkBox )
{
	return checkBox.checked;
}//getCheckBox





/*
	validateSelectValue
	Tenta la validazione di una select. Il controllo è
	considerato valido se il suo contenuto non è impostato al
	valore passato.

	select:
		Controllo SELECT controllare.

	value:
		Valore da utilizzare come valore errato.

	returns:
		TRUE se il controllo è validato, FALSE altrimenti.
*/

function validateSelectValue( select, value )
{
	return select.options[select.selectedIndex].value != value;
}//validateSelectValue





/*
	validateTextControl
	Tenta la validazione di un textfield o di una textarea.
	Il controllo è considerato valido se il suo contenuto è
	diverso dalla stringa vuota.

	textControl:
		textfield o textarea da controllare.

	returns:
		TRUE se il controllo contiene qualcosa, FALSE altrimenti.
*/

function validateTextControl( textControl )
{
	return textField.value.Trim() != "";
}//validateTextControl





// Ottiene un oggetto indipendentemente dal browser utilizzato
function getObj(name)
{
	if (document.getElementById)
		return document.getElementById(name);
	else if (document.all)
		return document.all[name];
	else if (document.layers)
		return document.layers[name];
}//getObj





// Apre una finestra popup
function openWin(nomefinestra, url, larghezza, altezza, barre, ridimensione, centrato)
{
	option = "toolbar=no,width=" + larghezza + ",height=" + altezza + ",resizable=" + ridimensione + ",scrollbars=" + barre;
	if(centrato == 1)
	{
		leftpos = screen.width ? (screen.width - larghezza) / 2 : 0;
		toppos = screen.height ? (screen.height - altezza) / 2 : 0;
		option = option + ",left=" + leftpos + ",top=" + toppos;
	}
	window.open(url, nomefinestra, option);
}//openWin





// Limita ad m il n. di caratteri della textarea f indicando i caratteri rimanenti nel textbox c
function txtKey(f, c, m)
{
	if (f.value.length > m)
	{
		f.value = f.value.substring(0, m);
		charleft = 0;
	}
	else charleft = m - f.value.length;
	c.value = charleft;
}//txtKey





// Aggiunge un collegamento nei bookmark
function CreateBookmarkLink(url, title)
{
	if(window.sidebar)						// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	else if(window.external)				// IE Favorite
		window.external.AddFavorite(url, title);
	else if(window.opera && window.print)	// Opera Hotlist
		return true;
}//CreateBookmarkLink





// nasconde un elemento
function hideElement( element )
{
	element.style.display = 'none';
}//hideElement





// mostra un elemento
function showElement( element )
{
	element.style.display = '';
}//showElement
