$(function()
{
    $("#search").click(function()
    {
        var searchString = "";
        var splitter = "";
        $(".search").each(function()
        {
            var field = $(this).attr("id");
            var value = $(this).val();
            var elementType = $(this).attr("type").toLowerCase();
            
            if (elementType == "checkbox")
            {
                value = 0;
                if ( $(this).attr("checked"))
                    value = 1;
            }

            searchString += splitter + field + value;
            splitter = "_"
        });
        var mode = $("#m").val();
        
        document.location = "/search/0/" + mode + "/" + searchString;
    });

    $(".favourites-link").click( function()
    {
        var id = $( this ).attr( "rel" );
        var cmd = $( this ).attr( "cmd" );
        
        if ( cmd == "add" )
        {
            $.executeCommand({
                command: "saveFavourite",
                extraItems:
                [
                    {name: "itemID", value: id}
                ]
            });
        } else {
            $.executeCommand({
                command: "deleteFavourite",
                extraItems:
                [
                    {name: "itemID", value: id}
                ]
            });
        }
    });
});

function saveFavourite_callback( data )
{
    window.history.go( 0 );
}

function deleteFavourite_callback( data )
{
    window.history.go( 0 );
}
