form_state['values'] generating error undefined index: values
The error indicates precisely what is going on: during the initial call of templates_form() the $form_state['values'] does not yet exist. This will exist in a future ajax call (if you do ajax) and in validate and submit functions. You better check if it exists first with isset or empty.