//javascript document

function Validate()
{
function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i


function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
var btn = valButton(document.form.action);
if (btn == null) {
alert("Action is a required field")
return false;
}
//else alert('Button value ' + btn + ' selected'); 

if (IsEmpty(document.form.agencynumber)) {
alert("Agency Number is a required field")
document.form.agencynumber.focus();
return false;
} //end if
if (document.form.agencyname.selectedIndex == 0) {
alert("Agency Name is a required field")
document.form.agencyname.focus();
return false;
} //end if
if (IsEmpty(document.form.first)) {
alert("First Name is a required field")
document.form.first.focus();
return false;
} //end if
if (IsEmpty(document.form.middle)) {
alert("Middle Initial is a required field")
document.form.middle.focus();
return false;
} //end if
if (IsEmpty(document.form.last)) {
alert("Last Name is a required field")
document.form.last.focus();
return false;
} //end if
if (IsEmpty(document.form.email)) {
alert("Email is a required field")
document.form.email.focus();
return false;
} //end if
if (!filter.test(document.form.email.value)) {
alert("Email address is not correct")
document.form.email.focus();
return false;
} //end if
if (IsEmpty(document.form.empid)) {
alert("Employee ID is a required field")
document.form.empid.focus();
return false;
} //end if
if (IsEmpty(document.form.sharp)) {
alert("Agency SHARP Security Contact Name is a required field")
document.form.sharp.focus();
return false;
} //end if
if (IsEmpty(document.form.semail)) {
alert("Agency SHARP Security Contact Email Address is a required field")
document.form.semail.focus();
return false;
} //end if
if (!filter.test(document.form.semail.value)) {
alert("Agency SHARP Security Contact Email address is not correct")
document.form.semail.focus();
return false;
} //end if
return true;
}//end function