$(document).ready(function(){
$('#startdate').datepicker();
$('#enddate').datepicker();
});
var headingId = null;
var subHeadingId = null;
var cityId = null;
var locationId = null;
var parentLocationId = null;
var parentName = null;
var previousSearchResult = null;
var previousPage = null;
function getSearchUrl(){
var result = '/events/search.html?key=108';
return result;
}
function getReportUrl(){
var result = '/events/report.html?key=108';
return result;
}
function getDetailUrl(){
var result= '/events/detail.html?key=108';
return result;
}
function changeHeading(defaultSubheadingText) {
var current = $("#headingselect");
var currentHeading = current.val();
var subheadingselect = $("#subheadingselect");
// disable element
subheadingselect.attr("disabled", true);
if(currentHeading == "")
{
// select first
subheadingselect.attr('selectedIndex', 0)
$("select#subheadingselect").html(options);
}
else {
// show list of new elements
var options = "";
var count = 0;
options += '';
for ( var i=0; i < subheadings.length; i++ ){
if(currentHeading == subheadings[i][1]) {
count++;
options += '';
}
}
$("select#subheadingselect").html(options);
if(count > 0) {
// enable element
subheadingselect.removeAttr("disabled");
}
}
}
function locationChanged(locId){
applyFacets();
}
function applyFacets(){
loadSearchResult(false);
}
function applyFacetRubriek(_headingId, _subHeadingId){
headingId = _headingId;
subHeadingId = _subHeadingId;
loadSearchResult(false, 1);
loadFacets(false);
}
function applyFacetLocation(_cityId, _locationId, _parentLocationId, _parentName){
cityId = _cityId;
locationId = _locationId;
parentLocationId = _parentLocationId;
parentName = _parentName;
loadSearchResult(false, 1);
loadFacets(false);
}
//construct list of "rubriek" headings
function getRubriekHeadings(){
var result = "";
var headingsForm = document.getElementById('headingsform');
$(':input', headingsForm).each(function() {
var type = this.type;
if(type == 'checkbox'){
if(this.checked == true){
result += this.value+";";
}
}
});
return result;
}
function getLocationUrl(){
var locationIds = getLocationIds();
var result="";
if(locationIds.length > 0){
result = "&location="+locationIds;
}
return result;
}
function getLocationIds(){
var locIds = "";
var locForm = document.getElementById('locationForm');
$(':input', locForm).each(function() {
var type = this.type;
var name = this.name
if(type == 'checkbox' && name =='location'){
if(this.checked == true){
locIds += this.value+";";
}
}
});
return locIds;
}
function loadSearchResult(ommitLocationAndRubrieken, page){
var resultsUrl = getSearchUrl();
resultsUrl += getBaseSearchUrl();
if(ommitLocationAndRubrieken == true){
resultsUrl += getBaseHeadingUrl();
}
if(page != null){
resultsUrl += "&page="+page;
}
if(ommitLocationAndRubrieken == false){
//resultsUrl += getLocationUrl();
resultsUrl = resultsUrl.replace("cityId","cityIdBox").replace("cityName","cityNameBox"); //cleanup checkbox input
if(subHeadingId != null){
resultsUrl += "&heading="+subHeadingId;
}
else if(headingId != null){
resultsUrl += "&heading="+headingId;
}
if(cityId != null){
resultsUrl += "&cityId="+cityId;
}
if(locationId != null){
resultsUrl += "&location="+locationId;
}
}
resultsUrl += "&d=" + new Date().getTime();
showSearchResultLoading();
$.ajax({
url: resultsUrl,
type: 'GET',
dataType: 'html',
timeout: 5000,
error: function(){
//getTargetElement().innerHTML = "Geen resultaten gevonden";
hideSearchResultLoading();
},
success: function(xml){
getTargetElement().innerHTML = xml;
previousSearchResult = xml;
hideSearchResultLoading();
//showSelector();
}
});
}
function loadDetail(eventId){
var detailUrl = getDetailUrl();
detailUrl += "&cdbid="+eventId;
detailUrl += "&d=" + new Date().getTime();
$.ajax({
url: detailUrl,
type: 'GET',
dataType: 'html',
timeout: 5000,
error: function(){
//var target = getTargetElement().innerHTML = "Geen resultaten gevonden";
hideSearchResultLoading();
},
success: function(xml){
getTargetElement().innerHTML = xml;
hideSearchResultLoading();
createBackLink();
//hideSelector();
}
});
}
function getTargetElement(){
var target = document.getElementById('search-overview');
if(target == null){
target = document.getElementById('content');
}
return target;
}
function putHistoryBack(){
if(previousSearchResult != null){
getTargetElement().innerHTML = previousSearchResult;
previousSearchResult = null;
}
else if(previousPage != null){
document.getElementById("content").innerHTML = previousPage;
}
else {
document.location="/vrije-tijd/events/index.html";
}
}
function createBackLink(){
var p = document.getElementById("terug");
if(previousSearchResult != null){
p.innerHTML="Keer terug";
}
}
function addHistory(){
var content = document.getElementById("content");
previousPage = content.innerHTML;
}
function deletePreviousPage(){
previousPage = null;
}
function getBaseSearchUrl(){
var resultsUrl = "";
var searchval = $("#searchquery").val();
var cityidval = $("#cityId").val();
//var startdateval = document.getElementById("from").value;
//var enddateval = document.getElementById("to").value;
var startdateval = $("#from").val();
var enddateval = $("#to").val();
//alert("startdateval: " + startdateval);
//alert("enddateeval: " + enddateval);
//var startDate = $.datepicker.parseDate('dd/mm/yy', startdateval);
//var endDate = $.datepicker.parseDate('dd/mm/yy', enddateval);
if(startdateval != null && startdateval != ""){
resultsUrl += "&startdate=" + startdateval;
}
if(enddateval != null && enddateval != ""){
resultsUrl += "&enddate=" + enddateval;
}
if(cityidval != "" && cityidval != null){
resultsUrl += "&cityId=" + $("#cityId").val();
resultsUrl += "&cityName=" + $('#cityId :selected').text();
}
if(searchval != "" && searchval != null){
resultsUrl += "&searchQuery=" + searchval;
}
return resultsUrl;
alert("hall");
}
function getBaseHeadingUrl(){
var resultsUrl = "";
var headingval = $("#headingselect").val();
var subheadinval = $("#subheadingselect").val();
if(subheadinval != "" && subheadinval != null) {
resultsUrl += "&heading=" + subheadinval;
resultsUrl += "&parentHeading=" + headingval;
}
else if(headingval != "" && headingval != null) {
resultsUrl += "&heading=" + headingval;
}
return resultsUrl;
}
function loadFacets(ommitLocationAndRubrieken){
var reportUrl = getReportUrl();
reportUrl += getBaseSearchUrl();
if(ommitLocationAndRubrieken==true){
reportUrl += getBaseHeadingUrl();
}
else{
if(ommitLocationAndRubrieken == false){
//resultsUrl += getLocationUrl();
reportUrl = reportUrl.replace("cityId","cityIdBox").replace("cityName","cityNameBox");
if(headingId != null){
if(subHeadingId == null){
reportUrl += "&heading="+headingId;
}
else if(headingId != null && subHeadingId != null){
reportUrl += "&parentHeading="+headingId+"&heading="+subHeadingId;
}
}
if(cityId != null){
reportUrl += "&cityId="+cityId;
if(locationId != null){
reportUrl += "&location="+locationId;
}
if(parentLocationId != null){
reportUrl += "&parentLocation="+parentLocationId;
}
if(parentName != null){
reportUrl += "&cityName="+parentName;
}
}
}
}
reportUrl += "&d=" + new Date().getTime();
showReportLoading();
$.ajax({
url: reportUrl,
type: 'GET',
dataType: 'html',
timeout: 10000,
error: function(){
//alert('Error loading html document');
hideReportLoading();
},
success: function(html){
document.getElementById('facetResult').innerHTML = html;
hideReportLoading();
}
});
}
//utils
function getCategorieCheckBox(headingId){
return document.getElementById('cat_'+headingId);
}
function getSubCategorieCheckBox(subHeadingId){
return eval('document.headingsform.subcat_' + subHeadingId);
}
function removeCity(){
document.getElementById('selectedCity').innerHTML = "";
document.getElementById('cityId').selectedIndex = 0;
loadFacets(false);
loadSearchResult(false);
}
function removeDate(){
document.getElementById('startdate').value = "";
document.getElementById('enddate').value = "";
document.getElementById('selectedDate').value = "";
loadFacets(false);
loadSearchResult(false);
}
function showSearchResultLoading(){
if(document.getElementById("searchresultloading") != null){
document.getElementById("searchresultloading").style.display = 'block';
}
}
function hideSearchResultLoading(){
if(document.getElementById("searchresultloading") != null){
document.getElementById("searchresultloading").style.display = 'none';
}
}
function showReportLoading(){
if(document.getElementById("reportloading") != null){
document.getElementById("reportloading").style.display = 'block';
}
}
function hideReportLoading(){
if(document.getElementById("reportloading") != null){
document.getElementById("reportloading").style.display = 'none';
}
}
function hideSelector(){
if(document.getElementById("cdbselector") != null){
document.getElementById("cdbselector").style.display = 'none';
}
}
function showSelector(){
if(document.getElementById("cdbselector") != null){
document.getElementById("cdbselector").style.display = 'block';
}
}