function loadStationInfo() {
    $(".stationinfo").empty();
    $(".searchinfo").empty();
    $.ajax({
        url: base_url+'index.php/oqrs/get_station_info',
        type: 'post',
        data: {'station_id': $("#station").val()},
        success: function (data) {
            if (data.count > 0) {
                $(".stationinfo").append('
' + data.count + ' Qsos logged between ' + data.mindate + ' and ' + data.maxdate + '.
');
                $(".stationinfo").append('
');
            } else {
                $(".stationinfo").append("No QSOs for this callsign was found!");
            }
        }
    });
}
function searchOqrs() {
    $(".searchinfo").empty();
    $.ajax({
        url: base_url+'index.php/oqrs/get_qsos',
        type: 'post',
        data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()},
        success: function (data) {
            $(".searchinfo").append(data);
        }
    });
}
function notInLog() {
    $.ajax({
        url: base_url + 'index.php/oqrs/not_in_log',
        type: 'post',
        data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()},
        success: function(html) {
            $(".searchinfo").html(html);
        }
    }); 
}
function saveNotInLogRequest() {
    $(".alertinfo").remove();
    if ($("#emailInput").val() == '') {
        $(".searchinfo").prepend('×You need to fill out an email address!
 ×You need to fill the QSO information before submitting a request!
 
×Your not in log query has been saved!
 ');
                }
            });
        }
    }
}
function oqrsAddLine() {
    var rowCount = $('.notinlog-table tr').length;
    var $myTable = $('.notinlog-table');
    var $row = $('|
');
    var $iterator = $('').html(rowCount);
    var $date = $(' | ').html('');
    var $time = $(' | ').html('');
    var $band = $(' | ').html('');
    var $mode = $(' | ').html('');
    $row.append($iterator, $date, $time, $band, $mode);
    $myTable.append($row);
}
function requestOqrs() {
    $.ajax({
        url: base_url + 'index.php/oqrs/request_form',
        type: 'post',
        data: {'station_id': $("#station").val(), 'callsign': $("#oqrssearch").val()},
        success: function(html) {
            $(".searchinfo").html(html);
            $('.result-table').DataTable({
                "pageLength": 25,
                responsive: false,
                ordering: false,
                "scrollY": "410px",
                "scrollCollapse": true,
                "paging": false,
                "scrollX": true,
            });
        }
    }); 
}
function submitOqrsRequest() {
    $(".alertinfo").remove();
    if ($("#emailInput").val() == '') {
        $(".searchinfo").prepend(' | ×You need to fill out an email address!
 ×You need to fill the QSO information before submitting a request!
 
×Your QSL request has been saved!
 ');
                }
            });
        }
    }
}
function deleteOqrsLine(id) {
    BootstrapDialog.confirm({
		title: 'DANGER',
		message: 'Warning! Are you sure you want to delete this OQRS request?',
		type: BootstrapDialog.TYPE_DANGER,
		closable: true,
		draggable: true,
		btnOKClass: 'btn-danger',
		callback: function (result) {
			$.ajax({
                url: base_url+'index.php/oqrs/delete_oqrs_line',
                type: 'post',
                data: { 'id': id,
                },
                success: function (data) {
                    $(".oqrsid_"+id).remove();
                }
            });
		}
	});
}
function searchLog(callsign) {
    $.ajax({
        url: base_url + 'index.php/oqrs/search_log',
        type: 'post',
        data: {'callsign': callsign,
        },
        success: function(html) {
            BootstrapDialog.show({
                title: 'QSO List',
                size: BootstrapDialog.SIZE_WIDE,
                cssClass: 'qso-dialog',
                nl2br: false,
                message: html,
                onshown: function(dialog) {
                    $('[data-toggle="tooltip"]').tooltip();
                },
                buttons: [{
                    label: 'Close',
                    action: function (dialogItself) {
                        dialogItself.close();
                    }
                }]
            });
        }
    });
}
function searchLogTimeDate(id) {
    $.ajax({
        url: base_url + 'index.php/oqrs/search_log_time_date',
        type: 'post',
        data: {'time': $('.oqrsid_'+id+ ' td:nth-child(2)').text(),
            'date': $('.oqrsid_'+id+ ' td:nth-child(1)').text(),
            'band': $('.oqrsid_'+id+ ' td:nth-child(3)').text(),
            'mode': $('.oqrsid_'+id+ ' td:nth-child(4)').text()
        },
        success: function(html) {
            BootstrapDialog.show({
                title: 'QSO List',
                size: BootstrapDialog.SIZE_WIDE,
                cssClass: 'qso-dialog',
                nl2br: false,
                message: html,
                onshown: function(dialog) {
                    $('[data-toggle="tooltip"]').tooltip();
                },
                buttons: [{
                    label: 'Close',
                    action: function (dialogItself) {
                        dialogItself.close();
                    }
                }]
            });
        }
    });
}
function markOqrsLineAsDone(id) {
    $.ajax({
        url: base_url+'index.php/oqrs/mark_oqrs_line_as_done',
        type: 'post',
        data: { 'id': id,
        },
        success: function (data) {
            $(".oqrsid_"+id).remove();
        }
    });
}