/**
 * Ajax-функции.
 */
function ajax_show(content) {
  $('div.wrapper_full_layer').remove();
  $('div.wrapper_content_layer').remove();
  $('body').append('<div id="wrapper_full" class="wrapper_full_layer" style="display: none;" title="Скрыть окно" onclick="ajax_hide();"></div><div id="wrapper_content" class="wrapper_content_layer" style="display: none;">'+content+'</div>');
  var wrapper_full_height = ($(document).height() > $('body').height()) ? $(document).height() : $('body').height();
  var wrapper_content_top = $(document).scrollTop() + 0.5*$(window).height() - 0.5*$('div#wrapper_content').height();
  $('div#wrapper_full').css({display: 'block', height: wrapper_full_height+'px'});
  $('div#wrapper_content').css({top: wrapper_content_top+'px', left: '50%', marginLeft: -0.5*$('div#wrapper_content').width()});
  $('div#wrapper_content').show();
}
function ajax_hide() {
  $('div.wrapper_full_layer').remove();
  $('div.wrapper_bar_layer').remove();
  $('div.wrapper_content_layer').hide(function() {
    $(this).remove();
  });
}
function ajax_content(content) {
  ajax_show(content);
}

/**
 * Функции валидации.
 */
function is_url(str) {
	return is_pattern("^https?:\\/\\/(?:[a-z0-9_-]{1,32}(?::[a-z0-9_-]{1,32})?@)?(?:(?:[a-z0-9-]{1,128}\\.)+(?:com|net|org|mil|edu|arpa|gov|biz|info|aero|inc|name|[a-z]{2})|(?!0)(?:(?!0[^.]|255)[0-9]{1,3}\\.){3}(?!0|255)[0-9]{1,3})(?:\\/[a-z0-9.,_@%&?+=\\~\\/-]*)?(?:#[^ '\"&<>]*)?$", str.toLowerCase());
}
function is_numeric(str) {
	return is_pattern("^[0-9]+$", str);
}
function is_integer(str) {
	return is_numeric(str);
}
function is_float(str) {
	return is_pattern("^[1-9]?[0-9]+(\\.[0-9]+)?$", str);
}
function is_email(str) {
	return is_pattern("^([a-z0-9_-]+)(\\.[a-z0-9_-]+)*@((([a-z0-9-]+\\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2}))|([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}))$", str.toLowerCase());
}
function is_pattern(pattern, str) {
	if(str.length && pattern.length) {
		var re = new RegExp(pattern, "g");
		return re.test(str);
	}
	return false;
}
