// JavaScript Document
//TODO get browser default language using this simple javascript
//Inernet Explorer variation details: http://www.javascriptkit.com/javatutors/navigator.shtml
//language = navigator.language;
//if(language)
//document.write(language);
function addEventHandler(obj, evType, fn, useCapture){  
  if (obj.addEventListener){  
    obj.addEventListener(evType, fn, useCapture);  
    return true;  
  } else if (obj.attachEvent){  
    var r = obj.attachEvent("on"+evType, fn);  
    return r;  
  } else {  
    //alert("Handler could not be attached");  
  }  
} 
window.onload = function(){
	registerEvents();
};

function registerEvents(){
	var scienceFormButton = document.getElementById("submitscienceForm");
	if(scienceFormButton.length>0)
	addEventHandler(scienceFormButton,"click",sendScienceWallForm,false);
	var cityWallFormButton = document.getElementById("submitcityForm");
	if(cityWallFormButton.length>0)
	addEventHandler(cityWallFormButton,"click",sendCityWallForm,false);
}

function updateBusinessPricePlan(id,val,buysell){
	xmlhttpco=GetXmlHttpObject();
	if (xmlhttpco==null)
	  {
	  //alert ("Browser does not support HTTP Request");
	  return;
	  }
	
	var url="shoping.php";
	url=url+"?task=updateBusinessPricePlan&id="+id;
	url=url+"&value="+val;
	url=url+"&buysell="+buysell;
	xmlhttpco.onreadystatechange=stateChangedco;
	xmlhttpco.open("GET",url,true);
	xmlhttpco.send(null);
}

function sendScienceWallForm(){
	tinyMCE.triggerSave();
	document.scienceForm.submit();
}
function ncode(n,v) {
	return encodeURIComponent(n) +
	'=' + encodeURIComponent(v);
	}
function sendCityWallForm(){
	tinyMCE.triggerSave();
	document.cityForm.submit();
} 
function ncode(n,v) {
	return encodeURIComponent(n) +
	'=' + encodeURIComponent(v);
	}
function stateChangedco()
{
if (xmlhttpco.readyState==4)
{
document.getElementById("txtstate").innerHTML=xmlhttpco.responseText;
setTimeout("clearMessage()",3000);
}
}
function clearMessage(){
	document.getElementById("txtstate").innerHTML=null;
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
/************************************jquery**********************************************/
function changeClub() {
  $("#clubSelection").change(function() {// if value=0
    this.submit();
  });
}

function startTinyMce(themeName,widthSize,heightSize,buttonsMode){
	switch (buttonsMode) {
	case 1:{
		line1= "image,media,bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|";//code,overstream,youtube,
		line2= "formatselect,fontselect,fontsizeselect,|,pagebreak,bullist,numlist|,forecolorpicker,backcolor";
		line3= "delete_table,tablecontrols,|,hr,visualaid";
		break;
	}
	case 2:{
		line1= "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|";
		line2= "formatselect,fontselect,fontsizeselect,|,pagebreak,bullist,numlist|,forecolorpicker,backcolor";
		line3= "delete_table,tablecontrols,|,hr,visualaid";
		break;
	}
	default:{
		line1= "image,media,bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,pagebreak";
		line2= "bullist,numlist,|,insertdate,inserttime,|,forecolorpicker,backcolor,|,delete_table,tablecontrols,|,hr,visualaid,|,emotions";
		line3= "";
		break;
	}
	}
	tinyMCE.init({
  	  mode : "specific_textareas",
  	  editor_selector : "mceEditor", 
  	  theme : themeName, 
  	  /*extended_valid_elements : "object[width|height],param[name|value|id],embed[src|type|width|height|allowFullScreen|wmode]",*/
  	  file_browser_callback : "imagemanager", 
  	  plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras", 
  	  theme_advanced_toolbar_location : "top", 
  	  theme_advanced_toolbar_align : "left", 
  	  theme_advanced_resizing : false, 
  	  language : "pl", 
  	  height : heightSize, 
  	  width : widthSize, 
  	  theme_advanced_buttons1 : line1, 
  	  theme_advanced_buttons2 : line2, 
  	  theme_advanced_buttons3 : line3, theme_advanced_buttons4 : ""
  		  });
	/*$('textarea.mceEditor').tinymce({
  	  script_url : "javascript/tiny_mce/tiny_mce_gzip.js",
  	  mode : "specific_textareas",
  	  editor_selector : "mceEditor", 
  	  theme : themeName, 
  	  file_browser_callback : "imagemanager", 
  	  plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras", 
  	  theme_advanced_toolbar_location : "top", 
  	  theme_advanced_toolbar_align : "left", 
  	  theme_advanced_resizing : false, 
  	  language : "pl", 
  	  height : heightSize, 
  	  width : widthSize, 
  	  theme_advanced_buttons1 : line1, 
  	  theme_advanced_buttons2 : line2, 
  	  theme_advanced_buttons3 : line3, theme_advanced_buttons4 : ""
  		  });*/
	/*	      tinyMCE.init({
		    	  script_url : "../javascript/tiny_mce/tiny_mce_gzip.js",
		    	  mode : "specific_textareas",
		    	  editor_selector : "mceEditor", 
		    	  theme : themeName, 
		    	  file_browser_callback : "imagemanager", 
		    	  plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras", 
		    	  theme_advanced_toolbar_location : "top", 
		    	  theme_advanced_toolbar_align : "left", 
		    	  theme_advanced_resizing : false, 
		    	  language : "pl", 
		    	  height : heightSize, 
		    	  width : widthSize, 
		    	  theme_advanced_buttons1 : line1, 
		    	  theme_advanced_buttons2 : line2, 
		    	  theme_advanced_buttons3 : line3, theme_advanced_buttons4 : ""
		    		  });*/
	   /*});*/
	/*THIS ONE WORKS AS A SINGLE
	 * tinyMCE_GZ.init({theme : themeName, 
		file_browser_callback : "imagemanager", 
		plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras",
		languages : "pl"
	   },function() {
		      tinyMCE.init({
		    	  mode : "specific_textareas",
		    	  editor_selector : "mceEditor", 
		    	  theme : themeName, 
		    	  file_browser_callback : "imagemanager", 
		    	  plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras", 
		    	  theme_advanced_toolbar_location : "top", 
		    	  theme_advanced_toolbar_align : "left", 
		    	  theme_advanced_resizing : false, 
		    	  language : "pl", 
		    	  height : heightSize, 
		    	  width : widthSize, 
		    	  theme_advanced_buttons1 : line1, 
		    	  theme_advanced_buttons2 : line2, 
		    	  theme_advanced_buttons3 : line3, theme_advanced_buttons4 : ""
		    		  });
	   });*/
	 
		       /*THIS ONE WORKS FINE WITH javascript/tiny_mce/tiny_mce.js
		        * tinyMCE.init({
		    	  mode : "specific_textareas",
		    	  editor_selector : "mceEditor", 
		    	  theme : themeName, 
		    	  file_browser_callback : "imagemanager", 
		    	  plugins : "imagemanager,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,visualchars,xhtmlxtras", 
		    	  theme_advanced_toolbar_location : "top", 
		    	  theme_advanced_toolbar_align : "left", 
		    	  theme_advanced_resizing : false, 
		    	  language : "pl", 
		    	  height : heightSize, 
		    	  width : widthSize, 
		    	  theme_advanced_buttons1 : line1, 
		    	  theme_advanced_buttons2 : line2, 
		    	  theme_advanced_buttons3 : line3, theme_advanced_buttons4 : ""
		    		  });*/
		      
}
function changeProfile() {
  $("#profileSelection").change(function() {
    var index = document.getElementById('profile').selectedIndex;
    if(index==0){null;}else
    this.submit();
  });
}
function removeExtras(element) {
  $(element).closest("p").remove();
}
function removeProduct(box) {
  var product = box.id;
  var id = $(box).prev().attr("value");
  var path = $(box).prev().prev().attr("value");
  $.post("shoping.php", {
    task : "removeProduct",
    product : product,
    id : id,
    DPPath : path
  }, function(data) {
    if (data.found == 1) {
      var koszyk = $(".koszyk-item-suma span");
      if ($(koszyk).length > 0) {
        $(box).closest("li").remove();
        var koszykItems = $(".koszyk-item");
        if (koszykItems.length > 0) {
          $(".koszyk-item-suma span").html(data.price);
        } else {
          $(".koszyk-item-suma").closest("ul").remove();
          $(".koszyk-options a").closest("p").remove();
        }
      } else {
        $(box).parent().parent().remove();
        $('input[value="'+id+'"]').parent().remove();
        $("tfoot tr th:eq(3)").html(data.price);
      }
    }
  }, 'json');
}
function addExtra() {
  var op = document.getElementById('sel1').value;
  var index = document.getElementById('sel1').selectedIndex;
  var text = document.getElementById('sel1').options[index].text;
  var ids = $(".leftSideExtras a");
  var found = false;
  if (ids.length > 0) {
    if (ids.filter(function() {
      return $(this).id == op
    }).length > 0)
      found = true;
  }// TODO to be finished
  if (op.length > 0) {
    if (found) {

    } else {
      // document.getElementById('addToBasketLink').href =
      // document.getElementById('addToBasketLink').href.replace(/A=shop/i,"A=shop"
      // + op);
      $(".produkt-side > h3")
          .after(
              "<p class=\"leftSideExtras\">"
                  + text
                  + "<span><a onclick=\"removeExtras(this)\" href=\"#\" id=\""
                  + op + "\">x</a></span></p>");
    }
  }
}

function addModified(box) {
  var modified = $(".leftSideExtras a").get();
  var extras = [];
  $(modified).each(function(index, value) {
    extras[index] = this.id;
  });
  var product = box.id;
  if (box.id > 0) {
    var path = $(".produkt-side h3").attr("id");
    var koszyk = $(".koszyk-item-suma span");
    $.post("shoping.php", {
      task : "addProduct",
      product : product,
      "extras[]" : extras,
      DPPath : path
    }, function(data) {
      if (koszyk.length > 0) {
        $(".koszyk-item-suma").before(data.item);
        $(".koszyk-item-suma span").html(data.price);
        // $(".koszyk-item-suma").after(data.extra);
      } else {

        $(".button-big4").after(data.basket);

      }
    }, 'json');
  }
}
function updateQuantity(box) {
  var product = box.id;
  var path = $(box).prev().attr("value");
  var koszyk = $(".koszyk-item-suma span").length;
  $.post("shoping.php", {
    task : "addProduct",
    product : product,
    DPPath : path
  }, function(data) {
    if (koszyk > 0) {
      $(".koszyk-item-suma").before(data.item);
      $(".koszyk-item-suma span").html(data.price);
    } else {
      $(".button-big4").after(data.basket);
    }
  }, 'json');
}

function swap(radBtn, group) {
  var group3VisSetting = (group == "2") ? ((radBtn.checked) ? "" : "none")
      : "none";
  var group4VisSetting = (group == "3") ? ((radBtn.checked) ? "" : "none")
      : "none";
  var group5VisSetting = (group == "4") ? ((radBtn.checked) ? "" : "none")
      : "none";
  document.getElementById("2").style.display = group3VisSetting;
  document.getElementById("3").style.display = group4VisSetting;
  document.getElementById("4").style.display = group5VisSetting;
  document.getElementById("joinFanClub").style.display = "block";
}

function swapB(radBtn, group) {
  var group3VisSetting = (group == "2") ? ((radBtn.checked) ? "" : "none")
      : "none";
  var group4VisSetting = (group == "3") ? ((radBtn.checked) ? "" : "none")
      : "none";
  var group5VisSetting = (group == "4") ? ((radBtn.checked) ? "" : "none")
      : "none";
  document.getElementById("2").style.display = group3VisSetting;
  document.getElementById("3").style.display = group4VisSetting;
  document.getElementById("4").style.display = group5VisSetting;
  document.getElementById("joinFanClub").style.display = "block";
}

function submitWallForm(){
	
}

$(document)
    .ready(
        function() {
        	$(".button-tablica a").bind("click",submitWallForm);
        	//Fancybox
        	$(".fancyimagethumb").fancybox({
        		'transitionIn' : 'elastic',
        		'transitionOut' : 'fade'
        	});
        	$(".fancyyoutubethumb").fancybox({
        		'transitionIn' : 'elastic',
        		'padding' : 0,
        		'autoScale' : false,
        		'transitionOut' : 'fade',
        		'width' : 680,
        		'height' : 495,
        		'type' : 'swf'
        		});
          // Expand Panel
          if (($('input[name=DPFormRepeatuser_reg]').length)
              && ($('.formErrors').length)) {
            $("div#panel").slideDown("slow");
          }
          $("#open").click(function() {
            $("div#panel").slideDown("slow");
          });
          
          $(".registerSubstitute").click(function() {
            $("div#panel").slideDown("slow");
            $("#toggle a").toggle();
          });

          // Collapse Panel
          $("#close").click(function() {
            $("div#panel").slideUp("slow");
          });

          // Switch buttons from "Log In | Register" to "Close Panel"
          // on click
          $("#toggle a").click(function() {
            $("#toggle a").toggle();
          });

          $(".rounded").each(function() {
            eval($(this).corner());
          });
          $(".rounded_top").each(function() {
            eval($(this).corner("top"));
          });
          $(".rounded_bottom").each(function() {
            eval($(this).corner("bottom"));
          });
          shopTableBody = $('.shop-menu tbody');
          shopTableBody.find('tr:nth-child(even)').addClass('even');
          shopTableBody.find('tr:nth-child(odd)').addClass('odd');
          /*
           * $('.shop-menu tbody
           * tr:nth-child(even)').addClass('even'); $('.shop-menu
           * tbody tr:nth-childeq(0)').removeClass('odd');
           */
          // mail
          var h1length = $('h2.profilename').text();
          if (h1length.length > 39) {
            $("div .usercard").css('min-height', '180px');
          }
          var newsAmount = $('input:hidden .newsAmount').val();
          if ((newsAmount > 0)) {
            $('#nav li:contains("Poczta")').append(
                ' (' + newsAmount + ')');
            $('#nav li:contains("mail")').append(
                ' (' + newsAmount + ')');
          }
          $(function() {
	//find all form with class jqtransform and apply the plugin
	$('form.jqtransform').jqTransform();
});
$(function() {
	$("#accordion").accordion({
		autoHeight: false
	});
});
          $(function() {
            //banners
            $(".scroll").scrollable({ circular: true }).autoscroll({ autoplay: true })
            // Accordion
            $(".accordion").accordion( {
              header : "h3",
              collapsible : true,
              autoHeight : false
            });

            // Tabs
            $('#tabs').tabs();

            // Dialog
            $('#dialog').dialog( {
              autoOpen : false,
              width : 600,
              buttons : {
                "Ok" : function() {
                  $(this).dialog("close");
                },
                "Cancel" : function() {
                  $(this).dialog("close");
                }
              }
            });

            // Dialog Link
            $('#dialog_link').click(function() {
              $('#dialog').dialog('open');
              return false;
            });
            // date localization for locale 'po'
            // provided by eRIZ (http://eriz.pcinside.pl/)

            // Datepicker
            $('#datepicker').datepicker(
                {
                  dayNames : [ 'Niedziela', 'PoniedziaÅ‚ek',
                      'Wtorek', 'Åšroda', 'Czwartek',
                      'PiÄ…tek', 'Sobota' ],
                  dayNamesMin : [ 'Ni', 'Po', 'Wt', 'Åšr',
                      'Cz', 'Pt', 'So' ],
                  monthNames : [ 'StyczeÅ„', 'Luty', 'Marzec',
                      'KwiecieÅ„', 'Maj', 'Czerwiec',
                      'Lipiec', 'SierpieÅ„', 'WrzesieÅ„',
                      'PaÅºdziernik', 'Listopad',
                      'GrudzieÅ„' ],
                  monthNamesShort : [ 'Sty', 'Lut', 'Mar',
                      'Kwi', 'Maj', 'Cze', 'Lip', 'Sie',
                      'Wrz', 'PaÅº', 'Lis', 'Gru' ],
                  dateFormat : 'yy-mm-dd',
                  showAnim : 'slideDown',
                  /* showOn: 'button', */
                  buttonImage : 'graphics/calendar.gif',
                  inline : true,
                  changeYear : true,
                  changeMonth : true,
                  defaultDate : '-22y'
                });

            // Slider
            $('#slider').slider( {
              range : true,
              values : [ 17, 67 ]
            });

            // Progressbar
            $("#progressbar").progressbar( {
              value : 20
            });

            // hover states on the static widgets
            $('#dialog_link, ul#icons li').hover(function() {
              $(this).addClass('ui-state-hover');
            }, function() {
              $(this).removeClass('ui-state-hover');
            });

          });

      $('.gallery').lightBox();

      $("#clubStatus0").before(
          '<img border=0 src="graphics/dolacz_kibic.jpg" />');
      $("#clubStatus1").before(
          '<img border=0 src="graphics/dolacz_czlonek.jpg" />');
      $("#clubStatus2").before(
          '<img border=0 src="graphics/dolacz_trener.jpg" />');
      $("#clubStatus3").before(
          '<img border=0 src="graphics/dolacz_admin.jpg" />');
      $("#businessStatus0").before(
          '<img border=0 src="graphics/dolacz_klient.JPG" />');
      $("#businessStatus1").before(
          '<img border=0 src="graphics/dolacz_admin.jpg" />');
      $("a[rel^='prettyPhoto']").prettyPhoto( {
        animationSpeed : 'normal', /* fast/slow/normal */
        allowresize : true, /* true/false */
        theme : 'light_rounded', /*
                       * light_rounded / dark_rounded /
                       * light_square / dark_square
                       */
        modal : false
      /*
       * If set to true, only the close button will close the window
       */
      });
      /*
       * $('.input-extra1').show(); $('.input-extra2').show();
       * $('#password').hide(); $('#passwordCheck').hide();
       * $('.input-side').each(function() { var default_value =
       * this.value; $(this).focus(function() { if(this.value ==
       * default_value) { this.value = ''; } }); $(this).blur(function() {
       * if(this.value == '') { this.value = default_value; } }); });
       * $('.input-extra1').focus(function() { $('.input-extra1').hide();
       * $('#password').show(); $('#password').focus(); });
       * $('#password').blur(function() { if($('#password').val() == '') {
       * $('.input-extra1').show(); $('#password').hide(); } });
       * $('.input-extra2').focus(function() { $('.input-extra2').hide();
       * $('#passwordCheck').show(); $('#passwordCheck').focus(); });
       * $('#passwordCheck').blur(function() {
       * if($('#passwordCheck').val() == '') { $('.input-extra2').show();
       * $('#passwordCheck').hide(); } });
       */
      $("input[type=text][title]").each(function() {
        if($(this).val()== "")  
        $(this).val($(this).attr("title"));
          if($.trim($(this).val()) == "")
            $(this).val($(this).attr("title"));
          $(this)
            .focus(function() {
              if($(this).val() == $(this).attr("title")) $(this).val("");
            })
            .blur(function() {
              if($.trim($(this).val()) == "") $(this).val($(this).attr("title"));
            });
        });
            $.widget( "ui.combobox", {
              _create: function() {
                var self = this,
                  select = this.element.hide(),
                  selected = select.children( ":selected" ),
                  value = selected.val() ? selected.text() : "";
                var input = this.input = $( "<input>" )
                  .insertAfter( select )
                  .val( value )
                  .autocomplete({
                    delay: 0,
                    minLength: 0,
                    source: function( request, response ) {
                      var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                      response( select.children( "option" ).map(function() {
                        var text = $( this ).text();
                        if ( this.value && ( !request.term || matcher.test(text) ) )
                          return {
                            label: text.replace(
                              new RegExp(
                                "(?![^&;]+;)(?!<[^<>]*)(" +
                                $.ui.autocomplete.escapeRegex(request.term) +
                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
                              ), "<strong>$1</strong>" ),
                            value: text,
                            option: this
                          };
                      }) );
                    },
                    select: function( event, ui ) {
                      ui.item.option.selected = true;
                      self._trigger( "selected", event, {
                        item: ui.item.option
                      });
                    },
                    change: function( event, ui ) {
                      if ( !ui.item ) {
                        var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                          valid = false;
                        select.children( "option" ).each(function() {
                          if ( $( this ).text().match( matcher ) ) {
                            this.selected = valid = true;
                            return false;
                          }
                        });
                        if ( !valid ) {
                          // remove invalid value, as it didn't match anything
                          $( this ).val( "" );
                          select.val( "" );
                          input.data( "autocomplete" ).term = "";
                          return false;
                        }
                      }
                    }
                  })
                  .addClass( "ui-widget ui-widget-content ui-corner-left" );

                input.data( "autocomplete" )._renderItem = function( ul, item ) {
                  return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append( "<a>" + item.label + "</a>" )
                    .appendTo( ul );
                };

                this.button = $( "<button>&nbsp;</button>" )
                  .attr( "tabIndex", -1 )
                  .attr( "title", "Show All Items" )
                  .insertAfter( input )
                  .button({
                    icons: {
                      primary: "ui-icon-triangle-1-s"
                    },
                    text: false
                  })
                  .removeClass( "ui-corner-all" )
                  .addClass( "ui-corner-right ui-button-icon" )
                  .click(function() {
                    // close if already visible
                    if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
                      input.autocomplete( "close" );
                      return false;
                    }

                    // pass empty string as value to search for, displaying all results
                    input.autocomplete( "search", "" );
                    input.focus();
                    return false;
                  });
              },

              destroy: function() {
                this.input.remove();
                this.button.remove();
                this.element.show();
                $.Widget.prototype.destroy.call( this );
              }
            });
            $( "#searchClub #category" ).combobox();
            $( "#side #category" ).combobox();
            $( "#side #discipline" ).combobox();
            /*$( "#toggle" ).click(function() {
            $( "#searchClub #category" ).toggle();
            $( "#side #category" ).toggle();
            });*/

      // find all form with class jqtransform and apply the plugin
      $('form.jqtransform').jqTransform();

      $('#btnAddExtra').click(
          function() {
            var num = $('.clonedInput').length;
            var newNum = new Number(num + 1);

            var newElem = $('#extrasToCopy' + num).clone()
                .attr('id', 'extrasToCopy' + newNum);

            newElem.find('input:eq(0)').attr('id',
                'extra-name_' + newNum);
            newElem.find('input:eq(0)').attr('name',
                'extra-name_' + newNum);
            newElem.find('input:eq(1)').attr('id',
                'extra-price_zl_' + newNum);
            newElem.find('input:eq(1)').attr('name',
                'extra-price_zl_' + newNum);
            newElem.find('input:eq(2)').attr('id',
                'extra-price_gr_' + newNum);
            newElem.find('input:eq(2)').attr('name',
                'extra-price_gr_' + newNum);

            $('#extrasToCopy' + num).after(newElem);

            // $('#btnDel').attr('disabled','');

            if (newNum == 20)
              $('#btnAdd').attr('disabled', 'disabled');
          });

      $('#movieUploadSubmit').submit(function() {
        countit();
      });
      $('#btnAdd')
          .click(
              function() {
                var num = $('.clonedInput').length;
                var newNum = new Number(num + 1);

                var newElem = $('#input' + num).clone()
                    .attr('id', 'input' + newNum);

                var spareAddButton = newElem.find(
                    '#btnAdd').parent('li');

                spareAddButton.remove();

                newElem.find('label:eq(0)').attr('for',
                    'trainingDays_' + newNum);
                newElem.find('select:eq(0)').attr('id',
                    'trainingDays_' + newNum).attr(
                    'name',
                    'trainingDays_' + newNum);

                newElem.find('label:eq(1)').attr('for',
                    'trainingHours_' + newNum);
                newElem.find('select:eq(1)').attr('id',
                    'trainingHours_' + newNum)
                    .attr(
                        'name',
                        'trainingHours_'
                            + newNum);

                newElem.find('label:eq(2)').attr('for',
                    'trainingMinutes_' + newNum);
                newElem.find('select:eq(2)').attr('id',
                    'trainingMinutes_' + newNum)
                    .attr(
                        'name',
                        'trainingMinutes_'
                            + newNum);

                newElem.find('label:eq(3)').attr('for',
                    'trainingEndHours_' + newNum);
                newElem.find('select:eq(3)').attr('id',
                    'trainingEndHours_' + newNum)
                    .attr(
                        'name',
                        'trainingEndHours_'
                            + newNum);

                newElem.find('label:eq(4)').attr('for',
                    'trainingEndMinutes_' + newNum);
                newElem.find('select:eq(4)').attr('id',
                    'trainingEndMinutes_' + newNum)
                    .attr(
                        'name',
                        'trainingEndMinutes_'
                            + newNum);

                newElem.find('label:eq(5)').attr('for',
                    'status_' + newNum);
                newElem.find('select:eq(5)').attr('id',
                    'status_' + newNum).attr(
                    'name', 'status_' + newNum);

                newElem.find('label:eq(6)').attr('for',
                    'shortNote_' + newNum);
                newElem.find('textarea:eq(1)').attr(
                    'id', 'shortNote_' + newNum)
                    .attr('name',
                        'shortNote_' + newNum)
                    .attr('value', '');

                $('#input' + num).after(newElem);

                $('#btnDel').attr('disabled', '');

                if (newNum == 20)
                  $('#btnAdd').attr('disabled',
                      'disabled');
              });

      $('#btnDel').click(function() {
        var num = $('.clonedInput').length;
        $('#input' + num).remove();

        $('#btnAdd').attr('disabled', '');
        if (num - 1 == 1)
          $('#btnDel').attr('disabled', 'disabled');
      });

      $('#btnDel').attr('disabled', 'disabled');

      $('#btnAdd2').click(
          function() {
            var num = $('.clonedInput').length;
            var newNum = new Number(num + 1);
            var newElem = $('#input' + num).clone().attr(
                'id', 'input' + newNum);
            var spareAddButton = newElem.find('#btnAdd2')
                .parent('li');
            spareAddButton.remove();
            newElem.find('label:eq(0)').attr('for',
                'price_' + newNum);
            newElem.find('input:eq(0)').attr('id',
                'price_' + newNum).attr('name',
                'price_' + newNum);
            newElem.find('label:eq(1)').attr('for',
                'per_' + newNum);
            newElem.find('select:eq(0)').attr('id',
                'per_' + newNum).attr('name',
                'per_' + newNum);
            newElem.find('label:eq(2)').attr('for',
                'caption_' + newNum);
            newElem.find('select:eq(1)').attr('id',
                'caption_' + newNum).attr('name',
                'caption_' + newNum);

            $('#input' + num).after(newElem);
            $('#btnDel2').attr('disabled', '');
            if (newNum == 15)
              $('#btnAdd2').attr('disabled', 'disabled');
          });
      $('#btnDel2').click(function() {
        var num = $('.clonedInput').length;
        $('#input' + num).remove();

        $('#btnAdd2').attr('disabled', '');
        if (num - 1 == 1)
          $('#btnDel2').attr('disabled', 'disabled');
      });

      $('#btnDel2').attr('disabled', 'disabled');

      $('#btnAdd3').click(
          function() {
            var num = $('.clonedInput').length;
            var newNum = new Number(num + 1);
            var newElem = $('#input' + num).clone().attr(
                'id', 'input' + newNum);
            /*var spareAddButton = newElem.find('#btnAdd2')
                .parent('li');
            spareAddButton.remove();*/
            newElem.find('label:eq(0)').attr('for',
                'price_buying_' + newNum);
            newElem.find('input:eq(0)').attr('id',
                'price_buying_' + newNum).attr('name',
                'price_buying_' + newNum);
            newElem.find('label:eq(1)').attr('for',
                'price_selling_' + newNum);
            newElem.find('input:eq(1)').attr('id',
                'price_selling_' + newNum).attr('name',
                'price_selling_' + newNum);
            newElem.find('label:eq(2)').attr('for',
                'product_' + newNum);
            newElem.find('select').attr('id',
                'product_' + newNum).attr('name',
                'product_' + newNum);

            $('#input' + num).after(newElem);
            $('#btnDel2').attr('disabled', '');
            if (newNum == 15)
              $('#btnAdd2').attr('disabled', 'disabled');
          });
      $('#btnDel3').click(function() {
        var num = $('.clonedInput').length;
        $('#input' + num).remove();

        $('#btnAdd3').attr('disabled', '');
        if (num - 1 == 1)
          $('#btnDel3').attr('disabled', 'disabled');
      });

      
      // NAV-Icons
      // Append span to each LI to add reflection

      $("#nav-reflection li").append("<span></span>");

      // Animate buttons, move reflection and fade

      $("#nav-reflection a").hover(function() {
        $(this).stop().animate( {
          marginTop : "-10px"
        }, 200);
        $(this).parent().find("span").stop().animate( {
          marginTop : "18px",
          opacity : 0.25
        }, 200);
      }, function() {
        $(this).stop().animate( {
          marginTop : "0px"
        }, 300);
        $(this).parent().find("span").stop().animate( {
          marginTop : "1px",
          opacity : 1
        }, 300);
      });

      /*
       * =Shadow Nav
       * --------------------------------------------------------------------------
       */

      // Append shadow image to each LI
      $("#nav-shadow li")
          .append(
              '<img class="shadow" src="graphics/icons-shadow.jpg" width="50" height="17" alt="" />');

      // Animate buttons, shrink and fade shadow

      $("#nav-shadow li").hover(function() {
        var e = this;
        $(e).find("a").stop().animate( {
          marginTop : "-14px"
        }, 250, function() {
          $(e).find("a").animate( {
            marginTop : "-10px"
          }, 250);
        });
        $(e).find("img.shadow").stop().animate( {
          width : "80%",
          height : "20px",
          marginLeft : "8px",
          opacity : 0.25
        }, 250);
      }, function() {
        var e = this;
        $(e).find("a").stop().animate( {
          marginTop : "4px"
        }, 250, function() {
          $(e).find("a").animate( {
            marginTop : "0px"
          }, 250);
        });
        $(e).find("img.shadow").stop().animate( {
          width : "100%",
          height : "27px",
          marginLeft : "0",
          opacity : 0.25
        }, 250);
      });

    });
var counter = -1;
feedback = '<h1>Zaczęło się ładowanie filmu, prosimy cierpliwie czekać przesyłanie filmu zajmuje od paru minut do paru godzin</h1>';
function countit() {
  setTimeout("countit()", 60000);
  if (counter++ == 60) {
    feedback += '<br /><h2>Minęła pierwsza godzina. Załadowanie pliku zajmującego około 1gb zajmuje średnio 3,5 godziny</h2> <br />';
  }
  document.getElementById("counter").innerHTML = feedback;
}

