I tested your code, it can't compile. Except after I edited line no. 11:
"End;" ---> "End"
And the million dollar question: is that the way the code is/was intended to run ?
Mostly the else parts, it is unclear to which if statement they are intended to belong to. Only TS is able to tell that, the code for sure doesn't (or actually it does, but again was it intended)
btw: only changing what you wrote @handoku then i get an error in line 16: "Fatal: Syntax error, ";" expected but "ELSE" found"
@\Rayvenhaus:
make things more clear for both the compiler and yourself by putting your nested if statements between begin.. end blocks.