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('
');
                // Get the input field
                var input = document.getElementById("oqrssearch");
                // Execute a function when the user presses a key on the keyboard
                input.addEventListener("keypress", function(event) {
                // If the user presses the "Enter" key on the keyboard
                if (event.key === "Enter") {
                    // Cancel the default action, if needed
                    event.preventDefault();
                    // Trigger the button element with a click
                    document.getElementById("stationbuttonsubmit").click();
                }
                });
            } 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().toUpperCase()},
        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().toUpperCase()},
        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!
× 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!
',
			qso.requesttime,
			qso.date,
			qso.time,
			qso.band,
			qso.mode,
			qso.requestcallsign,
			qso.station_callsign,
			qso.email,
			qso.note,
			echo_qsl_method(qso.qslroute),
			echo_searchlog_button(qso.requestcallsign, qso.id),
            echo_status(qso.status),
		];
		
		let createdRow = table.row.add(data).index();
		table.rows(createdRow).nodes().to$().data('oqrsID', qso.id);
		table.row(createdRow).node().id = 'oqrsID_' + qso.id;
	}
    table.columns.adjust().draw();
}
function echo_status(status) {
	switch(status.toUpperCase()) {
		case '0': return 'Open request'; break;
		case '1': return 'Not in log request'; break;
		case '2': return 'Request done'; break;
        default: return '';
	}
}
function echo_qsl_method(method) {
	switch(method.toUpperCase()) {
		case 'B': return 'Bureau'; break;
		case 'D': return 'Direct'; break;
		case 'E': return 'Electronic'; break;
        default: return '';
	}
}
function echo_searchlog_button(callsign, id) {
    return '