function reload(){
  var index1 = document.searcher.category.selectedIndex;
  var value1 = document.searcher.category.options[index1].value;
  var index2 = document.searcher.topic.selectedIndex;
  var value2 = document.searcher.topic.options[index2].value;
  buildTable(value1, value2);
}

function buildTable(param1, param2) {
  dwr.util.removeAllRows("t1");
  fillTable(param1, param2);
}

function removeElement(divNum) {
  var d = document.getElementById('t1');
  d.removeChild(divNum);
}

function fillTable(param1, param2) {

	VideoListManager.getVideoList(param1, param2, function(data) {
    // Create a new set cloned from the pattern row
    var videoDWR, id;
    var tbody1 = document.createElement('tbody');
    for (var i = 0; i < data.length; i++) {
    	videoDWR = data[i];
      	var train = videoDWR.trainType;
      	var theme1 = '&nbsp;|&nbsp;<b>Tematyka:</b>&nbsp;';
      	var theme2 = '';
      	var trainArr = train.split("|");
      	for(indeks in trainArr) {
      		if (indeks > 0) {
      			if (indeks > 1)
        			theme2 += '<span style=\"font-weight:normal;\">&nbsp;|&nbsp;</span>';
          		theme2 += '<a class="category_list" href=\"/pl/video/videolist?kat=' + trainArr[indeks].replace(/ /g, '_') + '\">' + trainArr[indeks] + '</a>';
      		}
      	}
      	if (trainArr.length == 1) {
        	theme1 = '';
        	theme2 = '';
      	}

      	var portal = '';
      	if (videoDWR.portalName == 'NBPortal')
      		portal = 'blue_';

      	var movieTime = '';
      	if (videoDWR.movieDuration != null && !videoDWR.movieDuration == '') {
			movieTime = '<div style="background-color:transparent; position:absolute; z-index:1; margin:0; padding:0; bottom:1px; right:0; width:109px; height:61px;"><div style="position:absolute; margin:0; padding:0; bottom:0px; right:0; background-color:#000000; color:#FFFFFF; z-index:1; font-size:11px;">&nbsp;' + videoDWR.movieDuration + '&nbsp;</div></div>';
      	}

      	var imageOne = '<img src="' + videoDWR.gteHost + '/wp/' + videoDWR.imgLabel + '?sizeX=109&amp;sizeY=61&format=jpg&cache=180" alt="" title=""/>';
      	if (videoDWR.streamType == 'audio'){
        	imageOne = '<img src="/static/img/vs/audio_' + portal + '110.png" border="0" alt="" title=""/>';
      	}
      	var td1 = '<td valign="top"><center style="padding-top:5px;"><div style="background-color:transparent; vertical-align:bottom; position:relative; zoom:1;"><div style="border:1px solid #7E9883; background-color:transparent; z-index:1; width:109px; min-height:61px;">' + imageOne + '<div title="' + videoDWR.titleShort + '" alt="' + videoDWR.titleShort+ '" style="background-color:transparent; zoom:1; position:absolute; top:0; left:0; cursor: pointer; z-index:2; width:110px; height:62px; background:transparent url(/static/img/vs/play_' + portal + '22.png) no-repeat 83px 5px;" onclick="openVideoPage(\'' + videoDWR.pagePath + '\');" ></div>' + movieTime + '</div></div></center></td>';
      	var td2 = '<td colspan="2"><div class="video_list" style="padding-left:5px; min-height:80px"><span class="video_list_header"><a href="' + videoDWR.pagePath + '">' + videoDWR.titleShort.toUpperCase() + '</a></span><span style="color:#1D1E1D;">&nbsp;|&nbsp;<b>Czas:</b>&nbsp;' + videoDWR.movieDuration + '<br/></span><div class="video_desc" style="padding:4px 0;">' + videoDWR.leadShort + '&nbsp;<a class="category_list" href="' + videoDWR.pagePath + '">&raquo;</a></div><b>Dodane:</b>&nbsp;' + videoDWR.emissionDate + '&nbsp;|&nbsp;<b>Kategoria:</b>&nbsp;<span class="video_list_kat"><a class="category_list" href=\"/pl/video/videolist?kat=' + trainArr[0].replace(/ /g, '_') + '\">' + trainArr[0] + '</a></span>' + theme1 + '<span class="video_list_kat">' + theme2 + '</span></div></td>';
      	jQuery(tbody1).append('<tr style="height:80px">' + td1 + td2 + '</tr>');
      	jQuery("#t1").append(tbody1);
	}
	if (data.length > listLength) {
    	pager.init();
      	//pager.showPageNav('pager', 'pageNavPosition', 1, 10);
      	pager.showPage(1);
    } else if (data.length == 0) {
		jQuery("#t1").append('<tr style="height:220"><td colspan="3" width="739" align="center"><span class="header_nbptv" style="font-size:1.1em; color:#C6C6C6;">Brak materia&#322;&#243;w video</span></td></tr>');
		pager.hidePageNav('pageNavPosition');
	} else {
		pager.hidePageNav('pageNavPosition');
	}
	});
}

