{
    function displayBigSuppPic(imagePath, idPhoto) {
        var oPicture = document.getElementById("bigSuppPic");
        var oRow     = document.getElementById("bigSuppPicRow");
        var oDivDesc = document.getElementById("bigSuppPic_descDiv");
        
        imagePath = imagePath.replace("&amp;", "&");
        
        if(displayBigSuppPic.currentPic != imagePath) {
            displayBigSuppPic.currentPic = imagePath;
            
            // var tempImg = new Image();
            // tempImg.src = imagePath;
            
            // if(tempImg.width > 580) {
                // imagePath += "&canvasWidth=580";
            // }
            // else if(tempImg.width > 460 && tempImg.height > 350) {
                // imagePath += "&canvasWidth=460&canvasHeight=350";
            // }
            
            oPicture.src       = imagePath;
            oRow.style.display = "";
            
            // get the picture's title and description
            var oTitle       = document.getElementById("multiPhoto" + idPhoto + "_title");
            var oDescription = document.getElementById("multiPhoto" + idPhoto + "_description");
            var title        = oTitle.value;
            var desc         = oDescription.value;
            
            if(title == "") title = "&#160;";
            if(desc == "") desc = "&#160;";
            
            oDivDesc.innerHTML = "<div>" + title + "</div>" + desc;
        }
        else {
            oPicture.src       = "";
            oRow.style.display = "none";
            
            displayBigSuppPic.currentPic = "";
        }
    }
    displayBigSuppPic.currentPic = "";
}




// Articles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
    function displayMemberArticle(idArticle) {
        if(idArticle > 0) {
            var sURL = "/ajax-getArticle.php?idArticle=" + idArticle;
            new Ajax.Request(sURL, { asynchronous : false,
                onComplete : function(p_oRequest) {
                    if(p_oRequest.responseText != "") {
                        var oJSON = eval('(' + p_oRequest.responseText + ')');
                        if(oJSON) {
                            if(oJSON.result == "true") {
                                var oArticle = oJSON.article;
                                if(oArticle) {
                                    var code         = oArticle.code;
                                    var label        = oArticle.label;
                                    var description  = oArticle.description;
                                    var picture      = oArticle.picture;
                                    
                                    var saleStore    = oArticle.saleStore;
                                    var saleWeb      = oArticle.saleWeb;
                                    var saleLink     = oArticle.saleLink;
                                    
                                    var displayPrice = oArticle.displayPrice;
                                    var costPrice    = oArticle.costPrice;
                                    
                                    
                                    var oPopup_content = document.getElementById("popup_articleBox_content");
                                    if(oPopup_content) {
                                        oPopup_content.innerHTML = "";
                                        
                                        var sHTML = "";
                                        sHTML += "<table class=\"form\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%;\">";
                                            sHTML += "<tbody>";
                                                sHTML += "<tr>";
                                                    if((picture && picture != "") || (saleStore == 1 || (saleWeb == 1 && saleLink != ""))) {
                                                        sHTML += "<td class=\"articleLeft\">";
                                                            sHTML += "<table class=\"form\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%;\">";
                                                                sHTML += "<tbody>";
                                                                    // article picture
                                                                    if(picture && picture != "") {
                                                                        sHTML += "<tr>";
                                                                            sHTML += "<td class=\"articleImage\">";
                                                                                sHTML += "<a href=\"/" + picture + "\" target=\"_blank\">";
                                                                                    sHTML += "<img border=\"0\" src=\"/getImage.php?path=" + picture + "&canvasWidth=250\" />";
                                                                                sHTML += "</a>";
                                                                            sHTML += "</td>";
                                                                        sHTML += "</tr>";
                                                                        //sHTML += "<tr class=\"separator\"><td /></tr>";
                                                                    }
                                                                    // article store & web
                                                                    if(saleStore == 1 || (saleWeb == 1 && saleLink != "")) {
                                                                        // section : availability
                                                                        sHTML += "<tr>";
                                                                            sHTML += "<td class=\"articleSection\">";
                                                                                sHTML += "Vente";
                                                                            sHTML += "</td>";
                                                                        sHTML += "</tr>";
                                                                        sHTML += "<tr>";
                                                                            sHTML += "<td>";
                                                                                sHTML += "<ul>";
                                                                                    if(saleStore == 1) {
                                                                                        sHTML += "<li>En vente en magasin</li>";
                                                                                    }
                                                                                    if(saleWeb == 1 && saleLink != "") {
                                                                                        saleLink = saleLink.replace(/http:\/\//gi, "");
                                                                                        saleLink = "http://" + saleLink;
                                                                                        
                                                                                        sHTML += "<li>";
                                                                                            sHTML += "En vente en ligne au ";
                                                                                            sHTML += "<a href=\"" + saleLink + "\" target=\"_blank\">";
                                                                                                sHTML += saleLink;
                                                                                            sHTML += "</a>";
                                                                                        sHTML += "</li>";
                                                                                    }
                                                                                sHTML += "</ul>";
                                                                            sHTML += "</td>";
                                                                       sHTML += "</tr>";
                                                                    }
                                                                sHTML += "</tbody>";
                                                            sHTML += "</table>";
                                                        sHTML += "</td>";
                                                    }
                                                    sHTML += "<td class=\"articleRight\">";
                                                        sHTML += "<table class=\"form\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%;\">";
                                                            sHTML += "<tbody>";
                                                                // article name
                                                                sHTML += "<tr>";
                                                                    sHTML += "<td class=\"articleName\">";
                                                                        sHTML += label;
                                                                    sHTML += "</td>";
                                                                sHTML += "</tr>";
                                                                if(description != "") {
                                                                    // section : description
                                                                    sHTML += "<tr>";
                                                                        sHTML += "<td class=\"articleSection\">";
                                                                            sHTML += "Description";
                                                                        sHTML += "</td>";
                                                                    sHTML += "</tr>";
                                                                    // article description
                                                                    sHTML += "<tr>";
                                                                        sHTML += "<td class=\"articleDescription\">";
                                                                            sHTML += description;//.replace(/\r\n|\n\r|[\r\n]/gi, "<br />");
                                                                        sHTML += "</td>";
                                                                    sHTML += "</tr>";
                                                                }
                                                                if(costPrice && costPrice != "" && costPrice != "0.00") {
                                                                    // section : article price
                                                                    sHTML += "<tr>";
                                                                        sHTML += "<td class=\"articleSection\">";
                                                                            sHTML += "Prix";
                                                                        sHTML += "</td>";
                                                                    sHTML += "</tr>";
                                                                    // article price
                                                                    sHTML += "<tr>";
                                                                        sHTML += "<td class=\"articlePrices\">";
                                                                            sHTML += "<ul>";
                                                                                sHTML += "<li>" + costPrice + " $</li>";
                                                                            sHTML += "</ul>";
                                                                        sHTML += "</td>";
                                                                    sHTML += "</tr>";
                                                                }
                                                            sHTML += "</tbody>";
                                                        sHTML += "</table>";
                                                    sHTML += "</td>";
                                                sHTML += "</tr>";
                                            sHTML += "</tbody>";
                                        sHTML += "</table>";
                                        
                                        oPopup_content.innerHTML = sHTML;
                                        
                                        if(displayMemberArticle.firstTime == true) {
                                            initPopup("popup_articleBox_div", "popup_articleBox_title");
                                            displayMemberArticle.firstTime = false;
                                        }
                                        
                                        showPopup("popup_articleBox_div");
                                    }
                                }
                            }
                            else {
                                alert("Une erreur est survenue lors du chargement des informations de l'article.");
                            }
                        }
                    }
                },
                onException : function(p_oRequest, p_oException)
                {
                    throw p_oException;
                },
                onLoaded : function()
                {
                }
            });
        }
    }
    displayMemberArticle.firstTime = true;
    
    
    function decodeArticleSummary(idDecoder) {
        var oDecoder = document.getElementById(idDecoder);
        if(oDecoder && oDecoder.value != "") {
            var sSummary = oDecoder.value.replace(/\r\n|\n\r|[\r\n]/gi, "<br />");
            
            document.write(sSummary);
        }
    }
}




// Comments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
    var commentBox_initialized = false;
    
    function addComment(name, email, content) {
        var oIdMember = document.getElementById("idMember");
        if(oIdMember) {
            var idMember = oIdMember.value;
            
            var sURL = "/administration/comments/ajax-getCommentForm.php?idMember=" + idMember;
            
            if(name && name != '') sURL += "&name=" + encodeURI(name);
            if(email  && email != '') sURL += "&email=" + encodeURI(email);
            if(content  && content != '') sURL += "&content=" + encodeURI(content);
            
            new Ajax.Request(sURL, { asynchronous : false,
                onComplete : function(p_oRequest) {
                    if(p_oRequest.responseText != "") {
                        if(commentBox_initialized == false) {
                            initPopup('popup_commentBox_div', 'popup_commentBox_title');
                            commentBox_initialized = true;
                        }
                        
                        var oPopupContent = document.getElementById("popup_commentBox_content");
                        oPopupContent.innerHTML = p_oRequest.responseText;
                        
                        
                        // replace labels in the comment form
                        var arrID           = new Array('comments_name_label','comments_email_label','comments_content_label','comments_confirmCaptchaInstruction_label','comments_captcha_label','comments_confirmCaptcha_label');
                        var arrLocalization = new Array('commentBox.field.name','commentBox.field.email','commentBox.field.content','commentBox.field.confirmCaptcha.label','commentBox.field.captcha','commentBox.field.confirmCaptcha');
                        
                        if(arrID.length > 0 && arrLocalization.length) {
                            for(iElement = 0; iElement < arrID.length; iElement ++) {
                                if(oElement = document.getElementById(arrID[iElement])) {
                                    oElement.innerHTML = Localization.getTranslation(arrLocalization[iElement]);    
                                }
                            }
                        }
                        
                        
                        showPopup('popup_commentBox_div');
                    }
                },
                onException : function(p_oRequest, p_oException)
                {
                    throw p_oException;
                },
                onLoaded : function()
                {
                }
            });
        }
    }
    
    function applyAddComment() {
        var functionResult = false;
        
        var oIdMember = document.getElementById("idMember");
        if(oIdMember) {
            var idMember = oIdMember.value;
            
            if(validateCommentForm()) {
                var bReload = false;
                
                var name    = document.getElementById("comments_name").value;
                var email   = document.getElementById("comments_email").value;
                var content = document.getElementById("comments_content").value;
                
                var captcha_key   = document.getElementsByName("ptitcaptcha_key")[0].value;
                var captcha_entry = document.getElementsByName("ptitcaptcha_entry")[0].value;
                
                var sURL = "/administration/comments/ajax-saveComment.php?idMember=" + idMember + "&name=" + escape(name) + "&email=" + escape(email) + "&content=" + escape(content) + "&ptitcaptcha_key=" + captcha_key + "&ptitcaptcha_entry=" + captcha_entry;
                new Ajax.Request(sURL, { asynchronous : false,
                    onComplete : function(p_oRequest) {
                        if(p_oRequest.responseText != "") {
                            var oJSON = eval('(' + p_oRequest.responseText + ')');
                            if(oJSON) {
                                if(oJSON.result == "true") {
                                    alert(Localization.getTranslation("message.commentCreationSuccess"));
                                    
                                    functionResult = true;
                                    
                                    closePopup("popup_commentBox_div");
                                }
                                else {
                                    if(oJSON.error == "captcha") {
                                        alert(Localization.getTranslation("message.wrongCaptcha"));
                                        bReload = true;
                                    }
                                    else {
                                        alert("Une erreur est survenue lors de l'enregistrement du commentaire.");
                                    }
                                }
                            }
                        }
                    },
                    onException : function(p_oRequest, p_oException)
                    {
                        throw p_oException;
                    },
                    onLoaded : function()
                    {
                    }
                });
                
                if(bReload == true) {
                    addComment(name, email, content);
                }
            }
        }
    }
    
    function validateCommentForm() {
        var bValid = true;
        
        var oName = document.getElementById("comments_name");
        if(oName) {
            if(oName.value == "") {
                var fieldName = Localization.getTranslation("commentBox.field.name");
                var message   = Localization.getTranslation("form.requiredField.message").replace("[fieldName]", fieldName.substring(0, fieldName.length - 3));
                alert(message);
                
                bValid = false;
            }
        }
        
        var oEmail = document.getElementById("comments_email");
        if(oEmail) {
            if(oEmail.value == "") {
                var fieldName = Localization.getTranslation("commentBox.field.email");
                var message   = Localization.getTranslation("form.requiredField.message").replace("[fieldName]", fieldName.substring(0, fieldName.length - 3));
                alert(message);
                
                bValid = false;
            }
        }
        
        var oContent = document.getElementById("comments_content");
        if(oContent) {
            if(oContent.value == "") {
                var fieldName = Localization.getTranslation("commentBox.field.content");
                var message   = Localization.getTranslation("form.requiredField.message").replace("[fieldName]", fieldName.substring(0, fieldName.length - 3));
                alert(message);
                
                bValid = false;
            }
        }
        
        var oCaptcha = document.getElementsByName("ptitcaptcha_entry")[0];
        if(oCaptcha) {
            if(oCaptcha.value == "") {
                var fieldName = Localization.getTranslation("commentBox.field.captcha");
                var message   = Localization.getTranslation("form.requiredField.message").replace("[fieldName]", fieldName.substring(0, fieldName.length - 3));
                alert(message);
                
                bValid = false;
            }
        }
        
        return bValid;
    }
    
    // FACEBOOK COMMENTS
    {
        function fb_askFriendsComments() {
            FB.Connect.ifUserConnected(sendToFacebook, loginToFacebook);
        }
    
        // function stream_callback (post_id, exception) {
            // if (post_id) {
                // // submitForm();
                // fb_askFriendsComments();
            // }
        // }
        
        function loginToFacebook() {
            FB.Connect.requireSession()   
        }
        
        function sendToFacebook() {
            var oMemberEnterprise = document.getElementById("memberEnterprise");
            var sMemberEnterprise = oMemberEnterprise.value;
            
            // var oForm    = document.getElementById("emailSendingForm");
    	    var sContent = "Quelqu'un peut me donner son avis sur ce commerce?\n" + sMemberEnterprise + "\n" + window.location.href; // : " + window.location.href;
    	    
    	    // if(sContent.length > 0) {
    	        // FB.Connect.streamPublish("", null, null, null, sContent, stream_callback);
    	        // FB.Connect.streamPublish(sContent, null, null, null, sContent, null);
    	        FB.Connect.streamPublish(sContent, null, null, null, "Commentaire", null);
    	    // }
        }
    }
}


// E-mail sending ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
    function sendEmail() {
        var sPopupName = 'popup_emailBox';
        if(!sendEmail.initialized) {
            initPopup(sPopupName + '_div', sPopupName + '_title');
            
            var oPopupContent = document.getElementById(sPopupName + '_content');
            if(oPopupContent) {
                var sHTML = '';
                sHTML += '<table class="form" border="0" cellpadding="0" cellspacing="0" style="width: 99%;">';
                sHTML += '  <tbody>';
                sHTML += '    <tr>';
                sHTML += '      <td class="label" style="width: 88px;">';
                sHTML += Localization.getTranslation("popup_emailBox.field.senderName") + " :";
                sHTML += '      </td>';
                sHTML += '      <td class="field">';
                sHTML += '        <input type="text" id="sendEmail_senderName" value="" style="width: 300px;" />';
                sHTML += '        <div class="requiredField">*</div>';
                sHTML += '      </td>';
                sHTML += '    </tr>';
                sHTML += '    <tr>';
                sHTML += '      <td class="label">';
                sHTML += Localization.getTranslation("popup_emailBox.field.senderEmail") + " :";
                sHTML += '      </td>';
                sHTML += '      <td class="field">';
                sHTML += '        <input type="text" id="sendEmail_senderEmail" value="" style="width: 300px;" />';
                sHTML += '        <div class="requiredField">*</div>';
                sHTML += '      </td>';
                sHTML += '    </tr>';
                sHTML += '    <tr class="separator" style="height: 16px; line-height: 16px;"><td colspan="2">&#160;</td></tr>';
                sHTML += '    <tr>';
                sHTML += '      <td class="label">';
                sHTML += Localization.getTranslation("popup_emailBox.field.subject") + " :";
                sHTML += '      </td>';
                sHTML += '      <td class="field">';
                sHTML += '        <input type="text" id="sendEmail_subject" value="" style="width: 95%;" />';
                sHTML += '        <div class="requiredField">*</div>';
                sHTML += '      </td>';
                sHTML += '    </tr>';
                sHTML += '    <tr>';
                sHTML += '      <td class="label">';
                sHTML += Localization.getTranslation("popup_emailBox.field.content") + " :";
                sHTML += '      </td>';
                sHTML += '      <td class="field">';
                sHTML += '        <textarea id="sendEmail_content" style="height: 150px; width: 95%;"></textarea>';
                sHTML += '        <div class="requiredField">*</div>';
                sHTML += '      </td>';
                sHTML += '    </tr>';
                sHTML += '  </tbody>';
                sHTML += '</table>';
                
                oPopupContent.innerHTML = sHTML;
            }
        }
        
        showPopup(sPopupName + '_div');
    }
    sendEmail.initialized = false;
    
    function applySendEmail() {
        if(sendEmail_validateForm()) {
            var sendResult = false;
            var idMember   = document.getElementById("idMember").value;
            
            var oSenderName  = document.getElementById("sendEmail_senderName");
            var oSenderEmail = document.getElementById("sendEmail_senderEmail");
            var oSubject     = document.getElementById("sendEmail_subject");
            var oContent     = document.getElementById("sendEmail_content");
            
            var sURL = "/profile_sendEmail.php";
            new Ajax.Request(sURL, { asynchronous : false, method : 'post',
                parameters : { idMember: idMember, senderName: escape(oSenderName.value), senderEmail: escape(oSenderEmail.value), subject: escape(oSubject.value), content: escape(oContent.value) },
                onComplete : function(p_oRequest) {
                    if(p_oRequest.responseText != "") {
                        var oJSON = eval('(' + p_oRequest.responseText + ')');
                        if(oJSON) {
                            if(oJSON.result == "true") {
                                sendResult = true;
                            }
                        }
                    }
                },
                onException : function(p_oRequest, p_oException)
                {
                    throw p_oException;
                },
                onLoaded : function()
                {
                }
            });
            
            if(sendResult == true) {
                alert(Localization.getTranslation("popup_emailBox.message.sendEmailSuccess"));
            }
            else {
                alert(Localization.getTranslation("popup_emailBox.message.sendEmailFailure"));
            }
            closePopup("popup_emailBox_div");
        }
    }
    
    function sendEmail_validateForm() {
        var bValid = true;
        
        var oSenderName  = document.getElementById("sendEmail_senderName");
        var oSenderEmail = document.getElementById("sendEmail_senderEmail");
        var oSubject     = document.getElementById("sendEmail_subject");
        var oContent     = document.getElementById("sendEmail_content");
        
        oSenderName.className  = "";
        oSenderEmail.className = "";
        oSubject.className     = "";
        oContent.className     = "";
        
        if(oSenderName.value == "") {
            oSenderName.className = "invalid";
            if(bValid == true) alert(Localization.getTranslation("popup_emailBox.message.senderName.invalid"));
            
            bValid = false;
        }
        
        if(!isEmail(oSenderEmail.value)) {
            oSenderEmail.className = "invalid";
            if(bValid == true) alert(Localization.getTranslation("popup_emailBox.message.senderEmail.invalid"));
            
            bValid = false;
        }
        
        if(oSubject.value == "") {
            oSubject.className = "invalid";
            if(bValid == true) alert(Localization.getTranslation("popup_emailBox.message.subject.invalid"));
            
            bValid = false;
        }
        
        if(oContent.value == "") {
            oContent.className = "invalid";
            if(bValid == true) alert(Localization.getTranslation("popup_emailBox.message.content.invalid"));
            
            bValid = false;
        }
        
        return bValid;
    }
}

