function sendForm(div, action){
	var form = $("#"+div);
	if(action) form.attr('action', action);
	form.submit();
}

function implode (glue, pieces) {
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];                tGlue = glue;
            }
            return retVal;
        }
    }    else {
        return pieces;
    }
}

(function($) {
     $.fn.errorStyle = function() {
         var oldErrore = this.html();
         var StyledError = "<div class=\"ui-state-error ui-corner-all\" style=\"padding: 2px; margin:0 0 5px 0;\">";
             StyledError += "<p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 3px; margin-top: 0px;\ \">";
             StyledError += "</span><b>";
             StyledError += oldErrore ;
             StyledError += "</b></p></div>";
 this.replaceWith(StyledError );
     }
 })(jQuery);
 
(function($) {
     $.fn.goodStyle = function() {
         var oldErrore = this.html();
         var StyledError = "<div class=\"ui-state-highlight  ui-corner-all\" style=\"padding: 2px; margin:0 0 5px 0;\">";
             StyledError += "<p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 3px; margin-top: 0px;\">";
             StyledError += "</span><b>";
             StyledError += oldErrore ;
             StyledError += "</b></p></div>";
 this.replaceWith(StyledError );
     }
 })(jQuery);



$(document).ready(function(){
	
    $('.tip').mouseover(function(){
  	  var id = this.id;
  	  var tresc = $("#tresc_"+id).html();
  	  
  	  var a = $("#"+id);
	  var offset = a.offset();	
	  
	  $("#info_"+id).remove();
	  $("body").append("<div id=\"info_"+id+"\" class=\"tooltip\" style=\"top:"+(offset.top+20)+"px;left:"+(offset.left+5)+"px;\"></div>");
      $("#info_"+id).html(tresc);
    });
    
   	$('.tip').mouseout(function(){
  	  var id = this.id;
  	  var tresc = this.title;	  
	  $("#info_"+id).remove();
    });  
    
	//$(".wyniki tr:even").addClass("abc");
	//$(".wyniki tr:odd").addClass("def");
	$(".wyniki tr").mouseover(function() {
    	$(this).addClass("tr_hover");
	}).mouseout(function() {
    	$(this).removeClass("tr_hover");
	});
	
	$(".wyniki tr").mouseover(function() {
    	$(this).addClass("tr_hover");
	}).mouseout(function() {
    	$(this).removeClass("tr_hover");
	});
	
	$(".error2").errorStyle();
	$(".good2").goodStyle();
	$("input:submit, .buttonek").button();

	$('.ajax_link').click(function(){
		var href = $(this).attr('href');
		$('#div_123').remove();
		
		var div = $('<div id="div_123">Czekaj trwa ładowanie...</div>');
		$("body").prepend(div);
		div.dialog({
				autoOpen: false,
				width: 500,
				title: $(this).attr('title'),
				close: function(ev, ui) { div.remove(); }
		});
		div.load(href);
		div.dialog("open");	

		return false;
	})

	function showDialog(id, tytul){
		$("#"+id).dialog({
				autoOpen: true,
				width: 500,
				title: tytul,
				close: function(ev, ui) { div.hide(); }
		});
	}
	
});

