MSV FM

dot.antimicrobial@66.96.161.157: ~ $
Path : /hermes/sb_web/b1536/advancedfunctions.co/safespacehelpworkingversiondonotedit/
File Upload :
Current < : //hermes/sb_web/b1536/advancedfunctions.co/safespacehelpworkingversiondonotedit/modulesMobile.js

var sendMode='';
var googleSheetsPortalScript='https://script.google.com/macros/s/AKfycbzYaj0KlVVYWSKLbg_cjwLMtWsbqJeqtRFZqr09Cd3T72Ajlc2-/exec';
var popupPanel='';
var firstName='';
var lastName='';
var email='';
var password='';
var conversationId='';
var conversation='';
var months=['January','February','March','April','May','June','July','August','September','October','November','December'];
var role='patient';
var chatNumbers=[];
var array=[];
var chatArray=[];
var patientToMatch='';
var therapistToMatch='';
var profilePicture='';
var description='';

var myProfilePic='';
var myName='';
var myProfileDescription='';

var partnerProfilePic='';
var partnerName='';
var partnerProfileDescription='';

var conversationDataAsString='';
var profilesArray=[];
var resourcesArray=[];
var meetingTimesArray=[];
var conversationData=[];

var currentProfile='';
var currentResources='';
var currentMeetingTimes='';
var waitForConversationToUpdate=false;

var profileArrayData='';
var autoCheckRunning=false;

var patientJustRegistered=false;
var therapistJustRegistered=false;

function setMode(modeToSend){
role=modeToSend;
}

function getLive(array){
return "<div id='meetingTimeToDisplay'></div>";
}

function showMeetingTimes(array){
var liveUi='';
var meetingIcon="<i class=\'fa fa-video-camera\'></i>";
var addMeeting= "<div class='autoScroll' style='width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;padding:5px 5px;text-align:center;cursor:pointer;' class='onHover' onclick='javascript:toggle(&#39;editMeetingTimes&#39;)'><i class='fas fa-edit' ></i> Edit</div><div id='editMeetingTimes' style='font:16px Calibri;height:200px;display:none;margin-top:10px;' onclick='javascript:removeMeetingTimesWarning()'><div style='border-top:1px solid lightgray;margin-top:10px;margin-bottom:10px;'></div><input id='zoomLink' placeholder='&#9990; &nbsp;Enter zoom link' style='width:100%;margin-bottom:20px;margin-bottom:20px;margin-right:5px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:10px 10px;border:none;' ></input><div>"+"<div style='width:75vw;height:50px;margin-bottom:20px;position:relative;left:50%;transform:translate(-50%,0%);'>"+getDay()+getDuration()+getHour()+getMinutes()+getAMPM()+"</div><div style='width:100%;text-align:center;-moz-border-radius:50px;-webkit-border-radius:50px;border-radius:50px;padding:5px 5px;float:left;cursor:pointer;' class='onHover'  onclick='javascript:setTimeout(function(){saveMeetingTimes();},100)' id='addNewSessionButton'>&#8853;&nbsp;&nbsp;Add new session</div></div></div>";



if(role=='patient'){
for(var i=0;i<array.length&&array[i]!='';i=i+2){
liveUi=liveUi+"<div class='onHover' style='font:12px Calibri;padding:10px;'><div onclick='javascript:{window.open(&#39;"+array[i]+"&#39;,&#39;_blank&#39;);}' style='cursor:pointer;' class='onHover'>"+meetingIcon+"&nbsp;&nbsp;&nbsp;"+array[i+1]+"</div></div>";
}

document.getElementById('meetingTimeToDisplay').innerHTML="<div id='live' style='display:none;padding:15px 12px;font:16px Calibri;' >"+liveUi+"</div></div>";
}


if(role=='therapist'){
for(var i=0;i<array.length&&array[i]!='';i=i+2){
liveUi=liveUi+"<div class='onHover' style='font:12px Calibri;padding:10px;'><div onclick='javascript:{window.open(&#39;"+array[i]+"&#39;,&#39;_blank&#39;);}'  class='onHover' style='cursor:pointer;display:inline-block;'>"+meetingIcon+"&nbsp;&nbsp;&nbsp;"+array[i+1]+"</div><span style='float:right'><div onclick='javascript:removeMeeting(&#39;"+array[i]+"&#39;,&#39;"+array[i+1]+"&#39;)' style='display:inline-block;color:lightgray;cursor:pointer;' >remove</div></span></div>";
}

document.getElementById('meetingTimeToDisplay').innerHTML="<div id='live' style='display:none;padding:15px 12px;font:16px Calibri;' >"+liveUi+addMeeting+"</div></div>"
}

}

function removeMeeting(url,meetingTime){
sendDataToGoogleSheets(['removeMeeting',firstName,lastName,url,meetingTime,conversationId],googleSheetsPortalScript);
setUpdating();
}

function getWorksheets(array){
var resourcesUi='';
return "<div id='resourcesToDisplay' class='autoScroll'></div>";
}

function showResources(array){
var resourcesToShow='';
var resourceIcon='';
var addWorksheet="<div style='width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;padding:5px 5px;text-align:center;cursor:pointer;' class='onHover' class='autoScroll' onclick='javascript:toggle(&#39;editResources&#39;)'><i class='fas fa-edit' ></i> Edit</div><div id='editResources' style='font:16px Calibri;padding:15px 12px;height:320px;display:none;' onclick='javascript:removeResourcesWarning()'><div style='margin-bottom:40px;position:relative;left:0px;border-top:1px solid lightgray;padding-top:10px;'><select id='resourceType' onchange='javascript:setResourceType(this.value)' ><option onclick='javascript:setEnabled(&#39;resourceUploader&#39;,false),setEnabled(&#39;websiteUrl&#39;,false),setEnabled(&#39;resourceTitle&#39;,false);' value='fileType'>File Type</option><option value='document' onClick='javascript:setEnabled(&#39;resourceUploader&#39;,true),setEnabled(&#39;websiteUrl&#39;,false),setEnabled(&#39;resourceTitle&#39;,true);'>Document</option><option value='video' onclick='javascript:setEnabled(&#39;resourceUploader&#39;,true),setEnabled(&#39;websiteUrl&#39;,false),setEnabled(&#39;resourceTitle&#39;,true);'>Video</option><option value='url' onclick='javascript:setEnabled(&#39;websiteUrl&#39;,true);setEnabled(&#39;resourceUploader&#39;,false),setEnabled(&#39;resourceTitle&#39;,true);' id='URL'>URL</option></select></div><div style='height:80px'><input id='resourceUploader' type='file' style='float:left;margin-right:5px;margin-bottom:20px;font:12px Calibri;' disabled=true></input><input id='websiteUrl' placeholder='Website URL' style='width:100%; margin-bottom:40px; float:left;margin-right:5px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:10px 10px;border:none;box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.2);' disabled=true></input></div><div  style='height:80px'><input placeholder='Title of file' id='resourceTitle' disabled=false style='width:100%;float:left;margin-bottom:10px;margin-right:5px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:10px 10px;border:none;box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.2);'></input><div style='width:100%;text-align:center;-moz-border-radius:50px;-webkit-border-radius:50px;border-radius:50px;padding:5px 5px;float:left;cursor:pointer;' class='onHover' id='addNewResourceButton' onclick='javascript:setTimeout(function(){saveResource();},100)' >&#8853;&nbsp;&nbsp;Add new resource</div></div></div>";


if(role=='patient'){
for(var i=0;i<array.length;i=i+3){
if(array[i]=='document'){
resourceIcon="<i class=\'fa fa-book\'></i>";}
if(array[i]=='video'){
resourceIcon="<i class='fa fa-film'></i>";}
if(array[i]=='url'){
resourceIcon="<i class='far fa-window-restore'></i>";}

if(resourceIcon!=''){
resourcesToShow=resourcesToShow+"<div class='onHover' style='font:16px Calibri;padding:15px 12px;'><div onclick='javascript:{window.open(&#39;"+array[i+2]+"&#39;,&#39;_blank&#39;);}' style='cursor:pointer;' class='onHover'>"+resourceIcon+"&nbsp;&nbsp;&nbsp;"+array[i+1]+"</div></div>";}
}
document.getElementById('resourcesToDisplay').innerHTML="<div id='resources' style='display: none; height:65vh;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;' >"+resourcesToShow+"</div>";
}

if(role=='therapist'){
for(var i=0;i<array.length;i=i+3){
if(array[i]=='document'){
resourceIcon="<i class=\'fa fa-book\'></i>";}
if(array[i]=='video'){
resourceIcon="<i class='fa fa-film'></i>";}
if(array[i]=='url'){
resourceIcon="<i class='far fa-window-restore'></i>";}

if(resourceIcon!=''){
resourcesToShow=resourcesToShow+"<div class='onHover' style='font:16px Calibri;padding:15px 12px;'><div onclick='javascript:{window.open(&#39;"+array[i+2]+"&#39;,&#39;_blank&#39;);}'  style='cursor:pointer;display:inline-block;' class='onHover'>"+resourceIcon+"&nbsp;&nbsp;&nbsp;"+"<xmp style='font:16px Calibri;display:inline-block;margin:0px;'>"+array[i+1]+"</xmp>"+"</div><span style='float:right'><div onclick='javascript:removeResource(&#39;"+array[i+1]+"&#39;,&#39;"+array[i+2]+"&#39;)' style='cursor:pointer;display:inline-block;color:lightgray;' >remove</div></span></div>";}
}
document.getElementById('therapistViewAreaScreen').style.display='none';
document.getElementById('therapistDisplay').style.display='none';
document.getElementById('resourcesToDisplay').innerHTML="<div id='resources' style='display: none; height:65vh;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;' >"+resourcesToShow+addWorksheet+"</div>";
removeUpdating();
}

}

function setResourceType(resourceType){

if(resourceType=='fileType'){
setEnabled('resourceUploader',false);
setEnabled('websiteUrl',false);
setEnabled('resourceTitle',false);}

if(resourceType=='document'){
setEnabled('resourceUploader',true);
setEnabled('websiteUrl',false);
setEnabled('resourceTitle',true);}

if(resourceType=='video'){
setEnabled('resourceUploader',true);
setEnabled('websiteUrl',false);
setEnabled('resourceTitle',true);}

if(resourceType=='url'){
setEnabled('resourceUploader',false);
setEnabled('websiteUrl',true);
setEnabled('resourceTitle',true);}

}


function removeResource(title,url){
sendDataToGoogleSheets(['removeResource',firstName,lastName,title,url,conversationId],googleSheetsPortalScript);
setUpdating();
}
function getContacts(){
return "<div id='contacts' class='autoScroll' style='display:none;height:65vh;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);' >"+getSearchBarUi(true)+"</div>";
}

function getPatients(){
return "<div id='patients' style='display:none;margin-left:10px;margin-bottom:10px;' ><div id='patientsBody' ></div></div>";

}

function getMyProfile(){

return "<div class='autoScroll' id='myProfile' style='display:none;height:65vh;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);' ><div style='height:20vh;width:100%;'><div style='height:20vh;width:100%;'><div style='background-color:white;width:16vh;height:16vh;position:relative;top:2vh;left:50%;transform:translate(-50%,0%);-moz-border-radius:8vh;-webkit-border-radius:8vh;border-radius:8vh;overflow:hidden;'><div id='myProfilePic' style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font: 8vh Arial;'></div></div></div><h3 style='text-align:center;color:tomato;'><div id='myProfileName'></div></h3><div id='myProfileDescription' style='padding:10px;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);border-top:1px solid lightgray;></div><div onclick='javascript:toggle(&#39;editProfile&#39;)' style='cursor:pointer'><div style='margin-top:10px;margin-bottom:10px; width:100%;font: 16px Calibri;padding:5px 5px;text-align:center;' class='onHover'><i class='fas fa-edit' ></i> Edit</div></div><div id='editProfile' style='display:none;'><div style='width:75vw;padding:10px 10px;border-top:1px solid lightgray;font: 12px Calibri'>Upload picture<input type='file' id='profilePictureUploader' style='margin-bottom:20px;margin-top:20px;'></input></div><div><textarea id='myProfileDescriptionToSave' placeholder='Write something about yourself.' style='margin-top:20px;width:75vw;box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.2);background-color:white;z-index:2;padding:10px 10px;border:none;margin-bottom:20px' ></textarea><div onclick='javascript:saveMyProfile()' style='cursor:pointer;' ><div style='margin-bottom:20px; width:100%;font: 16px Calibri;padding:5px 5px;text-align:center;' class='onHover'><i class='fas fa-save' ></i> Save</div></div></div></div></div>";
}

function saveMyProfile(){
var profilePictureToSave=document.getElementById('profilePictureUploader').files[0];
var profilePictureDimensions='';
var myProfileDescriptionToSave=getFieldText('myProfileDescriptionToSave');
var fileReader=new FileReader();
var rawFile='';

fileReader.onload=function(){
rawFile=fileReader.result;
var myProfilePictureData=rawFile.substring(rawFile.indexOf('base64,')+7,rawFile.length);
sendDataToGoogleSheets(['saveMyProfile',role,myProfilePictureData,profilePictureToSave.type,profilePictureDimensions,firstName,lastName,myProfileDescriptionToSave,conversationId],googleSheetsPortalScript);
setUpdating();
}

if(profilePictureToSave==undefined){
sendDataToGoogleSheets(['saveMyProfile',role,'','',profilePictureDimensions,firstName,lastName,myProfileDescriptionToSave,conversationId],googleSheetsPortalScript);
setUpdating();
}else{
fileReader.readAsDataURL(profilePictureToSave);}
}

function saveResource(){
var resourceToSave=document.getElementById('resourceUploader').files[0];
var websiteUrlToSave=getFieldText('websiteUrl');
var resourceTitleToSave=getFieldText('resourceTitle');
var resourceIndexToSave=0;
var fileReader=new FileReader();
var rawFile='';
var resourceType=document.getElementById('resourceType').value;

var allFieldsCompleted=true;

if(resourceType=='fileType'){
allFieldsCompleted=false;
document.getElementById('addNewResourceButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> File type not selected";
}
if((resourceType=='document'||resourceType=='video')&&(resourceTitleToSave==''||typeof resourceToSave=='undefined')){
allFieldsCompleted=false;
if(resourceTitleToSave==''){
document.getElementById('addNewResourceButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Resource title missing";}
if(typeof resourceToSave=='undefined'){
document.getElementById('addNewResourceButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> No file selected";}
}
if(resourceType=='url'&&(resourceTitleToSave==''||websiteUrlToSave=='')){
allFieldsCompleted=false;
if(resourceTitleToSave==''){
document.getElementById('addNewResourceButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Resource title missing";}
if(websiteUrlToSave==''){
document.getElementById('addNewResourceButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Website URL missing";}
}

if(allFieldsCompleted){
fileReader.onload=function(){
rawFile=fileReader.result;
var resourceData=rawFile.substring(rawFile.indexOf('base64,')+7,rawFile.length);
sendDataToGoogleSheets(['saveResource',role,resourceType,resourceData,resourceToSave.type,websiteUrlToSave,resourceTitleToSave,firstName,lastName,conversationId],googleSheetsPortalScript);
}

if(websiteUrlToSave!=''){
sendDataToGoogleSheets(['saveResource',role,resourceType,'','',websiteUrlToSave,resourceTitleToSave,firstName,lastName,conversationId],googleSheetsPortalScript);
}else{
fileReader.readAsDataURL(resourceToSave);}
setUpdating();
}

}

function removeResourcesWarning(){
document.getElementById('addNewResourceButton').innerHTML="&#8853;&nbsp;&nbsp;Add new resource";
}

function saveMeetingTimes(){
var zoomLink=document.getElementById('zoomLink').value;
var meetingTime=document.getElementById('getDay').value+' '+document.getElementById('getHour').value+':'+document.getElementById('getMinute').value+' '+document.getElementById('getAMPM').value+' ('+document.getElementById('getDuration').value+')';

var allFieldsCompleted=true;

if(document.getElementById('getAMPM').value=='AM/PM'){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> AM/PM not selected";
}
if(document.getElementById('getMinute').value=='Minute'){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Minute not selected";
}
if(document.getElementById('getHour').value=='Hour'){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Hour not selected";
}
if(document.getElementById('getDuration').value=='Duration'){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Duration not selected";
}
if(document.getElementById('getDay').value=='Day'){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Day not selected";
}
if(document.getElementById('zoomLink').value==''){
allFieldsCompleted=false;
document.getElementById('addNewSessionButton').innerHTML="<i class='fas fa-exclamation-triangle' style='color:orange'></i> Link missing";
}

if(allFieldsCompleted){
sendDataToGoogleSheets(['saveMeeting',zoomLink,meetingTime,firstName,lastName,conversationId],googleSheetsPortalScript);
setUpdating();}
}

function removeMeetingTimesWarning(){
document.getElementById('addNewSessionButton').innerHTML="&#8853;&nbsp;&nbsp;Add new session";
}

function getPatientsProfile(){
return "<div id='patientsProfile' style='display:none;margin-left:10px;margin-bottom:10px;' ><div id='patientsProfileDescription' class='autoScroll'  style='height:65vh;width:75vw;background-color:rgba(200,200,200,0.1);padding:10px;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;position:absolute;left:50%;transform:translate(-50%,0%);'></div></div>";
}

function getPartnerProfile(){
return "<div class='autoScroll' id='partnerProfile' style='display:none;height:65vh;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);' ><div style='height:20vh;width:100%;'><div style='background-color:white;width:16vh;height:16vh;position:relative;top:2vh;left:50%;transform:translate(-50%,0%);-moz-border-radius:8vh;-webkit-border-radius:8vh;border-radius:8vh;overflow:hidden;'><div id='partnerProfilePic' style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font: 8vh Arial;'></div></div></div><h3 style='text-align:center;color:tomato;'><div id='partnerProfileName'></div></h3><div id='partnerProfileDescription' style='font:16px Calibri;padding:10px;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);border-top:1px solid lightgray;'></div></div>";
}

function getTherapists(){
var therapistList="<div onclick='javascript:toggle(&#39;patientProfilePrompt&#39;)' style='cursor:pointer;'><div style='width:72vw;height:7vh;position:fixed;top:16vh;left:24vw;z-index:3;padding:10px 20px;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;float:left;font: 1.1vw Arial;display: block;' onclick='javascript:filpCaret()'><div id='caretToFlip' style='color:dodgerblue;position:absolute;top:50%;left:1vw;transform:translate(0%,-50%)'>View patient profile</div><div style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)' id='patientTherapistMatchingPrompt' >Select a patient</div></div></div><div class='autoScroll' id='therapists' style='margin-left:10px;margin-bottom:10px;height:60vh;display:none;' ><textarea style='width:45vw;height:60vh;position:fixed;left:37.5vw;top:25vh;box-shadow: 0px 4px 4px 4px rgba(0, 0, 0, 0.2);background-color:white;z-index:2;padding:5vw;-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border:none;display:none;' class='autoScroll' id='patientProfilePrompt' readonly></textarea><div id='therapistsBody' ></div></div>";
return therapistList;
}

function filpCaret(){
var elementId=document.getElementById('caretToFlip').innerHTML;

console.log(elementId,elementId=='View providers');
if(elementId=='View providers'){
document.getElementById('caretToFlip').innerHTML='View patient profile';}else{
document.getElementById('caretToFlip').innerHTML='View providers';
}

}

function getChat(array){
var chat='';

chat=chat+"<div style='width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;display: grid;grid-template-rows: auto 160px;display:none;'  id='chatWindow'>";///

chat=chat+"<div style='width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;height:54vh;display:flex;flex-direction:column-reverse;' class='autoScroll' ><div id='conversationBody' ></div></div>";

chat=chat+"<div style='position:relative;bottom:0px;width:75vw;position:relative;left:50%;transform:translate(-50%,0%);font: 16px Calibri;padding-right:0px;'>";//

chat=chat+"";

//chat=chat+"<div style='position:absolute;left:50%;transform:translate(-50%,0%);width:200px;text-align:center;box-shadow: 0px 4px 4px 4px rgba(0, 0, 0, 0.2);background-color:white;z-index:2'>21 September 2009</div>";

chat=chat+ "<form action='javascript:sendText()' autocomplete='off' ><textarea id='textToSend' style='position:relative;padding:10px 10px;width:100%;height:10vh;resize:none;margin-bottom:10px;border-bottom:none;border-left:none;border-right:none;outline:none;background-color:rgba(0,0,0,0);font:14px Calibri;' placeholder='Write something...'></textarea><div style='position:relative;float:right;margin-bottom:10px;' ><input id='sendButton' type='submit' value='Send'></div></form>";

chat=chat+"</div>";//

chat=chat+"</div>";///

return chat;
}

function getCalendar(){
var calendar='';
var namesOfDays=['So','Mo','Tu','We','Th','Fr','Sa'];
calendar="<div style='margin-bottom:5px;overflow:auto;'><div style='-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px;background-color:darkgray;color:white;padding:5px 5px;float:left'><</div><div style='padding:5px 5px;float:left;background-color:white;'>September</div><div style='-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px;background-color:darkgray;color:white;padding:5px 5px;float:left';>></div></div><div style='clear:left'></div>";
for(var i=0;i<7;i++){
calendar=calendar+"<div style='float:left;width:50px;padding:10px 10px;background-color:gray;color:white;text-align:center;'>"+namesOfDays[i]+"</div>";}

for(var week=0;week<5;week++){
calendar=calendar+"<div style='clear:left'></div>";
for(var day=0;day<7;day++){
calendar=calendar+"<div style='float:left;width:50px;padding:10px 10px;background-color:lightgray;color:black;text-align:center;'>"+day+"</div>";
}
}

//calendar=calendar+"<div style='clear:left'><h5 style='padding:20px 5px;'>Appointment: 12 September 2021| 3:30 p.m.</h5></div>";
return "<h3 style='background-color:black;color:white;margin-left:10px;padding:5px 5px;' onclick=javascript:toggle(\'calendar\')>Schedule appointment</h3><div id='calendar' style='display:none;margin-left:10px;margin-bottom:10px;overflow:auto;'>"+calendar+"</div>";
}
function getBody(myProfile,partnerProfile,contacts,worksheets,chats,patients,therapists,live,patientProfile){

return "<div id='myProfileUi'>"+myProfile+"</div><div id='partnerProfileUi'>"+partnerProfile+"</div><div id='patientsProfileUi'>"+patientProfile+"</div><div id='contactsUi'>"+contacts+"</div><div id='worksheetsUi'>"+worksheets+"</div><div id='liveUi'>"+live+"</div><div id='patientsUi'>"+patients+"</div><div id='chatsUi'>"+chats+"</div><div id='therapistsUi'>"+therapists+"</div>";

}

function displayCorrectBlocks(){
if(role=='patient'){
document.getElementById('myProfileUi').style.display='block';
document.getElementById('partnerProfileUi').style.display='block';
document.getElementById('worksheetsUi').style.display='block';
document.getElementById('patientsUi').style.display='none';
document.getElementById('contactsUi').style.display='block';
document.getElementById('chatsUi').style.display='block';
document.getElementById('therapistsUi').style.display='none';
document.getElementById('liveUi').style.display='block';
document.getElementById('patientsProfileUi').style.display='none';
}
if(role=='therapist'){
document.getElementById('myProfileUi').style.display='block';
document.getElementById('partnerProfileUi').style.display='block';
document.getElementById('worksheetsUi').style.display='block';
document.getElementById('patientsUi').style.display='none';
document.getElementById('contactsUi').style.display='block';
document.getElementById('chatsUi').style.display='block';
document.getElementById('therapistsUi').style.display='none';
document.getElementById('liveUi').style.display='block';
document.getElementById('patientsProfileUi').style.display='block';
}

if(role=='admin'){
document.getElementById('myProfileUi').style.display='none';
document.getElementById('partnerProfileUi').style.display='none';
document.getElementById('worksheetsUi').style.display='none';
document.getElementById('patientsUi').style.display='block';
document.getElementById('contactsUi').style.display='none';
document.getElementById('chatsUi').style.display='none';
document.getElementById('therapistsUi').style.display='block';
document.getElementById('liveUi').style.display='none';
document.getElementById('patientsProfileUi').style.display='none';
}
}

function toggle(item){
if(document.getElementById(item).style.display=='block'){
document.getElementById(item).style.display='none';
}else{
document.getElementById(item).style.display='block';}
}

function getLogin(elementId){
popupPanel=elementId;
resetUi();
//makePicture('saceSpaceHighContrastTransparency.png');
makeTitle('Login');
makeField('Email address');
makePasswordField('Password');
var loginUi="<div  style='padding:15px;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;box-shadow: 0px 4px 8px 4px rgba(0,0,0,0.2);width:90vw;position:fixed;left:50%;top:50px;transform:translate(-50%,0%);z-index:2;background-color:rgba(255,255,255,0.5);margin-bottom:0px;' onclick='javascript:clearPopupStatus()'>"+getFormUiAsString()+"<div style='margin-top:0px;margin-left:20px;margin-right:20px;'><button onclick='javascript:getSignup(&#39;"+elementId+"&#39;)' style='font:18px Calibri;width:100%;background-color:white;padding:6px;box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.2);color:black;-moz-border-radius:4px;-webkit-border-radius:4px;border-radius:4px;border:none;'>Register</button><div style='text-align:center;position:relative;left:50%;transform:translate(-50%,0%);font:14px Calibri;margin-top:30px;' id='popupStatus'>&nbsp;<br>&nbsp;</div><div style='margin-top:30px;font:18px Calibri;'><div onclick='javascript:getForgotPassword(&#39;"+elementId+"&#39;)' style='color:dodgerblue;cursor:pointer;'>Forgot password?</div></div></div></div>";
document.getElementById('popupPanel').style.display='block';
document.getElementById(elementId).innerHTML=loginUi;
sendMode='login';
}

function getSignup(elementId){
resetUi();
//makePicture('saceSpaceHighContrastTransparency.png');
makeTitle('Signup');
makeField('First name');
makeField('Last name');
makeField('Enter email address');
makePasswordField('Password (atleast 8 characters)');
makePasswordField('Re-enter password');

var signupUi="<div  style='padding:15px;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;box-shadow: 0px 4px 8px 4px rgba(0,0,0,0.2);width:90vw;position:fixed;left:50%;top:50px;transform:translate(-50%,0%);z-index:2;background-color:rgba(255,255,255,0.5);'>"+getFormUiAsString()+"</div>";
document.getElementById(elementId).innerHTML=signupUi;
sendMode='signup';
}

function getForgotPassword(elementId){
resetUi();
//makePicture('saceSpaceHighContrastTransparency.png');
makeTitle('Password recovery');
makeField('Enter email address');

var passwordRecoveryUi="<div  style='padding:15px;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;box-shadow: 0px 4px 8px 4px rgba(0,0,0,0.2);width:90vw;position:fixed;left:50%;top:50px;transform:translate(-50%,0%);z-index:2;background-color:rgba(255,255,255,0.5);' onclick='javascript:clearPopupStatus()'>"+getFormUiAsString()+"<div style='margin:25px'><div id='emailStatus' style='text-align:center;position:relative;left:50%;transform:translate(-50%,0%);font:14px Calibri;margin-top:50px;' ></div></div></div>";
document.getElementById(elementId).innerHTML=passwordRecoveryUi;
sendMode='passwordRecovery';
}

function clearPopupStatus(){
try{
document.getElementById('popupStatus').innerHTML="&nbsp;";}catch(err){}
try{
document.getElementById('emailStatus').innerHTML='';}catch(err){}
}
function send(){
if(sendMode=='login'){
document.getElementById('submitButtonGuiForm').disabled=true;
sendDataToGoogleSheets([sendMode,role,getFieldText('Email address'),getFieldText('Password')],googleSheetsPortalScript);
sendDataToGoogleSheets(['getContacts',role,getFieldText('Email address'),getFieldText('Password')],googleSheetsPortalScript);
sendDataToGoogleSheets(['getPatients'],googleSheetsPortalScript);
sendDataToGoogleSheets(['getTherapists'],googleSheetsPortalScript);
document.getElementById('popupStatus').innerHTML="<span style='animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'>&#x1F50E; Searching . . .</span> ";
}
if(sendMode=='signup'){
var formCompleted=true;
if(getFieldText('First name')==''){
formCompleted=false;
document.getElementById('First name').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";}else{
document.getElementById('First name').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";}
if(getFieldText('Last name')==''){
formCompleted=false;
document.getElementById('Last name').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";}else{
document.getElementById('Last name').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";}
if(getFieldText('Enter email address')==''){
formCompleted=false;
document.getElementById('Enter email address').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";}else{
document.getElementById('Enter email address').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";}
if(getFieldText('Password (atleast 8 characters)')==''){
formCompleted=false;
document.getElementById('Password (atleast 8 characters)').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";}else{
document.getElementById('Password (atleast 8 characters)').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";}
if(getFieldText('Re-enter password')==''){
formCompleted=false;
document.getElementById('Re-enter password').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";}else{
document.getElementById('Re-enter password').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";}
if(getFieldText('Password (atleast 8 characters)')==getFieldText('Re-enter password')&&getFieldText('Password (atleast 8 characters)').length>7&&getFieldText('Re-enter password').length>7){
document.getElementById('Password (atleast 8 characters)').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";
document.getElementById('Re-enter password').style.boxShadow= "0px 0px 1px 0px rgba(0,0,0,0.2)";
}else{
formCompleted=false;
document.getElementById('Password (atleast 8 characters)').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";
document.getElementById('Re-enter password').style.boxShadow= "0px 0px 1px 0px rgba(255,0,0,1)";
}
if(formCompleted){
firstName=getFieldText('First name');
lastName=getFieldText('Last name');
email=getFieldText('Enter email address');
password=getFieldText('Password (atleast 8 characters)');
if(role=='patient'){
renderPopup(popupPanel);}
if(role=='therapist'){
renderTherapistPopup(popupPanel);}
if(role=='admin'){
sendDataToGoogleSheets([sendMode,role,firstName,lastName,email,password],googleSheetsPortalScript);
sendDataToGoogleSheets(['getPatients'],googleSheetsPortalScript);
sendDataToGoogleSheets(['getTherapists'],googleSheetsPortalScript);
setUpdating();}
}
}
if(sendMode=='passwordRecovery'){
sendDataToGoogleSheets([sendMode,role,getFieldText('Enter email address')],googleSheetsPortalScript);
document.getElementById('emailStatus').innerHTML="<span style='animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'>&#x1F50E; Searching . . .</span> ";}
}

function sendText(){
document.getElementById('sendButton').disabled=true;
var dataToSendArray=[];
var date=new Date();
var minute=date.getMinutes();

dataToSendArray[0]=firstName;
dataToSendArray[1]=lastName;
dataToSendArray[2]=myProfilePic;
dataToSendArray[3]=date.getDate()+' '+months[date.getMonth()]+' '+date.getFullYear();
if(minute<10){
minute="0"+minute;}
if(date.getHours()<13){
dataToSendArray[4]=date.getHours()+":"+minute+" am";}else{
dataToSendArray[4]=(date.getHours()-12)+":"+minute+" pm";}
dataToSendArray[5]=getFieldText('textToSend');
if(dataToSendArray[5]!=''){
sendDataToGoogleSheets(['sendingText',conversationId,dataToSendArray.join('*^*')],googleSheetsPortalScript);
}
setFieldText('textToSend','');
}

function autoCheck(){
if(!autoCheckRunning){
setInterval(function(){
sendDataToGoogleSheets(['autoCheck',conversationId],googleSheetsPortalScript);
},3000);
autoCheckRunning=true;}
}

function receiveDataFromGoogleSheets(){
waitForGoogleThenExecute();
if(getDataFromGoogleSheetsAsArray()[0]=='loginFailed'){
document.getElementById('popupStatus').innerHTML="<span style='animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'><i class='fas fa-exclamation-triangle' style='color:orange'></i> Invalid email address / password</span> ";
document.getElementById('submitButtonGuiForm').disabled=false;
}
if(getDataFromGoogleSheetsAsArray()[0]=='loginSuccessful'){
try{
document.getElementById('popupStatus').innerHTML=" ";}catch(err){}

firstName=getDataFromGoogleSheetsAsArray()[1];
lastName=getDataFromGoogleSheetsAsArray()[2];
conversationId=getDataFromGoogleSheetsAsArray()[3];
conversationDataAsString=getDataFromGoogleSheetsAsArray()[4];

var conversationData=[];
conversationData=conversationDataAsString.split('~*data*~');

var profilesArray=[];
try{
currentProfile=conversationData[0];
profilesArray=currentProfile.split('~*profilesArray*~');}catch(err){}

var resourcesArray=[];
try{
currentResources=conversationData[1].split('~*resourcesArray*~');
resourcesArray=currentResources;}catch(err){}

var meetingTimesArray=[];
try{
currentMeetingTimes=conversationData[2].split('~*meetingTimesArray*~');
meetingTimesArray=currentMeetingTimes;}catch(err){}

conversation=conversationData[3];


for(var i=0;i<profilesArray.length;i++){
let profile=profilesArray[i].split('~*profile*~');
let firstNameToSave=profile[0];
let lastNameToSave =profile[1];
let myProfileDescriptionToSave=profile[2];
let profilePictureDimensions=profile[3];
let profilePictureFileUrl=profile[4];

if(firstName==firstNameToSave&&lastName==lastNameToSave){
profileArrayData=profile;
document.getElementById('myProfileName').innerHTML=firstNameToSave+' '+lastNameToSave;
try{document.getElementById('homeScreenMyProfileName').innerHTML=firstNameToSave+' '+lastNameToSave;}catch(err){}
document.getElementById('myProfileDescription').innerHTML="<xmp style='white-space:pre-wrap;font:16px Calibri'>"+myProfileDescriptionToSave+"</xmp>";
setFieldText('myProfileDescriptionToSave',myProfileDescriptionToSave);

if(profilePictureFileUrl==''){
myProfilePic=(firstNameToSave.substring(0,1)).toUpperCase()+(lastNameToSave.substring(0,1)).toUpperCase();
document.getElementById('myProfilePic').innerHTML=myProfilePic;
try{document.getElementById('homeScreenMyProfilePic').innerHTML="<div style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font: 9vw Arial;'>"+myProfilePic;+"</div>"}catch(err){}
}else{
myProfilePic=profilePictureFileUrl;
document.getElementById('myProfilePic').innerHTML="<img style='width:16vh' src='"+myProfilePic+"'>";
try{document.getElementById('homeScreenMyProfilePic').innerHTML="<img src='"+myProfilePic+"' style='width:18vw;transform:translate(0%,0%);'/>";}catch(err){}
}
}else{
if(profile!=''){
document.getElementById('patientsProfileDescription').innerHTML="<xmp style='white-space:pre-wrap;font:16px Calibri'>"+profilePictureDimensions+"</xmp>";
document.getElementById('partnerProfileName').innerHTML=firstNameToSave+' '+lastNameToSave;
document.getElementById('partnerProfileDescription').innerHTML="<xmp style='white-space:pre-wrap;font:16px Calibri;'>"+myProfileDescriptionToSave+"</xmp>";
if(profilePictureFileUrl==''){
partnerProfilePic=(firstNameToSave.substring(0,1)).toUpperCase()+(lastNameToSave.substring(0,1)).toUpperCase();
document.getElementById('partnerProfilePic').innerHTML=partnerProfilePic;
}else{
partnerProfilePic=profilePictureFileUrl;
document.getElementById('partnerProfilePic').innerHTML="<img style='width:16vh' src='"+partnerProfilePic+"'>";}}
}


}

var resourcesToShowArray=[];

for(var i=0;i<resourcesArray.length;i++){
let resource=resourcesArray[i].split('~*resource*~');
resourcesToShowArray[i*3]=resource[0];
resourcesToShowArray[i*3+1]=resource[1];
resourcesToShowArray[i*3+2]=resource[2];
}
showResources(resourcesToShowArray);





var meetingsToShowArray=[];

for(var i=0;i<meetingTimesArray.length;i++){
let meeting=meetingTimesArray[i].split('~*meeting*~');
meetingsToShowArray[i*2]=meeting[0];
meetingsToShowArray[i*2+1]=meeting[1];
}
showMeetingTimes(meetingsToShowArray);






removePopupPanel();

if(role!='admin'){
autoCheck();
setUpdating();
removeUpdatingOnConversationUpdate();}
displayDashboard();

if(role=='therapist'){
}
if(document.getElementById('myProfileName').innerHTML==''&&role!='admin'){
saveMyProfile();}
}

if(getDataFromGoogleSheetsAsArray()[0]=='noConversationId'){

if(patientJustRegistered){
document.location='https://buy.stripe.com/test_dR60202qFgwSg8M5km';}

removePopupPanel();
removeUpdating();
document.getElementById('loginRejectionPanel').innerHTML="<div onclick='javascript:{document.getElementById(&#39;loginRejectionPanel&#39;).innerHTML=&#39;&#39;;}' style='cursor:pointer;position:absolute;top:0px;left:0px;z-index:2;width:100vw;height:100vh;background-color:rgba(0,0,0,.5);'><div style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);color:white;font:44px Calibri;'>"+getDataFromGoogleSheetsAsArray()[1]+"</div></div>";
}

if(getDataFromGoogleSheetsAsArray()[0]=='updateConversation'){
if(waitForConversationToUpdate){
waitForConversationToUpdate=false;
removeUpdating();}
var conversationDataAsString=getDataFromGoogleSheetsAsArray()[1];

let conversation
let conversationData=[];
conversationData=conversationDataAsString.split('~*data*~');

var profilesArray=[];
try{
if(currentProfile!=conversationData[0]){

currentProfile=conversationData[0];
profilesArray=currentProfile.split('~*profilesArray*~');
updateProfile(profilesArray);
}
}catch(err){}

var resourcesArray=[];
try{
if(currentResources!=conversationData[1]){

currentResources=conversationData[1];

let resourcesToShowArray=[];
resourcesArray=currentResources.split('~*resourcesArray*~');

for(var i=0;i<resourcesArray.length;i++){
let resource=resourcesArray[i].split('~*resource*~');
resourcesToShowArray[i*3]=resource[0];
resourcesToShowArray[i*3+1]=resource[1];
resourcesToShowArray[i*3+2]=resource[2];
}

showResources(resourcesToShowArray);
}
}catch(err){}

var meetingTimesArray=[];
try{
if(currentMeetingTimes!=conversationData[2]){

currentMeetingTimes=conversationData[2];
meetingTimesArray=currentMeetingTimes.split('~*meetingTimesArray*~');
let meetingsToShowArray=[];
for(var i=0;i<meetingTimesArray.length;i++){
let meeting=meetingTimesArray[i].split('~*meeting*~');
meetingsToShowArray[i*2]=meeting[0];
meetingsToShowArray[i*2+1]=meeting[1];
}
showMeetingTimes(meetingsToShowArray);}
}catch(err){}


conversation=conversationData[3];
setConversationBody(conversation);
removeUpdating();
}

if(getDataFromGoogleSheetsAsArray()[0]=='signupSuccessful'){
}

if(getDataFromGoogleSheetsAsArray()[0]=='patientRequestSuccessful'){
}

if(getDataFromGoogleSheetsAsArray()[0]=='emailSent'){
document.getElementById('emailStatus').innerHTML="<span style='animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'><i class='fas fa-envelope' style='color:green'></i> &nbsp;Check your email for further instructions</span> ";
}
if(getDataFromGoogleSheetsAsArray()[0]=='emailNotFound'){
document.getElementById('emailStatus').innerHTML="<span style='animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'><i class='fas fa-exclamation-triangle' style='color:orange'></i> Invalid email address</span> ";
}

if(getDataFromGoogleSheetsAsArray()[0]=='contactsFound'){

var contactsArray=getDataFromGoogleSheetsAsArray()[1];
var contactList=contactsArray.split('*^*');
var contactNamesToDisplay=[];

for(var i=0;i<contactList.length;i++){
contactNamesToDisplay[i]=(contactList[i].split('*^^^*'))[0];
chatNumbers[contactNamesToDisplay[i]]=(contactList[i].split('*^^^*'))[1];
}
contactNamesToDisplay.join('^*^');
setRecordToSearch(contactNamesToDisplay);
}

if(getDataFromGoogleSheetsAsArray()[0]=='patientsFound'){
var tempPatientTherapistList=getDataFromGoogleSheetsAsArray()[1].split('*^*');
var patientTherapistList=[];
var patientTherapistPatientProfile=[];

for(var i=0;i<tempPatientTherapistList.length;i++){
var patientTherapistInfo=tempPatientTherapistList[i].split('*^^^*');
if(patientTherapistInfo[1]==''){
patientTherapistList[i]=patientTherapistInfo[0];
patientTherapistPatientProfile[i]=patientTherapistInfo[3];
}
else{
patientTherapistList[i]=patientTherapistInfo[0]+ " ( "+patientTherapistInfo[1]+" )";
patientTherapistPatientProfile[i]=patientTherapistInfo[3];
}
}
setPatientsList(patientTherapistList,patientTherapistPatientProfile);

}

if(getDataFromGoogleSheetsAsArray()[0]=='therapistsFound'){
var tempTherapistList=getDataFromGoogleSheetsAsArray()[1].split('*^*');
setTherapistList(tempTherapistList);
}

if(getDataFromGoogleSheetsAsArray()[0]=='therapistAssignedSuccessful'){
document.getElementById('patientTherapistMatchingPrompt').innerHTML='Select a patient';
document.getElementById('patientProfilePrompt').innerHTML='';
sendDataToGoogleSheets(['getPatients'],googleSheetsPortalScript);
}

}

function removeUpdatingOnConversationUpdate(){
waitForConversationToUpdate=true;}

function searchBarItemSelected(chatSelected){
conversationId=chatNumbers[chatSelected];
setUpdating();
}

function setPatientsList(patientNames,patientProfile){
removeUpdating();
var patientsNameUi='';
for(var i=0;i<patientNames.length;i++){
if(patientNames[i].indexOf('(')==-1){
patientsNameUi=patientsNameUi+"<div onclick='javascript:setPatientTherapistMatchingPrompt(&#39;"+patientNames[i]+"&#39;);setPatientTherapistMatchingProfile(&#39;"+patientProfile[i].replaceAll("\n",'~~~')+"&#39;)' style='cursor:pointer;'><div class='onHoverTherapist' style='-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;padding:15px 12px;' >"+patientNames[i]+"</div></div>";
}else{
patientsNameUi=patientsNameUi+"<div style='padding:15px 12px;'><div style='-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;display:inline-block;' disabled=true>"+patientNames[i]+"</div><span style='float:right'><div onclick='javascript:removeTherapist(&#39;"+patientNames[i]+"&#39;)' style='display:inline-block;color:#00C0FF;cursor:pointer;' >remove</div></span></div>";}

}
document.getElementById('patientsBody').innerHTML=patientsNameUi;
}

function setPatientTherapistMatchingPrompt(patientNameToMatch){
patientToMatch=patientNameToMatch;
document.getElementById('patientTherapistMatchingPrompt').innerHTML='Assign '+patientNameToMatch+' a therapist';
selectOnlyOne('therapists');
}

function setPatientTherapistMatchingProfile(patientProfile){
document.getElementById('patientProfilePrompt').innerHTML=patientProfile.replaceAll('~~~','\r\n');
}

function setTherapistList(therapistsNames){

var therapistsNameUi='';
therapistsNameUi="<div style='width:100%;height:70px;'></div>";
for(var i=0;i<therapistsNames.length;i++){
var therapistInfo=therapistsNames[i].split('*^^^*');
therapistsNameUi=therapistsNameUi+"<div onclick='javascript:setTherapist(&#39;"+therapistInfo[0]+' '+therapistInfo[1]+"&#39;)' style='cursor:pointer;'><div class='onHoverTherapist' style='-moz-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;'><div style='width:100%;'><div style='background-color:white;width:8vh;height:8vh;position:relative;top:2vh;left:50%;transform:translate(-50%,0%);-moz-border-radius:4vh;-webkit-border-radius:4vh;border-radius:4vh;overflow:hidden;'><div style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font: 4vh Arial;'><img style='width:8vh' src='"+therapistInfo[3]+"' >"+"</div></div></div><h3 style='text-align:center;color:tomato;'><div >"+therapistInfo[0]+' '+therapistInfo[1]+"</div></h3><h4 style='text-align:center;color:dimgrey'><div><textarea style='padding:10px 10px;width:90%;resize:none;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;margin-bottom:10px;border:none;overflow:none;' placeholder='Write something short...' readonly>"+therapistInfo[2]+"</textarea></div></h4></div></div>";
}
document.getElementById('therapistsBody').innerHTML=therapistsNameUi;
}

function setTherapist(therapistToMatchWithPatient){
therapistToMatch=therapistToMatchWithPatient;
if(patientToMatch!=''&&therapistToMatch!=''){
sendDataToGoogleSheets(['assignTherapist',patientToMatch,therapistToMatch],googleSheetsPortalScript);
setUpdating();
patientToMatch='';
therapistToMatch='';
}
}


function removeTherapist(patientAndTherapist){
var patientToUnassign=patientAndTherapist.substring(0,patientAndTherapist.indexOf('(')-1);
var therapistToUnassign=patientAndTherapist.substring(patientAndTherapist.indexOf('(')+2,patientAndTherapist.indexOf(')')-1);
sendDataToGoogleSheets(['unassignTherapist',patientToUnassign,therapistToUnassign],googleSheetsPortalScript);
setUpdating();
}

function setUpdating(){
document.getElementById('adminPatientRejectionPanel').innerHTML="<div style='cursor:pointer;position:absolute;top:0px;left:0px;z-index:2;width:100vw;height:100vh;'><div style='width:100%;height:100%;background-color:rgba(0,0,0,.5);animation-name:popupStatus;animation-duration:8s;animation-iteration-count:infinite'><div style='position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);font:44px Calibri;'><i class='fas fa-cloud-upload-alt' style='color:orange'></i> Updating...</div></div></div>";
}
function removeUpdating(){
document.getElementById('adminPatientRejectionPanel').innerHTML='';
}
function setConversationBody(conversationBodyToSet){
var conversationArray=[];
try{
conversationArray=conversationBodyToSet.split('*^^^*');}catch(err){
document.getElementById('conversationBody').innerHTML='';}
var chat='';
for(var i=0;i<conversationArray.length;i++){
try{
var messageArray=[];
messageArray=conversationArray[i].split('*^*');
if(messageArray.length>1){
if(firstName==messageArray[0]&&lastName==messageArray[1]){
if(myProfilePic.length>2){
chat=chat+"<div style='display:block;margin-bottom:10px;position:relative;top:0px;left:calc(100% - 60px);' ><div style='width:60px;height:60px;-moz-border-radius:30px;-webkit-border-radius:30px;border-radius:30px;overflow:hidden;'><img style='width:60px' src='"+myProfilePic+"'></div></div> ";}else{
chat=chat+"<div style='display:block;margin-bottom:10px;position:relative;top:0px;left:calc(100% - 60px);' ><div style='width:60px;height:60px;-moz-border-radius:30px;-webkit-border-radius:30px;border-radius:30px;overflow:hidden;background-color:whitesmoke'><div style='text-align:center;font:30px Calibri;position:relative;top:50%;transform:translate(0%,-50%)'>"+myProfilePic+"</div></div> </div> ";
}
chat=chat+"<div style='width:100%; position:relative;top:0px;left:0px;'><div style='padding:10px 10px; overflow:hidden;display:block;background-image:linear-gradient(to bottom,#ebe3d9,#f6dcc4);-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;-moz-border-top-right-radius:0px;-webkit-border-top-right-radius:0px;border-top-right-radius:0px;margin-bottom:10px;'><xmp style='white-space:pre-wrap;font:14px Calibri;'>"+messageArray[5]+"</xmp><div style='margin-top:10px;color:gray;text-align:right;font:10px Calibri;'>"+messageArray[3]+" | "+messageArray[4]+"</div></div></div>";}
else{

if(partnerProfilePic.length>2){
chat=chat+"<div style='display:block;margin-bottom:10px;' ><div style='width:60px;height:60px;-moz-border-radius:30px;-webkit-border-radius:30px;border-radius:30px;overflow:hidden;'><img style='width:60px' src='"+partnerProfilePic+"'></div> </div>";}else{
chat=chat+"<div style='display:block;margin-bottom:10px;' ><div style='width:60px;height:60px;-moz-border-radius:30px;-webkit-border-radius:30px;border-radius:30px;overflow:hidden;background-color:wheat'><div style='text-align:center;font:30px Calibri;position:relative;top:50%;transform:translate(0%,-50%)'>"+partnerProfilePic+"</div></div> </div> ";}

chat=chat+"<div style='width:100% ; position:relative;top:0px;left:0px;'><div style='padding:10px 10px; overflow:hidden;display:block;background-image:linear-gradient(to bottom,lightgray,whitesmoke);-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;-moz-border-top-left-radius:0px;-webkit-border-top-left-radius:0px;border-top-left-radius:0px;margin-bottom:10px;'><xmp style='white-space:pre-wrap;font:14px Calibri'>"+messageArray[5]+"</xmp><div style='margin-top:10px;color:gray;text-align:right;font:10px Calibri;'>"+messageArray[3]+" | "+messageArray[4]+"</div></div></div>";}
}
}catch(err){}
}

document.getElementById('conversationBody').innerHTML=chat;
document.getElementById('sendButton').disabled=false;
}


function waitForGoogleThenExecute(){}

function waitForPatientInfo(patientProfileInfo){
sendDataToGoogleSheets([sendMode,role,firstName,lastName,email,password,patientProfileInfo],googleSheetsPortalScript);
patientJustRegistered=true;
setUpdating();
}

function waitForTherapistInfo(therapistPic,therapistPicType,therapistDescription){
sendDataToGoogleSheets([sendMode,role,firstName,lastName,email,password,therapistPic,therapistPicType,therapistDescription],googleSheetsPortalScript);
therapistJustRegistered=true;
setUpdating();
}

function removePopupPanel(){
document.getElementById('popupPanel').style.display='none';
}

function getDay(){
return "<span><select style='float:left;padding:2px 2px;margin:2px;font:12px Calibri;' id='getDay'><option>Day</option><option value='Monday'>Monday</option><option value='Tuesday'>Tuesday</option><option value='Wednesday'>Wednesday</option><option value='Thursday'>Thursday</option><option value='Friday'>Friday</option><option value='Saturday'>Saturday</option><option value='Sunday'>Sunday</option></select></span>";
}

function getDuration(){
return "<span><select style='float:left;padding:2px 2px;margin:2px;font:12px Calibri;' id='getDuration'><option>Duration</option><option value='00h 15m'>00h 15m</option><option value='00h 30'>00h 30m</option><option value='00h 45m'>00h 45m</option><option value='01h 00m'>01h 00m</option><option value='01h 15m'>01h 15m</option><option value='01h 30m'>01h 30m</option><option value='01h 45m'>01h 45m</option><option value='02h 00m'>02h 00m</option></select></span>";
}

function getHour(){
return "<span><select style='float:left;padding:2px 2px;margin:2px;font:12px Calibri;' id='getHour'><option>Hour</option><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='11'>11</option><option value='12'>12</option></select></span>";
}

function getMinutes(){
return "<span><select style='float:left;padding:2px 2px;margin:2px;font:12px Calibri;' id='getMinute'><option>Minute</option><option value='05'>5</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option><option value='45'>45</option><option value='50'>50</option><option value='55'>55</option></select></span>";
}

function getAMPM(){
return "<span><select style='float:left;padding:2px 2px;margin:2px;font:12px Calibri;' id='getAMPM'><option>AM/PM</option><option value='AM'>AM</option><option value='PM'>PM</option></select></span>";
}

function updateProfile(profileArraysToUpdate){

for(var i=0;i<profileArraysToUpdate.length;i++){
let profile=profileArraysToUpdate[i].split('~*profile*~');

let firstNameToSave=profile[0];
let lastNameToSave =profile[1];
let myProfileDescriptionToSave=profile[2];
let profilePictureDimensions=profile[3];
let profilePictureFileUrl=profile[4];

if(firstName==firstNameToSave&&lastName==lastNameToSave){
}else{
if(profile!=''){
document.getElementById('patientsProfileDescription').innerHTML="<xmp style='white-space:pre-wrap;font:16px Calibri'>"+profilePictureDimensions+"</xmp>";
document.getElementById('partnerProfileName').innerHTML=firstNameToSave+' '+lastNameToSave;
document.getElementById('partnerProfileDescription').innerHTML="<xmp style='white-space:pre-wrap;font:16px Calibri'>"+myProfileDescriptionToSave+"</xmp>";
if(profilePictureFileUrl==''){
partnerProfilePic=(firstNameToSave.substring(0,1)).toUpperCase()+(lastNameToSave.substring(0,1)).toUpperCase();
document.getElementById('partnerProfilePic').innerHTML=partnerProfilePic;}else{
partnerProfilePic=profilePictureFileUrl;
document.getElementById('partnerProfilePic').innerHTML="<img style='width:16vh' src='"+partnerProfilePic+"'>";}}}
}
}