// Expands or collapses a div or span section
function expandcollapse (postid) 
{ 

   whichpost = document.getElementById(postid); 
   
   if (whichpost.className=="postshown") 
   { 
      whichpost.className="posthidden"; 
   } 
   else 
   { 
      whichpost.className="postshown"; 
   } 
   
} // end expandcollapse ()

// locks control controlA if controlB contains text.  Unlocks controlA if controlB is blank.  
// Usually used with onChange()
function BlankLock(controlA, controlB)
{

	//controlToEnableDisable = document.getElementById("userclass");
	//controlToEnableDisable = document.getElementById(controlA);
	controlToEnableDisable = document.ANUAForm.controlA;
	//alert(controlToEnableDisable.value);
	
	controlToCheckText = document.getElementById(controlB);
	
	//alert('VAL: ' + controlToCheckText.value);
	if(controlToCheckText.value != "")
   	{
	    alert('No Text');
	    controlToEnableDisable.disabled = true;
    }
    else
    {
	    alert('Text');
		controlToEnableDisable.disabled = false;
    }	 
} // end BlankLock ()

function confirmDelete()
{
	var x = confirm('Do you really want to delete this user?');
	if(x == true) 
	{		
		return true;
	} 
	else 
	{
		return false;
	}
}

// prompt user with a confirmation box that will contain a generic specified message
function confirmDelete(message)
{
	var x = confirm(message);
	if(x == true) 
	{		
		return true;
	} 
	else 
	{
		return false;
	}
} // end confirmDelete ()

function confirmDeleteLink()
{
	var x = confirm('Do you really want to delete this Link?');
	if(x == true) 
	{		
		return true;
	} 
	else 
	{
		return false;
	}
}

function validateOnSubmit() 
{
    var elem = document.entire.usertitle.value;
    var elem2 = document.entire.userfile.value;
    var jpgformat = document.entire.userfile.value.match(/(\w+)\.(jpg|JPG|jpeg|JPEG)$/g);  //matches the end of a string with a jpg file
	
    if(elem =='')  // if there is nothing in the box
    {
		alert('You must inlcude a title with your picture.');
		document.entire.usertitle.focus();
		return false;
    }
    else if(elem2 == '')
    {
 		alert('You must inlcude a jpg file with your entry.');	
		document.entire.userfile.focus();
		return false;
    }
    else if(!jpgformat)
    {
		alert('You must use a jpg file! The file you selected is not compatible with mydigitalportal.net .');
		document.entire.userfile.focus();
		return false;
    }
    return true;
}


// this function runs in real time to evaluate the user's password strength
function checkAndRatePassword(currentPasswordID)
{
	// grab the text of the password
	var passwordText = document.getElementById(currentPasswordID).value;
	
	// grab the submit button so we can enable or disable it or swap out the pictures
	var submitButton = document.getElementById("saveButton");
	
	// grab the whatswrong field so user will know what they are doing wrong
	var whatswrong = document.getElementById("whatswrong");
	
	// grab the confirmation password so we can check it against the real password later
	var passwordConf = document.getElementById("passwordConf").value;	
	
	// our restricted character members
	var containsRestrictedCharacter = false;
	var restrictedCharacterList = "/\\?'\"*";   // add or subtract from this list for restricted characters
	
	
	// check to see if they have cleared everything from the password field... if so, we can enable the submit button
	if(passwordText.length == 0)
	{
		submitButton.disabled = false;
		
		// now swap out so button looks enable
		var savePic = new Image();
		savePic.src = "images/save.png";		
		submitButton.src = savePic.src;
		
		whatswrong.innerHTML = ""; // clear out our error code
		
		// set the strength meter back to 0
		var level0 = new Image();
		level0.src = "images/level0.gif";		
		document["strengthMeter"].src = level0.src;
		
		return true;  // no need to keep going
	}
	
	// set up an array to keep score for the rating of the password
	var score = new Array(4);
	score[0] = 0;				// marks a lowercase character found
	score[1] = 0;				// marks an uppercase character found
	score[2] = 0;				// marks a numeric character found
	score[3] = 0;				// marks a special character found
	
	
	// check for a lowercase letter
	for (count = 0; count < passwordText.length; count++)
	{
		if(passwordText.charCodeAt(count) >= 97 && passwordText.charCodeAt(count) <= 122)
		{ // we just found a lowercase letter
		
			// mark success in our array
			score[0] = 1;
			
			// no sense to keep going
			break;
			
		} // end IF we found a lowercase letter
	} // end FOR each letter
	
	
	// check for an uppercase letter
	for (count = 0; count < passwordText.length; count++)
	{
		if(passwordText.charCodeAt(count) >= 65 && passwordText.charCodeAt(count) <= 90)
		{ // we just found a lowercase letter
		
			// mark success in our array
			score[1] = 1;
			
			// no sense to keep going
			break;
			
		} // end IF we found an uppercase letter
	} // end FOR each letter


	// check for a numeric character
	for (count = 0; count < passwordText.length; count++)
	{
		if(passwordText.charCodeAt(count) >= 48 && passwordText.charCodeAt(count) <= 57)
		{ // we just found a lowercase letter
		
			// mark success in our array
			score[2] = 1;
			
			// no sense to keep going
			break;
			
		} // end IF we found a numeric character
	} // end FOR each letter


	// check for a special character
	for (count = 0; count < passwordText.length; count++)
	{
		//                                ...'/'                                       :               ...                    @                                         [                    ...                `                                       }
		if(passwordText.charCodeAt(count) <= 47 || (passwordText.charCodeAt(count) >= 58 && passwordText.charCodeAt(count) <= 64) || (passwordText.charCodeAt(count) >= 91 && passwordText.charCodeAt(count) <= 96) || passwordText.charCodeAt(count) >= 125)
		{ // we just found a lowercase letter
		
			// mark success in our array
			score[3] = 1;
			
			// no sense to keep going
			break;
			
		} // end IF we found a special character
	} // end FOR each letter
	
	
	
	// add up our score
	var totalScore = 0;	
	for (count = 0; count < score.length; count++)
	{
		totalScore += score[count];
	
	} // end FOR each element in our score array
	
	
	// Now switch out the gifs to represent the strength of the password
	if(totalScore == 0)
	{						   
		var level0 = new Image();
		level0.src = "images/level0.gif";
		
		document["strengthMeter"].src = level0.src;
	}
	else if(totalScore == 1)
	{
		var level1 = new Image();
		level1.src = "images/level1.gif";
		
		document["strengthMeter"].src = level1.src;
		
	}
	else if(totalScore == 2)
	{
		var level2 = new Image();
		level2.src = "images/level2.gif";
		
		document["strengthMeter"].src = level2.src;
		
	}
	else if(totalScore == 3)
	{
		var level3 = new Image();
		level3.src = "images/level3.gif";
		
		document["strengthMeter"].src = level3.src;
		
	}
	else if(totalScore == 4)
	{
		var level4 = new Image();
		level4.src = "images/level4.gif";
		
		document["strengthMeter"].src = level4.src;
	}
	
	
	// check restricted character list
	for (passwordIndexer = 0; passwordIndexer < passwordText.length; passwordIndexer++)
	{
		for (restrictedIndexer = 0; restrictedIndexer < restrictedCharacterList.length; restrictedIndexer++)
		{
			if(passwordText.charAt(passwordIndexer) == restrictedCharacterList.charAt(restrictedIndexer))
			{
				containsRestrictedCharacter = true;
			
				break;
				
			} // end IF we found a restricted character
		
		} // end FOR each character in the restrictedCharacterList string
		
	} // end FOR each character in the passwordText field
	

	// check to see if we can finally enable the submit button... if we have a strong enough password
	if(totalScore < 2 || passwordText.length < 5 || containsRestrictedCharacter || passwordText != passwordConf)
	{
		submitButton.disabled = true;
		
		//alert(submitButton.src);
		
		// now swap out so button looks disabled
		var savePic = new Image();
		savePic.src = "images/saveDisabled.png";		
		submitButton.src = savePic.src;
		
		// now lets break down to the user whats wrong and display the message appropriately
		if(totalScore < 2)
		{
			whatswrong.innerHTML = "* You may not submit because your password is not strong enough. Get <A HREF=\"javascript:popitup('help/helpTemplate.php?subject=lowscorepassword')\">help</A> on this subject.";
		}
		else if(passwordText.length < 5)
		{
			whatswrong.innerHTML = "* You may not submit because your password is not <i>at least</i> 5 characters long. Get <a href=\"\">help</a> on this subject."
		}
		else if(passwordText != passwordConf)
		{
			whatswrong.innerHTML = "* You may not submit because your password does not match the confirmation password.";
		}
		else
		{
			whatswrong.innerHTML = "* Unknown reason.";
		}
		
		
		return false;
		
	} // end IF password stength score is greater than 2
	else
	{		
		submitButton.disabled = false;
		
		// now swap out so button looks enable
		var savePic = new Image();
		savePic.src = "images/save.png";		
		submitButton.src = savePic.src;
		
		whatswrong.innerHTML = ""; // clear out our error code
		
		return true;
	}
} // end checkAndRatePassword ()


// called to limit fields in forms 
function checkLength(form)
{
    if (form.description.value.length > 20){
        alert("Text too long. Must be 20 characters or less");
        return false;
    }
    return true;
}

// *********** this section is for the pop-up help **************** //     http://www.pcurtis.com/popup.htm

var newwindow = ''
// pop-up a help window
function popitup(url)  
{
	
		if (newwindow != '' && !newwindow.closed) 
		{
			newwindow.location.href = url;
			newwindow.focus(); 
			//alert('open already!'); // ttt
		}
		else
		{
			newwindow=window.open(url,'newwindow','width=404,height=400,resizable=0,scrollbars=yes');
			//alert('NOT open!'); // ttt
		}
	
}

// cleans up an already open help window
// I am not sure why this function doesn't work right
/*
function tidy() 
{
	if (newwindow.location && !newwindow.closed) 
	{
	   newwindow.close(); 
   }
}

*/

// *********** END pop-up help **************** //


// *********** prevent user from clicking submit button more than once ************* //
var formerrormsg="You\'ve attempted to submit this photo entry multiple times.\n Please reload page if you need to resubmit entry."

function CheckCanSubmit(submitbtn)
{
	submitbtn.form.submit();
	CheckCanSubmit = BlockSubmit;
	return false;
}


function BlockSubmit()
{
	if (typeof formerrormsg!="undefined")
		alert(formerrormsg);
	return false;
}
// *********** END prevent user from clicking submit button more than once ************* //

function TrimString(trimthis) 
{
  str = trimthis.replace(/^\s*|\s*$/g,"");
  return str
}
 
// check to see if the form has all the fields filled in
 
function CheckAddNewForm()
{
	var canProceed = true;
	var reasons = "";	
	var reasonsMessage = "";

	
	// grab username off the form 
	if(TrimString(document.ANUAForm.username.value) == "")
	{
		reasons += "-username left blank\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}
	
	// grab username off the form 
	if(TrimString(document.ANUAForm.userpassword.value) == "")
	{
		reasons += "-password left blank\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}
	
	// grab username off the form 
	if(TrimString(document.ANUAForm.userpasswordc.value) == "")
	{
		reasons += "-Password CONFIRMATION left blank\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}
	
	// check to make sure that the 2 passwords are the same 
	if(document.ANUAForm.userpassword.value !=  document.ANUAForm.userpasswordc.value)
	{
		reasons += "-Password and Password Confimations do not match\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}	
	
	// check userclass
	if(document.ANUAForm.userclass.value == "none" && document.ANUAForm.newUserClass.value == "")
	{
		reasons += "-You must choose a user visibility class\n";
		
		canProceed = false;
	}
	
	// check the realname field
	if(TrimString(document.ANUAForm.fullName.value) == "")
	{
		reasons += "-You must enter a Real Name for this user\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}
	
	// check the user level field
	if(TrimString(document.ANUAForm.userLevel.value) == "")
	{
		reasons += "-User Level has not been defined\n";
		
		// trip so we will not proceed later
		canProceed = false;
	}
	
	// if we are not allowed to proceed, display to the user why
	if(!canProceed)
	{
		reasonsMessage = "You may not continue because there are problems with the data you entered.  Here are the problems:\n\n";
		reasonsMessage += reasons;
		reasonsMessage += "\nPlease fix these problems and then try resubmitting.";
		
		alert(reasonsMessage);
	}	
	
	// return our verdict
	return canProceed;	
	
} // end CheckAddNewForm ()

/*
// AJAX Component retrieved from http://www.phpit.net/article/ajax-php-without-xmlhttprequest/
// Get base url   -- THIS STUFF NOT USED ANYMORE
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function ajax_do (url) {
        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }

        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}
*/

var http = createRequestObject(); 

// Ajax code from http://www.phpbuilder.com/columns/kassemi20050606.php3
/* The following function creates an XMLHttpRequest object... */
function createRequestObject()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer")
	{
		//alert("IE detected");
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */


// switches a photo entry to an editable state
function SwitchToEditMode(PhotoCellString, IDArgument)
{

	// get the title of the picture
	divTitle = document.getElementById(PhotoCellString + 'Title');
	var storageTitle = divTitle.innerHTML;
	// trim leading and trailing spaces from the title text
	storageTitle = TrimString(storageTitle);
	
	// get the caption of the picture
	divCaption = document.getElementById(PhotoCellString + 'Caption');
	var storageCaption = divCaption.innerHTML;
	// trim leading and trailing spaces from the caption text
	storageCaption = TrimString(storageCaption);
	
	// make the text fields into dynamic editable fields
	divTitle.innerHTML = "<input type=\"text\" name=\"usertitle\" id=\"usertitle\" maxlength = \"20\" value=\"" + storageTitle + "\" />";	
	divCaption.innerHTML = "<br /><br /><textarea name = \"mytextarea\" id=\"mytextarea\" rows = \"7\" cols = \"60\" >" + storageCaption + "</textarea>";
	
	// change the edit icon to a save icon
	var editButton = document.getElementById(PhotoCellString + "editButton");
	//alert(editButton);
	editButton.src = "images/save.png";
	editButton.onclick = new Function("SaveDataBackToServer(\'" + IDArgument + "\', \'" + PhotoCellString + "\');");
	
} // end SwitchToEditMode ()




function SaveDataBackToServer(IDArgument, PhotoCellString)
{
	http.onreadystatechange = SaveResponse; 
	
	// ready the new data to be sent to the server
	var poststr = "usertitle=" + encodeURI( document.getElementById("usertitle").value ) + "&mytextarea=" + encodeURI( document.getElementById("mytextarea").value );

	// send the data to the server
	//http.abort;  // this causes problems in IE so I am going to comment it out for now
	http.open("POST", "EAEP2_AJAX_Finish.php?barf=gross&" + IDArgument);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	
	// now start changing the GUI back to the way it was
	divTitle = document.getElementById(PhotoCellString + 'Title');
	divCaption = document.getElementById(PhotoCellString + 'Caption');
	
	// change the picture title and caption back to static text
	divTitle.innerHTML = document.getElementById("usertitle").value;
	divCaption.innerHTML = document.getElementById("mytextarea").value;
	
	// change the disk icon back to the edit icon
	var editButton = document.getElementById(PhotoCellString + "editButton");
	editButton.src = "images/Edit.png";
	
	// change the button onclick behavior back to default
	editButton.onclick = new Function("SwitchToEditMode(\'" + PhotoCellString + "\',\'" + IDArgument + "');");
	
} // end SaveDataBackToServer()

function SaveResponse()
{
	if(http.readyState == 4)
	{
		var response = http.responseText;
		
		//alert(response);
		
		if(response.match("CommnetEntryNumber") !=  null)
		{
			//alert('CommentEntryNumber Found');			
			//myXML= document.all(response).XMLDocument;
			var searchForElement = "CommnetEntryNumber";
			var IDNumber = response.substring(response.indexOf("<" + searchForElement + ">") + searchForElement.length + 2, response.indexOf("</" + searchForElement + ">"));
			
			searchForElement = "whichSection";
			var whichSection = response.substring(response.indexOf("<" + searchForElement + ">") + searchForElement.length + 2, response.indexOf("</" + searchForElement + ">"));
			
			var linkPostComment = document.getElementById(whichSection + 'PostCommentLink'); 
			linkPostComment.href = linkPostComment.href.replace("-99", IDNumber);
			
			//alert(response);
		}
		else if(response.match("ConfirmWatching") !=  null)
		{
			alert('You are now watching this photo conversation for replies.  This means you will receive e-mails notifying you of any activity in this section.\n\nIf at any time you no longer wish to monitor and receive notifications about this entry, please click on the Stop Monitoring link below the photo.');
		}
		else if(response.match("ConfirmNotWatching") !=  null)
		{
			alert('You are NO LONGER watching this photo conversation for replies.  This means you will NO LONGER receive e-mails notifying you of any activity in this section.\n\nIf at any time you wish to monitor and receive notifications about this entry, please click on the Start Monitoring link below the photo. ');
		}
		else
		{
			//alert("Responso: " + response);  // UNCOMMENT this later to stop the other messages from coming through
		}
		
	}
	
}

// this global keeps track of whether the script automatically expanded a comment of it was a user
var UserExpandedComments = false;

function ExpandComments(whichSection, numberOfComments)
{
	// if there is 0 comments, then show No Comments
	if(numberOfComments <=0)
		return;
	
	divComments = document.getElementById(whichSection + 'Comments');
	divReadComments = document.getElementById(whichSection + 'ReadComment');
	
	// if this is run EVEN though it was already visible, the user must have clicked on the Leave Comment link, therefor later we don't want to rescroll the whole window
	if(divComments.style.visibility == "visible")
		UserExpandedComments = true;
	else
		UserExpandedComments = false;
		
	
	divComments.style.visibility = "visible";
	divComments.style.display =  "block";
	
	divReadComments.innerHTML = "<a href=\"javascript:ShrinkComments(" + whichSection + ", " + numberOfComments + ")\"><span style=\"color:#4B47F7; font-weight:normal\"><img src=\"images/Shrink.png\" width=\"15px\"/>Hide Comments</span> </a>";
	
	// also show comments the user may have just made 
	divNewCommentReserveSpace = document.getElementById(whichSection + 'NewCommentReserveSpace');
	// ... but only if there is text in the div do we display
	if(TrimString(divNewCommentReserveSpace.innerHTML) != "")
	{
		divNewCommentReserveSpace.style.visibility = "visible";
		divNewCommentReserveSpace.style.display = "block";
	}	
	
} // end ExpandComments ()

// http://www.quirksmode.org/dom/getstyles.html
function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}


function ShrinkComments(whichSection, numberOfComments)
{
	divComments = document.getElementById(whichSection + 'Comments');
	divReadComments = document.getElementById(whichSection + 'ReadComment');
	
	divComments.style.visibility = "hidden";
	divComments.style.display =  "none";
	
	divReadComments.innerHTML = "<a href=\"javascript:ExpandComments(" + whichSection + "," + numberOfComments + ")\"><span style=\"color:#4B47F7; font-weight:normal\"><img src=\"images/Expand.png\" width=\"15px\" /> Read " + numberOfComments + " Comments</span> </a>";
	
	// also hide any comments the user may have just made 
	divNewCommentReserveSpace = document.getElementById(whichSection + 'NewCommentReserveSpace');
	divNewCommentReserveSpace.style.visibility = "hidden";
	divNewCommentReserveSpace.style.display = "none";
	
	// scroll the document back to the top
	window.location.href= "#" + whichSection + "PhotoLocation";
	
	// and give a margin of 50px above the picture
	window.scrollBy(0, -50);
	
} // end ShrinkComments ()


// displays or hides a comment box for a particular photo
function DisplayCommentBox(whichSection)
{	
	tableCommentLinks = document.getElementById(whichSection + 'ReadCommentLinks');
	tableSaveCommentLinks = document.getElementById(whichSection + 'SaveCommentLinks');
	
	divCommentBox = document.getElementById(whichSection + 'CommentBox');
	
	if(tableCommentLinks.style.visibility != "hidden")
	{
		// hide the Read and Leave Comments links
		tableCommentLinks.style.visibility = "hidden";
		tableCommentLinks.style.display = "none";
		
		// show the Post Comment and Cancel button
		tableSaveCommentLinks.style.visibility = "visible";
		tableSaveCommentLinks.style.display =  "block";
		
		// show the text area
		divCommentBox.style.visibility = "visible";
		divCommentBox.style.display =  "block";
		
	}
	else
	{
		
		// show the Read and Leave Comments links
		tableCommentLinks.style.visibility = "visible";
		tableCommentLinks.style.display = "block";
		
		tableSaveCommentLinks.style.visibility = "hidden";
		tableSaveCommentLinks.style.display =  "none";
		
		// hide the text area
		divCommentBox.style.visibility = "hidden";
		divCommentBox.style.display =  "none";
	}		
} // end DisplayCommentBox ()


// this function will scroll to a specific tag named #[identifier]ScrollToHere with an offset of -300 pixels.
// it also focuses the specific text area that goes with the tag
function ScrollToTag(whichSection)
{	
	// only do this if the user did NOT expand the comments themselves
	if(UserExpandedComments)
	{
		UserExpandedComments = false;
		return;
	}
	
	// have the window jump to the specified section
	window.location.href= "#" + whichSection + "ScrollToHere";
	
	// now move the scroll position up a few lines 
	window.scrollBy(0, -300);
	
	// focus the text area
	document.getElementById(whichSection + 'commenttextarea').focus();
	
	
} // end ScrollToTag ()



// saves the user comment back to the server
function SaveCommentToServer(IDArgument, whichSection, editComment, IDAndNumcountArgs)
{
	http.onreadystatechange = SaveResponse; 
	
	// ready the new data to be sent to the server
	//var poststr = "usertitle=" + encodeURI( document.getElementById("usertitle").value ) + "&mytextarea=" + encodeURI( document.getElementById("mytextarea").value );

	var poststr = "commenttextarea=" + encodeURI(document.getElementById(whichSection + "commenttextarea").value);
	
	// send the data to the server
	//http.abort;  // this causes problems in IE so I am going to comment it out for now
	http.open("POST", "SaveComment_AJAX.php?barf=gross&" + IDArgument + "&editComment=" + editComment + "&whichSection=" + whichSection + "&" + IDAndNumcountArgs, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	
	//alert('sent!');  this is sent?!!!!
	
	// add the new comments to the page
	divNewComment = document.getElementById(whichSection + 'NewCommentReserveSpace');
	divNewComment.style.visibility = "visible";
	divNewComment.style.display =  "block";
	divNewComment.innerHTML = "<blockquote><p align=\"left\"><span style=\"color:#0066FF\">____________________</span><br /></p><p align=\"left\"><span style=\"font-size:10px; color:#009966;\">You Just Said:</span></p><blockquote><p align=\"left\">" + document.getElementById(whichSection + "commenttextarea").value + "</p></blockquote></blockquote><br />";
	
	// close the comment box
	DisplayCommentBox(whichSection);	
	
	// now change the text of the "Post Comment!" link to "Update Last Comment"
	var linkPostComment = document.getElementById(whichSection + 'PostCommentLink'); 	
	linkPostComment.innerHTML = "<span style=\"color:#4B47F7; font-weight:normal\">Update Your Last Comment</span>";
	linkPostComment.href = "javascript:UpdateLastCommentToServer('" + IDArgument + "'," + whichSection + ", '-99')";
	
	// also change the Read () comments to a legit value!??
	divReadComments = document.getElementById(whichSection + 'ReadComment');
	if(divReadComments.innerHTML.match("No Comments") != null)
	{
		divReadComments.innerHTML = "<a href=\"javascript:ShrinkComments(" + whichSection + ", 1)\"><span style=\"color:#4B47F7; font-weight:normal\"><img src=\"images/Shrink.png\" width=\"15px\"/>Hide Comments</span> </a>";
	}
	
} // end SaveCommentToServer ()


// edits and updates last comment to server
function UpdateLastCommentToServer(IDArgument, whichSection, IDPhotoEntry)
{
	http.onreadystatechange = SaveResponse; 
	
	var poststr = "commenttextarea=" + encodeURI(document.getElementById(whichSection + "commenttextarea").value);
	
	//http.abort;  // this causes problems in IE so I am going to comment it out for now
	http.open("POST", "SaveComment_AJAX.php?barf=gross&" + IDArgument + "&editComment=true&IDPhotoEntry=" + IDPhotoEntry);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", poststr.length);
	http.setRequestHeader("Connection", "close");
	http.send(poststr);
	
	// close the comment box
	DisplayCommentBox(whichSection);	
	
	// add the new comments to the page
	divNewComment = document.getElementById(whichSection + 'NewCommentReserveSpace');
	divNewComment.style.visibility = "visible";
	divNewComment.style.display =  "block";
	divNewComment.innerHTML = "<blockquote><p align=\"left\"><span style=\"color:#0066FF\">____________________</span><br /></p><p align=\"left\"><span style=\"font-size:10px; color:#009966;\">You Just Said:</span></p><blockquote><p align=\"left\">" + document.getElementById(whichSection + "commenttextarea").value + "</p></blockquote></blockquote><br />";
	
} // end UpdateLastCommentToServer ()

function ChangeMonitorIcon(changeToStart, PhotoID, whichSection)
{
	// get the div that holds this link
	divStartStopMonitor = document.getElementById(whichSection + 'StartStopMonitor');
	
	if(changeToStart)  // change the icon to Start
	{
		// now must change the link to Start Monitoring
		divStartStopMonitor.innerHTML = "<a href=\"javascript:SaveMonitorResponseToServer(true, " + PhotoID + "," + whichSection + ");\"><span style=\"color:#4B47F7; font-weight:normal\"><img src=\"images/Start3.png\" width=\"15px\"/> Start Monitoring</span></a>";
	}
	else
	{
		// now must change the link to Stop Monitoring
		divStartStopMonitor.innerHTML = "<a href=\"javascript:SaveMonitorResponseToServer(false, " + PhotoID + "," + whichSection + ");\"><span style=\"color:#4B47F7; font-weight:normal\"><img src=\"images/Stop2.png\" width=\"15px\"/> Stop Monitoring</span></a>";
	}
	
}  // end ChangeMonitorIcon ()


function SaveMonitorResponseToServer(MonitorThread, PhotoID, whichSection)
{
	http.onreadystatechange = SaveResponse; 
	
	var poststr = "";
	var queryString = "";
		
	if(MonitorThread)
	{
		queryString = "monitorThread=true&photoID=" + PhotoID;
		
		ChangeMonitorIcon(false, PhotoID, whichSection);	
		
	}
	else
	{
		queryString = "monitorThread=false&photoID=" + PhotoID;
		
		ChangeMonitorIcon(true, PhotoID, whichSection);
	}
	
	//http.abort;  // this causes problems in IE so I am going to comment it out for now
	http.open("POST", "MonitorChangeSave_AJAX.php?barf=gross&" + queryString);
	//http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//http.setRequestHeader("Content-length", poststr.length);
	//http.setRequestHeader("Connection", "close");
	//http.send(poststr);
	http.send(null);
	
	
} // end SaveMonitorResponseToServer
