/*
Author: Stuart N. Wrigley
AMIDA: Augmented Multi-party Interaction with Distance Access
(c) 2007,2008 University of Sheffield
*/

/*
var hide=true;

function toggleRows(tableId, rowClass, linkTag){
  var tbl = document.getElementById(tableId);
  if (tbl!=null) {
    var len = tbl.rows.length;
    var vStyle = (hide)? "none":"";
  
    for(i=1; i< len; i++)
      if (tbl.rows[i].className==rowClass)
        tbl.rows[i].style.display = vStyle;
  
    if(hide)
      linkTag.innerHTML = "show "+rowClass;
    else
      linkTag.innerHTML = "hide "+rowClass;
    hide=!hide;
  }
}
*/

function toggleRows(tableId, rowClass, linkTag){
  var tbl = document.getElementById(tableId);
  if (tbl!=null) {
    for(i=1; i< tbl.rows.length; i++) {
      row=tbl.rows[i];
      if (row.className==rowClass) {
        if ( row.style.display != 'none' ) {
          row.style.display = 'none';
          linkTag.innerHTML = "show "+rowClass;
        }
        else {
          row.style.display = '';
          linkTag.innerHTML = "hide "+rowClass;
        }
      }
    }
  }
}


function toggleRowAndImage(rowId, parentRowId, linkTag, imageFilename){
  var row = document.getElementById(rowId);
  if ( row.style.display != 'none' ) {
    row.style.display = 'none';
    linkTag.innerHTML = "<img src=\"images/"+imageFilename+"_right.gif\" border=\"0\">";
    document.getElementById(parentRowId).style.background='';
  }
  else {
    row.style.display = '';
    linkTag.innerHTML = "<img src=\"images/"+imageFilename+"_down.gif\" border=\"0\">";
    document.getElementById(parentRowId).style.background='ffffcb'; // I don't like hardcoding this but not sure best way to fix
  }
}



Array.prototype.unique = function () {
	var r = new Array();
	o:for(var i = 0, n = this.length; i < n; i++)
	{
		for(var x = 0, y = r.length; x < y; x++)
		{
			if(r[x]==this[i])
			{
				continue o;
			}
		}
		r[r.length] = this[i];
	}
	return r;
}



Array.prototype.contains = function (item) {
	for(var i = 0, n = this.length; i < n; i++)
	  if (this[i]==item) return true;
	return false;
}


function sortNumber(a,b) {
  return a - b;
}


function humanSizeToBytes(item) {
  var text=item.value;
  var multiplier=1;
  text=text.toLowerCase();
  var siIndex=text.indexOf("m");
  if (siIndex>-1) {
    text=text.substring(0,siIndex);
    multiplier=1024*1024;
  }
  siIndex=text.indexOf("k");
  if (siIndex>-1) {
    text=text.substring(0,siIndex);
    multiplier=1024;
  }
  siIndex=text.indexOf("g");
  if (siIndex>-1) {
    text=text.substring(0,siIndex);
    multiplier=1024*1024*1024;
  }
  item.value=text*multiplier;
}

