// inscription infolettre
function inscription_infolettre()
{
    // if ready to accept
    if (ready_to_accept())
    {
        // build the command string
        sCommand = '/ajax_commands/inscription_infolettre.php?email=' + document.getElementById('infolettre_adresse').value;
        sCommand += '&first_name=' + document.getElementById('infolettre_prenom').value;
        sCommand += '&last_name=' + document.getElementById('infolettre_nom').value;
        
        // open XML feed
        xmlHttp.open('GET', sCommand);
        
        // when changes are occuring in status
        xmlHttp.onreadystatechange = function myFunction()
        {
            if (ready_to_process())
            {
                document.getElementById('infolettre_division').innerHTML = 'Inscription Effectuée avec succès';
            }
        }
        
        // send the xml feed
        xmlHttp.send(null);
    }
    // if not ready
    else
    {
        // attempt after 250ms
        setTimeout('inscription_infolettre()', 250);
    }
}

function voteSondage(iSondageId, iAnswerId)
{
    // if ready to accept
    if (ready_to_accept())
    {
        // build the command string
        sCommand = '/ajax_commands/vote_sondage.php?sondage_id=' + iSondageId + '&reponse=' + iAnswerId;
        
        // open the XML feed
        xmlHttp.open('GET', sCommand);
        
        // when on changes are occuring in status
        xmlHttp.onreadystatechange = function myFunction()
        {
            // if ready to process
            if (ready_to_process())
            {
                // replace the html of the survey
                if (xmlHttp.responseText == 'OK')
                {
                    replaceSurvey();
                }
            }
        };
        
        // send the xml feed
        xmlHttp.send(null);
    }
    
    // if not ready
    else
    {
        // attempt again after 250ms
        setTimeout('voteSondage(' + iSondageId + ', ' + iAnswerId + ')', 250);
    }
}

/**
 * function used to replace the survey container with some content
 */
function replaceSurvey()
{
    // build the command
    sCommand = '/ajax_commands/get_survey.php';
    
    // if ready to accept
    if (ready_to_accept())
    {
        //open the xml feed
        xmlHttp.open('GET', sCommand);
        
        // when there's a change in the xml feed status
        xmlHttp.onreadystatechange = function myFunction()
        {
            // if ready to process
            if (ready_to_process())
            {
                document.getElementById('survey_area').innerHTML = xmlHttp.responseText;
            }
        }
        
        // send the feed
        xmlHttp.send(null);
    }
    
    // if not ready
    else
    {
        // attempt after 250ms
        setTimeout('replaceSurvey()', 250);
    }
}
