<%
Sub UserLogged(i_UserID)
	if Session("Logged") = empty then
		Session("Logged") = ""
		response.redirect("default.asp?cache="&Now())
	end if
end Sub

function repQ(sTring)
	repQ = replace(sTring,"'","''")
end function

Sub AddAction(s_Category, s_SubCategory, s_ADescription, s_Detail)

	if Session("Logged") = Empty or Not IsNumeric(Session("Logged")) then Response.Redirect("default.asp")
	
	strSQLTmp = "SELECT Category, Subcategory, DateTime, UserID, Name, Short, Detail FROM ActionLog"
	set rsAddAction = server.createobject("ADODB.RecordSet")
	rsAddAction.open strSQLTmp, Application("CString"), 1, 3
	
	rsAddAction.AddNew
	
	rsAddAction("Category") = s_Category
	rsAddAction("Subcategory") = s_SubCategory
	rsAddAction("DateTime") = Now
	rsAddAction("UserID") = Session("Logged")
	
	set tmp_con = server.createobject("ADODB.Connection")
	tmp_con.open Application("CString")
	
	strSQLTmp = "SELECT RealName FROM Users WHERE UserID = " & Session("Logged")
	set rsName = tmp_con.execute(strSQLTmp)
	if not rsName.EOF then
		rsAddAction("Name") = rsName(0)
	else
		rsAddAction("Name") = "NoNameFound"	
	end if
	
	rsName.close
	set rsName = Nothing
	tmp_con.Close
	set tmp_con = Nothing
	
	rsAddAction("Short") = s_ADescription
	rsAddAction("Detail") = s_Detail
	
	rsAddAction.Update
	rsAddAction.Close
	set rsAddAction = Nothing
End Sub

Sub Timeout(theDir)

	if Session("Logged") = empty then
	
		thePath = ""
		
		if CInt(theDir) > 0 then
			For i = 1 to CInt(theDir)
				thePath = thePath & "../"
			Next
		end if%>
<script language="JavaScript">
window.open("<%=thePath%>default.asp?buster=<%=server.URLEncode(now)%>", "_top");
</script>
<%
		response.end
	end if	
	
End Sub

Sub AdminOnly(theDir)

	if CInt(Session("SecurityLevel")) <> 1 then
	
		thePath = ""
		
		if CInt(theDir) > 0 then
			For i = 1 to CInt(theDir)
				thePath = thePath & "../"
			Next
		end if%>
<script language="JavaScript">
window.open("<%=thePath%>default.asp?buster=<%=server.URLEncode(now)%>", "_top");
</script>
<%
		response.end
	end if

End Sub

'-----------------------------------------------
' formats the date to 12-May-01
'-----------------------------------------------
function formatDate(dateTheDate)
	varDay = Day(dateTheDate)
	varMonth = Left(MonthName(Month(dateTheDate)), 3)
	varYear = Mid(Year(dateTheDate), 3, 2)
	formatDate = varDay&"-"&varMonth&"-"&varYear
end function

'-----------------------------------------------
' formats the date to 12-May-2001
'-----------------------------------------------
function formatDate2(dateTheDate)
	varDay = Day(dateTheDate)
	varMonth = MonthName(Month(dateTheDate))
	varYear = Year(dateTheDate)
	formatDate2 = varDay&"-"&varMonth&"-"&varYear
end function

'-----------------------------------------------
' formats the date to 12-Nov-2001
'-----------------------------------------------
function formatDate3(dateTheDate)
	varDay = Day(dateTheDate)
	varMonth = Left(MonthName(Month(dateTheDate)), 3)
	varYear = Right(Year(dateTheDate), 2)
	formatDate3 = varDay&"-"&varMonth&"-"&varYear
end function

Sub SaveImageForNewGallery(strImagePath, strNewPath, intMaxWidth, intMaxHeight)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	
	intWidthRatio = CInt(intMaxWidth) / jpeg.OriginalWidth
	intHeightRatio = CInt(intMaxHeight) / jpeg.OriginalHeight
	
	if intHeightRatio < intWidthRatio then
	
		if CDbl(intHeightRatio) < 1 then
		
			jpeg.Height = CInt(intMaxHeight)
			jpeg.Width = CInt(jpeg.OriginalWidth * intHeightRatio)
			jpeg.Save strNewPath
			
		else
			jpeg.Save strNewPath
		end if
		
	else
	
		if CDbl(intWidthRatio) < 1 then
		
			jpeg.Width = CInt(intMaxWidth)
			jpeg.Height = CInt(jpeg.OriginalHeight * intWidthRatio)
			jpeg.Save strNewPath
			
		else
			jpeg.Save strNewPath
		end if
		
	end if
		
	set jpeg = nothing

end Sub

Sub SaveImage(strImagePath, strNewPath, strFile)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
		
	jpeg.Open(strImagePath)
	
	theBigWidthRatio = 200/jpeg.OriginalWidth
	if CDbl(theBigWidthRatio) < 1 then
		jpeg.Width = 200
		jpeg.Height = CInt(jpeg.OriginalHeight * theBigWidthRatio)
		jpeg.Save strNewPath & "/sml_" & strFile
	else
		jpeg.Save strNewPath & "/sml_" & strFile
	end if	

	set jpeg = nothing

end Sub

Sub SaveImageProject(strImagePath, strNewPath, intSize)


	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	if jpeg.OriginalHeight < 195 OR jpeg.OriginalWidth < 466 then
		%>
		<script language="JavaScript">
		window.alert("Please upload a bigger top image!");
		history.go(-1);
		</script>
		<%
		Response.End()
	end if	
	
	SetWidth = 466
	SetHeight = 195
	

	theBigHeightRatio = CInt(SetWidth)/jpeg.OriginalHeight
	theBigWidthRatio  = CInt(SetHeight)/jpeg.OriginalWidth	
	
	if CDbl(OriginalHeight) < 1 then
		jpeg.Height = CInt(SetHeight)
		jpeg.Width = CInt(jpeg.OriginalWidth * theBigHeightRatio)
		if CDbl(jpeg.Width) > SetWidth then
			strX0 = (CDbl(jpeg.Width) -SetWidth)/2
			strY0 = 0
			strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetWidth)/2)
			strY1 = jpeg.Height
			jpeg.Crop strX0, strY0, strX1, strY1
			response.write "1<br>strX0 :" & strX0 & "<br>"
			response.write "strY0 :" & strY0 & "<br>"
			response.write "strX1 :" & strX1 & "<br>"
			response.write "strY1 :" & strY1 & "<br>"									
		else
			if CDbl(jpeg.Width) > SetWidth then
				strX0 = (CDbl(jpeg.Width) -SetWidth)/2
				strY0 = 0
				strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetWidth)/2)
				strY1 = jpeg.Height
				jpeg.Crop strX0, strY0, strX1, strY1
				response.write "2<br>strX0 :" & strX0 & "<br>"
				response.write "strY0 :" & strY0 & "<br>"
				response.write "strX1 :" & strX1 & "<br>"
				response.write "strY1 :" & strY1 & "<br>"							
			end if
		end if
		jpeg.Save strNewPath
	else
		jpeg.Height = CDbl(OriginalHeight)
		jpeg.Width = CDbl(OriginalWidth)
		if CDbl(jpeg.Width) > SetWidth then
			strX0 = (CDbl(jpeg.Width) -SetWidth)/2
			strY0 = 0
			strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetWidth)/2)
			strY1 = jpeg.Height
			jpeg.Crop strX0, strY0, strX1, strY1
			response.write "3<br>strX0 :" & strX0 & "<br>"
			response.write "strY0 :" & strY0 & "<br>"
			response.write "strX1 :" & strX1 & "<br>"
			response.write "strY1 :" & strY1 & "<br>"			
		else
			if CDbl(jpeg.Width) > SetHeight then
				strX0 = (CDbl(jpeg.Width) -SetHeight)/2
				strY0 = 0
				strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetHeight)/2)
				strY1 = jpeg.Height
				jpeg.Crop strX0, strY0, strX1, strY1
				response.write "4<br>strX0 :" & strX0 & "<br>"
				response.write "strY0 :" & strY0 & "<br>"
				response.write "strX1 :" & strX1 & "<br>"
				response.write "strY1 :" & strY1 & "<br>"							
			end if
		end if	
		jpeg.Save strNewPath
	end if	

	set jpeg = nothing

'response.end
end Sub

Sub SaveImageProjectThumb(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	
	SetWidth = 100
	SetHeight = 128
	

	theBigHeightRatio = CInt(intSize)/jpeg.OriginalHeight
	
	if CDbl(OriginalHeight) < 1 then
		jpeg.Height = CInt(SetHeight)
		jpeg.Width = CInt(jpeg.OriginalWidth * theBigHeightRatio)
		if CDbl(jpeg.Width) > SetWidth then
			strX0 = (CDbl(jpeg.Width) -SetWidth)/2
			strY0 = 0
			strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetWidth)/2)
			strY1 = jpeg.Height
			jpeg.Crop strX0, strY0, strX1, strY1
			response.write "1strX0 :" & strX0 & "<br>"
			response.write "strY0 :" & strY0 & "<br>"
			response.write "strX1 :" & strX1 & "<br>"
			response.write "strY1 :" & strY1 & "<br>"									
		else
			if CDbl(jpeg.Width) > SetHeight then
				strX0 = (CDbl(jpeg.Width) -SetHeight)/2
				strY0 = 0
				strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetHeight)/2)
				strY1 = jpeg.Height
				jpeg.Crop strX0, strY0, strX1, strY1
				response.write "2strX0 :" & strX0 & "<br>"
				response.write "strY0 :" & strY0 & "<br>"
				response.write "strX1 :" & strX1 & "<br>"
				response.write "strY1 :" & strY1 & "<br>"							
			end if
		end if
		jpeg.Save strNewPath
	else
		jpeg.Height = CDbl(OriginalHeight)
		jpeg.Width = CDbl(OriginalWidth)
		if CDbl(jpeg.Width) > SetWidth then
			strX0 = (CDbl(jpeg.Width) -SetWidth)/2
			strY0 = 0
			strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetWidth)/2)
			strY1 = jpeg.Height
			jpeg.Crop strX0, strY0, strX1, strY1
			response.write "3strX0 :" & strX0 & "<br>"
			response.write "strY0 :" & strY0 & "<br>"
			response.write "strX1 :" & strX1 & "<br>"
			response.write "strY1 :" & strY1 & "<br>"			
		else
			if CDbl(jpeg.Width) > SetHeight then
				strX0 = (CDbl(jpeg.Width) -SetHeight)/2
				strY0 = 0
				strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -SetHeight)/2)
				strY1 = jpeg.Height
				jpeg.Crop strX0, strY0, strX1, strY1
				response.write "4strX0 :" & strX0 & "<br>"
				response.write "strY0 :" & strY0 & "<br>"
				response.write "strX1 :" & strX1 & "<br>"
				response.write "strY1 :" & strY1 & "<br>"							
			end if
		end if	
		jpeg.Save strNewPath
	end if	

	set jpeg = nothing

end Sub

Sub SaveImageGalleryThumb(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
		
		if jpeg.OriginalWidth > jpeg.OriginalHeight then
		
		theBigWidthRatio = CInt(intSize)/jpeg.OriginalWidth
		
			if CDbl(theBigWidthRatio) < 1 then
				jpeg.Width = CInt(intSize)
				jpeg.Height = CInt(jpeg.OriginalHeight * theBigWidthRatio)
				jpeg.Save strNewPath
			else
				jpeg.Save strNewPath
			end if		
		
		else
		
			theBigHeightRatio = CInt(intSize)/jpeg.OriginalHeight
			
			if CDbl(theBigHeightRatio) < 1 then
				jpeg.Width = CInt(jpeg.OriginalWidth * theBigHeightRatio)
				jpeg.Height = CInt(intSize)
				jpeg.Save strNewPath
			else
				jpeg.Save strNewPath
			end if		
		
		end if

	set jpeg = nothing

end Sub

Sub SaveImageNormal(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	

		theBigWidthRatio = CInt(intSize)/jpeg.OriginalWidth
		
		if CDbl(theBigWidthRatio) < 1 then
			jpeg.Width = CInt(intSize)
			jpeg.Height = CInt(jpeg.OriginalHeight * theBigWidthRatio)
			jpeg.Save strNewPath
		else
			jpeg.Save strNewPath
		end if
			

	set jpeg = nothing

end Sub

Sub SaveImages(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	

		theBigWidthRatio = CInt(intSize)/jpeg.OriginalWidth
		
		if CDbl(theBigWidthRatio) < 1 then
			jpeg.Width = CInt(intSize)
			jpeg.Height = CInt(jpeg.OriginalHeight * theBigWidthRatio)
			jpeg.Save strNewPath
		else
			jpeg.Save strNewPath
		end if
			

	set jpeg = nothing

end Sub

Sub ImageCropper(strImagePath, strNewPath, i_intSetWidth, i_intSetHeight)
'remove when done
	intSetWidth = i_intSetWidth
	intSetHeight = i_intSetHeight
	
	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	if jpeg.OriginalHeight < CInt(intSetHeight) OR jpeg.OriginalWidth < CInt(intSetWidth) then
		%>
		<script language="JavaScript">
		window.alert("Please upload a bigger image. It must be at least <%=intSetWidth%> wide and <%=intSetHeight%> heigh!");
		history.go(-1);
		</script>
		<%
		Response.End()
	end if
	
	theBigWidthRatio = CInt(intSetWidth)/jpeg.OriginalWidth
	intTestHeight = CInt(theBigWidthRatio*jpeg.OriginalHeight)
	
	theBigHeightRatio = CInt(intSetHeight)/jpeg.OriginalHeight
	intTestWidth = CInt(theBigHeightRatio*jpeg.OriginalWidth)

	if jpeg.OriginalWidth => jpeg.OriginalHeight then
		'OK so we have a landscape image 
		MyImageWidth = intTestWidth
		if intTestHeight=> intSetHeight then
			' No we can resize and then crop
			jpeg.Width = intSetWidth
			jpeg.Height = intTestHeight
			response.write "A1 : <br>intSetWidth : " & intSetWidth & "<br>intTestHeight : " & intTestHeight
			strX0 = (CDbl(jpeg.Width) - intSetWidth) /2
			strY0 = (CDbl(jpeg.Height) -intSetHeight)/2
			strX1 = (CDbl(jpeg.Width) -intSetWidth)/2 + intSetWidth
			strY1 = (CDbl(jpeg.Height) -intSetHeight)/2 + intSetHeight
			jpeg.Crop strX0, strY0, strX1, strY1			
		
		else
			' Our image Height is to small so we need to increment until we get a desired height
			ISaySo = False			
			do until ISaySo 
				if CInt(intTestHeight) => CInt(intSetHeight) then
					ISaySo = True
					jpeg.Width = MyImageWidth
					jpeg.Height = intTestHeight
					response.write "A2 : <br>intSetWidth : " & intSetWidth & "<br>intTestHeight : " & intTestHeight
					strX0 = (CDbl(jpeg.Width) - intSetWidth) /2
					strY0 = (CDbl(jpeg.Height) -intSetHeight)/2
					strX1 = (CDbl(jpeg.Width) -intSetWidth)/2 + intSetWidth
					strY1 = (CDbl(jpeg.Height) -intSetHeight)/2 + intSetHeight
					jpeg.Crop strX0, strY0, strX1, strY1
					exit do					
				else
					'lets increase the height by 1 pixels
					intTestHeight = intTestHeight + 1				
				end if
			loop
		
		end if
	
	else
	' OK so we have a portrate style image
		MyImageHeight = intTestHeight
		
		if intTestWidth => intSetWidth then
			response.write "intTestWidth1 : " & intTestWidth & "<br>"		
			' No we can resize and then crop
			jpeg.Width = intTestWidth
			jpeg.Height = intSetHeight
			response.write "B1 : <br>intSetHeight : " & intSetHeight & "<br>intTestWidth : " & intTestWidth		
			strX0 = (CDbl(jpeg.Width) - intSetWidth) /2
			strY0 = (CDbl(jpeg.Height) -intSetHeight)/2
			strX1 = (CDbl(jpeg.Width) -intSetWidth)/2 + intSetWidth
			strY1 = (CDbl(jpeg.Height) -intSetHeight)/2 + intSetHeight
			jpeg.Crop strX0, strY0, strX1, strY1
		else
			ISaySo = False
			do until ISaySo 
				if CInt(intTestWidth) => CInt(intSetWidth) then
					response.write "intTestWidth2 : " & intTestWidth & "<br>"
					response.write "intSetWidth : " & intSetWidth & "<br>"					
					ISaySo = True
					jpeg.Width = intTestWidth
					jpeg.Height = CDbl(MyImageHeight)
					response.write "B2 : <br>intSetHeight : " & intSetHeight & "<br>intTestWidth : " & intTestWidth& "<br>"				
					strX0 = (CDbl(jpeg.Width) - intSetWidth) /2
					strY0 = (CDbl(jpeg.Height) -intSetHeight)/2
					strX1 = (CDbl(jpeg.Width) -intSetWidth)/2 + intSetWidth
					strY1 = (CDbl(jpeg.Height) -intSetHeight)/2 + intSetHeight
					jpeg.Crop strX0, strY0, strX1, strY1
					exit do					
				else
					'lets increase the height by 1 pixels
					intTestWidth = intTestWidth + 1				
				end if			
			loop
		end if
	end if

	response.write "strX0 : " & strX0 & "<br>"
	response.write "strY0 : " & strY0 & "<br>"
	response.write "strX1 : " & strX1 & "<br>"
	response.write "strY1 : " & strY1 & "<br>"

	jpeg.Save strNewPath 
	set jpeg = nothing
'response.end
end Sub

Sub SaveImageContent(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	
	if jpeg.OriginalHeight < 160 OR jpeg.OriginalWidth < 631 then
		%>
		<script language="JavaScript">
		window.alert("Please upload a bigger top image!");
		history.go(-1);
		</script>
		<%
		Response.End()
	end if
	
		if jpeg.OriginalHeight < jpeg.OriginalWidth then
			
			Width = 631
			Height = jpeg.OriginalHeight * Width / jpeg.OriginalWidth
			response.write "jpeg.Width : " & Width
			response.write "jpeg.Height : " & Height
			if Height > 160 then
				jpeg.Height = Height
				jpeg.Width = Width			
				strX0 = 0 
				strY0 = (CDbl(jpeg.Height) -160)/2
				strX1 = jpeg.Width
				strY1 = CDbl(jpeg.Height) - ((CDbl(jpeg.Height) -160)/2)
				jpeg.Crop strX0, strY0, strX1, strY1			
			else
				Height  = 160
				Width = jpeg.OriginalWidth * Height / jpeg.OriginalHeight
				jpeg.Height = Height
				jpeg.Width = Width
				if Width > 631 then
					strX0 = (CDbl(jpeg.Width) -631)/2
					strY0 = 0
					strX1 = CDbl(jpeg.Width) - ((CDbl(jpeg.Width) -631)/2)
					strY1 = jpeg.Height
					jpeg.Crop strX0, strY0, strX1, strY1				
				end if

			end if
			
		else

			myHeight = 160
			myWidth = 631
			Width = jpeg.OriginalWidth * Height / jpeg.OriginalHeight
			response.write "jpeg.Width : " & jpeg.OriginalWidth
			response.write "jpeg.Height : " & jpeg.OriginalHeight			
			
			if jpeg.OriginalWidth => 631 then
				
				'jpeg.Width = Width
				'jpeg.Height = Height			
				strX0 = (CDbl(jpeg.OriginalWidth) - 631) /2
				strY0 = (CDbl(jpeg.OriginalHeight) -160)/2
				strX1 = (CDbl(jpeg.OriginalWidth) -631)/2 + 631
				strY1 = (CDbl(jpeg.OriginalHeight) -160)/2 + 160
				jpeg.Crop strX0, strY0, strX1, strY1
			else
				Width  = 631
				Height = jpeg.OriginalHeight * Width / jpeg.OriginalWidth
				'jpeg.Width = Width
				'jpeg.Height = Height
				if Height > 160 then
					strX0 = (CDbl(jpeg.Height) -160)/2
					strY0 = 0
					strX1 = CDbl(jpeg.Height) - ((CDbl(jpeg.Height) -631)/2)
					strY1 = jpeg.Width
					jpeg.Crop strX0, strY0, strX1, strY1				
				end if			
			end if
		end if

		jpeg.Save strNewPath 
		set jpeg = nothing

end Sub


Sub SaveImageBigGallery(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	

		theBigWidthRatio = CInt(intSize)/jpeg.OriginalWidth
		
		if CDbl(theBigWidthRatio) < 1 then
			jpeg.Width = CInt(intSize)
			jpeg.Height = CInt(jpeg.OriginalHeight * theBigWidthRatio)
			jpeg.Save strNewPath
		else
			jpeg.Save strNewPath
		end if
		
	session("GalImageHeight") = jpeg.Height
	session("GalImageWidth") = jpeg.Width
		
	set jpeg = nothing

end Sub

Sub SaveImageBig(strImagePath, strNewPath, intSize)

	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	
	jpeg.Width = jpeg.Width * 2
	jpeg.Height = jpeg.OriginalHeight 
	jpeg.Save strNewPath
	set jpeg = nothing

end Sub

Sub SaveImageTopBottom(strImagePath, strNewPath, strFile)
	Set jpeg = Server.CreateObject("Persits.Jpeg")
	jpeg.Open(strImagePath)
	
	if jpeg.OriginalHeight >= jpeg.OriginalWidth Then
		theBigWidthRatio = 170/jpeg.OriginalWidth
		jpeg.Width = 170
		jpeg.Height = CDbl(jpeg.OriginalHeight * theBigWidthRatio)
		jpeg.Save strNewPath & "/vs_" & strFile
	else
		theBigHeightRatio = 242/jpeg.OriginalHeight
		jpeg.Height = 242
		jpeg.Width = CDbl(jpeg.OriginalWidth * theBigHeightRatio)
		jpeg.Save strNewPath & "/vs_" & strFile
	end if
	set jpeg = nothing
end Sub

Sub DeleteFile(strPathFile)

	set oFS = Server.CreateObject("Scripting.FileSystemObject")
	
	if oFS.FileExists(strPathFile) then
		oFS.DeleteFile strPathFile
	end if
	
	set oFS = nothing
	
end Sub

function GetFileSize(strFilePath)

	set oFS = Server.CreateObject("Scripting.FileSystemObject")
	
	Set MainFile = oFS.GetFile(strFilePath)
	
	GetFileSize = MainFile.Size
	
	set MainFile = nothing
	set oFS = nothing

end function

Sub GetChildren(strMainFolder, strFolder, con)
	
	Dim strSQL
	
	Set fso = Server.Createobject("Scripting.FileSystemObject")
	Set folderSub = fso.GetFolder(server.mappath(strMainFolder &"\"& strFolder))
	set fileCollection = folderSub.Files
	
	For each varFile in fileCollection

		If LCase(Right(varFile.Name, 4)) = ".jpg" Then
			
			strSQL = "IF NOT EXISTS(SELECT '1' FROM PhotoGallery WHERE Directory_File = '"& Replace(strFolder&"\"&varFile.Name, "'", "''") &"') "& VBCRLF
			strSQL = strSQL &"BEGIN "& VBCRLF
			strSQL = strSQL &"    INSERT INTO PhotoGallery(Directory_File, Tooltip, ImageOrder, Description) "& VBCRLF
			strSQL = strSQL & "   SELECT '"& Replace(strFolder&"\"&varFile.Name, "'", "''") &"', '', COUNT(Directory_File) + 1, '' FROM PhotoGallery WHERE LOWER(RIGHT(Directory_File, 4)) = '.jpg' AND LEFT(Directory_File, "& (Len(strFolder) + 1) &") = '"& Replace(strFolder, "'", "''") &"\' AND CHARINDEX('\', Directory_File, "& (Len(strFolder) + 2) &") = 0 "& VBCRLF
			strSQL = strSQL &"END "& VBCRLF	
			
			con.execute(strSQL)
			
			t_Array = Split(strFolder & "\" & varFile.Name, "\")
			
			s_PrntDir = ""
			
			for i = 0 to UBound(t_Array)-1
				s_PrntDir = s_PrntDir & t_Array(i) & "\"
			next
			
			f_FileName = t_Array(UBound(t_Array))
			
			if not fso.FileExists(server.mappath("..\..\gallery\" & s_PrntDir & "thumbs\" & f_FileName)) then
				If Not fso.FolderExists(server.mappath("..\..\gallery\" & s_PrntDir & "thumbs")) Then Set newfolder = fso.CreateFolder(server.mappath("..\..\gallery\" & s_PrntDir & "thumbs")) 
				If Not fso.FolderExists(server.mappath("..\..\gallery\" & s_PrntDir & "big")) Then Set newfolder = fso.CreateFolder(server.mappath("..\..\gallery\" & s_PrntDir & "big")) 
				
				SaveImageNormal server.mappath("..\..\gallery\" & s_PrntDir & f_FileName), server.mappath("..\..\gallery\" & s_PrntDir & "big\" & f_FileName), 600
				SaveImageNormal server.mappath("..\..\gallery\" & s_PrntDir & f_FileName), server.mappath("..\..\gallery\" & s_PrntDir & "thumbs\" & f_FileName), 150
			end if
			
		End If
			
	Next
	
	Set subMainFolders = folderSub.SubFolders
	
	For Each folder In subMainFolders
	
		if UCase(folder.Name) <> "_NOTES" and UCase(Folder.Name) <> "THUMBS" and UCase(Folder.Name) <> "BIG" and UCase(Folder.Name) <> "_VTI_CNF" then
			
			strSQL = "IF NOT EXISTS(SELECT '1' FROM PhotoGallery WHERE Directory_File = '"& Replace(strFolder&"\"&folder.Name, "'", "''") &"')  "& VBCRLF
			strSQL = strSQL &"BEGIN "& VBCRLF
			strSQL = strSQL &"    INSERT INTO PhotoGallery(Directory_File, Tooltip, Description) VALUES('"& Replace(strFolder&"\"&folder.Name, "'", "''") &"', '', '')  "& VBCRLF
			strSQL = strSQL &"END "& VBCRLF	
			
			con.execute(strSQL)
			GetChildren strMainFolder, strFolder&"\"&folder.Name, con
		end if
		
	Next	
		
	set subMainFolders = nothing
	set fileCollection = nothing
	Set folderSub = nothing
	Set fso = nothing	

End Sub

Function DelChildren(strMainFolder, strFolder)

	Dim strSQL, strResult
	
	Set fso = Server.Createobject("Scripting.FileSystemObject")
	Set folderSub = fso.GetFolder(server.mappath(strMainFolder &"\"& strFolder))
	set fileCollection = folderSub.Files
	
	Set subMainFolders = folderSub.SubFolders
	
	strResult = ""
	
	For Each folder In subMainFolders
	
		if UCase(folder.Name) <> "_NOTES" and UCase(Folder.Name) <> "THUMBS" and UCase(Folder.Name) <> "BIG" and UCase(Folder.Name) <> "_VTI_CNF" then
			
			strResult = strResult & DelChildren(strMainFolder, strFolder&"\"&folder.Name)
			
			strResult = strResult & ", '"& strFolder&"\"&folder.Name &"'"
			
		end if
		
	Next	
	
	For each varFile in fileCollection

		If LCase(Right(varFile.Name, 4)) = ".jpg" Then
			
			strResult = strResult & ", '"& strFolder&"\"&varFile.Name &"'"
			
		End If
			
	Next
	
	set subMainFolders = nothing
	set fileCollection = nothing
	Set folderSub = nothing
	Set fso = nothing
	
	DelChildren = strResult

End Function 

Sub ExecuteGalleryCleanup

	If Session("GalleryUpdate") = "TRUE" Then

		Dim strPath, strtempSQL, strSQL
		
		strPath = "..\..\Gallery"
		
		Set con = Server.Createobject("ADODB.Connection")
		con.open Application("CString")
		
		Set fso = Server.Createobject("Scripting.FileSystemObject")
		Set folderMain = fso.GetFolder(server.mappath(strPath))
		
		Set subFolders = folderMain.SubFolders
		
		For Each folder In subFolders
		
			If UCase(folder.Name) <> "_NOTES" and UCase(Folder.Name) <> "THUMBS" and UCase(Folder.Name) <> "BIG" and UCase(Folder.Name) <> "_VTI_CNF" Then
			
				strSQL = "IF NOT EXISTS(SELECT '1' FROM PhotoGallery WHERE Directory_File = '"& Replace(folder.name, "'", "''") &"') "& VBCRLF
				strSQL = strSQL &"BEGIN "& VBCRLF
				strSQL = strSQL &"    INSERT INTO PhotoGallery(Directory_File, Description) VALUES('"& Replace(folder.name, "'", "''") &"', '') "& VBCRLF
				strSQL = strSQL &"END "& VBCRLF	
				
				con.execute(strSQL)
				GetChildren strPath, folder.name, con
				
			End If
		
		Next
		
		strtempSQL = "'NO Gallery!.asdfdsaf'"
		
		For Each folder In subFolders
		
			If UCase(folder.Name) <> "_NOTES" and UCase(Folder.Name) <> "THUMBS" and UCase(Folder.Name) <> "BIG" and UCase(Folder.Name) <> "_VTI_CNF" Then
			
				strtempSQL = strtempSQL & " , '"& Replace(folder.name, "'", "''") &"'"
				
				strtempSQL = strtempSQL & DelChildren(strPath, folder.name) 
				
			End If
		
		Next
		
		strSQL = "DELETE FROM PhotoGallery WHERE Directory_File NOT IN ("& strtempSQL &")"
		response.write strSQL
		con.execute(strSQL)
		
		Set subFolders = Nothing
		Set folderMain = Nothing
		Set fso = Nothing

		con.close
		Set con = Nothing
		
		PutGalleryOrder ""
		
		Session("GalleryUpdate") = ""
		
	End If

End Sub

Sub PutGalleryOrder(strDir)

	strSQL = "SELECT Directory_File, ImageOrder, ISNULL(ImageOrder, 10000) AS 'ImageOrder2' " & _ 
			"FROM PhotoGallery " & _ 
			"WHERE LOWER(RIGHT(Directory_File, 4)) <> '.jpg' AND " & _ 
			"LEFT(Directory_File, "& (Len(strDir)) &") = '"& Replace(strDir, "'", "''") &"' AND " & _ 
			"CHARINDEX('\', Directory_File, "& (Len(strDir) + 1) &") = 0 " & _
			"ORDER BY ImageOrder2"

	Set rsImageOrder = Server.CreateObject("ADODB.RecordSet")
	rsImageOrder.Open strSQL, Application("CString"), 1, 3
	
	i_StartOrder = 1
	
	Dim arrGallery()
	
	ReDim arrGallery(0)
	
	do while not rsImageOrder.EOF
		
		ReDim Preserve arrGallery(i_StartOrder)
	
		arrGallery(i_StartOrder - 1) 	= rsImageOrder("Directory_File")
		i_ImageOrder 					= CInt(rsImageOrder("ImageOrder2"))
	
		if i_StartOrder <> i_ImageOrder then
		
			rsImageOrder("ImageOrder") = i_StartOrder
			
			rsImageOrder.Update
			
		end if
	
		i_StartOrder = i_StartOrder + 1

		rsImageOrder.MoveNext
		
	loop
	
	rsImageOrder.Close
	set rsImageOrder = Nothing
	
	For i = 0 to UBound(arrGallery) - 1
	
		PutGalleryOrder arrGallery(i) & "\"
		
	Next		
	
End Sub

%>