$( document ).ready( function(){

/**
 * style for forms
 */

	$( 'input[@type=submit]' ).addClass( 'btnSubmit' );
	$( 'p:has( input[@type=submit] )' ).addClass( 'submit' );
	
	$( 'input[type=text]' ).addClass( 'text' );
	$( 'input[type=checkbox]' ).addClass( 'checkbox' );
	$( 'input[type=radio]' ).addClass( 'radio' );
	
	/**
	 * focus field style
	 */
	$( 'input[@type=text]' ).bind( 'focus', function(){
		$( this ).addClass( 'focus' );  
	});
	$( 'input[@type=text]' ).bind( 'blur', function(){
		$( this ).removeClass( 'focus' );
	});
	$( 'input[@type=password]' ).bind( 'focus', function(){
		$( this ).addClass( 'focus' );
	});
	$( 'input[@type=password]' ).bind( 'blur', function(){
		$( this ).removeClass( 'focus' );
	});
	$( 'textarea' ).bind( 'focus', function(){
		$( this ).addClass( 'focus' );
	});
	$( 'textarea' ).bind( 'blur', function(){
		$( this ).removeClass( 'focus' );
	});
 
	
	
	/**
	 * Required form field utility
	 */
	$('form .req' ).bind( 'focus', function(){
		$( this ).after( '<span class="required">To pole jest wymagane.</span>' );
	});
	
	$('form .req').bind( 'blur', function(){
		$( this ).next( '.required' ).remove();
	});
	
	/**
	 * Mask for input
	 * a - Represents an alpha character (A-Z,a-z)
	 * 9 - Represents a numeric character (0-9)
	 * * - Represents an alphanumeric character (A-Z,a-z,0-9) 
	 */
	if( $.mask ){
		$(function($){
			$(".maskedDate").mask("99/99/9999");
		});
		
		$(function($){
			$(".maskedPhone").mask("(99) 999 99 99");
		});
		
		$(function($){
			$(".maskedMobile").mask("+99 999 999 999");
		});
		
		$(function($){
			$(".maskedNIP").mask("999-99-99-999");
		});
		
		$(function($){
			$(".maskedPESEL").mask("99-99-99-99999");
		});
	}
	
	$('#subscriptions li').click( function(){
		$('#subscriptions li').removeClass('selected')
		var elem = $(this).find('input[@type=radio]');
		$('#subscriptions li').removeClass('selected');
		if( $(elem).attr( 'checked' ) === true ){
			$(this).addClass('selected');
		} else {
			$(elem).attr( 'checked', true );
			$(this).addClass('selected');
			$( '#subscriptions' ).parents('.row').removeClass( 'error' );
		}
	});
	
	

});