Dim Submission, Total, x, birthDay

'===Sets new color in rows,buttons in Mouse Over/Mouse Out event========
Function ChangeButtonColor(tID,mBGColor,mFColor)
    tID.style.background = mBGColor
    tID.style.color = mFColor
End Function

Function RestoreButtonColor(tID,mBGColor,mFColor)
    tID.style.background = mBGColor
    tID.style.color = mFColor
End Function
'===End of set new color in rows,buttons in Mouse Over/Mouse Out event===

'===Which button was clicked by the user===
Function WhichButton(mForm,mAction)
    with mForm
        .getAction.value = mAction
    end with
End Function
'==========================================

Function showInputBox(mForm)
    Dim iBox

    with mForm
       Submission = "True"

       iBox = InputBox("Pls enter the new category.", "New Category", "New Category")
       if trim(iBox) <> "" AND trim(iBox) <> "New Category" then
          .newCat.value = iBox
          .getAction.value = "addcategory"
          .submit()
       end if
    end with
End Function

Function get_Items(mForm)
    with mForm
       WhichButton mForm, "getItems"
       .submit()
    end with
End Function

'===Get a valid FileName===
Function GetFileName(mForm,mCtrl)
   Dim strFilename

   with mForm
        strFilename = strreverse(document.all("attach" & mCtrl).value)
        strFilename = strreverse(document.all("attach" & mCtrl).value)
        strFilename = instr(1,strfilename,"\")
        strfilename = right(document.all("attach" & mCtrl).value,strFilename - 1)

        document.all("FileName" & mCtrl).value = strFilename
   end with
End Function
'==========================

'===Validation of uploading form===
Function frmSend_Submit(mForm)
    Dim uploadBox(3),FileNameBox(3),x,y,z,validBannerFile,hasDuplicateFiles,hasFilesToUpload,ctr


    Submission = "True"
    with mForm

      uploadBox(0) = trim(.attach1.value)
'      uploadBox(1) = trim(.attach2.value)
'      uploadBox(2) = trim(.attach3.value)
'      uploadBox(3) = trim(.attach4.value)

      FileNameBox(0) = trim(.FileName1.value)
'      FileNameBox(1) = trim(.FileName2.value)
'      FileNameBox(2) = trim(.FileName3.value)
'      FileNameBox(3) = trim(.FileName4.value)

      '===valid banner/pix files only===
      validBannerFile = Array(".jpg", ".jpeg", ".gif", ".png", ".bmp", ".tif")
      '===valid banner/pix files only===

      hasFilesToUpload = "False"
      hasDuplicateFiles = "True"
      AllFilesValid = "True"
      y = 0
      z = 0

      for x = 0 to UBound(uploadBox)
         if uploadBox(x) <> "" then
            hasFilesToUpload = "True"

            '===Only the text file extensions are allowed
            do while z <= UBound(validBannerFile)
               if instr(1, uploadBox(x), validBannerFile(z), vbTextCompare) = 0 then
                  AllFilesValid = "False"
               else
                 AllFilesValid = "True"
                 exit do
               end if
               z = z + 1
            loop
            if Not AllFilesValid then exit for
            '===End of the text file extensions are allowed
         end if
      next

      if Not hasFilesToUpload then
         msgbox "Please click the browse button and select a file.", vbCritical, "No File Selected"
         Submission = "False"
         .attach1.focus()
         exit function
      end if

      if Not AllFilesValid then
         Msg = "Error : You can only select a valid image files." & vbcrlf & vbcrlf
         Msg = Msg & "Invalid file attached in File " & x + 1 & " box."
         msgbox Msg, vbCritical, "Invalid File Selected"
         Submission = "False"
         exit function
      end if
    end with
End Function
'==================================

'===Checks All and Unchecks All the delete checkboxes
'--when the user clicks the checkbox at the heading just like in hotmail
Function CheckAll(mForm)
    with mForm
      if .deleteall.Checked then
         for x = 1 to document.all("h").value
            set objChkDel = document.all("chkDelete" & x)
            objChkDel.Checked = "True"
         next
      else
         for x = 1 to document.all("h").value
            set objChkDel = document.all("chkDelete" & x)
            objChkDel.Checked = "False"
         next
      end if
    end with
End Function

'===If the user checks All delete checkboxes set the main checkbox at the heading to true
'===if not,set the main checkbox to false just like in hotmail===
Function CheckUncheck(mForm)
    with mForm
      chkDel = 0
      for x = 1 to document.all("h").value
         set objChkDel = document.all("chkDelete" & x)
         ctr = x
         if objChkDel.Checked then chkDel = chkDel + 1
      next
      if chkDel = ctr then 
         .deleteall.Checked = "True"
      else
         .deleteall.Checked = "False"
      end if
    end with
End Function
'================================================================

'===Delete validation in display page===
Function frmDelete_Submit(mForm)
    Dim Msg

    with mForm

        Total = 0
        Submission = "True"

        SELECT CASE trim(.getAction.value)
           Case "Delete"
              for x = 1 to .h.value
                 Set objChk = document.all("chkDelete" & x)
                 if objChk.Checked then total = total + 1
              next

              if total = 0 then
                 msgbox "Error : No checkbox selected." & vbCrLf & "You have to check at least one checkbox to delete!",vbCritical,"Cancel Delete"
                 Submission = "False"
                 exit function
              else
                 if msgbox("You are about to delete " & total & " record(s)!" & vbCrLf & "Delete anyway...",308,"Delete Confirmation") = vbNo then
                    Submission = "False"
                    exit function
                 end if
              end if
           Case "Update"
              for x = 1 to .h.value
                 set txtwdID = document.all("wdID" & x)
                 set cboWinDesc = document.all("WinDesc" & x)
                 if trim(txtwdID.value) <> trim(cboWinDesc.value) then total = total + 1
              next

              if total = 0 then
                 msgbox Msg,vbCritical,"Cancel Update"
                 Submission = "False"
                 exit function
              else
                 if msgbox("You are about to update " & total & " record(s)!" & vbCrLf & "Update anyway...",308,"Update Confirmation") = vbNo then
                    Submission = "False"
                    exit function
                 end if
              end if
        END SELECT
    end with
End Function
'===Delete validation in display page===

'===add/items.asp, edit/items.asp entry===
Function frmItems_Submit(mForm)
   with mForm
       Submission = "True"

       SELECT CASE trim(.getAction.value)
           Case "addcategory"
               
           Case "additem"
               if .catID.selectedIndex = 0 then
                   msgbox "Pls select the category from the list!",vbCritical,"No Category Selected"
                   .catID.focus()
                   Submission = "False"
                   exit function
               end if
               if trim(.ItemName.value) = "" then
                   msgbox "Pls enter the Item Name field!",vbCritical,"No Item Name"
                   .ItemName.focus()
                   Submission = "False"
                   exit function
               end if
               if trim(.ItemDesc.value) = "" then
                   msgbox "Pls enter the Item Description field!",vbCritical,"No Item Description"
                   .ItemDesc.focus()
                   Submission = "False"
                   exit function
               end if
       END SELECT
   end with
End Function
'===add/items.asp, edit/items.asp entry===

'===Search validations===
Function frmSearch_Submit(mForm)
   with mForm
       Submission = "True"

       SELECT CASE trim(.getAction.value)
          Case "Search"
             if trim(.Search.value) = "" then
                msgbox "Pls enter a keyword to be searched!",vbCritical,"No KeyWord"
                .Search.focus()
                Submission = "False"
                exit function
             end if
          Case "Register"
             if trim(.FName.value) = "" then
                msgbox "Pls enter your First Name!",vbCritical,"No First Name"
                .FName.focus()
                Submission = "False"
                exit function
             end if
             if trim(.LName.value) = "" then
                msgbox "Pls enter your Last Name!",vbCritical,"No Last Name"
                .LName.focus()
                Submission = "False"
                exit function
             end if
             if trim(.Email.value) = "" then
                msgbox "Pls enter your Email Address!",vbCritical,"No Email Address"
                .Email.focus()
                Submission = "False"
                exit function
             elseif instr(1,.Email.value,"@") = 0 OR instr(1,.Email.value,".") = 0 then
                msgbox "Pls enter your proper Email Address!",vbCritical,"Invalid Email Address"
                .Email.focus()
                Submission = "False"
                exit function
             end if
             if trim(.strCAPTCHA.value) = "" then
                msgbox "Pls enter the Verification Number!",vbCritical,"No Verification Number"
                .strCAPTCHA.focus()
                Submission = "False"
                exit function
             elseif not isnumeric(.strCAPTCHA.value) then
                msgbox "Verification Number should be an integer!",vbCritical,"Invalid Verification Number"
                .strCAPTCHA.focus()
                Submission = "False"
                exit function
             end if
       END SELECT
   end with
End Function
'===Search validations===
