/* Copyright Channel Intelligence, Inc. 2002-2010");
*/
function MxButtonCaller(routerUrl, scrapeSku, createSpan, elementName, skuIdentifier){
    this.ci_RQV = function (name,dValue){
        var qArg=new RegExp('[\\?&]'+name+'=?([^&#]*)','i').exec(window.document.location);
        if(qArg===null){return dValue===undefined?null:dValue;}else if(qArg.length<2){return '';}else{return qArg[1];}
    }

    this.callMXRouter = function (){
        if (scrapeSku==true)
        {
            routerUrl+="&sRetailerSku="+this.ci_RQV(skuIdentifier);
        }

        var oScript = document.createElement("SCRIPT");
        oScript.type = "text/javascript";
        oScript.src = routerUrl;

        var ci_MxButton = this.getButtonScriptNode();

        if (ci_MxButton != null && ci_MxButton.parentNode!=null)
        { 
            try{
                if (createSpan==true)
                {
                    var oElement = document.createElement("span");
                    oElement.id = elementName; //"Rockbrook";
                    var insertedElement = ci_MxButton.parentNode.insertBefore(oElement, ci_MxButton);
                }
                
                var insertedScript = ci_MxButton.parentNode.insertBefore(oScript, ci_MxButton);
            }
            catch(err){}
        }
    }

    this.getButtonScriptNode = function ()
    {
        var thisScript=null;
        var scripts=document.getElementsByTagName("script");
        try{
            for(var i=0; i<scripts.length; i++)
            {
                if (scripts[i].src.length>0 && (scripts[i].src.toLowerCase().match("services.sellpath.com")!=null || scripts[i].src.toLowerCase().match("channelintelligence.com")!=null))
                {
                    thisScript = scripts[i];
                    break;
                }
            }
        }catch(err){}
        return thisScript;
    }
    
}

var ci_caller = new MxButtonCaller('http://edge.services.sellpath.com/Renderer/Syndication?RF=Javascript&DeliveryType=Button&ContentType=ProductTour&MxType=HostSku&Host=8ad79ef5-5737-4d68-b8bc-73313f27d9a8&Locale=en-US&sRetailerSKU=202962&sElementName=Rockbrook&bcall=true', false, false, 'Rockbrook', 'sku_id');

if (false==true || document.getElementById("Rockbrook")!=null)
{
    if (document.addEventListener)
    { document.addEventListener("DOMContentLoaded", new function(){ci_caller.callMXRouter();}, false); }
    else if (document.all && !window.opera)
    {
        ci_caller.callMXRouter();
    }
}

