
$(document).ready(function()
{	
	$("#index_menu li").each(function(){
		$(this).hover(function()
			{
				$("#index_road").addClass(this.className);
				$("#index_after_map").addClass(this.className);				
				
			}, function()
			{
				
				$("#index_road").removeClass(this.className);
				$("#index_after_map").removeClass(this.className);
			}
		).css("cursor", "pointer").click(function(){
			document.location = $(this).find("a").get(0).href;
		});;		
	});
	
	$("form").each( function(){ $(this).formValidator();} );
	
});


function feedbackFormInit(form){
	return;
}


/*****************************************************************************/

/**
* Плагин для jQuery. Валидирует форму.
* работает так:
* $("#myForm").formValidator();
* После чего все значения тектовых полей обозначают их названия.
* Если вконце названия стоит * - это обязательное поле.
* после * может быть текст, отделенны  двумя палками //
* Пример :   Имя и Фамилия* //Ссюда вводятся ФИО
**/


(function($){
	$.fn.formValidator = function(options)
	{
		var settings = $.extend({
			error_massg: "Вы не заполнили %field%"
		},options||{});
		$(this).find(":text, textarea").each(function(){
			var val = $(this).val();
			val = $.trim(val.replace(/\/\/.+$/g,""));
			//alert(val);
			if(  val.match(/\*$/) ) $(this).attr("no_empty", val);
			$(this).attr("old_value", $(this).val()).focus(function(){
				if($(this).val() == $(this).attr("old_value")) $(this).val("");
			}).blur(function(){
				if( $.trim($(this).val()) == "" ) $(this).val($(this).attr("old_value"));
			});
		});
		$(this).submit(function(){
			var err = true;
			$(this).find(":text,textarea").each(function()
			{
				if( $(this).is("[no_empty]") && (! $(this).val() || $(this).val() == $(this).attr("old_value")) )
				{
					
					var msg = settings.replace(/%field%/, $(this).attr("no_empty").replace(/\*$/,"") );
					alert (msg);
					this.focus();
					err = false
					return false;
				}
				
				//if($(this).val() == $(this).attr("old_value")) $(this).val("");
				
			});
			return err;
		});
		
	}
})(jQuery);