/********************************************************
 *                                                      *
 * Script serving Country selection process             *
 * Copyright (c), Intelrate, 2008                       *
 *                                                      *
 ********************************************************/

/// asynchronous request to the server
var httpObject = getXmlHttpObject();

/** Identifier of flag element. */
var Registration =
{
    flagId : ''
};

/**
 * Gets selected country and sends request to the server in order ot display the flag.
 *
 * @param selectId identifier of pulldown list of countries
 * @param flagId identifier of span to put flag image into
 */
function countryChanged(selectId, flagId)
{
    Registration.flagId = flagId;

    var selectElement = document.getElementById(selectId);
    var countryUid = selectElement.options[selectElement.selectedIndex].value;

    httpObject.open('GET', '/account/SelectCountryHandler.php?'
                         + flagId + '=' + countryUid);
    httpObject.onreadystatechange = showSelectCountryStatus;
    httpObject.send(null);
}

/**
 * Handles asynchronous response from the server and displays a flag of selected country.
 * TODO: refactor this to use standard update web form function from common.js
 */
function showSelectCountryStatus()
{
    if (httpObject.readyState == 4)
    {
        var response = httpObject.responseText;
        document.getElementById(Registration.flagId).innerHTML = response;
    }
}

