When you get those kind of errors, its usually due to a syntax error. You probably forgot the {} on an if statement somewhere. Actually, I saw an else statement that was missing the curly braces. Good luck finding your missing pair.
Yeah, wait, actually, you're not using hardly any curly braces in your code. Sorry man, but they're required.