
function validateNotEmpty(str) {
var tmp = str;
tmp = trimAll(tmp);
if(tmp.length > 0) { return true; }  
return false;
}

function  validateEmail(str) {
var reg = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
return reg.test(str);
}

function trimAll(str) {
var reg = /^(\s*)$/;
if(reg.test(str)) {
	str = str.replace(reg, '');
	if( str.length == 0) return str;
	}
reg = /^(\s*)([\W\w]*)(\b\s*$)/;
if(reg.test(str)) { str = str.replace(reg, '$2'); }
return str;
}

function checkFields(form) {
var s = "";
var i = form;
if ( !validateNotEmpty(i.from_name.value) ) { s += "- You need to fill out \"Name\" field\n"; }
if ( !validateNotEmpty(i.from_email.value) ) { s += "- You need to fill out \"E-mail\" field\n"; }
else { if ( validateNotEmpty(i.from_email.value) && !validateEmail(i.from_email.value) ) { s += "- E-mail is not valid\n"; } }
if ( !validateNotEmpty(i.comment.value) ) { s += "- You need to fill out \"Text of Question\" field\n"; }
if ( s == "" ) { return true; } else { alert("This form cannot be submitted because:\n" + s); return false; }
}

function checkContactFields(form) {
var s = "";
var i = form;
if ( !validateNotEmpty(i.from_name.value) ) { s += "- You need to fill out \"Name\" field\n"; }
if ( !validateNotEmpty(i.from_email.value) ) { s += "- You need to fill out \"E-mail\" field\n"; }
else { if ( validateNotEmpty(i.from_email.value) && !validateEmail(i.from_email.value) ) { s += "- E-mail is not valid\n"; } }
if ( s == "" ) { return true; } else { alert("This form cannot be submitted because:\n" + s); return false; }
}

function checkOICFields(form) {
var s = "";
var i = form;
if ( !validateNotEmpty(i.from_name.value) ) { s += "- You need to fill out \"Name\" field\n"; }
if ( !validateNotEmpty(i.from_email.value) ) { s += "- You need to fill out \"E-mail\" field\n"; }
else { if ( validateNotEmpty(i.from_email.value) && !validateEmail(i.from_email.value) ) { s += "- E-mail is not valid\n"; } }
if ( i.marital_status.selectedIndex == 0 ) { s += "- You need to fill out \"Marital Status\" field\n"; }
if ( !validateNotEmpty(i.dependents.value) ) { s += "- You need to fill out \"# of Dependents\" field\n"; }
if ( !validateNotEmpty(i.owed_to_irs.value) ) { s += "- You need to fill out \"How much do you owe to the IRS\" field\n"; }
if ( i.taxes_filed.selectedIndex == 0 ) { s += "- You need to fill out \"Are all your tax returns filed\" field\n"; }
if ( !validateNotEmpty(i.gross_income.value) ) { s += "- You need to fill out \"Your family's gross monthly income\" field\n"; }
if ( s == "" ) { return true; } else { alert("This form cannot be submitted because:\n" + s); return false; }
}

