function debug(node) {
    var str= '';
   for(var prop in node) if( node[prop]!=null ) str += prop + ': ' + node[prop] + '\n';
   alert(str);
}

var run_scheduled = false;

function check_input() {
//    if (!e) e = window.event;
//    var src = e.target || e.srcElement;
//    var keyInfo = String.fromCharCode(e.keyCode);
    run_scheduled = false;

    var type = document.getElementById('scope').value;
    var input = document.getElementById('req_text');
    var text = input.value;
    text = text.replace(new RegExp("^[\\s.,;-]+|[\\s.,;]+$", "g"), "");
    var bad = ( text.match(/[ієїґ]/i) && text.match(/[ыъэё]/i) )
	    || ( text.match(/[ієїґ]/i) && (type=='rus' || type=='rusb'))
	    || ( text.match(/[ыёъэ]/i) && (type=='ukr' || type=='ukrq'))
	    || ( text.match(/[^ *?а-яёієїґ''’́-]/i) && type != 'lat' )
	    || ( text.match(/[^ *?a-z''’́-]/i) && type == 'lat' );
    if( bad )
	input.style.background = '#ff8080';
    else
	input.style.background = '';
}

function run_async() {
    if( ! run_scheduled ) {
	run_scheduled = true;
	setTimeout(check_input, 400);
    }
}

function init_input_check() {
//    document.getElementById('req_text').onchange = check_input;
//    document.getElementById('req_text').onkeypress = "setTimeout('check_input', 100)";
    document.getElementById('req_text').onkeydown = run_async;
    document.getElementById('req_text').onchange = run_async;
    document.getElementById('req_text').onmousedown = run_async;
    document.getElementById('scope').onchange = run_async;

    document.getElementById('req_text').focus();
}

