Const dfBritishEnglish = 0
Const dfUSEnglish = 1

  dim SysDateFormat,differ,SysDayFormat,SysMonthFormat,SysYearFormat,SysDelimiter
  dim mon 
  dim SecondDate 
	
 
 Function FormatDBDateNY(Byval DateToFormat)
	Dim tempDate, tempdel
	tempDate = FormatDBDate(DateToFormat)
	if tempDate <> "" then
		if instr(1,tempDate,"-")>0 then
			tempdel = "-" 
		else
		    if instr(1,tempDate,"/")>0 then tempdel = "/" 
		end if
		Pos = instr(1,tempDate,tempdel)
		FPLace = mid(tempDate,1,Pos-1)
		Pos1 = instr(Pos,tempDate,tempdel)
		SPLace = mid(tempDate,Pos,Pos1)
		tempDate = FPLace & SPLace
	end if	
	FormatDBDateNY = tempDate
end function
	
 	
 Function FormatDBDate(Byval DateToFormat)
	Dim Day1
	If trim(DateToFormat) = "" then
		FormatDBDate = ""
		exit function
	end if
	
	If Not ISNull(DateToFormat) then 
		Day1 = Day(DateToFormat)
		Month1=Month(DateToFormat)
		Year1=Year(DateToFormat)
		
		'enter the code for differing b/w yy and yyyy

		if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=0 then 
          'alert("0000")
		  if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
		  if Delimiter=0 then
		  FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
		  else
		  FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
          end if 
		end if
        if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=0 then 
			'alert("1000")
			if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
			if SysDelimiter=0 then
		        FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
		    else
		        FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
            end if
	    
        end if
        if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=0 then 
            'alert("0110")
            if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
			if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		      else
			  Day1 = Day(DateToFormat) 
		    End if
		    if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		      else
			  Month1 = Month(DateToFormat) 
		    End if
            if SysDelimiter=0 then
		         FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
		    else
		         FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
            end if
	     end if 
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=0 then 
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if
		        if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
                if SysDelimiter=0 then
		           FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
		        else
		           FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
                end if
	    
         end if
         if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=0 then          
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	             end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
		             FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
		        else
		             FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
                end if
	 end if
         if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=0 then
                'alert("1010")
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	             end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
		           FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
		        else
		           FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
                end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=0 then          
               'alert("0100")
				if SysYearFormat=0 then
	               Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=0 then          
               'alert("1100")
				if SysYearFormat=0 then
	                 Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
        if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=1 then 
            'alert("0001")
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if SysDelimiter=0 then
				FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
			else
				FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
			end if
	
        end if
        if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=1 then 
           ' alert("1001") 
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if SysDelimiter=0 then
				FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
			else
				FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
			end if
	
        end if
        if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=1 then 
         'alert("0111")
		 'alert("the Year format is:" & SysYearFormat)
         'alert("the Year is:" & Year1)
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		      else
			  Day1 = Day(DateToFormat) 
		    End if
		    if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		      else
			  Month1 = Month(DateToFormat) 
		    End if
            if SysDelimiter=0 then
				FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
			else
				FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
			end if
	        'alert(FormatDBDate)
			'alert("the Year is:" & Year1)
         end if 
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=1 then 
                'alert("1111")
				if SysYearFormat=1 then
		          Year1=Year1
		        end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if
		        if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
                if SysDelimiter=0 then
					FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=1 then          
                'alert("0011")
				if SysYearFormat=1 then
		           Year1=Year1
		        end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
					FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	            
         end if
         if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=1 then
                'alert("1011")
				if SysYearFormat=1 then
		             Year1=Year1
		        end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
					FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=1 then          
               'alert("0101")
				if SysYearFormat=1 then
		              Year1=Year1
		        end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDBDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDBDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=1 then          
               'alert("1101")
				if SysYearFormat=1 then
		            Year1=Year1
		         end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDBDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDBDate= Month1 & "-" & Day1 & "-" & Year1         
			end if
	
         end if
    else
		FormatDBDate = "" 

	End if 
	
	
	'if Not IsNull(DateToFormat) then 
	'	Day1 = Day(DateToFormat)
	''	if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
	''		Day1 = "0" & Day(DateToFormat)
	''	else
	''		Day1 = Day(DateToFormat) 
	''	End if
	
	'	if SysDateFormat = 0 then 
	'	    'FormatDBDate =  CDate(Day1 & "/" & Month(DateToFormat) & "/" & Year(DateToFormat)) 
 		     'FormatDBDate =  Formatday(Day1) & "/" & Formatmonth(Month(DateToFormat)) & "/" & Formatyear(Year(DateToFormat)) 
 	'	Else
     '       FormatDBDate =  formatmonth(Month(DateToFormat)) & "/" & formatday(Day1) & "/" &  formatyear(Year(DateToFormat))
	'	End IF 
	'else
	'	FormatDBDate = "" 
	'End if 
End Function


 function GetAge(startdate,AgeDisplayField)
	if startdate = "" then 
		GetAge = ""
		exit function
	end if
	Dim smonth,sday,syear,i,j
	dim ageyear,temp, rr,rr1,temp1
	dim monthi(12)
	monthi(1) = 31
	rr = round(Year(date) / 4)
	rr =  rr * 4
	if rr = year(startdate) then 
	   monthi(2) = 29
	else
	   monthi(2) = 28
	end if
	monthi(3) = 31
	monthi(4) = 30
	monthi(5) = 31
	monthi(6) = 30
	monthi(7) = 31
	monthi(8) = 31
	monthi(9) = 30
	monthi(10) = 31
	monthi(11) = 30
	monthi(12) = 31
	smonth=Month(startdate)
	sday=Day(startdate)
	syear=year(startdate)
	ageyear = Year(date) - syear
	if smonth = month(date) then 
	'months are equal then calculate only days
	'then if days are equal then 
	  If sday = day(date) then 
	     GetAge = ageyear & "Years "
	  End If
	  If sday > day(date) then 
	     temp = sday - day(date)
 		 temp = 31 - temp
		 ageyear = ageyear - 1
		 GetAge = ageyear & " Years 11 Months " & temp & " Days"
	  End if
	  If sday < day(date) then 
		'ok now days is greater then bdate is gone 
		temp = day(date) - sday
		GetAge = ageyear &  "Years " & temp & " Days"
	  End if	
	End if	
	'now check if smonth is less then todays month
		if smonth < month(date) then 
			'in this case birthday is gone , so calculate
			'only months gone and days gone
		temp = 0
		rr = month(date) 
		rr = rr - 1
		for i = smonth to rr
		temp = temp + monthi(smonth) - sday
		sday = 0
		next 
		temp = temp  + day(date) - 1
		GetAge = ageyear & " Years " & temp & " days"
		end if
		'if smonth is greater then today
	if smonth > month(date) then 
	'in this case birthday has to come 
	'so calculate the days left to birthday
	temp = 0
	rr = smonth
	rr = rr - 1
	rr1 = day(date)
	for i = month(date) to rr
	temp = temp + ( monthi(i) - rr1)
	rr1 = 0
	next 
	temp = temp  + sday
	ageyear = ageyear - 1
	temp1 = 0
	rr1 = month(date)
	rr1 = rr1 - 1
	for j = 1 to rr1
	temp1 = temp1 + monthi(j)
'	msgbox temp1 & "  " & monthi(j)
	next 
	temp =  temp + temp1 + day(date)
	GetAge = ageyear & " Years " & temp & " days"
	end if
    AgeDisplayField.value = GetAge
end function  
     
Function document_onreadystatechange()
  Dim datebit
  Dim obj
  If document.readyState = "complete" Then
     On Error Resume Next
	 SysDateFormat=document.all("sysdateformatbit").value 
  End If 
  SysDayFormat   =	Mid(SysDateFormat,2,1)
  SysMonthFormat =	Mid(SysDateFormat,3,1)
  SysYearFormat  =	Mid(SysDateFormat,4,1)
  SysDelimiter	 =	Mid(SysDateFormat,5,1)
  SysDateFormat  =	Mid(SysDateFormat,1,1)
  If document.readyState = "complete" Then
	On Error Resume Next
	attachEventForDateControl()
  End if 
End Function

Function getCurrentDate()
	getCurrentDate = CnvLngDate(Date)
End Function
   
Function CheckDate()
	Dim thevalue
	thevalue = value
	if trim(thevalue) = "" Then Exit Function
	'if (bitYear1=0 and bitYear1<> "") Then thevalue=value & "/" & Year(Date)
	if NOT IsValidDate(thevalue) Then
		alert("Please enter a valid Date")
		value =""
	End if
End Function


Function CheckDate_Blur()
	Dim thevalue
	thevalue = window.event.srcElement.value
	if trim(thevalue) = "" Then Exit Function
	if NOT IsValidDate(thevalue) Then
		alert("Please enter a valid Date")
		window.event.srcElement.value =""
	End if
End Function

Function IsPositiveDate(byval sdate,byval edate)
dim startdate,enddate
startdate=sdate
enddate=edate
'alert(startdate)
'alert(enddate)
  if instr(startDate,"/")>0 then start=split(startDate,"/")
  if instr(startDate,".")>0 then start=split(startDate,".")
  if instr(startDate,"-")>0 then start=split(startDate,"-")
  if instr(startDate," ")>0 then start=split(startDate," ")
  if instr(endDate,"/")>0 then end1=split(endDate,"/")
  if instr(endDate,".")>0 then end1=split(endDate,".")
  if instr(endDate,"-")>0 then end1=split(endDate,"-")
  if instr(endDate," ")>0 then end1=split(endDate,"-")
   'msgbox "The splitted date is:"&start(0)&" "&start(1)&" "&start(2)
   'msgbox "The splitted date is:"&end1(0)&" "& end1(1)&" "& end1(2)
   'alert(SysDateFormat)
 if SysDateFormat=0 then
      days=cint(start(0))-cint(end1(0))
	  months=cint(start(1))-cint(end1(1))
	  years=cint(start(2))-cint(end1(2))
	  'alert(days)
	  'alert(months)
	  'alert(years)
	  if days > 0 and months > 0 and years > 0 then
	  		 'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
	  elseif days < 0 and months < 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days <= 0 and months >= 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      
	  elseif days > 0 and months < 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days = 0 and months = 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days > 0 and months > 0 and years = 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days > 0 and months = 0 and years = 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
     
      else 
             'alert("this means that end date is greater")
			 IsPositiveDate=false
			 exit function
      end if

 end if
 if SysDateFormat=1 then
      months=cint(start(0))-cint(end1(0))
	  days=cint(start(1))-cint(end1(1))
	  years=cint(start(2))-cint(end1(2))
      	  if days > 0 and months > 0 and years > 0 then
	  		 'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
	  elseif days < 0 and months < 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days > 0 and months < 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days <= 0 and months >= 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 

	  elseif days = 0 and months = 0 and years > 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days > 0 and months > 0 and years = 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      elseif days > 0 and months = 0 and years = 0 then
	         'alert("this means that start date is greater")
			 IsPositiveDate=true 'this means that start date is greater
             exit function 
      else 
             'alert("this means that end date is greater")
			 IsPositiveDate=false
			 exit function
      end if
 end if
End Function


Function FormatDate(byval DateToFormat)
	Dim Day1
		
	DateToFormat = ConvertDate(DateToFormat)
	If trim(DateToFormat) = "" then
		FormatDate = ""
		exit function
	end if
	
	If Not ISNull(DateToFormat) then 
		Day1 = Day(DateToFormat)
		Month1=Month(DateToFormat)
		Year1=Year(DateToFormat)
	
		'enter the code for differing b/w yy and yyyy

		if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=0 then 
          'alert("0000")
		  if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
		  if Delimiter=0 then
		  FormatDate = Day1 & "/" & Month1 & "/" & Year1         
		  else
		  FormatDate= Day1 & "-" & Month1 & "-" & Year1         
          end if 
		end if
        if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=0 then 
			'alert("1000")
			if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
			if SysDelimiter=0 then
		        FormatDate = Month1 & "/" & Day1 & "/" & Year1         
		    else
		        FormatDate= Month1 & "-" & Day1 & "-" & Year1         
            end if
	    
        end if
        if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=0 then 
            'alert("0110")
            if SysYearFormat=0 then
	           Year1= mid(year1,3,2) 
	        end if
			if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		      else
			  Day1 = Day(DateToFormat) 
		    End if
		    if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		      else
			  Month1 = Month(DateToFormat) 
		    End if
            if SysDelimiter=0 then
		         FormatDate = Day1 & "/" & Month1 & "/" & Year1         
		    else
		         FormatDate= Day1 & "-" & Month1 & "-" & Year1         
            end if
	     end if 
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=0 then 
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if
		        if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
                if SysDelimiter=0 then
		           FormatDate = Month1 & "/" & Day1 & "/" & Year1         
		        else
		           FormatDate= Month1 & "-" & Day1 & "-" & Year1         
                end if
	    
         end if
         if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=0 then          
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	             end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
		             FormatDate = Day1 & "/" & Month1 & "/" & Year1         
		        else
		             FormatDate= Day1 & "-" & Month1 & "-" & Year1         
                end if
	 end if
         if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=0 then
                'alert("1010")
				if SysYearFormat=0 then
	              Year1= mid(year1,3,2) 
	             end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
		           FormatDate = Month1 & "/" & Day1 & "/" & Year1         
		        else
		           FormatDate= Month1 & "-" & Day1 & "-" & Year1         
                end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=0 then          
               'alert("0100")
				if SysYearFormat=0 then
	               Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=0 then          
               'alert("1100")
				if SysYearFormat=0 then
	                 Year1= mid(year1,3,2) 
	            end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
        if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=1 then 
            'alert("0001")
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if SysDelimiter=0 then
				FormatDate = Day1 & "/" & Month1 & "/" & Year1         
			else
				FormatDate= Day1 & "-" & Month1 & "-" & Year1         
			end if
	
        end if
        if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=0 and SysYearFormat=1 then 
           ' alert("1001") 
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if SysDelimiter=0 then
				FormatDate = Month1 & "/" & Day1 & "/" & Year1         
			else
				FormatDate= Month1 & "-" & Day1 & "-" & Year1         
			end if
	
        end if
        if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=1 then 
         'alert("0111")
		 'alert("the Year format is:" & SysYearFormat)
         'alert("the Year is:" & Year1)
			if SysYearFormat=1 then
		      Year1=Year1
		    end if
			if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		      else
			  Day1 = Day(DateToFormat) 
		    End if
		    if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		      else
			  Month1 = Month(DateToFormat) 
		    End if
            if SysDelimiter=0 then
				FormatDate = Day1 & "/" & Month1 & "/" & Year1         
			else
				FormatDate= Day1 & "-" & Month1 & "-" & Year1         
			end if
	        'alert(FormatDate)
			'alert("the Year is:" & Year1)
         end if 
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=1 and SysYearFormat=1 then 
                'alert("1111")
				if SysYearFormat=1 then
		          Year1=Year1
		        end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if
		        if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
                if SysDelimiter=0 then
					FormatDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=1 then          
                'alert("0011")
				if SysYearFormat=1 then
		           Year1=Year1
		        end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
					FormatDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	            
         end if
         if SysDateFormat = 1 and SysDayFormat=0 and SysMonthFormat=1 and SysYearFormat=1 then
                'alert("1011")
				if SysYearFormat=1 then
		             Year1=Year1
		        end if
				if Clng(Month1) > 0 and Clng(Month1) < 10 Then 
			       Month1 = "0" & Month(DateToFormat)
		        else
			       Month1 = Month(DateToFormat) 
		        End if
		        if SysDelimiter=0 then
					FormatDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDate= Month1 & "-" & Day1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 0 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=1 then          
               'alert("0101")
				if SysYearFormat=1 then
		              Year1=Year1
		        end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDate = Day1 & "/" & Month1 & "/" & Year1         
				else
					FormatDate= Day1 & "-" & Month1 & "-" & Year1         
				end if
	
         end if
         if SysDateFormat = 1 and SysDayFormat=1 and SysMonthFormat=0 and SysYearFormat=1 then          
               'alert("1101")
				if SysYearFormat=1 then
		            Year1=Year1
		         end if
				if Clng(Day1) > 0 and Clng(Day1) < 10 Then 
			       Day1 = "0" & Day(DateToFormat)
		        else
			      Day1 = Day(DateToFormat) 
		        End if  
		        if SysDelimiter=0 then
					FormatDate = Month1 & "/" & Day1 & "/" & Year1         
				else
					FormatDate= Month1 & "-" & Day1 & "-" & Year1         
			end if
	
         end if
    else
		FormatDate = "" 

	End if 
End Function

Function CheckDate(byval DateV)
	if datediff("d",ConvertDate(DateV), CnvLngDate(Date))<0 then
		CheckDate = false
	else
		CheckDate = true		
	end if
End Function

Function DateDifference2(byval FirstDate , byval SecondDate)
	Dim MinutesDiff 
	if IsNull(SecondDate) then SecondDate = Now()
	MinutesDiff = DateDifference & DateDiff("n",FirstDate,SecondDate) 
	Days = Int(Clng(MinutesDiff)/1440)
	DateDifference = Days & " Days " 
	MinutesDiff = MinutesDiff - (Days * 1440)
	Hours = Int(Clng(MinutesDiff)/60)
	DateDifference = DateDifference & Hours & " Hours " 
	MinutesDiff = MinutesDiff - (Hours * 60)
	DateDifference = DateDifference & MinutesDiff & " Minutes "
End Function 


Function FormDate(Byval FDate,Byval FFormat)
On Error Resume Next
if IsNull(FDate) Then
	FormDate = ""
	Exit Function
else
	if Trim(FDate) <> "" Then
		FormDate = FormatDate(FDate)
		Exit Function
	end if
End if 
End Function


Function IsValidDate(ByRef DatetoEval)
    Dim Delimiter, DateP ,i
	            
    If InStr(1, DatetoEval,"/",vbTextCompare) > 0 Then
        Delimiter = "/"
    ElseIf InStr(1, DatetoEval,"-",vbTextCompare) > 0 Then
        Delimiter = "-"
    Else
		IsValidDate = False
		Exit Function
	End If

    DateP = Split(DatetoEval, Delimiter)
    
    If UBound(DateP) <> 2 Then
        ErrMessage = " Invalid Date "
        IsValidDate = False
        Exit Function
    End If
    
    IsvalidDate= Isdate(convertdate(DatetoEval))
End Function

Function IsValidMonth(ByVal MonthToEval)
	Dim Months(12) , i
	Months(0) = "Jan"
	Months(1) = "Feb"
	Months(2) = "Mar"
	Months(3) = "Apr"
	Months(4) = "May"
	Months(5) = "Jun"
	Months(6) = "Jul"
	Months(7) = "Aug"
	Months(8) = "Sep"
	Months(9) = "Oct"
	Months(10) = "Nov"
	Months(11) = "Dec"

	For i = 0 To UBound(Months)
	    If StrComp(Months(i), MonthToEval, vbTextCompare) = 0 Then
	        IsValidMonth = True
	        Exit Function
	    End If
	Next
	IsValidMonth = False
End Function

Function DateDifference(byval interval,byval FirstDate , byval SecondDate)
	' NOT IS USE
	FirstDate = ConvertDate(FirstDate)
	SecondDate = ConvertDate(SecondDate)
	DateDifference = DateDiff(interval,FirstDate,SecondDate)	
End Function

Function CnvLngDate(Byval DatetoEval)
 if trim(DatetoEval)="" then
  CnvLngDate = ""
  exit function
 end if
  
 if not isDate(DatetoEval) then
	CnvLngDate = ""
	exit function
 else
    tempDay = datepart("d",trim(DatetoEval))
    tempmon = datepart("m",trim(DatetoEval))
    tempyear = datepart("yyyy",trim(DatetoEval))
    if tempDay>0 and tempmon>0 and tempyear>0 then
		tempDate = tempDay & "-" & MonthName(tempmon) & "-" & tempyear
		CnvLngDate = tempDate
	else
	 	CnvLngDate = ""
		exit function
	end if	
 end if 
 
End Function

function GetCurrDate()
	GetCurrDate = Date()
end function

Function getSysDay(dd)
   if SysDayFormat=0 then 
       getSysDay=cint(dd)
   end if
   if SysDayFormat=1 then 
       if cint(dd) < 10 then
	      getSysDay=0 & dd 
       else
          getSysDay=dd
        end if
   end if
end Function

Function getSysMonth(mm)
  if SysMonthFormat=0 then 
       getSysMonth=cint(mm)
   end if
   if SysMonthFormat=1 then 
       if cint(mm) < 10 then
	      getSysMonth=0 & mm 
       else
          getSysMonth=mm
        end if
   end if
end Function

Function getSysYear(yy)
    if SysYearFormat=0 then 
       yy=mid(yy,3,2)
	   getSysYear=yy
    end if
    if SysYearFormat=1 then 
       getSysYear=cint(yy)
    end if
end Function

function AddToDate(Byval interval,byval numtoadd,byval txtfield)
  dim monthi(12)
  Dim numtotal
  dim datesplit, dayvalue
  if instr(txtfield,"/")>0 then datesplit=split(txtfield,"/")
  if instr(txtfield,".")>0 then datesplit=split(txtfield,".")
  if instr(txtfield,"-")>0 then datesplit=split(txtfield,"-")
  If UBound(Datesplit) < 2 Then
  		AddToDate= "" 
        Exit Function
  End If
	datesplit =  dateadd(interval,numtoadd,ConvertDate(txtField))
	mmonth = Month(datesplit)
	dayvalue = Day(datesplit)
	yyear = Year(dateSplit)
	if SysDateFormat=0 and SysDelimiter= 0 then
		 AddToDate = getSysDay(dayvalue) & "/" & getSysMonth(mmonth) & "/" & getSysYear(yyear) 
	end if
    if SysDateFormat=1 and SysDelimiter= 0 then
		 AddToDate = getSysMonth(mmonth) & "/" & getSysDay(dayvalue)  & "/" & getSysYear(yyear) 
	end if
    if SysDateFormat=0 and SysDelimiter= 1 then
		 AddToDate = getSysDay(dayvalue) & "-" & getSysMonth(mmonth) & "-" & getSysYear(yyear) 
	end if
    if SysDateFormat=1 and SysDelimiter= 1 then
		 AddToDate = getSysMonth(mmonth) & "-" & getSysDay(dayvalue)  & "-" & getSysYear(yyear) 
	end if
End function


Function ConvertDate(Byval DatetoEval)

	 Dim Delimiter, DateP ,i
     If InStr(1, DatetoEval,"/",vbTextCompare) > 0 Then
         Delimiter = "/"
     ElseIf InStr(1, DatetoEval,"-",vbTextCompare) > 0 Then
         Delimiter = "-"
		 else
				 Convertdate= ""
				 exit function
		 End If
	 
		 DateP = Split(DatetoEval,Delimiter)
		 
     if Ubound(Datep) <> 2 Then
	     Convertdate= ""
		   exit function
		 end if
		 If SysDateFormat = 0 Then
		 	 dd = DateP(0)
			 mm = DateP(1)
		 Elseif SysDateFormat = 1 Then
			 mm = DateP(0)
			 dd = DateP(1)
		 End If
		 
			yy = DateP(2)
		
			  if IsNumeric(mm) and Isnumeric(dd) then		   
					
					if len(trim(yy))=2 then
					  if cint(yy) > 30 and cint(yy) < 100 then 
							yy= 19 & yy
						elseif cint(yy) < 30 and cint(yy) >= 0  then
							yy=20 & yy
						end if	
					elseif len(trim(yy))=4 then
						' do nothing
					else
							Convertdate= ""
							exit function
				  end if 
			 		 ConvertDate = Trim(dd) + Trim(Delimiter) + Trim(MonthName(mm)) + Trim(Delimiter) + Trim(yy)
				else
						ConvertDate = datetoeval
				end if
End Function

Function MonthName(Byval MonthToEval)
	Dim Months(12)
	Months(0) = "Jan"
	Months(1) = "Feb"
	Months(2) = "Mar"
	Months(3) = "Apr"
	Months(4) = "May"
	Months(5) = "Jun"
	Months(6) = "Jul"
	Months(7) = "Aug"
	Months(8) = "Sep"
	Months(9) = "Oct"
	Months(10) = "Nov"
	Months(11) = "Dec"

	if IsNumeric(MonthToEval) Then 
		if MonthToEval > 0 And MonthToEval <=12 Then
			MonthName = Months(MonthToEval - 1)
		else
			MonthName = 0
		end if 
	else
		MonthName = MonthToEval
	end if
End Function

Function FormatDay(Byval Fday)
	Dim Nday
	Nday = Fday
	if len(Fday) = 2 Then 
		NDay = Fday
	else
		if SysDayFormat Then NDay = "0" & trim(Fday)
	end if
	FormatDay = Nday
End Function

Function Formatmonth(Byval Fmonth)
	Dim Nmonth
	Nmonth = Fmonth
	if len(Fmonth) = 2 Then 
		Nmonth = Fmonth
	else
		if SysmonthFormat Then Nmonth = "0" & trim(Fmonth)
	end if
	FormatMonth = NMonth
End Function

Function Formatyear(Byval FYear)
	Dim NYear
	NYear = FYear
	if len(Fyear) = 2 Then
		'if SysYearFormat Then NYear = "0" & Trim(FYear)
	else
		if Not SysYearFormat Then NYear = Mid(Trim(FYear),3,2)
	end if
	FormatYear = NYear
End Function


Function FormatTime(TimeVal)
 Dim TimeArr, Hr, Min, TimeAmPm
 
 if TimeVal<>"" then
  TimeArr = split(trim(TimeVal),":")
  if ubound(TimeArr)<=0 then
   FormatTime = ""
   exit function
  end if
      
   TimeAmPm = ucase(right(trim(TimeVal),2))
   
   if TimeAmPm<>"PM" and TimeAmPm<>"AM" then
     FormatTime = ""
    exit function
   end if
	
	Hr = trim(TimeArr(0))
	
	if Hr = "" then
		FormatTime = ""
		exit function
	end if
	
	if Not isNumeric(Hr) then
		FormatTime = ""
		exit function
	end if
	
	if clng(Hr)<0 or clng(Hr)>12 then
		FormatTime = ""
		exit function
	end if
	
	Min = trim(left(trim(TimeArr(1)),len(trim(TimeArr(1)))-2))
	
	if Min = "" then
		FormatTime = ""
		exit function
	end if
	
	if Not isNumeric(Min) then
		 FormatTime = ""
		 exit function
	end if
  
	
	if clng(Min)<0 or clng(Min)>59 then
		FormatTime = ""
		exit function
	end if
	
	if Hr=0 then
		Hr=12
	end if
		
	if len(Hr)=1 then
	 Hr = "0" & Hr
	end if
	
	if len(Min)=1 then
	 Min = "0" & Min
	end if
	
    FormatTime = Hr & ":" & Min & lcase(TimeAmPm)
 else
	FormatTime = ""
 end if
End Function


Function GetCurrentTime()
	sysTime = Time
	SysMin = Minute(systime)
	if SysMin<10 then
	 SysMin = "0" & cstr(SysMin)
	end if
	
	if hour(systime) < 12 then
	 SysHour = hour(systime)
	 if SysHour=0 then
	  SysHour = 12
	 end if
	 if SysHour<10 then
	  SysHour = "0" & cstr(SysHour)
	 end if
	 GetCurrentTime = SysHour & ":" & SysMin & "am"
	else
	 if hour(systime)=12 then
		SysHour = hour(systime)
	 else	
		SysHour = hour(systime)-12
	 end if	
	 if SysHour<10 then
	  SysHour = "0" & cstr(SysHour)
	 end if
	 GetCurrentTime = SysHour & ":" & SysMin & "pm"
	end if
End Function 



Function CalculateNoofWeeks(StartDate,EndDate)
		if WeekDay(ConvertDate(StartDate)) = vbMonday Then 
			'Do Nothing
			TempStartDate = ConvertDate(StartDate)
		elseif WeekDay(ConvertDate(StartDate)) < vbMonday Then 
			TempStartDate = AddtoDate("d",vbMonday-Weekday(ConvertDate(StartDate)),ConvertDate(StartDate))
		else
			TempStartDate = AddtoDate("d",vbSaturday-Weekday(ConvertDate(StartDate))+vbMonday,ConvertDate(StartDate))
		End if 
		
		TempEndDate =  AddtoDate("d",vbSunday - Weekday(ConvertDate(EndDate)),ConvertDate(EndDate))
		TempTotalWeeks = Datediff("ww",ConvertDate(TempStartDate),ConvertDate(TempEndDate))
		
		StartWeekDay = WeekDay(ConvertDate(StartDate))
		EndWeekDay = WeekDay(ConvertDate(EndDate))
		
		if StartWeekDay = vbMonday and EndWeekDay = vbSunday Then 
			TempTotalWeeks = TempTotalWeeks
		End if 
		if (StartWeekDay = vbTuesday or StartWeekDay = vbWednesday or StartWeekDay = vbThursday) and EndWeekDay = vbSunday Then 
			TempTotalWeeks = TempTotalWeeks + 1
		End if 
		if ( StartWeekDay = vbFriday or StartWeekDay = vbSaturday or StartWeekDay = vbSunday)and EndWeekDay = vbSunday Then 
			TempTotalWeeks = TempTotalWeeks
		End if 
		if StartWeekDay = vbMonday and EndWeekDay <> vbSunday Then 
			TempTotalWeeks = TempTotalWeeks + 1
		End if 
		if (StartWeekDay = vbTuesday or StartWeekDay = vbWednesday or StartWeekDay = vbThursday)and EndWeekDay <> vbSunday Then 
			TempTotalWeeks = TempTotalWeeks + 2
		End if 
		if (StartWeekDay = vbFriday or StartWeekDay = vbSaturday or StartWeekDay = vbSunday)and EndWeekDay <> vbSunday Then 
			TempTotalWeeks = TempTotalWeeks + 1
		End if 
		
		CalculateNoofWeeks = TempTotalWeeks
End Function

Function FindDayOfWeek
	window.event.srcElement.title=""
	TempDate = convertDate(window.event.srcElement.value)
	If TempDate<> "" Then 
		Dow = WeekDay(TempDate)
		Select Case Dow
			Case vbMonday 
				window.event.srcElement.title="Day of week is Monday"
			Case vbTuesday
				window.event.srcElement.title="Day of week is Tuesday"
			Case vbWednesday
				window.event.srcElement.title="Day of week is Wednesday"
			Case vbThursday
				window.event.srcElement.title="Day of week is Thursday"
			Case vbFriday
				window.event.srcElement.title="Day of week is Friday"
			Case vbSaturday
				window.event.srcElement.title="Day of week is Saturday"
			Case vbSunday
				window.event.srcElement.title="Day of week is Sunday"
		End Select 
	End if 
End Function