// Copyright Channel Intelligence, Inc. 2002-2009");
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; //"CII_LaunchProductTour08e01ff31be545f99c4cb8d53c70f6e9";
                    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?ContentType=ProductTour&MxType=HostManufacturerModel&Host=161e75ed-940d-4635-8c4d-e38ba53c2caa&Locale=en-us&MFR=C9368AN&MDL=CI&selementname=CII_LaunchProductTour08e01ff31be545f99c4cb8d53c70f6e9&bcall=true', false, true, 'CII_LaunchProductTour08e01ff31be545f99c4cb8d53c70f6e9', 'sku_id');

if (true==true || document.getElementById("CII_LaunchProductTour08e01ff31be545f99c4cb8d53c70f6e9")!=null)
{
    if (document.addEventListener)
    { document.addEventListener("DOMContentLoaded", new function(){ci_caller.callMXRouter();}, false); }
    else if (document.all && !window.opera)
    {
        ci_caller.callMXRouter();
    }
}
