 function validate_form(){
 //alert('validate form');
 //alert(document.Ready_to_Post);
 var i,p,q,nm,test,num,min,max,errors='',gm=0,args=validate_form.arguments;
 for (i=0; i<(args.length-3); i+=4)
     {
     err_msg = args[i+3];
     test=args[i+2];
     val=find_this_object(args[i]);
     gmval = val;
     if (val)
        {
        nm=val.name;
        if ((val=val.value)!="")
           {
           if (test.indexOf('isEmail')!=-1)
              {
              //p=val.match(/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/);
              p=val.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/);
              if (p<1 || p==(val.length-1))
                 {
                 errors+='- '+err_msg+' must be a single, valid e-mail address\n';
                 }
              }
           if (test.indexOf('isState')!=-1)
              {
              p=val.match(/^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i);
              if (p<1 || p==(val.length-1))
                 {
                 errors+='- '+err_msg+' must be a US State\n';
                 }
              }
           if (test.indexOf('isZip5')!=-1)
              {
              p=val.match(/\d{5}/);
             if (p == null)
              	  {
                 errors+='- '+err_msg+' must be a 5 digit zip code\n';
                 }
              }
           if (test.indexOf('isZip4')!=-1)
              {
              p=val.match(/\d{4}/);
              if (p == null)
              	  {
                 errors+='- '+err_msg+' must be a 4 digit zip plus4 code\n';
                 }
              }
           if (test.indexOf('isDate')!=-1)
              {
              if (!isDate(val))
              	  {
                 errors+='- '+err_msg+' please enter a date in the format of MM/DD/YYYY\n';
                 }
              }
           if (test.indexOf('inRange') != -1)
              {
              num = parseFloat(val);
              if (isNaN(val))
                 {
                  errors+='- '+err_msg+' must be a number, no $ sign, no commas\n';
                  }
              else
                 {
                  p=test.indexOf(':');
                  min=test.substring(8,p); max=test.substring(p+1);
                  if (num<min || max<num)
                     {
                      errors+='- '+err_msg+' must be a number between '+min+' and '+max+' no $ sign, no commas\n';
                     }
                  }
               }
           //alert ('name: '+err_msg+' val: '+val+' status:'+gmval.checked);
           if (test.indexOf('isChecked') != -1)
              {
              if (!gmval.checked)
                 {
                 errors+='- '+err_msg+' is required\n';
                 }
              }
           }
           else
              {
              if (test.charAt(0) == 'R')
                 {
                 errors += '- '+err_msg+' is required\n';
                 }
              }
        }
     if (errors != '' && gm==0)
        {
        gm=1;
        gmfield = gmval;
        }
     }
  if (errors)
     {
     alert('The following error(s) occurred:\n'+errors);
     }
  if (errors) 
     {
     setTimeout("doSelection(gmfield)",0);
     }
  document.Ready_to_Post = (errors == '');
     
}
function find_this_object(n, d){
  var p,i,x;
  if(!d){
     d=document;
     }
   if((p=n.indexOf("?"))>0&&parent.frames.length){
      d=parent.frames[n.substring(p+1)].document;
      n=n.substring(0,p);
      }
  if(!(x=d[n])&&d.all){
     x=d.all[n];
     }
  for (i=0;!x&&i<d.forms.length;i++){
     x=d.forms[i][n];
     }
  for(i=0;!x&&d.layers&&i<d.layers.length;i++){
     x=find_this_object(n,d.layers[i].document);
     }
  if(!x && d.getElementById){
     x=d.getElementById(n);
     }
  return x;
}
function doSelection(fld){
  gmfield.focus()
  gmfield.select()
}
function format (expr, decplaces){
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	while (str.length <= decplaces)
	{
		str = "0" + str
	}
	var decpoint = str.length - decplaces
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
function MakeCents (expr){
	expr = expr /100;
	return format(expr,2);
}
function OpenWindow(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11) {
	//var action = new Array();
	//var action = action_array.split(",");
	//action = action_array;
	//alert('opening window1 '+action[1]+' 2 '+action[2]+' 3 '+action[3]+' 4 '+action[4]+' 5 '+action[5]+' 6 '+action[6]+' 7 '+action[7]+' 8 '+action[8]+' 9 '+action[9]+' 10 '+action[10]+' 11 '+action[11]);
	var wf = "";	
	wf = wf + "width=" + v3;
	wf = wf + ",height=" + v4;
	wf = wf + ",resizable=" + (v5 ? "yes" : "no");
	wf = wf + ",scrollbars=" + (v6 ? "yes" : "no");
	wf = wf + ",menubar=" + (v7 ? "yes" : "no");
	wf = wf + ",toolbar=" + (v8 ? "yes" : "no");
	wf = wf + ",directories=" + (v9 ? "yes" : "no");
	wf = wf + ",location=" + (v10 ? "yes" : "no");
	wf = wf + ",status=" + (v11 ? "yes" : "no");		
	window.open(v1,v2,wf);
}
function isDate(sDate) {
	//alert('isDate function');
   var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
   if (re.test(sDate)) {
      var dArr = sDate.split("/");
      var d = new Date(sDate);
      return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2];
   }
   else {
      return false;
   }
}