//**********************************************************************************
// FUNZIONI PER LA GESTIONE DEI LAYER
// Written by Alberto Picca
// (C) AreaSP 2009
//**********************************************************************************

var OP = (window.opera) ? 1:0; 
var IE4 = (document.all && !OP) ? 1:0; 
var IE5 = (IE4 && document.getElementById) ? 1:0; 
var NN4 = (document.layers) ? 1:0; 
var NN6 = (!IE4 && !NN4 && document.getElementById) ? 1:0; 
var NOT = (!OP && !IE4 && !IE5 && !NN4 && !NN6) ? 1:0;

var COLLAPSED_STYLE = "visibility:hidden;height:0px";
var GENERAL_OPEN_STYLE = "visibility:visible";

//************************************************************************************

function setLink(doc, link_name, value){
	if (NN4==1){ 
		//Netscape 4
		doc.layers[link_name].setAttribute("href", value);
	}else if(NN6==1){ 
		//Netscape 6.x, Firefox
		doc.getElementById(link_name).setAttribute("href", value);
	}else if ((IE5==1)||(IE4==1)){ 
		//Explorer		
		if (value == "#") {
			doc.all[link_name].setAttribute("href", getHref());
		}else{
			doc.all[link_name].setAttribute("href", value);
		}
	}	
}


function setAttribute(doc, div_name, attribute_name, attribute_value) {
    if (NN4 == 1) {
        //Netscape 4
        doc.layers[div_name].setAttribute(attribute_name, attribute_value);
        } else if (NN6 == 1) {
            //Netscape 6.x, Firefox
            doc.getElementById(div_name).setAttribute(attribute_name, attribute_value);
    } else if ((IE5 == 1) || (IE4 == 1)) {
    //Explorer
        doc.getElementById(div_name).setAttribute(attribute_name, attribute_value);
        //doc.all[div_name].setAttribute(attribute_name, attribute_value);
    }
}  

function getHref(){
	//applico il parametro ?isRefresh in modo tale che 
	//la servlet non effettui alcun aggiornamento dei dati
	// Risolve il problema del link "#"
	var tmp = new String(document.location);
    var str = tmp;
    if  (tmp.indexOf("?") == -1){
    	str = tmp + "?refresh=1"
    }else{
		if (tmp.indexOf("refresh=1") == -1){
			str = tmp + "&refresh=1";
		}
    }		
	return str;
}


function getHrefFromDoc(p_doc){
	//applico il parametro ?isRefresh in modo tale che 
	//la servlet non effettui alcun aggiornamento dei dati
	// Risolve il problema del link "#"
	var tmp = new String(p_doc.location);
    var str = tmp;
    if  (tmp.indexOf("?") == -1){
    	str = tmp + "?refresh=1"
    }else{
		if (tmp.indexOf("refresh=1") == -1){
			str = tmp + "&refresh=1";
		}
    }		
	return str;
}

function setImagePath(doc, img_name, path){
	if (NN4==1){ 
		//Netscape 4
		doc.layers[img_name].src 			= path
	}else if(NN6==1){ 
		//Netscape 6.x
		doc.getElementById(img_name).src 	= path;
	}else if ((IE5==1)||(IE4==1)){ 
		//Explorer
		doc.all[img_name].src 				= path;
	}
}

function setLayerPosition(doc, layerName, pLeft, pTop){
	if (NN4==1){ 
		//Netscape 4
		doc.layers[layerName].left 					= pLeft +'px';
		doc.layers[layerName].top 					= pTop  +'px';
	}else if(NN6==1){ 
		//Netscape 6.x, Firefox
		doc.getElementById(layerName).style.left 	= pLeft +'px';
		doc.getElementById(layerName).style.top 	= pTop  +'px';
	}else if ((IE5==1)||(IE4==1)){ 
		//Explorer
		doc.all[layerName].style.left 	= pLeft +'px';
		doc.all[layerName].style.top 	= pTop  +'px';
	}
}

function setLayerStatus(doc, layerName, visible){
	if (NN4==1){ 
		//Netscape 4
		doc.layers[layerName].visibility 				= ( ( visible ) ? "show" : "hide" )
	}else if(NN6==1){ 
		//Netscape 6.x, Firefox
		doc.getElementById(layerName).style.visibility 	= ( ( visible ) ? "visible" : "hidden" )
	}else if ((IE5==1)||(IE4==1)){ 
		//Explorer
		doc.all[layerName].style.visibility 			= ( ( visible ) ? "visible" : "hidden" );
	}
}

function setLayerValue(doc, layerName, value){
	if (NN4==1){ 
		//Netscape 4
		doc.layers[layerName].innerHTML 		= value
	}else if(NN6==1){ 
		//Netscape 6.x, Firefox
		doc.getElementById(layerName).innerHTML = value
	}else if (doc.all){ 
		//Explorer
		doc.all[layerName].innerHTML			= value;
	}
}


function setAllDivClosed(doc) {
    for (var index=1; index < 13;index++) {
        var nomeDiv = "sez" + index;
        setAttribute(doc, nomeDiv, "style", "");
        //setLayerStatus(doc, nomeDiv, false);
        setAttribute(doc, nomeDiv, "style", "visibility:hidden;heigth:0px"); 
    }
}



function isZero(str){
	return ((str=="0")||(str=="00"));
}
	
function isNull(str){
	if ((str=="0")||(str=="")||(str=="00")){
		return true;
	}else{
		return false;
	}
}

function isEmpty(str){
	return (str=="");
}

