$().ready(function() {

	$("div.options-container, div.options-container fieldset").hide(); 

	$('select').change(function() {
	
		var selectid = $(this).attr('id');
		var selectedoption = $(this).find('option:selected').attr('class');
	
		if ($('fieldset.'+selectedoption).length) {
			if ($('div.options-container.'+selectid+'_group fieldset.'+selectedoption).siblings(':visible')) {
				$('div.options-container.'+selectid+'_group fieldset.'+selectedoption).siblings().stop(true,true).fadeOut('200',function() {
					$('div.options-container.'+selectid+'_group').slideDown('200', function() {
						$(this).find('fieldset.'+selectedoption).stop(true,true).fadeIn('200');
						$(this).find('fieldset.'+selectedoption+' input[type="radio"]').each(function() {
 							if ($(this).attr("value") == "No") {
								$(this).attr({"checked": "checked"});
							}
						});
					});
				});
			} else {
				$('div.options-container.'+selectid+'_group').slideDown('200', function() {
				 	$(this).find('fieldset.'+selectedoption).fadeIn('200');
					$(this).find('fieldset.'+selectedoption+' input[type="radio"]').each(function() {
 						if ($(this).attr("value") == "No") {
							$(this).attr({"checked": "checked"});
						}
					});
				});
			}
		} else {
			$('div.options-container.'+selectid+'_group fieldset').fadeOut('200', function() {
				$('div.options-container.'+selectid+'_group').slideUp('200');
				$('div.options-container.'+selectid+'_group input[type="radio"]').each(function() {
					$(this).attr({"checked": ""});
				});
			});
		}    
				
		$("#num_officers, #num_firefighters").attr("value", "")/*.valid()*/;

	});	

	$('#num_officers').bind('blur', function() {
		var a = $(this).val();
		$('#num_firefighters').val(a);
	});

	$(' input[type="checkbox"]').click(function() {
   		var linkedoptions = $(this).attr('id');
   		var linkedoptionsselected = $(this).is(':checked')  ? '1' : '0';
   		
		if (linkedoptionsselected == '1') {
      		$('div.options-container.' + linkedoptions).slideDown('200');
      		$('div.options-container.' + linkedoptions + ' fieldset').fadeIn('200');
  		} else {
      		$('div.options-container.'+linkedoptions).slideUp('200').find('input[type="checkbox"], input[type="radio"]').each(function(){
      			$(this).attr({"checked": ""});
  			});
		}
	});
	
	$('.procurement_group').click(function() {
		var checkprocurement = '';
			
   		$('.procurement_group:checked').each(function() {
       		checkprocurement = '1'
   		});
			
     	$('.procurement_group_check').val(checkprocurement); 
  		$("#freeform").validate().element( ".procurement_group_check" );
	});
	
	$('#interestedin_option1').click(function() {
		$("#freeform").validate().element( ".procurement_group_check" );
	});
	
	$("#phone1, #phone2").mask("999-999-9999");

	$.metadata.setType("attr", "validate");

	
});
