/*
 *
 */

function submit_form(f) {
    if (f.query.value == "") {
        return false;
    } else {
        //document.getElementById('popup').style.visibility = 'visible';
        document.qbox.submit.value='Stop execution';
        document.qbox.onsubmit = function onsubmit(event) {
            return abort_query();
        }
        return true;
    }
}

function hide_popup() {
    //document.getElementById('popup').style.visibility = 'hidden';
    document.qbox.submit.value = 'Execute';
    document.qbox.onsubmit = function onsubmit(event) {
        return submit_form(this);
    }
}

function abort_query() {
    var xmlHttpReq = false;
    var self = this;

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', 'abort', true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            history.go(0);
            hide_popup(); 
        }
    }
    self.xmlHttpReq.send('');
}
