arg(1) changed when doing AJAX
When implementing AJAX in a form, it will send a callback to system/ajax, if you didn't set your path in the AJAX properties. So, when you use arg(1) in your code, it will return ajax, which is the value assigned to the hidden form field.