/**
 * @author Developing
 */

$(document).ready(function()
{
	var moreFirmButton = $("#moreFirms");
	var moreScalesButton = $("#moreScales");
	var firmsContainer = $("#firmsContainer");
	var scalesContainer = $("#scalesContainer");
	var selectElement = $("select[@name='f[firm]']");
	var selectElement2 = $("select[@name='f[scale]']");
	var mainTypesChecks = $("div.typeBox > input");
	
	moreFirmButton.toggle( function()
		{
			firmsContainer.show();
			moreFirmButton.text('Скрыть список');
			var value = selectElement.fieldValue();
			selectElement.attr("disabled", "disabled");
			$("input[@name='fullSearchFormFirms[" + value + "]']").attr("checked", "checked");
		}, 
		function()
		{
			firmsContainer.hide();
			moreFirmButton.text('Выбрать ещё');			
			$("div.firmBox > input").attr("checked", "");			
			selectElement.attr("disabled", "");			
		} );
		
	moreScalesButton.toggle( function()
		{
			scalesContainer.show();
			moreScalesButton.text('Скрыть список');
			var value = selectElement2.fieldValue();
			selectElement2.attr("disabled", "disabled");
			$("input[@name='fullSearchFormScales[" + value + "]']").attr("checked", "checked");
		}, 
		function()
		{
			scalesContainer.hide();
			moreScalesButton.text('Выбрать ещё');			
			$("div.firmBox > input").attr("checked", "");			
			selectElement2.attr("disabled", "");			
		} );
	
	
		
	$("#allFirmsCheck").change( function()
	{
		$("div.firmBox > input").attr('checked', $(this).attr('checked') == true);
	} );
	
	$("#allFirmsCheck").click( function() { $(this).change(); } );
	
	$("#allScalesCheck").change( function()
	{
		$("div.scaleBox > input").attr('checked', $(this).attr('checked') == true);
	})
	
	$("#allScalesCheck").click( function() { $(this).change(); } );	
	
	$("#allTypesCheck").change( function()
	{
		mainTypesChecks.attr('checked', $(this).attr('checked') == true);
		mainTypesChecks.change();
	})
	
	$("#allTypesCheck").click( function() { $(this).change(); } );

	mainTypesChecks.change( function()
	{
		$("#"+$(this).attr('title')+" input").attr('checked', $(this).attr('checked') == true);
	})
	
	mainTypesChecks.click( function(){	$(this).change(); } );
	
	$("input.fadedText").click( function() 
	{ 
		if ( $(this).val() == "(можно оставить пустой)") 
		{
			$(this).val("");
			$(this).removeClass("fadedText");
			$(this).addClass("normalText");
		}
	} );
	
	$(".firmContainer > a").each( function()
	{
		var scalesDiv = $(this).parent().find(".dropdownFirmScales");
		$(this).toggle( function()
		{
			//$(this).attr('src', imagesPath + "minus.gif");
			scalesDiv.show();
		}, function()
		{
			//$(this).attr('src', imagesPath + "plus.gif");
			scalesDiv.hide();
		} );
	} );
	
	$(".opens").each( function()
	{
		var parentDiv = $(this).parent();
		$(this).toggle( function()
		{
			//$(this).attr('src', imagesPath + "minus.gif");
			parentDiv.css('height', 'auto');
		}, function()
		{
			//$(this).attr('src', imagesPath + "plus.gif");
			parentDiv.css('height', $(this).height()+3+'px');
		} );
	} );
	
	$(".opens").each( function()
	{
		$(this).parent().css('height', $(this).height()+3+'px');
	});
	
	
})

