function goToThemePage(theme)
{
	if (theme.value != '')
	{
		window.location = theme.value;
	}
}

function addToFavorites(type, id)
{
	if (type != '' && id != '')
	{
		switch (type)
		{
			case 'photo':
				new Ajax.Request('/ajax/bibspotter/addtofavorites/photo/' + id + '.html');
				alert('De foto is toegevoegd aan je favorieten');
				break;
			case 'tip':
				new Ajax.Request('/ajax/bibspotter/addtofavorites/tip/' + id + '.html');
				alert('De tip is toegevoegd aan je favorieten');
				break;
			case 'spotter':
				new Ajax.Request('/ajax/bibspotter/addtofavorites/spotter/' + id + '.html');
				alert('De spotter is toegevoegd aan je favorieten');
				break;
			case 'accomodation':
				new Ajax.Request('/ajax/bibspotter/addtofavorites/accomodation/' + id + '.html');
				alert('De accommodatie is toegevoegd aan je favorieten');
				break;
		}
	}

	return false;
}

function addToFavoritesDest(type, sub, id, group)
{
	if (type != '' && id != '')
	{
		switch (type)
		{
			case 'destination':
				new Ajax.Request('/ajax/bibspotter/addtofavorites/destination/' + sub + '/' + id + '/' + group + '.html');
				alert('De bestemming is toegevoegd aan je favorieten');
				break;
		}
	}

	return false;
}

function bibNewGroupGeoFilter()
{
    new Ajax.Updater('subfilter', '/ajax/newbib_country_filter.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});
}

function bibGeoFilter()
{
    $('map_canvas').hide();
    $('map_canvas').innerHTML = '';

    new Ajax.Updater('subfilter', '/ajax/bib_country_filter.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});
}

function addComment(oForm)
{
    errors_input 	= $$('input.error');
    errors_select 	= $$('select.error');
    errors = array_merge(errors_input, errors_select);

    $('ajaxErrorWrapper').hide();

    if (errors.length > 0)
    {
        for (i=0; i<errors.length;i++)
        {
            errors[i].removeClassName('error');
        }
    }

    new Ajax.Request(oForm.action,
        {
            method: 'post',
            postBody: Form.serialize(oForm),
            onSuccess:
                function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    if (json.status == 'false')
                    {
                        ajaxFormErrorHandling(json);
                    }
                    else
                    {
                        reloadComments(oForm);
                    }
                }
        });

    return false;
}

function reloadComments(oForm)
{
    $('commentTxt').value = '';
    new Ajax.Updater('commentItems', '/ajax/get_comments.html', {method: 'post', postBody: Form.serialize($('commentForm'))});
}

function showInlineContent(content_type)
{
    $('tab_impressions').removeClassName('selected');
    $('tab_sights').removeClassName('selected');
    $('tab_news').removeClassName('selected');
    $('tab_specials').removeClassName('selected');
    $('tab_themes').removeClassName('selected');
    $('tab_events').removeClassName('selected');

    $('tab_' + content_type).addClassName('selected');

    $('newsWrapper').innerHTML = '<img src="/images/loading.gif" style="margin: 80px 0 0 300px;" />';
    $('content_type').value = content_type;
    new Ajax.Updater($('newsWrapper'), '/ajax/dynamic_content.html', {method: 'post', postBody: Form.serialize($('contentWide'))});
    return false;
}

function alertLogin()
{
	alert("Om gebruik te maken van deze handige service kunt u \neen eigen Reisdossier aanmaken. ( Gratis en vrijblijvend ) \nZie rechtsboven op deze pagina.");
	return false;
}

function addPhotoRating(mark, photo_id)
{
	new Ajax.Updater('vote_' + photo_id, '/ajax/' + mark + '/' + photo_id + '/add_photo_rate.html', {method: 'post', postBody: Form.serialize($('body'))});

	return false;
}

function addTipRating(mark, tip_id)
{
	new Ajax.Updater('vote_' + tip_id, '/ajax/' + mark + '/' + tip_id + '/add_tip_rate.html', {method: 'post', postBody: Form.serialize($('body'))});
}

function changeGroup()
{
    if ($('gf_geo_goto_group_id').value != '')
    {
        window.location = '/' + $('gf_geo_goto_group_id').value + '.html';
    }
    else
    {
        alert('Selecteer een reissoort.');
    }
    return false;
}

function snelFilter()
{
	if ($('destinationsMap'))
	{
	    new Ajax.Request('/ajax/set_filter_bestemmingen.html', {method: 'post', postBody: Form.serialize($('body'))});
        reloadMarkers();
	}
	else if ($('filter_tab').value == 'list')
	{
	    new Ajax.Updater('destinationList', '/ajax/filter_bestemmingen.html', {method: 'post', postBody: Form.serialize($('body'))});
	}
	else if ($('filter_tab').value == 'weather')
	{
	    new Ajax.Updater('destinationsWeather', '/ajax/filter_weer_bestemmingen.html', {method: 'post', postBody: Form.serialize($('body'))});
	}
	else if ($('filter_tab').value == 'images')
	{
	    new Ajax.Updater('dossierBeeld', '/ajax/filter_images_bestemmingen.html', {method: 'post', postBody: Form.serialize($('body'))});
	}
	else if ($('filter_tab').value == 'accomodations')
	{
	    new Ajax.Updater('destinationsAccomodations', '/ajax/filter_accomodations.html', {method: 'post', postBody: Form.serialize($('body'))});
	}
}

/*
function getCountry( continentid, countryid, groupname, tab )
{
	var url = '/'+groupname+'/'+tab+'.html';
	var options = { method:"post", postBody:'group_id='+groupname+'&filter_type=gf_geo&&gf_continent_id='+continentid+'&gf_country_id='+countryid };
	if ( new Ajax.Request(url,options) )
	{
		window.location = '/'+groupname+'/'+tab+'.html';
	}
}
*/

function getCountry( continentid, countryid, groupname, tab )
{
	var url = '/'+groupname+'/'+tab+'.html';
	var options = { method:"post", postBody:'group_id='+groupname+'&filter_type=gf_geo&&gf_continent_id='+continentid+'&gf_country_id='+countryid };
	// twee extra posts nodig om ervoor te zorgen dat de sessie zeker gezet is.
	if ( new Ajax.Request(url,options) )
	{
		new Ajax.Request(url,options);
	}
	new Ajax.Request(url, { method:"post", postBody:'group_id='+groupname+'&filter_type=gf_geo&&gf_continent_id='+continentid+'&gf_country_id='+countryid, onSuccess: window.location = '/'+groupname+'/'+tab+'.html' });
}



function updateMainGeoFilter()
{
	new Ajax.Updater('mainGeoFilter', '/ajax/filter_main_geo.html', {method: 'post', postBody: Form.serialize($('mainGeoFilter'))});
}

function goToFilterPage()
{
	if ($('qf_country').value != '')
	{
        $('mainGeoFilter').submit();
	}
	else
	{
	    alert('U dient minimaal een land te selecteren');
	    return false;
	}
}

function nextCarouselPage()
{
    new Ajax.Updater('imgThumbsWrapper', '/ajax/nextcarouselpage.html', {method: 'post', postBody: Form.serialize($('imgThumbsWrapper'))});
}

function previousCarouselPage()
{
    new Ajax.Updater('imgThumbsWrapper', '/ajax/prevcarouselpage.html', {method: 'post', postBody: Form.serialize($('imgThumbsWrapper'))});
}

var dm_lb = '1';

function showImageDetails(id)
{
	dm_lb = '0';
    $('show_photo_id').value = id;
    new Ajax.Updater('mainImageDetails', '/ajax/geo/imagedetails.html', {method: 'post', postBody: Form.serialize($('mainImageDetails'))});
}

function initDmLb()
{
	if (dm_lb == '0')
	{
		initLightbox();
	}
	dm_lb = '1';
}

function showPopDestTabs(eid)
{
    divs = $$('div.desttab');

    for(i=0;i<divs.length;i++)
    {
        divs[i].hide();

		$divObj = 'url_'+divs[i].id;
		$divObj = $divObj.replace('_tab','');
		$($divObj).className='';
    }

    $('tab_' + eid).show();
	$('url_' + eid).className='selected';

    return false;
}

function geoGroupFilterContinent()
{
    // er is gefilterd op continent
    $('gf_country_id').value = '';
    $('gf_region_id').value = '';
    $('gf_area_id').value = '';
    $('gf_city_id').value = '';

    // update de landen
    new Ajax.Updater('gf_country_id', '/gf_selector/countries.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de regio's
    new Ajax.Updater('gf_region_id', '/gf_selector/regions.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de gebieden
    new Ajax.Updater('gf_area_id', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city_id', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});
}

function geoGroupFilterCountry()
{
    // er is gefilterd op land
    // update de regio's
    new Ajax.Updater('gf_region_id', '/gf_selector/regions.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de gebieden
    new Ajax.Updater('gf_area_id', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city_id', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});
}

function geoGroupFilterRegion()
{
    // er is gefilterd op continenten
    // update de gebieden
    new Ajax.Updater('gf_area_id', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city_id', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});
}

function geoGroupFilterArea()
{
    // er is gefilterd op continenten
    // update de plaatsen
    new Ajax.Updater('gf_city_id', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_geo_filter'))});
}

function geoFilterContinent()
{
    // er is gefilterd op continent
    $('gf_country').value = '';
    $('gf_region').value = '';
    $('gf_area').value = '';
    $('gf_city').value = '';

    // update de landen
    new Ajax.Updater('gf_country', '/gf_selector/countries.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de regio's
    new Ajax.Updater('gf_region', '/gf_selector/regions.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de gebieden
    new Ajax.Updater('gf_area', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});
}

function geoFilterCountry()
{
    // er is gefilterd op land
    // update de regio's
    new Ajax.Updater('gf_region', '/gf_selector/regions.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de gebieden
    new Ajax.Updater('gf_area', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});
}

function geoFilterRegion()
{
    // er is gefilterd op continenten
    // update de gebieden
    new Ajax.Updater('gf_area', '/gf_selector/areas.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});

    // update de plaatsen
    new Ajax.Updater('gf_city', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});
}

function geoFilterArea()
{
    // er is gefilterd op continenten
    // update de plaatsen
    new Ajax.Updater('gf_city', '/gf_selector/cities.html', {method: 'post', postBody: Form.serialize($('gf_filter'))});
}

function updateSelectorFields(id)
{
    // update de landen
    new Ajax.Updater('country_id', '/ajax/bibspotter/selectorcountries.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});
    new Ajax.Updater('region_id', '/ajax/bibspotter/selectorregions.html');
    new Ajax.Updater('area_id', '/ajax/bibspotter/selectorareas.html');
    new Ajax.Updater('city_id', '/ajax/bibspotter/selectorcities.html');
}

function dm_selected_country()
{
    // update de regio's
    new Ajax.Updater('region_id', '/ajax/bibspotter/selectorregions.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});

    // update de gebieden
    new Ajax.Updater('area_id', '/ajax/bibspotter/selectorareas.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});

    // update de plaatsen
    new Ajax.Updater('city_id', '/ajax/bibspotter/selectorcities.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});
}

function dm_selected_region()
{
    // update de gebieden
    new Ajax.Updater('area_id', '/ajax/bibspotter/selectorareas.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});

    // update de plaatsen
    new Ajax.Updater('city_id', '/ajax/bibspotter/selectorcities.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});
}

function dm_selected_area()
{
    // update de plaatsen
    new Ajax.Updater('city_id', '/ajax/bibspotter/selectorcities.html', {method: 'post', postBody: Form.serialize($('bs_filter'))});
}

function popularWeatherUp(eid)
{
	new Effect.Morph(eid,{style:'margin-top:0px;'});
}
function popularWeatherDown(eid)
{
	new Effect.Morph(eid,{style:'margin-top:-373px;'});
}
function popularWeatherReset(eid)
{
	new Effect.Morph(eid,{ style:'margin-top:-188px;'});
}

function openAccommodatieDescription(eid, imgid, imgname_a, imgname_b, max_hoogte, min_hoogte)
{
	introBox 	= document.getElementById(eid);
	iconImg 	= document.getElementById(imgid);
	hoogteBox	= max_hoogte / 3;

	if (introBox.style.height == min_hoogte+'px')
	{
		//introBox.style.height = hoogteBox+'px';
		new Effect.Morph(introBox,{ style:'height:'+hoogteBox+'px;', duration:0.4 });
	}
	else
	{
		//introBox.style.height = min_hoogte+'px'
		new Effect.Morph(introBox,{ style:'height:'+min_hoogte+'px;', duration:0.4});
	}

	if (iconImg.src == imgname_b)
	{
		iconImg.src = imgname_a;
	}
	else if (iconImg.src == imgname_a)
	{
		iconImg.src = imgname_b;
	}
}

function openDescription(eid, imgid, imgname_a, imgname_b, max_hoogte, min_hoogte)
{
	introBox 	= document.getElementById(eid);
	iconImg 	= document.getElementById(imgid);
	hoogteBox	= Math.ceil(max_hoogte / 4.5);

	if (introBox.style.height == min_hoogte+'px')
	{
		//introBox.style.height = hoogteBox+'px';
		new Effect.Morph(introBox,{ style:'height:'+hoogteBox+'px;', duration:0.4 });
	}
	else
	{
		//introBox.style.height = min_hoogte+'px'
		new Effect.Morph(introBox,{ style:'height:'+min_hoogte+'px;', duration:0.4});
	}

	if (iconImg.src == imgname_b)
	{
		iconImg.src = imgname_a;
	}
	else if (iconImg.src == imgname_a)
	{
		iconImg.src = imgname_b;
	}
}

function openSnelzoeken(eid, imgid, imgname_a, imgname_b, hoogte)
{
	searchBox 	= document.getElementById(eid);
	iconImg 	= document.getElementById(imgid);
	if (searchBox.style.display == 'block')
	{
		searchBox.style.display = 'none'
		iconImg.src = imgname_a;
	}
	else
	{
		searchBox.style.display = 'block'
		iconImg.src = imgname_b;
	}
}

// verwerk formulier.
function saveItem(oForm)
{
    errors_input 	= $$('input.error');
    errors_select 	= $$('select.error');
    errors = array_merge(errors_input, errors_select);

    $('ajaxErrorWrapper').hide();

    if (errors.length > 0)
    {
        for (i=0; i<errors.length;i++)
        {
            errors[i].removeClassName('error');
        }
    }

    new Ajax.Request(oForm.action,
        {
            method: 'post',
            postBody: Form.serialize(oForm),
            onSuccess:
                function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    if (json.status == 'false')
                    {
                        ajaxFormErrorHandling(json);
                    }
                    else
                    {
                        formHandling(json);
                    }
                }
        });

    return false;
}

function preparePhotoForm(form)
{
	new Ajax.Request($F('prepareurl'),
    {
        method: 'post',
        postBody: Form.serialize(form),
        onSuccess:
            function(transport)
            {
                var json = transport.responseText.evalJSON();
                if (json.status == 'false')
                {
                    ajaxFormErrorHandling(json);
                    return false;
                }
                else
                {
                    // verstuur alle afbeeldingen naar de server...
                    submitPhotoForm(form)
                }
            }
    });

    return false;
}

function submitPhotoForm(form)
{
    form.onSubmit = '';
    form.submit();
}

function ajaxFormErrorHandling(json)
{
    if (json.errors.length > 0 && json.status == 'false')
    {
        $('ajaxErrorContent').innerHTML = '';

        for (i=0; i<json.errors.length;i++)
        {
            if ($(json.errors[i].fieldname))
            {
                $(json.errors[i].fieldname).addClassName('error');
            }
            $('ajaxErrorContent').innerHTML = $('ajaxErrorContent').innerHTML + '<p>' + json.errors[i].message + '</p>';
        }

        $('ajaxErrorWrapper').show();
    }
}

function formHandling(json)
{
    if (json.status == 'true')
    {
        if (json.location != '')
        {
            window.location = json.location;
        }
    }
}

function array_merge(arr)
{
	var merged = arr;
	for (var i = 1; i < arguments.length; i++)
	{
		merged = merged.concat(arguments[i]);
	}
	return merged;
}