function versus() {
    this.initialize = initialize;
    this.msgBoxClose = msgBoxClose;
    this.msgBoxOpen = msgBoxOpen;
    this.showContent = showContent;
    this.navActive = navActive;
    this.checkLogin = checkLogin;
    this.checkCountry = checkCountry;
    this.checkNewsletter = checkNewsletter;
    this.checkDatum = checkDatum;
    this.checkFindSearch = checkFindSearch;
    this.checkShowCity = this.checkShowCity;
    this.checkShowAge = this.checkShowAge;
    this.checkShowLastname = this.checkShowLastname;
    this.checkFriendsOnly = this.checkFriendsOnly;
    this.checkContestMails = this.checkContestMails;
    this.labelHide = labelHide;
    this.addSpotlight = addSpotlight;
    this.closeSpotlight = closeSpotlight;
    this.userBlock = userBlock;
    this.userFriends = userFriends;
    this.addPrikbordBericht = addPrikbordBericht;
    this.removePrikbordBericht = removePrikbordBericht;
    this.Vote = Vote;
    this.createAccount = createAccount;
    this.changeAccount = changeAccount;
    this.createProfile = createProfile;
    this.changeProfile = changeProfile;
    this.activateAccount = activateAccount;
    this.resetPassword = resetPassword;
    this.changePassword = changePassword;
    this.photoUploader = photoUploader;
    this.selectPhotoForCrop = selectPhotoForCrop;
    this.photoCropper = photoCropper;
    this.updateCoords = updateCoords;
    this.checkCoords = checkCoords;
    this.photoDelete = photoDelete;
    this.selectPhotoForDelete = selectPhotoForDelete;
    this.textCounter = textCounter;
}
function initialize(pagename) {
    if (pagename == 'frontpage') {
        $('.twitterFeedStatuses').jScrollPane();
        $(document).ready(function() {
            $('#fr-topBanner').fadeIn();
            $('#fr-SpotlightItems').fadeIn();
            $('#fr-topBanner').cycle({
                slideExpr: 'img',
                fx: 'fade',
                random: 1,
                speed: 10000
            });
            $('#fr-SpotlightItems').cycle({
                slideExpr: 'div',
                fx: 'fade',
                random: 1,
                speed: 5000
            });
             $('#lastResultaten').cycle({
                slideExpr: 'img',
                fx: 'fade',
                random: 1,
                speed: 5000
            });
        });
    }
    if (pagename == 'profile') {
        $('.photobookItems').jScrollPane();
        $('.profilePrikbordItems').jScrollPane();
    }
    if (pagename == 'account_aanmaken') {
        checkDatum();
    }
    if (pagename == 'account_profielfoto-wijzigen') {
        $('.cropPhotobook').jScrollPane();
    }
    if (pagename == 'account_foto-verwijderen') {
        $('.deletePhotobook').jScrollPane();
    }
    if (pagename == 'account_profiel-gegevens') {
        checkFindSearch();
        checkShowCity();
        checkShowAge();
        checkShowLastname();
        checkFriendsOnly();
        checkContestMails();
    }
    if (pagename == 'account_account-gegevens') {
        checkCountry();
        checkNewsletter();
    }
    navActive(pagename);
    checkLogin();
}
function msgBoxClose() {
    $('#msgBoxWrapper').hide();
    $('#msgBoxHead').text('');
    $('#msgBoxText').text('');
}
function msgBoxOpen() {
    $('#msgBoxWrapper').fadeIn();
}
function Vote(votetype, votecount, uvi, cid, head, text) {
    if (votetype == 'free') {
        this.voteText = $('#voteTextFree').html();
    }
    if (votetype == 'sms') {
        this.voteText = $('#voteTextSMS').html();
    }
    if (votetype == 'phone') {
        this.voteText = $('#voteTextPhone').html();
    }
    $('#msgBoxHead').text(head);
    $('#msgBoxText').html(text + this.voteText);
    this.msgBoxOpen();
}
function showContent(activeBox) {
    var contentBoxes = ["divnaam", "divnaam"];
    jQuery.each(contentBoxes,
    function() {
        $("#" + this).hide();
    });
    $('#' + activeBox).fadeIn();
}
function navActive(navitem) {
    this.n = "nav" + navitem.charAt(0).toUpperCase() + navitem.slice(1);
    $('#' + this.n).addClass('navActive');
}
function checkLogin() {
    this.user = $("#username").val();
    this.pass = $("#password").val();
    if (this.user == '') {
        $('#labelUsername').show();
    }
    if (this.pass == '') {
        $('#labelPassword').show();
    }
}
function checkDatum() {
    this.datum = $("#gebdatum").val();
    var d = this.datum;
    if (this.datum == '') {
        $('#labelGebdatum').show();
    }
    d = d.replace(/^\s+/, '');
    d = d.replace(/\s+$/, '');
    d = d.replace(' ', '-');
    d = d.replace(' ', '-');
    d = d.replace('/', '-');
    $("#gebdatum").val(d);
}
function checkCountry() {
    this.country = $("#landH").val();
    if (this.country == 'belgie') {
        document.accountGegevensForm.land[0].selected = true
    }
    if (this.country == 'nederland') {
        document.accountGegevensForm.land[1].selected = true
    }
}
function checkNewsletter() {
    this.letter = $("#nieuwsbriefH").val();
    if (this.letter == '1') {
        document.accountGegevensForm.nieuwsbrief[0].checked = true
    }
    if (this.letter == '0') {
        document.accountGegevensForm.nieuwsbrief[1].checked = true
    }
}
function checkFindSearch() {
    this.findsearch = $("#findSearchH").val();
    if (this.findsearch == '1') {
        document.profielGegevensForm.find_search[0].selected = true
    }
    if (this.findsearch == '0') {
        document.profielGegevensForm.find_search[1].selected = true
    }
}
function checkShowCity() {
    this.showcity = $("#showCityH").val();
    if (this.showcity == '1') {
        document.profielGegevensForm.show_woonplaats[0].selected = true
    }
    if (this.showcity == '0') {
        document.profielGegevensForm.show_woonplaats[1].selected = true
    }
}
function checkShowAge() {
    this.showage = $("#showAgeH").val();
    if (this.showage == '1') {
        document.profielGegevensForm.show_leeftijd[0].selected = true
    }
    if (this.showage == '0') {
        document.profielGegevensForm.show_leeftijd[1].selected = true
    }
}
function checkShowLastname() {
    this.showlastname = $("#showLastnameH").val();
    if (this.showlastname == '1') {
        document.profielGegevensForm.show_lastname[0].selected = true
    }
    if (this.showlastname == '0') {
        document.profielGegevensForm.show_lastname[1].selected = true
    }
}
function checkFriendsOnly() {
    this.friendsonly = $("#friendsOnlyH").val();
    if (this.friendsonly == '1') {
        document.profielGegevensForm.friendsonly[0].selected = true
    }
    if (this.friendsonly == '0') {
        document.profielGegevensForm.friendsonly[1].selected = true
    }
}
function checkContestMails() {
    this.contestmails = $("#mailWedstrijdH").val();
    if (this.contestmails == '1') {
        document.profielGegevensForm.mail_wedstrijdinfo[0].selected = true
    }
    if (this.contestmails == '0') {
        document.profielGegevensForm.mail_wedstrijdinfo[1].selected = true
    }
}
function labelHide(label) {
    this.label = label;
    if (this.label == 'username') {
        $('#labelUsername').hide();
    }
    if (this.label == 'password') {
        $('#labelPassword').hide();
    }
    if (this.label == 'gebdatum') {
        $('#labelGebdatum').hide();
    }
}
function addSpotlight() {
    $('#fr-showSpotlight').hide();
    $('#fr-addSpotlight').fadeIn();
}
function closeSpotlight() {
    $('#fr-addSpotlight').hide();
    $('#fr-showSpotlight').fadeIn();
}
function userBlock(userid,head) {
    jQuery.ajax({
        url: "/engine/responders/account/block/?action=block&userid=" + userid,
        method: 'post',
	    dataType: "html",
       	success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function userFriends(userid,head) {
    jQuery.ajax({
        url: "/engine/responders/account/friends/?action=friends&userid=" + userid,
        method: 'post',
	    dataType: "html",
       	success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function addPrikbordBericht(head) {
    var form = $("#addPrikbordForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/add-prikbord/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#addPrikbordDiv').html('Je bericht is verstuurd.');
            window.location.replace(location.href);

        }
    });
}
function removePrikbordBericht(id,head) {
    jQuery.ajax({
        url: "/engine/responders/account/remove-prikbord/?action=remove&prikbordid=" + id,
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function createAccount(head) {
    var form = $("#createAccountForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/add/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function changeAccount(head) {
    var form = $("#accountGegevensForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/change-account/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function createProfile(head) {
    var form = $("#createProfileForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/create-profile/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function changeProfile(head) {
    var form = $("#profielGegevensForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/change-profile/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function activateAccount(head) {
    var form = $("#activateAccountForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/activate/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function resetPassword(head) {
    var form = $("#resetPasswordForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/reset-password/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function changePassword(head) {
    var form = $("#changePasswordForm");
    var senddata = form.serialize();
    jQuery.ajax({
        url: "/engine/responders/account/change-password/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function photoUploader(head) {
    var filename = $("#filename").val();
    var location = '/engine/responders/account/photo-upload/?filename=filename';
    var status = '<img src="/vormgeving/photoUploadLoader.gif" alt="status">';
    var foutcode = 'Fout: Er ging iets mis. Probeer het nogmaals';
    ajaxUpload(document.photoUploadForm, location, 'uploadArea', status, foutcode);
    $('#filename').val('');
    $('#photoUploadExplain').html('Wil je nog een foto uploaden? Dat kan door nog een foto te selecteren zodra je foto geupload is.');
    return false;
}
function updateCoords(c) {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#w').val(c.w);
    $('#h').val(c.h);
};
function checkCoords() {
    if (parseInt($('#w').val())) return true;
    alert('Maak eerst een selectie hoe je de foto wilt bijsnijden en klik dan op wijzig.');
    return false;
};
function selectPhotoForCrop(photo) {
    $('#cropPhoto').html('<img src="' + photo + '" id="cropbox" >');
    $('#cropBtn').show();
    $('#photo').val(photo);
    $(function() {
        $('#cropbox').Jcrop({
            aspectRatio: 1,
            onSelect: updateCoords
        });
    });
}
function selectPhotoForDelete(photo) {
    $('#deletePhoto').html('<img src="' + photo + '" id="deletebox" >');
    $('#deleteBtn').show();
    $('#photo').val(photo);
}
function jcropDestroy() {
    $('#cropbox').Jcrop({
        destroy: true
    });
}
function photoCropper(head) {
    var cords = checkCoords();
    if (cords == true) {
        var form = $("#cropPhotoForm");
        var senddata = form.serialize();
        jQuery.ajax({
            url: "/engine/responders/account/change-profile-photo/",
            method: 'post',
            data: senddata,
            dataType: "html",
            success: function(data) {
                $('#cropBtn').hide();
                $('#cropPhoto').html('');
                $('#msgBoxHead').text(head);
                $('#msgBoxText').html(data);
                msgBoxOpen();
            }
        });
    }
}
function photoDelete(head) {
    var form = $("#deletePhotoForm");
    var senddata = form.serialize();
    var photo = $("#photo").val();
    var photo = photo.replace("/photobooks/", "");
    jQuery.ajax({
        url: "/engine/responders/account/photo-delete/",
        method: 'post',
        data: senddata,
        dataType: "html",
        success: function(data) {
            $('#deleteBtn').hide();
            $('#deletePhoto').html('');
            $('#' + photo).remove();
            $('#msgBoxHead').text(head);
            $('#msgBoxText').html(data);
            msgBoxOpen();
        }
    });
}
function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
        alert('Je mag maximaal 255 karakters typen.');
        return false;
    } else {
        countfield.value = maxlimit - field.value.length;
    }
}
var versus = new versus();
