﻿function search_tips() {
    var mode = "";

    for (i = 0; i < document.aspnetForm.search.length; i++) {
        if (document.aspnetForm.search[i].checked == true) {
            mode = document.aspnetForm.search[i].value;
            break;
        }
    }

    var val = document.aspnetForm.txtSearch.value;

    window.location = "search_tips.aspx?" + mode + "=" + escape(val);
    //alert("search_tips.aspx?" + mode + "=" + escape(val) );
}

function rate_tip(img, tip, value) {
    $.getJSON("scripts/tips/rate.aspx?tip=" + tip + "&rating=" + value, function(data) {

        if (data.Result == -100) {
            alert("You must be signed in to rate tips.");
            return;
        }
        if (data.Result == -200) {
            alert("An error occured when saving your rating.");
            return;
        }
        if (data.Result == -300) {
            alert("There was a problem with your request.");
            return;
        }

        $(img).attr("src", $(img).attr("src").replace("_grey", ""));
        $(img).attr("onclick", "");
        $(img).css("cursor", "default");

        if (value > 0)
            $(img).next().remove();
        else
            $(img).prev().remove();

        $(img).next(".rating_saved").fadeIn();

        /*var current_rating = parseInt($("#tip_rating_" + tip).html());
        current_rating += value;
        $("#tip_rating_" + tip).html(current_rating.toString());*/
    });
}