function selectLink(formId, linkValue)
{
  var selectForm = document.getElementById(formId);
  if  (!selectForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS200 -"
             + formId + ").\n");
       return;
  }
  
   // set service name
   selectForm.linkId.value=linkValue;	
   // submit form
   selectForm.submit();	
}

function submitFormButton(formId, buttonValue)
{
  var buttonForm = document.getElementById(formId);
  if  (!buttonForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS300 -"
             + formId + ").\n");
       return;
  }
  
   // set service name
   buttonForm.buttonPressed.value=buttonValue;	
   // submit form
   buttonForm.target=window.name;
   buttonForm.submit();	
}

function hidePopup(name)
{
   //alert("looking for "+name);
   el = document.getElementById(name);
   if (el)
       el.style.display = "none";
}

function swapImg(imgId, newImgSrc)
{
  var imageObj = document.getElementById(imgId);
  imageObj.src=newImgSrc;
}


// function called by <a> tags to toggle help panel etc
function toggleHelp(helpPanel, helpImgId, src1, src2)
{   toggle(helpPanel);
    toggleHelpImg(helpImgId, src1, src2);
}

// function to toggle display/hide state of panel identified by 'name'
function toggle(name)
{  //alert("looking for "+name);
   el = document.getElementById(name);
   disp = el.style.display;

   if (!disp || (disp == "none"))
       el.style.display = "block";
   else
       el.style.display = "none";
}

// create global variable which remembers state for page duration
var selectHelpImg1 = false;
function toggleHelpImg(imgId, src1, src2)
{
  var imageObj = document.getElementById(imgId);
   if (selectHelpImg1)
   {   imageObj.src = src1;
       selectHelpImg1 = false;
   }
   else
   {   imageObj.src = src2;
       selectHelpImg1 = true;
   }
}


var mimg1="mimg1";
var mimg2="mimg2";
var mapImg = mimg1;
function toggleMapImg(imgId, src1, src2)
{
   var imageObj = document.getElementById(imgId);
   if (mapImg == mimg1)
   {
       imageObj.src = src2;
       mapImg = mimg2;
   }
   else
   {
       imageObj.src = src1;
       mapImg = mimg1;
   }
}

function toggleMap(mapPanel, mapImgId, src1, src2)
{
    toggle(mapPanel);
    toggleMapImg(mapImgId, src1, src2);
}


// function to toggle display/hide state of scenario select panel and control buttons
function scenarioVisibility(visibility)
{  
   selectButton = document.getElementById("deferSelectionString");
   scenarioPanel = document.getElementById("scenarioSelectPanel");
   selectImageObj = document.getElementById("selectImg");
   deferImageObj = document.getElementById("deferImg");

   if (visibility)
   {   scenarioPanel.style.display = "block";
       selectButton.value = "false";    // select the scenarios now
       selectImageObj.src = "images/selectNowOn.gif";
       deferImageObj.src = "images/selectLaterOff.gif";
    }
   else
   {   scenarioPanel.style.display = "none";
       selectButton.value = "true";     // defer the selection
       selectImageObj.src = "images/selectNowOff.gif";
       deferImageObj.src = "images/selectLaterOn.gif";
   }
}



function validateLoginForm()
{
  var organizationIdValid = true;
  var userIdValid = true;
  var passwordValid = true;   
  var detailsValid = false;
  var consentValid = false;   
  var errorFields = "";
 
  var authForm = document.getElementById("authenticate");
  if  (!authForm)
  {    alert("A problem has occured on this page - please email support quoting reference (JS100).\n");
       return;
  }
  
   // validate organization id
   var organizationId = authForm.organizationId.value;	
   if  (organizationId == "" ||
        organizationId == " " ||
	organizationId.length < 5)
   {    organizationIdValid = false;
        errorFields += "\torganization id\n";
   }

   // validate user id
   var userId = authForm.userId.value;	
   if  (userId == "" ||
        userId == " " ||
	userId.length < 5)
   {    userIdValid = false;
		errorFields += "\tuser id\n";
   }

   // validate password
   var password = authForm.password.value;	
   if  (password == "" ||
        password == " " ||
        password.length < 5)
   {    passwordValid = false;
        errorFields += "\t\password\n";
   }
   

   // check flags and report any errors
   if  (!organizationIdValid  ||
        !userIdValid  ||
        !passwordValid )
   {    alert("The following fields have not been entered correctly.\n" +
              errorFields +
              "Please try again.");
        if  (!organizationIdValid)
             authForm.organizationId.focus();
        else if  (!userIdValid)
                  authForm.userId.focus();
             else authForm.password.focus();
   }
   else
   {    detailsValid = true;
   }


   // ensure consent box checked
   if  (detailsValid)
   {    // validate radio boxes
        var consent = authForm.consent;	
        var selected = false;
        for (i=0; i<consent.length; ++i) 
        {   if  (consent[i].checked == true)
            {    selected = consent[i].value;
            }
        }
        if  (selected == "true")
        {    authForm.submit();
        }
        else
        {    alert("You must agree to the terms and conditions of use for this website before logging in.");
        }
   }

} 


function validateClassLoginForm(buttonValue, formName)
{
  var organizationIdValid = true;
  var userIdValid = true;
  var passwordValid = true;   
  var detailsValid = false;
  var consentValid = false;   
  var errorFields = "";
 
  var authForm = document.getElementById(formName);
  if  (!authForm)
  {    alert("A problem has occured on this page - please email support quoting reference (JS133).\n");
       return;
  }
  
  authForm.buttonPressed.value=buttonValue;	
  authForm.submit();

} 


function validateOrganizationForm(buttonValue, formName)
{
  var nameValid = true;
  var primaryAuthorityValid = true;
  var secondaryAuthorityValid = true;
  var address1Valid = true;   
  var address2Valid = true;   
  var townValid = true;   
  var countyValid = true;   
  var postCodeValid = true;   
  var contactValid = true;   
  var telephoneValid = true;   
  var faxValid = true;   
  var emailValid = true;   
  var notesValid = true;   

  var errorFields = "";

  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS101).\n");
       return;
  }
  
   // validate name
   var name = candidateForm.name.value;	
   if  (!checkFieldSize(name, 1, 255))
   {
        nameValid = false;
        errorFields += "\tname\n";
   }

   // validate primaryAuthority
   var primaryAuthority = candidateForm.primaryAuthority.value;	
   if  (!checkFieldSize(primaryAuthority, 1, 60))
   {
        primaryAuthorityValid = false;
        errorFields += "\tprimary authority\n";
   }

   // validate secondaryAuthority
   var secondaryAuthority = candidateForm.secondaryAuthority.value;	
   if  (!checkFieldSize(secondaryAuthority, 1, 60))
   {
        secondaryAuthorityValid = false;
        errorFields += "\tsecondary authority\n";
   }

   // validate address 1
   var address1 = candidateForm.address1.value;	
   if  (!checkFieldSize(address1, 0, 30))
   {
        address1Valid = false;
	errorFields += "\taddress 1\n";
   }
   
   // validate address 2
   var address2 = candidateForm.address2.value;	
   if  (!checkFieldSize(address2, 0, 30))
   {
        address2Valid = false;
	errorFields += "\taddress 2\n";
   }
   
   // validate town
   var town = candidateForm.town.value;	
   if  (!checkFieldSize(town, 0, 30))
   {
        townValid = false;
	errorFields += "\town\n";
   }
   
   // validate county
   var county = candidateForm.county.value;	
   if  (!checkFieldSize(county, 0, 30))
   {
        countyValid = false;
	errorFields += "\tcounty\n";
   }
   
   // validate post code
   var postCode = candidateForm.postCode.value;	
   if  (!checkFieldSize(postCode, 0, 10))
   {
        postCodeValid = false;
	errorFields += "\tpost code\n";
   }   

   // validate contact
   var contact = candidateForm.contact.value;	
   if  (!checkFieldSize(contact, 0, 50))
   {
        contactValid = false;
	errorFields += "\tcontact\n";
   }
   
   // validate telephone
   var telephone = candidateForm.telephone.value;	
   if  (!checkFieldSize(telephone, 0, 30))
   {
        telephoneValid = false;
	errorFields += "\ttelephone\n";
   }
   
   // validate fax
   var fax = candidateForm.fax.value;	
   if  (!checkFieldSize(fax, 0, 30))
   {
        faxValid = false;
	errorFields += "\tfax\n";
   }
   
   // validate email
   var email = candidateForm.email.value;	
   if  (!checkFieldSize(email, 0, 80))
   {
        emailValid = false;
	errorFields += "\temail\n";
   }
   
   // validate notes
   var notes = candidateForm.notes.value;	
   if  (!checkFieldSize(notes, 0, 255))
   {
        notesValid = false;
	errorFields += "\tnotes\n";
   }
   
   // check flags and report any errors
   if  (!nameValid  ||
        !primaryAuthorityValid  ||
        !secondaryAuthorityValid  ||
        !address1Valid  ||
        !address2Valid  ||
        !townValid  ||
        !countyValid  ||
        !postCodeValid  ||
        !contactValid  ||
        !telephoneValid  ||
        !faxValid  ||
        !emailValid  ||
        !notesValid)
   {
   	alert("The following fields have not been entered correctly.\n" +
	      errorFields +
	      "Please try again.");
	if  (!nameValid)
	     candidateForm.name.focus();
	else if  (!primaryAuthorityValid)
             candidateForm.primaryAuthority.focus();
	else if  (!secondaryAuthorityValid)
             candidateForm.secondaryAuthority.focus();
	else if  (!address1Valid)
             candidateForm.address1.focus();
	else if  (!address2Valid)
             candidateForm.address2.focus();
	else if  (!townValid)
             candidateForm.town.focus();
	else if  (!countyValid)
             candidateForm.county.focus();
	else if  (!postCodeValid)
             candidateForm.postCode.focus();
	else if  (!contactValid)
             candidateForm.contact.focus();
	else if  (!telephoneValid)
             candidateForm.telephone.focus();
	else if  (!faxValid)
             candidateForm.fax.focus();
	else if  (!emailValid)
             candidateForm.email.focus();
	else candidateForm.notes.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        candidateForm.buttonPressed.value=buttonValue;	
	candidateForm.submit();
   }
} 


function validateBookingForm(buttonValue, formName)
{
  var organizationIdValid = true;
  var userIdValid = true;
  var classNameValid = true;
  var visitDateStringValid = true;   
  var visitTimeOnlyStringValid = true;   
  var ageGroupNameValid = true;   
  var referenceValid = true;   

  var errorFields = "";
 
  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS105).\n");
       return;
  }
  
   // validate user id
   var userId = candidateForm.userId.value;	
   if  (!checkFieldSize(userId, 1, 10))
   {
        userIdValid = false;
        errorFields += "\tuser id\n";
   }

   // validate organization id
   var organizationId = candidateForm.organizationId.value;	
   if  (!checkFieldSize(organizationId, 1, 10))
   {
        organizationIdValid = false;
        errorFields += "\torganization id\n";
   }

   // validate class name
   var className = candidateForm.className.value;	
   if  (!checkFieldSize(className, 1, 20))
   {
        classNameValid = false;
        errorFields += "\tclass name\n";
   }

   // validate visit date string
   var visitDateString = candidateForm.visitDateString.value;	
   if  (!checkFieldSize(visitDateString, 6, 6))
   {
        visitDateStringValid = false;
	errorFields += "\tvisit date\n";
   }
   
   // validate visit time only string
   var visitTimeOnlyString = candidateForm.visitTimeOnlyString.value;	
   if  (!checkFieldSize(visitTimeOnlyString, 4, 4))
   {
        visitTimeOnlyStringValid = false;
	errorFields += "\tvisit time\n";
   }
   
   // validate age group
   var ageGroupName = candidateForm.ageGroupName.value;	
   if  (!checkFieldSize(ageGroupName, 1, 10))
   {
        ageGroupNameValid = false;
	errorFields += "\tage group\n";
   }
         
   // validate reference
   var reference = candidateForm.reference.value;	
   if  (!checkFieldSize(reference, 1, 10))
   {
        referenceValid = false;
	errorFields += "\treference\n";
   }
         
   // check flags and report any errors
   if  (!organizationIdValid  ||
        !userIdValid  ||
        !classNameValid  ||
        !visitDateStringValid  ||
        !visitTimeOnlyStringValid  ||
        !ageGroupNameValid ||
        !referenceValid)
   {
   	alert("The following fields have not been entered correctly.\n" +
	      errorFields +
	      "Please try again.");
	if  (!organizationIdValid)
	     candidateForm.organizationId.focus();
	else if  (!userIdValid)
             candidateForm.userId.focus();
	else if  (!classNameValid)
             candidateForm.className.focus();
	else if  (!visitDateStringValid)
             candidateForm.visitDateString.focus();
	else if  (!visitTimeOnlyStringValid)
             candidateForm.visitTimeOnlyString.focus();
	else if  (!ageGroupNameValid)
             candidateForm.ageGroupName.focus();
	else candidateForm.reference.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        candidateForm.buttonPressed.value=buttonValue;	
	candidateForm.submit();
   }
} 


function validateBookingWithResultsForm(buttonValue, formName)
{
  var classNameValid = true;
  var visitDateStringValid = true;   
  var visitTimeOnlyStringValid = true;   
  var referenceValid = true;   

  var errorFields = "";
 
  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS105).\n");
       return;
  }
  
   // validate class name
   var className = candidateForm.className.value;	
   if  (!checkFieldSize(className, 1, 20))
   {
        classNameValid = false;
        errorFields += "\tclass name\n";
   }

   // validate visit date string
   var visitDateString = candidateForm.visitDateString.value;	
   if  (!checkFieldSize(visitDateString, 6, 6))
   {
        visitDateStringValid = false;
	errorFields += "\tvisit date\n";
   }
   
   // validate visit time only string
   var visitTimeOnlyString = candidateForm.visitTimeOnlyString.value;	
   if  (!checkFieldSize(visitTimeOnlyString, 4, 4))
   {
        visitTimeOnlyStringValid = false;
	errorFields += "\tvisit time\n";
   }
   
   // validate reference
   var reference = candidateForm.reference.value;	
   if  (!checkFieldSize(reference, 1, 10))
   {
        referenceValid = false;
	errorFields += "\treference\n";
   }
         
   // check flags and report any errors
   if  (!classNameValid  ||
        !visitDateStringValid  ||
        !visitTimeOnlyStringValid  ||
        !referenceValid)
   {
   	alert("The following fields have not been entered correctly.\n" +
	      errorFields +
	      "Please try again.");
	if  (!classNameValid)
             candidateForm.className.focus();
	else if  (!visitDateStringValid)
             candidateForm.visitDateString.focus();
	else if  (!visitTimeOnlyStringValid)
             candidateForm.visitTimeOnlyString.focus();
	else candidateForm.reference.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        candidateForm.buttonPressed.value=buttonValue;	
	candidateForm.submit();
   }
} 


function validateCompleteBookingForm(buttonValue, formName)
{
  var errorFields = "";
 
  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS109).\n");
       return;
  }
  
  // set the buttonPressed value so that the action knows which button caused the form to submit
  candidateForm.buttonPressed.value=buttonValue;	
  candidateForm.submit();
} 


function validateUserForm(buttonValue, formName)
{
  var firstNameValid = true;
  var lastNameValid = true;
  var organizationIdValid = true;   
  var workTelValid = true;   
  var mobileTelValid = true;   
  var emailValid = true;   
  var categoryValid = true;   
  var notesValid = true;   

  var errorFields = "";
 
  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS101).\n");
       return;
  }
  
   // validate first name
   var firstName = candidateForm.firstName.value;	
   if  (!checkFieldSize(firstName, 1, 30))
   {
        firstNameValid = false;
        errorFields += "\tfirst name\n";
   }

   // validate last name
   var lastName = candidateForm.lastName.value;	
   if  (!checkFieldSize(lastName, 1, 30))
   {
        lastNameValid = false;
        errorFields += "\tlast name\n";
   }

   // validate email
   var email = candidateForm.email.value;	
   if  (!checkFieldSize(email, 1, 80))
   {
        emailValid = false;
	errorFields += "\temail\n";
   }
   
   // validate organization id
   var organizationId = candidateForm.organizationId.value;	
   if  (!checkFieldSize(organizationId, 1, 30))
   {
        organizationIdValid = false;
	errorFields += "\torganization id\n";
   }
   
   // validate home telephone
   var workTel = candidateForm.workTel.value;	
   if  (!checkFieldSize(workTel, 0, 30))
   {
        workTelValid = false;
	errorFields += "\twork tel\n";
   }
   
   // validate mobile telephone
   var mobileTel = candidateForm.mobileTel.value;	
   if  (!checkFieldSize(mobileTel, 0, 30))
   {
        mobileTelValid = false;
	errorFields += "\tmobile tel\n";
   }
   
   // validate category
   var category = candidateForm.category.value;	
   if  (!checkFieldSize(category, 0, 30))
   {
        categoryValid = false;
	errorFields += "\tcategory\n";
   }
   
   // validate notes
   var notes = candidateForm.notes.value;	
   if  (!checkFieldSize(notes, 0, 255))
   {
        notesValid = false;
	errorFields += "\tnotes\n";
   }
   
   // check flags and report any errors
   if  (!firstNameValid  ||
        !lastNameValid  ||
        !emailValid  ||
        !organizationIdValid  ||
        !workTelValid  ||
        !mobileTelValid  ||
        !categoryValid  ||
        !notesValid)
   {
   	alert("The following fields have not been entered correctly.\n" +
	      errorFields +
	      "Please try again.");
	if  (!firstNameValid)
	     candidateForm.firstName.focus();
	else if  (!lastNameValid)
             candidateForm.lastName.focus();
	else if  (!emailValid)
             candidateForm.email.focus();
	else if  (!organizationIdValid)
             candidateForm.organizationId.focus();
	else if  (!workTelValid)
             candidateForm.workTel.focus();
	else if  (!mobileTelValid)
             candidateForm.mobileTel.focus();
	else if  (!categoryValid)
             candidateForm.category.focus();
	else candidateForm.notes.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        candidateForm.buttonPressed.value=buttonValue;	
	candidateForm.submit();
   }
} 


function validateTourGuideForm(buttonValue, formName)
{
  var firstNameValid = true;
  var lastNameValid = true;
  var errorFields = "";
 
  var tourGuideForm = document.getElementById(formName);
  if  (!tourGuideForm)
  {    alert("A problem has occured on this page - please email support quoting reference (JS2300).\n");
       return;
  }
  
   // validate first name
   var firstName = tourGuideForm.firstName.value;	
   if  (!checkFieldSize(firstName, 1, 25))
   {
        firstNameValid = false;
	errorFields += "\tfirst name\n";
   }

   // validate last name
   var lastName = tourGuideForm.lastName.value;	
   if  (!checkFieldSize(lastName, 1, 25))
   {
        lastNameValid = false;
	errorFields += "\tlast name\n";
   }
   

   // check flags and report any errors
   if  (!firstNameValid  ||
        !lastNameValid )
   {    alert("The following fields have not been entered correctly.\n" +
              errorFields +
              "Please try again.");
        if  (!firstNameValid)
             tourGuideForm.firstName.focus();
        else tourGuideForm.lastName.focus();
        return false;
   }
   else
   {    //tourGuideForm.tourGuideControl.value=buttonValue;
        //alert(tourGuideForm.tourGuideControl.value);
        //tourGuideForm.submit();
        return true;
   }

} 


function validateCreateQuestionForm(buttonValue)
{
  var examOidValid = true;
  var questionValid = true;
  var questionTypeValid = true;   
  var questionNumberValid = true;   
  var choiceAValid = true;   
  var choiceBValid = true;   
  var choiceCValid = true;   
  var choiceDValid = true;   
  var choiceEValid = true;   
  var choiceFValid = true;   
  // var textAnswerValid = true;   
  var scenarioNameValid = true;   
  var skillLevelValid = true;   
  var categoryNameValid = true;   
  var descriptionValid = true;   
 
  var errorFields = "";
 
  var questionForm = document.getElementById("createQuestionForm");
  if  (!questionForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS102).\n");
       return;
  }
  
   // validate exam oid
   var examOidString = questionForm.examOidString.value;	
   if  (!checkFieldSize(examOidString, 1, 10))
   {
        examOidValid = false;
        errorFields += "\texam oid\n";
   }

   // validate question
   var question = questionForm.question.value;	
   if  (!checkFieldSize(question, 1, 255))
   {
        questionValid = false;
        errorFields += "\tquestion\n";
   }

   // validate question type
   var questionTypeString = questionForm.questionTypeString.value;	
   if  (!checkFieldSize(questionTypeString, 1, 1))
   {
        questionTypeValid = false;
	errorFields += "\tquestion type\n";
   }
   
   // validate scenario name
   var scenarioName = questionForm.scenarioName.value;	
   if  (!checkFieldSize(scenarioName, 1, 50))
   {
        scenarioNameValid = false;
	errorFields += "\tscenario name\n";
   }   

   // validate question number string
   var questionNumberString = questionForm.questionNumberString.value;	
   if  (!checkFieldSize(questionNumberString, 1, 10))
   {
        questionNumberValid = false;
	errorFields += "\tquestion number\n";
   }
   
   // validate choiceA
   var choiceA = questionForm.choiceA.value;	
   if  (!checkFieldSize(choiceA, 0, 255))
   {
        choiceAValid = false;
	errorFields += "\tchoice A\n";
   }
      
   // validate choiceB
   var choiceB = questionForm.choiceB.value;	
   if  (!checkFieldSize(choiceB, 0, 255))
   {
        choiceBValid = false;
	errorFields += "\tchoice B\n";
   }
      
   // validate choiceC
   var choiceC = questionForm.choiceC.value;	
   if  (!checkFieldSize(choiceC, 0, 255))
   {
        choiceCValid = false;
	errorFields += "\tchoice C\n";
   }
   
   // validate choiceD
   var choiceD = questionForm.choiceD.value;	
   if  (!checkFieldSize(choiceD, 0, 255))
   {
        choiceDValid = false;
	errorFields += "\tchoice D\n";
   }
   
   // validate choiceE
   var choiceE = questionForm.choiceE.value;	
   if  (!checkFieldSize(choiceE, 0, 255))
   {
        choiceEValid = false;
	errorFields += "\tchoice E\n";
   }
   
   // validate choiceF
   var choiceF = questionForm.choiceF.value;	
   if  (!checkFieldSize(choiceF, 0, 255))
   {
        choiceFValid = false;
	errorFields += "\tchoice F\n";
   }
   
   // validate textAnswer
   /* var textAnswer = questionForm.textAnswer.value;	
   if  (!checkFieldSize(textAnswer, 0, 30))
   {
        textAnswerValid = false;
	errorFields += "\text answer\n";
   }
   */

   // validate skill level
   var skillLevelString = questionForm.skillLevelString.value;	
   if  (!checkFieldSize(skillLevelString, 0, 30))
   {
        skillLevelValid = false;
	errorFields += "\tskill level\n";
   }
   
   // validate category name
   var categoryName = questionForm.categoryName.value;	
   if  (!checkFieldSize(categoryName, 0, 50))
   {
        categoryNameValid = false;
	errorFields += "\tcategory\n";
   }
   
   // validate description
   var description = questionForm.description.value;	
   if  (!checkFieldSize(description, 0, 255))
   {
        descriptionValid = false;
	errorFields += "\tdescription\n";
   }


   // check flags and report any errors
   if  (!examOidValid  ||
        !questionValid  ||
        !questionTypeValid  ||
        !scenarioNameValid  ||
        !questionNumberValid  ||
        !choiceAValid  ||
        !choiceBValid  ||
        !choiceCValid  ||
        !choiceDValid  ||
        !choiceEValid  ||
        !choiceFValid  ||
//        !textAnswerValid  ||
        !skillLevelValid  ||
        !categoryNameValid  ||
        !descriptionValid)
   {
   	alert("The following fields have not been entered correctly.\n" +
	      errorFields +
	      "Please try again.");
	if  (!examOidValid)
	     questionForm.examOidString.focus();
	else if  (!questionValid)
             questionForm.question.focus();
	else if  (!questionTypeValid)
             questionForm.questionTypeString.focus();
	else if  (!scenarioNameValid)
             questionForm.scenarioName.focus();
	else if  (!questionNumberValid)
             questionForm.questionNumberString.focus();
	else if  (!choiceAValid)
             questionForm.choiceA.focus();
 	else if  (!choiceBValid)
             questionForm.choiceB.focus();
 	else if  (!choiceCValid)
             questionForm.choiceC.focus();
	else if  (!choiceDValid)
             questionForm.choiceD.focus();
	else if  (!choiceEValid)
             questionForm.choiceE.focus();
	else if  (!choiceFValid)
             questionForm.choiceF.focus();
//	else if  (!textAnswerValid)
//             questionForm.textAnswer.focus();
	else if  (!skillLevelValid)
             questionForm.skillLevelString.focus();
	else if  (!categoryNameValid)
             questionForm.categoryName.focus();
	else questionForm.description.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        questionForm.buttonPressed.value=buttonValue;	
	questionForm.submit();
   }
} 

function validateAdminExamTrackForm(buttonValue, formName)
{
  var organizationIdValid = true;

  var errorFields = "";
 
  var candidateForm = document.getElementById(formName);
  if  (!candidateForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS110).\n");
       return;
  }
  
   // validate organizationId
   var organizationId = candidateForm.organizationId.value;	
   if  (!checkFieldSize(organizationId, 1, 15))
   {
        organizationIdValid = false;
        errorFields += "\torganization id\n";
   }


   // check flags and report any errors
   if  (!organizationIdValid)
   {
   	alert("The 'organization id' field contains an error.\n")
	candidateForm.organizationId.focus();
   }
   else
   {
        // set the buttonPressed value so that the action knows which button caused the form to submit
        candidateForm.buttonPressed.value=buttonValue;	
	candidateForm.submit();
   }
} 

function checkFieldSize(fieldString, lowLimit, hiLimit)
{  retVal= true;
   if  (lowLimit > 0)
   {
       if  (fieldString == "" || fieldString == " ")
           retVal = false;
   }

   if  ( (fieldString.length < lowLimit) || (fieldString.length > hiLimit) )
   {
        retVal = false;
   }
   return retVal;
}

function answerQuestion(numberStr)
{
  var confirmForm = document.getElementById("UnansweredQuestionForm");
  if  (!confirmForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS400).\n");
       return;
  }
   confirmForm.linkQuestionNumber.value = numberStr;
   confirmForm.submit();
}

function rangeControl(formId)
{
   var graphForm = document.getElementById(formId);
   if  (!graphForm)
   {   alert("A problem has occured on this page - please email support quoting reference (JS730 - "
             + formId + ").\n");
       return;
   }
   var rangeFrom = document.getElementById("from");
   if  (!rangeFrom)
   {   alert("A problem has occured on this page - please email support quoting reference (JS731f).\n");
       return;
   }
   var rangeTo = document.getElementById("to");
   if  (!rangeTo)
   {   alert("A problem has occured on this page - please email support quoting reference (JS731t).\n");
       return;
   }
  
   if  (graphForm.rangeSelectOn.checked)
   {    rangeFrom.disabled = "true";
        rangeTo.disabled = "true";
   }
   else
   {    rangeFrom.disabled = "";
        rangeTo.disabled = "";
   }

   return true;
}

function submitReportRequest(formName)
{
  var reportForm = document.getElementById(formName);
  if  (!reportForm)
  {
       alert("A problem has occured on this page - please email support quoting reference (JS600).\n");
       return;
  }

  // remember window name of current window
  criteriaWindow = window.name;

  newWindow = window.open("", "title","toolbar=yes,status=yes,menubar=yes,scrollbars=yes,width=800,height=600,resizable=yes");
  newWindow.name = "reportWindow"+Math.random();
  reportForm.target = newWindow.name;
  reportForm.buttonPressed.value='Enter';	

  // detect browser and change form method to "GET" if non-IE browser
  userAgent = navigator.userAgent.toLowerCase();
  if  (userAgent.indexOf("msie") == -1)
       reportForm.method="GET";

  retVal= reportForm.submit();
  newWindow.focus();

  // revert form target back to original window
  reportForm.target = criteriaWindow;
  reportForm.buttonPressed.value='Continue';
  reportForm.submit();
}

var alreadyOpened = false;

function openMainWindow(URL)
{
  openNewWindow = true;
  if  (alreadyOpened)
  {   openNewWindow = confirm("The application has already been opened.\n\n"
                              +"Please confirm that you would like to open another window.");
  }

  if  (openNewWindow)
  {
      newWindow = window.open(URL, "title","toolbar=no,status=yes,menubar=no,scrollbars=yes,width=screen.width,height=screen.height,resizable=yes");
      newWindow.name = "reportWindow"+Math.random();
      alreadyOpened = true;
      newWindow.focus();
  }
}

function closeWindow()
{
//    self.close();
    window.close();
}
