function generateAddUserBtn(){
    var friendUserNameList = [];
    var upperCaseUserArr = [];
    if(user.friends != undefined || user.friends != null) {
      for (var i = 0; i < user.friends.length; i++) {
        for (var a = 0; a < userArr.length; a++) {
          if (userArr[a].uid == user.friends[i]) {
            friendUserNameList.push(userArr[a].userName.toUpperCase());
            break;
          }
        }
      }
    }
    for (var b = 0; b < userArr.length; b++){
      upperCaseUserArr.push(userArr[b].userName.toUpperCase());
    }

    addUserBtn.onclick = function() {
      var addSpan = document.getElementsByClassName("close")[1];
      var addBtn = document.getElementById('addInvite');
      var cancelBtn = document.getElementById('cancelInvite');
      var inviteInfo = document.getElementById('inviteInfo');
      userInput = document.getElementById('userNameInp');


      userInviteModal.style.display = "block";
      addBtn.innerHTML = "Send Invite";

      addBtn.onclick = function() {
        var userLocation = -1;
        for (var i = 0; i < upperCaseUserArr.length; i++) {
          if (upperCaseUserArr[i] == userInput.value.toUpperCase()) {
            userLocation = i;
            break;
          }
        }

        inviteInfo.innerHTML = "";
        if(userInput.value == ""){
          inviteInfo.innerHTML = "User Name Field Empty, Please Try Again!";
        } else if (friendUserNameList.includes(userInput.value.toUpperCase())) {
          inviteInfo.innerHTML = "That User Is Already Your Friend, Please Try Again!";
        } else if (user.userName.toUpperCase() == userInput.value.toUpperCase()){
          inviteInfo.innerHTML = "You Cannot Invite Yourself, Please Try Again!";
        } else if (userLocation != -1) {
          try {
            if (user.invites.includes(userArr[userLocation].uid)) {
              inviteInfo.innerHTML = "This User Already Sent You An Invite, Please Try Again!";
            } else if (userArr[userLocation].invites.includes(user.uid)) {
              inviteInfo.innerHTML = "You Already Sent This User An Invite, Please Try Again!";
            } else {
              generateConfirmDialog(userLocation);
            }
          } catch (err) {
            try {
              if (userArr[userLocation].invites.includes(user.uid)) {
                inviteInfo.innerHTML = "You Already Sent This User An Invite, Please Try Again!";
              } else {
                generateConfirmDialog(userLocation);
              }
            } catch (err) {
              generateConfirmDialog(userLocation);
            }
          }
        } else if (userInput.value.toUpperCase() == "USER NAME BELOW"){
          inviteInfo.innerHTML = "Very Funny, Please Enter A User Name";
        } else if (userInput.value.toUpperCase() == "A USER NAME"){
          inviteInfo.innerHTML = "Listen Here, Please Input Something Serious";
        } else if (userInput.value.toUpperCase() == "SOMETHING SERIOUS"){
          inviteInfo.innerHTML = "You're Just Mocking Me At This Point";
        } else {
          inviteInfo.innerHTML = "That User Name Does Not Exist, Please Try Again!";
        }
      };

      cancelBtn.onclick = function() {
        userInviteModal.style.display = "none";
        userInput.value = "";
        inviteInfo.innerHTML = "";
      };

      addSpan.onclick = function() {
        userInviteModal.style.display = "none";
        userInput.value = "";
        inviteInfo.innerHTML = "";
      };

      window.onclick = function(event) {
        if (event.target == userInviteModal) {
          userInviteModal.style.display = "none";
        }
      }
    };
    console.log("Add Button Generated");
  }
//This function generates the "Add User" button on the webpage as well as its functionality.
This function generates the "Add User" button on the webpage as well as its functionality.
This function generates the " Add User " button on the webpage as well as its functionality .
function generateAddUserBtn(){
    var friendUserNameList = [];
    var upperCaseUserArr = [];
    if(user.friends != undefined || user.friends != null) {
      for (var i = 0; i < user.friends.length; i++) {
        for (var a = 0; a < userArr.length; a++) {
          if (userArr[a].uid == user.friends[i]) {
            friendUserNameList.push(userArr[a].userName.toUpperCase());
            break;
          }
        }
      }
    }
    for (var b = 0; b < userArr.length; b++){
      upperCaseUserArr.push(userArr[b].userName.toUpperCase());
    }
    addUserBtn.onclick = function() {
      var addSpan = document.getElementsByClassName("close")[1];
      var addBtn = document.getElementById('addInvite');
      var cancelBtn = document.getElementById('cancelInvite');
      var inviteInfo = document.getElementById('inviteInfo');
      userInput = document.getElementById('userNameInp');
      userInviteModal.style.display = "block";
      addBtn.innerHTML = "Send Invite";
      addBtn.onclick = function() {
        var userLocation = -1;
        for (var i = 0; i < upperCaseUserArr.length; i++) {
          if (upperCaseUserArr[i] == userInput.value.toUpperCase()) {
            userLocation = i;
            break;
          }
        }
        inviteInfo.innerHTML = "";
        if(userInput.value == ""){
          inviteInfo.innerHTML = "User Name Field Empty, Please Try Again!";
        } else if (friendUserNameList.includes(userInput.value.toUpperCase())) {
          inviteInfo.innerHTML = "That User Is Already Your Friend, Please Try Again!";
        } else if (user.userName.toUpperCase() == userInput.value.toUpperCase()){
          inviteInfo.innerHTML = "You Cannot Invite Yourself, Please Try Again!";
        } else if (userLocation != -1) {
          try {
            if (user.invites.includes(userArr[userLocation].uid)) {
              inviteInfo.innerHTML = "This User Already Sent You An Invite, Please Try Again!";
            } else if (userArr[userLocation].invites.includes(user.uid)) {
              inviteInfo.innerHTML = "You Already Sent This User An Invite, Please Try Again!";
            } else {
              generateConfirmDialog(userLocation);
            }
          } catch (err) {
            try {
              if (userArr[userLocation].invites.includes(user.uid)) {
                inviteInfo.innerHTML = "You Already Sent This User An Invite, Please Try Again!";
              } else {
                generateConfirmDialog(userLocation);
              }
            } catch (err) {
              generateConfirmDialog(userLocation);
            }
          }
        } else if (userInput.value.toUpperCase() == "USER NAME BELOW"){
          inviteInfo.innerHTML = "Very Funny, Please Enter A User Name";
        } else if (userInput.value.toUpperCase() == "A USER NAME"){
          inviteInfo.innerHTML = "Listen Here, Please Input Something Serious";
        } else if (userInput.value.toUpperCase() == "SOMETHING SERIOUS"){
          inviteInfo.innerHTML = "You're Just Mocking Me At This Point";
        } else {
          inviteInfo.innerHTML = "That User Name Does Not Exist, Please Try Again!";
        }
      };
      cancelBtn.onclick = function() {
        userInviteModal.style.display = "none";
        userInput.value = "";
        inviteInfo.innerHTML = "";
      };
      addSpan.onclick = function() {
        userInviteModal.style.display = "none";
        userInput.value = "";
        inviteInfo.innerHTML = "";
      };
      window.onclick = function(event) {
        if (event.target == userInviteModal) {
          userInviteModal.style.display = "none";
        }
      }
    };
    console.log("Add Button Generated");
  }
function generateAddUserBtn ( ) { var friendUserNameList = [ ] ; var upperCaseUserArr = [ ] ; if ( user . friends != undefined || user . friends != null ) { for ( var i = 0 ; i < user . friends . length ; i ++ ) { for ( var a = 0 ; a < userArr . length ; a ++ ) { if ( userArr [ a ] . uid == user . friends [ i ] ) { friendUserNameList . push ( userArr [ a ] . userName . toUpperCase ( ) ) ; break ; } } } } for ( var b = 0 ; b < userArr . length ; b ++ ) { upperCaseUserArr . push ( userArr [ b ] . userName . toUpperCase ( ) ) ; } addUserBtn . onclick = function ( ) { var addSpan = document . getElementsByClassName ( "close" ) [ 1 ] ; var addBtn = document . getElementById ( 'addInvite' ) ; var cancelBtn = document . getElementById ( 'cancelInvite' ) ; var inviteInfo = document . getElementById ( 'inviteInfo' ) ; userInput = document . getElementById ( 'userNameInp' ) ; userInviteModal . style . display = "block" ; addBtn . innerHTML = "Send Invite" ; addBtn . onclick = function ( ) { var userLocation = - 1 ; for ( var i = 0 ; i < upperCaseUserArr . length ; i ++ ) { if ( upperCaseUserArr [ i ] == userInput . value . toUpperCase ( ) ) { userLocation = i ; break ; } } inviteInfo . innerHTML = "" ; if ( userInput . value == "" ) { inviteInfo . innerHTML = "User Name Field Empty, Please Try Again!" ; } else if ( friendUserNameList . includes ( userInput . value . toUpperCase ( ) ) ) { inviteInfo . innerHTML = "That User Is Already Your Friend, Please Try Again!" ; } else if ( user . userName . toUpperCase ( ) == userInput . value . toUpperCase ( ) ) { inviteInfo . innerHTML = "You Cannot Invite Yourself, Please Try Again!" ; } else if ( userLocation != - 1 ) { try { if ( user . invites . includes ( userArr [ userLocation ] . uid ) ) { inviteInfo . innerHTML = "This User Already Sent You An Invite, Please Try Again!" ; } else if ( userArr [ userLocation ] . invites . includes ( user . uid ) ) { inviteInfo . innerHTML = "You Already Sent This User An Invite, Please Try Again!" ; } else { generateConfirmDialog ( userLocation ) ; } } catch ( err ) { try { if ( userArr [ userLocation ] . invites . includes ( user . uid ) ) { inviteInfo . innerHTML = "You Already Sent This User An Invite, Please Try Again!" ; } else { generateConfirmDialog ( userLocation ) ; } } catch ( err ) { generateConfirmDialog ( userLocation ) ; } } } else if ( userInput . value . toUpperCase ( ) == "USER NAME BELOW" ) { inviteInfo . innerHTML = "Very Funny, Please Enter A User Name" ; } else if ( userInput . value . toUpperCase ( ) == "A USER NAME" ) { inviteInfo . innerHTML = "Listen Here, Please Input Something Serious" ; } else if ( userInput . value . toUpperCase ( ) == "SOMETHING SERIOUS" ) { inviteInfo . innerHTML = "You're Just Mocking Me At This Point" ; } else { inviteInfo . innerHTML = "That User Name Does Not Exist, Please Try Again!" ; } } ; cancelBtn . onclick = function ( ) { userInviteModal . style . display = "none" ; userInput . value = "" ; inviteInfo . innerHTML = "" ; } ; addSpan . onclick = function ( ) { userInviteModal . style . display = "none" ; userInput . value = "" ; inviteInfo . innerHTML = "" ; } ; window . onclick = function ( event ) { if ( event . target == userInviteModal ) { userInviteModal . style . display = "none" ; } } } ; console . log ( "Add Button Generated" ) ; }
This function generates the "Add User" button on the webpage as well as its functionality.
This function generates the " Add User " button on the webpage as well as its functionality .