$(document).ready(function (){
	var overlay = $(document.createElement('div'))
					.css({position: 'absolute', 
					  	  top: 0, 
						  left: 0, 
						  width: $(document).width(), 
						  height: $(document).height(),
						  zIndex: 10,
						  background: '#000000',
						  opacity: 0.2});

	$("a.order").click(function (){
		if ($("#forma").css('display')=='block') return;
		$("#forma").css({left:"50%",marginLeft:-250}).fadeIn(100);
		$('body').append(overlay);
		
		overlay.click(function (){
			$("#forma").fadeOut(300);
			overlay.remove();
		});
		
	});
	
	$("a#close").click(function (){
		$("#forma").fadeOut(300);
		overlay.remove();
		return false;
	});
	
	$('.text').focus(function(){
		var old_value = this.getAttribute('old_value');
		if(old_value==null)
		{
			this.setAttribute('old_value',this.value);
			old_value = this.value;
		}
		if(old_value==this.value)
			this.value = '';
	});
	$('.text').blur(function(){
		if(this.value=='')
			this.value = this.getAttribute('old_value');
	});
	
	function check_input(id,field)
	{
		$val = $('#'+id).val();
		if($val=='' || $val==field)
		{
			alert('Заполните поле '+field);
			return false;
		}
		return true;
	}
	
	$("#forma").submit(function(){
		if(!check_input('name','ФИО'))
			return false;
		//if(!check_input('org','Название организации'))
		//	return false;
		if(!check_input('phone','Телефон'))
			return false;
		//if(!check_input('email','E-mail'))
		//	return false;
		if(!check_input('message','Текст сообщения'))
			return false;
		return true;
	});
});
