	$(function() {
				
			var user_name = $("#user_name"),
			email = $("#email"),
			mess = $("#mess"),
			allFields = $([]).add(user_name).add(email),
			tips = $("#validateTips");
	
	
		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				//updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				updateTips("Моля попълнете полето " + n + ".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			width: 600,
			height: 400,
			modal: true,
			buttons: {
				'Изпрати': function() {
					
					var bValid = true;
					allFields.removeClass('ui-state-error');
					bValid = bValid && checkLength(user_name,"Име",3,16);
					bValid = bValid && checkLength(email,"Е-поща",6,80);
					//bValid = bValid && checkLength(mess,"Съобщение",6,80);
					
					
					if (bValid) {
						
						
						$.ajax({
							   
							  
							   
							   type: "POST",
							   url: "send_link.php",
							   data: "from="+$("#user_name").val()+"&email="+$("#email").val()+"&mess="+$("#mess").val()+"",
							   success: function(html){
																
								alert(html);
							   //$("#results_"+u+"").html('');	   
							   //$("#results_"+u+"").append(html);
							   
							   //setTimeout(function(){
							   //$("#container_"+u+"").slideUp();
							   //},3000);
							   
							
							   }
							 });
											
						//$(this).dialog('close');
					}
				},
				'Затвори': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		
		
		$('#create-user').click(function() {
										
			$('#dialog').dialog('open');
			
		})
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		).mousedown(function(){
			$(this).addClass("ui-state-active"); 
		})
		.mouseup(function(){
				$(this).removeClass("ui-state-active");
		});

	});