/*--start of const--*/
var BANNER_BASE_URL = 'http://www.conduit-banners.com/';
var LOG_SITE_URL = 'http://usage.conduit-banners.com/Logger/';
var LOG_ENABLED = true;
/*--end of const--*/
function __CreateDownloadToolbar()
{   
   var w="252px";
   var h = "246px";

//   if (window.navigator.userAgent.indexOf("MSIE") > 0) {

//       if (typeof downloadButtonType == "undefined") {
//           h = "245px"; 
//           
//       }
//       else
//       {
//           h = "260px"; 
//           
//       }
   //   }
//   if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {

//   }

   var dbType;
   if (typeof downloadButtonType == "undefined") {
       dbType = "";
   }
   else {
       dbType = 1;
   }

   //Check if strip-branding is needed
   var isBrandingStrip;
   if (typeof brandingstrip == "undefined") {
       isBrandingStrip = 'false';
   } else {
   isBrandingStrip = brandingstrip;
   }


    var strCulture = "";
   
    if (typeof downloadButtonBannerCulture == 'string')
    {
        strCulture  = downloadButtonBannerCulture;
    }


    if (typeof marketingchannelname == "undefined") {
        if (typeof setup == "undefined") //support for old banners
        {
            if (typeof (downloadUrl) != 'undefined' && downloadUrl != null)
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + downloadUrl + "Banners/Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&brandingstrip=" + isBrandingStrip + "'></iframe>");
            else
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + get_clientBaseUrl() + "Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&ctId=" + ctId + "&brandingstrip=" + isBrandingStrip + "'></iframe>");
        } //new banners with setup enabled
        else {
            if (typeof (downloadUrl) != 'undefined' && downloadUrl != null)
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + downloadUrl + "Banners/Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&setup=" + setup + "&brandingstrip=" + isBrandingStrip +  "'></iframe>");
            else
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + get_clientBaseUrl() + "Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&ctId=" + ctId + "&setup=" + setup + "&brandingstrip=" + isBrandingStrip +  "'></iframe>");
        }
    }
    else {
        if (typeof setup == "undefined") //support for old banners
        {
            if (typeof (downloadUrl) != 'undefined' && downloadUrl != null)
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + downloadUrl + "Banners/Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&brandingstrip=" + isBrandingStrip + "marketingchannelname=" + marketingchannelname +  "'></iframe>");
            else
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + get_clientBaseUrl() + "Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&ctId=" + ctId + "&brandingstrip=" + isBrandingStrip + "marketingchannelname=" + marketingchannelname +  "'></iframe>");
        } //new banners with setup enabled
        else {
            if (typeof (downloadUrl) != 'undefined' && downloadUrl != null)
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + downloadUrl + "Banners/Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&setup=" + setup + "&brandingstrip=" + isBrandingStrip + "marketingchannelname=" + marketingchannelname +  "'></iframe>");
            else
                document.write("<iframe style='width:" + w + ";height:" + h + ";' frameborder=\"0\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" src='" + get_clientBaseUrl() + "Download/?culture=" + strCulture + "&downloadButtonType=" + dbType + "&ctId=" + ctId + "&setup=" + setup + "&brandingstrip=" + isBrandingStrip + "marketingchannelname=" + marketingchannelname +  "'></iframe>");
        }
    }
   
    
   //log the banner
   if (LOG_ENABLED)
       var req = new LogScriptRequest(LOG_SITE_URL + logUsage(strCulture));
};

function get_clientBaseUrl()
{
    if (clientBaseUrl == 'http://hosting.conduit.com/' || typeof(clientBaseUrl)=='undefined' || clientBaseUrl==null)
        return BANNER_BASE_URL;
    return clientBaseUrl;
};
//------Log section------------//
String.format = function(text) {

    if (arguments.length <= 1) return text;
    var tokenCount = arguments.length - 2;
    for (var token = 0; token <= tokenCount; token++)
        text = text.replace(new RegExp("\\{" + token + "\\}", "gi"),
                                                    arguments[token + 1]);
    return text;
};
function LogScriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl;
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Create the script tag
    this.scriptObj = document.createElement("script");

    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl);
    this.scriptObj.setAttribute("id", this.scriptId);
    //add the Script tag
    this.headLoc.appendChild(this.scriptObj);
};

function GetIsSetup() {
    if (typeof setup == "undefined")
        return 'true';
    return setup;
};

function logUsage(strCulture) {
    try {
        if (typeof marketingchannelname == "undefined") {
            marketingchannelname = '';
        }
        var req = String.format('/?logType=impression&ctid={0}&bannertypeid={1}&bannerName={2}&bannerculture={3}&setup={4}&marketingchannelname={5}', ctId, 6, "Download_button", strCulture, GetIsSetup(), marketingchannelname);
        return req;
    }
    catch (e) {}
};

