/*
    JS file to get games listings on the fly
    Written by Mark Hinch for SEGA (June 2009)
*/

function setValue (whichOne, gameid, theValue) {
    document.getElementById('value_' + whichOne + '_' + '0').value = theValue;
}

function getGenreGames (whichOne, genre, start, limit) {
    infoArea = document.getElementById ('info_' + whichOne + '_' + '0');

    xmlhttpLb = false;
    try {xmlhttpLb = new ActiveXObject ('Msxml2.XMLHTTP');} catch (e) {
        try {xmlhttpLb = new ActiveXObject('Microsoft.XMLHTTP');} catch (E) {
            xmlhttpLb = false;
        }
    }
    if (!xmlhttpLb && typeof XMLHttpRequest != 'undefined') xmlhttpLb = new XMLHttpRequest ();

    paramGetGenreGamesString = '?genreid=' + genre;
    paramGetGenreGamesString += '&start=' + start;
    paramGetGenreGamesString += '&limit=' + limit;

    xmlhttpLb.open ('GET', HTML_TOP + 'ajax/genregames.php' + paramGetGenreGamesString, true);
    xmlhttpLb.onreadystatechange = function () {
        switch (xmlhttpLb.readyState) {
            case 1 : case 2 : case 3 :
                infoArea.innerHTML = '<div class="ajax-loader">&nbsp;</div>';
            break;
            case 4 :
                resultXML = xmlhttpLb.responseXML;
                returnHTML = '';

                result = resultXML.getElementsByTagName ("result");
                games = result[0].getElementsByTagName ('game');
                //returnHTML += '<h1>' + games[0].getAttribute("name") + '</h1>';

                for (a = 0; a < games.length; a++) {
                    returnHTML += games[a].firstChild.nodeValue;
                }

                infoArea.innerHTML = returnHTML;
            break;
        }
    }

    xmlhttpLb.send (null);
    return;
}
