﻿
function fillMyMapPane(memberID)
{    
    $("myMapContent").style.display = "none";

    PageMethods.getMemberInfo(memberID, onMemberResult, onMemberError);   
}
     
        function onMemberResult(resultSet)              //callback function that processes the page method call return value.
        {
            // This defines the onclick functions attached to the MyMap tabs (my favorites, my reviews, my posts etc)
            // The tabberOptions should not be defined as a global variable or else multiple instances of the tabs will appear 
                        
            //tabberOptions.onClick = setTabberOnClick
    
            //tabberAutomatic(tabberOptions);   //this creates a tabber only the first time it is called (then the orginal class names are not found because they were changed when run the first time)           
            
            fillMemberInfo(resultSet);
            $('tabberDiv').tabber.memberID = resultSet.tables[0].rows[0].memberID; //initializing the tabber with the memberID for which info should be display, this will be used by the onClick function below 
            $('tabberDiv').tabber.tabShow(0);  //reset to 1st tab (ie Favorites)
        }
                  
        function onMemberError(e)
        {
            var errMsg = "<br/><br/>Error message: "+e._message+"<br/><br/>Error details: "+e._stackTrace
            msgBox("Oops!", "Could not get member information."+errMsg, 500);
        }


function fillMemberInfo(resultSet)
{
   var table = resultSet.tables[0]
   var photos = resultSet.tables[1]  
   
   fillPhotoInfo(resultSet)
       
   $("myMapDisplay").innerHTML = table.rows[0].display;
   //$("myMapDisplayChange").innerHTML = "<a class='link' href='#'>change display name</a>"
   
   $("myMapAboutMe").innerHTML = table.rows[0].aboutMe
   
   $("myMapLink").innerHTML = createLink(table.rows[0].link)
   
   $("myMapFaith").innerHTML = createFaith(table.rows[0].faith)
   
   $("myMapChurch").innerHTML = table.rows[0].church
   
   $("myMapJoined").innerHTML = table.rows[0].joinedOn.format("MMM d, yyyy");
    
   $("myMapProfileEdit").innerHTML = "<a class='link' href='javascript:editProfile()'>edit profile</a>" 
    
   //$("myMapFavoritesMenu").innerHTML = "Loading... " 
   if (table.rows[0].favoriteCount == null) {table.rows[0].favoriteCount = 0}  //display "0" instead of "null"
   //$("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[0].firstChild.nodeValue = "Bookmarks"// ("+table.rows[0].favoriteCount+")"  //Update the tab title with new favoriteCount (note that 0 is the index of the Favorites tab in the returned array of <a> tags
   //$("myMapFavoritesDiv").title = "My favorites ("+table.rows[0].favoriteCount+")"   
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   { myUser.favoriteCount = table.rows[0].favoriteCount  } //initializing user favoriteCount field
   
   //$("myMapReviewsMenu").innerHTML = "Loading... "  
   if (table.rows[0].reviewCount == null) {table.rows[0].reviewCount = 0} 
   $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[1].firstChild.nodeValue = "Prayer Responses"// ("+table.rows[0].reviewCount+")"  //Update the tab title with new favoriteCount (note that 1 is the index of the Reviews tab in the returned array of <a> tags   
   //$("myMapReviewsDiv").title = "My reviews ("+table.rows[0].reviewCount+")"   
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   { myUser.reviewCount = table.rows[0].reviewCount }   //initializing user reviewCount field

   
   //$("myMapPostsMenu").innerHTML = "Loading... "  
   if (table.rows[0].postCount == null) {table.rows[0].postCount = 0} 
   $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[0].firstChild.nodeValue = "Prayer Requests"// ("+table.rows[0].postCount+")"  //Update the tab title with new postCount (note that 2 is the index of the Posts tab in the returned array of <a> tags
   //$("myMapPostsDiv").title = "My posts ("+table.rows[0].postCount+")"
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   {        myUser.postCount = table.rows[0].postCount }

   //$("myMapPlaydatesMenu").innerHTML = "Loading... "  
   if (table.rows[0].playdateCount == null) {table.rows[0].playdateCount = 0} 
   //$("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[3].firstChild.nodeValue = "Playdates"// ("+table.rows[0].playdateCount+")"  //Update the tab title with new playdateCount (note that 4 is the index of the Posts tab in the returned array of <a> tags
   //$("myMapPlaydatesDiv").title = "My playdates ("+table.rows[0].playdateCount+")"
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   {    myUser.playdateCount = table.rows[0].playdateCount  }      


  
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   {        
       //$("myMapPhotosMenu").innerHTML = "Loading... "  
       if (table.rows[0].photoCount == null) {table.rows[0].photoCount = 0} 
       $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[2].firstChild.nodeValue = "Photos"// ("+table.rows[0].photoCount+")"  //this handles the case where the tabs are already in place - Update the tab title with new photoCount (note that 3 is the index of the Photos tab in the returned array of <a> tags   
       //$("myMapPhotosDiv").title = "My photos ("+table.rows[0].photoCount+")"  //case where the live tabs have not been generated 
       myUser.photoCount = table.rows[0].photoCount  
       //try{$("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[3].firstChild.nodeValue = "My photos ("+myUser.photoCount+")"}catch(err){}  //this handles the case where the tabs are already in place - Update the tab title with new photoCount (note that 3 is the index of the Photos tab in the returned array of <a> tags
   }else{$("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[2].firstChild.nodeValue = "Photos"}  //don't display photo number since we don't know how many playdate photos need to be deducted from that count
   
   //display summary info while the rest of the user info is being retrieved
   $("myMapLoad").style.display = "none";
   $("myMapContent").style.display = "block";
   
   //if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   //{        
   //     $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[3].style.display = "inline";  //"inline";  
   //}
   //else {$("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[3].style.display = "none"; }  //hide playdate tab
   
   //initialize the user profile fields
   if (table.rows[0].memberID == myUser.memberID) // user is looking at his own profile
   {    
        myUser.aboutMe = table.rows[0].aboutMe;
        myUser.link = table.rows[0].link;
        myUser.location = table.rows[0].location;
        myUser.email = table.rows[0].email;
        myUser.password = table.rows[0].password;
        myUser.faith = table.rows[0].faith;
        myUser.church = table.rows[0].church;
        myUser.name = table.rows[0].name;
   }
   
   getPosts(resultSet.tables[0].rows[0].memberID)    

}

function fillPhotoInfo(resultSet)
{
   var table = resultSet.tables[0]
   var photos = resultSet.tables[1]  
   
   var primary;
   var tb;               
   var str = "";
    
   if (table.rows[0].primaryPic != null)
   {   
        primary = photoFolder+"/"+mbrFolder+"/"+table.rows[0].primaryPic;
        tb = 1;                     //tb is used in the addphoto url below so the function knows if it needs to create a primaryPic
        $("myMapPhoto").innerHTML = "<a href='javascript:getSlideShow(\"members\"," + table.rows[0].memberID + ", \"" + table.rows[0].primaryPic.slice(1) + "\");'><img class='mbrThumbnail' src='" + primary + "' alt='click to enlarge'></a>"   //not using: 'id="+table.rows[0].memberID+"&'
        //$("myMapPhotoMenu").innerHTML = "<a class='link' href='javascript:showBox(\"Add photo\", 330, 350, \"photoUpload.aspx?id="+table.rows[0].memberID+"&catG=members&tn="+tb+"&m="+myUser.memberID+"\", \"profile\");'>Add photo</a>" 
        $("myMapThumbnails").innerHTML = "";  //clear the thumbnails in case user switches from account with thumbnails to user with no thumbnails (if we don't clear the previous user's thumbnails will show)
        for (i=0;i<photos.rows.length;i++)
        {
            var thumbnail = photoFolder+"/"+mbrFolder+"/t"+photos.rows[i].photoName;
            var description = photos.rows[i].photoDesc
            var primaryComp = table.rows[0].primaryPic;  //if primaryComp = thumbnail, then thumbnail is a primary pic
            
            str += "<span><input type='checkbox' name='CBProfile' class='"+primaryComp+"' style='display:none' ";  //I'm using the class attribute to store the primary pic (minus first letter "p") so I can later compare it to the picture the user deletes and see if the primary pic needs to be deleted too
            str += "id='profile"+photos.rows[i].picID+"' value='" + description + "' />";

            str += "<a id=" + i + " href='javascript:getSlideShow(\"members\"," + table.rows[0].memberID + ",\"" + photos.rows[i].photoName + "\");'><img class='mbrThumbnail' src='" + thumbnail + "' alt='" + description + "' /></a></span>"
        }
        $("myMapThumbnails").innerHTML = str;
        $("myMapThumbnails").style.display = "block";
        photoMenu = ""
        photoMenu += "<a class='link' href='javascript:showBox(\"Add photo\", 330, 250, \"photoUpload.aspx?id="+table.rows[0].memberID+"&catG=members&tn="+tb+"&m="+myUser.memberID+"\", \"profile\");'>add photo</a>"
        photoMenu += " | "
        photoMenu += "<a id='managePhotoA' class='link' href='javascript:managePhotos()'>manage photos</a>"
        $("myMapPhotoMenu").innerHTML = photoMenu
   }
   else 
   {   
        addDefaultPhotoInfo()
   }     

}

function addDefaultPhotoInfo()
{
    photo = photoFolder + "/" + mbrDefaultPhoto;
    tb = 0;
    $("myMapPhoto").innerHTML = "<img class='mbrPhoto' src=" + photo + " alt='placeholder graphic'></a>" 
    photoMenu = "<a class='link' href='javascript:showBox(\"Add photo\", 330, 250, \"photoUpload.aspx?id="+myUser.memberID+"&catG=members&tn="+tb+"&m="+myUser.memberID+"\", \"profile\");'>add photo</a>"
    $("myMapPhotoMenu").innerHTML = photoMenu        
    $("myMapThumbnails").style.display = "none";
}

function createFaith(nbr)
{
    switch(nbr)
    {
        case 0:
            return "";   
        case 1:
            return "Buddhism";           
        case 2:
            return "Christianity";
        case 3:
            return "Hinduism";
        case 4:
            return "Islam";
        case 5:
            return "Judaism";
        case 6:
            return "Non-religious";
        case 7:
            return "Other";
        default:
            return(""); // default code
     }

}


function getFavorites(memberID)
{        
   if (memberID == myUser.memberID) // user is looking at his own profile
   {
       if ((myUser.favoriteCount != null) && (myUser.favoriteCount != 0))  //0 is in case a user adds, then deletes favorites
       {
            $("myMapFavoritesMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>" 
            PageMethods.getFavoritesInfo(myUser.memberID, onFavoritesResult, onMemberError);   
       }
       else
       {    
            $("myMapFavorites").innerHTML = ""  //clearing the favorites check boxes (case of previous user logged in)
            $("myMapFavoritesMenu").innerHTML = "<br/>You do not have any bookmark.<br/>";
       }
   }
   else  //user is looking at someone else's profile and we don't know if that other user has any bookmark yet
   {
       $("myMapFavoritesMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>" 
       PageMethods.getFavoritesInfo(memberID, onFavoritesResult, onMemberError);   
   } 
   
}

        function onFavoritesResult(resultTable)              //resultTable columns are: mapID, title, CG, CGdesc
        {
            if (resultTable.rows)  //if there are bookmark(s)
            {
                addMyMapMenu(resultTable.rows[0].memberID, "myMapFavoritesMenu", "Favorites");
                str = "";
                for (i=0; i<resultTable.rows.length; i++)
                {
                    str += "<div id='divFavorites"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'>"
                    str += "<input type='checkbox' name='CBFavorites' id='"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'/>";
                    str += resultTable.rows[i].title//+" ("+resultTable.rows[i].CGdesc+")"
                    str += "</div>";
                }  
                
                $("myMapFavorites").innerHTML = str;  
            }
            else {$("myMapFavoritesMenu").innerHTML = "<br/>No bookmark yet.<br/>";}        
        }
 
 
function getReviews(memberID)
{        
   $("myMapReviews").innerHTML = ""  //clearing the reviews check boxes (case of previous user logged in)

   if (memberID == myUser.memberID) // user is looking at his own profile
   {       
       if ((myUser.reviewCount != null) && (myUser.reviewCount != 0))  //0 is in case a user adds, then deletes reviews
       {
            $("myMapReviewsMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
            PageMethods.getReviewsInfo(myUser.memberID, onReviewsResult, onMemberError);   
       }
       else
       {    
            $("myMapReviewsMenu").innerHTML = "You do not have any prayer response.";
       }
   }
   else  //user is looking at someone else's profile and we don't know if that other user has any review yet
   {
        $("myMapReviewsMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
        PageMethods.getReviewsInfo(memberID, onReviewsResult, onMemberError);   
   }
}

        function onReviewsResult(resultTable)   //resultTable columns are: mapID, title, CG, CGdesc, cmtID, cmtTitle, cmtDescription, cmtRating, cmtDate
        {
            if (resultTable.rows)
            {
                addMyMapMenu(resultTable.rows[0].memberID, "myMapReviewsMenu", "Reviews");
                str = "";
                for (i=0; i<resultTable.rows.length; i++) //*** any change to the UI template below should also be made to the onNewReviewResult() function in find.js ***
                {
                    str += "<div id='divReviews"+resultTable.rows[i].CG+resultTable.rows[i].cmtID+"'>"
                    str += "<div><input type='checkbox' name='CBReviews' id='"+resultTable.rows[i].CG+resultTable.rows[i].cmtID+"' value='"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'/>";  //I'm using the value attribute to store the mapID based id (instead of the cmtID based id), ie "PG7" where seven is the mapID, this will be used later for showing the item on the map
                    str += "My prayer for <span class='rvwTitle'>"+resultTable.rows[i].title+"</span>:"// ("+resultTable.rows[i].CGdesc+"):</div>";
                    str += "</div>";
                    str += "<div class='cttReview'><div class='rvwBlockFind1'><span id='rvwRating"+i+"' class='rvwRating'>"+createRating2(1,resultTable.rows[i].cmtRating)+"</span>";
                    str += "<span class='rvwDesc'>"+resultTable.rows[i].cmtDescription+"</span></div>";
                    str += "<div class='rvwDate'>"+resultTable.rows[i].cmtDate.format("MMM d, yyyy")+"</div></div>"
                    str += "<input id='"+resultTable.rows[i].CG+resultTable.rows[i].cmtID+"rating' style='display:none' value='"+resultTable.rows[0].CG+resultTable.rows[i].cmtRating+"'/>"; //this is a hidden field used to store the rating so we can later pass it to the server when a comment is deleted to update the posts ratingTotal/ratingCount columns                 
                    str += "</div>";
                }            
                $("myMapReviews").innerHTML = str;   
            }
            else {$("myMapReviewsMenu").innerHTML = "No prayer response yet.";}  
        }


function getPosts(memberID)
{   
    $("myMapPosts").innerHTML = ""   //clear the posts div
    
    if (memberID == myUser.memberID) // user is looking at his own profile
    {        
       if ((myUser.postCount != null) && (myUser.postCount != 0))  //0 is in case a user adds, then deletes posts
       {
            $("myMapPostsMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
            PageMethods.getPostsInfo(myUser.memberID, onPostsResult, onMemberError);   
       }
       else
       {    
            $("myMapPostsMenu").innerHTML = "You do not have any prayer request.";
       }
    }  
    else  //user is looking at someone else's profile and we don't know if that other user has any post yet
    {
        $("myMapPostsMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
        PageMethods.getPostsInfo(memberID, onPostsResult, onMemberError);       
    } 
}

        function onPostsResult(resultTable)  //columns are: mapID, title, description, ratingTotal, ratingCount, createdOn, status, CG, CGdesc
        {
            if (resultTable.rows)
            {
                addMyMapMenu(resultTable.rows[0].memberID, "myMapPostsMenu", "Posts");
                str = "";
                for (i=0; i<resultTable.rows.length; i++)
                {
                    var rate
                    if (resultTable.rows[i].ratingTotal) {rate = resultTable.rows[i].ratingTotal/resultTable.rows[i].ratingCount} else {rate = 0}
                    
                    str += "<div id='divPosts"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'>"
                        str += "<input type='checkbox' name='CBPosts' id='"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"' value='"+resultTable.rows[i].primaryPic+"'/>";
                        str += "<span class='rvwTitle'>"+resultTable.rows[i].title + "</span><span id='postRating"+i+"' class='rvwRating'>"+createRating2(1,rate)+"</span>"  //+" ("+resultTable.rows[i].CGdesc+")</div>";
                        if (resultTable.rows[i].status) { str += "<span class='postPrayerAnswered'>Prayer Answered !</span>" }                   
                        str += "<div class='rvwBlockFind1'><span class='rvwDesc'>"+decHtmUpdate(resultTable.rows[i].description)+"</span></div>";
                        str += "<div class='rvwDate'>"+resultTable.rows[i].createdOn.format("MMM d, yyyy")+"</div>"
                    str += "</div>";
                }  
                
                $("myMapPosts").innerHTML = str; 
                Nifty("div.rvwBlockFind", "small transparent");   
            }
            else  {$("myMapPostsMenu").innerHTML = "No prayer request yet.";}
        }


function getPlaydates()
{        
   if ((myUser.playdateCount != null) && (myUser.playdateCount != 0))  //0 is in case a user adds, then deletes posts
   {
        $("myMapPlaydatesMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
        PageMethods.getPlaydatesInfo(myUser.memberID, onPlaydatesResult, onMemberError);   
   }
   else
   {    
        $("myMapPlaydates").innerHTML = "" 
        $("myMapPlaydatesMenu").innerHTML = "You do not have any playdate.";
   }
}

        function onPlaydatesResult(resultTable)              //resultTable columns are: mapID, title, CG, CGdesc
        {
            addMyMapMenu(myUser.memberID, "myMapPlaydatesMenu", "Playdates");
            str = "";
            for (i=0; i<resultTable.rows.length; i++)
            {
                str += "<div id='divPlaydates"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'>"
                str += "<input type='checkbox' name='CBPlaydates' id='"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"' value=''/>";
                str += resultTable.rows[i].title+" ("+resultTable.rows[i].CGdesc+")</div>";
            }  
            
            $("myMapPlaydates").innerHTML = str;     
        }


function getMyMapPhotos(memberID)
{
    $("myMapPhotos").innerHTML = ""  //clean photos div
    
    if (memberID == myUser.memberID) // user is looking at his own profile
    {        
       if ((myUser.photoCount != null) && (myUser.photoCount != 0))  //0 is in case a user adds, then deletes photos
       {
            $("myMapPhotosMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
            PageMethods.getMyMapPhotosInfo(myUser.memberID, onMyMapPhotosResult, onMemberError);   
       }
       else
       {    
            $("myMapPhotos").innerHTML = ""
            $("myMapPhotosMenu").innerHTML = "You do not have any photo.";
       }
    }
    else  //user is looking at someone else's profile and we don't know if that other user has any photos yet
    {
        $("myMapPhotosMenu").innerHTML = "<div class='loadingDiv'><img class='loadingImg' src='icons/progress_loading.gif'/>Loading...</div>"  
        PageMethods.getMyMapPhotosInfo(memberID, onMyMapPhotosResult, onMemberError);     
    } 
}

        function onMyMapPhotosResult(resultTable)              //resultTable columns are: membeID, mapID, title, primaryPic, CG, CGdesc, picID, photoName, photoDesc
        {
            if (resultTable.rows)
            {
                addMyMapMenu(resultTable.rows[0].memberID, "myMapPhotosMenu", "Photos");
                str = "";
                //not used: PDphotoCount = 0  //this is the number of playdate photos we hide from viewers and which we need to deduct from total number of photos showing in the photo tab
                for (i=0; i<resultTable.rows.length; i++)
                {
                    //do not show photo if it's a playdate and not your own
                  if ((resultTable.rows[i].CG == "PD") && (resultTable.rows[i].memberID != myUser.memberID)) {/*PDphotoCount += 1;*/} else { 
                    str += "<div id='divPhotos"+resultTable.rows[i].CG+resultTable.rows[i].picID+"'>"
                    str += "Photo I added for <span class='rvwTitle'>"+resultTable.rows[i].title+"</span>:<br/>"// ("+resultTable.rows[i].CGdesc+")<br/>"
                    str += "<input type='checkbox' name='CBPhotos' class='"+resultTable.rows[i].primaryPic+"' "   //I'm using the class attribute to store the primary pic (minus first letter "p") so I can later compare it to the picture the user deletes and see if the primary pic needs to be deleted too
                    str += "onclick='activatePhotoDescription(this.parentNode.getElementsByTagName(\"input\")[1]);'";  //on click we show the photo description in an edit box, so I'm passing the second input node under the div parent
                    str += "id='photo"+resultTable.rows[i].CG+resultTable.rows[i].picID+"' value='"+resultTable.rows[i].CG+resultTable.rows[i].mapID+"'/>";  //I'm using the value attribute to store the mapID based id (instead of the picID based id), ie "PG7" where seven is the mapID, this will be used later for showing the item on the map
                    str += "<a href='javascript:getSlideShow(\""+resultTable.rows[i].CG+"\","+resultTable.rows[i].mapID+",\""+resultTable.rows[i].photoName+"\");'>"
                    str += "<img id='img"+resultTable.rows[i].CG+resultTable.rows[i].picID+"' src='"+photoFolder+"/"+resultTable.rows[i].CG+"/t"+resultTable.rows[i].photoName+"' style='vertical-align:middle;border:0px;'/></a>"
                    str += "<input type='text' class='myMapPhotoDesc' id='photoDesc"+resultTable.rows[i].CG+resultTable.rows[i].picID+"' value='"+resultTable.rows[i].photoDesc+"' "
                    str += "name='"+resultTable.rows[i].photoDesc+"' readOnly=true/>"   //using the name attribute to also store original photo description so it can be compared to user's edit
                    str += "</div>";
                  }
                }        
                $("myMapPhotos").innerHTML = str;   
                /*  below is not correct, this decreases the photo number everytime the tab is clicked
                // if playdates photos were not shown we need to deduct them from total number of photo so the photo tab title matches the photo tab content
                if (PDphotoCount > 0)
                {
                    photoTabTitle = $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[4].firstChild.nodeValue  //ie "Photos (13)"
                    photoTabTitle = photoTabTitle.slice(photoTabTitle.lastIndexOf("(")+1)
                    photoNumber  = photoTabTitle.slice(0,photoTabTitle.lastIndexOf(")"))
                    newPhotoNumber = photoNumber - PDphotoCount
                    $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[4].firstChild.nodeValue = "Photos ("+newPhotoNumber+")"
                } */
            }
            else { $("myMapPhotosMenu").innerHTML = "No photo yet.";}         
        }
      
function addMyMapMenu(memberID, divID, itemType)
{    
    var str = ""
    
    if (memberID == myUser.memberID) //only add these menu items if it's the user viewing her own profile
    {
        if (itemType == "Reviews")
        {
            str += "<span class='tabberMenu'><a class='link' href='javascript:mapMyMapItems(\""+itemType+"\")'>show on map</a></span>";   
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:editReview(\""+itemType+"\")'>edit</a></span>"        
        }
        if ((itemType == "Posts") || (itemType == "Playdates"))
        {     
            str += "<span class='tabberMenu'><a class='link' href='javascript:viewPrayerChain(\""+itemType+"\")'>view prayer chain</a></span>"; 
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:myMapSTFriend(\""+itemType+"\")'>send to friend</a></span>";    
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:editPost(\""+itemType+"\")'>update</a></span>"        
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:addMyMapPhoto()'>add photo</a></span>"   
        }    
        if (itemType == "Photos")
        {
            str += "<span class='tabberMenu'><a class='link' href='javascript:mapMyMapItems(\""+itemType+"\")'>show on map</a></span>";   
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:setAsPrimary(\""+itemType+"\")'>set as primary</a></span>"
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:changePhotoDescription()'>change description</a></span>"        
        }    
        
        str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:confirmDelete(\""+itemType+"\")'>delete</a></span>"
    }
    else   //viewing other members
    {
        if (itemType == "Posts")
        {
            str += "<span class='tabberMenu'><a class='link' href='javascript:viewPrayerChain(\""+itemType+"\")'>view prayer chain</a></span>";  
            str += "&nbsp&nbsp|&nbsp&nbsp<span class='tabberMenu'><a class='link' href='javascript:myMapSTFriend(\""+itemType+"\")'>send to friend</a></span>";    
        }
        else
        {
            str += "<span class='tabberMenu'><a class='link' href='javascript:mapMyMapItems(\""+itemType+"\")'>show on map</a></span>";   
        } 
    }

    $(divID).innerHTML = str;   
}

function mapMyMapItems(itemType)
{
    var cbName = "CB" + itemType            //ie CBFavorites, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    map.Clear();
    clearMbrPane()
    
    if (arr.length != 0)
    {
        if ((itemType == "Photos") || (itemType == "Reviews"))    //converting the picID/cmtID ids into mapID ids
        {
            for (i=0; i<arr.length; i++)
            {
                arr[i] = $(arr[i]).value
            }
        }
        var arr2D = new Array();       
        arr2D =  transform2D(arr);                        // transform arr into a two dimensional array, ex (PG3,PG7,EV5) -> (PG,3,7),(EV,5)
        PageMethods.getMapItems(arr2D, onMapItemsResult, onMapItemsError); 

    }
    else
    {
        msgBox("Oops!", "Please select one or more item.", 300)
    }
}

    function onMapItemsResult(resultTable)
    {
        var CGmapID;
        var pins = new Array();       
        //Spread items with same lat and lon so they can be visible on the map
        spreadPins(resultTable.rows)
                                             // array to be passed to the map.SetMapView() method so all pins are shown
        for (i=0; i < resultTable.rows.length; i++)
        {       
            CGmapID = resultTable.rows[i].CG + resultTable.rows[i].mapID;        //ie PG203, contains a concatenation of the table category group and the mapID
            addPin(CGmapID, resultTable.rows[i].lat, resultTable.rows[i].lon, null)
            
            var pin = new VELatLong(resultTable.rows[i].lat, resultTable.rows[i].lon);
            pins.push(pin);
        }  
        
        if (pins.length == 1)   //with one item, user experience is not good when zooming in too close to we zoom back out
        {
            map.SetMapView(pins)
            map.SetZoomLevel(11);  
        }
        else
        {
            map.SetMapView(pins);
            map.ZoomOut();         // increases centering of pins
        }
    }

    function onMapItemsError()
    {
         msgBox("Oops!", "Could not map selected items.", 300)  
    }

    function transform2D(arr)                       // transform arr into a two dimensional array, ex (PG3,PG7,EV5) -> (PG,3,7),(EV,5)
    {
       var arr2D = new Array();
 
       for (i=0; i<arr.length; i++)
       {
            var CGexist = false;                         //whether or not CG already exist in arr2D            
            CG = arr[i].slice(0,2);
            
            for (j=0; j<arr2D.length; j++)                    // check if CG has already been added to arr2D
            {
                if (arr2D[j][0] == CG)
                {
                    CGexist = true
                }
            }
            
            if (CGexist == false)                    // populate arr2D line with mapID items 
            {
                var a = new Array();
                a.push(CG);
                mapID = arr[i].slice(2);
                a.push(mapID);
                for (j=(i+1);j<arr.length; j++)
                {
                    if (arr[j].slice(0,2) == CG )
                    {
                        mapID = arr[j].slice(2);
                        a.push(mapID);
                    }
                }
                arr2D.push(a);
            }   
       } 
       
       return arr2D;
    }
    
function confirmDelete(itemType)
{
    var cbName = "CB" + itemType            //ie CBFavorites, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    //map.Clear();
    
    if (arr.length != 0)
    {
        msgBox("Please confirm", "Are you sure you want to delete the items selected?<br/><br/><div class='divBut'><a id='confirmDeleteYes' class='but' href='javascript:removeMyMapItems(\""+itemType+"\")'>Yes</a></div>", 300) //Cancel button removed: <a id='confirmDeleteCancel' class='but' href='javascript:closeMsgBox();'>Cancel</a>
        if (document.all)  {  // round buttons for IE only (Firefox forces a left float on the anchor which makes the buttons uncentered. Attenpts to center on Firefox didn't work          
            Nifty("a#confirmDeleteYes", "transparent")   //round the yes and cancel buttons since they're added at run time
            //Nifty("a#confirmDeleteCancel", "transparent")
        }
    }
    else
    {
        msgBox("Oops!", "Please select one or more item.", 300)
    }
}


function removeMyMapItems(itemType)
{
    var cbName = "CB" + itemType            //ie CBFavorites, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    var arr2D = new Array();
    
    switch(itemType)
    {
        case "Favorites":   
            arr2D =  transform2D(arr);                        // transform arr into a two dimensional array, ex (PG3,PG7,EV5) -> (PG,3,7),(EV,5)
            disableBut("confirmDeleteYes", "Deleting...")
            PageMethods.removeFavorites(myUser.memberID, arr2D, onRemoveFavoritesResult, onRemoveItemsError);   
            break
        case "Reviews":
            arr2D =  transform2D(arr);        
            var arrMapID = new Array()              //stores the mapIDs of the selected reviews (ex:PG207)
            var arrRating = new Array()             //stores the CG + rating values (ex: PG3)
            var arr2DmapID = new Array();           
            var arr2Drating  = new Array();           
            for (i=0;i<arr.length;i++)
            {
                arrMapID.push($(arr[i]).value)
                arrRating.push($(arr[i]+"rating").value)
            }
            arr2DmapID = transform2D(arrMapID)
            arr2Drating = transform2D(arrRating)  
            disableBut("confirmDeleteYes", "Deleting...")              
            PageMethods.removeReviews(myUser.memberID, arr2D, arr2DmapID, arr2Drating, onRemoveReviewsResult, onRemoveItemsError);   
            break    
        case "Posts":   
            arr2D =  transform2D(arr);   
            disableBut("confirmDeleteYes", "Deleting...")                   
            PageMethods.removePosts(myUser.memberID, arr2D, onRemovePostsResult, onRemoveItemsError);   
            break   
        case "Playdates":   
            arr2D =  transform2D(arr);      
            disableBut("confirmDeleteYes", "Deleting...")                   
            PageMethods.removePosts(myUser.memberID, arr2D, onRemovePlaydatesResult, onRemoveItemsError);   
            break   
        case "Photos": 
            var updatePrimary = new Array();  // an array of mapIDs for which to update the primaryPic
            var updatePrimPic2D = new Array();
            var deletedPhotos = new Array();
            var delPhotos2D = new Array();
            for (i=0;i<arr.length;i++)   //this transform the array from mapID ids into picID ids
            {
                //var arr1 = new Array(); //I'm extracting the file names from the paths to compare them
                var arr2 = new Array();
                //arr1 = $(arr[i]).className.slice(1) //$(arr[i]).className.split("/")
                arr2 = $("img"+(arr[i].slice(5))).src.split("/")
                primaryName = $(arr[i]).className.slice(1) //arr1[arr1.length - 1]
                picName = arr2[arr2.length - 1].slice(1)    //removing "t" for thumbnail to get picture name                 
                if ( picName == primaryName)  // if the deleted photo is also a primaryPic;
                {
                    updatePrimary.push($(arr[i]).value);
                }               
                deletedPhotos.push(arr[i].slice(5,7)+picName);  // populate arrays of photos names for physical deletion on server     slice(5,7) returns PG from "photoPG123"
            }  
            for (i=0;i<arr.length;i++){arr[i] = arr[i].slice(5)} //remove "photo" prefix from the id
            arr2D =  transform2D(arr);  
            updatePrimPic2D = transform2D(updatePrimary);  
            delPhotos2D = transform2D(deletedPhotos);    
            disableBut("confirmDeleteYes", "Deleting...")                             
            PageMethods.removePhotos(myUser.memberID, arr2D, updatePrimPic2D, delPhotos2D, onRemovePhotosResult, onRemoveItemsError);   
            break   
        case "ProfileManage": 
            arr = getCheckBoxes("CBProfileManage", "manageprofile") //returns array of picIDs that have been selected
            delPrimary = false;  //boolean that tells whether to delete and replace the primary
            oldPrimaryPic = "";
            for (i=0;i<arr.length;i++)   //this transform the array from mapID ids into picID ids
            {
                var arr2 = new Array();
                //arr1 = $("manageprofile"+arr[i]).className.split("/")
                arr2 = $("manageprofile"+arr[i]).parentNode.getElementsByTagName("img")[0].src.split("/")
                primaryName = $("manageprofile"+arr[i]).className.slice(1)
                picName = arr2[arr2.length - 1].slice(1)            //removing the "t" in front of the thumbnail file           
                
                
                if (picName == primaryName)  // if the deleted photo is also a primaryPic;
                {
                    delPrimary = true;
                    oldPrimaryPic = "p" + picName  //adding p to make the primary name
                }               
            }                            
            //PageMethods.removePhotos(myUser.memberID, arr2D, updatePrimPic2D, delPhotos2D, onRemovePhotosResult, onRemoveItemsError);   
            disableBut("confirmDeleteYes", "Deleting...")   
            PageMethods.removeProfilePhotos(myUser.memberID, arr, delPrimary, oldPrimaryPic, onRemoveProfilePhotosResult, onRemoveItemsError);   
            break   
            
        default:
            msgBox("Oops!", "Sorry, this feature (Delete "+itemType+") is not implemented yet.", 300)

    }  
}


    function onRemoveFavoritesResult()
    {
         map.Clear();
         clearMbrPane()    
         var arr = getCheckBoxes("CBFavorites", "")                 // this returns an array of ids.                       
         myUser.favoriteCount = myUser.favoriteCount - arr.length;  // update user's favorite count
         //$("myMapFavoritesDiv").title = "Favorites ("+myUser.favoriteCount+")"   
         
         $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[0].firstChild.nodeValue = "Bookmarks"// ("+myUser.favoriteCount+")"  //Update the tab title with new favoriteCount (note that 0 is the index of the Favorites tab in the returned array of <a> tags
         
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $("divFavorites"+arr[i]).style.display = "none";
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "remove".               
         }
         
         if (myUser.favoriteCount == 0)
         {
            $("myMapFavoritesMenu").innerHTML = "<br/>You do not have any bookmark.<br/>";
         }
         enableBut("confirmDeleteYes")
         msgBox("Thank you", "Items have been deleted.", 300)  
    }
    
    
    function onRemoveReviewsResult()
    {
         map.Clear();          
         clearMbrPane()
         var arr = getCheckBoxes("CBReviews", "")                 // this returns an array of ids.                       
         myUser.reviewCount = myUser.reviewCount - arr.length;  // update user's favorite count
         //$("myMapFavoritesDiv").title = "Favorites ("+myUser.favoriteCount+")"   
         
         $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[1].firstChild.nodeValue = "Prayer Responses"// ("+myUser.reviewCount+")"  //Update the tab title with new favoriteCount (note that 1 is the index of the Reviews tab in the returned array of <a> tags
         
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $("divReviews"+arr[i]).style.display = "none";
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "remove".               
         }
         
         if (myUser.reviewCount == 0)
         {
            $("myMapReviewsMenu").innerHTML = "<br/>You do not have any prayer response.<br/>";
         }
         enableBut("confirmDeleteYes")
         msgBox("Thank you", "Items have been deleted.", 300)  
         
        //also need to clear the infobox so it requeries the server and show the prayer response updated with the deletion

    }


    function onRemovePhotosResult(table)
    {
         map.Clear();  
         clearMbrPane()  
         var arr = getCheckBoxes("CBPhotos", "")                 // this returns an array of ids.                       
         myUser.photoCount = myUser.photoCount - arr.length;  // update user's favorite count
         //$("myMapFavoritesDiv").title = "Favorites ("+myUser.favoriteCount+")"   
         
         $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[2].firstChild.nodeValue = "Photos"// ("+myUser.photoCount+")"  //Update the tab title with new photoCount (note that 3 is the index of the Photos tab in the returned array of <a> tags
         
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $("divPhotos"+arr[i].slice(5)).style.display = "none";
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "remove".               
         }
         
         if (myUser.photoCount == 0)
         {
            $("myMapPhotosMenu").innerHTML = "<br/>You do not have any photos.<br/>";
         }
         
         //update remaining photos with new primaryPics if any
         try {
             var photoArr = new Array();
             photoArr = document.getElementsByName("CBPhotos");
             for (i=0;i<photoArr.length;i++)
             {
                for (j=0;j<table.rows.length;j++)
                {
                    if (photoArr[i].value == (table.rows[j].CG + table.rows[j].mapID))
                    {                
                        photoArr[i].className = table.rows[j].primaryPic
                    }
                }
             }
         }
         catch(err){}
         
         enableBut("confirmDeleteYes")
         msgBox("Thank you", "Items have been deleted.", 300, 100)  
    
    }

    function onRemoveProfilePhotosResult(primaryPath)
    {
         var arr = getCheckBoxes("CBProfileManage", "manage")                 // this returns an array of ids of the check boxes from the CBProfile group, 
                                                                     //however I need to hide the items from the CBProfile group                              
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $(arr[i]).parentNode.style.display = "none"; 
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "remove".               
         }
                           
            //update primary pic in mymap main photo area
        if (primaryPath != "")  //if primaryPath is empty, then the primaryPic was not deleted and does not need to be replaced
        {            
            $("myMapPhoto").getElementsByTagName("img")[0].src = primaryPath
            //update className of all pics since the primary changed
            primaryPic = primaryPath.slice(primaryPath.lastIndexOf("/")+1)
            //primaryComp = photoFolder+"/"+mbrFolder+"/t"+primaryComp.slice(1)
            arr = document.getElementsByName("CBProfile")
            for (i=0;i<arr.length;i++)
            {
                arr[i].className = primaryPic
            }
         }
         if (primaryPath == (photoFolder + "/" + mbrDefaultPhoto))
         {
            $("managePhotoA").style.display = "none";
            addDefaultPhotoInfo();          //reset default photo element (ie default photo, link, thumbnail div hidden...
         }
        
        enableBut("confirmDeleteYes") 
        clearManagePhotos()
        msgBox("Thank you", "Photo(s) has been deleted.", 300)
    
    }


    function onRemovePostsResult()
    {
         map.Clear();  
         clearMbrPane()  
         var arr = getCheckBoxes("CBPosts", "")                 // this returns an array of ids.                       
         myUser.postCount = myUser.postCount - arr.length;  // update user's post count
         
         $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[0].firstChild.nodeValue = "Prayer Requests"// ("+myUser.postCount+")"  //Update the tab title with new postCount (note that 2 is the index of the Posts tab in the returned array of <a> tags
         
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $("divPosts"+arr[i]).style.display = "none";
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "delete".               
         }
         
         if (myUser.postCount == 0)
         {
            $("myMapPostsMenu").innerHTML = "<br/>You do not have any prayer request.<br/>";
         }
         
         enableBut("confirmDeleteYes")
         msgBox("Thank you", "Items have been deleted.", 300)  
    }

    function onRemovePlaydatesResult()
    {
         map.Clear(); 
         clearMbrPane()   
         var arr = getCheckBoxes("CBPlaydates", "")                 // this returns an array of ids.                       
         myUser.playdateCount = myUser.playdateCount - arr.length;  // update user's post count
         
         $("tabberDiv").getElementsByTagName("ul")[0].getElementsByTagName("a")[3].firstChild.nodeValue = "Playdates"// ("+myUser.playdateCount+")"  //Update the tab title with new postCount (note that 2 is the index of the Posts tab in the returned array of <a> tags
         
         for (i=0; i<arr.length; i++)                               //remove items from UI as well
         {
            $("divPlaydates"+arr[i]).style.display = "none";
            $(arr[i]).checked = false;                      //so we don't pick up these check boxes again in subsequent user actions, ie "show on map" or "delete".               
         }
         
         if (myUser.playdateCount == 0)
         {
            $("myMapPlaydatesMenu").innerHTML = "<br/>You do not have any playdates.<br/>";
         }
         
         enableBut("confirmDeleteYes")
         msgBox("Thank you", "Items have been deleted.", 300)  
    }

    function onRemoveItemsError()
    {
         msgBox("Oops!", "Could not delete selected items.", 300)  
    }


function editReview(itemType)
{
    var cbName = "CB" + itemType            //ie CBReviews, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    switch(arr.length)  //processes only one item at a time
    {
        case 0:   
            msgBox("Oops!", "Please select one or more item.", 300)
            break
        case 1: 
            var CG = arr[0].slice(0,2);
            var cmtID = arr[0].slice(2);
            var mapID = $(arr[0]).value.slice(2);
            PageMethods.loadReview(myUser.memberID, CG, mapID, cmtID, onLoadReviewResult, onLoadReviewError) //the callback onLoadReviewResult() is in review.js
            break   
        default:
            msgBox("Oops!", "Please select only one item at a time.", 300)
    }  

}
/*
    function onLoadReviewResult(resultTable)  //returna datatable including: CG, mapID, cmtID, cmtTitle, cmtDescription, cmtRating
    {
        //fill comment fields that are temporarily used to store cmt title, description and rating 

        cmtRef.CG = resultTable.rows[0].CG;        
        cmtRef.id = resultTable.rows[0].cmtID;
        cmtRef.mapID = resultTable.rows[0].mapID;
        
        cmtRef.rating = resultTable.rows[0].cmtRating;     
        rater.Value = resultTable.rows[0].cmtRating ;
        CastleRater.Refresh(rater, "rater")   //set rater value

           
        cmtRef.title = resultTable.rows[0].cmtTitle;
        $("reviewPaneTitle").value = resultTable.rows[0].cmtTitle;
        
        if (resultTable.rows[0].cmtDescription != null)   // if database returns null, convert to empty string so "null" doesn't show in the UI
        {       
            cmtRef.description = resultTable.rows[0].cmtDescription;
            $("reviewPaneDesc").value = resultTable.rows[0].cmtDescription;   
        }
        else
        {
            cmtRef.description = "";            
            $("reviewPaneDesc").value = "";          
        }
        
        //change the submit functionality from new to edit mode
        $("reviewSubmitBut").href = "javascript:submitEditReview();";
        //$("reviewSubmitBut").onclick = function(){submitEditReview();}; 
            
        $("reviewPane").style.display = "block";
        
               
    }
  
    function onLoadReviewError()
    {
        msgBox("Oops!", "Could not load review.", 300, 100)  
    }
    
*/

function viewPrayerChain(itemType)
{
    var cbName = "CB" + itemType            //ie CBPosts, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    switch(arr.length)  //processes only one item at a time
    {
        case 0:   
            msgBox("Oops!", "Please select an item.", 300)
            break
        case 1: 
            //var CG = arr[0].slice(0,2);
            var mapID = arr[0].slice(2);
            getPrayerChain(mapID)
            break   
        default:
            msgBox("Oops!", "Please select only one item at a time.", 300)
    }  
}

function myMapSTFriend(itemType)
{
    var cbName = "CB" + itemType            //ie CBPosts, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    switch(arr.length)  //processes only one item at a time
    {
        case 0:   
            msgBox("Oops!", "Please select an item.", 300)
            break
        case 1: 
            var CG = arr[0].slice(0,2);
            var mapID = arr[0].slice(2);
            prayerTitle = $("divPosts"+CG+mapID).getElementsByTagName("span")[0].firstChild.nodeValue
            pickFriends(CG, mapID, prayerTitle)
            break   
        default:
            msgBox("Oops!", "Please select only one item at a time.", 300)
    }  

}

function addMyMapPhoto()
{
    var arr = getCheckBoxes("CBPosts", "")     // "" means there's no need to clip any prefix from the ids returned
    
    switch(arr.length)  //processes only one item at a time
    {
        case 0:   
            msgBox("Oops!", "Please select an item.", 300)
            break
        case 1: 
            var CG = arr[0].slice(0,2);
            var mapID = arr[0].slice(2);
            var tn = 0   //if thumbail exists tn=1 else tn=0 (by default)
            var thumb = $(CG+mapID).value
            if ((thumb != "undefined") && (thumb != "null") && (thumb != "")){tn = 1}
            showBox("Add photo", 330, 250, "photoUpload.aspx?id="+mapID+"&catG="+CG+"&tn="+tn+"&m="+myUser.memberID+"")
            break   
        default:
            msgBox("Oops!", "Please select only one item at a time.", 300)
    }  
}



function editPost(itemType)
{
    //if not App.post then download Post feature
    
      if (App.post == false)
      {
        //loadPostPanel();   
        App.post = true;              
        fillPostCat()
      }
      if (App.playdate == false)
      {
          App.playdate = true;              
          fillPostPDCat()
      }
    
    var cbName = "CB" + itemType            //ie CBPosts, this is so we can parse all checkboxes of that name
    var arr = getCheckBoxes(cbName, "")     // "" means there's no need to clip any prefix from the ids returned
    
    switch(arr.length)  //processes only one item at a time
    {
        case 0:   
            msgBox("Oops!", "Please select one or more item.", 300, 100)
            break
        case 1: 
            var CG = arr[0].slice(0,2);
            var mapID = arr[0].slice(2);
            PageMethods.loadPost(myUser.memberID, CG, mapID, onLoadPostResult, onLoadPostError)
            break   
        default:
            msgBox("Oops!", "Please select only one item at a time.", 300)
    }  
  
}

    function onLoadPostResult(resultDataSet)  //returna dataset including table0: post title, description, status, and details fields; table1:categories; table2: ages; table3 location, table4: dates (event case), table5:friends (playdate case), table6:invitees (playdate case)
    {
        //fill postRef object
        var postTbl = resultDataSet.tables[0];
        var catTbl = resultDataSet.tables[1];
        var ageTbl = resultDataSet.tables[2];
        var locTbl = resultDataSet.tables[3];
        
        var CG = getCG(postTbl);
        var mapID = getMapID(postTbl, 0);

        postRef.catGroup = CG;
        postRef.mapID = mapID;
        
        postRef.ratingTotal = postTbl.rows[0].ratingTotal; //only used to recreate the prayer item in the prayer list (move it to the top) once the post has been updated
        
        postRef.title = postTbl.rows[0].title;
        $("postTitle").value = dec(postTbl.rows[0].title);
        
        postRef.description = postTbl.rows[0].description;
        $("postDescription").value = decTxtUpdate(dec(postTbl.rows[0].description));   //I decode existing updates ie "!xyz1tk!" into "--- UPDATE ("
        
        if (postTbl.rows[0].status == 1) 
        { 
            $("postPrayerAnswerCB").checked = true;
        } 
        postRef.status = postTbl.rows[0].status
        
        $("postNotifyMeCB").checked = postTbl.rows[0].notifyMe;
        postRef.notifyMe = postTbl.rows[0].notifyMe
           
        if (postTbl.rows[0].age != null)   // if database returns null, convert to empty string so "null" doesn't show in the UI
        {
            postRef.ageStr = postTbl.rows[0].age;            
            setAgeRange(postTbl.rows[0].age)   //$("postAgeStr").value = postTbl.rows[0].age       
        }
        else
        {
            postRef.ageStr = "";            
            setAgeRange("");  //$("postAgeStr").value = "";          
        }

        if (postTbl.rows[0].time != null)
        {
            postRef.time = postTbl.rows[0].time;            
            $("postTime").value = dec(postTbl.rows[0].time)
        }
        else
        {
            postRef.time = ""           
            $("postTime").value = ""
        }
        

        if (postTbl.rows[0].cost != null)
        {
            postRef.cost = postTbl.rows[0].cost;        
            $("postCost").value = dec(postTbl.rows[0].cost)
        }
        else
        {
            postRef.cost = ""       
            $("postCost").value = ""      
        }
        

        if (postTbl.rows[0].phone != null)
        {
            postRef.phone = postTbl.rows[0].phone;        
            $("postPhone").value = dec(postTbl.rows[0].phone)
        }
        else
        {
            postRef.phone = ""      
            $("postPhone").value = ""
        }
        

        if (postTbl.rows[0].web != null)
        {
            postRef.web = postTbl.rows[0].web;        
            $("postWeb").value = dec(postTbl.rows[0].web)
        }
        else
        {
            postRef.web = ""     
            $("postWeb").value = ""
        }
    
        postRef.cat = new Array();
        for (i=0; i<catTbl.rows.length; i++)
        {
            postRef.cat.push(catTbl.rows[i].catID);
            $("post"+catTbl.rows[i].catID).checked = true;
        }
  /*      
        postRef.ages = new Array();
        for (i=0; i<ageTbl.rows.length; i++)
        {
            postRef.ages.push(ageTbl.rows[i].ageID);
            $("cbAge"+ageTbl.rows[i].ageID).checked = true;
        }
   */
        // filling the two hidden location labels in Wizpage1 for the Preview feature  
        $("postLat").value = myUser.lat  //locTbl.rows[0].lat;
        $("postLon").value = myUser.lon  //locTbl.rows[0].lon;  
        
        
        if ((CG == "EV") || (CG == "PD"))   //Event or Playdate case
        {
            var dateTbl = resultDataSet.tables[4];  //this is either a table of exact dates (1 column) or of range (3 columns).
            postRef.dates = new Array();            //initialize dates as an array
            
            if (dateTbl.columns.length > 1)  //case of date range
            {
                postRef.dateMin = dateTbl.rows[0].dateMin
                $("dateInputPost2").value = dateTbl.rows[0].dateMin.format("M/d/yy");
                postRef.dateMax = dateTbl.rows[0].dateMax
                $("dateInputPost3").value = dateTbl.rows[0].dateMax.format("M/d/yy");
                
                postRef.days = dateTbl.rows[0].days
                var arr = dateTbl.rows[0].days.split(",")
                for (i=0;i<arr.length;i++)
                {
                    $("cbDay"+arr[i]).checked = true;
                }   
            }
            else    //case of exact dates
            {
                $("postDates").value = ""   //clears the default boiler text and grey color
                $("postDates").style.color = "black"
                for (i=0;i<dateTbl.rows.length;i++)
                {
                    postRef.dates.push(dateTbl.rows[i].date)
                    $("postDates").value += dateTbl.rows[i].date.format("M/d/yy")
                    if (i < (dateTbl.rows.length - 1))
                    {
                        $("postDates").value += ", "    //important since we parse this out on submit
                    }
                }
                // Set postRef range date to 'null' values so they can be compared during user post edit
                postRef.dateMin = new Date(); //returns today's date and time
                postRef.dateMin.setFullYear("1900")  
                postRef.dateMax = new Date(); //returns today's date and time
                postRef.dateMax.setFullYear("1900")   
            }
                    
            //show the date UI
        
        }
        
        if (CG == "PD")   // Playdate case
        {
            enablePlaydateWiz()
            enablePlaydateEdit()  //wiz changes specific to edit mode
            var friendTbl = resultDataSet.tables[5]   //contains, memberID, email, display and primaryPic
            var inviteeTbl = resultDataSet.tables[6]  
            

            // add friends
            if (friendTbl.rows)
            {
                $("postFriendsDiv").innerHTML = "";   //clear "Loading..." text          
                for (i=0;i<friendTbl.rows.length;i++)
                {
                    createFriend($("postFriendsDiv"), friendTbl.rows[i].memberID, friendTbl.rows[i].email, friendTbl.rows[i].display, friendTbl.rows[i].primaryPic, "postFriendsCB", "cbFriend")  //append new Friend
                }
            }
            else
            {
                 $("postFriendsDiv").innerHTML = "You have not invited friends to a playdate yet."
            }
            
              //there are 3 type of friends that need different handling          
            if (inviteeTbl.rows)
            {
                postRef.friendsID = new Array();
                postRef.friendsEmail = new Array();
                
                for (i=0;i<inviteeTbl.rows.length;i++)
                {
                    if (inviteeTbl.rows[i].memberID == myUser.memberID) {} //do nothing
                    else  {
                        // check friends who have been invited to this playdate
                        friendFound = false;
                        arr = document.getElementsByName("postFriendsCB")
                        for (j=0;j<arr.length;j++)
                        {
                            if (arr[j].id == "cbFriend"+inviteeTbl.rows[i].memberID)
                            {
                                arr[j].checked = true;
                                arr[j].disabled = true;
                                friendFound = true;
                            }
                        }               
                        if (!friendFound)  //case of indirect invitee where the user replied but is not on the original list of friends, we add the friend to the playdate list (we do not add it to the member friends' list though)
                        {
                            createFriend($("postFriendsDiv"), inviteeTbl.rows[i].memberID, inviteeTbl.rows[i].email, inviteeTbl.rows[i].display, inviteeTbl.rows[i].primaryPic, "postFriendsCB", "cbFriend")  //append new Friend
                            $("cbFriend"+inviteeTbl.rows[i].memberID).checked = true;
                            $("cbFriend"+inviteeTbl.rows[i].memberID).disabled = true;
                        }
                        postRef.friendsID.push(inviteeTbl.rows[i].memberID)
                        postRef.friendsEmail.push(inviteeTbl.rows[i].email)
                    }
                }  
            }
            else {}              
        }
        
        //set catGroup and categories
        var CGid = convertToCGid(CG)         
        showPostCat(CGid);     
        $("postCG"+CGid).checked = true;  //setting category group
        
        /*
        for (i=0; i<$("postList").options.length; i++)
        {
            if ($("postList").options[i].value == CGid)
            {
                $("postList").selectedIndex = i;
                showPostCat();
            }
        } */
             
        //Disable catgroup editing
        //$("postList").disabled = "disabled";
        //Hide WizPage2 back button
        //$("postWiz2BackBut").style.display = "none";
        //Show Wizard and hide myMap
        $("myMapPane").style.display = "none";
        $("postPane").style.display = "block";
        $("postWiz0").style.display = "none";
        $("postWiz1").style.display = "none";
        $("postWiz2").style.display = "block";   
        
        //show the prayer update fields
        $("postPrayerUpdateLabel").style.display = "block"; 
        $("postPrayerUpdateText").style.display = "block"; 
        $("postPrayerAnswer").style.display = "block"; 
        //show "show categories link" and hide categories block
        $("showCategoriesLink").style.display = "block"; 
        $("postCatLabel").style.display = "none"; 
        $("postCheckCat").style.display = "none"; 
        //show "show more details link" and hide details block
        $("showPostMoreDetails").style.display = "block"; 
        $("postMoreDetails").style.display = "none"; 
        
        //Change submit functionality from postNew() to postEdit()
        $("postSubmitBut").href = "javascript:postEdit();";
        //$("postSubmitBut").onclick = function(){postEdit();};   //the onclick button does not take just a string "postEdit();" but instead a function reference 
        $("postCloseBut").href = "javascript:cancelEditPost();";   
        //$("postCancelBut1").onclick = function(){cancelEditPost();};    
        //$("postCancelBut2").onclick = function(){cancelEditPost();}; 
        //$("postCancelBut3").onclick = function(){cancelEditPost();}; 
        //$("postCancelBut4").onclick = function(){cancelEditPost();}; 
        if (CG == "PD")
        {
            deactivateNavButtons()
            //$("playdateNavBut").className = "activelink";
        }
        else
        {
            deactivateNavButtons()
            $("postNavBut").className = "activelink";
        }      
    }
    
    
    function onLoadPostError()
    {
        msgBox("Oops!", "Could not load post.", 300)  
    }
    

function managePhotos()
{
 
    str = $("myMapThumbnails").innerHTML    
    //replace check box names so when don't grab duplicates "CBProfile" --> "CBProfileManage"
    str = str.replace(/CBProfile/g,"CBProfileManage")        
    content = str  
    // add photo description box 
    content += "<div id='managePhotoDescription' class='postText'>Photo description:<br/><input id='mPD' type='text'/></div>"
    // add menu    
    content += "<div id='photoManageMenu'><a class='link' href='javascript:changeProfilePhotoDescription()'>change description</a>&nbsp&nbsp|&nbsp&nbsp<a class='link' href='javascript:setAsPrimary(\"ProfileManage\");'>set as primary</a>&nbsp&nbsp|&nbsp&nbsp<a class='link' href='javascript:confirmDelete(\"ProfileManage\")'>delete</a></div>"

    $("managePhotoContent").innerHTML = content
    //make check boxes visible    
    arr = document.getElementsByName("CBProfileManage")
    //adding functionality so description box gets updated when check box is clicked
    for (i=0;i<arr.length;i++)
    {
        arr[i].id = "manage"+arr[i].id         //changing managed cb ids so there's no conflicts with original cb ids
        arr[i].style.display = "inline";
        arr[i].onclick = function(){if(this.checked){$("mPD").value = dec(this.value);}else{$("mPD").value = ""}}  //updating description field when check box is clicked
    }
    
    $("managePhotoPane").style.display = "block";

}

function changePhotoDescription()
{

    var arr = getCheckBoxes("CBPhotos", "photo")
    if (arr.length == 0) {msgBox("Oops!", "Please select a photo by clicking on the check box on its left.", 300);return}  
    if (arr.length > 1) {msgBox("Oops!", "Please select only one photo at a time", 300);return}      
    
    CGpicID = arr[0]
    picID = arr[0].slice(2)
    CG = arr[0].slice(0,2)

    //check validity of photo description input field
    
    PageMethods.updatePhotoDescription(CG, picID, $("photoDesc"+CGpicID).value.trims(), onupdatePhotoDescriptionResult, onupdatePhotoDescriptionError)

}

        function onupdatePhotoDescriptionResult()
        {
            var arr = getCheckBoxes("CBPhotos", "photo")
            CGpicID = arr[0]
            $("photo"+CGpicID).checked = false;
            $("photoDesc"+CGpicID).name = $("photoDesc"+CGpicID).value.trims()   //reset the name value to the new photo description
            $("photoDesc"+CGpicID).readOnly = true;
            $("photoDesc"+CGpicID).style.border = "1px solid white"           

            msgBox("Thank you", "The photo description has been updated.", 300)
        }

function activatePhotoDescription(inputNode)  //inputNode is the description input field node
{
        //var arr = getCheckBoxes("CBPhotos", "photo")
        //CGpicID = arr[0]
        //$("photoDesc"+CGpicID).readOnly = false;
        //$("photoDesc"+CGpicID).style.border = "blue"          
    if (inputNode.parentNode.getElementsByTagName("input")[0].checked == true)   //if check box is checked
    {
        inputNode.readOnly = false;
        inputNode.style.border = "1px solid #84a2d4"
    }
    else
    {
        inputNode.value = inputNode.name
        inputNode.readOnly = true;
        inputNode.style.border = "1px solid white"
    }      
}

function changeProfilePhotoDescription()
{

    var arr = getCheckBoxes("CBProfileManage", "manageprofile")

    if (arr.length == 0) {msgBox("Oops!", "Please select a photo by clicking on the check box on its left.", 300);return}  
    if (arr.length > 1) {msgBox("Oops!", "Please select only one photo at a time", 300);return}  

    //check validity of photo description input field
    picID = arr[0]     
    PageMethods.updatePhotoDescription(mbrFolder, picID, $("mPD").value.trims(), onupdateProfilePhotoDescriptionResult, onupdatePhotoDescriptionError)

}

        function onupdateProfilePhotoDescriptionResult()
        {
            var arr = getCheckBoxes("CBProfileManage", "manageprofile")
            picID = arr[0] 
            arr2 = document.getElementsByName("CBProfile")
            for (i=0; i<arr2.length; i++)
            {
                if (arr2[i].id == ("profile"+picID))
                {
                    arr2[i].value = $("mPD").value.trims()  //update description within check box
                    arr2[i].parentNode.getElementsByTagName("img")[0].alt = $("mPD").value.trims()   //update description within image tag                                         
                    break;
                }
            }
            clearManagePhotos()

            msgBox("Thank you", "The photo description has been updated.", 300)
        }

        function onupdatePhotoDescriptionError()
        {
            msgBox("Oops!", "Could not update photo description.", 300)
        }

function setAsPrimary(itemType)    //itemType is either "Photos" for user photos or "manageprofile" for profile photos
{
    
    var arr = getCheckBoxes("CB"+itemType, "")
    
    if (arr.length == 0) {msgBox("Oops!", "Please select a photo by clicking its check box.", 300);return}  
    if (arr.length > 1) {msgBox("Oops!", "Please select only one photo at a time", 300);return}  

    str = $(arr[0]).parentNode.getElementsByTagName("img")[0].src
    index = str.lastIndexOf("/")
    newPrimary = "p" + str.slice(index+2)    
    oldPrimary = $(arr[0]).className
    
    if (oldPrimary == newPrimary) {msgBox("Oops!", "The selected photo is already the primary photo.", 300);return}  
    
    if (itemType == "Photos")  //user photos as apposed to profile photos
    {
        ID = $(arr[0]).value.slice(2)  //mapID
        type = $(arr[0]).value.slice(0,2)  //CG
        PageMethods.updatePrimaryPic(ID, type, oldPrimary, newPrimary, onupdatePrimaryPicResult, onupdateMemberPrimaryPicError)
    }
    else
    {
        ID = myUser.memberID
        type = mbrFolder  
        PageMethods.updatePrimaryPic(ID, type, oldPrimary, newPrimary, onupdateMemberPrimaryPicResult, onupdateMemberPrimaryPicError)
    }


}
        function onupdatePrimaryPicResult(primaryPath)   //callback for the user photo primary update
        {                                                // the primary path returned is actually primaryPath + "/" + CGmapID
        
                //update className of all pics since the primary changed
            realPrimaryPath = primaryPath.slice(0, primaryPath.lastIndexOf("/"))
            primaryPic = realPrimaryPath.slice(realPrimaryPath.lastIndexOf("/")+1)           
            CGmapID = primaryPath.slice(primaryPath.lastIndexOf("/")+1)  
            
            arr = document.getElementsByName("CBPhotos")
            for (i=0;i<arr.length;i++)
            {
                if (arr[i].value == CGmapID)
                {
                    arr[i].className = primaryPic
                }    
            }
            msgBox("Thank you", "This photo has been set as the primary photo.", 300)
        }

        function onupdateMemberPrimaryPicResult(primaryPath)  //callback for profile primary update
        {
                //update primary pic in mymap main photo area
            $("myMapPhoto").getElementsByTagName("img")[0].src = primaryPath
                //update className of all pics since the primary changed
            primaryPic = primaryPath.slice(primaryPath.lastIndexOf("/")+1)
            //primaryComp = photoFolder+"/"+mbrFolder+"/t"+primaryComp.slice(1)
            arr = document.getElementsByName("CBProfile")
            for (i=0;i<arr.length;i++)
            {
                arr[i].className = primaryPic
            }
            clearManagePhotos()
            msgBox("Thank you", "This photo has been set as the primary photo.", 300)
        }

        function onupdateMemberPrimaryPicError()
        {
            msgBox("Oops!", "Could not set photo as a primary photo.", 300)
        }


function clearManagePhotos()
{
    $('managePhotoContent').innerHTML = '';
    $('managePhotoPane').style.display = 'none'
}
        
function clearMyMapPane()
{
    //clear Favorites, Reviews, Posts, Photos check boxes 

    var arr1 = new Array()
    var arr2 = new Array()
    var arr3 = new Array()
    var arr4 = new Array()
    arr1 = document.getElementsByName("CBFavorites")
    arr2 = document.getElementsByName("CBReviews")
    arr3 = document.getElementsByName("CBPosts")
    arr4 = document.getElementsByName("CBPhotos")
    for (i=0;i<arr1.length;i++){arr1[i].checked = false;}
    for (i=0;i<arr2.length;i++){arr2[i].checked = false;}
    for (i=0;i<arr3.length;i++){arr3[i].checked = false;}
    for (i=0;i<arr4.length;i++){arr4[i].checked = false;}
    
    $("myMapThumbnails").style.display = "none"; //this is so members with no pic do not see a blank space between default photo and 'add photo' link
    $("myMapPane").style.display = "none"
    //map.Clear();
    deactivateNavButtons()
    
    //remove all check boxes so they don't show up from profile viewing to another profile viewing
    //$("myMapFavorites").innerHTML = "";
    $("myMapReviews").innerHTML = "";
    $("myMapPosts").innerHTML = "";
    //$("myMapPlaydates").innerHTML = "";
    $("myMapPhotos").innerHTML = "";
}

function disableMyMap(display)
{
//change pane title
$("myMapHeaderDiv").innerHTML = display +"'s map";

//disable links
$("myMapProfileEdit").style.display = "none";
$("myMapPhotoMenu").style.display = "none";

//hide playdate posts and photos

}

function enableMyMap()  //reverses changes introduced by disableMyMap()
{
$("myMapHeaderDiv").innerHTML = "My Faithmap";
$("myMapProfileEdit").style.display = "block";
$("myMapPhotoMenu").style.display = "block";

deactivateNavButtons()
$("myMapNavBut").className = "activelink";

}


/***************************/
/* Profile pane functions  */
/***************************/


function editProfile()
{
    //fill profile pane
    $("profDisplay").value = dec(myUser.display)
    $("profAbout").value = dec(myUser.aboutMe)
    $("profLink").value = dec(myUser.link)
    $("profEmail").value = dec(myUser.email)
    $("profPassword").value = dec(myUser.password)
    $("profLocation").innerHTML = dec(myUser.location)
    setListBox($("profFaith"), myUser.faith)   
    $("profChurch").value = dec(myUser.church)
    $("profName").value = dec(myUser.name)
      
    $("profilePane").style.display = "block"

}

function setListBox(node, value)
{
    for (i=0;i<node.options.length;i++)
    {
        if (node.options[i].value == value)
        {
            node.selectedIndex = i;
            break
        }
    }
}

function cancelProfile()
{
    clearProfilePane()
}

function clearProfilePane()
{
    $("profDisplay").value = ""
    $("profAbout").value = ""
    $("profLink").value = ""
    $("profEmail").value = ""
    $("profPassword").value = ""
    $("profPassword2").value = ""
    $("profLocation").innerHTML = ""
    $("profFaith").selectedIndex = 0
    $("profChurch").value = ""
    $("profName").value = ""
    $("profChangePassword1").style.display = "none"
    $("profChangePassword2").style.display = "none"
    $("profChangePasswordLink").style.display = "block"
        
    $("profilePane").style.display = "none"
}

function saveProfile()
{
    var profileItems = validateProfileEdit();

    if  (typeof(profileItems) == "string")   //an error string is returned (instead of an array)
    {
        var error = profileItems;             
        msgBox("Oops!", error, 300)
        return
    }

    if (profileItems.length > 0)
    {
        disableBut("saveProfileBut")
        PageMethods.updateProfile(myUser.memberID, profileItems, onUpdateProfileResult, onUpdateProfileError)
    }
    else
    {
        //msgBox("Oops!", "No modifications were detected. To close the Profile pane click Cancel.", 300)  
        clearProfilePane();
    }

}

    function onUpdateProfileResult()
    {
        //updating myUser object, myMap and cookie if needed
        var profileItems = validateProfileEdit();   //get changes
        for (i=0; i<profileItems.length; i++)
        {
            if (profileItems[i][0] == "display")
            {
                myUser.display = profileItems[i][1];
                $("myMapDisplay").innerHTML = profileItems[i][1];
                deleteCookie("display")
                setCookie("display",profileItems[i][1],900)
                refreshGreeting();
            }
            if (profileItems[i][0] == "aboutMe")
            {
                myUser.aboutMe = profileItems[i][1];
                $("myMapAboutMe").innerHTML = profileItems[i][1];
            }
            if (profileItems[i][0] == "link")
            {
                myUser.link = profileItems[i][1];
                $("myMapLink").innerHTML = createLink(profileItems[i][1]);
            }
            if (profileItems[i][0] == "email")
            {
                myUser.email = profileItems[i][1];
            }
            if (profileItems[i][0] == "password")
            {
                myUser.password = profileItems[i][1];
            }       
            if (profileItems[i][0] == "location")
            {
                myUser.location = profileItems[i][1];
            }    
            if (profileItems[i][0] == "faith")
            {
                myUser.faith = profileItems[i][1];
                $("myMapFaith").innerHTML = createFaith(+profileItems[i][1]);
            }    
            if (profileItems[i][0] == "church")
            {
                myUser.church = profileItems[i][1];
                $("myMapChurch").innerHTML = profileItems[i][1];
            }    
            if (profileItems[i][0] == "name")
            {
                myUser.name = profileItems[i][1];
                deleteCookie("usrname")
                setCookie("usrname",profileItems[i][1],900)
            }    
                
        }
        enableBut("saveProfileBut")
        clearProfilePane();
        msgBox("Thank you", "Your profile has been updated.", 300)
    }

    function onUpdateProfileError()
    {
         msgBox("Oops!", "Could not update profile.", 300)

    }
  
    
function validateProfileEdit()   // returns a two dim array with changes, changed item (ie display) and new value
{
    var profileItems = new Array();
    
    if ($("profDisplay").value.trims() != myUser.display)
    {
        if (isEmpty($("profDisplay"))) 
        {
            var error = "The display field is empty. Please enter a display name."
            return error
        }  
        var profileRow = new Array();
        profileRow.push("display")
        profileRow.push($("profDisplay").value.trims())
        profileItems.push(profileRow)
    }
    
    if ($("profAbout").value.trims() != myUser.aboutMe)
    {
        var profileRow = new Array();
        profileRow.push("aboutMe")
        profileRow.push($("profAbout").value.trims())
        profileItems.push(profileRow)
    }
 
    if ($("profLink").value.trims() != myUser.link)
    {
        var profileRow = new Array();
        profileRow.push("link")
        profileRow.push($("profLink").value.trims())
        profileItems.push(profileRow)
    }
    
    if ($("profFaith").options[$("profFaith").selectedIndex].value != myUser.faith)
    {
        var profileRow = new Array();
        profileRow.push("faith")
        profileRow.push($("profFaith").options[$("profFaith").selectedIndex].value)
        profileItems.push(profileRow)
    }
    
    if ($("profChurch").value.trims() != myUser.church)
    {
        var profileRow = new Array();
        profileRow.push("church")
        profileRow.push($("profChurch").value.trims())
        profileItems.push(profileRow)
    }
    
    if ($("profName").value.trims() != myUser.name)
    {
        var profileRow = new Array();
        profileRow.push("name")
        profileRow.push($("profName").value.trims())
        profileItems.push(profileRow)
    }
    
    if ($("profEmail").value.trims() != myUser.email)
    {
        if (!emailValid($("profEmail").value))
        {
            var error = "The email address entered is not valid, please try again."
            return error
        }  
        var profileRow = new Array();
        profileRow.push("email")
        profileRow.push($("profEmail").value.trims())
        profileItems.push(profileRow)
    }
    
    if ($("profPassword").value.trims() != myUser.password)
    {
                //validate password field    
        if ($("profPassword").value.trims() == "")
        {
            var error = "The password entered is empty, please try again."
            return error
        }     
        //verify passwords match
        if ($("profPassword").value.trims() != $("profPassword2").value.trims())
        {
            var error = "The two passwords entered do not match, please try again."
            return error
        }
    
        var profileRow = new Array();
        profileRow.push("password")
        profileRow.push($("profPassword").value.trims())
        profileItems.push(profileRow)
    }
    
    return profileItems;
}

function changeLocation()
{
    $("profilePane").style.display = "none"    // I should check first for user profile edits before discarding Profile pane
    $("newLocation").value = $("profLocation").innerHTML;
    $("locationPane").style.display = "block";   
}

function clearLocation()
{
    $("locationPane").style.display = "none";  
    $("newLocation").value = "";
    $("profilePane").style.display = "block"
}


function findNewUserLocation()    //same as the findUser() in join.js
{
      //check that address field is not empty   
    if (isEmpty($("newLocation"))) 
    {
        msgBox("Oops!", "The zip code field is empty. Please enter a zip code.", 300)
        return
    } 
    
    map.Clear();
    clearMbrPane()
    map.ShowDisambiguationDialog(false);
    //map.FindLocation($('userLoc').value, onFoundResults);
    map.Find(null,$('newLocation').value,null,null,null,null,null,null,false,null,onNewLocationResults);
}

    function onNewLocationResults(ShapeLayer,FindResult,Place,HasMore)     //in VE4: onFoundResults(e)
    {
        PageMethods.updateMemberLocation(myUser.memberID, Place[0].LatLong.Latitude, Place[0].LatLong.Longitude, Place[0].Name, onMemberLocationResult, onMemberLocationError)
/*
        
        //filter the redundant results from VE countaining "county" and "river"
        for (i=0; i<Place.length; i++)
        {
            if ((Place[i].Name.match("(county)") != null) || (Place[i].Name.match("(river)") != null))   //in VE4: e[i].ID.match("...
            {
                Place.splice(i, 1)  //remove that element from the array  
                i=i-1            //resetting for loop because when the array is sliced, if the next item also was a match it would be skipped over 
            }
        }
        
        if (Place.length > 1)
        {
            var results="More than one location exist for your entry. Please select your location area:<ul>";
            for (i=0; i<Place.length; i++)
            {
                results+="<li><a href='javascript:closeMsgBox();map.Find(null,\""+Place[i].Name+"\",null,null,null,null,null,null,false,null,onNewLocationResults);'>"+Place[i].Name+"</a><br></li>";                
                //results+="<li><a href='javascript:closeMsgBox();map.FindLocation(\""+e[i].ID+"\", onFoundResults);'>"+e[i].ID+"</a><br></li>";  //VE4
            }
            results+="</ul>";
            msgBox("Faith Map", results, 300);
         }
         else
         {  
            if (Place.length == 1)
            {   
                //alert(Place[0].LatLong.Latitude + " , "+Place[0].LatLong.Longitude+ " , "+ Place[0].Name)
                
                PageMethods.updateMemberLocation(myUser.memberID, Place[0].LatLong.Latitude, Place[0].LatLong.Longitude, Place[0].Name, onMemberLocationResult, onMemberLocationError)
            }
            else {msgBox("Oops!", "The zip code can not be mapped, please try a different zip code or alternatively enter your 'city, state'.", 300);}
         }
         */
    }
    
    function onMemberLocationResult(location)
    {
        $("profLocation").innerHTML = location
        myUser.location = location
        clearLocation()
    
    }
    
    function onMemberLocationError()
    {
        msgBox("Oops!", "Could not update location.", 300)
    }
    
    function showPasswordBoxes()
    {
        $("profChangePasswordLink").style.display = "none"
        $("profChangePassword1").style.display = "block"
        $("profChangePassword2").style.display = "block"

    }