function toggle(what,state) {
  var e = document.getElementById(what);
  if ( e.style.display == "none" ) {
    e.style.display = "";
  }
  else {
    e.style.display = "none";
  }
}

// Checkboxes have issues because onClick does not work right
// If checked it's visible. If not, it's not visible.

function checkboxToggle(checkbox,target) {
  var the_target = document.getElementById(target);
  if ( checkbox.checked == true ) {
    the_target.style.display = "";
  }
  else {
    the_target.style.display = "none";
  }
}


function widgetClick(id) {

  var nextTR = $('#' + id).next('tr');
  var nextId = $(nextTR).attr("id");
  var currentSetting = $(nextTR).css("display");
  
  if (currentSetting == "none") {
    while (nextId.indexOf(id) != -1) {
      $(nextTR).attr("style","display:");
      var nextTR = $('#' + nextId).next('tr');
      var nextId = $(nextTR).attr("id");
    }
    $('#' + id + '_widget').attr("src","/images/admin/icons/widgetOpen.gif");
    PHPSession('set',id,"open");
  }
  else {
    while (nextId.indexOf(id) != -1) {
      $(nextTR).attr("style","display:none");
      var nextTR = $('#' + nextId).next('tr');
      var nextId = $(nextTR).attr("id");
    }
    $('#' + id + '_widget').attr("src","/images/admin/icons/widgetClosed.gif");
    PHPSession('unset',id);
  }
}

focusEach = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" focusEach";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" focusEach\\b"), "");
		}
	}
}

