// JavaScript Document
/*
Description :        This page contains all the different javascript functions for the PurplePassport Website (FIREFOX)
Exceptions :        If a javascript function needs some server side code, then it will be run on the page itself
*/
//*******************************
      function validateCourseFormStep1_FF(form) {

        var txtTitle = document.getElementById('txtTitle').value
        var selAwarding = document.getElementById('selAwarding').value;
        var selTraining = document.getElementById('selTraining').value;
        var selLevel = document.getElementById('selLevel').value;
        var txtHours = document.getElementById('txtHours').value;
        var txtPISDate = document.getElementById('txtPISDate').value;
        var selStatus = document.getElementById('selStatus').value;

        var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
        var hoursRegex = /[0-9]^[a-zA-Z]/;
        var message = "";

        if(txtTitle == "") 
        {
          message += "You must enter the course title \n";
        }
        
        if(selAwarding == 0) 
        {
          message += "You must select the Awarding Body\n";
        }
            
        if(txtHours == "") 
        {
          message += "You must enter the amount of course hours \n";
        }

        if(selTraining == 0) 
        {
          message += "You must select the course type\n";
        }

        if(selLevel == 0) {
          message += "You must select the course level \n";
        }

        if(txtPISDate != "") {
          if (isDate(txtPISDate) == false){
              message += "You must enter the correct Renewal Date. Match dd/mm/yyyy \n";
          }
        }
//        else 
//        {
//            message += "You must enter the Renewal Date \n";            
//        }


        if(selStatus == 0) {
          message += "You must select the status\n";          
        }
        if (message != "")
        {
            alert(message);
            return false;
        }
        else return true;
     }
     
     
  function validateAddEditCourseStep2_FF(form) {

//  var txtTarget = document.getElementById('txtTarget').value;
//  var txtCPReq = document.getElementById('txtCPReq').value;
//  var txtEntryReq = document.getElementById('txtEntryReq').value;
//  var txtCertification = document.getElementById('txtCertification').value;
//  var txtProgression = document.getElementById('txtProgression').value;
//  var txtTopics = document.getElementById('txtTopics').value;
//  var txtMethods = document.getElementById('txtMethods').value;
//  var selRegions = document.getElementById('selRegions').value;

//  if(txtTarget == "") {
//    alert("You must enter the target candidates");
//    return false;
//  }

//  if(txtCPReq == "") {
//    alert("You must enter the delivery requirements");
//    return false;
//  }

//  if(txtEntryReq == "") {
//    alert("You must enter the entry requirements");
//    return false;
//  }

//  if(txtCertification == "") {
//    alert("You must enter the certification");
//    return false;
//  }

//  if(txtProgression == "") {
//    alert("You must enter the opportunities for progression");
//    return false;
//  }

//  if(txtTopics == "") {
//    alert("You must enter the topics and areas of study");
//    return false;
//  }

//  if(txtMethods == "") {
//    alert("You must enter the assessment and methods that are used");
//    return false;
//  }

//  var selRegions = document.getElementById('selRegions').value;
//  if(selRegions == 0) {
//    alert("You must select the region");
//    return false;
//  }
  document.getElementById('courseForm').submit();
  return true;
}

function validateAddNewProviderDetails_FF(form) {

  var txtFreeText = document.getElementById('txtFreeText').value;
  var txtAddr = document.getElementById('txtAddr').value;
  var txtPostCode = document.getElementById('txtPostCode').value;
  var txtSkills = document.getElementById('txtSkills').value;
  var txtCodeOfPractice = document.getElementById('txtCodeOfPractice').value;
  var txtKeyContact = document.getElementById('txtKeyContact').value;
  var txtPhone = document.getElementById('txtPhone').value;
  var txtEmail = document.getElementById('txtEmail').value;
  var txtWebAddr = document.getElementById('txtWebAddr').value;

  var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var numbRegex = /[0-9]^[a-zA-Z]/;
  var message = "";

  if(txtFreeText == "") {
    message += "You must enter New provider`s name\r\n";
  }
  
  if(txtAddr == "") {
    message += "You must enter the address\r\n";
  }

  if(txtPostCode == "") {
    message += "You must enter the post code\r\n";
  }
  
  if(postit(document.getElementById("txtPostCode")) == false)
  {
    message += "You have entered an invalid postcode\r\n";
  }
  
  if(txtPhone == "") {
    message += "You must enter the phone no\r\n";
  }

  if(txtEmail == "") {
    message += "You must enter the email\r\n";
  }

  if(!txtEmail.match(emailRegex))  {
    message += "You have entered an invalid email\r\n";
  }

  if (message != "")
  {
    alert(message);
    return false;
  }
  return true;
}

function validateFindCourseToEdit_FF(form)
{
  var txtKeyWord = document.getElementById('txtKeyWord').value;
  var selTraining = document.getElementById('selTraining').value;
  var selStatus = document.getElementById('selStatus').value;
  var selRegion = document.getElementById('selRegion').value;
  var txtFrom = document.getElementById('txtFrom').value;
  var txtTo = document.getElementById('txtTo').value;

  var msg = "";
//  if (txtKeyWord == "") msg = "You must enter keyword\n"
// else if (selTraining == 0) msg = "You must select training course or qualification\n";
//  else if (selStatus == 0) msg = "You must select status of the course\n";
//  else if (selRegion == 0) msg = "You must select region\n";
  if (txtFrom == "") msg += "You must enter renewal start date\n"
  if (txtTo == "") msg += "You must enter renewal end date\n"
  if (!isDate(txtFrom)) msg += "Entered renewal start date is incorrect\n"
  if (!isDate(txtTo)) msg += "Entered renewal end date is incorrect"

  if (msg == "") return true;
  else
  {
    alert(msg);
    return false;
  }
}

 function validateQuickSearch_FF(form) {

  
 if (formQuickSearch.ShowAllByLevel != null )
  formQuickSearch.ShowAllByLevel.value = 0;
  
 if (formQuickSearch.ShowAllByStatus != null )
  formQuickSearch.ShowAllByStatus.value = 0;
 
 if (formQuickSearch.ShowAllByLevel2 != null )
  formQuickSearch.ShowAllByLevel2.value = 0;
 
 if (formQuickSearch.ShowAllByStatus2 != null )
  formQuickSearch.ShowAllByStatus2.value = 0;

  return true;
}  
  
function validateQuickSearch1_FF(form) {
  var ShowAllByLevel = formQuickSearch.ShowAllByLevel.value;
  

 if (formQuickSearch.ShowAllByStatus != null )
  formQuickSearch.ShowAllByStatus.value = 0;

  if (formQuickSearch.ShowAllByLevel2 != null )
    formQuickSearch.ShowAllByLevel2.value = 0;

  if (formQuickSearch.ShowAllByStatus2 != null)  
    formQuickSearch.ShowAllByStatus2.value = 0;
  
  
  if(ShowAllByLevel == 0) {
    alert('You must select the course level');
    return false;
  }

  return true;
}  
    
function validateQuickSearch2_FF(form) {
  var ShowAllByStatus = formQuickSearch.ShowAllByStatus.value;
  
 if (formQuickSearch.ShowAllByLevel != null )
  formQuickSearch.ShowAllByLevel.value = 0;
 
 if (formQuickSearch.ShowAllByLevel2 != null )
  formQuickSearch.ShowAllByLevel2.value = 0;
 
 if (formQuickSearch.ShowAllByStatus2 != null )
  formQuickSearch.ShowAllByStatus2.value = 0;


  if(ShowAllByStatus == 0) {
    alert('You must select the status');
    return false;
  }

  return true;
}    
    
function validateQuickSearch3_FF(form) {
  var ShowAllByLevel2 = formQuickSearch.ShowAllByLevel2.value;
  var ShowAllByStatus2 = formQuickSearch.ShowAllByStatus2.value;
  
   if (formQuickSearch.ShowAllByLevel != null )
  formQuickSearch.ShowAllByLevel.value = 0;
  
   if (formQuickSearch.ShowAllByStatus != null )
  formQuickSearch.ShowAllByStatus.value = 0;


  if(ShowAllByLevel2 == 0) {
    alert('You must select the course level');
    return false;
  }

  if(ShowAllByStatus2 == 0) {
    alert('You must select the status');
    return false;
  }

  return true;
}

function validateQuickSearchForm_FF(form, button)
{
  var selLvl = document.getElementById('ShowAllByLevel').value;
  var selStat = document.getElementById('ShowAllByStatus').value;
  var selReg = (document.getElementById('ShowAllByRegion') != null ? true : false);
  var selStat2 = -1;
  var selLvl2 = -1;
  var msg = '';
  
  var isAvSelLvl2 = (document.getElementById('ShowAllByLevel2') != null ? true : false);  
  if (isAvSelLvl2) selLvl2 = document.getElementById('ShowAllByLevel2').value;
  
  var isAvSelStat2 = (document.getElementById('ShowAllByStatus2') != null ? true : false);
  if (isAvSelStat2) selStat2 = document.getElementById('ShowAllByStatus2').value;
  
  if (button == 'submit1') 
  {
    msg = '';
  }
  else if (button == 'submit2')
  {
    if (selLvl == '0') msg = 'You must select the course level'; 
  }
  else if (button == 'submit3')
  {
    if (selStat == '0') msg = 'You must select the status'; 
  }
  else if (button == 'submit4')
  {
    if ((isAvSelLvl2) && (selLvl2 == '0')) msg = 'You must select the course level';
    else if ((isAvSelStat2) && (selStat2 == '0')) msg = 'You must select the status';
  }
  else if (button == 'submit5')
  {
    if (selReg == '0') msg = 'You must select the Region'; 
  }

  if (msg == '') return true;
  else
  {
    alert(msg);
    return false;
  }
  
}

function validateFindUserCourse_FF(form) {
  var txtKeyWord = form.txtKeyWord.value;
  //if(txtKeyWord == '') {
  //  alert('You must enter the key word');
  //  return false;
  //}
  return true;
}
