/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @author:  Steve Phillips <steve@visual77.com>
* @created: February 10, 2010
*/


// ==UserScript==
// @name           Greased PMA
// @namespace      http://visual77.com/blog/
// @description    Provide enhanced functionality to phpmyadmin query windows
// @include        *querywindow.php*
// @version        0.1
// ==/UserScript==

if(document.getElementById('sqlqueryform')) {
    
    document.getElementById('sqlquery').style.height = (window.innerHeight - 185)+'px';
    setInterval(function() {
        document.getElementById('sqlquery').style.height = (window.innerHeight - 185)+'px';
    }, 500);
    
    document.getElementById('sqlquery').addEventListener('keypress', function(e) {  
        if(e.keyCode == 13 && e.ctrlKey) {
            document.getElementById('sqlqueryform').submit();
        } else if (e.keyCode == 9 && !e.shiftKey) {
            e.preventDefault();
            var sqlquery = document.getElementById('sqlquery');
            var cursorloc = sqlquery.selectionStart;
            var beforecursor = sqlquery.value.substring(0,cursorloc);
            var aftercursor = sqlquery.value.substring(cursorloc);
            sqlquery.value = beforecursor + "    " + aftercursor;
            sqlquery.selectionStart = cursorloc + 4;
            sqlquery.selectionEnd = sqlquery.selectionStart;
        }
    }, true);
    
}
