Content-Type: multipart/related; start=; boundary=----------VIkciIu2gJEL5dl14ihIzo Content-Location: http://help.netbynet.ru/nastrojka-vpn/mac-os-vpn/ Subject: =?utf-8?Q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=BD=D0=B5=D1=82=20=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20(VPN)=20=D0=B4=D0=BB=D1=8F=20Mac=20OS=20:=20Help.netbynet.ru?= MIME-Version: 1.0 ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=default.htm Content-Type: text/html; charset=UTF-8; name=default.htm Content-ID: Content-Location: http://help.netbynet.ru/nastrojka-vpn/mac-os-vpn/ Content-Transfer-Encoding: Quoted-Printable =D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0 =D0=B8= =D0=BD=D1=82=D0=B5=D1=80=D0=BD=D0=B5=D1=82 =D1=81=D0=BE=D0=B5=D0=B4=D0=B8= =D0=BD=D0=B5=D0=BD=D0=B8=D1=8F (VPN) =D0=B4=D0=BB=D1=8F Mac OS : Help.ne= tbynet.ru = = = = =
=D0=9B=D0=BE=D0=B3=D0=B8=D0=BD:

= =D0=9F=D0=B0=D1=80=D0=BE=D0=BB=D1=8C:
=D0=97=D0=B0=D0=B1=D1=8B=D0= =BB=D0=B8 =D0=BF=D0=B0=D1=80=D0=BE=D0=BB=D1=8C?
=D0=9F=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=D1=82=D1=8C=D1=81= =D1=8F =D0=BF=D0=BE =D1=82=D0=B5=D0=BB=D0=B5=D1=84=D0=BE=D0=BD=D1=83:

8 495 980 25 00

=D0=A1=D0=BB=D1=83=D0=B6=D0=B1=D0=B0 =D0=BF=D0=BE=D0=B4=D0=B4=D0=B5= =D1=80=D0=B6=D0=BA=D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=D1=91 =D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B8 =D0=BF=D1=80= =D0=B0=D0=B2=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE — =D1=83=D0=B2=D0=B8=D0= =B4=D0=B8=D1=82=D0=B5 =D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=B8=D1=87=D0= =BD=D0=BE=D0=B5 =D0=BE=D0=BA=D0=BD=D0=BE:

3D""

=


------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=jquery-latest.js Content-Type: application/javascript; charset=utf-8; name=jquery-latest.js Content-Location: http://code.jquery.com/jquery-latest.js Content-Transfer-Encoding: Base64 LyohCiAqIGpRdWVyeSBKYXZhU2NyaXB0IExpYnJhcnkgdjEuMTEuMQogKiBodHRw Oi8vanF1ZXJ5LmNvbS8KICoKICogSW5jbHVkZXMgU2l6emxlLmpzCiAqIGh0dHA6 Ly9zaXp6bGVqcy5jb20vCiAqCiAqIENvcHlyaWdodCAyMDA1LCAyMDE0IGpRdWVy eSBGb3VuZGF0aW9uLCBJbmMuIGFuZCBvdGhlciBjb250cmlidXRvcnMKICogUmVs ZWFzZWQgdW5kZXIgdGhlIE1JVCBsaWNlbnNlCiAqIGh0dHA6Ly9qcXVlcnkub3Jn L2xpY2Vuc2UKICoKICogRGF0ZTogMjAxNC0wNS0wMVQxNzo0MloKICovCgooZnVu Y3Rpb24oIGdsb2JhbCwgZmFjdG9yeSApIHsKCglpZiAoIHR5cGVvZiBtb2R1bGUg PT09ICJvYmplY3QiICYmIHR5cGVvZiBtb2R1bGUuZXhwb3J0cyA9PT0gIm9iamVj dCIgKSB7CgkJLy8gRm9yIENvbW1vbkpTIGFuZCBDb21tb25KUy1saWtlIGVudmly b25tZW50cyB3aGVyZSBhIHByb3BlciB3aW5kb3cgaXMgcHJlc2VudCwKCQkvLyBl eGVjdXRlIHRoZSBmYWN0b3J5IGFuZCBnZXQgalF1ZXJ5CgkJLy8gRm9yI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YgKCB0eXBlb2YgZGVmaW5lID09PSAi ZnVuY3Rpb24iICYmIGRlZmluZS5hbWQgKSB7CglkZWZpbmUoICJqcXVlcnkiLCBb XSwgZnVuY3Rpb24oKSB7CgkJcmV0dXJuIGpRdWVyeTsKCX0pOwp9CgoKCgp2YXIK CS8vIE1hcCBvdmVyIGpRdWVyeSBpbiBjYXNlIG9mIG92ZXJ3cml0ZQoJX2pRdWVy eSA9IHdpbmRvdy5qUXVlcnksCgoJLy8gTWFwIG92ZXIgdGhlICQgaW4gY2FzZSBv ZiBvdmVyd3JpdGUKCV8kID0gd2luZG93LiQ7CgpqUXVlcnkubm9Db25mbGljdCA9 IGZ1bmN0aW9uKCBkZWVwICkgewoJaWYgKCB3aW5kb3cuJCA9PT0galF1ZXJ5ICkg ewoJCXdpbmRvdy4kID0gXyQ7Cgl9CgoJaWYgKCBkZWVwICYmIHdpbmRvdy5qUXVl cnkgPT09IGpRdWVyeSApIHsKCQl3aW5kb3cualF1ZXJ5ID0gX2pRdWVyeTsKCX0K CglyZXR1cm4galF1ZXJ5Owp9OwoKLy8gRXhwb3NlIGpRdWVyeSBhbmQgJCBpZGVu dGlmaWVycywgZXZlbiBpbgovLyBBTUQgKCM3MTAyI2NvbW1lbnQ6MTAsIGh0dHBz Oi8vZ2l0aHViLmNvbS9qcXVlcnkvanF1ZXJ5L3B1bGwvNTU3KQovLyBhbmQgQ29t bW9uSlMgZm9yIGJyb3dzZXIgZW11bGF0b3JzICgjMTM1NjYpCmlmICggdHlwZW9m IG5vR2xvYmFsID09PSBzdHJ1bmRlZmluZWQgKSB7Cgl3aW5kb3cualF1ZXJ5ID0g d2luZG93LiQgPSBqUXVlcnk7Cn0KCgoKCnJldHVybiBqUXVlcnk7Cgp9KSk7Cg== ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=jquery-ui.js Content-Type: application/javascript; charset=utf-8; name=jquery-ui.js Content-Location: http://code.jquery.com/ui/1.10.0/jquery-ui.js Content-Transfer-Enco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WxmIG9yIGlu Y2x1ZGluZwovLyBqcXVlcnkuY29sb3Iuc3ZnLW5hbWVzLmpzLgpjb2xvcnMgPSBq UXVlcnkuQ29sb3IubmFtZXMgPSB7CgkvLyA0LjEuIEJhc2ljIGNvbG9yIGtleXdv cmRzCglhcXVhOiAiIzAwZmZmZiIsCglibGFjazogIiMwMDAwMDAiLAoJYmx1ZTog IiMwMDAwZmYiLAoJZnVjaHNpYTogIiNmZjAwZmYiLAoJZ3JheTogIiM4MDgwODAi LAoJZ3JlZW46ICIjMDA4MDAwIiwKCWxpbWU6ICIjMDBmZjAwIiwKCW1hcm9vbjog IiM4MDAwMDAiLAoJbmF2eTogIiMwMDAwODAiLAoJb2xpdmU6ICIjODA4MDAwIiwK CXB1cnBsZTogIiM4MDAwODAiLAoJcmVkOiAiI2ZmMDAwMCIsCglzaWx2ZXI6ICIj YzBjMGMwIiwKCXRlYWw6ICIjMDA4MDgwIiwKCXdoaXRlOiAiI2ZmZmZmZiIsCgl5 ZWxsb3c6ICIjZmZmZjAwIiwKCgkvLyA0LjIuMy4gInRyYW5zcGFyZW50IiBjb2xv ciBrZXl3b3JkCgl0cmFuc3BhcmVudDogWyBudWxsLCBudWxsLCBudWxsLCAwIF0s CgoJX2RlZmF1bHQ6ICIjZmZmZmZmIgp9OwoKfSkoIGpRdWVyeSApOwoKCi8qKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qKioqKioqKioqKioqKioqKioq KioqKioqKioqKiogQ0xBU1MgQU5JTUFUSU9OUyAqKioqKioqKioqKioqKioqKioq KioqKioqKioqKiovCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCihm dW5jdGlvbigpIHsKCnZhciBjbGFzc0FuaW1hdGlvbkFjdGlvbnMgPSBbICJhZGQi LCAicmVtb3ZlIiwgInR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XJuICQu ZWZmZWN0cy5hbmltYXRlQ2xhc3MuY2FsbCggdGhpcywgewoJCQlhZGQ6IGFkZCwK CQkJcmVtb3ZlOiByZW1vdmUKCQl9LCBzcGVlZCwgZWFzaW5nLCBjYWxsYmFjayAp OwoJfQp9KTsKCn0pKCk7CgovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq LwovKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiogRUZGRUNUUyAq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwovKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqLwoKKGZ1bmN0aW9uKCkgewoKJC5leHRlbmQoICQu ZWZmZWN0cywgewoJdmVyc2lvbjogIjEuMTAuMCIsCgoJLy8gU2F2ZXMgYSBzZXQg b2YgcHJvcGVydGllcyBpbiBhIGRhdGEgc3RvcmFnZQoJc2F2ZTogZnVuY3Rpb24o IGVsZW1lbnQsIHNldCApIHsKCQlmb3IoIHZhciBpPTA7IGkgPCBzZXQubGVuZ3Ro OyBpKysgKSB7CgkJCWlmICggc2V0WyBpIF0gIT09IG51bGwgKSB7CgkJCQllbGVt ZW50LmRhdGEoIGRhdGFTcGFjZSArIHNldFsgaSBdLCBlbGVtZW50WyAwIF0uc3R5 bGVbIHNldFsgaSBdIF0gKTsKCQkJfQoJCX0KCX0sCgoJLy8gUmVzdG9yZXMgYSBz ZXQgb2YgcHJldmlvdXNseSBzYXZlZCBwcm9wZXJ0aWVzIGZyb20gYSBkYXRhIHN0 b3JhZ2UKCXJlc3RvcmU6IGZ1bmN0aW9uKCBlbGVtZW50LCBzZXQgKSB7CgkJdmFy IHZhbCwgaTsKCQlmb3IoIGk9MDsgaSA8IHNldC5sZW5ndGg7IGkrKyApIHsKCQkJ aWYgKCBzZXRbIGkgXSAhPT0gbn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gkJCXJldHVybiB0aGlzLmVmZmVj dC5jYWxsKCB0aGlzLCBhcmdzICk7CgkJfQoJfSwKCgkvLyBoZWxwZXIgZnVuY3Rp b25zCgljc3NVbml0OiBmdW5jdGlvbihrZXkpIHsKCQl2YXIgc3R5bGUgPSB0aGlz LmNzcygga2V5ICksCgkJCXZhbCA9IFtdOwoKCQkkLmVhY2goIFsgImVtIiwgInB4 IiwgIiUiLCAicHQiIF0sIGZ1bmN0aW9uKCBpLCB1bml0ICkgewoJCQlpZiAoIHN0 eWxlLmluZGV4T2YoIHVuaXQgKSA+IDAgKSB7CgkJCQl2YWwgPSBbIHBhcnNlRmxv YXQoIHN0eWxlICksIHVuaXQgXTsKCQkJfQoJCX0pOwoJCXJldHVybiB2YWw7Cgl9 Cn0pOwoKfSkoKTsKCi8qKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8q KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiBFQVNJTkcgKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCi8qKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKiovCgooZnVuY3Rpb24oKSB7CgovLyBiYXNlZCBvbiBlYXNp bmcgZXF1YXRpb25zIGZyb20gUm9iZXJ0IFBlbm5lciAoaHR0cDovL3d3dy5yb2Jl cnRwZW5uZXIuY29tL2Vhc2luZykKCnZhciBiYXNlRWFzaW5ncyA9IHt9OwoKJC5l YWNoKCBbICJRdWFkIiwgIkN1YmljIiwgIlF1YXJ0IiwgIlF1aW50IiwgIkV4cG8i IF0sIGZ1bmN0aW9uKCBpLCBuYW1lICkgewoJYmFzZUVhc2luZ3NbIG5hbWUgXSA9 IGZ1bmN0aW9uKCBwICkgewoJCXJldHVybiBNYXRoLnBvdyggcCwgaSArIDIgKTsK CX07Cn0pOwoK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lbGVt ZW50WzBdOwoJCQl0aGF0LmNsb3NlKCBldmVudCwgdHJ1ZSApOwoKCQkJLy8gUmVt b3ZlIGltbWVkaWF0ZWx5OyBkZXN0cm95aW5nIGFuIG9wZW4gdG9vbHRpcCBkb2Vz bid0IHVzZSB0aGUKCQkJLy8gaGlkZSBhbmltYXRpb24KCQkJJCggIiMiICsgaWQg KS5yZW1vdmUoKTsKCgkJCS8vIFJlc3RvcmUgdGhlIHRpdGxlCgkJCWlmICggZWxl bWVudC5kYXRhKCAidWktdG9vbHRpcC10aXRsZSIgKSApIHsKCQkJCWVsZW1lbnQu YXR0ciggInRpdGxlIiwgZWxlbWVudC5kYXRhKCAidWktdG9vbHRpcC10aXRsZSIg KSApOwoJCQkJZWxlbWVudC5yZW1vdmVEYXRhKCAidWktdG9vbHRpcC10aXRsZSIg KTsKCQkJfQoJCX0pOwoJfQp9KTsKCn0oIGpRdWVyeSApICk7Cg== ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=scripts.js Content-Type: text/javascript; name=scripts.js Content-Location: http://help.netbynet.ru/wp-content/themes/nbn-help-new/scripts.js Content-Transfer-Encoding: 8bit $(document).ready(function() { var elements = document.getElementsByTagName('a'); for (var i = 0, len = elements.length; i < len; i++) { elements[i].removeAttribute('title'); } var elements = document.getElementsByTagName('img'); for (var i = 0, len = elements.length; i < len; i++) { elements[i].removeAttribute('title'); } $(".btn-city").click(function() { $("#panel").fadeToggle("fast"); return false; }); $("body").click(function() { $("#panel").fadeOut("fast") }); $(".login-open").click(function() { $(".login-form").toggleClass("opened", 200 ); return false; }); $("body").click(function() { $(".login-form").removeClass("opened", 200 ); }); $(".noclose").click(function(e){ e.stopPropagation(); }); }); ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=favicon.ico Content-Type: image/x-icon; name=favicon.ico Content-Location: http://help.netbynet.ru/wp-content/themes/nbn-help-new/img/icons/favicon.ico Content-Transfer-Encoding: Base64 AAABAAEAEBAAAAEAIABoB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/hh2Z/4Yd mf+GHZn/hh2Z/6plt/+5f8Pehh2Z/4Ydmf+GHZn/hh2Z/4Ydmf+PL6H/+fT6//Xu 9/+LJ53/hh2Z/4Ydmf+GHZn/hh2Z/4Ydmf+qZbf/uX/D3oYdmf+GHZn/hh2Z/4Yd mf+GHZn/lDil//37/f/48/n/jy6g/4Ydmf+GHZn/hh2Z/4Ydmf+GHZn/qmW3/da3 3KqGHpn/hh2Z/4Ydmf+GHZn/hh2Z/4ggmv+bRav/plq0/4olnP+GHZn/hh2Z/4Yd mf+GHZn/hh2Z/8aZzsr+/v4U17jdpbd7wd61eMDgtXjA4LV4wOC1eMDgtXjA4LV4 wOC1eMDgtXjA4LV4wOC1eMDgtXjA4NCq17L9/P0h9/8AAOP/AADh/wAAgAEAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAEAAA== ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline; filename=normalize.css Content-Type: text/css; name=normalize.css Content-Location: http://help.netbynet.ru/wp-content/themes/nbn-help-new/normalize.css?ver=1.0 Content-Transfer-Encoding: 8bit /*! normalize.css v1.0.1 | MIT License | git.io/normalize */ /* ========================================================================== HTML5 display definitions ========================================================================== */ /* * Corrects `block` display not defined in IE 6/7/8/9 and Firefox 3. */ article, aside, details, figcaption, figure, footer, header, hgroup, nav, section, summary { display: block; } /* * Corrects `inline-block` display not defined in IE 6/7/8/9 and Firefox 3. */ audio, canvas, video { display: inline-block; *display: inline; *zoom: 1; } /* * Prevents modern browsers from displaying `audio` without controls. * Remove excess height in iOS 5 devices. */ audio:not([controls]) { display: none; height: 0; } /* * Addresses styling for `hidden` attribute not present in IE 7/8/9, Firefox 3, * and Safari 4. * Known issue: no IE 6 support. */ [hidden] { display: none; } /* ========================================================================== Base ========================================================================== */ /* * 1. Corrects text resizing oddly in IE 6/7 when body `font-size` is set using * `em` units. * 2. Prevents iOS text size adjust after orientation change, without disabling * user zoom. */ html { font-size: 100%; /* 1 */ -webkit-text-size-adjust: 100%; /* 2 */ -ms-text-size-adjust: 100%; /* 2 */ } /* * Addresses `font-family` inconsistency between `textarea` and other form * elements. */ html, button, input, select, textarea { font-family: sans-serif; } /* * Addresses margins handled incorrectly in IE 6/7. */ body { margin: 0; } /* ========================================================================== Links ========================================================================== */ /* * Addresses `outline` inconsistency between Chrome and other browsers. */ a:focus { outline: thin dotted; } /* * Improves readability when focused and also mouse hovered in all browsers. */ a:active, a:hover { outline: 0; } /* ========================================================================== Typography ========================================================================== */ /* * Addresses font sizes and margins set differently in IE 6/7. * Addresses font sizes within `section` and `article` in Firefox 4+, Safari 5, * and Chrome. */ h1 { font-size: 2em; margin: 0.67em 0; } h2 { font-size: 1.5em; margin: 0.83em 0; } h3 { font-size: 1.17em; margin: 0; } h4 { font-size: 1em; margin: 1.33em 0; } h5 { font-size: 0.83em; margin: 1.67em 0; } h6 { font-size: 0.75em; margin: 2.33em 0; } /* * Addresses styling not present in IE 7/8/9, Safari 5, and Chrome. */ abbr[title] { border-bottom: 1px dotted; } /* * Addresses style set to `bolder` in Firefox 3+, Safari 4/5, and Chrome. */ b, strong { font-weight: bold; } blockquote { margin: 1em 40px; } /* * Addresses styling not present in Safari 5 and Chrome. */ dfn { font-style: italic; } /* * Addresses styling not present in IE 6/7/8/9. */ mark { background: #ff0; color: #000; } /* * Addresses margins set differently in IE 6/7. */ p, pre { margin: 1em 0; } /* * Corrects font family set oddly in IE 6, Safari 4/5, and Chrome. */ code, kbd, pre, samp { font-family: monospace, serif; _font-family: 'courier new', monospace; font-size: 1em; } /* * Improves readability of pre-formatted text in all browsers. */ pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; } /* * Addresses CSS quotes not supported in IE 6/7. */ q { quotes: none; } /* * Addresses `quotes` property not supported in Safari 4. */ q:before, q:after { content: ''; content: none; } /* * Addresses inconsistent and variable font size in all browsers. */ small { font-size: 80%; } /* * Prevents `sub` and `sup` affecting `line-height` in all browsers. */ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sup { top: -0.5em; } sub { bottom: -0.25em; } /* ========================================================================== Lists ========================================================================== */ /* * Addresses margins set differently in IE 6/7. */ dl, menu, ol, ul { margin: 1em 0; } dd { margin: 0 0 0 40px; } /* * Addresses paddings set differently in IE 6/7. */ menu, ol, ul { padding: 0 0 0 40px; } /* * Corrects list images handled incorrectly in IE 7. */ nav ul, nav ol { list-style: none; list-style-image: none; } /* ========================================================================== Embedded content ========================================================================== */ /* * 1. Removes border when inside `a` element in IE 6/7/8/9 and Firefox 3. * 2. Improves image quality when scaled in IE 7. */ img { border: 0; /* 1 */ -ms-interpolation-mode: bicubic; /* 2 */ } /* * Corrects overflow displayed oddly in IE 9. */ svg:not(:root) { overflow: hidden; } /* ========================================================================== Figures ========================================================================== */ /* * Addresses margin not present in IE 6/7/8/9, Safari 5, and Opera 11. */ figure { margin: 0; } /* ========================================================================== Forms ========================================================================== */ /* * Corrects margin displayed oddly in IE 6/7. */ form { margin: 0; } /* * Define consistent border, margin, and padding. */ fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } /* * 1. Corrects color not being inherited in IE 6/7/8/9. * 2. Corrects text not wrapping in Firefox 3. * 3. Corrects alignment displayed oddly in IE 6/7. */ legend { border: 0; /* 1 */ padding: 0; white-space: normal; /* 2 */ *margin-left: -7px; /* 3 */ } /* * 1. Corrects font size not being inherited in all browsers. * 2. Addresses margins set differently in IE 6/7, Firefox 3+, Safari 5, * and Chrome. * 3. Improves appearance and consistency in all browsers. */ button, input, select, textarea { font-size: 100%; /* 1 */ margin: 0; /* 2 */ vertical-align: baseline; /* 3 */ *vertical-align: middle; /* 3 */ } /* * Addresses Firefox 3+ setting `line-height` on `input` using `!important` in * the UA stylesheet. */ button, input { line-height: normal; } /* * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` * and `video` controls. * 2. Corrects inability to style clickable `input` types in iOS. * 3. Improves usability and consistency of cursor style between image-type * `input` and others. * 4. Removes inner spacing in IE 7 without affecting normal text inputs. * Known issue: inner spacing remains in IE 6. */ button, html input[type="button"], /* 1 */ input[type="reset"], input[type="submit"] { -webkit-appearance: button; /* 2 */ cursor: pointer; /* 3 */ *overflow: visible; /* 4 */ } /* * Re-set default cursor for disabled elements. */ button[disabled], input[disabled] { cursor: default; } /* * 1. Addresses box sizing set to content-box in IE 8/9. * 2. Removes excess padding in IE 8/9. * 3. Removes excess padding in IE 7. * Known issue: excess padding remains in IE 6. */ input[type="checkbox"], input[type="radio"] { box-sizing: border-box; /* 1 */ padding: 0; /* 2 */ *height: 13px; /* 3 */ *width: 13px; /* 3 */ } /* * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome. * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome * (include `-moz` to future-proof). */ input[type="search"] { -webkit-appearance: textfield; /* 1 */ -moz-box-sizing: content-box; -webkit-box-sizing: content-box; /* 2 */ box-sizing: content-box; } /* * Removes inner padding and search cancel button in Safari 5 and Chrome * on OS X. */ input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; } /* * Removes inner padding and border in Firefox 3+. */ button::-moz-focus-inner, input::-moz-focus-inner { border: 0; padding: 0; } /* * 1. Removes default vertical scrollbar in IE 6/7/8/9. * 2. Improves readability and alignment in all browsers. */ textarea { overflow: auto; /* 1 */ vertical-align: top; /* 2 */ } /* ========================================================================== Tables ========================================================================== */ /* * Remove most spacing between table cells. */ table { border-collapse: collapse; border-spacing: 0; } ------------VIkciIu2gJEL5dl14ihIzo Content-Disposition: inline Content-Type: image/jpeg Content-Location: http://help.netbynet.ru/wp-content/themes/nbn-help-new/img/topnav.jpg Content-Transfer-Encoding: Base64 /9j/4QNrRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEb AAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodp AA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YAAAAAAAEAMgAAAAEAWgAAAAYAAAAAAAEA NQAAAAEALQAAAAYAAAAAAAE4QklNA/gAAAAAAHAAAP////////////////////// //////8D6AAAAAD/////////////////////////////A+gAAAAA//////////// /////////////////wPoAAAAAP////////////////////////////8D6AAAOEJJ TQQAAAAAAAACAAI4QklNBAIAAAAAAAYAAAAAAAA4QklNBDAAAAAAAAMBAQEAOEJJ TQQtAAAAAAAGAAEAAAADOEJJTQQIAAAAAAAQAAAAAQAAAkAAAAJAAAAAADhCSU0E HgAAAAAABAAAAAA4QklNBBoAAAAAA0kAAAAGAAAAAAAAAAAAAAAaAAAAAQAAAAoA VQBuAHQAaQB0AGwAZQBkAC0ANAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAA AAAAAAAAAQAAABoAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAQ AAAAAQAAAAAAAG51bGwAAAACAAAABmJvdW5kc09iamMAAAABAAAAAAAAUmN0MQAA AAQAAAAAVG9wIGxvbmcAAAAAAAAAAExlZnRsb25nAAAAAAAAAABCdG9tbG9uZwAA ABoAAAAAUmdodGxvbmcAAAABAAAABnNsaWNlc1ZsTHMAAAABT2JqYwAAAAEAAAAA AAVzbGljZQAAABIAAAAHc2xpY2VJRGxvbmcAAAAAAAAAB2dyb3VwSURsb25nAAAA AAAAAAZvcmlnaW5lbnVtAAAADEVTbGljZU9yaWdpbgAAAA1hdXRvR2VuZXJhdGVk AAAAAFR5cGVlbnVtAAAACkVTbGljZVR5cGUAAAAASW1nIAAAAAZib3VuZHNPYmpj AAAAAQAAAAAAAFJjdDEAAAAEAAAAAFRvcCBsb25nAAAAAAAAAABMZWZ0bG9uZwAA AAAAAAAAQnRvbWxvbmcAAAAaAAAAAFJnaHRsb25nAAAAAQAAAAN1cmxURVhUAAAA AQAAAAAAAG51bGxURVhUAAAAAQAAAAAAAE1zZ2VURVhUAAAAAQAAAAAABmFsdFRh Z1RFWFQAAAABAAAAAAA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Omluc3RhbmNlSUQ9 InhtcC5paWQ6Q0E2QzhEMzREOTZBRTIxMUE2MDNBMTc5QTAzMDQzMkIiIHN0RXZ0 OndoZW49IjIwMTMtMDEtMzFUMTE6Mjk6NTArMDQ6MDAiIHN0RXZ0OnNvZnR3YXJl QWdlbnQ9IkFkb2JlIFBob3Rvc2hvcCBDUzUgV2luZG93cyIgc3RFdnQ6Y2hhbmdl ZD0iLyIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3Jp cHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+ICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAg