Guest User

Untitled

a guest
Oct 9th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bmi_htmlEdit = 0;
  2. var bmi_ie;
  3. var bmi_ns;
  4. var bmi_safari;
  5. var bmi_imageObjSelected;
  6. var bmi_ffx_op_toolTip = "Shift+R improves the quality of this image. Shift+A improves the quality of all images on this page.";
  7. var bmi_toolTip = "Shift+R improves the quality of this image. CTRL+F5 reloads the whole page.";
  8. var bmi_ns_tooltip = "Shift+Reload reloads the whole page.";
  9. var bmi_toolTipSeperator = " ... ";
  10. var bmi_concatStr = "bmi_orig_img";
  11. var bmi_frameNotAllowed;
  12. var agt = navigator.userAgent.toLowerCase();
  13. var is_major = parseInt(navigator.appVersion);
  14. var is_minor = parseFloat(navigator.appVersion);
  15. var bmi_ns = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1) && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
  16. var bmi_ns2 = (bmi_ns && (is_major == 2));
  17. var bmi_ns3 = (bmi_ns && (is_major == 3));
  18. var bmi_ns4 = (bmi_ns && (is_major == 4));
  19. var bmi_ns4up = (bmi_ns && (is_major >= 4));
  20. var bmi_nsonly = (bmi_ns && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1) || (agt.indexOf("Netscape") != -1) || (agt.indexOf("netscape") != -1)));
  21. var bmi_ns6 = (bmi_ns && (is_major == 5));
  22. var bmi_ns6up = (bmi_ns && (is_major >= 5));
  23. var is_gecko = (agt.indexOf('gecko') != -1);
  24. var bmi_firefox = (agt.indexOf('firefox') != -1);
  25. var bmi_safari = (agt.indexOf('applewebkit') != -1);
  26. var bmi_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  27. var bmi_ie3 = (bmi_ie && (is_major < 4));
  28. var bmi_ie4 = (bmi_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1));
  29. var bmi_ie4up = (bmi_ie && (is_major >= 4));
  30. var bmi_ie5 = (bmi_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1));
  31. var bmi_ie5_5 = (bmi_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
  32. var bmi_ie5up = (bmi_ie && !bmi_ie3 && !bmi_ie4);
  33. var bmi_ie5_5up = (bmi_ie && !bmi_ie3 && !bmi_ie4 && !bmi_ie5);
  34. var bmi_ie6 = (bmi_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1));
  35. var bmi_ie6up = (bmi_ie && !bmi_ie3 && !bmi_ie4 && !bmi_ie5 && !bmi_ie5_5);
  36. var bmi_opera = (agt.indexOf("opera") != -1);
  37. var bmi_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
  38. var bmi_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
  39. var bmi_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
  40. var bmi_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
  41. var bmi_opera5up = (bmi_opera && !bmi_opera2 && !bmi_opera3 && !bmi_opera4);
  42.  
  43. function bmi_checkAccess(win) {
  44.     bmi_frameNotAllowed = 0;
  45.     window.bmioldOnError = window.onerror;
  46.     window.onerror = null;
  47.     try {
  48.         var l = win.location.href;
  49.     } catch (e) {
  50.         bmi_frameNotAllowed = 1;
  51.     }
  52.     if (bmi_frameNotAllowed == 1) {
  53.         window.onerror = window.bmioldOnError;
  54.         return false;
  55.     } else {
  56.         window.onerror = window.bmioldOnError;
  57.         return true;
  58.     }
  59. }
  60.  
  61. function bmi_ImageElement(el) {
  62.     if (!el) return 0;
  63.     var str = new String(el.tagName);
  64.     if (str.match("IMG")) {
  65.         return 1;
  66.     }
  67.     if (str.match("INPUT")) {
  68.         if (el.type && bmi_checkInputType(el.type)) {
  69.             return 1;
  70.         }
  71.         return 0;
  72.     }
  73.     if (str.match("OBJECT")) {
  74.         if (el.type && bmi_checkMIMEType(el.type)) {
  75.             el.bmi_objTag = 1;
  76.             return 1;
  77.         }
  78.     }
  79.     if (str.match("EMBED")) {
  80.         if (el.type && bmi_checkMIMEType(el.type)) {
  81.             return 1;
  82.         }
  83.     }
  84.     if (str.match("AREA") || str.match("A")) {
  85.         var p = el.parentNode;
  86.         if (p && (p.tagName == "MAP") && (p.bmi_imgObj != null)) {
  87.             el.bmi_mapImage = p.bmi_imgObj;
  88.             p.bmi_imgObj.bmi_areaEl = el;
  89.             return 1;
  90.         }
  91.     }
  92.     return 0;
  93. }
  94.  
  95. function bmi_resetTitle(el) {
  96.     if (!el) return;
  97.     if (el.bmi_touched != 1) return;
  98.     el.title = "";
  99.     if (el.bmi_oldTitle) {
  100.         el.title = el.bmi_oldTitle;
  101.         if (el.bmi_oldAlt) {
  102.             el.alt = el.bmi_oldAlt;
  103.         }
  104.     } else if (el.bmi_oldAlt) {
  105.         el.alt = el.bmi_oldAlt;
  106.         if (bmi_ie) el.title = el.alt;
  107.     }
  108.     if (el.bmi_gotOriginal) {
  109.         if (el.bmi_orig_mouseout) {
  110.             el.onmouseout = el.bmi_orig_mouseout;
  111.         }
  112.     }
  113. }
  114.  
  115. function bmi_checkElement(el) {
  116.     var pwindow = null;
  117.     if (el.bmi_gotOriginal) return;
  118.     if (el.bmi_mapImage) {
  119.         if (el.bmi_mapImage.bmi_gotOriginal == 1) {
  120.             el.bmi_gotOriginal = 1;
  121.             if (el.bmi_touched) bmi_resetTitle(el);
  122.             return;
  123.         }
  124.     }
  125.     if (el.bmi_touched != 1) {
  126.         bmi_setElementTitle(el);
  127.         if (el.onmouseout) {
  128.             el.bmi_orig_mouseout = el.onmouseout;
  129.             el.onmouseout = bmi_safeMouseOutEvents;
  130.         } else {
  131.             el.onmouseout = bmi_safeMouseOutEvents;
  132.         }
  133.     } else {
  134.         el.title = el.bmi_title;
  135.         el.alt = el.bmi_alt;
  136.     }
  137.     if (el.bmi_mapImage) bmi_imageObjSelected = el.bmi_mapImage;
  138.     else bmi_imageObjSelected = el;
  139.     if (bmi_ie || bmi_opera) pwindow = document.parentWindow;
  140.     else if (bmi_nsonly || is_gecko) pwindow = document.defaultView;
  141.     else pwindow = null;
  142.     if (pwindow && (pwindow != pwindow.parent)) {
  143.         pwindow.focus();
  144.         el.bmi_changedFocus = 1;
  145.     }
  146.     return;
  147. }
  148.  
  149. function bmi_setElementTitle(el) {
  150.     var tmpAlt = "";
  151.     if (el.alt) {
  152.         tmpAlt = el.alt;
  153.         el.bmi_oldAlt = el.alt;
  154.         el.bmi_alt = "";
  155.         el.alt = "";
  156.     }
  157.     if (el.title) {
  158.         el.bmi_oldTitle = el.title;
  159.         el.title = el.title + "";
  160.     } else {
  161.         el.title = tmpAlt + "";
  162.     }
  163.     if (bmi_firefox) {
  164.         el.title = el.title + bmi_toolTipSeperator + bmi_ffx_op_toolTip;
  165.         el.bmi_touched = 1;
  166.         el.bmi_title = el.title;
  167.     } else if (bmi_opera || bmi_safari) {
  168.         el.title = bmi_ffx_op_toolTip;
  169.         el.bmi_touched = 1;
  170.         el.bmi_title = el.title;
  171.     } else {
  172.         el.title = el.title + bmi_toolTipSeperator + bmi_toolTip;
  173.         el.bmi_touched = 1;
  174.         el.bmi_title = el.title;
  175.     }
  176.     return;
  177. }
  178.  
  179. function bmi_checkInputType(type) {
  180.     if (!type) return 0;
  181.     if (type.match("image") || type.match("Image")) {
  182.         return 1;
  183.     }
  184.     return 0;
  185. }
  186.  
  187. function bmi_checkMIMEType(type) {
  188.     var typeStr = new String(type);
  189.     var find = /image\//gi;
  190.     if (typeStr.search(find) != -1) return 1;
  191.     return 0;
  192. }
  193.  
  194. function bmi_mouseOver(e) {
  195.     bmi_imageObjSelected = null;
  196.     var obj;
  197.     if (document.bmi_onmouseover_original != null) document.bmi_onmouseover_original(e);
  198.     if (bmi_ie || bmi_opera) {
  199.         var e = window.event;
  200.         obj = e.srcElement;
  201.     } else {
  202.         obj = e.target;
  203.     }
  204.     if (obj.bmi_gotOriginal) return;
  205.     if (bmi_ImageElement(obj)) {
  206.         bmi_checkElement(obj);
  207.     }
  208.     return;
  209. }
  210.  
  211. function bmi_safeMouseOutEvents(e) {
  212.     var obj;
  213.     if (bmi_ie || bmi_opera) {
  214.         e = window.event;
  215.         obj = e.srcElement;
  216.     } else {
  217.         obj = e.target;
  218.     }
  219.     bmi_resetTitle(obj);
  220.     if (obj.bmi_changedFocus == 1) {
  221.         var pwindow = null;
  222.         if (bmi_ie || bmi_opera) pwindow = document.parentWindow;
  223.         else if (bmi_nsonly || is_gecko) pwindow = document.defaultView;
  224.         else pwindow = null;
  225.         if (pwindow) {
  226.             pwindow.top.focus();
  227.             obj.bmi_changedFocus = 0;
  228.         }
  229.     }
  230.     if (obj.bmi_orig_mouseout) {
  231.         obj.bmi_orig_mouseout();
  232.     }
  233. }
  234.  
  235. function bmi_updateImageSrc(src) {
  236.     var found = 0;
  237.     var find = /\?/g;
  238.     var editUrl;
  239.     var editIndex;
  240.     var editProto;
  241.     var bmiSignIndex;
  242.     var bmiSign;
  243.     srcString = new String(src);
  244.     if (srcString.search(find) != -1) {
  245.         found = 1;
  246.         srcString = srcString.concat("&" + bmi_concatStr + "=1");
  247.     } else {
  248.         var i = srcString.lastIndexOf("/");
  249.         var newStr = srcString.substring(i + 1);
  250.         srcString = srcString.concat("/" + bmi_concatStr + "/" + newStr);
  251.     }
  252.     if (bmi_htmlEdit) {
  253.         editIndex = srcString.indexOf("://");
  254.         if (editIndex != -1) {
  255.             editProto = srcString.substring(0, editIndex + 3);
  256.             editUrl = srcString.substring(editIndex + 3);
  257.             editIndex = editUrl.indexOf("/");
  258.             if (editIndex != -1) {
  259.                 editUrl = editUrl.substring(editIndex + 1);
  260.                 bmiSignIndex = editUrl.indexOf("/");
  261.                 if (bmiSignIndex != -1) {
  262.                     bmiSign = editUrl.substring(0, bmiSignIndex);
  263.                     if (bmiSign == "bmi") {
  264.                         editUrl = editUrl.substring(bmiSignIndex + 1);
  265.                         srcString = editProto + editUrl;
  266.                     }
  267.                 }
  268.             }
  269.         }
  270.     }
  271.     return (srcString);
  272. }
  273.  
  274. function bmi_replaceImages(array) {
  275.     if (!array) return;
  276.     for (var i = 0; i < array.length; i++) {
  277.         if (array[i].bmi_gotOriginal) {
  278.             continue;
  279.         }
  280.         if (array[i].bmi_objTag) {
  281.             array[i].data = bmi_updateImageSrc(array[i].data);
  282.         } else {
  283.             array[i].src = bmi_updateImageSrc(array[i].src);
  284.         }
  285.         array[i].bmi_gotOriginal = 1;
  286.         if (array[i].bmi_touched) {
  287.             bmi_resetTitle(array[i]);
  288.         }
  289.     }
  290.     return;
  291. }
  292.  
  293. function bmi_replaceInputImages(array) {
  294.     if (!array) return;
  295.     for (var i = 0; i < array.length; i++) {
  296.         if (array[i].bmi_gotOriginal) {
  297.             continue;
  298.         }
  299.         if (array[i].type && bmi_checkInputType(array[i].type)) {
  300.             array[i].src = bmi_updateImageSrc(array[i].src);
  301.             array[i].bmi_gotOriginal = 1;
  302.             if (array[i].bmi_touched) {
  303.                 bmi_resetTitle(array[i]);
  304.             }
  305.         }
  306.     }
  307.     return;
  308. }
  309.  
  310. function bmi_NSlayers() {
  311.     if (document != null) {
  312.         if (!document.layers) {
  313.             bmi_replaceImages(document.tags.IMG);
  314.             bmi_replaceInputImages(document.tags.INPUT);
  315.             return;
  316.         }
  317.         for (var i = 0; i < document.layers.length; i++) {
  318.             bmi_NSlayers(document.layers[i].document);
  319.             bmi_replaceImages(document.layers[i].document.tags.IMG);
  320.             bmi_replaceInputImages(document.layers[i].document.tags.INPUT);
  321.         }
  322.     }
  323.     return;
  324. }
  325.  
  326. function bmi_downloadAllHandler() {
  327.     if ((true == bmi_checkAccess(parent)) && (parent.location.href != self.location.href)) {
  328.         var newparent = parent;
  329.         do {
  330.             newparent = newparent.parent;
  331.             if ((false == bmi_checkAccess(newparent.parent)) || (newparent.parent.location.href == newparent.location.href)) {
  332.                 break;
  333.             }
  334.         } while (newparent); //
  335.         var numFrames = newparent.frames.length;
  336.         var index = 0;
  337.         var frame;
  338.         for (; index < newparent.frames.length; index++) {
  339.             frame = newparent.frames[index];
  340.             if (false == bmi_checkAccess(frame.window)) {
  341.                 continue;
  342.             }
  343.             if (frame.window.bmi_reDownloadAllImages) {
  344.                 frame.window.bmi_reDownloadAllImages();
  345.             }
  346.         }
  347.         return;
  348.     }
  349.     bmi_reDownloadAllImages();
  350. }
  351.  
  352. function bmi_reDownloadAllImages() {
  353.     var imgArray;
  354.     var inputArray;
  355.     var backgroundArray;
  356.     var numFrames = window.frames.length;
  357.     var index = 0;
  358.     var frame;
  359.     for (; index < numFrames; index++) {
  360.         frame = window.frames[index];
  361.         if (false == bmi_checkAccess(frame.window)) {
  362.             continue;
  363.         }
  364.         if (frame.window.bmi_reDownloadAllImages) {
  365.             frame.window.bmi_reDownloadAllImages();
  366.         }
  367.     }
  368.     if ((bmi_ie5up || bmi_ns6up || bmi_opera5up || bmi_firefox)) {
  369.         imgArray = document.getElementsByTagName("IMG");
  370.         inputArray = document.getElementsByTagName("INPUT");
  371.         bmi_replaceImages(imgArray);
  372.         bmi_replaceInputImages(inputArray);
  373.     } else if (bmi_ns && (bmi_ns4 || bmi_ns3)) {
  374.         var imgArray;
  375.         var docLayers;
  376.         docLayers = document.layers;
  377.         if (docLayers && docLayers.length) {
  378.             for (var layi = 0; layi < 0; layi++) {
  379.                 imgArray = docLayers[layi].document.images;
  380.                 bmi_replaceImages(imgArray);
  381.             }
  382.         } else {
  383.             imgArray = document.images;
  384.             bmi_replaceImages(imgArray);
  385.         }
  386.     } else {
  387.         imgArray = document.images;
  388.         bmi_replaceImages(imgArray);
  389.     }
  390.     return;
  391. }
  392.  
  393. function bmi_reDownloadSelectedImage(img) {
  394.     if (img.bmi_gotOriginal) {
  395.         return;
  396.     }
  397.     if (img && !img.bmi_gotOriginal) {
  398.         if (img.bmi_objTag) {
  399.             img.data = bmi_updateImageSrc(img.data);
  400.         } else {
  401.             img.src = bmi_updateImageSrc(img.src);
  402.         }
  403.         img.bmi_gotOriginal = 1;
  404.         if (img.bmi_touched) {
  405.             bmi_resetTitle(img);
  406.         }
  407.         if (img.bmi_areaEl && (img.bmi_areaEl.bmi_touched)) {
  408.             bmi_resetTitle(img.bmi_areaEl);
  409.             img.bmi_areaEl.bmi_gotOriginal = 1;
  410.         }
  411.     }
  412.     return;
  413. }
  414.  
  415. function bmi_keypress(e) {
  416.     var reloadSingle = 0;
  417.     var reloadAll = 0;
  418.     var obj;
  419.     if (bmi_ns) {
  420.         if (bmi_ns6up) {
  421.             if ((String.fromCharCode(e.charCode) == 'r') || (String.fromCharCode(e.charCode) == 'R')) reloadSingle = 1;
  422.             else {
  423.                 if ((String.fromCharCode(e.charCode) == 'A')) reloadAll = 1;
  424.             }
  425.             obj = e.target;
  426.             var str = new String(obj.tagName);
  427.             if (str.match("INPUT") && (bmi_checkInputType(obj.type) != 1)) {
  428.                 if (bmi_imageObjSelected == obj) reloadAll = reloadSingle = 0;
  429.             }
  430.         } else {
  431.             if ((String.fromCharCode(e.which) == 'R') && (e.modifiers == Event.SHIFT_MASK)) reloadSingle = 1;
  432.             else {
  433.                 if ((String.fromCharCode(e.which) == 'A') && (e.modifiers == Event.SHIFT_MASK)) reloadAll = 1;
  434.             }
  435.         }
  436.     }
  437.     if (bmi_ie || bmi_opera) {
  438.         if ((String.fromCharCode(window.event.keyCode) == 'R') && (window.event.shiftKey)) reloadSingle = 1;
  439.         else if (bmi_opera) {
  440.             if ((String.fromCharCode(window.event.keyCode) == 'A') && (window.event.shiftKey)) reloadAll = 1;
  441.         }
  442.         var e = window.event;
  443.         obj = e.srcElement;
  444.         var str = new String(obj.tagName);
  445.         if (str.match("INPUT") && (bmi_checkInputType(obj.type) != 1)) {
  446.             if (bmi_imageObjSelected == obj) reloadSingle = reloadAll = 0;
  447.         }
  448.     }
  449.     if (reloadSingle == 1) {
  450.         if (bmi_ns) {
  451.             if (bmi_ns4 || bmi_ns3 || bmi_ns2) {
  452.                 return;
  453.             }
  454.         }
  455.         if (bmi_imageObjSelected) bmi_reDownloadSelectedImage(bmi_imageObjSelected);
  456.     } else {
  457.         if (reloadAll == 1) {
  458.             bmi_downloadAllHandler();
  459.         }
  460.     }
  461.     if ((document.bmi_onkeypress_original != null) && (document.bmi_onkeypress_original != bmi_keypress)) {
  462.         return (document.bmi_onkeypress_original(e));
  463.     }
  464.     return;
  465. }
  466.  
  467. function bmi_linkMapImages(maps, objs) {
  468.     var linked = 0;
  469.     for (var i = 0; i < objs.length; i++) {
  470.         if (linked >= maps.length) {
  471.             return linked;
  472.         }
  473.         if (objs[i].useMap) {
  474.             var newStr = new String(objs[i].useMap);
  475.             var mapName = newStr.substring(newStr.lastIndexOf("#") + 1);
  476.             if (bmi_ImageElement(objs[i]) != 1) continue;
  477.             for (var j = 0; j < maps.length; j++) {
  478.                 if (maps[j].name == mapName) {
  479.                     maps[j].bmi_imgObj = objs[i];
  480.                     linked++;
  481.                 }
  482.             }
  483.         }
  484.     }
  485.     return linked;
  486. }
  487.  
  488. function bmi_load() {
  489.     if (bmi_orig_onLoad) {
  490.         bmi_orig_onLoad();
  491.     }
  492.     if (bmi_ns2 || bmi_ns3 || bmi_ns4) {
  493.         window.defaultStatus = bmi_ns_tooltip;
  494.         return;
  495.     }
  496.     if (document.onmouseover) {
  497.         if (document.onmouseover != bmi_mouseOver) {
  498.             document.bmi_onmouseover_original = document.onmouseover;
  499.         }
  500.     }
  501.     document.onmouseover = bmi_mouseOver;
  502.     if (document.onkeypress) {
  503.         if (document.onkeypress != bmi_keypress) {
  504.             document.bmi_onkeypress_original = document.onkeypress;
  505.         }
  506.     } else {
  507.         document.bmi_onkeypress_original = null;
  508.     }
  509.     document.onkeypress = bmi_keypress;
  510.     var maps = document.getElementsByTagName("MAP");
  511.     if ((maps == null) || (maps.length == 0)) {
  512.         return;
  513.     }
  514.     var objs = null;
  515.     if (bmi_ie || bmi_opera) {
  516.         objs = document.all;
  517.         if (objs) {
  518.             bmi_linkMapImages(maps, objs);
  519.         }
  520.     }
  521.     if (bmi_ns || is_gecko) {
  522.         var num = 0;
  523.         objs = document.getElementsByTagName("IMG");
  524.         if (objs) {
  525.             num = num + bmi_linkMapImages(maps, objs);
  526.         }
  527.         if (num >= maps.length) {
  528.             return;
  529.         }
  530.         objs = null;
  531.         objs = document.getElementsByTagName("INPUT");
  532.         if (objs) {
  533.             num += bmi_linkMapImages(maps, objs);
  534.         }
  535.         if (num >= maps.length) {
  536.             return;
  537.         }
  538.         objs = null;
  539.         objs = document.getElementsByTagName("OBJECT");
  540.         if (objs) {
  541.             num += bmi_linkMapImages(maps, objs);
  542.         }
  543.     }
  544.     return;
  545. }
  546. var bmi_orig_onLoad;
  547.  
  548. function bmi_SafeAddOnload(f, urlStr, htmlEdit) {
  549.     if (urlStr) {
  550.         bmi_concatStr = urlStr;
  551.     }
  552.     if (htmlEdit) {
  553.         bmi_htmlEdit = htmlEdit;
  554.     }
  555.     if (bmi_ie4) {
  556.         window.onload = f;
  557.     } else if (window.onload) {
  558.         if (window.onload != f) {
  559.             bmi_orig_onLoad = window.onload;
  560.             window.onload = f;
  561.         }
  562.     } else {
  563.         window.onload = f;
  564.     }
  565. }
Add Comment
Please, Sign In to add comment