if (!window.jqsDCCRnC)
    jqsDCCRnC = jQuery;
(function(jQuery) {
    function newLinkingSuccessCallback(data) {
        if (data == null) return;
        var colData = eval(data);
        for (i = 0; i < ratingDivs.length; i++) {
            var ratingDiv = jQuery(ratingDivs[i]);
            for (j = 0; j < colData.length; j++) {
                var objData = colData[j];
                if (objData.CommentObject.toLowerCase() == ratingDiv.attr("strCommentObjVal").toLowerCase()
                && ratingDiv.attr("ratingmode") == objData.RatingMode) {
                    ratingDiv.html(ratingDiv.html().replace("[PRC_TOTALRATINGS]", objData.TotalRatings)
                        .replace("[PRC_AVERAGERATINGVALUE]", objData.AverageRating).replace("[PRC_AVERAGERATINGVALUE]", objData.AverageRating)
                        .replace("[PRC_COMMENTCOUNT]", objData.CommentCount).replace("[PRC_RETURNINGURL]", objData.ReturningURL)
                        );
                    ratingDiv.find("img").attr("src", objData.ImagePath);
                    break;
                }
            }
        }
        ratingDivs.show();
    }
    var ratingDivs = null;
    jQuery(document).ready(function() {
        var domainName = window.location.host;
        var appPath;
        ratingDivs = jQuery("div[class*=dcc_rnc_CLSelector]");
        if (ratingDivs.length > 0) {
            var strCrossLinkingDataColl = "";
            for (i = 0; i < ratingDivs.length; i++) {
                var ratingDiv = jQuery(ratingDivs[i]);
                appPath = ratingDiv.attr("apppath");
                if (appPath == undefined) appPath = '';
                if (ratingDiv.attr("co_val").indexOf('qsp:') != -1 && ratingDiv.attr("co_val2")) {
                    if (ratingDiv.attr("co_val2") != 'QS') {
                        ratingDiv.attr("strCommentObjVal", ratingDiv.attr("co_val") + "=" + ratingDiv.attr("co_val2"));
                    }
                    else {
                        ratingDiv.attr("strCommentObjVal", ratingDiv.attr("co_val") + "=" + RC_getQuerystring(ratingDiv.attr("co_val").replace('qsp:', ''), ''));
                    }
                }
                else {
                    ratingDiv.attr("strCommentObjVal", ratingDiv.attr("co_val"));
                }

                //Data Format is :- CommentObjVal, CommentObjType,ModuleId,RatingMode
                strCrossLinkingDataColl += ratingDiv.attr("strCommentObjVal")
            + "," + ratingDiv.attr("co_type")
            + "," + parseInt(ratingDiv.attr("moduleid"))
            + "," + ratingDiv.attr("ratingmode") + "}";
            }
            strCrossLinkingDataColl = strCrossLinkingDataColl.substr(0, strCrossLinkingDataColl.length - 1);

            jQuery.ajax({
                type: "POST",
                url: window.location.protocol + "//" + window.location.host + appPath + "/desktopmodules/dnncentric-ratingandcomments/CrossLinking.ashx?type=new",
                data: strCrossLinkingDataColl,
                success: newLinkingSuccessCallback
            });
        }
    })
})(jqsDCCRnC);
function createXMLHttpRequest() {
    try { return new XMLHttpRequest(); } catch (e) { }
    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
    alert("XMLHttpRequest not supported");
    return null;
}
function RC_GetCrossLinkHTML(appPath, ratingMode, tabModID, comobjtype, comobjval, comobjval2) {
    var xmlHttpObject = createXMLHttpRequest();
    var domainName = document.domain;
    if (comobjtype == 'Q') {
        if (comobjval2 == undefined)
            comobjval2 = '';
        xmlHttpObject.open("GET", window.location.protocol + "//" + window.location.host + appPath + "/desktopmodules/dnncentric-ratingandcomments/CrossLinking.ashx?comobjtype=" + comobjtype + "&comobjval=" + comobjval + ":" + comobjval2 + "&tabmodid=" + tabModID + "&ratingmode=" + ratingMode, false);
    }
    else {
        xmlHttpObject.open("GET", window.location.protocol + "//" + window.location.host + appPath + "/desktopmodules/dnncentric-ratingandcomments/CrossLinking.ashx?comobjtype=" + comobjtype + "&comobjval=" + comobjval + "&tabmodid=" + tabModID + "&ratingmode=" + ratingMode, false);
    }
    xmlHttpObject.send(null);
    var resString = xmlHttpObject.responseText;
    return resString;
}

function RC_getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.toLowerCase().replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
} 
