;	Declaring "arrays"
pseudoarray_Programs := Object()
pseudoarray_Delay := Object()
IE_links := Object()
Chrome_links := Object()
FireFox_links := Object()

;---------------
;===PROGRAMS====
;---------------

; If you set this to false, It'll just give you message boxes with information in them, but won't run the Programs / Browsers
;	useful if you want to test it before hand
prog_run := true
web_run := true
;	should be set to true if you want it to open stuff

;	read the programs file and assign the lines to arrays
loop, read, programs.txt
{
    regexmatch(A_LoopReadLine, "(?:(?!,).)*", match)
		pseudoarray_Programs.Insert(match)
	regexmatch(A_LoopReadLine, "\b,\s+\K\S+", match)
		pseudoarray_Delay.Insert(match)
}

loop, read, settings.txt
{
	ifinstring, A_LoopReadLine, Dealer
	{
		regexmatch(A_LoopReadLine, "\b:\s+\K\S+", match)
			dlr_del := match
	}
}

if(prog_run = false)
{
	msgbox, read the files
}

;	check each element in the array(s)
for index, element in pseudoarray_Programs
{
	prog_open := element
	prog_delay:= pseudoarray_Delay[index]
	
;		assign the Chrome ones to the correct vars
	ifinstring, prog_open, chrome
	{
		chrm_loc := prog_open
		chrm_del :=	prog_delay
		if(prog_run = false)
		{
			msgbox, found chrome
		}
	}
	
;		assign the IE ones to the correct vars
	ifinstring, prog_open, iexplore
	{
		ie_loc := prog_open
		ie_del := prog_delay
		if(prog_run = false)
		{
			msgbox, found IE
		}
	}

;		assign the FF ones to the correct vars
	ifinstring, prog_open, firefox
	{
		ff_loc := prog_open
		ff_del := prog_delay
		if(prog_run = false)
		{
			msgbox, found FireFox
		}
	}
	
	ifinstring, prog_open, Deere
	{
		temp_loc := prog_open
		temp_del := prog_delay
		if(prog_run = false)
		{
			msgbox % "Case Template: " . temp_loc . " or " . prog_open
		}
	}

	if(prog_run = true)
	{
		if prog_open not contains firefox,chrome,iexplore,Deere
		{
			run, %prog_open%
			sleep, prog_delay
		}
	}
	
	else
	{
		msgbox % "" prog_open . " should take " . prog_delay "ms to open."
	}
}

;	Just to make outlook stop flashing
WinActivate, Outlook

if(prog_run = true)
{
	run, %temp_loc%
	sleep, temp_del
	WinActivate, Case
	send {Tab}
	sleep, 100
	send {Tab}
	sleep, 100
	send {Tab}
	sleep, 100
	send {Tab}
	sleep, 100
	send x123456
	sleep, 100
	send {Tab}
	sleep, 100
	send {Enter}
	sleep, dlr_del
	send !{F4}
	sleep, 100
}

if(prog_run = false)
{
	msgbox, got done with the programs
}

;---------------
;===BROWSERS====
;---------------

loop, read, ie.txt
{
	IE_links.Insert(A_LoopReadLine)
}

if(web_run = false)
{
	msgbox, read ie.txt
}

loop, read, chrome.txt
{
	Chrome_links.Insert(A_LoopReadLine)
}

if(web_run = false)
{
	msgbox, read chrome.txt
}

loop, read, firefox.txt
{
	FireFox_links.Insert(A_LoopReadLine)
}

if(web_run = false)
{
	msgbox, read firefox.txt
}

if(web_run = true)
{
;	open Chrome
	run, %chrm_loc%
	sleep, chrm_del
	for index, element in Chrome_links
	{
		sleep, 250
		send !d
		sleep, 500
		send %element%
		sleep, 250
		send {Enter}
		sleep, 1000
		send ^t
	}
	send ^w
	sleep, 2000
	
;	open IE
	run, %ie_loc%
	sleep, ie_del
	for index, element in IE_links
	{
		sleep, 250
		send !d
		sleep, 500
		send %element%
		sleep, 250
		send {Enter}
		sleep, 1000
		send ^t
	}
	sleep, 1000
	send ^w
	
;	open FireFox
	run, %ff_loc%
	sleep, ff_del
	WinActivate, Mozilla
	sleep, 1000
	for index, element in FireFox_links
	{
		sleep, 250
		send !d
		sleep, 500
		send %element%
		sleep, 250
		send {Enter}
		sleep, 1000
		send ^t
	}
	send ^w
}

else
{
	msgbox Won't run browsers, just show links (hopefully)
	
	for index, element in Chrome_links
		{
			msgbox, Chrome: %element%
		}
	sleep, 500
	
	for index, element in IE_links
		{
			msgbox, IE: %element%
		}
	sleep, 500
	
	for index, element in FireFox_links
		{
			msgbox, FF: %element%
		}
}


;--------------------------------
;==============EOF===============
;--------------------------------
exit