//------------------
// My table cell roll over script
//------------------

function mOvr(src,clrOver)
{ 
  if (!src.contains(event.fromElement))
  { 
    src.style.cursor = 'hand'; 
    src.bgColor = clrOver; 
  } 
} 

function mOut(src,clrIn)
{ 
  if (!src.contains(event.toElement))
  { 
    src.style.cursor = 'default'; 
    src.bgColor = clrIn; 
  } 
}

function mClk(src)
{
  if(event.srcElement.tagName=='TD')
  {
    src.children.tags('A')[0].click();
  }
}



// ----- Function library for PetCall -----
// 
// Does not exist in all other sites using this engine
//
// ----------------------------------------


  function checkEmail(varEmail)
  { // returns true if e-mail address is ok
    varEmailOK = false;  // assumes it is not ok
    if (varEmail != "")  // check for blank e-mail address
    {
      if (varEmail.indexOf("@") != -1 && varEmail.indexOf(".") != -1 && varEmail.indexOf(" ") == -1)
      {
        varEmailOK = true;
      }
      else
      {
        alert("Please enter valid e-mail address.");
      }
    }
    else
    {
      alert("Please enter e-mail address.");
    }

    return varEmailOK;
  }

  function checkName(varSalutation, varName)
  { // returns true if salutation and full name is ok
    //  - salutation is not blank
    //  - full name is not blank
    varNameOK = false;  // assumes it is not ok
    if ((varSalutation != "") &&   // salutation is not blank
        (varName != ""))           // name is not blank
    {varNameOK = true;}
    else
    {
      alert("Please enter name.");
    }
    return varNameOK;
  }

  function checkIdent(varIdent)
  { // returns true if NRIC/FIN number is valid
    varIdentOK = false;  // assumes it is not ok
    if (varIdent != "")  // check for blank NRIC/FIN number
    { // Verify that NRIC or FIN number is correct; not a blank NRIC/FIN has been supplied
      if ((varIdent.length == 9) &&               //  - must be 9 characters in total length
          (isNaN (varIdent.substring(0,1))) &&    //  - first character must be alphabet
          (!isNaN (varIdent.substring(1,8))) &&   //  - next 7 characters must be numeric
          (isNaN (varIdent.substring(8,9))))      //  - last character must be alphabet
      {
        if (varIdent.substring(0,1).toUpperCase() == "S")
        { // Check digit verification for S series NRIC
          varCheckTotal = 0
          varCheckTotal = varCheckTotal + (varIdent.substring(1,2) * 2);
          varCheckTotal = varCheckTotal + (varIdent.substring(2,3) * 7);
          varCheckTotal = varCheckTotal + (varIdent.substring(3,4) * 6);
          varCheckTotal = varCheckTotal + (varIdent.substring(4,5) * 5);
          varCheckTotal = varCheckTotal + (varIdent.substring(5,6) * 4);
          varCheckTotal = varCheckTotal + (varIdent.substring(6,7) * 3);
          varCheckTotal = varCheckTotal + (varIdent.substring(7,8) * 2);
          varCheckTotal = 11 - (varCheckTotal % 11);

          varCheckDigit = ""
          if (varCheckTotal == 1) {varCheckDigit = "A";}
          if (varCheckTotal == 2) {varCheckDigit = "B";}
          if (varCheckTotal == 3) {varCheckDigit = "C";}
          if (varCheckTotal == 4) {varCheckDigit = "D";}
          if (varCheckTotal == 5) {varCheckDigit = "E";}
          if (varCheckTotal == 6) {varCheckDigit = "F";}
          if (varCheckTotal == 7) {varCheckDigit = "G";}
          if (varCheckTotal == 8) {varCheckDigit = "H";}
          if (varCheckTotal == 9) {varCheckDigit = "I";}
          if (varCheckTotal == 10) {varCheckDigit = "Z";}
          if (varCheckTotal == 11) {varCheckDigit = "J";}
 
          if (varIdent.substring(8,9).toUpperCase() == varCheckDigit) {varIdentOK = true;}
        }

        if (varIdent.substring(0,1).toUpperCase() == "T")
        { // Check digit verification for T series NRIC
          //  - algorithm is unknown at this time
          varIdentOK = true;
        }

        if (varIdent.substring(0,1).toUpperCase() == "F")
        { // Check digit verification for F series FIN
          //  - algorithm is unknown at this time
          varIdentOK = true;
        }

        if (varIdent.substring(0,1).toUpperCase() == "G")
        { // Check digit verification for G series FIN
          //  - algorithm is unknown at this time
          varIdentOK = true;
        }
      }
    }
    if (!varIdentOK)
    {
      alert("Please enter NRIC/FIN number.\n\nA valid NRIC/FIN number should be:\n     - prefixed by the appropriate century prefix\n       [S or T for NRIC; F or G for FIN]\n     - 7 digits in length; no alphabets or punctuation marks\n     - suffixed by the appropriate check letter\n       [verifiable by computation]");
    }
    return varIdentOK;
  }

  function checkAddress(varAddress, varState, varZip, varCountry)
  { // returns true if a complete address is provided
    varAddressOK = false;  // assumes it is not ok
    if ((varAddress != "") &&     //  - Address is not blank
        (varState != "") &&       //  - State is not blank
        (varZip != "") &&         //  - Zip code is not blank
        (varZip.length == 6) &&   //  - Zip code is 6 digits long
        (!isNaN(varZip)) &&       //  - Zip code is numeric only
        (varCountry != ""))       //  - Country is not blank
    {varAddressOK = true;}
    else
    {
      alert("Please enter complete address.\n\nA complete address should have:\n     - the Address field is filled in\n     - the State/province field is filled in\n     - the Zip/post code field is filled in with a valid zip/post code\n       [6 digits; no alphabets or punctuation marks]\n     - the Country field is selected for your country");
    }
    return varAddressOK;
  }

  function checkContact(varNumber, varType)
  { // returns true if a complete contact number is provided
    //  - Fax & Mobile numbers are optional
    varNumberOK = false;  // assumes it is not ok
    if (varType == "phone")
    {
      if ((varNumber != "") &&                    //  - Number is not a blank
          (varNumber.length == 9) &&              //  - Number is 8 digits long with separator; total 9
          (!isNaN(varNumber.substring(0,4))) &&   //  - First 4 digit sequence is numeric only
          (isNaN(varNumber.substring(4,5))) &&    //  - Separator is not a number
          (!isNaN(varNumber.substring(5,9))) &&   //  - Second 4 digit sequence is numeric only
          (varNumber.substring(4,5) == "-"))      //  - Separator is the character "-" only
      {varNumberOK = true;}
    }
    else
    {
      if (varNumber != "")
      {
      if ((varNumber.length == 9) &&              //  - Number is 8 digits long with separator; total 9
          (!isNaN(varNumber.substring(0,4))) &&   //  - First 4 digit sequence is numeric only
          (isNaN(varNumber.substring(4,5))) &&    //  - Separator is not a number
          (!isNaN(varNumber.substring(5,9))) &&   //  - Second 4 digit sequence is numeric only
          (varNumber.substring(4,5) == "-"))      //  - Separator is the character "-" only
        {varNumberOK = true;}
      }
      else
      {
        varNumberOK = true;
      }
    }
    if (!varNumberOK)
    {
      alert("Please enter " + varType + " number.\n\nA valid " + varType + " number is in the form of 9999-9999.");
    }
    return varNumberOK;
  }



  function checkMicrochip(varMicrochip)
  { // returns true if microchip number is ok
    varMicrochipOK = false;
    if (varMicrochip != "")        // microchip is a number
     {   // (!isNaN(varMicrochip)) &&      // microchip is a number
        // (varMicrochip.length == 15))   // microchip length is 15 characters
    varMicrochipOK = true;
	}
    else
    {
      alert("Please enter pet's microchip number.");
    }
    return varMicrochipOK;
  }

  function checkPetName(varName)
  { // returns true if pet name is ok
    varNameOK = false;  // assumes it is not ok
    if (varName != "") {varNameOK = true;}  // check for blank pet name
    else
    {
      alert("Please enter pet's name.");
    }
    return varNameOK;
  }

  function checkSpeciesBreed(varSpecies,varBreed)
  { // returns true if pet species and breed is ok
    varSpeciesBreedOK = false;  // assumes it is not ok
    if ((varSpecies != "") &&   // species is not blank
        (varBreed != ""))       // breed is not blank
    {varSpeciesBreedOK = true;}
    else
    {
      alert("Please select pet's species and breed.");
    }
    return varSpeciesBreedOK;
  }

  function checkDateBirth(varPetBirthDay,varPetBirthMonth,varPetBirthYear)
  { // returns true if pet birth date is ok
    varPetBirthOK = false;  // assumes it is not ok

    varPetBirth = new Date();
    varPetBirth.setDate(varPetBirthDay);
    varPetBirth.setMonth(varPetBirthMonth - 1);
    varPetBirth.setFullYear(varPetBirthYear);
    varPetNow = new Date();

    if ((varPetBirthMonth == 4) ||   // April
        (varPetBirthMonth == 6) ||   // June
        (varPetBirthMonth == 9) ||   // September
        (varPetBirthMonth == 11))    // November
    { // Months with 30 days
      if (varPetBirthDay <= 30)
      {
        if (varPetNow - varPetBirth >= 0) {varPetBirthOK = true;}
      }
    }

    if ((varPetBirthMonth == 1) ||    // January
        (varPetBirthMonth == 3) ||    // March
        (varPetBirthMonth == 5) ||    // May
        (varPetBirthMonth == 7) ||    // July
        (varPetBirthMonth == 8) ||    // August
        (varPetBirthMonth == 10) ||   // October
        (varPetBirthMonth == 12))     // December
    { // Months with 31 days
      if (varPetBirthDay <= 31)
      {
         if (varPetNow - varPetBirth >= 0) {varPetBirthOK = true;}
      }
    }

    if (varPetBirthMonth == 2)
    { // February special case
      if (varPetBirthYear % 4 == 0)
      { // Leap year - February has 29 days
        if (varPetBirthDay <= 29)
        {
           if (varPetNow - varPetBirth >= 0) {varPetBirthOK = true;}
        }
      }
      else
      { // Not leap year - February has 28 days
        if (varPetBirthDay <= 28)
        {
           if (varPetNow - varPetBirth >= 0) {varPetBirthOK = true;}
        }
      }
    }

    if (!varPetBirthOK)
    {
      alert("Please select pet's birth date.");
    }

    return varPetBirthOK;
  }

  function checkDateDeath(varPetBirthDay,varPetBirthMonth,varPetBirthYear,varPetDeathDay,varPetDeathMonth,varPetDeathYear)
  { // returns true if pet death date is ok
    varPetDeathOK = false;  // assumes it is not ok

    varPetBirth = new Date();
    varPetBirth.setDate(varPetBirthDay);
    varPetBirth.setMonth(varPetBirthMonth - 1);
    varPetBirth.setFullYear(varPetBirthYear);
    varPetDeath = new Date();
    varPetDeath.setDate(varPetDeathDay);
    varPetDeath.setMonth(varPetDeathMonth - 1);
    varPetDeath.setFullYear(varPetDeathYear);
    varPetNow = new Date();

    if ((varPetDeathDay == "--") && (varPetDeathMonth == "--") && (varPetDeathYear == "--"))
    { // No date specified - valid value to be ignored by script
      varPetDeathOK = true;
    }
    else
    {
      if ((varPetDeathDay != "--") && (varPetDeathMonth != "--") && (varPetDeathYear != "--"))
      { // A date was specified - verify validity

        if ((varPetDeathMonth == 4) ||   // April
            (varPetDeathMonth == 6) ||   // June
            (varPetDeathMonth == 9) ||   // September
            (varPetDeathMonth == 11))    // November
        { // Months with 30 days
          if (varPetDeathDay <= 30)
          {
            if ((varPetDeath - varPetBirth >= 0) && (varPetNow - varPetDeath >= 0)) {varPetDeathOK = true;}
          }
        }

        if ((varPetDeathMonth == 1) ||    // January
            (varPetDeathMonth == 3) ||    // March
            (varPetDeathMonth == 5) ||    // May
            (varPetDeathMonth == 7) ||    // July
            (varPetDeathMonth == 8) ||    // August
            (varPetDeathMonth == 10) ||   // October
            (varPetDeathMonth == 12))     // December
        { // Months with 31 days
          if (varPetDeathDay <= 31)
          {
            if ((varPetDeath - varPetBirth >= 0) && (varPetNow - varPetDeath >= 0)) {varPetDeathOK = true;}
          }
        }

        if (varPetDeathMonth == 2)
        { // February special case
          if (varPetDeathYear % 4 == 0)
          { // Leap year - February has 29 days
            if (varPetDeathDay <= 29)
            {
              if ((varPetDeath - varPetBirth >= 0) && (varPetNow - varPetDeath >= 0)) {varPetDeathOK = true;}
            }
          }
          else
          { // Not leap year - February has 28 days
            if (varPetDeathDay <= 28)
            {
              if ((varPetDeath - varPetBirth >= 0) && (varPetNow - varPetDeath >= 0)) {varPetDeathOK = true;}
            }
          }
        }
      }
      else
      { // Not a valid date - mixture of "--" and digits
        varPetDeathOK = false;
      }
    }

    if (!varPetDeathOK)
    {
      alert("Please select pet's demise date.");
    }

    return varPetDeathOK;
  }

  function checkGender(varGender)
  { // returns true if pet gender is ok
    varGenderOK = false;  // assumes it is not ok
    if (varGender != "") {varGenderOK = true;}  // check for blank gender
    else
    {
      alert("Please select pet's gender.");
    }
    return varGenderOK;
  }

  function checkColor(varColor)
  { // returns true if pet color is ok
    varColorOK = false;  // assumes it is not ok
    if (varColor != "") {varColorOK = true;}  // check for blank color
    else
    {
      alert("Please enter pet's color.");
    }
    return varColorOK;
  }

  function checkOrganisation(varOrganisation)
  { // returns true if agent organisation is ok
    varOrganisationOK = false;  // assumes it is not ok
    if (varOrganisation != "") {varOrganisationOK = true;}  // check for blank organisation
    else
    {
      alert("Please enter organisation's name.");
    }
    return varOrganisationOK;
  }

  function checkPassword(varPassword)
  { // returns true if password is ok
    varPasswordOK = false;  // assumes it is not ok
    if (varPassword != "") {varPasswordOK = true;}  // check for blank password
    else
    {
      alert("Please enter supplied password.");
    }
    return varPasswordOK;
  }

  function checkLastSeenWhen(varDay,varMonth,varYear)
  { // returns true if pet last seen date is ok
    varLastSeenOK = false;  // assumes it is not ok

    varLastSeen = new Date();
    varLastSeen.setDate(varDay);
    varLastSeen.setMonth(varMonth - 1);
    varLastSeen.setFullYear(varYear);
    varPetNow = new Date();

    if ((varMonth == 4) ||   // April
        (varMonth == 6) ||   // June
        (varMonth == 9) ||   // September
        (varMonth == 11))    // November
    { // Months with 30 days
      if (varDay <= 30)
      {
        if (varPetNow - varLastSeen >= 0) {varLastSeenOK = true;}
      }
    }

    if ((varMonth == 1) ||    // January
        (varMonth == 3) ||    // March
        (varMonth == 5) ||    // May
        (varMonth == 7) ||    // July
        (varMonth == 8) ||    // August
        (varMonth == 10) ||   // October
        (varMonth == 12))     // December
    { // Months with 31 days
      if (varDay <= 31)
      {
        if (varPetNow - varLastSeen >= 0) {varLastSeenOK = true;}
      }
    }

    if (varMonth == 2)
    { // February special case
      if (varYear % 4 == 0)
      { // Leap year - February has 29 days
        if (varDay <= 29)
        {
          if (varPetNow - varLastSeen >= 0) {varLastSeenOK = true;}
        }
      }
      else
      { // Not leap year - February has 28 days
        if (varDay <= 28)
        {
          if (varPetNow - varLastSeen >= 0) {varLastSeenOK = true;}
        }
      }
    }

    if (!varLastSeenOK)
    {
      alert("Please select a valid date.");
    }

    return varLastSeenOK;
  }

  function checkLastSeenWhere(varWhere)
  { // returns true if last seen place is ok
    varLastSeenOK = false;  // assumes it is not ok
    if (varWhere != "") {varLastSeenOK = true;}  // check for blank place
    else
    {
      alert("Please enter a location.");
    }
    return varLastSeenOK;
  }
