

	function hideKom(id)
	{
		$('.komunikat_class').fadeOut();
		$('#komunikat_text').hide();
		if(id!='')
		{
			$(id).focus();
			$(id).css({'border':'1px solid #ae0000'});
		}
	}
	function sendForm(form, div)
	{			
			$(form+' :input').each(function(){
									if($(this).attr('name')!='submit'){
											$(this).css({'border':'1px solid #9e9e9e'});
										}
										});
			$(".komunikat_class").ajaxStart(function(){
			$(this).fadeIn("normal");
			$('#loader').show();
			});
			$("#loader").ajaxStop(function() {
			$(this).hide();
});
			var now	 = new Date();
			var url = $(form).attr('action');
			var met = $(form).attr('method');				
			var data;
			$(form+' :input').each
			(
				function (elementIndex)
				{
					var name = $(this).attr('name');
					var value = $(this).val();
					
					if(name=='add_klient_niski'||name=='add_klient_nie_parter'||name=='add_klient_nie_ostatnie'||name=='add_klient_kredyt'){
						if(!$('#'+name).is(':checked')){
							value = 'nie';
						}
					}
					if (data == null)
						data = name+'='+value;
					else
						data += '&'+name+'='+value;
				}
			);
			$.ajax
			(
				{					
					type: met,
					url: url,
					data: data,
 
					error: function (XMLHttpRequest, textStatus, errorThrown)
					{
						$("#error").show();
						$("#error").append('Błąd obiektu o nazwie:'+XMLHttpRequest+'<br />Komunikat:'+textStatus+'<br />Rodzaj:'+ errorThrown);
					},
					success: function(html)
					{
						$(div).html(html);
						$("#komunikat_5").click(function(){
							hideKom("#telefon");
						});
						$("#komunikat_7").click(function(){
							hideKom("#mail");
						});
						$("#komunikat_8").click(function(){
							hideKom("#wiadomosc2");
						});
						$("#komunikat_1").click(function(){
							hideKom('#kod');
							$('#token').attr('src','send.php?'+now.getTime());
						});
						$("#komunikat_3").click(function(){
							hideKom();
							
							$('#token').attr('src','send.php?'+now.getTime());
							$(form+' :input').each(function(){
									var type = this.type;
									var tag = this.tagName.toLowerCase();
									if (type == 'text' || tag == 'textarea')
										this.value = "";
								}
							);
							$("#form_add_klient, #mail_kontak").expose({api: true, closeSpeed: 'slow'}).close()
						});
					}
				}
			); 
	}

$(document).ready(function(){
	
	//wyróżnienie formularza plugin-expose
	$("#form_add_klient, #mail_kontak").click(function() { 
		$(this).expose({api: true, maskId:'mask', closeSpeed: 'slow', opacity: 0.5}).load(); 
	});

//zmiana kodu obrazkowego
	$('#token').click(function(){
		var token = new Date();
		$(this).attr('src','send.php?'+token.getTime())
	});
	//ukryj komunikat
	$(".komunikat_class").hide();
	//wyślij formularz
	$("#poszukuje").submit(function(){
		sendForm("#poszukuje", "#kom");
		return false;
	});
	$("#send_mail").submit(function(){
	sendForm("#send_mail", "#kom");
	 return false;
});
});


