// JavaScript Document
function validate_registration_form(thisform)
{
with (thisform)
{

  if (validate_required(fname,"First name must be filled out!")==false)
  {fname.focus();return false;}
  if (validate_required(lname,"Last name must be filled out!")==false)
  {lname.focus();return false;}
  if(dropDownMenuD()==false)
  {return false;}
  if(dropDownMenuM()==false)
  {return false;}
  if(dropDownMenuY()==false)
  {return false;}
  if(dropDownCourse()==false)
  {return false;}
  if (validate_required(nationality,"Nationality must be filled out!")==false)
  {nationality.focus();return false;}
  if (validate_required(passport,"Passport must be filled out!")==false)
  {passport.focus();return false;}
  if (validate_required(email,"Email must be filled out!")==false)
  {email.focus();return false;}
  if (validate_email(email,"Not a valid E-mail address!")==false)
  {email.focus();return false;}  
  if ( document.regform.agreement.checked == false )
    {
        alert ( "Please check the Terms & Conditions box." );
        return false;
    }

  
  
}

}
var menu_selection1="";
var menu_selection2="";
var menu_selection3="";
var menu_selection4="";
function dropDownMenuD(form)  {
var myindex=document.regform.day.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the day menu.");
document.regform.day.focus();
return false;
}
else {
menu_selection1=document.regform.day.options[myindex].value;
return true;
   }
}

function dropDownMenuM(form)  {
var myindex=document.regform.month.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the month menu.");
document.regform.month.focus();
return false;
}
else {
menu_selection2=document.regform.month.options[myindex].value;
return true;
   }
}

function dropDownMenuY(form)  {
var myindex=document.regform.year.selectedIndex;
if (myindex==0) {
alert("\nYou must make a selection from the year menu.");
document.regform.year.focus();
return false;
}
else {
menu_selection3=document.regform.year.options[myindex].value;
return true;
   }
}

function dropDownCourse(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_selection4=document.regform.course.options[myindex].value;
return true;
   }
}
function doSubmit() {

//asubmit is the name of the SUBMIT button in the form
document.exam.submittest.click();
}
function doSubmit2() {

//asubmit is the name of the SUBMIT button in the form
document.exam.submittest2.click();
}
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;}
}
}

var _countDowncontainer=0;
var _currentSeconds=0;
function ActivateCountDown(strContainerID, initialValue) {
    _countDowncontainer = document.getElementById(strContainerID);
    if (!_countDowncontainer) {
        alert("count down error: container does not exist: "+strContainerID+
            "\nmake sure html element with this ID exists");
        return;
    }
    SetCountdownText(initialValue);
    window.setTimeout("CountDownTick()", 1000);
}
function CountDownTick() {
    if (_currentSeconds <= 0) {
        alert("your time has expired!");
		
        return;
		
    }
   
    SetCountdownText(_currentSeconds-1);
    window.setTimeout("CountDownTick()", 1000);
}
 
function SetCountdownText(seconds) {
    //store:
    _currentSeconds = seconds;
   
    //get minutes:
    var minutes=parseInt(seconds/60);
   
    //shrink:
    seconds = (seconds%60);
   
    //get hours:
    var hours=parseInt(minutes/60);
   
    //shrink:
    minutes = (minutes%60);
   
    //build text:
    var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);
   
    //apply:
    _countDowncontainer.innerHTML = strText;
}
 
function AddZero(num) {
    return ((num >= 0)&&(num < 10))?"0"+num:num+"";
} 

