      function getArticleList()
      {
        var str = document.getElementById('articleEdit').value;

        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'articleEditList',
            modul:'download',
            str: str
          },
          dataType:'json',
          success:function(a){
            if(a!=''){
                
                //$('#articleEditList').clear();
                document.getElementById('articleEditList').innerHTML = '';
                              
                for (var key in a) {
                  var obj = a[key];                
                  var lista= '<div> <a id="art_' + a[key]['id'] + '"onclick="loadArticle(' + a[key]['id'] + ')">' + a[key]['tytul'] + '</a> </div>' ;

                  $('#articleEditList').append(lista);
                  //alert ( obj['id'] );
                }



            }
          }
        })

      
      }



      function getFilesList()
      {
        var str = document.getElementById('filesEdit').value;

        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'filesEditList',
            modul:'download',
            str: str,
            file_id: document.getElementById('id_pliku').value
          },
          dataType:'json',
          success:function(a){
            if(a!=''){
                
                //$('#articleEditList').clear();
                document.getElementById('filesEditList').innerHTML = '';

                for (var key in a) {
                  var obj = a[key];                
                  var lista= '<div> <a id="art_' + a[key]['id'] + '"onclick="assignFile(' + a[key]['id'] + ')">' + a[key]['nazwa_wyswietlana'] + '</a> </div>' ;

                  $('#filesEditList').append(lista);
                  //alert ( obj['id'] );
                }



            }
          }
        })

      
      }





      function assignFile(file_id)
      {
        if( document.getElementById('id_pliku').value == '' )
        {
          alert('Najpierw wybierz artykul!');
          return;
        }
      
        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'assignFile',
            modul:'download',
            file_id: file_id,
            article_id: document.getElementById('id_pliku').value
          },
          dataType:'json',
          success:function(a){
              
//              document.getElementById('filesEdit').value = '';
              getFilesList();
              getAssignedFileList();
            }
        })
            
      }



      function unassignFile(file_id)
      {
        if( document.getElementById('id_pliku').value == '' )
        {
          alert('Najpierw wybierz artykul!');
          return;
        }
      
        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'unassignFile',
            modul:'download',
            file_id: file_id,
            article_id: document.getElementById('id_pliku').value
          },
          dataType:'json',
          success:function(a){
              
//              document.getElementById('filesEdit').value = '';
              getFilesList();
              getAssignedFileList();
            }
        })
            
      }




      function getAssignedFileList()
      {
        if( document.getElementById('id_pliku').value == '' )
        {
          return;
        }
      
        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'assignedFileList',
            file_id: document.getElementById('id_pliku').value
          },
          dataType:'json',
          success:function(a){

                document.getElementById('assignedFilesEditList').innerHTML = '';

                for (var key in a) {
                  var obj = a[key];                
                  var lista= '<div> <a id="file_' + a[key]['id'] + '"onclick="unassignFile(' + a[key]['id'] + ')">' + a[key]['nazwa_wyswietlana'] + '</a> </div>' ;

                  $('#assignedFilesEditList').append(lista);
                  //alert ( obj['id'] );
                }

            }
        })         
            
      }





      function loadArticle(id)
      {
      
        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'loadArticle',
            modul:'download',
            id: id
          },
          dataType:'json',
          success:function(a){
            if(a!=''){                
                  document.getElementById('id_pliku').value =  a[0]['id'];
                  document.getElementById('tytul').value =  a[0]['tytul'];
                  document.getElementById('opis_art').value =  a[0]['opis'];
                  document.getElementById('zalety').value =  a[0]['zalety'];
                  document.getElementById('wady').value =  a[0]['wady'];
                  document.getElementById('zakladka').value =  'artykul';
                  document.getElementById('id_pliku').value = id;

                  getFilesList();
                  getAssignedFileList();
                }

            }
        })
            
      }


      function tab3Disable(disable) {
          if (disable == true) {
              $('#tab3 :input').attr('disabled', true);
              $('#tab3 :input').css('background-color', '#DCDCDC');
              $('#dodajDoSerwisu').css('display', 'none');

          } else {
              $('#tab3 :input').removeAttr('disabled');
            //  $('#tab3 :input').css('background-color', '#FFFFFF');
          }   
      }        

      function tab2ShowSection(num)
      {
        switch(num) {
          case 1: 
              $('#section0').hide();
              $('#section1').slideDown("slow");
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
              document.getElementById('zakladka').value = 'video';
              document.getElementById('swfList').innerHTML = '';
              document.getElementById('video_kategorie').style.display = "";
              document.getElementById('gry_kategorie').style.display = "none";
              document.getElementById('download_kategorie').style.display = "none";
              document.getElementById('id_pliku').value = "";
              document.getElementById('flash_upload').value = 0;

              tab3ShowSection(3);
            break;
          case 2: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').slideDown("slow");
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
              document.getElementById('zakladka').value = 'gra';
              document.getElementById('swfList').innerHTML = '';
              document.getElementById('video_kategorie').style.display = "none";
              document.getElementById('gry_kategorie').style.display = "";
              document.getElementById('download_kategorie').style.display = "none";
              document.getElementById('id_pliku').value = "";

              tab3ShowSection(3);
            break;
          case 3: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').slideDown("slow");
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
               document.getElementById('zakladka').value = 'plik';
               document.getElementById('swfList').innerHTML = '';
              tab3ShowSection(3);
            break;        
          case 4: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').slideDown("slow");
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
            break;        
          case 5: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').slideDown("slow");
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
            break;        
          case 6: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').slideDown("slow");
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
            break;                          
          case 7: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').slideDown("slow");
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
            break;        
          case 8: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').slideDown("slow");
              $('#section9').hide();
              $('#section10').hide();
              $('#section11').hide();
            break;        

          case 9: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').slideDown("slow");
              $('#section10').hide();
              $('#section11').hide();
            break;        
          case 10: 
              $('#section0').hide();
              $('#section1').hide();
              $('#section2').hide();
              $('#section3').hide();
              $('#section4').hide();
              $('#section5').hide();
              $('#section6').hide();
              $('#section7').hide();
              $('#section8').hide();
              $('#section9').hide();
              $('#section10').slideDown("slow");
              $('#section11').hide();
            break;        


        }
      }  

      function tab3ShowSection(num)
      {
        switch(num) {
          case 1: 
              $('#descriptionOff').hide();
              tab3Disable(false);            
              $('#descriptionOn').slideDown("slow");
            break;
          case 2: 
              $('#descriptionOff').hide();
              $('#newArticle').slideDown("slow");
            break;                 
          case 3: 
              $('#descriptionOn').hide();
              $('#descriptionOff').show();
              $('#newArticle').hide();
            break;


        }                 
      }


      function zdublowaneVideo(link, tytul)
      {
          document.getElementById('zdublowaneVideoLink').href = link;
          document.getElementById('zdublowaneVideoLink').innerHTML = tytul;
          
          tab2ShowSection(10);     
          tab3ShowSection(3);

      }


      function convertVideoFile(fileName)
      {
          getJSON("http://srv2.cda.pl/ff.php?filename="+ fileName +"&jsoncallback=?","Variable")
      }

      function vidFileUploadScreen()
      {
          tab3ShowSection(1);
          document.getElementById('section1').style.display = "none";
			    JQ("#upload_stats_container").slideDown("fast");

      }



      var icount = 0;
      var lbl;

	    function doDelayLoop() {
	        icount++; 
	 
	        if (icount < 100000) {
	            setTimeout('performYourActions()',3000);
          }
	        else
	            return true;
	    }
	 
	    function performYourActions() {
          var file = document.getElementById('tempFile').value;
          getJSON("http://srv2.cda.pl/yt_ajax_status.php?file="+ file +"&jsoncallback=?","Variable");
         
            
          if( document.getElementById('tempFileUploaded').value == 1 )
          {
              //alert('gotowe');         
              getJSON("http://srv2.cda.pl/yt_ajax2.php?file="+ file +"&linktype=youtube&jsoncallback=?","Variable");
          } 
          //lbl.value = icount;	 
          if( document.getElementById('tempFileUploaded').value != 1 )
              doDelayLoop();
	    }


     function submitYt()
     {
          if( document.getElementById('ytLink').value == '' )
          {
            alert('Wklej poprawny link do Youtube!');
            return false;
          }


          tab2ShowSection(4);
          tab3ShowSection(1);
          document.getElementById('video_kategorie').style.display = "";


          var link = escape(document.getElementById('ytLink').value);

          getJSON("http://srv2.cda.pl/yt_ajax.php?link="+ link +"&jsoncallback=?","Variable")

          doDelayLoop();          


          return false;         
      }


	    function doDelayLoop2() {
	        icount++; 
	 
	        if (icount < 100000) {
	            setTimeout('performYourActions2()',3000);
          }
	        else
	            return true;
	    }
	 
	    function performYourActions2() {
          var file = document.getElementById('tempFile').value;
          getJSON("http://srv2.cda.pl/directvideolink_ajax_status.php?file="+ file +"&jsoncallback=?","Variable");
         
            
          if( document.getElementById('tempFileUploaded').value == 1 )
          {
              //alert('gotowe');         
              getJSON("http://srv2.cda.pl/directvideolink_ajax2.php?file="+ file +"&jsoncallback=?","Variable");
          } 
          //lbl.value = icount;	 
          if( document.getElementById('tempFileUploaded').value != 1 )
              doDelayLoop2();
	    }


     function submitDirectVideoLink()
     {

          if( document.getElementById('directVideoLink').value == '' )
          {
            alert('Wklej poprawny link do pliku video!');
            return false;
          }

          tab2ShowSection(4);
          tab3ShowSection(1);
          document.getElementById('video_kategorie').style.display = "";


          var link = escape(document.getElementById('directVideoLink').value);

          getJSON("http://srv2.cda.pl/directvideolink_ajax.php?link="+ link +"&jsoncallback=?","Variable")

          doDelayLoop2();

          return false;         
      }



      function getJSON(address,target){
              var url = address+"?target="+target;
          	headElement = document.getElementsByTagName("body").item(0);
          	//konqueror & safari don't like head element so i have to use body
              var scriptTag = document.createElement("script");
              scriptTag.setAttribute("id", "runJSON"+target);
              scriptTag.setAttribute("type", "text/javascript");
              scriptTag.setAttribute("src", url);
          	headElement.appendChild(scriptTag);
             // headElement.removeChild(scriptTag);				
     }


     function submitFlash()
     {
          if( document.getElementById('flashLink').value == '' || document.getElementById('flashLink').value =='Link do strony z grą' )
          {
            //alert('Wklej poprawny link do gry!');
            jAlert('Wklej poprawny link do gry!','Uploader');
            return false;
          }

          tab2ShowSection(6);
          tab3ShowSection(1);
          
          document.getElementById('gry_kategorie').style.display = "";
          document.getElementById('gry_miniatura').style.display = "";

          document.getElementById('flash_upload').value = "1";


          var link = escape(document.getElementById('flashLink').value);


          function getJSON(address,target){
              var url = address+"?target="+target;
          	headElement = document.getElementsByTagName("body").item(0);
          	//konqueror & safari don't like head element so i have to use body
              var scriptTag = document.createElement("script");
              scriptTag.setAttribute("id", "runJSON"+target);
              scriptTag.setAttribute("type", "text/javascript");
              scriptTag.setAttribute("src", url);
          	headElement.appendChild(scriptTag);
          }

          getJSON("http://www7.cda.pl/flash_ajax.php?link="+ link +"&jsoncallback=?","Variable")

          return false;         
      }

     function articlePage()
     {
          document.getElementById('zakladka').value = 'artykul';
          document.getElementById('video_kategorie').style.display = "none";
          document.getElementById('gry_kategorie').style.display = "none";
          document.getElementById('download_kategorie').style.display = "";

          tab2ShowSection(9);
          tab3ShowSection(2);
     }

     function sprRegulamin()
     {
          var sel = document.getElementById("kat_id_gry");
          var gry = sel.options[sel.selectedIndex].value;

          var sel = document.getElementById("kat_id_video");
          var vid = sel.options[sel.selectedIndex].value;
          
          if(vid == '-' && gry == '-')
          {
            uAlert('Wybierz kategorie!');
            return false;          
          }

         if(document.getElementById('akceptacja').checked  == false)
         {
            uAlert('Musisz zaakceptowac regulamin!');
            return false;
         }
         else
            return true; 

     
     }


     function getCheckedValue(radioObj) {
    	if(!radioObj)
    		return "";
    	var radioLength = radioObj.length;

    	if(radioLength == undefined)
    		if(radioObj.checked)
    			return radioObj.value;
    		else
    			return "";
    	for(var i = 0; i < radioLength; i++) {
    		if(radioObj[i].checked) {
    			return radioObj[i].value;
    		}
    	}
    	return "";
     } 
    
    
     function setCheckedValue(radioObj, newValue) {
    	if(!radioObj)
    		return;
    	var radioLength = radioObj.length;
    	if(radioLength == undefined) {
    		radioObj.checked = (radioObj.value == newValue.toString());
    		return;
    	}
    	for(var i = 0; i < radioLength; i++) {
    		radioObj[i].checked = false;
    		if(radioObj[i].value == newValue.toString()) {
    			radioObj[i].checked = true;
    		}
    	}
     }


     function saveDirectVideoLink()
     {

        //gry link
        //var obj = document.getElementById('swfLink1');
        var obj = document.forms['swfForm'].elements['swfLink1'];

        document.getElementById('swfLink').value = getCheckedValue( obj );
                                                      
        if( document.getElementById('disableFormCheck').value == '1' )
          return true;

        if( document.getElementById('nazwa_wyswietlana').value.length < 3 )
        {
          uAlert("Wpisz tytuł (minimum 3 znaki)");
          return false;                  
        } 

        if( document.getElementById('opis').value.length < 10 )
        {
          uAlert("Wpisz opis (minimum 10 znaków)");
          return false;                  
        } 

        if( document.getElementById('tagi').value.length < 3 )
        {
          uAlert("Wpisz przynajmniej jeden tag (minimum 3 znaki)");
          return false;                  
        } 

        if( sprRegulamin() == true )
          return true;
        else
          return false;
     }



     function submitNormal()
     {
          
         document.getElementById('opisField').style.display = "none";
          document.getElementById('tagiField').style.display = "none";

          tab2ShowSection(4);
          tab3ShowSection(1);

          var link = escape(document.getElementById('normalLink').value);

          getJSON("http://srv2.cda.pl/remoteupload_ajax.php?link="+ link +"&jsoncallback=?","Variable")

          document.getElementById('disableFormCheck').value = "1";

          return false;         
      }

     function submitAlias()
     {
          
          document.getElementById('opisField').style.display = "none";
          document.getElementById('tagiField').style.display = "none";


          document.getElementById('link_do_pliku').value = document.getElementById('aliasLink').value;
          document.getElementById('nazwaPliku').value = document.getElementById('aliasLink').value;


          document.getElementById('dodajDoSerwisu').style.display='';;
          document.getElementById('dodajDoSerwisu1').style.display='';;
                      
          tab2ShowSection(5);
          tab3ShowSection(1);

          var link = escape(document.getElementById('aliasLink').value);

          document.getElementById('disableFormCheck').value = "1";

          return false;         
      }



      function validateForm()
      {
        radio_choice = false; 
        /*
        for (counter = 0; counter < document.getElementById('swfLink1').length; counter++)
        {
          if ( eval(document.getElementById('swfLink1').counter.checked) == true )
            radio_choice = true; 
        }
        */

        var obj = document.forms['swfForm'].elements['swfLink1'];

        //tylko dla flash
        if( obj )
        {
            if( getCheckedValue( obj ) != "" )
              radio_choice = true;
    
            if(radio_choice == false)
            {
              uAlert("Wybierz animacje FLASH");
              return false;
            }
        }

        if( document.getElementById('nazwa_wyswietlana').value.length < 3 )
        {
          if( document.getElementById('tytul').value.length < 3 )
          {
            uAlert("Wpisz tytuł (minimum 3 znaki)");
            return false;                  
          }
        } 

        if( document.getElementById('opis').value.length < 10 )
        {

          if( document.getElementById('opis_art').value.length < 3 && document.getElementById('nazwa_wyswietlana').value.length < 3 )
          {
            uAlert("Wpisz opis (minimum 10 znaków)");
            return false;                  
          }
        } 

        if( document.getElementById('tagi').value.length < 3 )
        {
          if( document.getElementById('tytul').value.length < 3 && document.getElementById('nazwa_wyswietlana').value.length < 3 )
          {
            uAlert("Wpisz przynajmniej jeden tag (minimum 3 znaki)");
            return false;                  
          }
        } 


        return true; 
      }



      function similarGamesList()
      {

        if( document.getElementById('nazwa_wyswietlana').lengh < 4 || document.getElementById('flash_upload').value == 0)
        {
          return;
        }
      
        $.ajax({
          url:"/ajax",type:"POST",
          data:{
            typ:'podobneGry',
            tytul: document.getElementById('nazwa_wyswietlana').value
          },
          dataType:'json',
          success:function(a){

                document.getElementById('similar_games_list').innerHTML = '';
                
                if( a.length > 0 )
                {
                    $('#similar_games_list').append("Sprawdź czy gra nie znajduje się już w serwisie: <br/>");
                    $('#similar_games_list').append("(linki otwierają się w nowym oknie)<br/>");
    
                    for (var key in a) {
                      var obj = a[key];                
                      var lista= '<a target="_blank" href="' + a[key]['link'] + '">' + a[key]['tytul'] + '</a><br/> ' ;
    
                      $('#similar_games_list').append(lista);
                    }
                    $('#similar_games_list').append("<br/>");
                }

            }
        })         
  
      
        $('#similar_games').slideDown("slow");
      
      
      }
      
      function similarGamesListClear()
      {
        $('#similar_games').hide();
        document.getElementById('similar_games_list').innerHTML = '';      
      }
