$(document).ready(function() {
	
	//dymki
	$('a.title').click( function(e) {
		return false;
	});
	
	// formularz zakadania konta
		// miasto //
	if( $('#blnOtherCity').find('input').attr("checked") == true )
		$('#showSelect').hide();
	else
		$('#showInput').hide();
	
	$('#blnOtherCity').find('input').click( function(e) {
		if( $(this).attr("checked") == true )
		{	//zaznaczony, pokazuje list
			$('#showSelect').hide();
			$('#showInput').show();
		} else {
			//odznaczony, pokazuje pol do wpisania
			$('#showInput').hide();
			$('#showSelect').show();
		}
	});
		// e-mail //
	if( $('#blnLogin').find('input').attr("value") == "on" )
		$('#strLogin').hide();
	
	$('#blnLogin').find('input').click( function(e) {
		if( $(this).attr("checked") == true )
		{	//zaznaczony, pokazuje list
			$('#strLogin').show();
		} else {
			//odznaczony, pokazuje pol do wpisania
			$('#strLogin').hide();
		}
	});
	
});

// zakadanie aukcji
$("#revenueList").ready(function() {
	
	$("a.auctionDelete").click( function(e) {
		$(this).parent().parent().remove();
		return false;
	});
	
	$('a.auctionAdd').click( function(e) {
		$( '<div class="revenue">' + $("div.revenue").html() + '<li>' + $("li.revenueRemove").html() + '</li></div>' ).appendTo("div#revenueList").find('a').click( function(e) {
			$(this).parent().parent().remove();
			return false;
		});
		return false;
	});
	
});

//sumowanie
$('#intAmountOfCredit').ready(function() {
	
	if( !$("#intAmountOfCredit").val() )
	{
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	}
	
	$('#intAmountOfObligation').change( function(e) {
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	});
	
	$('#intOtherObligation').change( function(e) {
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	});
	
	$('#intPurposeAny').change( function(e) {
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	});
	
	$('#intValueOfEstate').change( function(e) {
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	});
	
	$('#intPersonalParticipation').change( function(e) {
		intValue = addAllFields();
		$("#intAmountOfCredit").attr({ "value": intValue });
	});
	
	function addAllFields()
	{
		intAmountOfObligation = intOtherObligation = intPurposeAny = intValueOfEstate = intPersonalParticipation = 0;
		
		if( $("#intAmountOfObligation").val() )
			intAmountOfObligation = parseInt( $("#intAmountOfObligation").val() );
		
		if( $("#intOtherObligation").val() )
			intOtherObligation = parseInt( $("#intOtherObligation").val() );
		
		if( $("#intPurposeAny").val() )
			intPurposeAny = parseInt( $("#intPurposeAny").val() );
		
		if( $("#intValueOfEstate").val() && $("#intOtherBankSelect").val() )
			intValueOfEstate = parseInt( $("#intValueOfEstate").val() );
		
		if( $("#intPersonalParticipation").val() )
			intPersonalParticipation = parseInt( $("#intPersonalParticipation").val() );
		
		intValue = intAmountOfObligation + intOtherObligation + intPurposeAny + intValueOfEstate - intPersonalParticipation;
		return intValue;
	}
});