$(document).ready(function () {
    $("#chInfoDiv").hide();
    $("#checkHeaderForm").submit(function () {
        $("#chInfoDiv").show("slow");
        $("#chInfo").show("slow");
        $("#chsInfo").show("slow");
        $("#chInfoBody").html("");
        $("#chsInfoBody").html("");
        $("#chInfoDiv").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Getting Response Headers and info...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/sitechecker.py/GetHeaderInfo",
            data: "url=" + $("#chBox").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 12000,
            success: function (json) {
                if (json.error) {
                    $("#chInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">This page could not be checked. Please check the page URL that you entered. <input type="button" id="chInvalid" value="OK" /></div>'
                    });
                    $("#chInvalid").click(function () {
                        $("#chInfoDiv").unblock();
                        return false;
                    });
                } else {
                    chHtml = "";
                    $.each(json.Criteria, function (i, item) {
                        if (item.CheckedCriterion == "Status") {
                            chHtml += "<tr><td>Status</td><td>" + item.Description + "</td></tr>";
                        } else {
                            headers = item.Description.split("<br />");
                            $.each(headers, function (i) {
                                head = headers[i].split(":");
                                chHtml += "<tr><td>" + head[0] + "</td><td>" + head[1] + "</td></tr>";
                            });
                        }
                    });
                    $("#chInfoBody").html(chHtml);
                }
            }
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/sitechecker.py/GetSiteInfo",
            data: "url=" + $("#chBox").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 12000,
            success: function (json) {
                if (json.error) {
                    $("#chInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">This page could not be checked. Please check the page URL that you entered. <input type="button" id="chInvalid" value="OK" /></div>'
                    });
                    $("#chInvalid").click(function () {
                        $("#chInfoDiv").unblock();
                        return false;
                    });
                } else {
                    chsHtml = "";
                    $.each(json.Criteria, function (i, item) {
                        cc = item.CheckedCriterion;
                        if (cc == "Original URL" || cc == "DNS IP" || cc == "Ping") {
                            chsHtml += '<tr><td width="150">' + cc + '</td><td width="350">' + item.Description + "</td></tr>";
                        }
                    });
                    $("#chsInfoBody").html(chsHtml);
                    $("#chInfoDiv").unblock();
                }
            }
        });
        return false;
    });
});
var firstRun = true;
var MAX_FIELDS = 5;
var domain = "";
var objs = [];
var done = 0;
var numOfFields = 0;
var ajaxManager = $.manageAjax({
    manageType: "sync",
    maxReq: 0,
    blockSameRequest: true
});
var prs = [];
var googles = [];
var yahoos = [];
var lives = [];
var urls = [];
$(document).ready(function () {
    $("#domainReset").click(function () {
        $("#domainInfoBody").empty();
        $("#domainInfoDiv").unblock();
        $("#domainInfoForm input[type=text]").each(function () {
            $(this).val("");
        });
        objs = [];
        numOfFields = 0;
        done = 0;
        prs = [];
        googles = [];
        yahoos = [];
        lives = [];
        urls = [];
    });
});

function domainFormSubmit() {
    if (firstRun == true) {
        firstRun = false;
        $("#domainInfo").show("slow");
    }
    done = 0;
    objs = [];
    prs = [];
    googles = [];
    yahoos = [];
    lives = [];
    urls = [];
    $("#domainInfoBody").empty();
    $("#domainInfoDiv").block({
        css: {
            border: "0px solid #e6e6e6",
            padding: "5px",
            backgroundColor: "#ffffff",
            opacity: ".9",
            filter: "alpha(opacity = 90)",
            zoom: "1",
            color: "#000000",
            width: "400px",
            textAlign: "left"
        },
        overlayCSS: {
            border: "0px solid #e6e6e6",
            backgroundColor: "#000000",
            opacity: ".5",
            filter: "alpha(opacity = 50)",
            zoom: "1"
        },
        message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Gathering Domain Statistics...</div>'
    });
    re = /(http\:\/\/)?\w+([\.\-]?\w+)*(\.\w{2,3})(\/)?$/;
    $("#domainInfoForm input[type=text]").each(function () {
        numOfFields++;
        if (re.test($(this).val())) {
            if ($(this).val().indexOf("http://") >= 0) {
                domain = jQuery.trim($(this).val());
            } else {
                domain = "http://" + jQuery.trim($(this).val());
            }
            if (domain.substr(domain.length - 1, 1) != "/") {
                domain = domain + "/";
            }
            urls.push(domain);
        } else {
            if ($(this).val() == "") {
                numOfFields--;
            } else {
                errorMsg = "Invalid Domain. Please enter a valid URL and try again.";
                $("#domainInfoDiv").unblock().block({
                    css: {
                        border: "0px solid #e6e6e6",
                        padding: "5px",
                        backgroundColor: "#ffffff",
                        opacity: "1",
                        filter: "alpha(opacity = 90)",
                        zoom: "1",
                        color: "#000000",
                        width: "400px",
                        textAlign: "left"
                    },
                    message: '<div class="domainTitle">' + errorMsg + ' <input type="button" id="domainInvalid" value="OK" /></div>'
                });
                $("#domainInvalid").click(function () {
                    $("#domainInfoDiv").unblock();
                    return false;
                });
                return false;
            }
        }
    });
    if (numOfFields > 0) {
        getData();
    } else {
        errorMsg = "No domains specified. Please enter a domain and try again.";
        $("#domainInfoDiv").unblock().block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: "1",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            message: '<div class="domainTitle">' + errorMsg + ' <input type="button" id="domainInvalid" value="OK" /></div>'
        });
        $("#domainInvalid").click(function () {
            $("#domainInfoDiv").unblock();
            return false;
        });
        return false;
    }
}
function getData() {
    if (urls.length < 1) { return; }
    urlsValue = "";
    for (var i in urls) {
        if (i < urls.length) {
            var url = encodeURIComponent(urls[i]);
            urlsValue = urlsValue + url + "|";
        }
    }
    urlsValue = urlsValue.slice(0,-1); //remove the last |            
    $.ajax({
        type: "GET",
        url: "http://www.bruceclay.com/python/pageinfo.py/GetAllInfo",
        data: "urls=" + urlsValue + "&ip=127.0.0.1",
        dataType: "jsonp",
        jsonp: "jsonp",
        timeout: 20000,
        success: function(json) {
            //hack to deal with crap JSON encoding from simplejson
            var pages = $.parseJSON(json.data.pages.replace(/\'/g,'\"')); 
            var pr = $.parseJSON(json.data.pr.replace(/\'/g,'\"'));
          
            for (var i in urls) {              
                if (i < urls.length) {
                    prs.push(pr[urls[i]]);
                    googles.push(pages[urls[i]].Google);
                    done++;
                    yahoos.push(pages[urls[i]].Yahoo);
                    done++;
                    lives.push(pages[urls[i]].Bing);
                    done++;
                }
            }
            displayDomainInfo();
        }        
    });
}
function displayDomainInfo() {
    if (numOfFields * 3 == done) {
        for (var i in urls) {
          if (i < urls.length) {
            google = googles[i] * 1;
            yahoo = yahoos[i] * 1;
            live = lives[i] * 1;
            pr = prs[i] * 1;
            url = urls[i];
            total = (google * 1) + (yahoo * 1) + (live * 1);
            datamax = Math.max(google, yahoo, live);
            digits = parseInt((Math.log(datamax) / Math.log(10))) + 1;
            fact = Math.pow(10, digits - 1);
            max = Math.round(datamax / fact) * fact;
            if (max < datamax) {
                max += fact;
            }
            chartURI = "http://chart.apis.google.com/chart?chs=180x75&cht=bhs&chco=0060ae|ae3900|3c8a33&chxt=x,y&chxs=0,,10|1,,,1,10,1,t&chbh=a&chf=c,lg,90,ffffff,0,e0e8f1,0.6|bg,s,e0e8f1";
            chartURI += "&chxl=0:|0|" + max / 2 + "|" + max + "|1:|Live|Yahoo|Google";
            chartURI += "&chd=t:" + google + "," + yahoo + "," + live;
            chartURI += "&chxr=0,0," + max;
            chartURI += "&chds=0," + max;

            function addCommas(sValue) {
                sValue = "" + sValue;
                var sRegExp = new RegExp("(-?[0-9]+)([0-9]{3})");
                while (sRegExp.test(sValue)) {
                    sValue = sValue.replace(sRegExp, "$1,$2");
                }
                return sValue;
            }
            replacement = "<tr>";
            replacement += '<td style="text-align:left;"><a href="' + url + '">' + url + "</a></td>";
            replacement += "<td>" + pr + "</td>";
            replacement += "<td><b>" + addCommas(total) + "</b></td>";
            replacement += '<td><a href="http://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&safe=off&q=site%3A' + url + '">' + addCommas(google) + "</a></td>";
            replacement += '<td><a href="http://siteexplorer.search.yahoo.com/search?p=' + url + '&bwm=p&bwms=p&fr=sfp&fr2=seo-rd-se">' + addCommas(yahoo) + "</a></td>";
            replacement += '<td><a href="http://search.msn.com/results.aspx?q=site%3A' + url + '&FORM=QBNO">' + addCommas(live) + "</a></td>";
            replacement += '<td><img src="' + chartURI + '"></td>';
            replacement += "</tr>";
            $("#domainInfoBody").append(replacement);
          }
        }
        done = 0;
        numOfFields = 0;
        $("#domainInfoDiv").unblock();
    }
}
var done = 0,
    numOfRequests = 0,
    cats = "",
    dems = "",
    kwdTerms = 0,
    maxTerms = 12,
    lastUsed = new Array();
$(document).ready(function () {
    $("#kwdTable tbody").empty();
    $("#kwdReset").click(function () {
        $("#kwdTable tbody").empty();
        $("#kwdDiv").unblock();
        $("#kwd").val("");
        done = 0;
        numOfRequests = 0;
        kwdTerms = 0;
    });
    $("#kwdTable").tablesorter();
    $("#kwdTable").bind("sortEnd", function () {
        while (kwdTerms > maxTerms) {
            removedKwd = lastUsed.pop();
            $("#kwdTable tbody tr:contains(" + removedKwd + ")").remove();
            kwdTerms--;
            done--;
        }
        $("#kwdTable tbody tr:even").removeClass().addClass("even");
        $("#kwdTable tbody tr:odd").removeClass().addClass("odd");
        $("#kwdTable tr th:first-child").attr("style", "text-align:left;width:240px;");
        $("#kwdTable tr td:first-child").attr("style", "text-align:left;width:240px;");
    });
});

function getKeywordInfo() {
    kwd = "";
    flag = false;
    if ($("#kwd").val().indexOf("\n") >= 0 || $("#kwd").val().indexOf(",") >= 0) {
        keywords = $("#kwd").val().split(/\n|\,/g);
        tempArray = keywords;
        k = 0;
        while (k < keywords.length) {
            flag = false;
            for (var j in lastUsed) {
                if (lastUsed[j] == keywords[k]) {
                    flag = true;
                }
            }
            if (flag) {
                keywords.splice(k, 1);
                k--;
            } else {
                if (keywords[k] == "") {
                    keywords.splice(k, 1);
                    k--;
                }
            }
            k++;
        }
        for (var k = 0; k < keywords.length; k++) {
            lastUsed.unshift(keywords[k]);
            kwdTerms++;
        }
        kwd = keywords.join("|");
    } else {
        kwd = jQuery.trim($("#kwd").val());
        kwdTerms++;
        for (var j in lastUsed) {
            if (kwd == lastUsed[j]) {
                flag = true;
            }
        }
        if (!flag) {
            lastUsed.unshift(kwd);
        }
    }
    if (kwd == "") {
        errorMsg = "";
        if (lastUsed.length == 0) {
            errorMsg = "Please enter at least 1 keyword.";
        } else {
            errorMsg = "You've already entered these search terms. Please enter new keywords and try again.";
        }
        $("#kwdDiv").unblock().block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: "1",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            message: '<div class="kwdTitle">' + errorMsg + ' <input type="button" id="kwdTimeOut" value="OK" /></div>'
        });
        $("#kwdTimeOut").click(function () {
            $("#kwdDiv").unblock();
            return false;
        });
        return;
    }
    function getKSP(kwd) {
        return "http://ksp.smartz.com/KSP.asmx/GetKeywordStatistics?kwd=" + kwd + "&filter=activity|cpc|ctr|categories|demographics&specific=true";
    }
    var proxy = "/cgi-bin/proxy.pl?url=";
    var keyword = "",
        activity = "",
        ctr = "",
        cpc = "",
        categories = "",
        googleActivity = "",
        yahooActivity = "",
        liveActivity = "",
        demographics = "",
        firstRun = true;
    var ajaxManager1 = $.manageAjax({
        manageType: "sync",
        maxReq: 0,
        blockSameRequest: true
    });
    if (firstRun == true) {
        firstRun = false;
        $("#kwdTable").show("slow");
    }
    $("#kwdDiv").block({
        css: {
            border: "0px solid #e6e6e6",
            padding: "5px",
            backgroundColor: "#ffffff",
            opacity: ".9",
            filter: "alpha(opacity = 90)",
            zoom: "1",
            color: "#000000",
            width: "400px",
            textAlign: "left"
        },
        overlayCSS: {
            border: "0px solid #e6e6e6",
            backgroundColor: "#000000",
            opacity: ".5",
            filter: "alpha(opacity = 50)",
            zoom: "1"
        },
        message: '<div style="line-height:50px;" class="kwdTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Gathering Keyword Statistics...</div>'
    });
    $(this).ajaxStart(function () {});
    ajaxManager1.add({
        url: proxy + escape(getKSP(kwd)),
        datatype: "xml",
        beforeSend: function (XMLHttpRequest) {
            numOfRequests++;
        },
        success: function (xml) {
            $("ProxyError", xml).each(function () {
                $("#kwdDiv").unblock().block({
                    css: {
                        border: "0px solid #e6e6e6",
                        padding: "5px",
                        backgroundColor: "#ffffff",
                        opacity: "1",
                        filter: "alpha(opacity = 90)",
                        zoom: "1",
                        color: "#000000",
                        width: "400px",
                        textAlign: "left"
                    },
                    message: '<div class="kwdTitle">The Keyword Server has timed out. Please try again later. <input type="button" id="kwdTimeOut" value="OK" /></div>'
                });
                removeKwds = $("#kwd").val().split(/\n|\,/g);
                for (kwd in removeKwds) {
                    removedKwd = lastUsed.pop();
                    kwdTerms--;
                    done--;
                }
                $("#kwdTimeOut").click(function () {
                    $("#kwdDiv").unblock();
                    return false;
                });
            });
            kwds = 0;
            done++;
            $("#kwdTable tbody").append("<tr></tr>");
            $("keywordStats", xml).each(function () {
                kwds++;
                keyword = $(this).find("Keyword").text();
                activity = $(this).find("Activity").text();
                googleActivity = $(this).find("GoogleActivity").text();
                yahooActivity = $(this).find("YahooActivity").text();
                liveActivity = $(this).find("LiveActivity").text();
                ctr = $(this).find("CTR").text();
                cpc = $(this).find("CPC").text();
                categories = new Array();
                $("Categories", $(this)).find("string").each(function () {
                    categories.push($(this).text());
                });
                demographics = new Array();
                $("Demographics", $(this)).children().each(function () {
                    demographics[this.tagName.replace(/_/, "-").replace(/Age/, "")] = $(this).text();
                });
                if (kwds > 1) {
                    $("#kwdTable tbody").append('<tr><td colspan="6"></td></tr>');
                    done++;
                }
                updatePage();
            });
        }
    });

    function insertKSPBlock(kwd, activity, google, yahoo, live, ctr, cpc, categories, demographics) {
        cats = '<span style="color:#993333;font-weight:bold;">Categories for "' + kwd + '"</span>';
        count = 0;
        for (var cat in categories) {
            var i = parseInt(cat, 10);
            if (!isNaN(i)) {
              cats += "<br />&raquo;" + categories[i].replace(/_/g, " ");
              count++;
            }          
        }
        dems = '<span style="color:#993333;font-weight:bold;">Demographics:</span><br />';
        dems += "Male: " + demographics.Male + "&nbsp;&nbsp;Female: " + demographics.Female + "<br />";
        dems += "Error: +/- " + demographics.GenderUnknown + "<br /><br />";
        dems += "Ages:<br />";
        dems += "&nbsp;&nbsp;0-13: " + demographics["0-13"] + "<br />";
        dems += "&nbsp;&nbsp;13-18: " + demographics["13-18"] + "<br />";
        dems += "&nbsp;&nbsp;18-25: " + demographics["18-25"] + "<br />";
        dems += "&nbsp;&nbsp;25-35: " + demographics["25-35"] + "<br />";
        dems += "&nbsp;&nbsp;35-50: " + demographics["35-50"] + "<br />";
        dems += "&nbsp;&nbsp;50-65: " + demographics["50-65"] + "<br />";
        dems += "&nbsp;&nbsp;65+: " + demographics["65"] + "<br />";
        dems += "&nbsp;&nbsp;Age Error: +/- " + demographics.Unknown;
        toReturn = "";
        toReturn += "<tr>";
        toReturn += '<td><div style="color:blue" class="kwdCell">' + kwd + "</div></td>";
        toReturn += "<td>" + google + "</td>";
        toReturn += "<td>" + yahoo + "</td>";
        toReturn += "<td>" + live + "</td>";
        toReturn += '<td style="font-weight:bold">' + activity + "</td>";
        toReturn += "<td>" + ctr + "</td>";
        toReturn += "<td>" + cpc + "</td>";
        toReturn += '<td><div style="color:blue" class="catCell">' + count + " Categories</div></td>";
        toReturn += "</tr>";
        return toReturn;
    }
    function updatePage() {
        replacement = "#kwdTable tbody tr:eq(" + (done - 1) + ")";
        $(replacement).replaceWith(insertKSPBlock(keyword, activity, googleActivity, yahooActivity, liveActivity, ctr, cpc, categories, demographics));
        $(".catCell:last").attr("title", cats);
        $(".kwdCell:last").attr("title", dems);
        //take off callouts for now since jquery.bt doesn't work right
        /*
        $(".kwdCell:last,.catCell:last").bt({
            positions: "top",
            fill: "rgba(255,251,240,1)",
            cssStyles: {
                color: "black",
                width: "auto"
            },
            width: 350,
            padding: 10,
            cornerRadius: 10,
            spikeLength: 15,
            spikeGirth: 10
        });
        */
        sorting = [
            [4, 1]
        ];
        if (done >= kwdTerms) {
            $("#kwdDiv").unblock();
            $("#kwdTable").trigger("update");
            $("#kwdTable").trigger("sorton", [sorting]);
        }
    }
}
$(document).ready(function () {
    $("#laInfoDiv").hide();
    $("#linkAnalysisForm").submit(function () {
        $("#laInfoDiv").show("slow");
        $("#laInfo").show("slow");
        $("#laInfoBody").html("");
        $("#laInfoDiv").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Gathering Inbound Links...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/pageinfo.py/GetLinkAnalysis",
            data: "urls=" + $("#laBox").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 20000,
            success: function (json) {
                links = [];
                $.each(json, function (i, item) {
                    links.push(item);
                });
                links.sort(function (a, b) {
                    counta = countb = 0;
                    if (a.Google) {
                        counta++;
                    }
                    if (a.Yahoo) {
                        counta++;
                    }
                    if (a.Bing) {
                        counta++;
                    }
                    if (b.Google) {
                        countb++;
                    }
                    if (b.Yahoo) {
                        countb++;
                    }
                    if (b.Bing) {
                        countb++;
                    }
                    if (counta < countb) {
                        return -1;
                    }
                    if (counta > countb) {
                        return 1;
                    }
                    return 0;
                });
                laHtml = "";
                $.each(links, function (i, item) {
                    laHtml += '<tr><td style="text-align:left;">' + (item.Url.length < 83 ? item.Url : item.Url.substring(0, 79) + "...") + "</td>";
                    laHtml += "<td>" + (item.Google ? '<img src="/checkmark.png" align="center" />' : "&nbsp;") + "</td>";
                    laHtml += "<td>" + (item.Yahoo ? '<img src="/checkmark.png" align="center" />' : "&nbsp;") + "</td>";
                    laHtml += "<td>" + (item.Bing ? '<img src="/checkmark.png" align="center" />' : "&nbsp;") + "</td></tr>";
                    return (i < 30);
                });
                $("#laInfoBody").html(laHtml);
                $("#laInfoDiv").unblock();
            },
            error: function (xhr, status, error) {
                $("#laInfoDiv").unblock().block({
                    css: {
                        border: "0px solid #e6e6e6",
                        padding: "5px",
                        backgroundColor: "#ffffff",
                        opacity: ".9",
                        filter: "alpha(opacity = 90)",
                        zoom: "1",
                        color: "#000000",
                        width: "600px",
                        textAlign: "left"
                    },
                    overlayCSS: {
                        border: "0px solid #e6e6e6",
                        backgroundColor: "#000000",
                        opacity: ".5",
                        filter: "alpha(opacity = 50)",
                        zoom: "1"
                    },
                    message: '<div style="line-height:50px;" class="domainTitle">The links for this URL could not be gathered. Please try again later. <input type="button" id="laInvalid" value="OK" /></div>'
                });
                $("#laInvalid").click(function () {
                    $("#laInfoDiv").unblock();
                    return false;
                });
            }
        });
        return false;
    });
});
$(document).ready(function () {
    $("#rInfoDiv").hide();
    $("#kwdReset").click(function () {
        $("#rInfoDiv").find("tbody").empty();
        $("#rInfoDiv").unblock();
        $("#researchSearchWord").val("");
    });
    $("#researchForm").submit(function () {
        $("#rInfoDiv").show("slow");
        $("#rDomains").show("slow");
        $("#rUrls").show("slow");
        $("#rDomainsBody").html("");
        $("#rUrlsBody").html("");
        $("#rInfoDiv").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Gathering Top Ranked Pages...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/pageinfo.py/GetResearch?",
            data: "keyword=" + $("#researchSearchWord").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 30000,
            success: function (json) {
                if (json.error) {
                    $("#rInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">Ranked Pages could not be gathered. Please try again later. <input type="button" id="rInvalid" value="OK" /></div>'
                    });
                    $("#rInvalid").click(function () {
                        $("#rInfoDiv").unblock();
                        return false;
                    });
                } else {
                    json.Domains.sort(function (a, b) {
                        if (a.Rankings.TotalRank < b.Rankings.TotalRank) {
                            return -1;
                        }
                        if (a.Rankings.TotalRank > b.Rankings.TotalRank) {
                            return 1;
                        }
                        return 0;
                    });
                    var rRankings = [];
                    $.each(json.Rankings, function (i, item) {
                        if (i != "success") {
                            var rObj = item;
                            rObj.url = i;
                            if (!("TotalRank" in rObj)) {
                                rObj.TotalRank = 300;
                            }
                            rRankings.push(rObj);
                        }
                    });
                    rRankings.sort(function (a, b) {
                        if (a.TotalRank < b.TotalRank) {
                            return -1;
                        }
                        if (a.TotalRank > b.TotalRank) {
                            return 1;
                        }
                        return 0;
                    });
                    rHtml = "";
                    counter = 0;
                    $.each(json.Domains, function (i, item) {
                        rHtml += '<tr><td style="text-align:left">' + item.Domain + "</td>";
                        rHtml += "<td>" + item.PageRank + "</td>";
                        rHtml += "<td>" + item.KeywordsInTitle.Google + "</td>";
                        rHtml += "<td>" + item.PagesIndexed.Google + "</td>";
                        rHtml += "<td>" + item.InboundLinks.Google + "</td>";
                        rHtml += "<td>" + item.Rankings.Google + "</td>";
                        rHtml += "<td>" + item.Rankings.Yahoo + "</td>";
                        rHtml += "<td>" + item.Rankings.Bing + "</td></tr>";
                        counter++;
                        return counter < 9;
                    });
                    $("#rDomainsBody").html(rHtml);
                    rHtml = "";
                    counter = 0;
                    $.each(rRankings, function (i, item) {
                        rHtml += '<tr><td style="text-align:left">' + item.url + "</td>";
                        rHtml += "<td>" + item.Google + "</td>";
                        rHtml += "<td>" + item.Yahoo + "</td>";
                        rHtml += "<td>" + item.Bing + "</td>";
                        counter++;
                        return counter < 10;
                    });
                    $("#rUrlsBody").html(rHtml);
                    $("#rInfoDiv").unblock();
                }
            }
        });
        return false;
    });
});
$(document).ready(function () {
    $("#spaInfoDiv").hide();
    var spaReportsDone = 0;
    $("#spaForm").submit(function () {
        spaReportsDone = 0;
        $("#spaInfoDiv").show("slow");
        $("#spaTags").show("slow");
        $("#spaWordMetrics").show("slow");
        $("#spaWordPhrases").show("slow");
        $("#spaTagsBody").html("");
        $("#spaWordMetricsBody").html("");
        $("#spaWordPhrasesBody").html("");
        $("#spaInfoDiv").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Analyzing Web Page...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/kda.py/GetPage?",
            data: "url=" + $("#spaUrl").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 10000,
            success: function (page_json) {
                if (page_json.error) {
                    $("#spaInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">This page could not be spidered. Please check the URL and try again. <input type="button" id="spaInvalid" value="OK" /></div>'
                    });
                    $("#spaInvalid").click(function () {
                        $("#spaInfoDiv").unblock();
                        return false;
                    });
                } else {
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetTagInformation?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 15000,
                        success: function (json) {
                            tagHtml = "";
                            $.each(json.Tags, function (i, item) {
                                if (item.Name == "Title" || item.Name == "Description" || item.Name == "Keywords") {
                                    tagHtml += '<tr><td style="text-align:left">' + item.Name + "</td>";
                                    tagHtml += "<td>" + item.Count + "</td>";
                                    tagHtml += "<td>" + item.StopWords + "</td>";
                                    tagHtml += "<td>" + item.UsedWords + "</td>";
                                    tagHtml += "<td>" + item.Length + "</td>";
                                    tagHtml += "<td>" + item.Data.ResultData + "<br /><br />" + item.Data.TextData + "</td></tr>";
                                }
                            });
                            $("#spaTagsBody").html(tagHtml);
                            spaReportsDone++;
                            if (spaReportsDone == 3) {
                                $("#spaInfoDiv").unblock();
                            }
                        }
                    });
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetWordMetrics?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 15000,
                        success: function (json) {
                            metricHtml = "";
                            $.each(json.WordMetrics, function (i, item) {
                                metricHtml += '<tr><td style="text-align:left">' + item.Name + "</td>";
                                metricHtml += "<td>" + (Math.round(item.Value * 100) / 100) + "</td>";
                                metricHtml += '<td style="text-align:left;">' + item.Description + "</td></tr>";
                            });
                            $("#spaWordMetricsBody").html(metricHtml);
                            spaReportsDone++;
                            if (spaReportsDone == 3) {
                                $("#spaInfoDiv").unblock();
                            }
                        }
                    });
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetWordPhrases?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 30000,
                        error: function(jqXHR, textStatus, errorThrown) {
                            console.log("GetWordPhrases ERROR: " + textStatus + " :: " + errorThrown);
                            $("#spaInfoDiv").unblock();
                        },
                        success: function (json) {
                            phrases = [json.Phrases[3], json.Phrases[2]];
                            phrases[0].Keywords.sort(function (a, b) {
                                if (a.AllWords.Counter > b.AllWords.Counter) {
                                    return -1;
                                }
                                if (a.AllWords.Counter < b.AllWords.Counter) {
                                    return 1;
                                }
                                return 0;
                            });
                            phrases[1].Keywords.sort(function (a, b) {
                                if (a.AllWords.Counter > b.AllWords.Counter) {
                                    return -1;
                                }
                                if (a.AllWords.Counter < b.AllWords.Counter) {
                                    return 1;
                                }
                                return 0;
                            });
                            phraseHtml = "";
                            $.each(phrases, function (i, item) {
                                if (i == 0) {
                                    phraseHtml += '<tr><td colspan="9"><span style="color:#900">1 Word Phrases</span></td></tr>';
                                } else {
                                    phraseHtml += '<tr><td colspan="9"><span style="color:#900">2 Word Phrases</span></td></tr>';
                                }
                                phraseHtml += '<tr><td style="text-align:right"><b>Used Words</b></td>';
                                phraseHtml += '<td><b><span class="' + item.Count.MetaTitle.Style + '">' + item.Count.MetaTitle.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.MetaDesc.Style + '">' + item.Count.MetaDesc.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.MetaKeywords.Style + '">' + item.Count.MetaKeywords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.Heads.Style + '">' + item.Count.Heads.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.AltTags.Style + '">' + item.Count.AltTags.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.FirstWords.Style + '">' + item.Count.FirstWords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.BodyWords.Style + '">' + item.Count.BodyWords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.AllWords.Style + '">' + item.Count.AllWords.Counter + "</span></b></td>";
                                $.each(item.Keywords, function (j, jItem) {
                                    phraseHtml += '<tr><td style="text-align:left">' + jItem.Name + "</td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaTitle.Style + '">' + jItem.MetaTitle.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaDesc.Style + '">' + jItem.MetaDesc.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaKeywords.Style + '">' + jItem.MetaKeywords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.Heads.Style + '">' + jItem.Heads.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.AltTags.Style + '">' + jItem.AltTags.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.FirstWords.Style + '">' + jItem.FirstWords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.BodyWords.Style + '">' + jItem.BodyWords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.AllWords.Style + '">' + jItem.AllWords.Counter + "</span></td>";
                                    if (i == 0) {
                                        return j < 22;
                                    } else {
                                        return j < 9;
                                    }
                                });
                                phraseHtml += "<br /><br />";
                            });
                            $("#spaWordPhrasesBody").html(phraseHtml);
                            spaReportsDone++;
                            if (spaReportsDone == 3) {
                                $("#spaInfoDiv").unblock();
                            }
                        }
                    });
                }
            }
        });
        return false;
    });
    $("#spaInfoDiv2").hide();
    var spaReportsDone2 = 0;
    $("#spaForm2").submit(function () {
        spaReportsDone2 = 0;
        $("#spaInfoDiv2").show("slow");
        $("#spaTags2").show("slow");
        $("#spaWordMetrics2").show("slow");
        $("#spaWordPhrases2").show("slow");
        $("#spaTagsBody2").html("");
        $("#spaWordMetricsBody2").html("");
        $("#spaWordPhrasesBody2").html("");
        $("#spaInfoDiv2").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Analyzing Web Page...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/kda.py/GetPage?",
            data: "url=" + $("#spaUrl2").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 10000,
            success: function (page_json) {
                if (page_json.error) {
                    $("#spaInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">This page could not be spidered. Please check the URL and try again. <input type="button" id="spaInvalid2" value="OK" /></div>'
                    });
                    $("#spaInvalid2").click(function () {
                        $("#spaInfoDiv2").unblock();
                        return false;
                    });
                } else {
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetTagInformation?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 15000,
                        success: function (json) {
                            tagHtml = "";
                            $.each(json.Tags, function (i, item) {
                                if (item.Name == "Title" || item.Name == "Description" || item.Name == "Keywords") {
                                    tagHtml += '<tr><td style="text-align:left">' + item.Name + "</td>";
                                    tagHtml += "<td>" + item.Count + "</td>";
                                    tagHtml += "<td>" + item.StopWords + "</td>";
                                    tagHtml += "<td>" + item.UsedWords + "</td>";
                                    tagHtml += "<td>" + item.Length + "</td>";
                                    tagHtml += "<td>" + item.Data.ResultData + "<br /><br />" + item.Data.TextData + "</td></tr>";
                                }
                            });
                            $("#spaTagsBody2").html(tagHtml);
                            spaReportsDone2++;
                            if (spaReportsDone2 == 3) {
                                $("#spaInfoDiv2").unblock();
                            }
                        }
                    });
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetWordMetrics?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 15000,
                        success: function (json) {
                            metricHtml = "";
                            $.each(json.WordMetrics, function (i, item) {
                                metricHtml += '<tr><td style="text-align:left">' + item.Name + "</td>";
                                metricHtml += "<td>" + (Math.round(item.Value * 100) / 100) + "</td>";
                                metricHtml += '<td style="text-align:left;">' + item.Description + "</td></tr>";
                            });
                            $("#spaWordMetricsBody2").html(metricHtml);
                            spaReportsDone2++;
                            if (spaReportsDone2 == 3) {
                                $("#spaInfoDiv2").unblock();
                            }
                        }
                    });
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/kda.py/GetWordPhrases?",
                        data: "pid=" + page_json.id + "&project=0",
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 15000,
                        success: function (json) {
                            phrases = [json.Phrases[3], json.Phrases[2]];
                            phrases[0].Keywords.sort(function (a, b) {
                                if (a.AllWords.Counter > b.AllWords.Counter) {
                                    return -1;
                                }
                                if (a.AllWords.Counter < b.AllWords.Counter) {
                                    return 1;
                                }
                                return 0;
                            });
                            phrases[1].Keywords.sort(function (a, b) {
                                if (a.AllWords.Counter > b.AllWords.Counter) {
                                    return -1;
                                }
                                if (a.AllWords.Counter < b.AllWords.Counter) {
                                    return 1;
                                }
                                return 0;
                            });
                            phraseHtml = "";
                            $.each(phrases, function (i, item) {
                                if (i == 0) {
                                    phraseHtml += '<tr><td colspan="9"><span style="color:#900">1 Word Phrases</span></td></tr>';
                                } else {
                                    phraseHtml += '<tr><td colspan="9"><span style="color:#900">2 Word Phrases</span></td></tr>';
                                }
                                phraseHtml += '<tr><td style="text-align:right"><b>Used Words</b></td>';
                                phraseHtml += '<td><b><span class="' + item.Count.MetaTitle.Style + '">' + item.Count.MetaTitle.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.MetaDesc.Style + '">' + item.Count.MetaDesc.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.MetaKeywords.Style + '">' + item.Count.MetaKeywords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.Heads.Style + '">' + item.Count.Heads.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.AltTags.Style + '">' + item.Count.AltTags.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.FirstWords.Style + '">' + item.Count.FirstWords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.BodyWords.Style + '">' + item.Count.BodyWords.Counter + "</span></b></td>";
                                phraseHtml += '<td><b><span class="' + item.Count.AllWords.Style + '">' + item.Count.AllWords.Counter + "</span></b></td>";
                                $.each(item.Keywords, function (j, jItem) {
                                    phraseHtml += '<tr><td style="text-align:left">' + jItem.Name + "</td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaTitle.Style + '">' + jItem.MetaTitle.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaDesc.Style + '">' + jItem.MetaDesc.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.MetaKeywords.Style + '">' + jItem.MetaKeywords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.Heads.Style + '">' + jItem.Heads.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.AltTags.Style + '">' + jItem.AltTags.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.FirstWords.Style + '">' + jItem.FirstWords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.BodyWords.Style + '">' + jItem.BodyWords.Counter + "</span></td>";
                                    phraseHtml += '<td><span class="' + jItem.AllWords.Style + '">' + jItem.AllWords.Counter + "</span></td>";
                                    if (i == 0) {
                                        return j < 22;
                                    } else {
                                        return j < 9;
                                    }
                                });
                                phraseHtml += "<br /><br />";
                            });
                            $("#spaWordPhrasesBody2").html(phraseHtml);
                            spaReportsDone2++;
                            if (spaReportsDone2 == 3) {
                                $("#spaInfoDiv2").unblock();
                            }
                        }
                    });
                }
            }
        });
        return false;
    });
});
$(document).ready(function () {
    $("#stInfoDiv").hide();
    $("#statusForm").submit(function () {
        $("#stInfoDiv").show("slow");
        $("#stInfo").show("slow");
        $("#strInfo").show("slow");
        $("#stInfoBody").html("");
        $("#StrInfoBody").html("");
        $("#stInfoDiv").block({
            css: {
                border: "0px solid #e6e6e6",
                padding: "5px",
                backgroundColor: "#ffffff",
                opacity: ".9",
                filter: "alpha(opacity = 90)",
                zoom: "1",
                color: "#000000",
                width: "400px",
                textAlign: "left"
            },
            overlayCSS: {
                border: "0px solid #e6e6e6",
                backgroundColor: "#000000",
                opacity: ".5",
                filter: "alpha(opacity = 50)",
                zoom: "1"
            },
            message: '<div style="line-height:50px;" class="domainTitle"><img src="ajax-loader.gif" style="float:left; padding-right:10px;" />Getting Indexed Pages and Links...</div>'
        });
        $.ajax({
            type: "GET",
            url: "http://www.bruceclay.com/python/pageinfo.py/GetPagesIndexed?",
            data: "urls=" + $("#stBox").val(),
            dataType: "jsonp",
            jsonp: "jsonp",
            timeout: 5000,
            success: function (pijson) {
                if (pijson.error) {
                    $("#stInfoDiv").unblock().block({
                        css: {
                            border: "0px solid #e6e6e6",
                            padding: "5px",
                            backgroundColor: "#ffffff",
                            opacity: ".9",
                            filter: "alpha(opacity = 90)",
                            zoom: "1",
                            color: "#000000",
                            width: "600px",
                            textAlign: "left"
                        },
                        overlayCSS: {
                            border: "0px solid #e6e6e6",
                            backgroundColor: "#000000",
                            opacity: ".5",
                            filter: "alpha(opacity = 50)",
                            zoom: "1"
                        },
                        message: '<div style="line-height:50px;" class="domainTitle">This page could not be checked. Please check the page URL that you entered. <input type="button" id="stInvalid" value="OK" /></div>'
                    });
                    $("#stInvalid").click(function () {
                        $("#stInfoDiv").unblock();
                        return false;
                    });
                } else {
                    $.ajax({
                        type: "GET",
                        url: "http://www.bruceclay.com/python/pageinfo.py/GetInboundLinks?",
                        data: "urls=" + $("#stBox").val(),
                        dataType: "jsonp",
                        jsonp: "jsonp",
                        timeout: 5000,
                        success: function (iljson) {
                            if (iljson.error) {
                                $("#stInfoDiv").unblock().block({
                                    css: {
                                        border: "0px solid #e6e6e6",
                                        padding: "5px",
                                        backgroundColor: "#ffffff",
                                        opacity: ".9",
                                        filter: "alpha(opacity = 90)",
                                        zoom: "1",
                                        color: "#000000",
                                        width: "600px",
                                        textAlign: "left"
                                    },
                                    overlayCSS: {
                                        border: "0px solid #e6e6e6",
                                        backgroundColor: "#000000",
                                        opacity: ".5",
                                        filter: "alpha(opacity = 50)",
                                        zoom: "1"
                                    },
                                    message: '<div style="line-height:50px;" class="domainTitle">This page could not be checked. Please check the page URL that you entered. <input type="button" id="stInvalid" value="OK" /></div>'
                                });
                                $("#stInvalid").click(function () {
                                    $("#stInfoDiv").unblock();
                                    return false;
                                });
                            } else {
                                for (var key in pijson) {
                                    stHtml = "";
                                    stHtml += '<tr><td style="text-align:left;">Google</td><td>' + pijson[key].Google + "</td><td>" + iljson[key].Google + "</td>";
                                    stHtml += '<tr><td style="text-align:left;">Yahoo</td><td>' + pijson[key].Yahoo + "</td><td>" + iljson[key].Yahoo + "</td>";
                                    stHtml += '<tr><td style="text-align:left;">Bing</td><td>' + pijson[key].Bing + "</td><td>" + iljson[key].Bing + "</td>";
                                    $("#stInfoBody").html(stHtml);
                                    $("#stInfoDiv").unblock();
                                }
                            }
                        }
                    });
                }
            }
        });
        return false;
    });
});
