var form_list
var displayed_form_count;
var max_forms = 10;
$(document).ready(function(){
	$("#add_form_link").click( function(event){
		event.preventDefault();
		if( displayed_form_count < max_forms ){
			hidden_list = $("div:hidden")
			// just show the first hidden one
			if(hidden_list.length){
				$(hidden_list[0]).show('slow');
				displayed_form_count++;
				if(displayed_form_count == max_forms){
					$("#add_form_link_container").html("You can only upload 10 photos at a time. Submit the form then visit this page again to upload more photos.");
					//$("#add_form_link").click(null);
				}
			}
		}

	} )
	form_list = $(".a_form")
	displayed_form_count = form_list.length;
	$(".a_form").each(function(i){
		if(i>0){
			hide_this_form = true
			$(this).find('input').each(function(){
				if( $(this).val() != "" ){
					if( this.type != 'checkbox' && this.type != 'radio'){
						// don't hide checkboxes unless they are checked
						hide_this_form = false;
					}
					else if( this.type == 'checkbox' && this.checked){
						hide_this_form = false;
					}
					else if(this.type == 'radio' && this.checked){
					    hide_this_form = false;
					}
				}
			})
			$(this).find('textarea').each(function(){
			    if( $(this).html() != ""){
			        hide_this_form = false;
			    }
			})
			// todo- display forms with selected options...
			if($(this).find('option:selected').length){
				hide_this_form = false;
			}
			if(hide_this_form){
				$(this).hide();
				displayed_form_count--;
			}
		}
	})
	// we never hide the first form
	
});