function popup(mylink, windowname, width, height ) {
  if (! window.focus)return true;
    var href;
    if (typeof(mylink) == 'string')
      href=mylink;
    else
      href=mylink.href;
    window.open(href, windowname, 'width=' + width + ' ,height=' + height + ' ,scrollbars=yes');
  return false;
}

function popupNoScrollbars(mylink, windowname, width, height ) {
	  if (! window.focus)return true;
	    var href;
	    if (typeof(mylink) == 'string')
	      href=mylink;
	    else
	      href=mylink.href;
	    window.open(href, windowname, 'width=' + width + ' ,height=' + height + ' ,scrollbars=no');
	  return false;
	}

function cambiaSemaforo(divSemaforoDaVisualizzare, divSemaforoDaNascondere, divCollegato, visualizzaDivCollegato, proprieta, valore){
  var elSdv = document.getElementById(divSemaforoDaVisualizzare);
  elSdv.style.display="inline";

  var elSdn = document.getElementById(divSemaforoDaNascondere);
  elSdn.style.display="none";
  
  if (valore != null) proprieta.value = valore;

  var elDc = document.getElementById(divCollegato);
  if (visualizzaDivCollegato == 'true') {
  	elDc.style.visibility="visible";
  } else {
    elDc.style.visibility="hidden";
  }
}

function cambiaSemaforo2(divSemaforoDaVisualizzare, divSemaforoDaNascondere, divCollegatoDaVisualizzare, divCollegatoDaNascondere, proprieta, valore){
  var elSdv = document.getElementById(divSemaforoDaVisualizzare);
  elSdv.style.display="inline";
  
  var elCSdv = document.getElementById(divCollegatoDaVisualizzare);
  elCSdv.style.display="inline";

  var elSdn = document.getElementById(divSemaforoDaNascondere);
  elSdn.style.display="none";
  
  var elCSdn = document.getElementById(divCollegatoDaNascondere);
  elCSdn.style.display="none";
  
  if (valore != null) proprieta.value = valore;	

}


function HideDiv(ID){
	document.getElementById(ID).style.display="none";
}
		
function ShowDiv(ID){
	document.getElementById(ID).style.display="";
}

function ShowHideDiv(ID){
	if(document.getElementById(ID).style.display==""){
		HideDiv(ID);
	}else{
		ShowDiv(ID);
	}
}


function ShowTr(ospedale,reparto) {
	
	var trs = document.getElementsByTagName('tr');	//recupero tutti i tag <tr>
	for(i=0;i<trs.length;i++) {
	
		if ( (ospedale=='') && (reparto=='') ) {						//nessuna ricerca
			trs[i].style.display="";
		} else {
			if ( ( trs[i].id.search('ttt') != -1 )  ) {			//elimino le righe di intestazione
				trs[i].style.display="none";
			}
			if ( (ospedale!='') && (reparto=='') ) {					//ricerca per ospedale
				if ( ( trs[i].id.search('zzz') != -1 ) && ( trs[i].id.search(ospedale) != -1 ) ) {
					trs[i].style.display="";
				} else {
					trs[i].style.display="none";
				}																								//fine ricerca per ospedale
			} else { 
				if ( (ospedale=='') && (reparto!='') ) {				//ricerca per reparto
					if ( ( trs[i].id.search('zzz') != -1 ) && ( trs[i].id.search(reparto) != -1 ) ) {
						trs[i].style.display="";
					} else {
						trs[i].style.display="none";
					}																								//fine ricerca per reparto																							//fine ricerca per ospedale
				} else {	//  (ospedale!='') && (reparto!='')		//ricerca per ospedale e reparto
					if ( ( trs[i].id.search('zzz') != -1 ) && ( trs[i].id.search(ospedale) != -1 ) && ( trs[i].id.search(reparto) != -1 ) ) {
						trs[i].style.display="";
					} else {
						trs[i].style.display="none";
					}																								//fine ricerca per ospedale e per reparto
				}
			}
		}
		if ( ( trs[i].id.search('zzz') == -1 ) && ( trs[i].id.search('ttt') == -1 )  ) {
			trs[i].style.display="";
		}
	}
}

function SetLinks(ospedale, reparto) {

	var links = document.getElementsByName('dynamiclink');

	for(i=0;i<links.length;i++) {
		var link = links[i].getAttribute('href');
		if ( (ospedale == "" ) && (reparto == "" ) ) {		//nessun ospedale e reparto selezionato
			if ( link.indexOf("&osp") != -1) {										//annullo la selezione precedente
				links[i].setAttribute('href', link.substring(0, link.indexOf("&osp")) );
			}
		} else {
			if ( link.indexOf("&osp") == -1) {
				links[i].setAttribute('href', link + '&ospedale=' + ospedale + '&reparto=' + reparto);
			} else {
				var string = link.substring(0, link.indexOf("&osp"));
				links[i].setAttribute('href', string + '&ospedale=' + ospedale + '&reparto=' + reparto);
			}
		}
	}


}


function selOspRep() {
	ospBox = document.forms[0].ospedalerisorsa;
	repBox = document.forms[0].repartorisorsa;
	ospselected = ospBox.options[ospBox.selectedIndex].value;
	repselected = repBox.options[repBox.selectedIndex].value;
	ShowTr(ospselected,repselected);
	SetLinks(ospselected, repselected);
}



function en_disableCheckBox(ID, IDCB){
	if(document.getElementById(ID).checked){
		document.getElementById(IDCB).disabled = false;
	}else{
		document.getElementById(IDCB).disabled = true;
	}
}


function SelectMoveRows(IDSS1,IDSS2)
{
		SS1 = document.getElementById(IDSS1);
		SS2 = document.getElementById(IDSS2);		
    var SelID='';
    var SelText='';
    // Move rows from SS1 to SS2 from bottom to top
    for (i=SS1.options.length - 1; i>=0; i--)
    {
        if (SS1.options[i].selected == true)
        {
            SelID=SS1.options[i].value;
            SelText=SS1.options[i].text;
            
            var newRow = new Option(SelText,SelID, true);
            SS2.options[SS2.length]=newRow;
            SS1.options[i]=null;
        }
    }
    SelectSort(SS2);
}
function SelectSort(SelList)
{
    var ID='';
    var Text='';
    for (x=0; x < SelList.length - 1; x++)
    {
        for (y=x + 1; y < SelList.length; y++)
        {
            if (SelList[x].text > SelList[y].text)
            {
                // Swap rows
                ID=SelList[x].value;
                Text=SelList[x].text;
                SelList[x].value=SelList[y].value;
                SelList[x].text=SelList[y].text;
                SelList[y].value=ID;
                SelList[y].text=Text;
            }
        }
    }
}

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


