$( document ).ready( function(){
  
    
    
  if ( $( 'input[@type=submit]' ) ) { $( 'input[@type=submit]' ).addClass( 'btnSubmit' ); }

	
	/**
	 * focus field style
	 */
  if ( $( 'input[@type=text]' ) ) {
	 $( 'input[@type=text]' ).bind( 'focus', function(){ $( this ).addClass( 'focus' ); });
    $( 'input[@type=text]' ).bind( 'blur', function(){ $( this ).removeClass( 'focus' ); });
	}
	
  if ($( 'input[@type=password]' ) ) {	
	 $( 'input[@type=password]' ).bind( 'focus', function(){ $( this ).addClass( 'focus' ); });
    $( 'input[@type=password]' ).bind( 'blur', function(){ $( this ).removeClass( 'focus' );});
	}
	
  if ( $( 'textarea' ) ) {
	 $( 'textarea' ).bind( 'focus', function(){ $( this ).addClass( 'focus' );	});
  	 $( 'textarea' ).bind( 'blur', function(){ $( this ).removeClass( 'focus' );});
	}
	
	/**
	 * Required form field utility
	 */
  if ( $('form .req' ) ){	 
	 $('form .req' ).bind( 'focus', function(){ $( this ).after( '<span class="required">To pole jest wymagane.</span>' );});
	 $('form .req').bind( 'blur', function(){ $( this ).next( '.required' ).remove(); });
	}
	/**
	 * Ajax from validation
	 */
	 
	 var currElem;
	 var fieldName;
    if ( $('form .req' ) ){	 
	 $('form .req').bind( 'blur', function(){
		currElem = $( this );
		
		/* clear field name - need to create method name */
		fieldName = ucFirst( clearName( $(currElem).attr('name') ) );
		var value = $(currElem).attr('value') ? $(currElem).attr('value') : '';
		var data = $.evalJSON( '{"'+$(currElem).attr('name') +'":"'+value+'"}' );
		
		$.post( sitePath+'/ajax/_index/ajaxValidate'+fieldName,
				data,
				function( response ){
					$( currElem ).next( '.reqFeedback' ).remove();
					$( currElem ).after( '<span class="reqFeedback">'+response+'</span>' );
				}
			);
		
	 });
	 
	 }
	 
	 function clearName( sName ){
		sName = sName.replace( /data\[/gi, '' );
		sName = sName.replace( /\]/gi, '' );
		return sName;
	 }	
	
});