$(document).ready(function() {

$('.datefield').datepicker({dateFormat: 'yy-mm-dd',changeYear: true,changeMonth: true});

$('.modalLink').nyroModal();

$('.timefield').timepickr({trigger: 'click'});

$('.dataTable').dataTable({
            "bLengthChange" : false,
            "iDisplayLength": 30,
            "sPaginationType": "full_numbers",
            "oLanguage": {
                "sZeroRecords": "Ingen data funnet",
                "sProcessing": "Laster...",
                "sLengthMenu": "Vis _MENU_ treff",
                "sInfo": "Viser _START_ til _END_ av _TOTAL_ treff",
                "sInfoEmpty": "Viser 0 til 0 av 0 treff",
                "sInfoFiltered": "(filtrert fra _MAX_ totalt treff)",
                "sSearch": "Søk:",
                "oPaginate": {
                        "sFirst":    "Første",
                        "sPrevious": "Forrige",
                        "sNext":     "Neste",
                        "sLast":     "Siste"
            }
        }
});

$('.dataTableFirstColumnSortedDescending').dataTable({
            "bLengthChange" : false,
            "iDisplayLength": 30,
            "sPaginationType": "full_numbers",
            "aaSorting": [[ 0, "desc" ]],
            "oLanguage": {
                "sZeroRecords": "Ingen data funnet",
                "sProcessing": "Laster...",
                "sLengthMenu": "Vis _MENU_ treff",
                "sInfo": "Viser _START_ til _END_ av _TOTAL_ treff",
                "sInfoEmpty": "Viser 0 til 0 av 0 treff",
                "sInfoFiltered": "(filtrert fra _MAX_ totalt treff)",
                "sSearch": "Søk:",
                "oPaginate": {
                        "sFirst":    "Første",
                        "sPrevious": "Forrige",
                        "sNext":     "Neste",
                        "sLast":     "Siste"
            }
        }
});

});

function getFileUpload(browse_id, owner, owner_id, buttonText, completeFunction) {

$(browse_id).uploadify ({
'uploader'      : '/js/jquery_uploadify/uploadify.swf',
'script'        : '/file/upload',
'cancelImg'     : '/js/jquery_uploadify/cancel.png',
'auto'          : true,
'scriptData'    : {'owner': owner,'owner_id':owner_id},
'buttonText'    : buttonText,
'onComplete'    : completeFunction,
'onError'       : fileUploadErrorFunction
});

}

function fileUploadErrorFunction(event,queueID,fileObj,errorObj){

    alert(errorObj);
}

function setSuccessMessage(message){
    $('#s_messages').html('<div id="s_message" class="s_message s_messageSuccess">'+message+'</div>')
    $("#s_messages").fadeIn();
    setTimeout(function(){
      $("#s_messages").fadeOut("", function () {
          $("#s_messages").html('');
          $("#s_messages").hide();
        }); }, 5000);
}

function showReportMenu(id) {
    if ($('#reportMenu' + id + ' ul').css("display") == "block") {
        $('#reportMenu' + id + ' ul').hide();
     } else {
        $('.reportMenu ul').hide();
        $('#reportMenu' + id + ' ul').show();
    }
}
