$(document).ready(function(){
    $("a#more_search_options").click(function(event){
        event.preventDefault();
        if($("#advanced_search").is(":visible")) {
            $("#advanced_search").hide(200);
            $("#advanced_search").removeClass("hide");
            $("#more_search_options").removeClass("down_arrow_red").addClass("right_arrow_red");
        } else {
            $("#advanced_search").show(200);
            $("#advanced_search").removeClass("show");
            /* set default search quality */
            $("input[name=quality]")[0].checked = true;
            $("input[name=listing_type]").val("list");
            $("#more_search_options").removeClass("right_arrow_red").addClass("down_arrow_red");
        }
    });
    
    $("a#clear_form").click(function(event) {
        event.preventDefault();
        $("#search_form").clearForm()
    });
    
});

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form') {
            return $(':input',this).clearForm();
        }
        if (type == 'text' || type == 'password' || tag == 'textarea') {
            this.value = '';
        } else if (type == 'checkbox' || (type == 'radio' && this.name != 'quality')) {
            this.checked = false;
        } else if (tag == 'select') {
            this.selectedIndex = -1;
        }
    });
};



