$(document).ready(function() {
	// validate form
	$("form.box").validate();
	
	// set label width
	var max = 0;
	$("label").each(function(){
		if ($(this).width() > max)
			max = $(this).width();   
	});
	$("label").width(max);
	
	// validate form
	$("form").validate({
		rules: {
			logo: { accept: "jpg" },
			da1: { accept: "png" },
			da2: { accept: "png" }
		}
	});
	
	// toggle categories
	$('#categories h1 span').click(function() {
		var id = $(this).attr("id");
		
		$('#s_' + id).slideToggle();
	});
	
	// check all categories
	$('.parent_category').click(function() {
		var id = $(this).val();
		var chk = $(this).attr('checked')? true : false;
		
		$(".check_" + id).attr('checked', chk);
	});
	
	// search type
	$('[name="s_type"]').change(function() {
		var type = $("OPTION:selected", this).val();
		
		if (type == 1) {
			$('#s_keyword').css('display', 'inline');
			$('#s_keyword').val('Enter keyword(s)');
			$('#s_company').hide();
			$('#s_state').hide();
			$('#s_state').val('0');
		}
		else if (type == 2) {
			$('#s_keyword').hide();
			$('#s_company').css('display', 'inline');
			$('#s_company').val('Enter company name');
			$('#s_state').hide();
			$('#s_state').val('0');
		}
		else if (type == 3) {
			$('#s_keyword').hide();
			$('#s_company').hide();
			$('#s_state').css('display', 'inline');
		}
	});
	
	// search fields
	$('#s_keyword').focus(function() {
		if ($(this).val() == 'Enter keyword(s)')
			$(this).val('');
	});
	
	$('#s_company').focus(function() {
		if ($(this).val() == 'Enter company name')
			$(this).val('');
	});
});
