﻿function wbnMyEscape(s) { return escape(s.replace(/&#8242;|&#039;/g, "'")); }
function wbnPush(arr, val, def, doEscape)
{
  if (eval("typeof("+arr+") == 'undefined'")) 
    arr = new Array();
  else
    arr = eval(arr);
  arr.push(eval("typeof("+val+") == 'undefined'") ? def : (typeof(doEscape) != "undefined" && doEscape ? wbnMyEscape(eval(val)) : eval(val)));
  return arr;
}

wbnHost = typeof (wbnHost) == "undefined" || wbnHost.indexOf("xywidgets.com") > -1 ? (location.hostname == "localhost" ? "" : "http://www.uplication.com/") : wbnHost;
upStatsHost = location.hostname == "localhost" ? "http://localhost/up_stats/" : (wbnHost.indexOf("si-sv3109.com") > -1 ? "http://upstats.si-sv3109.com/" : "http://ustats.uplication.com/");
wbnAutoPlay = typeof(wbnAutoPlay)=="undefined"?0:wbnAutoPlay;
_wbnWidgetType = wbnPush("_wbnWidgetType", "wbnWidgetType", 11); 
_wbnShowBg = wbnPush("_wbnShowBg", "wbnShowBg", 1); 
_wbnMaterialId = wbnPush("_wbnMaterialId", "wbnMaterialId", 0);
_wbnMaterialStatus = wbnPush("_wbnMaterialStatus", "wbnMaterialStatus", "get");
_wbnSNA = wbnPush("_wbnSNA", "wbnSNA", 0);
_wbnSN = wbnPush("_wbnSN", "wbnSN", 0);
_wbnSM = wbnPush("_wbnSM", "wbnSM", 1);
_wbnNoAds = wbnPush("_wbnNoAds", "wbnNoAds", 0); 
_wbnReferralId = wbnPush("_wbnReferralId", "wbnReferralId", -1); 
_wbnWebsiteId = wbnPush("_wbnWebsiteId", "wbnWebsiteId", -1); 
_wbnWebsiteMaterialId = wbnPush("_wbnWebsiteMaterialId", "wbnWebsiteMaterialId", 0); 
_wbnCategoryId = wbnPush("_wbnCategoryId", "wbnCategoryId", 0); 
_wbnDir = wbnPush("_wbnDir", "wbnDir", "ltr"); 
_wbnLink = wbnPush("_wbnLink", "wbnLink", ""); 
_wbnTitle = wbnPush("_wbnTitle", "wbnTitle", "", true); 
_wbnPosition = wbnPush("_wbnPosition", "wbnPosition", ""); 
_wbnLeft = wbnPush("_wbnLeft", "wbnLeft", ""); 
_wbnTop = wbnPush("_wbnTop", "wbnTop", ""); 
wbnHidden = typeof(wbnHidden)=="undefined"?0:wbnHidden;
wbnShowBanner = typeof(wbnShowBanner)=="undefined"?0:wbnShowBanner;
wbnCoverImageUrl = typeof(wbnCoverImageUrl)=="undefined"?null:wbnCoverImageUrl;
wbnPlaceHolderDivId = typeof(wbnPlaceHolderDivId)=="undefined"?null:wbnPlaceHolderDivId;
wbnBannerPlaceHolderDivId = typeof(wbnBannerPlaceHolderDivId)=="undefined"?null:wbnBannerPlaceHolderDivId;
wbnBannerAfterPlayer = typeof(wbnBannerAfterPlayer)=="undefined"?0:wbnBannerAfterPlayer;

function wbnGetNextIndex()
{
  var i=0;
  while (document.getElementById("ifrwbnwidget"+i)) i++;
  return i;
}

function wbnWidth(index)
{
  switch(_wbnWidgetType[index])
  {
    case 110 : 
    case 111 : return "140px";
    case 112 : return "142px";
    case 11000000 : return "127px";
    case 11000003 :
    case 11000004 : 
    case 11000005 : return "426px";
    case 11000006: return "426px";
    case 11000007: return "423px";
    case 11000008: return "423px";
    default : return "248px"; // 11
  }
}

function wbnHeight(index)
{
  switch(_wbnWidgetType[index])
  {
    case 110 : 
    case 111 : 
    case 112 : return "24px";
    case 11000000 : return "147px";
    case 11000003 : return "83px";
    case 11000004 : 
    case 11000005 : return "28px";
    case 11000006: return "28px";
    case 11000007: return "26px";
    case 11000008: return "26px";
    default : return "36px"; // 11
  }
}
function wbnBannerWidth(index)
{
  switch(_wbnWidgetType[index])
  {
    case 11000000 : 
    case 11000001 : return "120px";
    case 11000005 : return "468px";
    case 11000006: return "468px";
    case 11000007: return "300px";
    case 11000008: return "468px";
    default : return "0px"; 
  }
}

function wbnBannerHeight(index)
{
  switch(_wbnWidgetType[index])
  {
    case 11000000 : 
    case 11000001 : return "100px";
    case 11000005 : return "60px";
    case 11000006: return "60px";
    case 11000007: return "100px";
    case 11000008: return "60px";
    default : return "0px"; // 11
  }
}

function wbnAlwaysShowBanner(index)
{
  switch(_wbnWidgetType[index])
  {
    case 11000006: return true;
    default : return false; 
  }
}

function wbnCreateSponsor(index)
{
  switch(_wbnWebsiteId[index])
  {
    /*
      case 1172116: return '<a href="'+wbnHost+'PreLaunch.aspx?u='+'http://www.dodaq.com/?utm_source=IDEX%2BOnline&utm_medium=Banner%2Bon%2BNewsroom&utm_campaign=Idex%2BNews%2BBanner&at=1&wb=1172116&i=7650529" target="_blank"><img src="'+
                wbnHost+'images/wbn/idex/player11beforeSponsor.png" alt="" style="border:0px;" /></a>';
    */
      case 746760: return '<a href="'+wbnHost+'PreLaunch.aspx?u='+'http://www.20off.co.il&at=1&wb=746760&i=9949395" target="_blank"><img src="'+
                wbnHost+'images/wbn/ynet/player11beforeSponsor.jpg" alt="" style="border:0px;" /></a>';
      default: return 'Advertise here&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    //default: return '';
  }
}
function wbnCreateCoverImage(index)
{
  return wbnCoverImageUrl ? '<table id="wbnwidgetcoverimage'+index+'" cellpadding="0" cellspacing="0" '+
      'style="width:'+wbnWidth(index)+'; height:'+wbnHeight(index)+'; '+(_wbnMaterialStatus[index] != 'on' ? 'display:none;' : '')+'">'+
    '<tr><td align="'+(_wbnDir[index]=="ltr"?"right":"left")+'" valign="middle" onclick="wbnOpenPlayer(document.getElementById(\'wbnwidgetcoverimage'+index+'\'), '+index+');" '+
      'style="background-image:url('+wbnHost+wbnCoverImageUrl+'); background-repeat:no-repeat; cursor:pointer; font-family:Arial; '+
      (_wbnPosition[index]!=""&&_wbnTop[index]!=""&&_wbnLeft[index]!="" ? 'position:'+_wbnPosition[index]+'; top:'+_wbnTop[index]+'; left:'+_wbnLeft[index]+'; ' : '')+      
      '">'+
      wbnCreateSponsor(index)+
    '</td></tr></table>': '';
}
function wbnCreatePlayerIframe(index)
{
  return '<iframe id="ifrwbnwidget'+index+'" '+(document.all?'allowtransparency="true" ':'')+
        (wbnHidden == 1 || wbnCoverImageUrl ? 'src="about:blank" player' : '')+
        'src="'+wbnHost+'PreLaunchWidget.aspx?'+
            'mid='+_wbnMaterialId[index]+'&bm=noBanner'+
            '&sbg='+_wbnShowBg[index]+'&sna='+_wbnSNA[index]+
            '&sn='+_wbnSN[index]+'&wb='+_wbnWebsiteId[index]+
            '&ap='+(wbnAutoPlay||wbnCoverImageUrl?"1":"0")+'&na='+_wbnNoAds[index]+
            //'&na='+(_wbnWebsiteId[index]==1172116?"1":_wbnNoAds[index])+
            '&sm='+_wbnSM[index]+
            '&r='+_wbnReferralId[index]+'&dir='+_wbnDir[index]+
            '&webid='+_wbnWebsiteId[index]+'&wmid='+_wbnWebsiteMaterialId[index]+
            '&wt=' + _wbnWidgetType[index] + '&wcid=' + _wbnCategoryId[index] + "&url=" + encodeURIComponent(document.location.href) +
            '&lnk='+encodeURIComponent(_wbnLink[index])+'&ttl='+_wbnTitle[index]+'" '+
        'width="'+wbnWidth(index)+'" height="'+wbnHeight(index)+'" scrolling="no" '+
        'style="height:'+wbnHeight(index)+'; '+
            'width:'+wbnWidth(index)+'; '+
            (_wbnMaterialStatus[index] != 'on' || wbnHidden == 1 || wbnCoverImageUrl ? 'display:none;' : '') +
            'border:none; margin:0px; padding:0px; '+
            (_wbnPosition[index]!=""&&_wbnTop[index]!=""&&_wbnLeft[index]!="" ? 'position:'+_wbnPosition[index]+'; top:'+_wbnTop[index]+'; left:'+_wbnLeft[index]+'; ' : '')+
            '" '+
        'frameborder="0"></iframe>';
}
function wbnCreateBannerIframe(index)
{
  return wbnShowBanner!=1 ? '': '<br/>'+
        '<iframe id="ifrWBNWidgetBanner'+index+'" '+(document.all?'allowtransparency="true" ':'')+
        ' src="about:blank" bannersrc="'+wbnHost+'PreLaunchWidget.aspx?'+
            'ci=0&css=body&bm=onlyBanner'+
            '&webid='+_wbnWebsiteId[index]+'&wmid='+_wbnWebsiteMaterialId[index]+
            '&wcid='+_wbnCategoryId[index]+'&wb='+_wbnWebsiteId[index]+
            '&wt='+_wbnWidgetType[index]+'" '+
        'width="'+wbnBannerWidth(index)+'" height="'+wbnBannerHeight(index)+'" scrolling="no" '+
        'style="height:'+wbnBannerHeight(index)+'px; width:'+wbnBannerWidth(index)+'px; '+
                'display:none; border:none; margin:0px; padding:0px; '+
                (_wbnPosition[index]!=""&&_wbnTop[index]!=""&&_wbnLeft[index]!="" ? 'position:'+_wbnPosition[index]+'; top:'+_wbnTop[index]+'; left:'+_wbnLeft[index]+'; ' : '')+      
                '" '+
        'frameborder="0"></iframe>';
}
function wbnCreateView() {
  var s = "<script type='text/javascript' " +
  "src='" + upStatsHost + "default.aspx?m=view&wt=" + _wbnWidgetType[wbnIndex] + "&webid=" + _wbnWebsiteId[wbnIndex] + "'" +
  "></script>";  
  return s;
}
function wbnInsertView() {
  var s = wbnCreateView();
  document.write(s);
}
function wbnCreate(index) {
  if (_wbnMaterialStatus[index] == "get" && _wbnWebsiteId[index] != "1172116" && _wbnWebsiteId[index] != "269016") {
      document.write("<script type='text/javascript' src='" + wbnHost +
      "PreMaterialStatus.aspx?swid=" + (wbnCoverImageUrl ? "wbnwidgetcoverimage" : "ifrwbnwidget") + index + '&bi=' + index +
    '&webid=' + _wbnWebsiteId[index] + '&wmid=' + _wbnWebsiteMaterialId[index] + 
    '&wcid=' + _wbnCategoryId[index] + '&wt='+_wbnWidgetType[index] +
    '&mid=' + _wbnMaterialId[index] + '&lnk=' + encodeURIComponent(_wbnLink[index]) + 
    '&ttl=' + _wbnTitle[index] + '&url='+encodeURIComponent(document.location.href) + "'></script>");
  }
  else if (_wbnMaterialStatus[index] == "on") {
  // insert player view here
  }
  wbnInsertView();
  return wbnCreateCoverImage(index) + wbnCreatePlayerIframe(index) + wbnCreateBannerIframe(index);
}

function wbnOpenPlayer(coverImg, index)
{
  index = typeof(index) == "undefined" ? 0 : index;
  coverImg = typeof(coverImg) == "undefined" ? null : coverImg;
  if (coverImg) coverImg.style.display = "none";
  var ifrWidget = document.getElementById("ifrwbnwidget"+index);
  
  if (ifrWidget.src == "about:blank" && ifrWidget.getAttribute("playersrc")) 
  {
    ifrWidget.src = ifrWidget.getAttribute("playersrc");
    if (wbnShowBanner == 1 && wbnBannerAfterPlayer == 1)
    {
      if (document.all) ifrWidget.attachEvent("onload", new Function("{wbnOpenBanner("+index+");}"));
      else ifrWidget.addEventListener("load", new Function("{wbnOpenBanner("+index+");}"), false);
    }
  }
  else if (ifrWidget.src != "about:blank" && ifrWidget.src != "" && wbnShowBanner == 1) wbnOpenBanner(index); 
  ifrWidget.style.display = "";
}

function wbnOpenBanner(index, specificCampaignId)
{
  if (wbnBannerPlaceHolderDivId)
  {
    document.getElementById(wbnBannerPlaceHolderDivId).style.display = "";
  }
  else
  {
    var ifrBanner = document.getElementById("ifrWBNWidgetBanner"+index);
    if (!ifrBanner)
    {
      setTimeout("wbnOpenBanner("+index+","+specificCampaignId+")", 100);
      return;
    }
    ifrBanner.src = typeof(specificCampaignId) != "undefined" ? wbnReplaceArg(ifrBanner.getAttribute("bannersrc"), "scid", specificCampaignId) : ifrBanner.getAttribute("bannersrc");
    ifrBanner.style.display = "";
  }
}

function wbnLoadMaterial(mid, ap)
{
  if (!document.getElementById("ifrWBNWidget0"))
  {
    alert("No BNarrator player found. Please embed at least one.");
    return;
  }
  var src = document.getElementById("ifrWBNWidget0").src;
  src = wbnReplaceArg(src, "mid", mid);
  src = wbnReplaceArg(src, "ap", typeof(ap)=="undefined"?"1":ap);
  document.getElementById("ifrWBNWidget0").src = src;    
}

function wbnReplaceArg(url, arg, value)
{
  var p = url.indexOf(arg + "=");
  if (p == -1)
    return url + (url.indexOf("?")>-1?"&":"?") + arg + "=" + value;
    
  var q = url.indexOf("&", p);
  if (q == -1)
    return url.substr(0, p) + arg + "=" + value;
  
  return url.substr(0, p) + arg + "=" + value + url.substr(q);
}

var wbnIndex = wbnGetNextIndex();
if (wbnPlaceHolderDivId)
  document.getElementById(wbnPlaceHolderDivId).innerHTML = wbnCreate(wbnIndex);
else
  document.write(wbnCreate(wbnIndex));    

