// Application specific Javascript functions
  /*
  window.onload = initialisePage;
  function initialisePage()
  {
    var forms = document.getElementsByTagName("form");
    for (var i=0; i<forms.length; i++)
    {
      var form = forms[i];
      form.onsubmit = checkForm;

      var buttons = form.getElementsByTagName("input");
      for (var j=0; j<buttons.length; j++)
      {
        var button = buttons[j];
        if (button.type== "submit" || button.type == "image") {button.onclick = setButtonPressed;}
      }

    }
  }
  X

  function setButtonPressed(e)
  { // Locate Form containing the button and set the buttonPressed value
    var b = getActivatedObject(e);
    var form = b.parentNode;         var fcount=0;
    while (form.tagName != "FORM" && fcount<50) {fcount++; form = form.parentNode;}
    form.buttonPressed.value = b.name;
  }
  */

  function checkForm(f)
  {
    //var f = getActivatedObject(e);
    //  alert ("Here in checkForm");
    //  alert ("Name=" + f.name);
    // alert ("bp=" + f.buttonPressed.value);

    /*   To test the chosen option in a Select statement:
              var opt=this.selectname.selectedIndex;
              var field=this.selectname.options[opt].text;
              (Can use value instead of text if the option statements have a value clause)

         To test the value of the selected radio button
              var radioLength = this.radioname.length;
              var radioValue = "";
              for (var i=0; i < radioLength; i++)
              {
                if (this.radioname[i].checked)
                {
                  radioValue = this.radioname[i].value;
                  break;
                }
              }
    */

    if (f.buttonPressed.value=="Cancel") {return true;}
    if (f.buttonPressed.value=="Delete")
    {
      if (confirm("Are you really sure you want to delete this record?"))
      {return true;}
      else {return false;}
    }

    if (f.type)
    { // Button pressed
      if (f.name.value =="Cancel") {return true;}
    }
    if (f.type)
    {
      if (f.name.value =="Copy") {return true;}
    }
    if (f.name.value=="Delete")
    {
      if (confirm("Are you really sure you want to delete this record?"))
      {return true;}
      else {return false;}
    }


    var errMsg="";
    var confirmMessage ="";
    switch (f.name)
    {
      case "bannerForm":
        if (empty(f.bannerText.value))
        {
          if (errMsg=="") {f.bannerText.focus();}
          errMsg+="Please enter the Banner Text\n";
        }

        var datesValid = true;
        if (!validateDate(f, "bannerStartDate"))
        {
          if (errMsg=="") {f.bannerStartDateDay.focus();}
          errMsg+="The Banner Start Date is not a valid date\n";
          datesValid = false;
        }

        if (!validateDate(f, "bannerEndDate"))
        {
          if (errMsg=="") {f.bannerEndDateDay.focus();}
          errMsg+="The Banner End Date is not a valid date\n";
          datesValid = false;
        }

        if (datesValid)
        {
          if (compareDates (f, "bannerStartDate", "bannerEndDate") == 1)
          {
            if (errMsg=="") {f.bannerStartDateDay.focus();}
            errMsg+="The Banner Start Date is later than the End date\n";
          }
        }

      break;

      case "centreForm":
        if (empty(f.centreName.value))
        {
          if (errMsg=="") {f.centreName.focus();}
          errMsg+="Please enter the Centre Name\n";
        }

        if (empty(f.centreAddress.value))
        {
          if (errMsg=="") {f.centreAddress.focus();}
          errMsg+="Please enter the Centre Address\n";
        }

        if (empty(f.centrePhone.value))
        {
          if (errMsg=="") {f.centrePhone.focus();}
          errMsg+="Please enter the Centre Telephone No.\n";
        }

        if (empty(f.centreShortDescription.value))
        {
          if (errMsg=="") {f.centreShortDescription.focus();}
          errMsg+="Please enter the Short Description\n";
        }

        if (empty(f.centreLongDescription.value))
        {
          if (errMsg=="") {f.centreLongDescription.focus();}
          errMsg+="Please enter the Full Description\n";
        }
        /*
        if (empty(f.centreDirections.value))
        {
          if (errMsg=="") {f.centreDirections.focus();}
          errMsg+="Please enter the Directions\n";
        }
        */
        if (!empty(f.centreDisplaySequence.value) && !isNumeric(f.centreDisplaySequence.value))
        {
          if (errMsg=="") {f.centreDisplaySequence.focus();}
          errMsg+="If entered the Display Sequence must be numeric\n";
        }
      break;

      case "contactForm":
        if (empty (f.contactName.value))
        {
           if (errMsg=="")  {f.contactName.focus();}
           errMsg+="Please enter your Name\n";
        }

        /*
        if (empty (f.contactCompany.value))
        {
           if (errMsg=="")  {f.contactCompany.focus();}
           errMsg+="Please enter your contactCompany Name\n";
        }


        // if (empty (f.contactAddress1.value) && empty (f.contactAddress2.value) && empty (f.contactAddress3.value))
        if (empty (f.contactAddress1.value))
        {
           if (errMsg=="")  {f.contactAddress1.focus();}
           errMsg+="Please enter your Address\n";
        }

        if (empty (f.contactPostcode.value))
        {
           if (errMsg=="")  {f.contactPostcode.focus();}
           errMsg+="Please enter your contactPostcode\n";
        }
        */
        if (empty (f.contactPhone.value) && empty (f.contactEmail.value))
        {
           if (errMsg=="")  {f.contactPhone.focus();}
           errMsg+="Please enter either your Telephone number or Email Address\n";
        }
        else
        {
          if (!empty (f.contactEmail.value) && !checkEmail (f.contactEmail.value))
          {
            if (errMsg=="")  {f.contactEmail.focus();}
            errMsg+="That Email address is not valid\n";
          }
        }

        if (empty (f.contactMessage.value))
        {
           if (errMsg=="")  {f.contactMessage.focus();}
           errMsg+="Please enter details of your Enquiry\n";
        }
        /*
        if (empty (f.contactSpare04.value))
        {
           if (errMsg=="")  {f.contactSpare04.focus();}
           errMsg+="Please enter your contactSpare04\n";
        }

        if (empty (f.contactSpare05.value))
        {
           if (errMsg=="")  {f.contactSpare05.focus();}
           errMsg+="Please enter your contactSpare05\n";
        }

        if (empty (f.contactSpare06.value))
        {
           if (errMsg=="")  {f.contactSpare06.focus();}
           errMsg+="Please enter your contactSpare06\n";
        }

        if (empty (f.contactSpare07.value))
        {
           if (errMsg=="")  {f.contactSpare07.focus();}
           errMsg+="Please enter your contactSpare07\n";
        }

        if (empty (f.contactSpare08.value))
        {
           if (errMsg=="")  {f.contactSpare08.focus();}
           errMsg+="Please enter your contactSpare08\n";
        }

        if (empty (f.contactSpare09.value))
        {
           if (errMsg=="")  {f.contactSpare09.focus();}
           errMsg+="Please enter your contactSpare09\n";
        }

        if (empty (f.contactSpare10.value))
        {
           if (errMsg=="")  {f.contactSpare10.focus();}
           errMsg+="Please enter your contactSpare10\n";
        }

        if (empty (f.contactSpare11.value))
        {
           if (errMsg=="")  {f.contactSpare11.focus();}
           errMsg+="Please enter your contactSpare11\n";
        }

        if (empty (f.contactSpare12.value))
        {
           if (errMsg=="")  {f.contactSpare12.focus();}
           errMsg+="Please enter your contactSpare12\n";
        }

        if (empty (f.contactSpare13.value))
        {
           if (errMsg=="")  {f.contactSpare13.focus();}
           errMsg+="Please enter your contactSpare13\n";
        }

        if (empty (f.contactSpare14.value))
        {
           if (errMsg=="")  {f.contactSpare14.focus();}
           errMsg+="Please enter your contactSpare14\n";
        }

        */
      break;

      case "eventForm":
        if (empty(f.eventTitle.value))
        {
          if (errMsg=="") {f.eventTitle.focus();}
          errMsg+="Please enter the Event Title\n";
        }

        /*
        if (empty(f.eventDescription.value))
        {
          if (errMsg=="") {f.eventDescription.focus();}
          errMsg+="Please enter the Event Description\n";
        }
        */
        if (f.eventRegularOneOff[1].checked)
        { // On-off event
          if (!validateDate(f, "eventDate"))
          {
            if (errMsg=="") {f.eventDateDay.focus();}
            errMsg+="The Event Date is not a valid date\n";
          }
        }

        if (compareTimes(f, "eventStartTime", "eventEndTime") != 2)
        {
          if (errMsg=="") {f.eventEndTimeHour.focus();}
          errMsg+="The Event End Time must be later than the Event Start Time\n";
        }

        /*
        if (empty(f.eventContactPhone.value) && empty(f.eventContactEmail.value))
        {
          if (errMsg=="") {f.eventContactPhone.focus();}
          errMsg+="Please enter either a Event Contact Telephone No. or Contact Email Address\n";
        }
        */
        if (!empty(f.eventContactEmail.value) && !checkEmail(f.eventContactEmail.value))
        {
          if (errMsg=="") {f.eventContactEmail.focus();}
          errMsg+="The Contact Email Address is not valid\n";
        }

        if (!empty(f.eventURL.value) && !checkURL(f.eventURL.value))
        {
          if (errMsg=="") {f.eventURL.focus();}
          errMsg+="The Event Website Address is not a valid URL\n";
        }
        /*
        if (empty(f.eventField13.value))
        {
          if (errMsg=="") {f.eventField13.focus();}
          errMsg+="Please enter the Event Field13\n";
        }

        if (empty(f.eventField14.value))
        {
          if (errMsg=="") {f.eventField14.focus();}
          errMsg+="Please enter the Event Field14\n";
        }

        if (empty(f.eventField15.value))
        {
          if (errMsg=="") {f.eventField15.focus();}
          errMsg+="Please enter the Event Field15\n";
        }
        */

      break;

      case "feesForm":
        if (empty(f.feesPrivate.value))
        {
          if (errMsg=="") {f.feesPrivate.focus();}
          errMsg+="Please enter the Fee for Private Individuals\n";
        }
        else
        {
          if (!isNumeric(f.feesPrivate.value,2))
          {
            if (errMsg=="") {f.feesPrivate.focus();}
            errMsg+="The Fee for Private Individuals must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.feesAffiliate.value))
        {
          if (errMsg=="") {f.feesAffiliate.focus();}
          errMsg+="Please enter the Fee forAffiliate Groups\n";
        }
        else
        {
          if (!isNumeric(f.feesAffiliate.value,2))
          {
            if (errMsg=="") {f.feesAffiliate.focus();}
            errMsg+="The Fee for Affiliate Groups must be numeric, maximum 2 decimal places\n";
          }
        }

        /*
        if (empty(f.feesField04.value))
        {
          if (errMsg=="") {f.feesField04.focus();}
          errMsg+="Please enter the Fee forField04\n";
        }
        */
      break;

      case "pageForm":
        if (empty(f.pageName.value))
        {
          if (errMsg=="") {f.pageName.focus();}
          errMsg+="Please enter the Page Name\n";
        }

        /*
        if (empty(f.pageField06.value))
        {
          if (errMsg=="") {f.pageField06.focus();}
          errMsg+="Please enter the Page Field06\n";
        }
        */
      break;

      case "roomForm":
        if (empty(f.roomName.value))
        {
          if (errMsg=="") {f.roomName.focus();}
          errMsg+="Please enter the Room Name\n";
        }

        if (empty(f.roomCapacity.value))
        {
          if (errMsg=="") {f.roomCapacity.focus();}
          errMsg+="Please enter the Room Capacity\n";
        }
        else
        {
          if (!isNumeric(f.roomCapacity.value))
          {
            if (errMsg=="") {f.roomCapacity.focus();}
            errMsg+="The Room Capacity must be numeric\n";
          }
        }

        if (!empty(f.roomCapacityParties.value) && !isNumeric(f.roomCapacityParties.value))
        {
          if (errMsg=="") {f.roomCapacityParties.focus();}
          errMsg+="The Maximum Capacity for Parties must be numeric\n";
        }


        if (empty(f.roomDescription.value))
        {
          if (errMsg=="") {f.roomDescription.focus();}
          errMsg+="Please enter the Room Description\n";
        }

        if (empty(f.roomPublicRateWeekdayBand1.value))
        {
          if (errMsg=="") {f.roomPublicRateWeekdayBand1.focus();}
          errMsg+="Please enter the Weekday Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekdayBand1.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekdayBand1.focus();}
            errMsg+="The Weekday Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomPublicRateWeekdayBand2.value))
            {
              if (errMsg=="") {f.roomPublicRateWeekdayBand2.focus();}
          errMsg+="Please enter the Weekday Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekdayBand2.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekdayBand2.focus();}
            errMsg+="The Weekday Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomPublicRateWeekdayBand3.value))
            {
              if (errMsg=="") {f.roomPublicRateWeekdayBand3.focus();}
          errMsg+="Please enter the Weekday Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekdayBand3.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekdayBand3.focus();}
            errMsg+="The Weekday Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomPublicRateWeekendBand1.value))
            {
              if (errMsg=="") {f.roomPublicRateWeekendBand1.focus();}
          errMsg+="Please enter the Weekend Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekendBand1.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekendBand1.focus();}
            errMsg+="Weekend Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomPublicRateWeekendBand2.value))
            {
              if (errMsg=="") {f.roomPublicRateWeekendBand2.focus();}
          errMsg+="Please enter the Weekend Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekendBand2.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekendBand2.focus();}
            errMsg+="Weekend Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomPublicRateWeekendBand3.value))
            {
              if (errMsg=="") {f.roomPublicRateWeekendBand3.focus();}
          errMsg+="Please enter the Weekend Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomPublicRateWeekendBand3.value, 2))
          {
            if (errMsg=="") {f.roomPublicRateWeekendBand3.focus();}
            errMsg+="The Weekend Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomAffiliateRateWeekdayBand1.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekdayBand1.focus();}
          errMsg+="Please enter the Affiliate Weekday Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekdayBand1.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekdayBand1.focus();}
            errMsg+="The Affiliate Weekday Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomAffiliateRateWeekdayBand2.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekdayBand2.focus();}
          errMsg+="Please enter the Affiliate Weekday Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekdayBand2.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekdayBand2.focus();}
            errMsg+="The Affiliate Weekday Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }


        if (empty(f.roomAffiliateRateWeekdayBand3.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekdayBand3.focus();}
          errMsg+="Please enter the Affiliate Weekday Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekdayBand3.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekdayBand3.focus();}
            errMsg+="The Affiliate Weekday Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomAffiliateRateWeekendBand1.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekendBand1.focus();}
          errMsg+="Please enter the Affiliate Weekend Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekendBand1.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekendBand1.focus();}
            errMsg+="The Affiliate Weekend Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomAffiliateRateWeekendBand2.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekendBand2.focus();}
          errMsg+="Please enter the Affiliate Weekend Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekendBand2.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekendBand2.focus();}
            errMsg+="The Affiliate Weekend Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomAffiliateRateWeekendBand3.value))
            {
              if (errMsg=="") {f.roomAffiliateRateWeekendBand3.focus();}
          errMsg+="Please enter the Affiliate Weekend Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomAffiliateRateWeekendBand3.value, 2))
          {
            if (errMsg=="") {f.roomAffiliateRateWeekendBand3.focus();}
            errMsg+="The Affiliate Weekend Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomCommercialRateWeekdayBand1.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekdayBand1.focus();}
          errMsg+="Please enter the Commercial Weekday Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekdayBand1.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekdayBand1.focus();}
            errMsg+="The Commercial Weekday Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomCommercialRateWeekdayBand2.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekdayBand2.focus();}
          errMsg+="Please enter the Commercial Weekday Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekdayBand2.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekdayBand2.focus();}
            errMsg+="The Commercial Weekday Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }


        if (empty(f.roomCommercialRateWeekdayBand3.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekdayBand3.focus();}
          errMsg+="Please enter the Commercial Weekday Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekdayBand3.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekdayBand3.focus();}
            errMsg+="The Commercial Weekday Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomCommercialRateWeekendBand1.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekendBand1.focus();}
          errMsg+="Please enter the Commercial Weekend Rate 9am - 6pm\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekendBand1.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekendBand1.focus();}
            errMsg+="The Commercial Weekend Rate 9am - 6pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomCommercialRateWeekendBand2.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekendBand2.focus();}
          errMsg+="Please enter the Commercial Weekend Rate 6pm - 11pm\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekendBand2.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekendBand2.focus();}
            errMsg+="The Commercial Weekend Rate 6pm - 11pm must be numeric, maximum 2 decimal places\n";
          }
        }

        if (empty(f.roomCommercialRateWeekendBand3.value))
            {
              if (errMsg=="") {f.roomCommercialRateWeekendBand3.focus();}
          errMsg+="Please enter the Commercial Weekend Rate 11pm - midnight\n";
        }
        else
        {
          if (!isNumeric(f.roomCommercialRateWeekendBand3.value, 2))
          {
            if (errMsg=="") {f.roomCommercialRateWeekendBand3.focus();}
            errMsg+="The Commercial Weekend Rate 11pm - midnight must be numeric, maximum 2 decimal places\n";
          }
        }

      break;

      case "weblinkForm":
        if (empty(f.weblinkName.value))
        {
          if (errMsg=="") {f.weblinkName.focus();}
          errMsg+="Please enter the Link Name\n";
        }
        /*
        if (empty(f.weblinkDescription.value))
        {
          if (errMsg=="") {f.weblinkDescription.focus();}
          errMsg+="Please enter the Description\n";
        }
        */
        if (empty(f.weblinkWebAddress.value))
        {
          if (errMsg=="") {f.weblinkWebAddress.focus();}
          errMsg+="Please enter the Web Address\n";
        }
        else
        {
          if (!checkURL(f.weblinkWebAddress.value))
          {
            if (errMsg=="") {f.weblinkWebAddress.focus();}
            errMsg+="That Web Address is not valid\n";
          }
        }

        if (!empty(f.weblinkSequence.value) && !isNumeric(f.weblinkSequence.value))
        {
          if (errMsg=="") {f.weblinkSequence.focus();}
          errMsg+="If entered the Display Sequence must be numeric\n";
        }

      break;



      default:
      return true;
    }

    if (errMsg!="")
    {
      alert(errMsg);
      return false;
    }
    else
    {
       if (confirmMessage!="")
       {
         if (confirm(confirmMessage)) {return true;}
         else {return false;}
       }
       else {return true;}
    }
  }

  function showHideDiv(event)
  {
    var e = getElement(event);
    if (e)
    {
      if (e.className == "hideDiv" || e.className == "hideDiv2")
      {
        if (e.className == "hideDiv") {e.className = "showDiv";} else {e.className = "showDiv2";}
      }
      else
      {
        if (e.className == "showDiv") {e.className = "hideDiv";} else {e.className = "hideDiv2";}
      }
    }
  }