/*
function fadeFlash() {
  if (typeof Prototype == "undefined") {
    var expr = "var e = document.getElementById('flash'); if (e) { e.parentNode.removeChild(e); }";
  } else {
    var expr = "if ($('flash')) Effect.Fade('flash');";
  }
  setTimeout(expr, 10000);
} */

function fadeFlash() {
  var e = $("flash");
  if (e) {
    e.setStyle({'position': 'relative'});
    (new Fx.Styles(e, {'duration': 1000})).custom({'top': [0, 25]});
    setTimeout(function() { (new Fx.Styles(e, {'duration': 2000})).custom({'opacity': [1, 0]}); }, 5000);
  }
}
if (typeof Prototype == "undefined") {
  if (typeof window.onload == "function") { // if window.onload is already there, chain the call to fadeFlash
    var oldFunction = window.onload;
    window.onload = function() {
      oldFunction();
      fadeFlash();
    };
  } else {
    window.onload = fadeFlash;
  }
} else {
  Event.observe(window, 'load', fadeFlash);
}

function submitOnce(e) {
  e.disabled = true;
  e.form.submit();
  return false;
}

function lowerEmailCase(b) {
  if (b.form['email']) {
    b.form['email'].value = b.form['email'].value.toLowerCase();
  } 
  if (b.form['user[email]']) {
    b.form['user[email]'].value = b.form['user[email]'].value.toLowerCase();
  }
  return false;
};

function removeMsgBox(h) {
  document.cookie = "closed_msg_hash=" + h + "; path=/; max-age=" + (60*60*24*365);
  if (typeof(Prototype) == "undefined") {
    var e = document.getElementById("msgBox");
    e.parentNode.removeChild(e);
  } else {
    $("msgBox").hide();
  }
}

function selectedRadioValue(group) {
  var el = $$("input[name='" + group + "']").find(function(re) {return re.checked;});
  return el ? el.value : undefined;
}

function numbersonly(ev, dec) {
  if (ev.keyCode != 0) { return; }
  if (("0123456789").indexOf(String.fromCharCode(ev.charCode)) > -1) { return; }
  if (dec && (String.fromCharCode(ev.charCode) == ".") && (this.value.indexOf('.') == -1)) { return; }
  ev.stop();
}

function confirm_expire(camp_name) {
  return confirm("Are you sure you want to expire " +  camp_name + " ?");
}
