/**
*
*  Jquery spraudnis !priekš lietotāja tabulas formas
*/
(function($){
	$.fn.extend({
		changeCompanyTypeInput : function (){
			settings = {
				select_name	: '#veids',
				input_name	: '#v_other_nos'
			};
			var $checkbox = $(this);
			var $select = $(settings.select_name);
			var $input = $(settings.input_name);
			
			$checkbox.checkCompanyTypeInput($select, $input, $checkbox.is(':checked'));
			
			$checkbox.click(function(){
				$checkbox.checkCompanyTypeInput($select, $input, $checkbox.is(':checked'));
			});
		},
		checkCompanyTypeInput : function ($select, $input, $bool){
			if ($bool) {
				$select.attr('disabled', true);
				$input.removeAttr('disabled');
			} else {
				$select.removeAttr('disabled');
				$input.attr('disabled', true);
			}
		},
		allowSubmit : function (){
			settings = {
				submit_name	: 'input[type=submit]'
			};
			var $checkbox = $(this);
			var $submit = $(settings.submit_name);
			
			$checkbox.checkDisableRegister($submit, $checkbox.is(':checked'));
			
			$checkbox.click(function(){
				$checkbox.checkDisableRegister($submit, $checkbox.is(':checked'));
			});
		},
		checkDisableRegister : function ($submit, $bool){
			if ($bool) {
				$submit.removeAttr('disabled');
			} else {
				$submit.attr('disabled', true);
			}
		}
	});
})($);

/**
*
* Document ready funkcija izsauc iepriekš izveidoto spraudni
*/
$(document).ready(function() {
 	$('#v_other').changeCompanyTypeInput();
 	$('#agree').allowSubmit();
});

