function changeFaqOrder(iFaqId, iNewOrder, bIsBefore) {
    if (ready_to_accept()) {
        xmlHttp.open('GET', '/ajax_commands/change_faq_order.php?faqs_id=' + iFaqId + '&display_order=' + iNewOrder + '&is_before=' + bIsBefore);
        xmlHttp.onreadystatechange = function myFunction() {
            if (ready_to_process()) {
                aList = xmlHttp.responseText.split('|');

                for (a = 0; a < aList.length; a++) {
                    aRecord = aList[a].split('-');

                    document.getElementById('row_' + aRecord[0]).innerHTML = aRecord[1];
                }
            }
        }
        xmlHttp.send(null);
    }
    else {
        setTimeout('changeFaqOrder(' + iFaqId + ', ' + iNewOrder + ')', 250);
    }
}

/**
* Thsi function will retreive the error message of a javascript form
*/
function getErrorMessage(sErrorKey) {
    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_error_message.php?error_key=' + sErrorKey);

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if we are ready to process
            if (ready_to_process()) {
                // return the response
                alert(xmlHttp.responseText);
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if we are not ready
    else {
        // try again in 250 MS
        setTimeout('getErrorMessage("' + sErrorKey + '")', 250);
    }
}

/**
* This function will detect if we are using captcha or not
*/
function checkCaptcha() {
    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/check_captcha.php');

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if we are ready to process
            if (ready_to_process()) {
                // return the response
                if (xmlHttp.responseText == 'yes') {
                    return true;
                }
                else {
                    return false;
                }
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('checkCaptcha()', 250);
    }
}

/**
* Get google maps company
*/
function getGoogleMapsCompany() {
    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_company.php');

        // when status change
        xmlHttp.onreadystatechange = function myFunction() {
            // if we are ready to process
            if (ready_to_process()) {
                document.getElementById('google_maps_company').innerHTML = xmlHttp.responseText;
                return true;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsCompany()', 250);
    }
}

/**
* This will get the google maps city
*/
function getGoogleMapsCity() {
    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_city.php');

        // when status change
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // set the city
                document.getElementById('google_maps_city').innerHTML = xmlHttp.responseText;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsCity()', 250);
    }
}

/**
* This will get the google maps address
*/
function getGoogleMapsAddress() {
    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_address.php');

        // when status change
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // set the address
                document.getElementById('google_maps_address').innerHTML = xmlHttp.responseText;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsAddress()', 250);
    }
}

/**
* This will get the google maps province
*/
function getGoogleMapsProvince() {
    // if ready to process
    if (ready_to_process()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_province.php');

        //when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // set the province
                document.getElementById('google_maps_province').innerHTML = xmlHttp.responseText;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsProvince()', 250);
    }
}

/**
* Thsi function will get the rotating image delay
*/
function getRotatingImageDelay() {
    xmlHttp.open('GET', '/ajax_commands/get_image_delay.php', false);
    xmlHttp.send(null);
    return xmlHttp.responseText;
}

/**
* This function will get the transition duration
*/
function getRotatingTransitionDuration() {
    xmlHttp.open('GET', '/ajax_commands/get_transition_duration.php', false);
    xmlHttp.send(null);
    return xmlHttp.responseText;
}

/**
* This will get the google maps country
*/
function getGoogleMapsCountry() {
    // if ready to process
    if (ready_to_process()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_country.php');

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // set the country
                document.getElementById('google_maps_country').innerHTML = xmlHttp.responseText;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsCountry()', 250);
    }
}

/**
* Get google maps zipcode
*/
function getGoogleMapsZipcode() {
    // if ready to process
    if (ready_to_process()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/get_google_maps_zipcode.php');

        // as status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // set the zipcode
                document.getElementById('google_maps_zipcode').innerHTML = xmlHttp.responseText;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250ms
        setTimeout('getGoogleMapsZipcode()', 250);
    }
}


/**
* This function will check if we are using multiple languages
*/
function checkMultipleLanguage() {
    // initiate a return variable
    var bReturn;

    // if we are ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/check_multiple_language.php');

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if we are ready to process
            if (ready_to_process()) {
                if (xmlHttp.responseText == 'true') {
                    alert(xmlHttp.responseText);

                    bReturn = 'true';
                }
                else {
                    bReturn = 'false';
                }

                return bReturn;
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // repeat after 250mms
        setTimeout('checkMultipleLanguage()', 250);
    }
}

/**
* This function will retreive the list of attribute choices
*/
function getAtributeChoices(iAttributeId) {
    if (ready_to_accept()) {
        xmlHttp.open('GET', '/ajax_commands/get_attribute_choices.php?product_attributes_id=' + iAttributeId);
        xmlHttp.onreadystatechange = function myFunction() {
            if (ready_to_process()) {
                droplist = document.price_configuration_form.attribute_choices_id;
                droplist.options.length = 1;

                aAttributeChoices = xmlHttp.responseText.split('|');

                if (aAttributeChoices.length != 0) {
                    for (a = 0; a < aAttributeChoices.length; a++) {
                        aChoice = aAttributeChoices[a].split('*');

                        var newOption = document.createElement('OPTION');
                        newOption.text = aChoice[1];
                        newOption.value = aChoice[0];
                        droplist.options.add(newOption);
                    }
                }
            }
        }
        xmlHttp.send(null);
    }
    else {
        setTimeout('getAttributeChoices(' + iAttributeId + ')', 250);
    }
}

/**
* This function will display the add new block container
*/
function showAddNewBlock(iPageId) {
    // if ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/show_new_text_block.php?page_details_id=' + iPageId);

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // get the response text and put into container
                document.getElementById('main_section').innerHTML = xmlHttp.responseText;

                // get the instance
                var instance = CKEDITOR.instances['new_block_text'];

                // if the instance exists
                if (instance) {
                    // remove it
                    CKEDITOR.remove(instance);
                }

                // replace the text area with a CKEditor instance
                CKEDITOR.replace('new_block_text',
                {
                    filebrowserBrowseUrl: "/kfm/"
                });
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // repeat after 250ms
    else {
        setTimeout('showAddNewBlock(' + iPageId + ')', 250);
    }
}

/**
* This function will display the content container in the page
*/
function showPageContentBlock(iPageId) {
    // open the feed
    xmlHttp.open('GET', '/ajax_commands/show_page_container.php?page_details_id=' + iPageId, false);

    // send the feed
    xmlHttp.send(null);
    // get the response text and put into container
    document.getElementById('main_section').innerHTML = xmlHttp.responseText;

    // get the instance
    var instance = CKEDITOR.instances['page_content_text'];

    // if the instance exists
    if (instance) {
        // destroy it
        CKEDITOR.remove(instance);
    }

    // replace the textarea with a CKEditor instance
    CKEDITOR.replace('page_content_text',
                {
                    filebrowserBrowseUrl: "/kfm/"
                });

    // hide all
    hideAll();

    // set the background color
    document.getElementById('main_link').style.backgroundColor = '#C0C0C0';

}

/**
* This function will show a text container
*/
function showTextContainer(iPageId) {
    // if ready to accept
    if (ready_to_accept()) {
        // open the feed
        xmlHttp.open('GET', '/ajax_commands/show_text_block_container.php?page_details_id=' + iPageId);

        // when status changes
        xmlHttp.onreadystatechange = function myFunction() {
            // if ready to process
            if (ready_to_process()) {
                // get the response and put in main content
                document.getElementById('main_section').innerHTML = xmlHttp.responseText;

                // get the instance
                var instance = CKEDITOR.instances['text_block_' + iPageId];

                // if the instance exists
                if (instance) {
                    // destroy it
                    CKEDITOR.remove(instance);
                }

                // replace the textarea with a CKEDITOR instance
                CKEDITOR.replace('text_block_' + iPageId,
                {
                    filebrowserBrowseUrl: "/kfm/"
                });

                // hide all
                hideAll();

                // set the tab active
                setTabActive('text_block_' + iPageId);

                // display the main section
                document.getElementById('main_section').style.display = '';
            }
        }

        // send the feed
        xmlHttp.send(null);
    }

    // if not ready
    else {
        // retry after 250ms
        setTimeout('showTextContainer(' + iPageId + ')', 250);
    }
}
/**
* This function will reload the parent window's product gallery list to select the one we just created
*/
function reloadParentGalleryList(iGalleryId) {
    // open the call
    xmlHttp.open('GET', '/ajax_commands/refresh_product_galleries_list.php', false);

    // send the call
    xmlHttp.send(null);

    // set the droplist from the opener
    droplist = opener.document.product_form.image_gallery_id;
    // set the list length to one
    droplist.options.length = 1;
    // explode the list of galleries
    aGalleryChoices = xmlHttp.responseText.split('|');

    // if we have at least one choice avvailable
    if (aGalleryChoices.length != 0) {
        // for each choice available
        for (a = 0; a < aGalleryChoices.length; a++) {
            // explode the choice
            aChoice = aGalleryChoices[a].split('*');

            // create the new option
            var newOption = opener.document.createElement('OPTION');
            // set the option text
            newOption.text = aChoice[1];
            // set the option value
            newOption.value = aChoice[0];

            // if the choice is the one selected
            if (iGalleryId == aChoice[0]) {
                // set the option as selected
                newOption.selected = true;
            }

            // add the option into the list
            droplist.options.add(newOption);
        }
    }
}

// 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()) {
                if (document.getElementById('infolettre_division')) {
                    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 timeoutRefresh(sPage) {
    for (a = 1; a <= blocks; a++) {

        var oObject = document.getElementById('block_' + a + '_content');

        if (oObject) {
            xmlHttp.open('GET', '/ajax_commands/reload_block_content.php?block=' + a + '&page=' + sPage, false);
            xmlHttp.send(null);

            document.getElementById('block_' + a + '_content').innerHTML = xmlHttp.responseText;
        }
    }

    sAjaxUrl = document.location.href.replace('http://' + document.location.hostname, '');
    sAjaxUrl = sAjaxUrl.replace('?building=true', '');

    xmlHttp.open('GET', '/ajax_commands/get_page_structure_elements.php?url=' + sAjaxUrl, false);
    xmlHttp.send(null);

    aElements = xmlHttp.responseText.split(',');
    

    // for all elements
    for (a = 0; a < aElements.length; a++) {
        // get the url of the control
        sUrl = document.getElementById('structure_' + aElements[a] + '_edit').href;

        // replace height and width
        sUrl = sUrl.replace('width=600', 'width=' + parent.window.childPrettyPhotoWidth);
        sUrl = sUrl.replace('height=400', 'height=' + parent.window.childPrettyPhotoHeight);

         // replace the url
         document.getElementById('structure_' + aElements[a] + '_edit').href = sUrl;
    }

    jQuery.prettyPhoto.close();
    load_prettyphotos();

    if (document.getElementById('divtreemenu')) {
        ddtreemenu.createTree("treemenu2", false, 5);
    }
}

function closePrettyPhotoStructure(sPage) {

    setTimeout('timeoutRefresh("' + sPage + '")', 1000);
}

function toggleControlRow(sElement) {
    if (document.getElementById(sElement).style.display == 'none') {
        document.getElementById(sElement).style.display = '';
    }
    else {
        document.getElementById(sElement).style.display = 'none';
    }
}

function refreshPageSelector() {
    xmlHttp.open('GET', '/ajax_commands/refresh_page_selector.php', false);
    xmlHttp.send(null);

    oSelectionList = document.getElementById('page_selector');

    iLength = oSelectionList.options.length;

    for (a = iLength; a > 1; a--) {
        oSelectionList.remove(a - 1);
    }
    oSelectionList.options.length = 1;

    aList = xmlHttp.responseText.split('*');

    for (a = 0; a < aList.length; a++) {
        aItem = aList[a].split('@');

        var oOption = document.createElement('option');
        oOption.text = aItem[0];
        oOption.value = aItem[1];

        try {
            oSelectionList.add(oOption, null);
        }

        catch (ex) {
            oSelectionList.add(oOption);
        }
    }

    oSelectionList.selectedIndex = 0;
}

function checkExistingPage() {
    var form = document.rename_form;

    form.url.value = returnNormalizedValue(form.url.value);
    
    xmlHttp.open('GET', '/ajax_commands/check_existing_page.php?url=' + form.url.value + '&language=' + form.language.value + '&page_details_id=' + form.page_details_id.value, false);
    xmlHttp.send(null);

    if (xmlHttp.responseText != 0) {
        alert('Une page est deja presente avec ce nom de fichier. Veuillez selectionner un autre nom');
        form.url.focus();
        document.getElementById('rename_button').disabled = true;
        return false;
    }
    else {
        if (document.getElementById('old_address_container').innerHTML.replace('.php', '') == form.url.value) {
            alert('Le nouveau nom de fichier est le meme que l\'ancien. Veuillez choisir un autre nom');
            form.url.focus();
            document.getElementById('rename_button').disabled = true;
        }
        else {
            document.getElementById('rename_button').disabled = false;
        }
    }
}

function returnNormalizedValue(sValue) {
    xmlHttp.open('GET', '/ajax_commands/return_normalized_value.php?value=' + sValue, false);
    xmlHttp.send(null);

    return xmlHttp.responseText;
}

function getCSSPropertyDescription(sProperty) {
    xmlHttp.open('GET', '/ajax_commands/get_css_property_description.php?property=' + sProperty, false);
    xmlHttp.send(null);

    document.getElementById('property_description').innerHTML = xmlHttp.responseText;

    if (sProperty == 'background-image') {
        document.getElementById('background_image_section').style.display = '';
    }
    else {
        document.getElementById('background_image_section').style.display = 'none';
    }
}
