$(document).ready(function(){

    $("a.openTipFriend").click(function() {
        var artUrl = ($(this).attr("href"));
        var xhr;
        try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
        catch (e) {
            try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
            catch (e2) {
                try { xhr = new XMLHttpRequest(); }
                catch (e3) { xhr = false; }
            }
        }
        xhr.onreadystatechange=function() {
            if(xhr.readyState==4) {
                document.getElementById("tipForm").innerHTML=xhr.responseText;
                $("div.artToolTipFriend").toggle("slow");
            }
        }
        xhr.open("GET",artUrl + "?service=ajax&function=tipFriend",true);
        xhr.send(null);
        return false;
    });

    $('#tipForm .button').live("click", function() {
        var senderName = $("#yourName").val();
        var emailTo = $("#emailTo").val();
        var comment = $("#comment").val();
        var artUrl = $("#artUrl").val();

        var xhr;
        try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
        catch (e) {
            try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
            catch (e2) {
                try { xhr = new XMLHttpRequest(); }
                catch (e3) { xhr = false; }
            }
        }
        xhr.onreadystatechange=function() {
            if(xhr.readyState==4) {
                document.getElementById("tipForm").innerHTML=xhr.responseText;
                //$("div.artToolTipFriend").toggle();
                setTimeout(function(){
                    $("div.artToolTipFriend").toggle("slow");
                },5000);
            }
        }
        var qString = "";
        qString = qString + "&sender=" + senderName + "&recipient=" + emailTo + "&comment=" + comment + "&artUrl=" + artUrl;
        xhr.open("GET",artUrl + "?service=ajax&function=sendTip" + qString,true);
        xhr.send(null);
        return false;
    });

});
