///////////////////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS (used in all js modules)                                 //
///////////////////////////////////////////////////////////////////////////////
// There are certain shortcuts for accessing and setting form elements that  //
// I want to be standard and ALWAYS present when we develop web applications.//
// These helpers are listed below and short of these, there are many more    //
// that do need to be added.  If you wish to add your own, please let me know//
// by e-mailing me and explaining them - why you think they should be added  //
// and why they're beneficial.  Keep in mind, these are GENERIC functions,   //
// meaning, they need to work in any application!  Not just the one you're   //
// currently working on.  An example would be a function that fills any      //
// <select> form element that exists. Thanks... dtw                          //
///////////////////////////////////////////////////////////////////////////////
// objById() or gO() short for getObject or objectById()
function gO(x){return document.getElementById(x);}
// gS() short for getStyle
function gS(x){return gO(x).style;}
// iV() short for inputValue
function iV(x){return gO(x).value;}
// sIdx() short for selectedIndex property of provided select object
function sIdx(x){return gO(x).selectedIndex;}
// sV() short for selectedValue
function sV(x){
 var s_idx; return
 	(((s_idx = sIdx(x)) < 0) ? null : gO(x).options[s_idx].value);
}
// dWrt() short for document.write()
function dWrt(x){document.write(x);}
// sRpt() short for str_repeat()
function sRpt(i,m){for(var o=[];m>0;o[--m]=i);return(o.join(''));}
// sprintf() from Google
function sprintf() {
 var i=0, a, f=arguments[i++], o=[], m, p, c, x;
 while(f) {
  if(m = /^[^\x25]+/.exec(f))
   o.push(m[0]);
  else if(m=/^\x25{2}/.exec(f))
   o.push('%');
  else if(m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
   if(((a=arguments[m[1]||i++])==null)||(a==undefined))
    throw("Too few arguments.");
   if(/[^s]/.test(m[7]) && (typeof(a) != 'number'))
    throw("Expecting number but found " + typeof(a));
   switch(m[7]){
    case 'b': a=a.toString(2);break;
    case 'c': a=String.fromCharCode(a);break;
    case 'd': a=parseInt(a);break;
    case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
    case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
    case 'o': a = a.toString(8); break;
    case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
    case 'u': a = Math.abs(a); break;
    case 'x': a = a.toString(16); break;
    case 'X': a = a.toString(16).toUpperCase(); break;
   }
   a = (/[def]/.test(m[7])&&m[2]&&a>0?'+'+a:a);
   c = m[3]?m[3]=='0'?'0':m[3].charAt(1):' ';
   x = m[5]-String(a).length;
   p = m[5]?sRpt(c,x):'';
   o.push(m[4]?a+p:p+a);
  }else
   throw("Huh ?!");
  f=f.substring(m[0].length);
 }
 return o.join('');
}
