function el(id)
{
return document.getElementById(id);
}

function clearFormFields(section_id)
{//clear all the input type values in a section
var l = form2AA(section_id);
clearFields(l); 
}

function clearFields(fl)
{//given an aa list of fields.. sets values to "";
 
var o;
var i;

for(i in fl) 
  {
  o = document.getElementById(i)
  if(o)
     o.value = "";
  }//for
 
}//func



function setFields(fl)
{//given an aa list of fields.. sets values to "";
 //[field-name] = "value";
var o;
var i;

for(i in fl) 
  {
  o = document.getElementById(i)
  if(o)
     o.value = fl[i];
  }//for
 
}//func

function lprops(obj)
{
var r = "";
var o;
for(i in obj)
  {
  r += i+" = "+obj[i]+"\n";  
  }//for
  
return r;
}//func


function formatCurrency(num,hide_cents) {
res = 0;
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
res = ((sign)?'':'-') + '$' + num;
if(!hide_cents)
  res +=  '.' + cents;
return (res);
}




function form2AA_workhorse(section_id,a,tag)
{
//a = associate array to append values to
var s = document.getElementById(section_id)
var f = s.getElementsByTagName(tag);
var flen = f.length;
var o;
var id;

for(i=0; i < flen; i++) // has some extra fields if use for(i in f)
  {
  o = f[i]
  id = o.id;
  o = document.getElementById(id);
  a[id] = o.value; 
  }//for

}//func


function form2AA(section_id)
{//converts input values found in scope of id "section_id"
 //to an AA object.
var r = new Object();

form2AA_workhorse(section_id, r, 'input'); 
form2AA_workhorse(section_id, r, 'textarea');
 
return r;
}//func


function setFormFieldProps(aa,code)
{// aa = [field-name] = 'value'; // this is kinda weird but we're using it for now.
 // code = ".onkeyup = 'abc';";
var i,o;
for(i in aa)
  {
  o = document.getElementById(i);
  if(o)
    {
    eval("o"+code);
    }
  }//for
}//func


function stripTags(t)
{// 2007.11.20
 // http://zamov.online.fr/EXHTML/DHTML/DHTML_983246.html
 
 if(t)
   return t.replace(/(<([^>]+)>)/ig,"");
 else
   return t;
 
}//func


function getEvent(e)
{
 if (!e) var e = window.event;
 return e;
}

function getKey(e)
{//http://www.quirksmode.org/js/introevents.html
var code;

if (e.keyCode) code = e.keyCode;
	else 
if (e.which) code = e.which;
	
return code;
}


function getElementsByClass(searchClass,node,tag) {
// http://www.dustindiaz.com/top-ten-javascript/
// 2007.12.04
//
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
