Microsoft's Active Server Pages (ASP) technology (or, Classic ASP as it's called these days) was designed to an easy way to build web applications: just code some HTML and sprinkle some VBScript between <'% ... %>
blocks. It was (and, for the most part, still can be) a decent, simple tool for building simple things.
Of course, there's one big problem with simple tools: they're simple, and certain developers are too smart for simple. And that brings us to Catherine P, who's found herself maintaining a sprawling mess of a Classic ASP system that should have been retired years ago. Of the many "innovative and unique" patterns introduced by the original developer is "limiting the amount of JavaScript sent to the browser." As to how is this wizardy is accomplished... there is code like this is in the header of each page.
<head> ... <script language="JavaScript"><!-- // Get date checking functions <% = CheckDateFunction %> <% = IsNumericFunction %> //--> </script> </head>
So long as you include client_functions.asp
, you can simply "reference" whatever JavaScript functions are needed on the page, without needing to have the browser download all sorts of code it won't use for that page.
<% ''''''''''''''''''''''''''''''''''''''''''''''''''''' ' client_functions.asp ''''''''''''''''''''''''''''''''''''''''''''''''''''' Function CheckDateFunction() ' Returns the HTML/Javascript required to produce the CheckDate() function. Dim strHTML strHTML = strHTML & "function CheckDate(strDate, strCentury)" & vbCrLf strHTML = strHTML & "{" & vbCrLf strHTML = strHTML & " var strToday = new Date(); " & vbCrLf strHTML = strHTML & " var strDay = '';" & vbCrLf strHTML = strHTML & " var strMonth = '';" & vbCrLf strHTML = strHTML & " var strYear = '';" & vbCrLf strHTML = strHTML & " var intPos; " & vbCrLf strHTML = strHTML & " var strMonthname;" & vbCrLf strHTML = strHTML & " var strFinalDate;" & vbCrLf strHTML = strHTML & " var blnIsLeapYear" & vbCrLf strHTML = strHTML & " var strLastValidDay" & vbCrLf strHTML = strHTML & " strMonthName = new Array('Dummy', 'Jan', 'Feb', 'Mar', 'Apr', " strHTML = strHTML & " 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');" & vbCrLf strHTML = strHTML & " intPos = 0" & vbCrLf strHTML = strHTML & " while(IsNumeric(strDate.charAt(intPos)) && intPos < strDate.length){" & vbCrLf strHTML = strHTML & " strDay += strDate.charAt(intPos);" & vbCrLf strHTML = strHTML & " intPos++;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " if(strDate.charAt(intPos) != ' ' && strDate.charAt(intPos) != '.' && " strHTML = strHTML & " strDate.charAt(intPos) != '/' && strDate.charAt(intPos) != '-') " & vbCrLf strHTML = strHTML & " return('');" & vbCrLf strHTML = strHTML & " while((strDate.charAt(intPos) == ' ' || strDate.charAt(intPos) == '.' || " strHTML = strHTML & " strDate.charAt(intPos) == '/' || strDate.charAt(intPos) == '-') && " strHTML = strHTML & " intPos < strDate.length)" & vbCrLf strHTML = strHTML & " intPos += 1;" & vbCrLf strHTML = strHTML & " while(strDate.charAt(intPos) != ' ' && strDate.charAt(intPos) != '.' && " strHTML = strHTML & " strDate.charAt(intPos) != '/' && strDate.charAt(intPos) != '-' && " strHTML = strHTML & " intPos < strDate.length){" & vbCrLf strHTML = strHTML & " strMonth += strDate.charAt(intPos);" & vbCrLf strHTML = strHTML & " intPos += 1;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " while((strDate.charAt(intPos) == ' ' || strDate.charAt(intPos) == '.' || " strHTML = strHTML & " strDate.charAt(intPos) == '/' || strDate.charAt(intPos) == '-') && " strHTML = strHTML & " intPos < strDate.length)" & vbCrLf strHTML = strHTML & " intPos += 1;" & vbCrLf strHTML = strHTML & " while(intPos < strDate.length){" & vbCrLf strHTML = strHTML & " strYear += strDate.charAt(intPos);" & vbCrLf strHTML = strHTML & " intPos += 1;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " if(!strCentury){ " & vbCrLf strHTML = strHTML & " if(strYear == ''){" & vbCrLf strHTML = strHTML & " today = new Date()" & vbCrLf strHTML = strHTML & " strYear = today.getFullYear();" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " else{" & vbCrLf strHTML = strHTML & " if(strYear < 70){ " & vbCrLf strHTML = strHTML & " if(parseInt(strYear,10) < 10) " & vbCrLf strHTML = strHTML & " strYear = '0' + parseInt(strYear,10)" & vbCrLf strHTML = strHTML & " strYear = '20' + strYear;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " else{" & vbCrLf strHTML = strHTML & " if(strYear < 100)" & vbCrLf strHTML = strHTML & " strYear = '19' + strYear;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " else{ " & vbCrLf strHTML = strHTML & " if(strYear == ''){" & vbCrLf strHTML = strHTML & " today = new Date()" & vbCrLf strHTML = strHTML & " strYear = today.getFullYear();" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " else{" & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) < 100){" & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) < 10)" & vbCrLf strHTML = strHTML & " strYear = '0' + parseInt(strYear,10)" & vbCrLf strHTML = strHTML & " strYear = strCentury + strYear;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " if(!(IsNumeric(strDay) && IsNumeric(strYear)))" & vbCrLf strHTML = strHTML & " return ('') ;" & vbCrLf strHTML = strHTML & " if(parseInt(strDay, 10) < 10)" & vbCrLf strHTML = strHTML & " strDay = '0' + parseInt(strDay,10)" & vbCrLf strHTML = strHTML & " if(IsNumeric(strMonth) && parseInt(strMonth, 10) > 0 && " strHTML = strHTML & " parseInt(strMonth,10) < 13)" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[parseInt(strMonth, 10)];" & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) < 0 || parseInt(strYear,10) > 9999)" & vbCrLf strHTML = strHTML & " return '' " & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) % 400 == 0)" & vbCrLf strHTML = strHTML & " blnIsLeapYear = true;" & vbCrLf strHTML = strHTML & " else{" & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) % 100 == 0)" & vbCrLf strHTML = strHTML & " blnIsLeapYear = false;" & vbCrLf strHTML = strHTML & " else{" & vbCrLf strHTML = strHTML & " if(parseInt(strYear, 10) % 4 == 0)" & vbCrLf strHTML = strHTML & " blnIsLeapYear = true;" & vbCrLf strHTML = strHTML & " else" & vbCrLf strHTML = strHTML & " blnIsLeapYear = false;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " strMonth = strMonth.substr(0, 3)" & vbCrLf strHTML = strHTML & " strMonth = strMonth.toLowerCase()" & vbCrLf strHTML = strHTML & " switch(strMonth) {" & vbCrLf strHTML = strHTML & " case 'jan' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[1];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'feb' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[2];" & vbCrLf strHTML = strHTML & " blnIsLeapYear ? strLastValidDay = '29' " strHTML = strHTML & " : strLastValidDay = '28'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'mar' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[3];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'apr' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[4];" & vbCrLf strHTML = strHTML & " strLastValidDay = '30'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'may' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[5];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'jun' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[6];" & vbCrLf strHTML = strHTML & " strLastValidDay = '30'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'jul' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[7];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'aug' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[8];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'sep' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[9];" & vbCrLf strHTML = strHTML & " strLastValidDay = '30'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'oct' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[10];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'nov' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[11];" & vbCrLf strHTML = strHTML & " strLastValidDay = '30'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " case 'dec' :" & vbCrLf strHTML = strHTML & " strMonth = strMonthName[12];" & vbCrLf strHTML = strHTML & " strLastValidDay = '31'" & vbCrLf strHTML = strHTML & " break;" & vbCrLf strHTML = strHTML & " default : " & vbCrLf strHTML = strHTML & " return ''" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " if(parseInt(strDay,10) < 1 || parseInt(strDay, 10) > " strHTML = strHTML & " parseInt(strLastValidDay, 10))" & vbCrLf strHTML = strHTML & " return '';" & vbCrLf strHTML = strHTML & " strFinalDate = strDay + ' ' + strMonth + ' ' + strYear;" & vbCrLf strHTML = strHTML & " return strFinalDate" & vbCrLf strHTML = strHTML & "}" & vbCrLf & vbCrLf CheckDateFunction = strHTML End Function Public Function IsNumericFunction() ' Returns the HTML/Javascript required to produce the IsNumeric() function. Dim strHTML strHTML = strHTML & "function IsNumeric(strNum)" & vbCrLf strHTML = strHTML & "{" & vbCrLf strHTML = strHTML & " var intCount = 0;" & vbCrLf strHTML = strHTML & " blnIsNumeric = new Boolean(true); " & vbCrLf strHTML = strHTML & " while(intCount < strNum.length){" & vbCrLf strHTML = strHTML & " if(!(parseInt(strNum.charAt(intCount), 10) >=0 && " strHTML = strHTML & " parseInt(strNum.charAt(intCount), 10) <= 9))" & vbCrLf strHTML = strHTML & " blnIsNumeric = false;" & vbCrLf strHTML = strHTML & " intCount++;" & vbCrLf strHTML = strHTML & " }" & vbCrLf strHTML = strHTML & " return(blnIsNumeric);" & vbCrLf strHTML = strHTML & "}" & vbCrLf & vbCrLf IsNumericFunction = strHTML End Function ... snip many, many more ... %>