function submitForm(formName) {
	if (formName.length < 0) {
		$('form#'+formName).submit();
	}
}

$(document).ready(function() {
//	 All elements with class=datepicker become datepicker elements
	if ($('input.datepicker').length > 0) {
		$('input.datepicker').datepicker({
			appendText: '(dd-mm-yyyy)',
			dateFormat: 'dd-mm-yy',
			dayNamesMin: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
			minDate: 0,
			monthNames: ['januari','februari','maart','april','mei','juni','juli','augustus','september','oktober','november','december'],
			nextText: 'volgende',
			prevText: 'vorige'
		});
	}
	
//	 All elements with class=timepicker become timepicker elements
	if ($('input.timepicker').length > 0) {
		$("input.timepicker").mask("99:99");
	}

	$(".btn-pokeren").click(function(){
		if ($(this).hasClass("disabled")) {
			return false;
		}
		
        $.get($(this).attr("href"), {}, function(response){
            if(Number(response) == 1) {
                $(".btn-pokeren").removeClass('inactive');
            } else {
                $(".btn-pokeren").addClass('inactive');
            }

			$(".btn-pokeren").addClass("disabled");
			setTimeout(function() {
				$(".btn-pokeren").removeClass("disabled");
			}, 1000);
        });

        return false;
    });

    $(".replaceOnClick").one('click', function(){
        $(this).attr("value", "");
    });
  
//     accordion in ul
    $('ul.accordion .slide').hide();

    $('ul.accordion a.opener').each(function(){
    	if($(this).hasClass('active'))
    		$(this).parent().find('.slide').show();
    });

    $('ul.accordion a.opener').live('click', function() {
    	if($(this).hasClass('active'))
    		$(this).parent().find('.slide').slideUp(300);
    	else
    		$(this).parent().find('.slide').slideDown(300);
    		$(this).toggleClass('active');
    	return false;
    });

//     accordion in div
    $('div.accordion .slide').hide();

    $('div.accordion a.opener').each(function(){
    	if($(this).hasClass('active'))
    		$(this).parent().parent().find('.slide').show();
    });

    $('div.accordion a.opener').live('click', function() {
    	if($(this).hasClass('active'))
    		$(this).parent().parent().find('.slide').slideUp(300);
    	else
    		$(this).parent().parent().find('.slide').slideDown(300);
   		$(this).toggleClass('active');
    	return false;
    });

//    $('ul.vrienden-list a.accept').each(function(){
//    	$(this).addClass('active');
//    });
    $('ul.vrienden-list a.accept').click(function(){
    	$(this).addClass('active');
    	$(this).parent().find('a.reject').removeClass('active');
    	return true;
    });
    $('ul.vrienden-list a.reject').click(function(){
    	$(this).parent().find('a.accept').removeClass('active');
    	$(this).addClass('active');
    	$(this).parent().parent().removeClass('onhover');
    	return true;
    });     
	
	$(".no-image-38").live('error', function(){
		$(this).attr("src", "");
	})
});

function checkErrorImages()
{
	$("img").error(function(){
		$(this).attr("src", "");
	})
}

function updateNewMessages()
{
  $.get(baseUrl + 'user/messages/do/newMessages', {}, function(response){
    $(".mail").text('(' + response +')');
  });
}

function gotoPlayer(id)
{
	var html = '<form id="goto" method="post" action="' + baseUrl + 'players/">' +
		'<input type="hidden" name="id" value="' + id + '" />' +
		'<input type="hidden" name="tab" value="vrienden" />' +
	'</form>';
	$('body').append(html);
	$('form#goto').submit();
}


function gotoEvent(id)
{
	var html = '<form id="goto" method="post" action="' + baseUrl + 'agenda/">' +
		'<input type="hidden" name="eventid" value="' + id + '" />' +
		'</form>';
	$('body').append(html);
	$('form#goto').submit();
}


function gotoRoom(id)
{
	var html = '<form id="goto" method="post" action="' + baseUrl + 'rooms/">' +
		'<input type="hidden" name="id" value="' + id + '" />' +
	'</form>';
	$('body').append(html);
	$('form#goto').submit();
}

function gotoGroup(id)
{
	var html = '<form id="goto" method="post" action="' + baseUrl + 'players/">' +
		'<input type="hidden" name="id" value="' + id + '"/>' +
		'<input type="hidden" name="tab" value="groepen"/>' +
		'<input type="hidden" name="layout" value="1"/>' +
	'</form>';
	$('body').append(html);
	$('form#goto').submit();
}
