;------------------
;===VERSION 0.2====
;------------------

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



;-----------------------
;===TEXT REPLACEMENT====
;-----------------------
;	I put this in a seperate file for ease of restarting

	run, Case_Text.ahk



;---------------
;===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, Documents/programs.txt
{
    regexmatch(A_LoopReadLine, "(?:(?!,).)*", match)
		pseudoarray_Programs.Insert(match)
	regexmatch(A_LoopReadLine, "\b,\s+\K\S+", match)
		pseudoarray_Delay.Insert(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
		}
	}

;		Case Template
	ifinstring, prog_open, CaseTemplate
	{
		temp_loc := prog_open
		temp_del := prog_delay
		if(prog_run = false)
		{
			msgbox % "Case Template: " . temp_loc . " at " . prog_open
		}
	}

;		Zeacom	
	ifinstring, prog_open, Telephony
	{
		zcom_loc := prog_open
		zcom_del := prog_delay
		if(prog_run = false)
		{
			msgbox % "Zeacom: (" prog_open . ") " . prog_delay "ms to open."
		}
	}

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

;	Phone
if(prog_run = true)
{
	send {LWin}
	sleep, 250
	send communicator
	sleep, 2000
	send {enter}
	sleep, temp_del
}

;	Zeacom
if(prog_run = true)
{
if(zcom_loc <> "")
{
	run, %zcom_loc%
	sleep, zcom_del
	
}
}

;	Case Template
if(prog_run = true)
{
if(temp_loc <> "")
{
	run, %temp_loc%
	sleep, temp_del
	winwaitactive, Case Template
	sleep, 500
	send {Tab 4}
	sleep, 100
	send x123456
	sleep, 100
	send {Tab}
	sleep, 100
	send {Enter}
	winwaitactive, Dealer Info
	send !{F4}
	sleep, 100
	send {Tab 12}
	send {Enter}
	send {Tab 4}
}
}

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



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

;	read files
loop, read, Documents/ie.txt
{
	IE_links.Insert(A_LoopReadLine)
}

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

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

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

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

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


;	open pages
if(web_run = true)
{
;	open Chrome
if(chrm_loc <> "")
{
	run, %chrm_loc%
	sleep, chrm_del
	winwaitactive, Google
	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
if(ie_loc <> "")
{
	run, %ie_loc%
	sleep, ie_del
	winwaitactive, Internet Explorer
	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
if(ff_loc <> "")
{
	run, %ff_loc%
	sleep, ff_del
	winwaitactive, Mozilla Firefox
	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