function showRequest(formData, jqForm, options) {
	//$('#addCommentResult').html('<strong>Trwa przetwarzanie danych</strong> <img src="/leszekkrutulski.pl/trunk/szablon/02/mod/comments/img/ajax-loader2.gif">');
	var width = $("#formularz").width();
	var height = $("#formularz").height();
	$('#formularz').append('<div id="loading" style="background-color: #f2f2f2; filter: alpha(opacity=50); -moz-opacity: 0.5; opacity: 0.5; position: absolute; width: '+ width +'px; height: '+ height +'px; "><table width="'+ width +'" height="'+ height +'"><tr><td style="text-align: center; vertical-align: middle;"><img src="/szablon/03/img/loadingAnimation.gif"/></td></tr></table></div>');	 
    return true; 
} 
  
function showResponse(responseText, statusText)  {      
    $('#formularz').html(responseText);             
}

function proccedJson(data) {	
	$('#loading').remove();		
	$('#addCommentResult').html(data.komunikat);
	$('#addCommentResult').show();
		
	if ( data.pola ) {	
		for ( i = 0; i < data.pola.length; i++ ) {		
			$('#' + data.pola[i]).css('border', '2px solid red');
			if ( data.pola[i] == 'captcha' ) { 
				odswiezCaptcha(data.sciezka);
				$('#' + data.pola[i]).css('border', '2px solid red');
			}
		}
	} else {		
		$(':input[name^="formularz"]').css('border', 'none');
		$(':input[name^="formularz"]').val('');
		odswiezCaptcha(data.sciezka);
	}					
}
 
function pokazListe(warstwa, img, adres) {
	$('#commentsContent').hide();	
	$('#commentsTabList').attr('class', '');
	$('#commentsTabAdd').attr('class', 'off');		
	$('#' + warstwa).toggle();
	
	pobierzKomentarze(adres);	
}  
 
function pokazFormularz(warstwa, img) {	
	$('#showComments').hide();	
	$('#commentsTabList').attr('class', 'off');
	$('#commentsTabAdd').attr('class', '');	
	$('#' + warstwa).toggle();	
} 
 
$(document).ready(function() { 
	$('#showComments').hide();
	var options = {          
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       proccedJson,  // post-submit callback 
 
         
        dataType:  'json'       // 'xml', 'script', or 'json' (expected server response type)          
    };
		
    // bind 'myForm' and provide a simple callback function     
    $('#userInfo').ajaxForm(options); 
});

function czysc(element) {
	$('#' + element).attr('value','');
	$('#' + element).css('border','1px solid #d9d9d9');
}

function odswiezCaptcha(sciezka) {
 	$.post(sciezka + 'index.php?modul=PubECmsGaleria&akcja=odswiezCaptcha', function(response){
 		$('.captcha').html(response);
 	});
}

function xhr( adres ) {
	
	var width = $("#formularz").width();
	var height = $("#formularz").height();
	
	$("#formularz").ajaxStart(function(){
   		$(this).append('<div style="background-color: #CCCCCC; filter: alpha(opacity=50); -moz-opacity: 0.5; opacity: 0.5; position: absolute; width: '+ width +'px; height: '+ height +'px; text-align: center; vertical-align: middle; "><img src="/szablon/03/img/loadingAnimation_.gif"></div>');
 	});

	$.post(adres, function(response){
		//$("#loading").html('');
 		$('#formularz').html(response);
		tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
		imgLoader = new Image();// preload image
		imgLoader.src = tb_pathToImage; 		
 	});
}
