﻿// JScript File

//Update Sept 5th 2009 - Ability to add Visitors
jQuery(document).ready(function() {
    PostMessageSetup();
    jQuery('#becomesupporter_a').click(function() { jQuery('#becomesupporter_div').show("slow"); });
    jQuery('.blogfrogshownext').click(function() { jQuery(this).next().show("slow"); });

    //hover
    jQuery('.bfvisitrow').hover(function() {
        var pos = jQuery(this).position();
        var width = jQuery(this).width();
        jQuery(this).next("div").css({ "left": (pos.left + width - 20) + "px", "top": pos.top + "px" });
        jQuery(this).next("div").stop(true, true).fadeIn("slow");
    }, function() { jQuery(this).next("div").fadeOut("fast"); });

    jQuery('.bf_popup').hover(function() {
        jQuery(this).stop(true, true).show();
    }, function() { jQuery(this).fadeOut("fast"); });

});

function supporter_jsonp_callback(result) {
    var parsedresponse = result.split("&");

    if (parsedresponse[0].toString() != 'NOERROR') {
        //ERROR!!!
        document.getElementById('result_p').innerHTML = parsedresponse[0];
    }
    else {
        //SUCESSFUL POST!
        document.getElementById("result_p").innerHTML = 'Thanks for becoming a friend of this blog. The next time someone clicks your link to this blog, your blog will appear above!';
        document.getElementById("instructions_div").style.display = "none"; //hide the directions
    }

    //re-enable the button, show the result, hide the scanning message
    document.getElementById('postbutton').setAttribute('disabled', false);
    document.getElementById('postbutton').disabled = false;
    document.getElementById('result_p').style.display = "block";
    document.getElementById('working_p').style.display = "none";
}

function PostMessageSetup() {
    jQuery('#postbutton').click(function() {
        // format the querystring
        var poststr = "requestingURL=" + document.getElementById("theurl").value +
                    "&blogID=" + BlogFrogBlogID +
                    "&UserID=" + BlogFrogUserID;

        // Call our Web Service, passing in our Query params. The error function is called
        // whenever an exception is thrown by the web service (among other times)
        jQuery.ajax({
            type: "GET",
            url: "http://theblogfrog.com/widgets/NewSupporter.ashx?" + poststr + "&callback=supporter_jsonp_callback",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            error: function(xhr, msg) {
                jQuery('#errormessage').innerHTML = 'There was a problem with the request, please try again<br/>';
            }


        });
        //show the busy image, disable the button
        document.getElementById('postbutton').setAttribute('disabled', true);
        document.getElementById('working_p').style.display = "inline";
        return false;
    });
}

var blogfrogvisitID;  //used to store

function BFhidethisvisit(visitID) {
    var poststr = "mode=deletevisit&visitID=" + visitID + "&OwnerblogID=" + BlogFrogBlogID + "&OwnerUserID=" + BlogFrogUserID;

    jQuery.ajax({
        type: "GET",
        url: "http://theblogfrog.com/widgets/VisitorHandler.ashx?" + poststr + "&callback=visitor_jsonp_callback",
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        error: function(xhr, msg) {
            jQuery('.bfvisitrow' + visitID).html('<p>There was a problem communicating the request, please try again in a few moments</p>');
        }
    });

    blogfrogvisitID = visitID;
}

function BFalwayshide(visitID, visitoruserID, blogID) {
    var poststr = "mode=blockuser&visitID=" + visitID + "&blogID=" + BlogFrogBlogID + "&userID=" + visitoruserID;

    jQuery.ajax({
        type: "GET",
        url: "http://theblogfrog.com/widgets/VisitorHandler.ashx?" + poststr + "&callback=visitor_jsonp_callback",
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        error: function(xhr, msg) {
            jQuery('.bfvisitrow' + visitID).html('<p>There was a problem communicating the request, please try again in a few moments</p>');
        }
    });

    blogfrogvisitID = visitID;
}

function visitor_jsonp_callback(result) {
    jQuery('.bfvisitrow' + blogfrogvisitID).html(result);
}

//If we were the ones that included jQuery, return the $ back to other libraries
try {
    if (BFincludedjQuery) {
        jQuery.noConflict();
    }
}
catch (theerror)
{ }

var ref = document.referrer;
if(ref.search(/\?/) > 0){
    ref = ref.substring(0,ref.search(/\?/));
}
document.write("<script type=\"text/javascript\" src=\"http://theblogfrog.com/widgets/SupportersWidget.aspx?UserID=" + BlogFrogUserID + "&BlogID=" + BlogFrogBlogID + "&sample=" + BlogFrogSample + "&color=" + BlogFrogColor + "&n=" + BlogFrogN + "&width=" + BlogFrogWidth + "&showtop=" + BlogFrogShowTop + "&widget_title=" + encodeURI(BlogFrogTitle) + "&top_title=" + encodeURI(BlogFrogTopTitle) + "&friendtitle=" + encodeURI(BlogFrogFriendName) + "&ref=" + ref + "\"></script>");

