﻿Sys.Application.add_init(AppInit);

function AppInit() {
	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function(sender, args) {
		//$('#' + filterBoxId).keyup(onFilterTextChanged);
		$('#' + resultBoxId).click(onListClicked);
	});

	//$('#' + filterBoxId).keyup(onFilterTextChanged);
	$('#' + resultBoxId).click(onListClicked);
}

//function onFilterTextChanged(e) {
//	PageMethods.GetFilteredOptions($get(filterBoxId).value, filter__CallBack);
//}

function filter__CallBack(response) {
	var jsonObj = this.JSON.parse(response);
	$('#' + resultBoxId).binddata(jsonObj);
}

function onListClicked(e) {
	if ($get(resultBoxId).value != '-1') {
		PageMethods.GetRelatedArticles(parseInt($get(resultBoxId).value), list__CallBack);
	}
}

function list__CallBack(response) {
	var values = response.split('|');
	var list = $('#articleList');

	list.empty();

	if (values != '') {
		$.each(
		values,
		function(iIndex, objValue) {
			var line = objValue.split(',');
			list.append($('<li><a href="http://www.tiemantrading.nl/?article=' + line[0] + '" target="_top">' + line[1] + '</a></li>'));
		});
	}
	else {
		list.append($('<li>Er kunnen geen resultaten gevonden worden</li>'));
	}
}
