Guest User

Untitled

a guest
Jan 13th, 2016
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://www.linkbucks.com/scripts/intermissionLink.v3.js
  2. (function () {
  3.  
  4.   if (!window.JSON) {
  5.     window.JSON = {
  6.       parse : function (sJson) {
  7.         return eval("(" + sJson + ")");
  8.       }
  9.     };
  10.   }
  11.  
  12.   var browser = function () {
  13.     var n = navigator.userAgent.toLowerCase();
  14.     var b = {
  15.       webkit : /webkit/.test(n),
  16.       mozilla : (/mozilla/.test(n)) && (!/(compatible|webkit|trident)/.test(n)),
  17.       chrome : /chrome/.test(n) && !(/edge/.test(n)),
  18.       msie : (/msie/.test(n) || /trident/.test(n)) && (!/opera/.test(n)) && !(/edge/.test(n)),
  19.       edge : /edge/.test(n),
  20.       firefox : /firefox/.test(n) && !(/edge/.test(n)),
  21.       safari : (/safari/.test(n) && !(/chrome/.test(n)) && !(/edge/.test(n))),
  22.       opera : /opera/.test(n)
  23.     };
  24.     b.version = (b.safari) ? (n.match(/.+(?:ri)[\/: ]([\d.]+)/) || [])[1] : (n.match(/.+(?:ox|me|ra|ie|rv)[\/: ]([\d.]+)/) || [])[1];
  25.     try {
  26.       b.majorVersion = b.version.split('.')[0];
  27.     } catch (e) {
  28.       b.majorVersion = null;
  29.     }
  30.  
  31.     b.getXmlHttp = function () {
  32.       var xmlhttp;
  33.       try {
  34.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  35.       } catch (e) {
  36.         try {
  37.           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  38.         } catch (e) {
  39.           xmlhttp = false;
  40.         }
  41.       }
  42.       if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  43.         xmlhttp = new XMLHttpRequest();
  44.       }
  45.       return xmlhttp;
  46.     };
  47.  
  48.     return b;
  49.   }
  50.   ();
  51.  
  52.   // IE trim function fix
  53.   if (typeof String.prototype.trim !== 'function') {
  54.     String.prototype.trim = function () {
  55.       return this.replace(/^\s+|\s+$/g, '');
  56.     };
  57.   }
  58.  
  59.   var cookies = new(function () {
  60.       this.set = function (value) {
  61.         document.cookie = value;
  62.       };
  63.  
  64.       this.get = function (key) {
  65.         var keyValuePairs = document.cookie.split(';');
  66.         for (var i = 0; i < keyValuePairs.length; i++) {
  67.           var keyValuePair = keyValuePairs[i].trim();
  68.           if (keyValuePair.length == 0) {
  69.             continue;
  70.           }
  71.  
  72.           var keyValueArray = keyValuePair.split('=');
  73.           if (keyValueArray.length != 2) {
  74.             continue;
  75.           }
  76.  
  77.           if (keyValueArray[0] == key) {
  78.             return keyValueArray[1];
  79.           }
  80.         }
  81.  
  82.         return null;
  83.       };
  84.     })();
  85.  
  86.   var events = new(function () {
  87.       this.attach = function (name, handler) {
  88.         if (document.addEventListener) {
  89.           document.addEventListener(name, handler, false);
  90.         } else {
  91.           document.attachEvent("on" + name, handler);
  92.         }
  93.       };
  94.  
  95.       this.detach = function (name, handler) {
  96.         if (document.removeEventListener) {
  97.           document.removeEventListener(name, handler, false);
  98.         } else {
  99.           document.detachEvent("on" + name, handler);
  100.         }
  101.       };
  102.     })();
  103.  
  104.   // Important: keep in sync with full page script
  105.   var popUnder = function (url, options) {
  106.     var topWindow = (top != self && typeof(top.document.location.toString()) === 'string') ? top : self;
  107.     var windowConfig = 'toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=' + options.width.toString() + ',height=' + options.height.toString() + ',screenX=' + options.left.toString() + ',screenY=' + options.top.toString();
  108.  
  109.     var flashObj = null;
  110.     var useFlash = false;
  111.     if (browser.chrome == true && browser.majorVersion >= 35 && navigator.userAgent.toLowerCase().indexOf('mac os') == -1) {
  112.       var flashEnabled = typeof(navigator.mimeTypes["application/x-shockwave-flash"]) !== 'undefined';
  113.       if (flashEnabled && options.swfUrl) {
  114.         initFlashPop(options.swfUrl);
  115.         useFlash = true;
  116.       }
  117.     }
  118.  
  119.     this.open = function () {
  120.       if (options.callback) {
  121.         options.callback();
  122.       }
  123.  
  124.       if (useFlash) {
  125.         popViaFlash();
  126.         return;
  127.       }
  128.  
  129.       // Chrome 30 and above use tabs
  130.       if (browser.chrome == true && browser.majorVersion >= 30) {
  131.         openInBackgroundTab();
  132.         return;
  133.       }
  134.  
  135.       var popunder = topWindow.window.open(url, options.name, windowConfig);
  136.       if (popunder) {
  137.         try {
  138.           popunder.blur();
  139.           popunder.opener.window.focus();
  140.           window.self.window.focus();
  141.           window.focus();
  142.  
  143.           if (browser.firefox)
  144.             openCloseWindow();
  145.           if (browser.webkit && !browser.edge)
  146.             openCloseTab();
  147.           if (browser.msie || browser.edge) {
  148.             setTimeout(function () {
  149.               popunder.blur();
  150.               popunder.opener.window.focus();
  151.               window.self.window.focus();
  152.               window.focus();
  153.             }, 1000);
  154.           }
  155.         } catch (e) {}
  156.       }
  157.     }
  158.  
  159.     function openInBackgroundTab() {
  160.       var a = document.createElement("a");
  161.       a.href = url;
  162.       a.target = options.name;
  163.  
  164.       var evt = document.createEvent("MouseEvents");
  165.       // The tenth parameter of initMouseEvent sets ctrl key
  166.       evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
  167.       a.dispatchEvent(evt);
  168.     }
  169.  
  170.     function initFlashPop(swfUrl) {
  171.       flashObj = document.createElement("object");
  172.       flashObj.setAttribute("type", "application/x-shockwave-flash");
  173.       flashObj.setAttribute("id", "flash_pop");
  174.       flashObj.setAttribute("data", swfUrl);
  175.       flashObj.setAttribute("style", "position:fixed;visibility:visible;left:0;top:0;width:1px;height:1px;z-index:99999");
  176.  
  177.       var winTransParam = document.createElement("param");
  178.       winTransParam.setAttribute("name", "wmode");
  179.       winTransParam.setAttribute("value", "transparent");
  180.       flashObj.appendChild(winTransParam);
  181.  
  182.       var menuParam = document.createElement("param");
  183.       menuParam.setAttribute("name", "menu");
  184.       menuParam.setAttribute("value", "false");
  185.       flashObj.appendChild(menuParam);
  186.  
  187.       var accessParam = document.createElement("param");
  188.       accessParam.setAttribute("name", "allowscriptaccess");
  189.       accessParam.setAttribute("value", "always");
  190.       flashObj.appendChild(accessParam);
  191.  
  192.       var screenParam = document.createElement("param");
  193.       screenParam.setAttribute("name", "allowfullscreen");
  194.       screenParam.setAttribute("value", "true");
  195.       flashObj.appendChild(screenParam);
  196.  
  197.       document.body.insertBefore(flashObj, document.body.firstChild);
  198.       flashObj.focus();
  199.  
  200.       window['showPop'] = function () {
  201.         flashObj.style.width = "0px";
  202.         flashObj.style.height = "0px";
  203.         flashObj.style.visibility = "hidden";
  204.  
  205.         topWindow.window.open(url, options.name, windowConfig);
  206.       };
  207.     }
  208.  
  209.     function popViaFlash() {
  210.       flashObj.style.width = "100%";
  211.       flashObj.style.height = "100%";
  212.     }
  213.  
  214.     function openCloseWindow() {
  215.       var ghost = window.open('about:blank');
  216.       ghost.focus();
  217.       ghost.close();
  218.     }
  219.  
  220.     function openCloseTab() {
  221.       var nothing = '';
  222.       var ghost = document.createElement("a");
  223.       ghost.href = "data:text/html,<scr" + nothing + "ipt>window.close();</scr" + nothing + "ipt>";
  224.       document.getElementsByTagName("body")[0].appendChild(ghost);
  225.  
  226.       var clk = document.createEvent("MouseEvents");
  227.       clk.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
  228.       ghost.dispatchEvent(clk);
  229.  
  230.       ghost.parentNode.removeChild(ghost);
  231.     }
  232.   };
  233.  
  234.   function bindPopUnder(url, options) {
  235.     var pop = new popUnder(url, options);
  236.  
  237.     if (browser.chrome == true) {
  238.       // mousedown is used instead of click because it is a pre condition for chrome pop via flash
  239.       events.attach('mousedown', pop.open);
  240.     } else {
  241.       // click is needed for ie and firefox, otherwise pop up will be blocked
  242.       events.attach('click', pop.open);
  243.     }
  244.   }
  245.  
  246.   var Lbjs = {
  247.     IsMouse : false,
  248.     Flipped : false,
  249.     UrlEncoded : 0,
  250.     AdType : 0,
  251.     ContentType : 0,
  252.     Token : "",
  253.     Key : null,
  254.     AdUrl : "",
  255.     KeyUrl : "",
  256.     AdPop : false,
  257.     Preview : false,
  258.     AdPopUrl : "",
  259.     TargetUrl : "",
  260.     Countdown : 0,
  261.     Initialized : false,
  262.     UnloadTracked : false,
  263.     UserId : null,
  264.     AdBlockSpotted : false,
  265.     UnloadRequested : false,
  266.     SwfUrl : null,
  267.  
  268.     Init : function (num, params) {
  269.       this.Token = params.Token;
  270.       this.AuthKey = params.AuthKey;
  271.       this.UrlEncoded = params.UrlEncoded;
  272.       this.AdType = params.AdType;
  273.       this.ContentType = params.ContentType;
  274.       this.AdUrl = params.AdUrl;
  275.       this.Preview = params.Preview;
  276.       this.AdPopUrl = params.AdPopUrl;
  277.       this.KeyUrl = params.KeyUrl;
  278.       this.AdPop = params.AdPop;
  279.       this.TargetUrl = params.TargetUrl;
  280.       this.Countdown = params.Countdown;
  281.       this.UserId = params.UserId;
  282.       this.SwfUrl = params.SwfUrl;
  283.  
  284.       this.InitJsKey(num, this.Token);
  285.       this.Content();
  286.       this.Resize();
  287.  
  288.       // Restore url to normal if encoded
  289.       if (this.UrlEncoded == true) {
  290.         this.TargetUrl = this.Encode(this.ConvertFromHex(this.TargetUrl));
  291.       }
  292.  
  293.       if (this.Preview == false) {
  294.         this.Pop();
  295.       }
  296.  
  297.       if (this.Gate.Exists(this.TargetUrl)) {
  298.         this.TargetUrl = this.Gate.InsertGateKey(this.TargetUrl);
  299.       }
  300.  
  301.       document.onmouseover = Lbjs.MouseOverHandler;
  302.       window.onbeforeunload = this.UnloadHandler;
  303.  
  304.       document.getElementById('refLink').onclick = this.UnblockNavigation;
  305.       document.getElementById('advertise').onclick = this.UnblockNavigation;
  306.       document.getElementById('advertise2').onclick = this.UnblockNavigation;
  307.     },
  308.  
  309.     isOldFormatLinkRequest : function () {
  310.       // Link can be in two formats linkcode.domain.com or domain.com/linkcode. Check if link is of format linkcode.domain.com
  311.       var parts = window.location.hostname.split('.');
  312.       return parts.length > 2 && /[a-zA-Z0-9]{8}/.test(parts[0]);
  313.     },
  314.  
  315.     storePopOpened : function (cookieName) {
  316.       var cookiePath;
  317.       if (this.isOldFormatLinkRequest()) {
  318.         cookiePath = '/';
  319.       } else {
  320.         var locationParts = window.location.toString().split('//')[1].split('/');
  321.         var codeMatch = locationParts[1].match(/^([a-zA-Z0-9]{1,8})/g);
  322.         if (codeMatch.length > 0) {
  323.           cookiePath = '/' + codeMatch[0];
  324.         } else {
  325.           cookiePath = '/';
  326.         }
  327.       }
  328.  
  329.       var now = new Date();
  330.       var expires = new Date(now.getTime() + 24 * 60 * 60 * 1000);
  331.  
  332.       cookies.set(cookieName + '=1;expires=' + expires.toGMTString() + ';path=' + cookiePath);
  333.     },
  334.  
  335.     Pop : function () {
  336.       if (this.AdPop == false) {
  337.         return;
  338.       }
  339.  
  340.       var thisRef = this;
  341.       bindPopUnder(this.AdPopUrl, {
  342.         name : 'ad_' + Math.floor(89999999 * Math.random() + 10000000),
  343.         width : window.screen.availWidth,
  344.         height : window.screen.availHeight,
  345.         top : 0,
  346.         left : 0,
  347.         swfUrl : this.SwfUrl,
  348.         callback : function () {
  349.           var cookieName = "lb_popunder_" + thisRef.AdType + "_" + thisRef.ContentType;
  350.           thisRef.storePopOpened(cookieName);
  351.         }
  352.       });
  353.     },
  354.  
  355.     Util : {
  356.       getQueryParam : function (targetStr, name) {
  357.         var uriParts = targetStr.split('?');
  358.         if (uriParts.length != 2) {
  359.           return null;
  360.         }
  361.  
  362.         var queryString = uriParts[1];
  363.  
  364.         var query = (function (keyValuePairs) {
  365.           if (keyValuePairs == null || keyValuePairs.length == 0) {
  366.             return {};
  367.           }
  368.  
  369.           var result = {};
  370.           for (var i = 0; i < keyValuePairs.length; ++i) {
  371.             var keyValue = keyValuePairs[i].split('=');
  372.             if (keyValue.length != 2)
  373.               continue;
  374.             result[keyValue[0]] = decodeURIComponent(keyValue[1].replace(/\+/g, " "));
  375.           }
  376.           return result;
  377.         })(queryString.split('&'));
  378.  
  379.         return query[name] || null;
  380.       },
  381.  
  382.       replaceQueryParam : function (targetStr, name, value) {
  383.         var paramStart = targetStr.indexOf('&' + name + '=');
  384.         if (paramStart == -1) {
  385.           paramStart = targetStr.indexOf('?' + name + '=');
  386.         }
  387.         if (paramStart == -1) {
  388.           throw 'Parameter not found';
  389.         }
  390.  
  391.         var paramEnd = targetStr.indexOf('&', paramStart + 1);
  392.         var paramValueStart = targetStr.indexOf('=', paramStart);
  393.  
  394.         var result = targetStr.substr(0, paramValueStart) + '=' + value;
  395.         if (paramEnd != -1) {
  396.           result += targetStr.substr(paramEnd, targetStr.length - paramEnd);
  397.         }
  398.         return result;
  399.       },
  400.  
  401.       frameLoadedAndVisible : function (element, srcPattern) {
  402.         if (element == null || element.tagName.toLowerCase() !== 'iframe') {
  403.           return false;
  404.         }
  405.  
  406.         var currentElement = element;
  407.         while (currentElement != null && currentElement !== document.body) {
  408.           if (currentElement.style.visibility === 'hidden' && currentElement.style.display === 'none') {
  409.             return false;
  410.           }
  411.  
  412.           currentElement = currentElement.parentNode;
  413.         }
  414.  
  415.         if (element.clientHeight <= 0 || element.clientWidth <= 0) {
  416.           return false;
  417.         }
  418.  
  419.         if (element.src == null || element.src != srcPattern) {
  420.           return false;
  421.         }
  422.  
  423.         if (window.getComputedStyle) {
  424.           var style = window.getComputedStyle(element, null);
  425.           if (style && style.getPropertyValue && style.getPropertyValue('display') == 'none') {
  426.             return false;
  427.           }
  428.         } else if (element.offsetWidth == 0) {
  429.           return false;
  430.         }
  431.  
  432.         return true;
  433.       }
  434.     },
  435.  
  436.     Gate : {
  437.       Exists : function (url) {
  438.         var gate = Lbjs.Util.getQueryParam(url, "_lbGate");
  439.         return gate != null && /^[0-9]{6}$/.test(gate);
  440.       },
  441.  
  442.       InsertGateKey : function (url) {
  443.         if (!this.Exists(url)) {
  444.           return url;
  445.         }
  446.  
  447.         var gate = Lbjs.Util.getQueryParam(url, "_lbGate");
  448.         return Lbjs.Util.replaceQueryParam(url, "_lbGate", this.CalculateGateCode(gate).toString());
  449.       },
  450.  
  451.       CalculateGateCode : function (gateId) {
  452.         var result = Lbjs.UserId;
  453.         var gateIdStr = gateId.toString();
  454.         for (var i = 0; i < gateIdStr.length; i++) {
  455.           var num = parseInt(gateIdStr.charAt(i));
  456.  
  457.           var navigatorLen = window.navigator.userAgent.length;
  458.  
  459.           num = num % (navigatorLen - 1);
  460.           result += num;
  461.           result += window.navigator.userAgent.charCodeAt(num);
  462.         }
  463.         return result;
  464.       }
  465.     },
  466.  
  467.     SetKey : function (key) {
  468.       this.Key = key;
  469.     },
  470.  
  471.     Timer : function () {
  472.       var timer = document.getElementById("timer");
  473.       var skipDisabled = document.getElementById("skip_disabled");
  474.  
  475.       timer.innerHTML = this.Countdown;
  476.  
  477.       if (--this.Countdown >= 0) {
  478.         setTimeout(function () {
  479.           Lbjs.Timer();
  480.         }, 1000);
  481.       } else {
  482.         if (this.TargetUrl == null || this.TargetUrl == '') {
  483.           if (!this.Util.frameLoadedAndVisible(document.getElementById('content'), this.AdUrl)) {
  484.             this.AdBlockSpotted = true;
  485.           } else {
  486.             this.LoadTargetUrl();
  487.           }
  488.         }
  489.  
  490.         this.Fader.FadeOut(timer, 500, null);
  491.         this.Fader.FadeOut(skipDisabled, 750, function () {
  492.           Lbjs.Skip();
  493.         });
  494.         this.OnTimerComplete();
  495.       }
  496.     },
  497.  
  498.     LoadTargetUrl : function () {
  499.       var request = browser.getXmlHttp();
  500.       var adBlock = typeof(window['__noAdBlock']) === "undefined" || window['__noAdBlock'] !== true;
  501.       request.open('GET', '/intermission/loadTargetUrl?t=' + this.Token + '&aK=' + this.AuthKey + '&a_b=' + adBlock, false);
  502.       request.send(null);
  503.  
  504.       if (request.status === 200) {
  505.         var response = JSON.parse(request.responseText);
  506.         if (response.Success == true) {
  507.           if (response.AdBlockSpotted == true) {
  508.             this.AdBlockSpotted = true;
  509.           } else {
  510.             this.TargetUrl = response.Url;
  511.           }
  512.         } else if (typeof(response.Errors) !== "undefined" && response.Errors.length > 0) {
  513.           this.TargetUrl = '';
  514.         }
  515.       }
  516.     },
  517.  
  518.     OnTimerComplete : function () {},
  519.  
  520.     MouseOverHandler : function () {
  521.       Lbjs.IsMouse = true;
  522.     },
  523.  
  524.     UnloadHandler : function () {
  525.       Lbjs.UnloadRequested = true;
  526.  
  527.       if (Lbjs.Key != null && Lbjs.UnloadTracked == false) {
  528.         Lbjs.Track(6);
  529.         Lbjs.UnloadTracked = true;
  530.       }
  531.  
  532.       return "You are going to be redirected away from the current page. Are you sure you want to continue?\n\nNote: To arrive at your intended destination, you must click to stay on the page and then click 'Skip Ad'";
  533.     },
  534.  
  535.     Resize : function () {
  536.  
  537.       var resizeWindow = false;
  538.       var minWindowWidth = 1024;
  539.       var minWindowHeight = 768;
  540.       var windowWidth = this.GetWindowWidth();
  541.       var windowHeight = this.GetWindowHeight();
  542.  
  543.       if (windowWidth < minWindowWidth) {
  544.         if (screen.width < minWindowWidth)
  545.           windowWidth = screen.width;
  546.         else
  547.           windowWidth = minWindowWidth;
  548.  
  549.         resizeWindow = true;
  550.       }
  551.  
  552.       if (windowHeight < minWindowHeight) {
  553.         if (screen.height < minWindowHeight)
  554.           windowHeight = screen.height;
  555.         else
  556.           windowHeight = minWindowHeight;
  557.  
  558.         resizeWindow = true;
  559.       }
  560.  
  561.       if (resizeWindow) {
  562.         window.resizeTo(windowWidth, windowHeight);
  563.         window.focus();
  564.       }
  565.     },
  566.  
  567.     Content : function () {
  568.  
  569.       var content = document.getElementById("content");
  570.       var parent = content.parentNode;
  571.  
  572.       parent.removeChild(content);
  573.       parent.appendChild(content);
  574.  
  575.       content.style.display = "";
  576.       content.src = this.AdUrl;
  577.     },
  578.  
  579.     UnblockNavigation : function () {
  580.       // In some browsers timer execution in iframe can overwrite window.top.location in the middle of redirect
  581.       // Code below prevents this
  582.       if (Lbjs.UnloadRequested == true) {
  583.         var content = document.getElementById("content");
  584.         var parent = content.parentNode;
  585.         parent.removeChild(content);
  586.       }
  587.  
  588.       window.onbeforeunload = null;
  589.     },
  590.  
  591.     Skip : function () {
  592.       var skip = document.getElementById("skiplink");
  593.       skip.style.display = "";
  594.       skip.href = '#';
  595.  
  596.       if (this.AdBlockSpotted) {
  597.         skip.onclick = function () {
  598.           alert('You are not allowed to access the destination web page until you view an advertisement. Please make sure that all Ad blocking software is turned off and refresh the page.');
  599.           return false;
  600.         };
  601.       } else if (this.TargetUrl == null || this.TargetUrl == '') {
  602.         skip.onclick = function () {
  603.           alert('There was an error obtaining a link to the destination web page, please refresh the page.');
  604.           return false;
  605.         };
  606.       } else {
  607.         skip.onclick = function (e) {
  608.           Lbjs.UnblockNavigation();
  609.  
  610.           // Sctrip script to avoid XSS
  611.           var url = Lbjs.TargetUrl;
  612.           while (url.indexOf('javascript:') != -1) {
  613.             url = url.replace(/javascript:/g, '');
  614.           }
  615.  
  616.           var evt = !e ? window.event : e;
  617.           var which = evt.which || evt.keyCode;
  618.           if (typeof which != 'undefined' && which != null) {
  619.             window.location.href = url;
  620.             // On safari mobile pop under prevents navigation if link is not set
  621.             skip.href = url;
  622.           }
  623.         };
  624.       }
  625.  
  626.       skip.onmousedown = function () {
  627.         Lbjs.Track(4);
  628.       };
  629.  
  630.       var height = screen.height;
  631.       var width = screen.width;
  632.       var browserHeight = document.documentElement.clientHeight || document.body.clientHeight;
  633.       var browserWidth = document.documentElement.clientWidth || document.body.clientWidth;
  634.       Lbjs.Track(1, "h=" + height + "&w=" + width + "&m=" + (Lbjs.IsMouse == true ? '1' : '0') + "&bh=" + browserHeight + "&bw=" + browserWidth);
  635.     },
  636.  
  637.     Track : function (type, params) {
  638.       var img = new Image();
  639.       var rnd = Math.random();
  640.  
  641.       var url = "/track/" + type + "/?t=" + this.Token + "&rnd=" + rnd + "&k=" + this.Key + (params ? '&' + params : '');
  642.  
  643.       img.src = url;
  644.     },
  645.  
  646.     TrackSync : function (type, params) {
  647.  
  648.       var rnd = Math.random();
  649.       var url = "/track/" + type + "/?t=" + this.Token + "&rnd=" + rnd + "&k=" + this.Key + (params ? '&' + params : '');
  650.  
  651.       var xmlhttp = browser.getXmlHttp();
  652.       xmlhttp.open('GET', url, false);
  653.       xmlhttp.send(null);
  654.     },
  655.  
  656.     AddScript : function (scriptUrl, scriptId) {
  657.  
  658.       var s1 = document.createElement("script");
  659.  
  660.       s1.type = "text/javascript";
  661.       s1.id = scriptId;
  662.       s1.async = true;
  663.       s1.src = scriptUrl;
  664.  
  665.       var s2 = document.getElementsByTagName("script")[0];
  666.       s2.parentNode.insertBefore(s1, s2);
  667.     },
  668.  
  669.     CreateScriptElement : function (url) {
  670.       var script = document.createElement("script");
  671.       script.setAttribute("type", "text/javascript");
  672.  
  673.       var rand = Math.floor(89999999 * Math.random() + 10000000);
  674.       script.src = (url.indexOf("?") > -1) ? url + "&" + rand : url + "?" + rand;
  675.  
  676.       return script;
  677.     },
  678.  
  679.     AddScriptWithCallback : function (scriptUrl, callback) {
  680.       var head = document.getElementsByTagName("head")[0];
  681.       var script = this.CreateScriptElement(scriptUrl);
  682.  
  683.       var done = false;
  684.       script.onload = script.onreadystatechange = function () {
  685.         // Some browser has support of both ways and some might fire loaded event more than once (e.g. Opera)
  686.         // So use done flag to prevent multiple callback calls
  687.         if (done == false && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
  688.           done = true;
  689.           script.onload = script.onreadystatechange = null;
  690.  
  691.           if (typeof callback == "function") {
  692.             callback();
  693.           }
  694.         }
  695.       };
  696.  
  697.       // Use insertBefore to prevent an IE6 bug.
  698.       head.insertBefore(script, head.firstChild);
  699.     },
  700.  
  701.     AddEvent : function (target, eventName, handlerName) {
  702.  
  703.       if (target.addEventListener) {
  704.         target.addEventListener(eventName, eval(handlerName), false);
  705.       } else if (target.attachEvent) {
  706.         target.attachEvent("on" + eventName, eval(handlerName));
  707.       } else {
  708.         var originalHandler = target["on" + eventName];
  709.         if (originalHandler) {
  710.           target["on" + eventName] = eval(handlerName);
  711.         } else {
  712.           target["on" + eventName] = eval(handlerName);
  713.         }
  714.       }
  715.     },
  716.  
  717.     Encode : function (str) {
  718.  
  719.       var s = [],
  720.       j = 0,
  721.       x,
  722.       res = '',
  723.       k = arguments.callee.toString().replace(/\s+/g, "");
  724.       for (var i = 0; i < 256; i++) {
  725.         s[i] = i;
  726.       }
  727.       for (i = 0; i < 256; i++) {
  728.         j = (j + s[i] + k.charCodeAt(i % k.length)) % 256;
  729.         x = s[i];
  730.         s[i] = s[j];
  731.         s[j] = x;
  732.       }
  733.       i = 0;
  734.       j = 0;
  735.       for (var y = 0; y < str.length; y++) {
  736.         i = (i + 1) % 256;
  737.         j = (j + s[i]) % 256;
  738.         x = s[i];
  739.         s[i] = s[j];
  740.         s[j] = x;
  741.         res += String.fromCharCode(str.charCodeAt(y)^s[(s[i] + s[j]) % 256]);
  742.       }
  743.       return res;
  744.     },
  745.  
  746.     ConvertFromHex : function (str) {
  747.  
  748.       var result = [];
  749.       while (str.length >= 2) {
  750.         result.push(String.fromCharCode(parseInt(str.substring(0, 2), 16)));
  751.         str = str.substring(2, str.length);
  752.       }
  753.  
  754.       return result.join("");
  755.     },
  756.  
  757.     GetWindowHeight : function () {
  758.       var myHeight = 0;
  759.  
  760.       if (typeof(window.innerHeight) == 'number') {
  761.         myHeight = window.innerHeight;
  762.       } else if (document.documentElement && document.documentElement.clientHeight) {
  763.         myHeight = document.documentElement.clientHeight;
  764.       } else if (document.body && document.body.clientHeight) {
  765.         myHeight = document.body.clientHeight;
  766.       }
  767.  
  768.       return myHeight;
  769.  
  770.     },
  771.  
  772.     GetWindowWidth : function () {
  773.       var myWidth = 0;
  774.  
  775.       if (typeof(window.innerWidth) == 'number') {
  776.         myWidth = window.innerWidth;
  777.       } else if (document.documentElement && document.documentElement.clientWidth) {
  778.         myWidth = document.documentElement.clientWidth;
  779.       } else if (document.body && document.body.clientWidth) {
  780.         myWidth = document.body.clientWidth;
  781.       }
  782.  
  783.       return myWidth;
  784.     },
  785.  
  786.     SetStyle : function (element, text) {
  787.       element.setAttribute("style", text);
  788.       element.style.cssText = text;
  789.     },
  790.  
  791.     Fader : {
  792.       FadeOut : function (element, duration, callback) {
  793.  
  794.         var params = {
  795.           State : 0,
  796.           Element : element,
  797.           Duration : duration,
  798.           Callback : callback,
  799.           Remaining : 0,
  800.           LastTick : 0
  801.         };
  802.  
  803.         this.Init(params);
  804.         this.Animate(params);
  805.       },
  806.  
  807.       FadeIn : function (element, duration, callback) {
  808.  
  809.         var params = {
  810.           State : 1,
  811.           Element : element,
  812.           Duration : duration,
  813.           Callback : callback,
  814.           Remaining : 0,
  815.           LastTick : 0
  816.         };
  817.  
  818.         this.Init(params);
  819.         this.Animate(params);
  820.       },
  821.  
  822.       Init : function (params) {
  823.  
  824.         var display = params.Element.style.display;
  825.  
  826.         if (display === "inline") {
  827.           params.Element.style.display = "inline-block";
  828.         } else {
  829.           params.Element.style.display = "inline";
  830.           params.Element.style.zoom = 1;
  831.         }
  832.  
  833.         params.Remaining = params.Duration;
  834.         params.LastTick = new Date().getTime();
  835.       },
  836.  
  837.       Animate : function (params) {
  838.  
  839.         var newTick = new Date().getTime();
  840.         var scope = this;
  841.         var opacity;
  842.  
  843.         params.Remaining -= newTick - params.LastTick;
  844.         opacity = params.Remaining / params.Duration;
  845.         opacity = (params.State == 0) ? opacity : (1 - opacity);
  846.  
  847.         var setOpacity = function (opacity) {
  848.           params.Element.style.opacity = opacity;
  849.           params.Element.style.filter = 'alpha(opacity = ' + (opacity * 100) + ')';
  850.         };
  851.  
  852.         if (params.Remaining <= 0) {
  853.  
  854.           if (params.State == 0) {
  855.             opacity = 0;
  856.             params.Element.style.display = "none";
  857.           } else {
  858.             opacity = 1;
  859.             params.Element.style.display = "";
  860.           }
  861.  
  862.           setOpacity(opacity);
  863.  
  864.           if (typeof params.Callback == "function")
  865.             params.Callback();
  866.  
  867.           return;
  868.         } else {
  869.           setOpacity(opacity);
  870.         }
  871.  
  872.         params.LastTick = new Date().getTime();
  873.         setTimeout(function () {
  874.           scope.Animate(params);
  875.         }, 50);
  876.       }
  877.     },
  878.  
  879.     InitJsKey : function (num, token) {
  880.       window['_sK' + num] = function (v) {
  881.         Lbjs.SetKey(v);
  882.       };
  883.       var thisRef = this;
  884.       var onLoad = this.AdType == 2 ? function () {
  885.         thisRef.Timer();
  886.       }
  887.        : null;
  888.       this.AddScriptWithCallback(this.KeyUrl, onLoad);
  889.     }
  890.   };
  891.  
  892.   window.initLbjs = function (authKey, params) {
  893.     if (typeof(authKey) !== "string") {
  894.       return;
  895.     }
  896.  
  897.     Lbjs.Init(authKey, params);
  898.   };
  899. })();
Add Comment
Please, Sign In to add comment