/* common functions for v2.floodalert.org */

/* allow multiple submit buttons control over actions on same form */
function submitter(frm,action,method) {
  if (frm == null) frm = 'qform';
  var qform = document.getElementById(frm);
  if (action != null) qform.action = action;
  if (method != null && method != 'null') qform.method = method;
  
  debounce_submit(qform);
}

/* don't let a user hit a button twice */
function debounce_submit(qform) {
  if (document.all||document.getElementById){
    //hunt down "submit" style buttons
    for (i=0;i<qform.length;i++){
      var btn=qform.elements[i];
      if(btn.type.toLowerCase()=="submit"||
	 btn.type.toLowerCase()=="button") {
	//disable em
	btn.disabled=true
	}
    }
  }
  qform.submit();
}

/* prevent inappropriate actions without confirmation */
function ok_submitter(frm,action,message,method) {
  if (message == null) message = 'Please confirm';
  if ( confirm (message) ) {
    submitter(frm,action,method);
  }
}

/* select an html page */
function submitHtml(frm,pageChoice) {
    var qform = document.getElementById(frm);
    qform.page.value = pageChoice;
    /* confirm('submitHtml is working:' + qform.page.value); */
    debounce_submit(qform);
}

/* toggle the previeux state */
/* there are two choices here:
     resubmit each time, and get the (table or image) data fresh,
     and deliver both modes each time and let javascript render on/off
     I lean towards the former right now because of the images.
  */
function togglePrevieux(frm) {
    var qform = document.getElementById(frm);
    debounce_submit(qform);
}

