/*Riempe il comboBox
Parametri : idtag  e arrayOpzioni e valori 
text = testo primo item "Select .."
nascondi = true  (se l'array è vuoto il combo non viene visualizzato) */ 
function riempiCombo(idtag, arrayOpzioni , arrayValori, text  , nascondi){
if ( (arrayOpzioni.length == 0) && (nascondi) ) {
	idtag.style.display = "none";
}else{
	idtag.style.display = "block";
}
while (idtag.options.length > 0){
	idtag.options[(idtag.options.length - 1)] = null;
}
idtag.options[0]= new Option( text , '');
for (var i=1; i < (arrayOpzioni.length + 1); i++) {
	idtag.options[i]= new Option ( arrayOpzioni[(i-1)] , i);
	idtag.options[i].value = arrayValori [(i-1)];
}
}

function changeText(idtag, elem, text) {
 var idtag = document.getElementById (idtag);
 var myText = document.createElement(elem);
 idtag.innerHTML = text;
 if (idtag.hasChildNodes())
 {
	idtag.replaceChild (myText, idtag.firstChild);
 } else {
	idtag.appendChild (myText);
 }
}

/************ SHOW TOOLTIP ********/
function showTooltip(srcObj,message,distanzaX,distanzaY) {
	var pos;
	pos=findPos(srcObj);
	tooltip.style.left=pos[0] + srcObj.offsetWidth + distanzaX;
	tooltip.style.top=pos[1] + distanzaY;
	tooltip.style.display="block";
	tooltiptext.innerHTML=message;
}

function hideTooltip() {
	tooltip.style.display="none";	
}
	
function findPos(obj) {
	var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft;
			curtop = obj.offsetTop;
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			}
		}
		return [curleft,curtop];
}
/********************************/

// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame(f) {
   if (at_checkbrowser('FIREFOX','') ){
		new_height = f.contentWindow.document.body.parentNode.clientHeight + "px";
   } else if (at_checkbrowser('SAFARI','') ){
		new_height = f.contentWindow.document.body.offsetHeight + "px";
   } else {
		new_height = f.contentWindow.document.body.scrollHeight + "px";
   }
   f.style.height = new_height;
}



function getAllElementsByName(name, tagName)
{
	var elems = document.getElementsByTagName(tagName);
	var arr = new Array();
	for ( var i = 0; i < elems.length; i++ )
	{
		var elem = elems[i];
		if ( elem.getAttribute('name') == name )
		{
			arr.push(elem);
		}
	}
	return arr;
}


//Visualizza/Nasconde tutti gli elementi con nome  = name
//display_mode = "none" || display
function visualHide_ElementsByName(name , display_mode , tagName ){
	if(tagName=='')
	tagName='div';
	v = getAllElementsByName(name , tagName);
	for (i=0; i< v.length ; i++){
		v[i].style.display= display_mode;	
	}
}



function visualHide_ElementById (id , display_mode){
// Nasconde/esplode il div con id= id
//se passo display_mode ha priorità sennò controllo se è visibile o non e faccio l'azione contraria
	if (display_mode == 'y'){
		display = "block";
	}else if (display_mode == 'n') {
	display = "none";
	}else{
		if (document.getElementById(id).style.display == "none"){display="block";}
		else {	display="none"; }
	}
	document.getElementById(id).style.display = display;
}
