function get_states(iCountry) {
    if (ready_to_accept()) {
        xmlHttp.open('GET', '/ajax_commands/get_states.php?countries_id=' + iCountry);
        xmlHttp.onreadystatechange = function myFunction() {
            if (ready_to_process()) {
                sStates = xmlHttp.responseText;
                aStates = sStates.split('~');
                j = 1;

                for (i in aStates) {
                    aState = aStates[i].split('|');
                    j++;
                    document.theForm.states_id.length = j;
                    document.theForm.states_id.options[j - 1].text = aState[1];
                    document.theForm.states_id.options[j - 1].value = aState[0];
                }
                document.theForm.states_id.options[0].selected = true;
            }
        }
        xmlHttp.send(null);
    }
    else {
        setTimeout('get_states(' + iCountry + ')', 250);
    }
}

function get_cities(iCountry, iState) {
    if (ready_to_accept()) {
        xmlHttp.open('GET', '/ajax_commands/get_cities.php?countries_id=' + iCountry + '&states_id=' + iState);
        xmlHttp.onreadystatechange = function myFunction() {
            if (ready_to_process()) {
                sCities = xmlHttp.responseText;
                aCities = sCities.split('~');
                j = 1;

                for (i in aCities) {
                    aCity = aCities[i].split('|');
                    j++;
                    document.theForm.cities_id.length = j;
                    document.theForm.cities_id.options[j - 1].text = aCity[1];
                    document.theForm.cities_id.options[j - 1].value = aCity[0];
                }
                document.theForm.cities_id.options[0].selected = true;
            }
        }
        xmlHttp.send(null);
    }
    else {
        setTimeout('get_cities(' + iCountry + ', ' + iState + ')', 250);
    }
}

function rate_video(iVideo, iScore) {
    if (ready_to_accept()) {
        xmlHttp.open('GET', '/ajax_commands/rate_video.php?videos_id=' + iVideo + '&ratings=' + iScore);
        xmlHttp.onreadystatechange = function myFunction() {
        if (ready_to_process()) {
            document.getElementById('rating_section').innerHTML = xmlHttp.responseText;
            }
        }
        xmlHttp.send(null);
    }
    else
    {
    setTimeout('rate_video(' + iVideo + ', ' + iScore + ')', 250);
    }
}