$(document).ready(function ()
{
	$('body').everyTime(60000, ping);
	
	$("#register_form").register_form();
	$("#auth_form").auth_form();
	
	$(".kom:odd").addClass("kom_grey");
	
	// Cat
		$(".cat").click(function ()
		{
			$(".cat").removeClass("cat_activ");
			$(this).addClass("cat_activ");
			
			$(".vkladka").hide();
			$(".vkladka_"+$(this).attr("_name")).removeClass("hid").show();
		});
	// Cat End
	
	$(".hid").hide();
	
	$(".counter_close").click(function ()
	{
		$(".counters_container").css("opacity", 0);
	});
});

temp_img('img/submit_bg_over.png');
temp_img('images/arr_l_over.png');
temp_img('images/arr_r_over.png');
/*temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');
temp_img('img/.png');*/

// Ping
	function ping()
	{
		$.get("ping.php");
	}
// Ping End

// Auth
	jQuery.fn.auth_form=function ()
	{
		// Bg
			$(this).find(".input").each(function ()
			{
				var _bg=$(this).attr("_bg");
				$(this).focus(function ()
				{
					$(this).css('background-image', '');
				}).blur(function ()
				{
					if ($(this).val()=='')
					{
						$(this).css('background-image', 'url(img/'+_bg+')');
					}
				}).css('background-image', 'url(img/'+_bg+')');
			});
		// Bg End
		
		// Submit
			$(this).submit(function ()
			{
				if (($(this).find('#auth_mail').val()=='')||($(this).find('#auth_pass').val()==''))
				{
					alert('Логин и пароль обязательны для заполнения');
					return false;
				}
			});
		// Submit End
		
		return this;
	};
// Auth End


// Register Form
	jQuery.fn.register_form=function ()
	{
		$(this).pass_form();
		
		return this;
	};
// Register Form End

// Pass Form
	jQuery.fn.pass_form=function ()
	{
		var _name=$(this).attr('name');
		
		// Пароль
			var _pass=$(this).find("#input_"+_name+"_pass");
			var _pass2=$(this).find("#input_"+_name+"_pass2");
			
			$(_pass).keyup(function ()
			{
				$(this).closest(".forma_blok").find(".forma_bottom").pass_line($(this).val());
			});
			
			var pass12_prov=function ()
			{
				if ($(_pass2).val()=='') { return; }
				if ($(_pass).val()==$(_pass2).val())
				{
					$(_pass2).closest('.forma_blok').find(".forma_blok_right").html("<img src=\"img/register_ok.png\" border=\"0\" />");
				}
				else
				{
					$(_pass2).closest('.forma_blok').find(".forma_blok_right").html("<img src=\"img/register_no.png\" border=\"0\" />");
				}
			};
			var pass12_prov_up=function ()
			{
				if ($(_pass).val()==$(_pass2).val())
				{
					$(_pass2).closest('.forma_blok').find(".forma_blok_right").html("<img src=\"img/register_ok.png\" border=\"0\" />");
				}
			};
			$(_pass).change(pass12_prov);
			$(_pass2).change(pass12_prov);
			$(_pass2).keyup(pass12_prov_up);
		// Пароль End

		// Submit
			$(this).submit(function ()
			{
				if (($(_pass).val()!=$(_pass2).val()))
				{
					alert('Пароли не совпадают');
					return false;
				}
			});
		// Submit End
		
		return this;
	};
// Pass Form End

// Проверка полей формы
	function register_pole_prov(_input, _name)
	{
		_input=$(_input);
		var _val=$(_input).val();
		var _div=$(_input).closest('.forma_blok').find('.input_prov');
		$(_div).load();
		
		$.getJSON('register_pole_prov.php', {
			pole:_name,
			val:_val
		}, function (ob)
		{
			if (ob.ok)
			{
				$(_div).html("<img src=\"img/register_ok.png\" border=\"0\" />");
			}
			else
			{
				$(_div).html("<div class=\"red\">"+ob.text+"</div>");
			}
		});
	}
// Проверка полей формы End

// Мощность пароля
	jQuery.fn.pass_line=function (text)
	{
		if (text=='')
		{
			$(this).html('');
		}
		else
		{
			var proc=checkPassword(text);
		
			$(this).html("<div class=\"pass_line\"><div class=\"pass_line_proc\"><img src=\"box/spacer.gif\" width=\"1\" height=\"1\" border=\"0\" /></div></div><div class=\"pass_text\"></div>");
			var _line_proc=$(this).find(".pass_line_proc");
			if ($.browser.msie)
			{
				$(_line_proc).css("height", "5px");
			}
			var _line_text=$(this).find(".pass_text");
			var _color;
			var _text;
			if (proc<=30)
			{
				_color="#AA0000";
				_text="Плохой пароль";
			}
			else if (proc<=50)
			{
				_color="#CC9900";
				_text="Нормальный пароль";
			}
			else if (proc<=95)
			{
				_color="#339900";
				_text="Хороший пароль";
			}
			else if (proc>95)
			{
				_color="#339900";
				_text="Отличный пароль";
			}
			$(_line_proc).width(proc).css("background", _color);
			$(_line_text).html(_text);
		}
		
		return this;
	};
// Мощность пароля End

// Person Val
	function person_set_val(_name, _val)
	{
		$.get('person_val.php', {
			name:_name,
			val:_val
		});
	}
// Person Val End

