﻿/*____________________________________________
|     _     _ ___      __ _                   |
|    (_)___(_) __|___ / _| |_ __ _ _ _ ___    |
|    | |_ /| \__ | _ \  _|  _/ _` | '_/ -_)   |
|    |_/__||_|___|___/_|  \__\__,_|_| \___|   |
|                                             |
|       ©2010 iziSoftware - Version 1.0       |
|_____________________________________________|

WECounterCoreJS : Affiche un compteur de visites

*/


//Démarrage
$(document).ready(function() {

    WECounterCoreJS.Initialize();

});

var WECounterCoreJS = {

    Initialize: function() {



        if (WEInfoPage.RenderMode != "Export") {
            //alert("Impossible d'executer cette action depuis OpenElement.\n Vous devez mettre en ligne votre page.");
            return false;
        }

        //evite les erreurs php en local
        if ((WEInfoPage.RenderMode == "Export") && (window.location.protocol.match("file+"))) {
            return false;
        }

        // Option d'envoi AJAX 
        var CurDat = new Date().getTime(); //Actualisation du php sous IE
        var options = {
            beforeSubmit: this.showRequest,
            success: this.showResponse,
            url: WEInfoPage.RelativePath + 'WEFiles/Server/WECounter_v' + WEInfoPage.OEVersion + '.php',
            data: { PagePath: WEInfoPage.PageAssociatePath, Culture: WEInfoPage.Culture, Dat: CurDat }
        };

        $.ajax(options);
        return false;
    },

    showRequest: function(formData, jqForm, options) {
    },

    showResponse: function(data, statusText) {
        //alert(data);
        dataInit = data;
        try {
            data = data.substr(data.indexOf("{"), data.lastIndexOf("}") - data.indexOf("{") + 1);
            data = JSON.parse(data);
            for (ID in data) {
                value = data[ID]["Value"] + ""; //Conversion en string
                html = "";
                for (i = 0; i < (data[ID]["Lenght"] - value.length); i++) {
                    html = html + "<div class='OESZ_Digit OESZG_" + ID + "'>0</div>";
                }
                for (i = 0; i < value.length; i++) {
                    //alert(value.charAt(i));
                    html = html + "<div class='OESZ_Digit OESZG_" + ID + "'>" + value.charAt(i) + "</div>";
                }
                $("#" + ID).html(html);
            }
        }
        catch (Err) {
            alert("Error : " + Err.description + "\n\n" + dataInit); //Affichage de l'erreur lorsque l'affichage standard ne fonctionne pas + affichage du retour du php (en cas d'erreur php non parsable
        }


    }

}
