function listSet(page){	
	var options = {
			method : "get",
			onSuccess : listPrint,
			parameters : {
				"page" : page,
				"sort" : $("sort").value,
				"type" : $("boardType").value,
				"s_type" : $("searchType").value, 
				"word" : $("searchWord").value				
			}
	};	

	new Ajax.Request("./ajax/BBS_List.php", options);
}

function listPrint(xhr){	
	var json = xhr.responseJSON;
	var list = json.list	
	var color;
	var oRow, oCell1, oCell2, oCell3, oCell4, oCell5;
	
	var oTable = $("listTable");
	var tbody = new Element('tbody');
		tbody.setAttribute('id', 'listTbody');
	var Row_Cnt = oTable.rows.length;
	
	if(Row_Cnt > 2){
		$("listTbody").remove();
	}
	
	if(json.totalCount == 0){		
		oRow = new Element('tr').setStyle({
			'background' : '#FFFFFF',
			'textAlign' : 'center',
			'height' : '26px'
		});	

		var oCell1 = new Element('td').setStyle({			
			'textAlign' : 'center'			
		});
		oCell1.colSpan = '5';
		oCell1.innerHTML = "没有发布的内容！";

		oRow.insert(oCell1);

		tbody.insert(oRow);
		oTable.insert(tbody);		
	}else{
		for(i=0;i<list.length;i++){
			if(i%2 == 0){
				color = "#FFFFFF";
			}else{
				color = "#F7F7F7";
			}				
			
			oRow = InsTD(json.type, color, json.pnum--, list[i]);			

			tbody.insert(oRow);
			oTable.insert(tbody);	
		}

		$('totalCnt').innerHTML = json.totalCount;
	}	

	$('page').value = json.page;
	$('totalPage').innerHTML = json.totalPage;
	$('paging').innerHTML = pagingSet(json.page, json.totalPage, 'listSet');
}

function InsTD(type, color, pnum, list){
	var oRow, oCell1, oCell2, oCell3, oCell4, oCell5;

	oRow = new Element('tr').setStyle({
		'background' : color,
		'textAlign' : 'center',
		'height' : '26px'
	});	
	
	switch(type){

		case "free":
			oCell1 = new Element('td');
			oCell2 = new Element('td').setStyle({			
				'textAlign' : 'left',
				'padding' : '0px 0px 0px 10px'
			});
			oCell3 = new Element('td');
			oCell4 = new Element('td');
			oCell5 = new Element('td');

			oCell1.innerHTML = pnum;
			oCell2.innerHTML = "<a href='./free_view.php?no="+list.NO+"'>"+list.SUBJECT+"</a>";
			oCell3.innerHTML = list.ID;
			oCell4.innerHTML = list.REG_DT;
			oCell5.innerHTML = list.READ_CNT;
			
			oRow.insert(oCell1);
			oRow.insert(oCell2);
			oRow.insert(oCell3);
			oRow.insert(oCell4);			
			oRow.insert(oCell5);	

			break;

		case "W_Report":
			oCell1 = new Element('td');
			oCell2 = new Element('td').setStyle({			
				'textAlign' : 'left',
				'padding' : '0px 0px 0px 10px'
			});
			oCell3 = new Element('td');

			oCell1.innerHTML = pnum;
			oCell2.innerHTML = "<a href='./WeekReportView.php?no="+list.NO+"'>"+list.SUBJECT+"</a>";
			oCell3.innerHTML = list.READ_CNT;

			oRow.insert(oCell1);
			oRow.insert(oCell2);
			oRow.insert(oCell3);

			break;
		
		case "W_Report_content":
			oCell1 = new Element('td');
			oCell2 = new Element('td').setStyle({			
				'textAlign' : 'left',
				'padding' : '0px 0px 0px 10px'
			});
			oCell3 = new Element('td');

			oCell1.innerHTML = pnum;			
			oCell2.innerHTML = '<table width="100%"><tr><td><img src="/biz/img/week/'+list.IMG_SRC+'" width="69" height="47"></td><td><a href="./WeekReportView.php?no='+list.NO+'"><b>'+list.SUBJECT+'</b><br>'+list.SUMMARY+'</a></td></tr></table>';		

			oCell3.innerHTML = list.READ_CNT;

			oRow.insert(oCell1);
			oRow.insert(oCell2);
			oRow.insert(oCell3);

			break;
		
		case "Inform":
			oCell1 = new Element('td');
			oCell2 = new Element('td').setStyle({			
				'textAlign' : 'left',
				'padding' : '0px 0px 0px 10px'
			});
			oCell3 = new Element('td');

			oCell1.innerHTML = pnum;			
			oCell2.innerHTML = "<a href='./inform_data_view.php?no="+list.NO+"'>"+list.SUBJECT+"</a>";		

			oCell3.innerHTML = list.REG_DT;

			oRow.insert(oCell1);
			oRow.insert(oCell2);
			oRow.insert(oCell3);

			break;
		
		case "Press":
			oCell1 = new Element('td');
			oCell2 = new Element('td').setStyle({			
				'textAlign' : 'left',
				'padding' : '0px 0px 0px 10px'
			});
			oCell3 = new Element('td');
			oCell4 = new Element('td');

			oCell1.innerHTML = pnum;			
			oCell2.innerHTML = "<a href='./rk_newsView.php?no="+list.NO+"' target='_blank'>"+list.SUBJECT+"</a>";		

			oCell3.innerHTML = list.ORIGIN;
			oCell4.innerHTML = list.REG_DT;

			oRow.insert(oCell1);
			oRow.insert(oCell2);
			oRow.insert(oCell3);
			oRow.insert(oCell4);

			break;
	}

	return oRow;
}