/* note: the brackets '[]' seem to prevent referencing with prototype $("aofs[]") */

function group_selectall() {
   col = $("groups[]");
   len = col.length;

   for(i=0; i < len; i++) {
     x = col.options[i].value;
     y = col.options[i].innerHTML;
     col.options[i].value = x + '|^|' + y;      
     col.options[i].selected = true;      
   }
}

function noWayBackMsg() {
	if ( $('IsPrivate_0').checked ) {
		alert("Please note that once you make this record public, you can no longer restrict access to it.");
	}
}

function prepareGroup() {
   col = $("groups[]");
   len = col.length;

   vsc = $('group_serialized');
   vsc.value = ""

   delimiter = ''
   for(i=0; i < len; i++) {
      if ( i > 0 ) delimiter = ','
      vsc.value = vsc.value + delimiter + col.options[i].value;
   }
}

function group_xMod() {
  col = $("groups[]");

  sl = col.selectedIndex;
  if ( sl != -1 && col.options[sl].value > "" ) {
    if ( col.options[sl].value!="" ) {
        col.options[sl]=null;
    } else {
      alert("Please select a Group first.");
      return false;
    }
  }

  prepareGroup();
  return false;
}

function group_addMod() {
  col = $("groups[]");

  idx = col.length

  if( Element.getStyle('allgroups', 'display') != "none") {
    colfrm = 'dummygroups';
  } else {
    colfrm = 'filtergroups';
  }
  
  sl = $(colfrm).selectedIndex;

  if ( sl != -1 && $(colfrm).options[sl].value ) {
    id  = $(colfrm).options[sl].value
    lbl = $(colfrm).options[sl].innerHTML.replace(/&amp;/, "&")
  } else {
    alert("Please select a Group first.");
    return false;
  }

  for(i=0; i < idx; i++) {
     if ( col.options[i].value == id ) {
       alert(lbl + ' already added to the list.')
       return false;
     }
  }

  if ( col ) {
    col.options[idx] = new Option(lbl, id);
  }

  prepareGroup();
  return false;
}

function groupPickerTestForEnter(e) {
  var keyCode = e.keyCode;
  if ( keyCode == 13 ) {
    $('group_filter_button').click();
    return false;
  } else {
    return true;
  }
}
