function changeGiftElement(description, link, received, title, key, where, uid, date, buyer, creator) {
        var editGift = document.getElementById("gift" + uid);
        editGift.innerHTML = title;
        editGift.className = "gift";
        if (received == 1) {
            editGift.className += " checked";
            //console.log("Checked, changed");
        }
        editGift.onclick = function () {
            var spanGift = document.getElementsByClassName("close")[0];
            var editBtn = document.getElementById('giftEdit');
            var deleteBtn = document.getElementById('giftDelete');
            var titleField = document.getElementById('giftTitle');
            var descField = document.getElementById('giftDescription');
            var creatorField = document.getElementById('giftCreator');
            var whereField = document.getElementById('giftWhere');
            var linkField = document.getElementById('giftLink');
            var boughtField = document.getElementById('giftBought');
            var buyField = document.getElementById('giftBuy');
            var dontBuyField = document.getElementById('giftDontBuy');

            if (link != "") {
                linkField.innerHTML = "Click me to go to the webpage!";
                linkField.onclick = function () {
                    var newGiftLink = "http://";
                    if (link.includes("https://")) {
                        link = link.slice(8, link.length);
                    } else if (link.includes("http://")) {
                        link = link.slice(7, link.length);
                    }
                    newGiftLink += link;
                    window.open(newGiftLink, "_blank");
                };
            } else {
                linkField.innerHTML = "There was no link provided";
                linkField.onclick = function () {
                };
            }
            if (received == 1) {
                if (buyer == null || buyer == undefined) {
                    boughtField.innerHTML = "This gift has been bought";
                } else {
                    if (buyer == "")
                        boughtField.innerHTML = "This gift has been bought";
                    else
                        boughtField.innerHTML = "This gift was bought by " + buyer;
                }
            } else {
                boughtField.innerHTML = "This gift has not been bought yet";
            }
            if (description != "") {
                descField.innerHTML = "Description: " + description;
            } else {
                descField.innerHTML = "There was no description provided";
            }
            if (creator == null || creator == undefined) {
                creatorField.innerHTML = "Gift creator unavailable";
            } else {
                if (creator == "")
                    creatorField.innerHTML = "Gift creator unavailable";
                else
                    creatorField.innerHTML = "Gift was created by " + creator;
            }
            titleField.innerHTML = title;
            if (where != "") {
                whereField.innerHTML = "This can be found at: " + where;
            } else {
                whereField.innerHTML = "There was no location provided";
            }
            if (date != undefined) {
                if (date != "") {
                    giftCreationDate.innerHTML = "Created on: " + date;
                } else {
                    giftCreationDate.innerHTML = "Creation date not available";
                }
            } else {
                giftCreationDate.innerHTML = "Creation date not available";
            }
            editBtn.onclick = function () {
                updateMaintenanceLog("privateList", "Attempting to update gift:" + title + " " + key + " " + currentUser.userName);
                updateGiftElement(uid);
            };
            deleteBtn.onclick = function () {
                if (creator == currentUser.userName || creator == null || creator == undefined) {
                    updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                    deleteGiftElement(key, title, buyer);
                } else {
                    if (creator == ""){
                        updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                        deleteGiftElement(key, title, buyer);
                    } else {
                        updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                        alert("Only the creator, " + creator + ", can delete this gift. Please contact them to delete this gift " +
                            "if it needs to be removed.");
                    }
                }
            };
            buyField.innerHTML = "Click on me to buy the gift!";
            buyField.onclick = function () {
                if (received == 0) {
                    firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                        received: 1,
                        buyer: currentUser.userName
                    });
                } else {
                    alert("This gift has already been marked as bought!");
                }
            };
            dontBuyField.innerHTML = "Click on me to un-buy the gift!";
            dontBuyField.onclick = function () {
                if (received == 1) {
                    if (buyer == currentUser.userName || buyer == null || buyer == undefined) {
                        firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                            received: 0,
                            buyer: ""
                        });
                    } else {
                        if (buyer == "") {
                            firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                                received: 0,
                                buyer: ""
                            });
                        } else {
                            alert("Only the buyer, " + buyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " +
                                "if this has been done in error.");
                        }
                    }
                } else {
                    alert("This gift has already been marked as \"Un-Bought\"!");
                }
            };

            //show modal
            modal.style.display = "block";
            currentModalOpen = uid;
            console.log("Modal Open: " + currentModalOpen);

            //close on close
            spanGift.onclick = function () {
                currentModalOpen = "";
                console.log("Closed modal");
                modal.style.display = "none";
            };

            //close on click
            window.onclick = function (event) {
                if (event.target == modal) {
                    currentModalOpen = "";
                    console.log("Closed modal");
                    modal.style.display = "none";
                }
            };
        };
    }
//with the proper gift's details and buttons.
with the proper gift's details and buttons.
with the proper gift ' s details and buttons .
function changeGiftElement(description, link, received, title, key, where, uid, date, buyer, creator) {
        var editGift = document.getElementById("gift" + uid);
        editGift.innerHTML = title;
        editGift.className = "gift";
        if (received == 1) {
            editGift.className += " checked";
        }
        editGift.onclick = function () {
            var spanGift = document.getElementsByClassName("close")[0];
            var editBtn = document.getElementById('giftEdit');
            var deleteBtn = document.getElementById('giftDelete');
            var titleField = document.getElementById('giftTitle');
            var descField = document.getElementById('giftDescription');
            var creatorField = document.getElementById('giftCreator');
            var whereField = document.getElementById('giftWhere');
            var linkField = document.getElementById('giftLink');
            var boughtField = document.getElementById('giftBought');
            var buyField = document.getElementById('giftBuy');
            var dontBuyField = document.getElementById('giftDontBuy');
            if (link != "") {
                linkField.innerHTML = "Click me to go to the webpage!";
                linkField.onclick = function () {
                    var newGiftLink = "http://";
                    if (link.includes("https://")) {
                        link = link.slice(8, link.length);
                    } else if (link.includes("http://")) {
                        link = link.slice(7, link.length);
                    }
                    newGiftLink += link;
                    window.open(newGiftLink, "_blank");
                };
            } else {
                linkField.innerHTML = "There was no link provided";
                linkField.onclick = function () {
                };
            }
            if (received == 1) {
                if (buyer == null || buyer == undefined) {
                    boughtField.innerHTML = "This gift has been bought";
                } else {
                    if (buyer == "")
                        boughtField.innerHTML = "This gift has been bought";
                    else
                        boughtField.innerHTML = "This gift was bought by " + buyer;
                }
            } else {
                boughtField.innerHTML = "This gift has not been bought yet";
            }
            if (description != "") {
                descField.innerHTML = "Description: " + description;
            } else {
                descField.innerHTML = "There was no description provided";
            }
            if (creator == null || creator == undefined) {
                creatorField.innerHTML = "Gift creator unavailable";
            } else {
                if (creator == "")
                    creatorField.innerHTML = "Gift creator unavailable";
                else
                    creatorField.innerHTML = "Gift was created by " + creator;
            }
            titleField.innerHTML = title;
            if (where != "") {
                whereField.innerHTML = "This can be found at: " + where;
            } else {
                whereField.innerHTML = "There was no location provided";
            }
            if (date != undefined) {
                if (date != "") {
                    giftCreationDate.innerHTML = "Created on: " + date;
                } else {
                    giftCreationDate.innerHTML = "Creation date not available";
                }
            } else {
                giftCreationDate.innerHTML = "Creation date not available";
            }
            editBtn.onclick = function () {
                updateMaintenanceLog("privateList", "Attempting to update gift:" + title + " " + key + " " + currentUser.userName);
                updateGiftElement(uid);
            };
            deleteBtn.onclick = function () {
                if (creator == currentUser.userName || creator == null || creator == undefined) {
                    updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                    deleteGiftElement(key, title, buyer);
                } else {
                    if (creator == ""){
                        updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                        deleteGiftElement(key, title, buyer);
                    } else {
                        updateMaintenanceLog("privateList", "Attempting to delete gift:" + title + " " + key + " " + currentUser.userName);
                        alert("Only the creator, " + creator + ", can delete this gift. Please contact them to delete this gift " +
                            "if it needs to be removed.");
                    }
                }
            };
            buyField.innerHTML = "Click on me to buy the gift!";
            buyField.onclick = function () {
                if (received == 0) {
                    firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                        received: 1,
                        buyer: currentUser.userName
                    });
                } else {
                    alert("This gift has already been marked as bought!");
                }
            };
            dontBuyField.innerHTML = "Click on me to un-buy the gift!";
            dontBuyField.onclick = function () {
                if (received == 1) {
                    if (buyer == currentUser.userName || buyer == null || buyer == undefined) {
                        firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                            received: 0,
                            buyer: ""
                        });
                    } else {
                        if (buyer == "") {
                            firebase.database().ref("users/" + user.uid + "/privateList/" + key).update({
                                received: 0,
                                buyer: ""
                            });
                        } else {
                            alert("Only the buyer, " + buyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " +
                                "if this has been done in error.");
                        }
                    }
                } else {
                    alert("This gift has already been marked as \"Un-Bought\"!");
                }
            };
            modal.style.display = "block";
            currentModalOpen = uid;
            console.log("Modal Open: " + currentModalOpen);
            spanGift.onclick = function () {
                currentModalOpen = "";
                console.log("Closed modal");
                modal.style.display = "none";
            };
            window.onclick = function (event) {
                if (event.target == modal) {
                    currentModalOpen = "";
                    console.log("Closed modal");
                    modal.style.display = "none";
                }
            };
        };
    }
function changeGiftElement ( description , link , received , title , key , where , uid , date , buyer , creator ) { var editGift = document . getElementById ( "gift" + uid ) ; editGift . innerHTML = title ; editGift . className = "gift" ; if ( received == 1 ) { editGift . className += " checked" ; } editGift . onclick = function ( ) { var spanGift = document . getElementsByClassName ( "close" ) [ 0 ] ; var editBtn = document . getElementById ( 'giftEdit' ) ; var deleteBtn = document . getElementById ( 'giftDelete' ) ; var titleField = document . getElementById ( 'giftTitle' ) ; var descField = document . getElementById ( 'giftDescription' ) ; var creatorField = document . getElementById ( 'giftCreator' ) ; var whereField = document . getElementById ( 'giftWhere' ) ; var linkField = document . getElementById ( 'giftLink' ) ; var boughtField = document . getElementById ( 'giftBought' ) ; var buyField = document . getElementById ( 'giftBuy' ) ; var dontBuyField = document . getElementById ( 'giftDontBuy' ) ; if ( link != "" ) { linkField . innerHTML = "Click me to go to the webpage!" ; linkField . onclick = function ( ) { var newGiftLink = "http://" ; if ( link . includes ( "https://" ) ) { link = link . slice ( 8 , link . length ) ; } else if ( link . includes ( "http://" ) ) { link = link . slice ( 7 , link . length ) ; } newGiftLink += link ; window . open ( newGiftLink , "_blank" ) ; } ; } else { linkField . innerHTML = "There was no link provided" ; linkField . onclick = function ( ) { } ; } if ( received == 1 ) { if ( buyer == null || buyer == undefined ) { boughtField . innerHTML = "This gift has been bought" ; } else { if ( buyer == "" ) boughtField . innerHTML = "This gift has been bought" ; else boughtField . innerHTML = "This gift was bought by " + buyer ; } } else { boughtField . innerHTML = "This gift has not been bought yet" ; } if ( description != "" ) { descField . innerHTML = "Description: " + description ; } else { descField . innerHTML = "There was no description provided" ; } if ( creator == null || creator == undefined ) { creatorField . innerHTML = "Gift creator unavailable" ; } else { if ( creator == "" ) creatorField . innerHTML = "Gift creator unavailable" ; else creatorField . innerHTML = "Gift was created by " + creator ; } titleField . innerHTML = title ; if ( where != "" ) { whereField . innerHTML = "This can be found at: " + where ; } else { whereField . innerHTML = "There was no location provided" ; } if ( date != undefined ) { if ( date != "" ) { giftCreationDate . innerHTML = "Created on: " + date ; } else { giftCreationDate . innerHTML = "Creation date not available" ; } } else { giftCreationDate . innerHTML = "Creation date not available" ; } editBtn . onclick = function ( ) { updateMaintenanceLog ( "privateList" , "Attempting to update gift:" + title + " " + key + " " + currentUser . userName ) ; updateGiftElement ( uid ) ; } ; deleteBtn . onclick = function ( ) { if ( creator == currentUser . userName || creator == null || creator == undefined ) { updateMaintenanceLog ( "privateList" , "Attempting to delete gift:" + title + " " + key + " " + currentUser . userName ) ; deleteGiftElement ( key , title , buyer ) ; } else { if ( creator == "" ) { updateMaintenanceLog ( "privateList" , "Attempting to delete gift:" + title + " " + key + " " + currentUser . userName ) ; deleteGiftElement ( key , title , buyer ) ; } else { updateMaintenanceLog ( "privateList" , "Attempting to delete gift:" + title + " " + key + " " + currentUser . userName ) ; alert ( "Only the creator, " + creator + ", can delete this gift. Please contact them to delete this gift " + "if it needs to be removed." ) ; } } } ; buyField . innerHTML = "Click on me to buy the gift!" ; buyField . onclick = function ( ) { if ( received == 0 ) { firebase . database ( ) . ref ( "users/" + user . uid + "/privateList/" + key ) . update ( { received : 1 , buyer : currentUser . userName } ) ; } else { alert ( "This gift has already been marked as bought!" ) ; } } ; dontBuyField . innerHTML = "Click on me to un-buy the gift!" ; dontBuyField . onclick = function ( ) { if ( received == 1 ) { if ( buyer == currentUser . userName || buyer == null || buyer == undefined ) { firebase . database ( ) . ref ( "users/" + user . uid + "/privateList/" + key ) . update ( { received : 0 , buyer : "" } ) ; } else { if ( buyer == "" ) { firebase . database ( ) . ref ( "users/" + user . uid + "/privateList/" + key ) . update ( { received : 0 , buyer : "" } ) ; } else { alert ( "Only the buyer, " + buyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " + "if this has been done in error." ) ; } } } else { alert ( "This gift has already been marked as \"Un-Bought\"!" ) ; } } ; modal . style . display = "block" ; currentModalOpen = uid ; console . log ( "Modal Open: " + currentModalOpen ) ; spanGift . onclick = function ( ) { currentModalOpen = "" ; console . log ( "Closed modal" ) ; modal . style . display = "none" ; } ; window . onclick = function ( event ) { if ( event . target == modal ) { currentModalOpen = "" ; console . log ( "Closed modal" ) ; modal . style . display = "none" ; } } ; } ; }
with the proper gift's details and buttons.
with the proper gift ' s details and buttons .
//console.log("Checked, changed"); //show modal //close on close //close on click