﻿/* javascript code for bazaarvoice */
var winLoc = window.location.toString();

/* Check to see if on staging vs production*/
if(document.domain.indexOf("uniteu.net")!=-1)
    document.domain = "uniteu.net";
else
    document.domain = "lumens.com";

//redirect to http if https
if (winLoc.indexOf("https") != -1) {
    window.location = winLoc.replace("https", "http");
}

/* AA base implementation */
function BVQADisplayed(questionCount, answerCount) {
    if (questionCount > 0) {
        var bvALPLink = document.getElementById("BVALPLinkContainer");
        if (bvALPLink) { bvALPLink.style.display = "block"; }
    }
    // Other custom items leveraging these values.
    // TODO: insert Web Analytics tracking here
}

/* R&R base implementation */
function ratingsDisplayed(totalReviewsCount, avgRating, ratingsOnlyReviewCount, recommendPercentage, productID) {
    if (totalReviewsCount > 0) {
        var bvRevCntr = document.getElementById("BVReviewsContainer");
        if (bvRevCntr) { bvRevCntr.style.display = "block"; }
        var bvSVPLink = document.getElementById("BVSVPLinkContainer");
        if (bvSVPLink) { bvSVPLink.style.display = "block"; }
    }
    // Other custom items leveraging these values.
    // TODO: insert Web Analytics tracking here
}

/* ask & answer code */
/*
function BVQADisplayed(questionCount, answerCount) {
if (questionCount > 0) {
var bvALPLink = document.getElementById("BVALPLinkContainer");
if (bvALPLink) { bvALPLink.style.display = "block"; }
} 
// Other custom items leveraging these values.
}
//url changes depending on whether this is a submission or not
if (bvdisplaycode!="") {	//is a submission
document.write("<link TYPE=\"text/css\" REL=\"STYLESHEET\" HREF=\"http://" + gAAdomainStr + "/" + gBvUrlStr + "answers/" + bvdisplaycode + "/static/bazaarvoiceQA.css\"/></link>");
document.write("<script LANGUAGE=\"JavaScript\" SRC=\"http://" + gAAdomainStr + "/" + gBvUrlStr + "answers/" + bvdisplaycode + "/static/bazaarvoiceQA.js\" TYPE=\"text/javascript\"></script>");
} else {	//normal behavior
document.write("<link TYPE=\"text/css\" REL=\"STYLESHEET\" HREF=\"http://" + gAAdomainStr + "/" + gBvUrlStr + "answers/7525/static/bazaarvoiceQA.css\"/></link>");
document.write("<script LANGUAGE=\"JavaScript\" SRC=\"http://" + gAAdomainStr + "/" + gBvUrlStr + "answers/7525/static/bazaarvoiceQA.js\" TYPE=\"text/javascript\"></script>");
}
*/

function positionReviews() {
    //position reviews
    var bvRevContainer = document.getElementById("bvRevSumTmp");
    var bvRev = document.getElementById("bvRevSum");
    var curRevleft = 0;
    var curRevtop = 0;
    curRevleft = findPosX(bvRevContainer);
    curRevtop = findPosY(bvRevContainer);
    if (curRevtop != 0) {
        bvRev.style.top = curRevtop + "px";
        bvRev.top = curRevtop + "px";
    } //this overrides a top pos. specified in the CSS, in case nothing is returned
    if (curRevleft != 0) {
        bvRev.style.left = curRevleft + "px";
        bvRev.left = curRevleft + "px";
    } //this overrides a left pos. specified in the CSS, in case nothing is returned

    if (document.getElementById("BVSVPLinkContainer")) {
        //find out if #BVSVPLinkContainer display is none, that means there are no printable reviews
        //make BVCustomerRatings float = none and width 100%
        var bvPrintRevLink = document.getElementById("BVSVPLinkContainer");
        if (bvPrintRevLink.style.display == "none") {
            document.getElementById("BVCustomerRatings").style.cssFloat = "none";
            document.getElementById("BVCustomerRatings").style.width = "95%";
        }
    }

    //position ask & answer
    /*
    var bvAAContainer = document.getElementById("bvAASumTmp");
    var bvAA = document.getElementById("bvAASum");
    var curAAleft = 0;
    var curAAtop = 0;
    curAAleft = findPosX(bvAAContainer);
    curAAtop = findPosY(bvAAContainer);
    if (curAAtop !=0) {
    bvAA.style.top = curAAtop + "px";
    bvAA.top = curAAtop + "px";
    } //this overrides a top pos. specified in the CSS, in case nothing is returned
    if (curAAleft != 0) {	
    bvAA.style.left = curAAleft + "px";
    bvAA.left = curAAleft + "px";
    } //this overrides a left pos. specified in the CSS, in case nothing is returned
    */
}
function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}