function is_valid_mail(mail){
    return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(mail);
}

function print_r( array, return_val ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Michael White (http://getsprink.com)
    // +   improved by: Ben Bryan
    // *     example 1: print_r(1, true);
    // *     returns 1: 1

    var output = "", pad_char = " ", pad_val = 4;

    var formatArray = function (obj, cur_depth, pad_val, pad_char) {
        if (cur_depth > 0) {
            cur_depth++;
        }

        var base_pad = repeat_char(pad_val*cur_depth, pad_char);
        var thick_pad = repeat_char(pad_val*(cur_depth+1), pad_char);
        var str = "";

        if (obj instanceof Array || obj instanceof Object) {
            str += "Array\n" + base_pad + "(\n";
            for (var key in obj) {
                if (obj[key] instanceof Array) {
                    str += thick_pad + "["+key+"] => "+formatArray(obj[key], cur_depth+1, pad_val, pad_char);
                } else {
                    str += thick_pad + "["+key+"] => " + obj[key] + "\n";
                }
            }
            str += base_pad + ")\n";
        } else if(obj == null || obj == undefined) {
            str = '';
        } else {
            str = obj.toString();
        }

        return str;
    };

    var repeat_char = function (len, pad_char) {
        var str = "";
        for(var i=0; i < len; i++) {
            str += pad_char;
        };
        return str;
    };
    output = formatArray(array, 0, pad_val, pad_char);

    if (return_val !== true) {
        document.write("<pre>" + output + "</pre>");
        return true;
    } else {
        return output;
    }
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };

    return sa ? s : s[0];
}
function empty( mixed_var ) {    // Determine whether a variable is empty
	//
	// +   original by: Philippe Baumann

	return ( mixed_var === "" || mixed_var === 0   || mixed_var === "0" || mixed_var === null  || mixed_var === false  ||  ( is_array(mixed_var) && mixed_var.length === 0 ) );
}

function json_decode(str_json) {
	// http://kevin.vanzonneveld.net
	// +      original by: Public Domain (http://www.json.org/json2.js)
	// + reimplemented by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// *     example 1: json_decode('[\n    "e",\n    {\n    "pluribus": "unum"\n}\n]');
	// *     returns 1: ['e', {pluribus: 'unum'}]

	/*
        http://www.JSON.org/json2.js
        2008-11-19
        Public Domain.
        NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
        See http://www.JSON.org/js.html
    */

	var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
	var j;
	var text = str_json;

	var walk = function(holder, key) {
		// The walk method is used to recursively walk the resulting structure so
		// that modifications can be made.
		var k, v, value = holder[key];
		if (value && typeof value === 'object') {
			for (k in value) {
				if (Object.hasOwnProperty.call(value, k)) {
					v = walk(value, k);
					if (v !== undefined) {
						value[k] = v;
					} else {
						delete value[k];
					}
				}
			}
		}
		return reviver.call(holder, key, value);
	}

	// Parsing happens in four stages. In the first stage, we replace certain
	// Unicode characters with escape sequences. JavaScript handles many characters
	// incorrectly, either silently deleting them, or treating them as line endings.
	cx.lastIndex = 0;
	if (cx.test(text)) {
		text = text.replace(cx, function (a) {
			return '\\u' +
			('0000' + a.charCodeAt(0).toString(16)).slice(-4);
		});
	}

	// In the second stage, we run the text against regular expressions that look
	// for non-JSON patterns. We are especially concerned with '()' and 'new'
	// because they can cause invocation, and '=' because it can cause mutation.
	// But just to be safe, we want to reject all unexpected forms.

	// We split the second stage into 4 regexp operations in order to work around
	// crippling inefficiencies in IE's and Safari's regexp engines. First we
	// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
	// replace all simple value tokens with ']' characters. Third, we delete all
	// open brackets that follow a colon or comma or that begin the text. Finally,
	// we look to see that the remaining characters are only whitespace or ']' or
	// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
	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, ''))) {

		// In the third stage we use the eval function to compile the text into a
		// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
		// in JavaScript: it can begin a block or an object literal. We wrap the text
		// in parens to eliminate the ambiguity.

		j = eval('(' + text + ')');

		// In the optional fourth stage, we recursively walk the new structure, passing
		// each name/value pair to a reviver function for possible transformation.

		return typeof reviver === 'function' ?
		walk({
			'': j
		}, '') : j;
	}

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

function is_array( mixed_var ) {
	// http://kevin.vanzonneveld.net
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   improved by: Legaev Andrey
	// +   bugfixed by: Cord
	// +   bugfixed by: Manish
	// +   improved by: Onno Marsman
	// %        note 1: In php.js, javascript objects are like php associative arrays, thus JavaScript objects will also
	// %        note 1: return true
	// *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
	// *     returns 1: true
	// *     example 2: is_array('Kevin van Zonneveld');
	// *     returns 2: false
	// *     example 3: is_array({0: 'Kevin', 1: 'van', 2: 'Zonneveld'});
	// *     returns 3: true
	// *     example 4: is_array(function tmp_a(){this.name = 'Kevin'});
	// *     returns 4: false

	var key = '';

	if (!mixed_var) {
		return false;
	}

	if (typeof mixed_var === 'object') {

		if (mixed_var.hasOwnProperty) {
			for (key in mixed_var) {
				// Checks whether the object has the specified property
				// if not, we figure it's not an object in the sense of a php-associative-array.
				if (false === mixed_var.hasOwnProperty(key)) {
					return false;
				}
			}
		}

		// Uncomment to enable strict JavsScript-proof type checking
		// This will not support PHP associative arrays (JavaScript objects), however
		// Read discussion at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_is_array/
		//
		//  if (mixed_var.propertyIsEnumerable('length') || typeof mixed_var.length !== 'number') {
		//      return false;
		//  }

		return true;
	}

	return false;
}
//transliteration
  var ru2en = { 
    ru_str : "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя ", 
    en_str : ['A','B','V','G','D','E','JO','ZH','Z','I','J','K','L','M','N','O','P','R','S','T',
      'U','F','H','C','CH','SH','SHH',String.fromCharCode(35),'I',String.fromCharCode(39),'JE','JU',
      'JA','a','b','v','g','d','e','jo','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f',
      'h','c','ch','sh','shh',String.fromCharCode(35),'i',String.fromCharCode(39),'je','ju','ja','_'], 
    translit : function(org_str) { 
      var tmp_str = ""; 
      
      for(var i = 0 ; i < org_str.length ; i++) { 
        var s = org_str.charAt(i), n = this.ru_str.indexOf(s); 
        if(n >= 0) { tmp_str += this.en_str[n]; } 
        else { tmp_str += s; } 
      } 
      return tmp_str; 
    } 
  }
  
