/**
    Mailua jquery utils lib

    Setter:
        $("#formtest").field("fieldname", "value");
    Getter:
        var res = $("#formtest").field("fieldname");

    Multilang and key_filter functions by Vitaliy Yanchuk

    Key filter:
        Description: Function to filter characters from input field
        Usage: $("#inputtext").key_filter('[a-z0-9]', 'i');

    Multilang:
        Summary:
        <script type="text/javascript" src="/scripts/lang/jquery.utils.js"></script>
        <script type="text/javascript" src="/scripts/lang/ru.js"></script>
        alert( $.lang('Hello') );
        alert( $.lang('Hello %s %s', $fname, $lname) );

    Initiating:
        You must initialize language replasement sequences by adding lang.json script to the page

    Using:
        To translate some simple word or phrase from list:

        var greeting = $.lang('greeting'); // Will give a translation, "Приветствую" if such word has been found in the loaded json data,

        if the word is not it will return the original.

    To translate the phrase with the replaceses:
    Example:

        var phrase = $.lang('My name is %s and my second name is %s', 'John', 'Smith');
        @returns: My name is John and my second name is Smith

    Quoting, if you want to put % character, use 2 of them
    Example: var phrase = $.lang('My name is %s and my second name is %%s', 'John', 'Smith');
    will print: My name is John and my second name is %s
*/

/*jsl:import xvarinit.js*/

//IE 8 with some plugins version fix:
$(document).ready(function() {
    if ($.browser.msie && $.browser.version == '6.0' ) {
        $.browser.version = ((navigator.userAgent.toLowerCase()).match( /msie[\/: ]([0-57-9][\d.]+)/ ) || [0,'6.0'])[1];
    }
});

(function($) {

    // does this function ever used? useless wrapper
    function field(fname, fvalue) {
        return $.fn.val.apply($("input[name='"+fname+"']", this), Array.prototype.slice.call(arguments, 1));
    }

    function clear_anchor_redirect(html) {
        var Rexp = new RegExp("href\\s*=\\s*(['\"]?)"+ROOT_DOMAIN+ROOT_URL+"/go/\\?([^'\"\\s>]*)", "gi");
        html = html.replace(Rexp, function(full, one, two){
            try {
                two = decodeURIComponent(two);
            } catch (ex) {
                return full;
            }

            return 'href=' + one + two;
        });
        return html;
    }

    function text2anchor(html, nordc) {
        html = html.replace(/\&nbsp;/gi, ' \&nbsp; ');

        html = html.replace(/<([^aA])([^>]*)?>(www\.[^\s\.\'\"<>]+?\.[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function(full, one, two, three) {
            return '<' + one + two + '><a href="' +
                (nordc ?
                    'http://'+three :
                    ROOT_DOMAIN + ROOT_URL + '/go/?' + encodeURIComponent('http://'+three) ) +
                '" target="_blank">'+three+'</a>';
        });

        html = html.replace(/([\s\n])(www\.[^\s\.\'\"<>]+?\.[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function (full, one, two) {
            return one + '<a href="' +
                (nordc ?
                    'http://' + two :
                    ROOT_DOMAIN + ROOT_URL + '/go/?' + encodeURIComponent('http://'+two)) +
                '" target="_blank">' + two + '</a>';
        });

        html = html.replace(/^(www\.[^\s\.\'\"<>]+?\.[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function (full, one) {
            return '<a href="' +
                (nordc ?
                    'http://' + one :
                    ROOT_DOMAIN + ROOT_URL + '/go/?' + encodeURIComponent('http://'+one)) +
                '" target="_blank">' + one + '</a>';
        });

        html = html.replace(/<([^aA])([^>]*)?>((?:http|https|ftp|news):\/\/[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function(full, one, two, three){
            return '<' + one + two + '><a href="' +
                (nordc ?
                    three :
                    ROOT_URL + '/go/?' + encodeURIComponent(three)) +
                '" target="_blank">' + three + '</a>';
        });

        html = html.replace(/^((?:http|https|ftp|news):\/\/[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function(full, one) {
              return '<a href="' +
                (nordc ?
                    one :
                    ROOT_URL + '/go/?' + encodeURIComponent(one)) +
                '" target="_blank">'+one+'</a>';
        });

        html = html.replace(/([^\'\"\=>])((?:http|https|ftp|news):\/\/[^\s\'\"<>]+[^\s\'\"\<\>\!\-\?\.\,\;\:\)\(\]\[\}\{])/gi,
        function(full, one, two) {
              return one + '<a href="' +
                (nordc ?
                    two :
                    ROOT_URL + '/go/?' + encodeURIComponent(two)) +
                '" target="_blank">'+two+'</a>';
        });

        html = html.replace(/(^|\s|\>)([\w\.\-]+\@[\w\.\-]+)/gi,'$1<a href="mailto:$2">$2</a>');
        html = html.replace(/ccid=<a href="mailto:[\w\.\-]+\@[\w\.\-]+">([\w\.\-]+\@[\w\.\-]+)<\/a>/gi,'ccid=$1');
        html = html.replace(/<a[\s]*href=["']{0,1}mailto:[\s]*<a href="mailto:[\w\.\-]+\@[\w\.\-]+">([\w\.\-]+\@[\w\.\-]+)<\/a>["']{0,1}/gi,'<a href="mailto:$1"');
        html = html.replace(/\s+(alt|title)="([^><"]*)<a[^>]*>([^><"]*)<\/a[^><]*>([^><"]*)"/gi,' $1="$2$3$4"');
        html = html.replace(/\s+(alt|title)='([^><']*)<a[^>]*>([^><']*)<\/a[^><]*>([^><']*)'/gi," $1='$2$3$4'");
        html = html.replace(/ \&nbsp; /gi, '\&nbsp;');
        return html;
    }

    function key_filter(p, flags, option) {
        var reg = new RegExp(p, flags);

        $(this).keypress(function(e) {
            // Keys will pass:
            if (e.keyCode == 8  ||  // Backspace
                e.keyCode == 9  ||  // Tab
                e.keyCode == 33 ||  // PageUP
                e.keyCode == 34 ||  // PageDown
                e.keyCode == 35 ||  // End
                e.keyCode == 36 ||  // Home
                e.keyCode == 37 ||  // LeftArrow
                e.keyCode == 39 ||  // RightArrow
                e.keyCode == 45 ||  // Insert
                e.keyCode == 46 ){   // Delete
                return true;
            } else if (!reg.test(String.fromCharCode(e.which))) {
                return false;
            }
        });
    }

    function lang(s) {
        if (jLang[s]) s = jLang[s];
        if ('undefined' != typeof s) {
            var next = 1,
                re = /%(%|s)/g,
                args = arguments;

            s = s.replace(re, function(t, v) {
                return '%' == v ? '%' : (args[next++] || '');
            });
        }

        return s;
    }

    function take_lang(array) {
        jLang = array;
    }

    function check_disabled() {
        return this.each(function() {
            var jthis   = $(this),
                checkbox = jthis.attr("title");

            checkbox || (checkbox = jthis.attr("checkbox"));
            var checked = $(checkbox).attr("checked");
            jthis.attr("checkbox", checkbox);
            jthis.removeAttr("title");

            if ($(this).parent().is(".disabled")) {
                checked = false;
            }

            if (checked) {
                jthis.removeClass("disabled").
                    find("input, textarea, select, button").
                    removeAttr("disabled");
            } else {
                jthis.addClass("disabled").
                    find("input, textarea, select, button").
                    attr("disabled", "disabled");
            }
            return this;
        });
    }

    function html2text(html, cleartag_only) {
        cleartag_only || (html = html.replace(/\n/g, ' '));
        html = html.replace(/<p\s[^>]*?>/ig,'\n').
            replace(/<br[^>]*?>/ig,'\n').
            replace(/<[^>]*>/ig,' ').
            replace(/&nbsp;/ig,' ').
            replace(/ +/ig,' ').
            replace(/\n\s/g,'\n');

        if ($.browser.msie) html = html.replace(/\n\s+/g, '\n'+'\n');
        html = html.replace(/&lt;/g, '<').
            replace(/&gt;/g,'>').
            replace(/&amp;/g,'&').
            replace(/&quot;/g,'"').
            replace(/&#039;/g,"'");
        return html;
    }

    function text2html(html, nordc) {
        html=html.replace(/</g, '&lt;').replace(/>/g,'&gt;');
        html=$.text2anchor(html, nordc);
        html=html.replace(/\n/ig,'<br />');
        return html;
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        rep,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

    function parseJSON(text, expectedType) {
        if (!text) return '';
        var j;
        cx.lastIndex = 0;
        if (cx.test(text)) {
            text = text.replace(cx, function (a) {
                return '\\u' +
                    ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            });
        }

        try {
            if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
                replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
                replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
                return eval('(' + text + ')');
            }
        } catch (replacedEvalError) {
            try {
                j = eval('(' + text + ')');
                return j;
            } catch (pureEvalError) {
                return expectedType ?
                    (expectedType == 'array' ?
                        [] :
                        (expectedType == 'object' ?
                            {
                                status: 1,
                                data: text,
                                err_msg: $.lang(/ALARM TIMEOUT!/.test(text) ?
                                    'Sorry, timeout error occured during processing your request. Please try again later or reduce the number of attachments, or their size.' :
                                    'Sorry, error occured during processing your request. Please try again later or contact administrator.')
                            } :
                            (expectedType == 'string' ? text : null ))) :
                    null;
            }
        }

        // If the text is not JSON parseable, then a SyntaxError is thrown.
        return text;//throw new SyntaxError('parseJSON');
    }

   function muaJSON(url, data, callback, method, expectedType) {
        if ( $.isFunction( data ) ) {
            callback = data;
            data = null;
        }

        if (typeof(method) != 'undefined' && method.toUpperCase() == 'POST') method='POST';
        else method='GET';

        return jQuery.ajax({
            type: method,
            url: url,
            data: data,
            success: function(jdata) {
                if ($.isFunction(callback)) callback(parseJSON(jdata, expectedType));
            }
        });
   }

    function str(key, holder) {

// Produce a string from holder[key].

        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

// If the value has a toJSON method, call it to obtain a replacement value.

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

// What happens next depends on the value's type.

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.

            return String(value);

// If the type is 'object', we might be dealing with an object or an array or
// null.

        case 'object':

// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.

            if (!value) {
                return 'null';
            }

// Make an array to hold the partial results of stringifying this object value.

            gap += indent;
            partial = [];

// Is the value an array?

            if (Object.prototype.toString.apply(value) === '[object Array]') {

// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

// Join all of the elements together, separated with commas, and wrap them in
// brackets.

                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

// If the replacer is an array, use it to select the members to be stringified.

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

// Otherwise, iterate through all of the keys in the object.

                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

// Join all of the member texts together, separated with commas,
// and wrap them in braces.

            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        default: return (value && value.valueOf);
        }
    }

    function obj2str(value, replacer, space) {

// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.

        var i;
        gap = '';
        indent = '';

// If the space parameter is a number, make an indent string containing that
// many spaces.

        if (typeof space === 'number') {
            for (i = 0; i < space; i += 1) {
                indent += ' ';
            }

// If the space parameter is a string, it will be used as the indent string.

        } else if (typeof space === 'string') {
            indent = space;
        }

// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.

        rep = replacer;
        if (replacer && typeof replacer !== 'function' &&
                (typeof replacer !== 'object' ||
                 typeof replacer.length !== 'number')) {
            throw new Error('JSON.stringify');
        }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.

        return str('', {'': value});
    }

    function quote(string) {
      escapable.lastIndex = 0;
      return escapable.test(string) ?
         '"' + string.replace(escapable, function (a) {
             var c = meta[a];
             return typeof c === 'string' ? c :
                 '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
         }) + '"' :
         '"' + string + '"';
    }

    function toJSON(key) {
        if (key.constructor === Date) {
            return isFinite(key.valueOf()) ?
                   key.getUTCFullYear()   + '-' +
                   f(key.getUTCMonth() + 1) + '-' +
                   f(key.getUTCDate())      + 'T' +
                   f(key.getUTCHours())     + ':' +
                   f(key.getUTCMinutes())   + ':' +
                   f(key.getUTCSeconds())   + 'Z' : null;
        } else if (key.constructor === String || key.constructor === Number || key.constructor === Boolean )
            return key.valueOf();
        return key;
    }

   function is_supported_browser(){
       var is_supported = false;
       // check jQuery.browser.version in IE7 after upgrade to jQuery 1.3 and remove it if works
        jQuery.browser.version = jQuery.browser.msie && (/msie 7\.0/i).test(navigator.userAgent) ?
            "7.0" :
            jQuery.browser.version;
       if($.browser.mozilla){
           is_supported = true;
       }

       if($.browser.safari){
           is_supported = true;
       }

       if($.browser.opera){
           if($.browser.version>=8){
               is_supported = true;
           }
       }

       if($.browser.msie){
           if($.browser.version>=6){
               is_supported = true;
           }
       }

       return is_supported;
   }

/*
    function int(str){
        return ( parseInt(str) || 0 );
    }
*/

    //string to array (equivalent to perl's qw// )
    //input: 'aaa bbb ccc'
    //output: [aaa, bbb, ccc]
    function qw(s){
        return s.split(/\s+/);
    }

    /**
     *  string to hash
     *  input: 'aaa bbb ccc'
     *  output: {aaa : 1, bbb : 1, ccc : 1}
     *  v - optional, if not defined v = 1
     */
    function qw2h(s, v) {
        v || (v = 1);
        var a = qw(s),
            res = [];
        for (var i = a.length; i--; ) {
            res[a[i]] = v;
        }
        return res;
    }

    function validate_email(email, or_domain) {
        var is_email = /^[\\w\\.\\-\\+\\=]+\\@(?:\\w[\\w-]*\\.?){1,4}[a-zA-Z]{2,16}$/,
            is_domain_mail = /^\\*\\@(?:\\w[\\w-]*\\.?){1,4}[a-zA-Z]{2,16}$/;

        if (is_email.test(email) || or_domain && is_domain_mail.test(email)) return 1;
        return 0;
    }

    function inflector(num, value1, value2, value3) {
        var reg = /(\d?)(\d)$/,
            arr = reg.exec(num);
        if (arr[1] == '0' || arr[1] == 1 || arr[2] >= 5 || (arr[1] && arr[2] == '0') || arr[0] == '0') {
            return value3;
        } else if (arr[2] == 1) {
            return value1;
        }
        return value2;
    }

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    /*jsl:ignore*/
    function md5(input) {
        var xl;

        var rotateLeft = function (lValue, iShiftBits) {
            return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
        };

        var addUnsigned = function (lX,lY) {
            var lX4, lY4, lX8, lY8, lResult;
            lX8 = (lX & 0x80000000);
            lY8 = (lY & 0x80000000);
            lX4 = (lX & 0x40000000);
            lY4 = (lY & 0x40000000);
            lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
            if (lX4 & lY4) {
                return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
            }

            if (lX4 | lY4) {
                if (lResult & 0x40000000) {
                    return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
                } else {
                    return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
                }
            } else {
                return (lResult ^ lX8 ^ lY8);
            }
        };

        var _F = function (x,y,z) { return (x & y) | ((~x) & z); };
        var _G = function (x,y,z) { return (x & z) | (y & (~z)); };
        var _H = function (x,y,z) { return (x ^ y ^ z); };
        var _I = function (x,y,z) { return (y ^ (x | (~z))); };

        var _FF = function (a,b,c,d,x,s,ac) {
            a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac));
            return addUnsigned(rotateLeft(a, s), b);
        };

        var _GG = function (a,b,c,d,x,s,ac) {
            a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac));
            return addUnsigned(rotateLeft(a, s), b);
        };

        var _HH = function (a,b,c,d,x,s,ac) {
            a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac));
            return addUnsigned(rotateLeft(a, s), b);
        };

        var _II = function (a,b,c,d,x,s,ac) {
            a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac));
            return addUnsigned(rotateLeft(a, s), b);
        };

        var convertToWordArray = function (input) {
            var lWordCount;
            var lMessageLength = input.length;
            var lNumberOfWords_temp1=lMessageLength + 8;
            var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
            var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
            var lWordArray=new Array(lNumberOfWords-1);
            var lBytePosition = 0;
            var lByteCount = 0;
            while ( lByteCount < lMessageLength ) {
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (input.charCodeAt(lByteCount)<<lBytePosition));
            lByteCount++;
            }
            lWordCount = (lByteCount-(lByteCount % 4))/4;
            lBytePosition = (lByteCount % 4)*8;
            lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
            lWordArray[lNumberOfWords-2] = lMessageLength<<3;
            lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
            return lWordArray;
        };

        var wordToHex = function (lValue) {
            var wordToHexValue="",wordToHexValue_temp="",lByte,lCount;
            for (lCount = 0;lCount<=3;lCount++) {
            lByte = (lValue>>>(lCount*8)) & 255;
            wordToHexValue_temp = "0" + lByte.toString(16);
            wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length-2,2);
            }
            return wordToHexValue;
        };

        var x=[],
            k,AA,BB,CC,DD,a,b,c,d,
            S11=7, S12=12, S13=17, S14=22,
            S21=5, S22=9 , S23=14, S24=20,
            S31=4, S32=11, S33=16, S34=23,
            S41=6, S42=10, S43=15, S44=21;

        input = $.utf8_encode(input);
        x = convertToWordArray(input);
        a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

        xl = x.length;
        for (k=0;k<xl;k+=16) {
            AA=a; BB=b; CC=c; DD=d;
            a=_FF(a,b,c,d,x[k+0], S11,0xD76AA478);
            d=_FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
            c=_FF(c,d,a,b,x[k+2], S13,0x242070DB);
            b=_FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
            a=_FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
            d=_FF(d,a,b,c,x[k+5], S12,0x4787C62A);
            c=_FF(c,d,a,b,x[k+6], S13,0xA8304613);
            b=_FF(b,c,d,a,x[k+7], S14,0xFD469501);
            a=_FF(a,b,c,d,x[k+8], S11,0x698098D8);
            d=_FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
            c=_FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
            b=_FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
            a=_FF(a,b,c,d,x[k+12],S11,0x6B901122);
            d=_FF(d,a,b,c,x[k+13],S12,0xFD987193);
            c=_FF(c,d,a,b,x[k+14],S13,0xA679438E);
            b=_FF(b,c,d,a,x[k+15],S14,0x49B40821);
            a=_GG(a,b,c,d,x[k+1], S21,0xF61E2562);
            d=_GG(d,a,b,c,x[k+6], S22,0xC040B340);
            c=_GG(c,d,a,b,x[k+11],S23,0x265E5A51);
            b=_GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
            a=_GG(a,b,c,d,x[k+5], S21,0xD62F105D);
            d=_GG(d,a,b,c,x[k+10],S22,0x2441453);
            c=_GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
            b=_GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
            a=_GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
            d=_GG(d,a,b,c,x[k+14],S22,0xC33707D6);
            c=_GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
            b=_GG(b,c,d,a,x[k+8], S24,0x455A14ED);
            a=_GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
            d=_GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
            c=_GG(c,d,a,b,x[k+7], S23,0x676F02D9);
            b=_GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
            a=_HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
            d=_HH(d,a,b,c,x[k+8], S32,0x8771F681);
            c=_HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
            b=_HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
            a=_HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
            d=_HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
            c=_HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
            b=_HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
            a=_HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
            d=_HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
            c=_HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
            b=_HH(b,c,d,a,x[k+6], S34,0x4881D05);
            a=_HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
            d=_HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
            c=_HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
            b=_HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
            a=_II(a,b,c,d,x[k+0], S41,0xF4292244);
            d=_II(d,a,b,c,x[k+7], S42,0x432AFF97);
            c=_II(c,d,a,b,x[k+14],S43,0xAB9423A7);
            b=_II(b,c,d,a,x[k+5], S44,0xFC93A039);
            a=_II(a,b,c,d,x[k+12],S41,0x655B59C3);
            d=_II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
            c=_II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
            b=_II(b,c,d,a,x[k+1], S44,0x85845DD1);
            a=_II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
            d=_II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
            c=_II(c,d,a,b,x[k+6], S43,0xA3014314);
            b=_II(b,c,d,a,x[k+13],S44,0x4E0811A1);
            a=_II(a,b,c,d,x[k+4], S41,0xF7537E82);
            d=_II(d,a,b,c,x[k+11],S42,0xBD3AF235);
            c=_II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
            b=_II(b,c,d,a,x[k+9], S44,0xEB86D391);
            a=addUnsigned(a,AA);
            b=addUnsigned(b,BB);
            c=addUnsigned(c,CC);
            d=addUnsigned(d,DD);
        }

        var temp = wordToHex(a)+wordToHex(b)+wordToHex(c)+wordToHex(d);

        return temp.toLowerCase();
    }
    /*jsl:end*/

    function utf8_encode ( argString ) {
    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");

    var utftext = "";
    var start, end;
    var stringl = 0;

    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;

        if (c1 < 128) {
        end++;
        } else if (c1 > 127 && c1 < 2048) {
        enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
        enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
        if (end > start) {
            utftext += string.substring(start, end);
        }
        utftext += enc;
        start = end = n+1;
        }
    }

    if (end > start) {
        utftext += string.substring(start, string.length);
    }

    return utftext;
    }

    function xor_str(s, key) {
        var res = '';
        for(var i = s.length; i--; ) {
            res = String.fromCharCode(key^str.charCodeAt(i)) + res;
        }
        return res;
    }

    function decrypt_str(s, key){
        var res = '';
        for (var i = s.length; i--; ) {
            res = String.fromCharCode(key^s.charCodeAt(i)) + res;
        }
        return res;
    }

    /**
     *  Field Notice
     *
     *  Add hide/show helping text on input, like in the search form in the corner of firefox
     *
     *
     *         / Vitaliy Yanchuk (vitalik@mail.ua)
     *  Authors
     *         \ Igor Korchinskiy (zantor@mail.ua)
     *
     *
     *
     *
     * Example:
     * -------
     *
     * $("#search_input").field_motice('Search frase ...');
     *
     *
     *
     * If no parameters given for string it will take it from inputs title
     *
     * Can work with multiple elements
     * $(".my_input_class").field_notice();
     *
     *
     */
    function field_notice(txt) {
        return this.filter(':text').each(function(){

            var $this = $(this),
                notice_style = 'field_notice',
                notice = $this.prev('.'+notice_style);

            if (txt) {
                $this.attr('title', txt);
            } else if ($this.attr('title')) {
                txt = $this.attr('title');
            }

            if (notice.size()) {
                notice.text(txt);
            } else {
                notice = $('<div class="'+ notice_style +'" />').text(txt).
                    insertBefore($this).
                    css({
                        'position': 'absolute',
                        'line-height': $this.outerHeight() + 'px',
                        'width': $this.outerWidth()  + 'px',
                        'height': $this.outerHeight() + 'px',
                        'font-size': $this.css('font-size'),
                        'text-indent': $this.css('border-left-width'),
                        'font-family': $this.css('font-family')
                    }).bind('click.field_notice', function(){
                        notice.hide();
                        $this.focus();
                    });

                $this.bind('blur.field_notice', function(){
                    notice[$this.val().length?'hide':'show']();
                }).bind('focus.field_notice', function(){
                    notice.hide();
                }).triggerHandler('blur.field_notice');
            }
        });
    }

    function htmlescape(s) {
        s && s.toString && (s = s.toString());
        if (!s) return '';
        var entities = ['&quot;', '"', '&#039;', "'", '&lt;', '<', '&gt;', '>', '&amp;', '&'];
        for (var i = entities.length; i--; ) s = s.split(entities[i]).join(entities[--i]);
        return s;
    }

    $.fn.extend({
        field           : field,
        key_filter      : key_filter ,
        check_disabled  : check_disabled,
        field_notice    : field_notice
    });

    $.extend({
        qw2h                  : qw2h,
        text2anchor           : text2anchor,
        clear_anchor_redirect : clear_anchor_redirect,
        html2text             : html2text,
        text2html             : text2html,
        parseJSON             : parseJSON,
        obj2str               : obj2str,
        muaJSON               : muaJSON,
        lang                  : lang,
        take_lang             : take_lang,
        is_supported_browser  : is_supported_browser,
        validate_email        : validate_email,
        inflector             : inflector,
        md5                   : md5,
        utf8_encode           : utf8_encode,
        xor_str               : xor_str,
        decrypt_str           : decrypt_str,
        htmlescape            : htmlescape,
        'int'                 : function (s) {
            return parseInt(s, 10) || 0;
        }
    });

})(jQuery);
