// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// form.js
//
// copyright (c) 2006-2009 drow <drow@bin.sh>
// all rights reserved.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// client form, kill submit event

function client_form (form_id) {
  Event.observe(form_id,'submit', function (event) { event.stop(); });
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// select field

function selv (sel) {
  return sel.options[sel.selectedIndex].value;
}
function setv (sel,val) {
  for (i = 0; i < sel.options.length; i++) {
    if (sel.options[i].value == val) { sel.selectedIndex = i; break; }
  }
  return sel.selectedIndex;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// new select options

function new_options (select,list) {
  var marked = select.options[select.selectedIndex].value;

  $A(select.getElementsByTagName('option')).each(function (opt) {
    Element.remove(opt);
  });
  var idx = 0; list.each(function (opt) {
    if (opt.value == marked) idx = select.options.length;
    Element.insert(select,opt);
  });
  select.selectedIndex = idx;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// field cookie

function field_cookie (prefix,field) {
  var name = prefix + '.' + field.name;

  if (field.type == 'checkbox') {
    value = (field.checked) ? '1' : '0';
  } else if (field.type == 'select-one') {
    value = selv(field);
  } else {
    value = field.value;
  }
  set_cookie(name,value,'never','default','default');
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

