//**************************************************
$(document).ready(
	function() 
		{ 
			$("input[type^=text], input[type^=file], textarea,  input[type^=password]").focus( function()
				{
					$(this).css("border-color", "#aaa");
					//$(this).css("background", "url(img/inputbg.png) #FFFFFF repeat-x");
				}
			);
			$("input[type^=text], input[type^=file], textarea,  input[type^=password]").blur( function()
				{
					$(this).css("border-color", "#ccc");
					//$(this).css("background", "#fff");
				}
			);
			
			$('.spoiler-body').prev('.dtitle').click(function(){
				if($(this).next('.spoiler-body:visible').length > 0) {
					$(this).next().hide();
				} else {
					$('.spoiler-body').hide();
					$(this).next().show();
				}
			});
			
			function response(responseText, statusText)
				{
					$('.form .loader').hide();
				}
				//--------------------------------------------------------------------------		  
				  $("#regform").validate({
				  	submitHandler: function(form)
					{
				   	  var options = {success: response, target: '#reg .content', timeout: 3000};
					  $('.form .loader').show();
				  	  $(form).ajaxSubmit(options);
				    },
				    focusInvalid: false,
				    focusCleanup: false,
				    rules: {
				      email: {
				      	required: true,
				      	email: true,
						remote: "reg/users.php"
				      },
				      pass1: {
				      	required: true,
				      	rangelength: [6, 12]
				      },
				      pass2: {
				      	required: true,
						rangelength: [6, 12],
						equalTo: "#pass1"
				      }
				    },
				    messages: {
				      email: {
				        required: "Укажите email адрес",
				        email: "Укажите корректный email адрес",
						remote: "Такой адрес уже зарегистрирован"
				      },
				      pass1: {
				      	required: "Укажите пароль",
						rangelength: "Пароль - от 6 до 12 символов"
				      },
				      pass2: {
				      	required: "Подтвердите пароль",
						rangelength: "Пароль - от 6 до 12 символов",
						equalTo: "Подтверждение пароля не совпадает"
				      }
				    },
				    errorPlacement: function(error, element) {
				      var er = element.attr("name");
				      error.appendTo(element.parent().find("em#label" + er));
					  //alert(error);
				    }
				});
				// ---- Форма -----
				$("#remform").validate({
				  	submitHandler: function(form)
					{
					  var options = {success: response, target: '#rem .content', timeout: 3000};
					  $('.form .loader').show();
				  	  $(form).ajaxSubmit(options);
				    },
				    focusInvalid: false,
				    focusCleanup: false,
				    rules: {
				      email: {
				      	required: true,
				      	email: true
				      }
				    },
				    messages: {
				      email: {
				        required: "Укажите email адрес",
				        email: "Укажите корректный email адрес"
				      }
				    },
				    errorPlacement: function(error, element) {
				      var er = element.attr("name");
				      error.appendTo(element.parent().find("em#label" + er));
				    }
				});
		} 
	);
	
function showform(form)
	{
		$('#bg').css('height', $('body').css('height')).show();
		$('#' + form + '.form').fadeIn('fast');
		return false;
	}		
function hideform(form)
	{
		$('#' + form + '.form').fadeOut('fast');
		//$('#' + form + '.form .content').empty();
		$('#bg').hide();
		return false;
	}

