﻿// JScript File
// Seleziona o deseleziona tutti i checkbox della form
function Select_DeselectAllCheckBoxes(chkVal, idVal)
{
    var frm = document.forms[0];
    // Scorro tutti gli elementi
    for (i=0; i<frm.length; i++)
    {
        // Controllo la Checkbox dell'Header Template
        if (idVal.indexOf ('SelectAllCheckBox') != -1)
        {
            if (frm.elements[i].type == 'checkbox' && frm.elements[i].id.indexOf ('SelectAllCheckBox') == -1)
            {
                var tr = frm.elements[i].parentNode.parentNode;
                // Controllo se la checkbox principale e checked, 
                // quindi seleziono o deseleziono i checkbox della datagrid 
                if(chkVal == true)
                {
                    frm.elements[i].checked = true;
                    tr.className = "selected";
                }
                else
                {
                    frm.elements[i].checked = false;
                    tr.className = "deselected";
                }
            }
        }
    }
}

// Permette di evidenziare l'intera riga selezionata
function HighlightSelected(chk)
{
    var td = chk.parentNode; 
    if (td == null) 
        return; 
        
    var tr = td.parentNode;
    if (chk.checked)
    { 
        tr.className = "selected";
    } 
    else 
    { 
        tr.className = "deselected";
    } 
}

function Toggle( commId, imageId, path)
{
	var div = document.getElementById(commId);
	var GetImg = document.getElementById(imageId);

	if (div.style.display == 'none')
	{	
		div.style.display = 'block';
		GetImg.src = path + 'expand.gif';
	}
	else
	{	
		div.style.display = 'none';
		GetImg.src = path + 'collapse.gif';
	}
}

function toggleElement(id) 
{
  var cl = document.getElementById(id);

  if (cl != undefined) 
  {
      if (cl.className == 'visible')
        cl.className = 'hidden';
    else
        cl.className = 'visible';
  }
}

function toggleItem(id) 
{
  var cl = document.getElementById(id);

  if (cl != undefined) 
  {
	if (cl.style.display == 'none')
		cl.style.display = 'block';
	else
		cl.style.display = 'none';
  }
}

// Manage Tag Cloud
function weight_to_em(weight, min_weight, max_weight) {
    maxFontSize = 22; //26;
    minFontSize = 10; //8;

    x = (maxFontSize - minFontSize) * (weight - min_weight) / (max_weight - min_weight);
    if (max_weight - min_weight == 0)
	    x = 12;

    return Math.round(x + minFontSize) + "px";
}

function makeCloud() {
    cloud = document.getElementById("cloudtag");
    if(cloud == undefined)
        return;

    cloud.innerHTML = "";

    weightArray = [];
    for(key in cloudData) {
        el = cloudData[key];
        weight = parseInt(el[1], 10);
        if(weight > 0)
	    weightArray.push(weight);
    }

    weightArray.sort(function(a,b){return b-a;});

    ul = document.createElement("ul");
    ul.appendChild(document.createTextNode("\n"));
    for(key in cloudData){
        el = cloudData[key];
        fontSize = weight_to_em(el[1], weightArray[weightArray.length - 1], weightArray[0]);
        li = document.createElement("li");
        link = document.createElement("a");
        link.href = el[2];
        link.appendChild(document.createTextNode(el[0]));
        link.style.fontSize = fontSize;
        li.appendChild(link);
        ul.appendChild(li);
        ul.appendChild(document.createTextNode("\n"));
    }
    cloud.appendChild(ul);
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
           if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

// End Manage Tag Cloud
