﻿$(".favLink").click(function ()
{

    var fldName = this.id;

    $(this).fadeOut(20, function() { });

    var clientFieldId = fldName.substring(fldName.indexOf("XX") + 2);
    sweepId = clientFieldId.substring(fldName.indexOf("_") - 1);
    $.getJSON("http://acuwin.com/ajax/ToggleFavoriteSweep.aspx", { sid: sweepId, control_id: fldName },
    function (data)
    {
        //alert(data['sweep_id']);
        //alert(data["action"]);
        //alert(data["result"]);
        var fieldName = "#"+data['control_id'];

        //Ajax request was successful
        if (data["result"] == "OK")
        {
            //the item was added, set text to remove
            if (data["action"] == "add")
            {
                $(fieldName).text("Remove From Favorites");
            }
            //the item was removed, set text to addw
            else
            {
                $(fieldName).text("Add To Favorites");
            }
        }
        else
        {
            $(fieldName).html("<font color='red'>Favorites are for Members Only.</font> <a href='/join.aspx'>Create a Free Account Now!</a>");
        }
        $(fieldName).fadeIn(300, function () { });
    })
});

$('.default-value').each(function ()
{
    var default_value = "Optional";
    $(this).css('color', '#666'); // this could be in the style sheet instead
    $(this).focus(function ()
    {
        if (this.value == default_value)
        {
            this.value = '';
            $(this).css('color', '#333');
        }
    });
    $(this).blur(function ()
    {
        if (this.value == '')
        {
            $(this).css('color', '#666');
            this.value = default_value;
        }
    });
});