	
	current_form = '';
	
	$(document).ready(function(){
	  var options = { 
		success: showResponse,
		beforeSubmit: showRequest,
		dataType: 'json'
	  };
	  $('#sending_form').submit(function() {
	  	current_form = $(this);
	    $(this).ajaxSubmit(options); 
	    return false;
	  }); 
	});
	
	$(document).ready(function(){
	  var options = {
		success: showResponseTweet,
		beforeSubmit: beforeSubmitTweet,
		dataType: 'json'
	  };
	  $('#addtweet').submit(function() {
	  	current_form = $(this);
	    $(this).ajaxSubmit(options); 
	    return false;
	  }); 
	});
	
	$(document).ready(function(){
	  var options = {
		success: showResponseFotoComment,
		beforeSubmit: showCommentLoading,
		dataType: 'json'
	  };
	  $('#addfotocomment').submit(function() {
	  	current_form = $(this);
	    $(this).ajaxSubmit(options); 
	    return false;
	  }); 
	});
	
	$(document).ready(function(){
	  var options = {
		success: showResponseLoveMsg,
		dataType: 'json'
	  };
	  $('#lovemsg_form').submit(function() {
	  	current_form = $(this);
	    $(this).ajaxSubmit(options); 
	    return false;
	  }); 
	});
	
	
	function showCommentLoading()
		{
		$("#loading_img_comment").fadeIn("fast");
		}
	
	function beforeSubmitTweet()
		{
		current_form.hide("slow");
		}
	
	function showResponseLoveMsg(json)
		{
		
		if (json.type == 'success')
			{
			current_form.clearForm();
			
			$("#addlovemsg_msg").html('<div class="umsg_alert" id="output_addlovemsg_msg">'+json.msg+'</div>');
			
			$("#addlovemsg").hide("slow");
			}
		else
			{
			//current_form.show("slow");
			$("#addlovemsg_msg").html('<div class="umsg_error" id="output_addlovemsg_msg">'+json.msg+'</div>');
			setTimeout(hide_msg_lovemsg, 3000);
			}
		//
		//setTimeout(add_new_tweet, 3000);
		}
	
	function hide_msg_lovemsg()
		{
		$("#output_addlovemsg_msg").hide("slow");
		}
	
	function showResponseTweet(json)
		{
		
		if (json.type == 'success')
			{
			current_form.clearForm();
			
			$("#addtweet_msg").html('<div class="umsg_alert" id="output_addtweet_msg">'+json.msg+'</div>');
						
			var tmpl = "<tr bgcolor=\"#DDEEFF\"><td class=\"foto_list\">"+json.foto+"</td><td>"+json.username+"</td><td>"+json.tweet+"</td></tr>";
			
			$("#tweetslist").prepend(tmpl); 
			}
		else
			{
			current_form.show("slow");
			$("#addtweet_msg").html('<div class="umsg_error" id="output_addtweet_msg">'+json.msg+'</div>');
			}
		setTimeout(hide_msg_tweet, 3000);
		setTimeout(add_new_tweet, 3000);
		}
	
	function add_new_tweet()
		{
		$("#addtweet").show("slow");
		twitt_length();
		}
	
	function showResponseFotoComment(json)
		{
		$("#loading_img_comment").fadeOut("fast");
		if (json.type == 'success')
			{
			current_form.clearForm();
			current_form.hide("slow");
			$("#addfotocomment_msg").html('<div class="umsg_alert" id="output_addfotocomment_msg">'+json.msg+'</div>');
			
			var tmpl = "<tr bgcolor=\"#DDEEFF\"><td class=\"foto_list\" width=\"100\">"+json.foto+"</td><td width=\"150\">"+json.username+"</td><td>"+json.rezult+"</td></tr>";
			$("#fotocomments").prepend(tmpl); 
			}
		else
			{
			$("#addfotocomment_msg").html('<div class="umsg_error" id="output_addfotocomment_msg">'+json.msg+'</div>');
			}
		setTimeout(hide_msg_fotocomment, 3000);
		setTimeout(add_new_comment, 3000);
		}
	
	function add_new_comment()
		{
		current_form.show("slow");
		}
	
	function showResponse(json)
		{
		
		if (json.type == 'success')
			{
			current_form.clearForm();
			current_form.hide("slow");
			$("#output").html('<div class="umsg_alert" id="outputmsg">'+json.msg+'</div>');
			}
		else
			{
			$("#output").html('<div class="umsg_error" id="outputmsg">'+json.msg+'</div>');
			current_form.find("#str_key").clearFields();
			setTimeout(hide_msg, 3000);
			}
		}
		
	function hide_msg_tweet()
		{
		$("#output_addtweet_msg").hide("slow");
		$("#tweetslist tr").attr("bgcolor","#ffffff");
		}
		
	function hide_msg_fotocomment()
		{
		$("#output_addfotocomment_msg").hide("slow");
		$("#fotocomments tr").attr("bgcolor","#ffffff");
		}
	
	function hide_msg()
		{
		$("#outputmsg").animate({ opacity: "0" }, "slow");
		}
	
	$(document).ready(function(){
		$(".text_input").focus(function(){
		$(this).prev().animate({ opacity: "hide" }, "fast");
		});
			
		$(".text_input").hover(function(){
			$(this).prev().animate({ opacity: "hide" }, "fast");
		});
	});
	
	function showRequest(formData, jqForm, options)
		{
		func_return = true;
		
		current_form.find(".check_empty").each( function(i, elem)
			{
			if (elem.value == "")
				{
				$(elem).prev().fadeIn("fast");
				func_return = false;
				}
			}
		);
		
		current_form.find(".check_email").each( function(i, elem)
			{
			if (!isValidEmail(elem.value))
				{
				$(elem).prev().fadeIn("fast");
				func_return = false;
				}
			}
		);
		
		current_form.find(".check_int").each( function(i, elem)
			{
			if (!isValidNumber(elem.value))
				{
				$(elem).prev().fadeIn("fast");
				func_return = false;
				}
			}
		);
		return func_return;
		}
	
function isValidEmail(email)
	{
	return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
	}
	
function isValidPhone(tel)
	{
	return (/^([0-9- ()+,]){6,200}$/i).test(tel);
	}	

function isValidNumber(num)
	{
	return (/^([0-9]){1,10}$/i).test(num);
	}		
	
function reload_kaptcha(src)
	{
	document.getElementById('kaptcha').src= src + '&id='+(new Date()).getTime();
	}
