// JavaScript Document
function validate_registration_form(thisform)
{
with (thisform)
{

  if (validate_required(studentname,"Name must be filled out!")==false)
  {studentname.focus();return false;}
  if (validate_required(studentemail,"Email must be filled out!")==false)
  {studentemail.focus();return false;}
  if (validate_email(studentemail,"Not a valid E-mail address!")==false)
  {studentemail.focus();return false;}  
  if (validate_required(studentmobile,"Mobile must be filled out!")==false)
  {studentmobile.focus();return false;}
  if(isNumeric(studentmobile,"Mobile must me number")==false)
  {studentmobile.focus();return false;}
  if (validate_required(studentid,"Student ID must be filled out!")==false)
  {studentid.focus();return false;}  
  if(coursedropDownMenu()==false)
  {return false;}
  
}

}

function coursedropDownMenu(form)  {
var myindex=document.regform.course.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the course menu.");
document.regform.course.focus();
return false;
}
else {
menu_selection1=document.regform.course.options[myindex].value;
return true;
   }
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression) || elem.value==null || elem.value==""){
	elem.style.background = 'white';
		return true;
		
	}else{
	elem.style.background = 'Maroon';
		alert(helperMsg);
		elem.focus();
		
		return false;
	}
}

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {field.style.background = 'Maroon';field.style.color = 'white';alert(alerttxt);return false;}
else {field.style.background = 'white';field.style.color = 'black';return true;}
}
}

function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2) 
  {field.style.background = 'Maroon';field.style.color = 'white';alert(alerttxt);return false;}
else {field.style.background = 'white';field.style.color = 'black';return true;}
}
}


