var requiredHash=new Array();

function makeRequiredHash(form){
	var LABELS = form.getElementsByTagName('LABEL');

for(var i=0;i<LABELS.length;i++){
	if(LABELS[i].className == 'req'){
	requiredHash[LABELS[i].htmlFor] = LABELS[i].innerHTML;
		} // end if
	} // end for
}

function checkForm(form_name){
var form=document.forms[0];
var re_email = new RegExp('.*email.*');
if(form_name){
form=document.forms[form_name];
}
makeRequiredHash(form);

error_msg='';
var error_msg_email='';var error_confirm_msg = '';
for(var field_name in requiredHash){
if(! form[field_name]){continue;}
if(form[field_name].type=='radio'){
val='';
for(var i=0;i < form[field_name].length;i++){
	if(form[field_name][i].checked){val = 'true';}
}}

if(form[field_name].style){
form[field_name].style.backgroundColor='#fff';}
var val;
if(form[field_name].type=='text'){
val=form[field_name].value;
	var confirm_fail;
if(form[field_name + '_confirm']){
	if(form[field_name + '_confirm'].value != form[field_name].value){
		confirm_fail = 1; 

if(requiredHash[field_name]){
error_confirm_msg+=requiredHash[field_name]+' does not match it\'s confirm value,';
}else{
error_confirm_msg+=field_name.replace(/_/g,' ')+' does not match it\'s confirm value,';}

}
}

} // end if form[field_name].type=='text'
if(form[field_name].type=='checkbox'){
val='';
if(form[field_name].checked){val='true';}}

if(form[field_name].type=='textarea'){
val=form[field_name].value;}
if(form[field_name].type=='select-one'){
val=form[field_name].options[form[field_name].selectedIndex].value;}
if(form[field_name].name){
if(form[field_name].name.match(re_email)){
var re = new RegExp('.*@.+\..+');
if(! val.match(re)){val='';
error_msg_email='\n Email address is malformed';}
}}
val=val.replace(/ /g,'');
if(!val){if(form[field_name].style){
form[field_name].style.backgroundColor='#ffc';
}
if(requiredHash[field_name]){
error_msg+=requiredHash[field_name]+',';
}else{
error_msg+=field_name.replace(/_/g,' ')+',';}
}}
if((error_msg) ||(error_confirm_msg)){alert('Please complete these fields:\n'+error_msg + error_msg_email + error_confirm_msg);return false;}
return true;
}
