// dummy function to handle return of Ajax call invoked to keep track of links read

function dummyJournalFunction(XMLtext)
{
//    alert("update returned");
    return;
}

function showJournalDetail(nbr, usernamePassedIn)
{
    if (journalDetailFlag[nbr] && journalDetailFlag[nbr] == 1) { // 1 means it is already showing detail so remove the detail
        journalDetailFlag[nbr] = 0;
        dd.elements["journalDetailSpot" + nbr].write("<hr>");
    }
    else {
        singleDetail = journalDetailText[nbr];
        newDetail = "";
        bracketSpot = startSpot = 0;
        singleID = journalJournalIDNodes[nbr].firstChild.nodeValue;  // value of text node in a <journalID>
	editString = "";
	// user (unencoded) and username (encoded) defined in including program
	if (usernamePassedIn && usernamePassedIn == journalNamesNodes[nbr].firstChild.nodeValue) {
	    editString = "&nbsp;&nbsp;&nbsp;" + 
                          '<a href="http://www.biketouringtips.com/login.php?username=' +
                          argumentList['username'] +
                          '&loginCmd=testLogin' +
                          '&destination=editJournalEntry.php' +
                          '&jid=' + singleID + '">Edit Journal</a>';
        }
	// fullThreadText was added by RS 1/22/09 to bold "View full thread" if there are comments in entry
	fullThreadText = "View complete Journal";
	if (journalEntryNodes[nbr].firstChild.nodeValue > 0) {
	    fullThreadText = "<b>View complete Journal</b></a>";
	}
        clickOptions = "<table width=100%><tr>" +
		       "<td align=left valign='baseline' class=smallfont>" +
	               "<a href='javascript:m(\"badlink-" + singleID + "\", \"?subject=Bad link in " + singleID + "\")'>report bad link</a></td>" +
	               "<td align=right class=detailfont>" +
                       "<a href='javascript:void(0)' " +
                       "onclick='showJournalDetail(" + nbr + ");'>Close</a>" +
                       "&nbsp;&nbsp;&nbsp;" +
                       "<a href='http://www.biketouringtips.com/showJournalPages.php?jid=" + singleID + "&username=" + 
		       argumentList['username'] +
                       "&from=threadEntries' target=_blank>" + fullThreadText + "</a>" +  // fullThreadText added 1/23/09
                       "&nbsp;&nbsp;&nbsp;" +
                       '<a href="http://www.biketouringtips.com/login.php?username=' +
                       argumentList['username'] +
                       '&loginCmd=testLogin' +
                       '&destination=showJournalPages.php' +
                       '&command=commentEntry&jid=' + singleID + '">Add a Comment</a>' +
		       editString + 
                       "</td></tr></table>";
        dd.elements["journalDetailSpot" + nbr].write("<br>" + singleDetail + "<br><br>" + clickOptions + "<hr>");
	if (journalDetailFlag[nbr] == -1) {
	     // put ajax call here to count the hit on the link
	     postDataReturnXml('http://www.biketouringtips.com/getJournalData.php', 'command=countJournalsOpened&jid=' + singleID, dummyJournalFunction);
	}
        journalDetailFlag[nbr] = 1;
    }
}

// the following code is no longer used as it can't be cut/paste. 
function showJournalEntryDetail(nbr, usernamePassedIn)
{
    if (journalEntryDetailFlag[nbr] && journalEntryDetailFlag[nbr] == 1) { // 1 means it is already showing detail so remove the detail
        journalEntryDetailFlag[nbr] = 0;
        dd.elements["journalEntryDetailSpot" + nbr].write("<hr>");
    }
    else {
        distanceData = "";  // used to add distance data to top of singleDetail
        timeData = "";  // used to add time data to top of singleDetail
	// determine which date of the week it is
	dayOfWeek = "";
	if (journalEntryTourDatesNodes[nbr].firstChild && journalEntryTourDatesNodes[nbr].firstChild.nodeValue != " ") {
	    dateInfo = journalEntryTourDatesNodes[nbr].firstChild.nodeValue.split("-");
	    dateInfo = new Date(dateInfo[0], dateInfo[1] - 1, dateInfo[2]);
	    day = new Array();
	    day[0] = "Sunday";
	    day[1] = "Monday";
	    day[2] = "Tuesday";
	    day[3] = "Wednesday";
	    day[4] = "Thursday";
	    day[5] = "Friday";
	    day[6] = "Saturday";
	    dayOfWeek = "Day of week: " + day[dateInfo.getDay()] + "<br><br>";
	}
	// note that there is only one journal so the index for distance/time flag will always be 0
        if (journalDistanceFlagNodes[0].firstChild.nodeValue != "N" && 
	    journalEntryDistanceNodes[nbr].firstChild &&
	    journalEntryDistanceNodes[nbr].firstChild.nodeValue != " ") {
	    distanceData = "Daily Distance: " +  journalEntryDistanceNodes[nbr].firstChild.nodeValue;
	    if (journalDistanceFlagNodes[0].firstChild.nodeValue == "M") {
	         distanceData += " Miles (";
	         conversion = journalEntryDistanceNodes[nbr].firstChild.nodeValue * 1.61;
		 distanceData += conversion.toFixed(2) + " Kilometers)";
		 distanceData += "&nbsp;&nbsp;Total Miles: " + journalEntryTotalDistanceNodes[nbr].firstChild.nodeValue;
	         conversion = journalEntryTotalDistanceNodes[nbr].firstChild.nodeValue * 1.61;
		 distanceData += " (" + conversion.toFixed(2) + " Kilometers)<br><br>";
	    }
	    else { // must be "K"
	         distanceData += " Kilometers (";
	         conversion = journalEntryDistanceNodes[nbr].firstChild.nodeValue / .61;
		 distanceData += conversion.toFixed(2) + " Miles)";
		 distanceData += "&nbsp;&nbsp;Total Kilometers: " + journalEntryTotalDistanceNodes[nbr].firstChild.nodeValue;
	         conversion = journalEntryTotalDistanceNodes[nbr].firstChild.nodeValue / 1.61;
	         distanceData += " (" + conversion.toFixed(2) + " Miles)<br><br>";
	    }
	}
        if (journalTimeFlagNodes[0].firstChild.nodeValue == "Y" && 
	    journalEntryHoursNodes[nbr].firstChild &&
	    journalEntryHoursNodes[nbr].firstChild.nodeValue != " ") {
	    dayTime = journalEntryHoursNodes[nbr].firstChild.nodeValue;
            dayTime = dayTime.replace(/^ 0*/, '');
            dayTime = dayTime.replace(/:0*$/, '');
	    timeData = "Daily Hours: " +  dayTime;
	    dayTime = journalEntryTotalHoursNodes[nbr].firstChild.nodeValue;
            dayTime = dayTime.replace(/^0*/, '');
            dayTime = dayTime.replace(/:0*$/, '');
   	    timeData += "&nbsp;&nbsp;Total Hours: " + dayTime + "<br><br>";
	}
        singleDetail = journalEntryDetailText[nbr];
        newDetail = "";
        bracketSpot = startSpot = 0;
        singleID = journalEntryEntryIDNodes[nbr].firstChild.nodeValue;  // value of text node in a <entryID>
	editString = "";
	// user (unencoded) and username (encoded) defined in including program
	if (user && user == journalEntryNamesNodes[nbr].firstChild.nodeValue) {
	    editString = "&nbsp;&nbsp;&nbsp;" + 
                          '<a href="http://www.biketouringtips.com/login.php?username=' +
                          argumentList['username'] +
                          '&loginCmd=testLogin' +
                          '&destination=editDailyJournalEntry.php' +
                          '&eid=' + singleID + 
			  '&jid=' + journalEntryJournalIDNodes[nbr].firstChild.nodeValue +
			  '">Edit</a>';
        }
        clickOptions = "<table width=100%><tr>" +
		       "<td align=left valign='baseline' class=smallfont>" +
	               "<a href='javascript:m(\"badlink-" + singleID + "\", \"?subject=Bad link in Journal Entry " + singleID + "\")'>report bad link</a></td>" +
	               "<td align=right class=detailfont>" +
                       "<a href='#page" + ((nbr - 2) < 0 ? 0 : (nbr - 2)) + "' " +
                       "onclick='showJournalEntryDetail(" + nbr + ");'>Close</a>" +
                       "&nbsp;&nbsp;&nbsp;" +
/* unimplemented for journal entries.
                       '<a href="http://www.biketouringtips.com/login.php?username=' +
                       argumentList['username'] +
                       '&loginCmd=testLogin' +
                       '&destination=tipCommentEntry.html' +
                       '&tipID=' + singleID + '">Add a Comment</a>' +
*/
		       editString + 
                       "</td></tr></table>";
        dd.elements["journalEntryDetailSpot" + nbr].write("<br>" + dayOfWeek + distanceData + timeData + 
	                                                   singleDetail + "<br><br>" + clickOptions + "<hr>");
	if (journalEntryDetailFlag[nbr] == -1) {
	     // put ajax call here to count the hit on the link
	     postDataReturnXml('http://www.biketouringtips.com/getJournalData.php', 'command=countJournalEntriesOpened&jeid=' + singleID, dummyJournalFunction);
	}
        journalEntryDetailFlag[nbr] = 1;
    }
}

