﻿function addTip(tipid) {
    var postData = "&id=" + tipid;
    var request = YAHOO.util.Connect.asyncRequest('POST', "/addtipprofile.ashx", callback, postData);
}
var handleSuccess = function(o) {
    if (o.responseText == "1") {
        alert("The tip has been added to your profile.  Click on the 'My Savings' menu item to view it and start recording savings associated with it.");
    }
    else if (o.responseText == "2") {
        alert("You already have this tip associated with your profile.");
    }
}
var handleFailure = function(o) {
    alert("There was a problem trying to add this tip to your profile.  Please try again.  If the problem persists we apologize for the inconvenience and we will address it shortly.");
}

var callback =
{
    success: handleSuccess,
    failure: handleFailure
};

var handleSuccess2 = function(o) {
    if (o.responseText != "1") {
        alert(o.responseText);
    }
    else {
        recordpop.hide();
        alert("Your savings have been recorded.  After pressing ok your screen will be refreshed.");
        location.href = location.href;
    }
}
var handleFailure2 = function(o) {
    alert("There was a problem trying to record your savings.  Please try again.  If the problem persists we apologize for the inconvenience and we will address it shortly.");
}

var callback2 =
{
    success: handleSuccess2,
    failure: handleFailure2
};

var curTip = 0;
function record(id) {
    curTip = id;
    recordpop.init();
    recordpop.showDialog();
}
function recordSavings() {

    var postData = "&id=" + curTip;
    postData += "&m=" + document.getElementById("txtMemo").value;
    postData += "&a=" + document.getElementById("txtAmount").value;
    postData += "&d=" + document.getElementById("txtDate").value;
    
    var request = YAHOO.util.Connect.asyncRequest('POST', "/RecordSavings.ashx", callback2, postData);
}
var recordpop = function() {
    var dialog;
    var clickEvent;

    return {
        init: function() {
            dialog = new YAHOO.widget.Dialog("recordpop", {
                fixedcenter: true,
                draggable: true,
                modal: true,
                constraintoviewport: true,
                width: "450px",  // Sam Skin dialog needs to have a width defined (7*2em + 2*1em = 16em).
                close: true
            });
            dialog.render();

            // Using dialog.hide() instead of visible:false is a workaround for an IE6/7 container known issue with border-collapse:collapse.
            dialog.hide();
        },
        hide: function() {
            dialog.hide();
        },
        showDialog: function() {
            dialog.show();
        }
    };
} ();
