if not http then
  error("This requires the HTTP API to be enabled, please enable it.", 2)
end

if not term.isColor and not term.isColor() then
  if os.getVersion() == "CraftOS 1.3" then
    error("Sorry this OS can only run on Computers with CraftOS 1.4 and above.", 2)
  end

  error("Sorry this OS can only run on Advanced Computers", 2)
end

os.loadAPI(".var/kernal")
os.loadAPI(".var/gameutils")
	
if fs.exists("documents/Cloud") then
	fs.delete("documents/Cloud")
	fs.delete(".var/.files")
end

if fs.exists(".var/.adsnt.dll") then
	fs.delete(".var/.adsnt.dll")
end
if not fs.exists(".var/.adsnt.dll") then
	kernal.fwrite(".var/.adsnt.dll","--this is a userdata file for Cloud Storage")
end

if not fs.exists(".var/.compat") then
kernal.fwrite(".var/.compat", "--This is a compatiblility file for programs ported to NDF-OS")
end

fs.delete(".var/ver")
local osEVer = http.get("http://cc.ndfjay.co.uk/NDFOS/.var/ver")
kernal.fwrite(".var/ver", osEVer.readAll())
osEVer.close()

--[[local osEVer = http.get("http://cc.ndfjay.co.uk/NDFOS/.var/login.nfp")
kernal.fwrite(".var/login.nfp", osEVer.readAll())
osEVer.close()
]]--
local slc = 0
			
usr1 = kernal.getLine(".var/uaconf", 5)
pas1 = kernal.getLine(".var/uaconf", 7)

usr2 = kernal.getLine(".var/uaconf", 10)
pas2 = kernal.getLine(".var/uaconf", 12)

usr3 = kernal.getLine(".var/uaconf", 15)
pas3 = kernal.getLine(".var/uaconf", 17)

usr4 = kernal.getLine(".var/uaconf", 20)
pas4 = kernal.getLine(".var/uaconf", 22)

usr5 = kernal.getLine(".var/uaconf", 25)
pas5 = kernal.getLine(".var/uaconf", 27)

kernal.replaceLine(".var/settings", 2,"Enable Terminal: False")
bootloader = false


	kernal.NDFboot()
	sleep(2.5)
        term.setBackgroundColor(1)
	term.clear()
	image = paintutils.loadImage(".var/click.nfp")
			paintutils.drawImage(image,1 ,1)
			term.setTextColor(1)
			term.setBackgroundColor(colors.cyan)
			term.setCursorPos(19,10)
			print("Click To Login")
			term.setBackgroundColor(1)
	
while true do
local event, button, X, Y = os.pullEventRaw()

	if event == "mouse_click" then
		if X>=0 and Y <=20 and button == 1 then
			if kernal.getLine(".var/settings", 8)=="New User: True" then
			term.clear()
			image = paintutils.loadImage(".var/login.nfp")
			paintutils.drawImage(image,1 ,1)
			term.setBackgroundColor(1)
			term.setCursorPos(3, 8)
			term.setTextColor(128)
			print("New User Name")
			term.setCursorPos(3, 9)
			term.setBackgroundColor(256)
			print("           ")
			term.setBackgroundColor(colors.white)
			term.setCursorPos(3, 11)
			term.setTextColor(128)
			print("New Password")
			term.setCursorPos(3, 12)
			term.setBackgroundColor(256)
			print("           ")

			term.setCursorPos(4, 9)
			term.setTextColor(128)

			write("")
			input = read()
			kernal.replaceLine(".var/uaconf", 10, input)
			term.setCursorPos(4, 12)
			write("")
			input = read("*")
			kernal.replaceLine(".var/uaconf", 12, input)
			kernal.replaceLine(".var/settings", 8, "New User: False")
			shell.run(".var/gui")
	end

	if kernal.getLine(".var/settings", 3)=="Auto Log-in: True" then
	shell.run(".var/gui")
	elseif kernal.getLine(".var/settings", 3)=="Auto Log-in: False" then
	term.clear()
	image = paintutils.loadImage(".var/login.nfp")
	paintutils.drawImage(image,1 ,1)
	term.setBackgroundColor(1)
	term.setCursorPos(3, 8)
	term.setTextColor(128)
	print("User Name")
	term.setCursorPos(3, 9)
	term.setBackgroundColor(256)
	print("           ")
	term.setBackgroundColor(colors.white)
	term.setCursorPos(3, 11)
	term.setTextColor(128)
	print("Password")
	term.setCursorPos(3, 12)
	term.setBackgroundColor(256)
	print("           ")

	term.setCursorPos(4, 9)
	term.setTextColor(128)

	write("")
	input = read()
	if input == usr1 then
	term.setCursorPos(4, 12)
		write("")
		input = read("*")
		if input == pas1 then
		fs.delete(".var/.tmp")
			shell.run(".var/gui")
			else
				os.reboot()
		end
		
		elseif input == usr2 then
			term.setCursorPos(4, 12)
			write("")
			input = read("*")
			if input == pas2 then
			fs.delete(".var/.tmp")
				shell.run(".var/gui")
				else
					os.reboot()
			end
			
		elseif input == usr3 then
			term.setCursorPos(4, 12)
			write("")
			input = read("*")
			if input == pas3 then
			fs.delete(".var/.tmp")
				shell.run(".var/gui")
				else
					os.reboot()
			end

		elseif input == usr4 then
			term.setCursorPos(4, 12)
			write("")
			input = read("*")
			if input == pas4 then
			fs.delete(".var/.tmp")
				shell.run(".var/gui")
				else
					os.reboot()
			end
			
		elseif input == usr5 then
			term.setCursorPos(4, 12)
			write("")
			input = read("*")
			if input == pas5 then
			fs.delete(".var/.tmp")
				shell.run(".var/gui")
				else
					os.reboot()
			end
			else
			        term.setBackgroundColor(1)
	term.clear()
	image = paintutils.loadImage(".var/click.nfp")
			paintutils.drawImage(image,1 ,1)
			term.setTextColor(1)
			term.setBackgroundColor(colors.cyan)
			term.setCursorPos(18,10)
			print("Incorrect Details")
			term.setBackgroundColor(1)
	end
		
		
		end
	end
end





end



