// <!-- To allow Internet Explorer to change the color of the row where the mouse is over by changing the label from hover to hilite -->
// var rows = document.getElementsByTagName('tr');
// for (var i = 0; i < rows.length; i++) {
//     rows[i].onmouseover = function() {
//         this.className += ' hilite';
//     }
//     rows[i].onmouseout = function() {
//         this.className = this.className.replace('hilite', '');
//     }
// }


function is_punct(char)
{
    if (char == ' ' || char == ';' || char == ',') return(true);
    return(false);
}

var finished = true;

function get_results(check)
{
    var length = document.symptoms.symptoms.value.length;

    if (length == 0) return;

    if (check == true) 
    {
        var last_char = document.symptoms.symptoms.value.charAt(length-1);

        if (!is_punct(last_char)) // if the last char is not a punctuation sign
        {
            reset_timer();
            return;
        }
    }

    if (finished == false) return;
    finished = false;

    open_url('http://www.lookfortherapy.com/results.php' +
             '?lang=' + document.symptoms.lang.value +
             '&symptoms=' + document.symptoms.symptoms.value + 
             '&mode=' + 'F' + //document.symptoms.mode.value + 
             '&parent=' + document.symptoms.parent.value +
             '&only_table=1', document.getElementById("results"));
}

function open_url(url, containerid)
{
    var page_request = false;

    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    {
        page_request = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) // if IE
    { 
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){}
        }
    }
    else {
        return false; 
    }

    page_request.onreadystatechange = function() { loadpage(page_request, containerid); }

    page_request.open('GET', url, true);
    page_request.send(null);
}

function loadpage(page_request, containerid)
{
    if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http")==-1))
    {
        containerid.innerHTML = page_request.responseText;

        finished = true;
    }
}

function redirect()
{
    location.href = 'http://www.lookfortherapy.com/results.php' +
                    '?lang=' + document.symptoms.lang.value +
                    '&symptoms=' + document.symptoms.symptoms.value + 
                    '&mode=' + 'F' + //document.symptoms.mode.value + 
                    '&parent=' + document.symptoms.parent.value;
}


var timeout = "";
function reset_timer()
{
    if (timeout != "") {
        clearTimeout(timeout);
        if (timeout2 != "") {
            clearTimeout(timeout2);
        }
    }
    timeout = setTimeout('get_results(false)', 1000); 
}

var timeout2 = "";
function reset_timer2()
{
    if (timeout2 != "") {
        clearTimeout(timeout2);
    }
    timeout2 = setTimeout('redirect()', 2000); 
}
