
var k = 0;
$(document).ready( function() {
	$( 'body' ).click( function() {
		if( $( '#flags' ).css( 'display' ) == 'block' )
		{
			if( k == 1 )
			{
				$( '#flags' ).hide();
				k = 0;
			}
			else
			{
				k = 1;
			}
		}
		else
		{
			k = 0;
		}
	} );
	if( $( '#features' ).length )
	{
		AnalizeCheckbox();
	}
} );
function AnalizeCheckbox()
{
	$( 'input[@type=radio]' ).click(function() {
		if( $( this ).attr( 'checked' ) )
		{
			ParentCheckbox( $( this ).parent().parent() );
		}
	} );
	$( 'input[@type=checkbox]' ).click(function() {
		if( !$( this ).attr( 'checked' ) )
		{
			$( 'input[@type=radio]', $( this ).parent().parent() ).attr( 'checked', false );
		}
	} );
}
function ParentCheckbox( obj )
{
	if( $( obj ).hasClass( 'nowe_cechy' ) )
	{
		$( 'input.features_groups:first', obj ).attr('checked', 'checked' );
		return;
	}
	if( $( 'input.features_groups:first', obj ).length )
	{
		$( 'input.features_groups:first', obj ).attr('checked', 'checked' );
	}
	ParentCheckbox( $( obj ).parent().parent() );
}
function Flags()
{
	if( $( '#flags' ).css( 'display' ) == 'none' )
	{
		$( '#flags' ).show();
	}
	else
	{
		$( '#flags' ).hide();
		k = 0;
	}
}

function ShowAndHide( what )
{
	if( $( what ).css( 'display' ) == 'none' )
	{
		$( what ).show();
	}
	else
	{
		$( what ).hide();
	}
}

function setTab( class, tabs )
{
	for( var i = 0; i < tabs.length; i++ )
	{
		if( class == tabs[i] )
		{
			$( 'li.' + tabs[i] ).attr( 'id', 'current' );
			$( 'ul.' + tabs[i] ).css( 'display', 'block' );
		}
		else
		{
			$( 'li.' + tabs[i] ).attr( 'id', '' );
			$( 'ul.' + tabs[i] ).css( 'display', 'none' );
		}
	}
}

function CopyData()
{
	$( 'input' ).each( function( i, obj ) {
		name = $( obj ).attr( 'name' );
		val = $( obj ).val();
		if( !val )
		{
			$( '#' + name + '2' ).addClass( 'pending' );
		}
		else
		{
			$( '#' + name + '2' ).removeClass( 'pending' );
		}
		$( '#_transport' ).addClass( 'pending' );
		$( '#' + name + '2' ).val( val );
	} );
}