//BLOG FUNCTIONS
//this function replaces a blog comment and it's edit / delete buttons with an editable comment area and a save / cancel button combo when viewing blogs as an admin
function commentedit(id, blogid){
	var element = document.getElementById("comment" + id);  //get the comment conatiner div
	var contentcontainer = document.getElementById("content" + id);  //get the comment conatiner paragraph
	var content = contentcontainer.firstChild.nodeValue; //get the contents of the comment
	//replace the div contents with different html
	element.innerHTML = "<textarea id='TAedit" + id + "' cols='60' rows='5'>" + content + "</textarea><br/><input id='BTNsave" + id + "' type='button' value='Save' onclick='commentsave(" + id + "," + blogid + ")' />&nbsp;<input id='BTNcancel" + id + "' type='button' value='Cancel' onclick='commentcancel(" + blogid + ")' />";
}
//this function cancels an edit operation on a blog comment while viewing as an admin
function commentcancel(id){
	window.location = "blog_Details.aspx?blogid=" + id; //simple redirect back to blog page
}
//this function saves information about the comment edits to be saved and causes an asp postback from a basic html button (a magical feat if you ask me)
function commentsave(id, blogid){
	//assigns hidden variables and html objects assosiated when the comment we are saving to javascript variables
	//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
	//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
	var HDNid = document.getElementById("ctl00_cphContent_HDNid");
	var HDNblogid = document.getElementById("ctl00_cphContent_HDNblogid");
	var HDNcontent = document.getElementById("ctl00_cphContent_HDNcontent");
	var TAcomment = document.getElementById("TAedit" + id);
	
	//next save the ids passed to this function to the hidden variables
	HDNid.value = id;
	HDNblogid.value = blogid;
	HDNcontent.value = TAcomment.value;
	
	//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
	__doPostBack('SaveEdit','');
}
//this function deletes a comment from the blog
function commentdelete(id, blogid){
	//ask the user if they are sure they want to delete this comment
	var answer = confirm("Are you sure would you like to delete this comment? This can not be undone!");
	//if the answer is yes
	if (answer){
		//assigns hidden variables assosiated when the comment we are deleting to javascript variables
		//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
		//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
		var HDNid = document.getElementById("ctl00_cphContent_HDNid");
		var HDNblogid = document.getElementById("ctl00_cphContent_HDNblogid");
		
		//next save the ids passed in this function to the hidden variables
		HDNid.value = id;
		HDNblogid.value = blogid;
	
		//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
		__doPostBack('Delete','');
	}
}
// FORUM FUNCTIONS
//this function replaces a forum category and it's edit / delete buttons with an editable areas and a save / cancel button combo when viewing as an admin
function categoryedit(id){
	var titleelement = document.getElementById("cattitle" + id);  //get the category title paragraph
	var titleTD = document.getElementById("cattitleTD" + id);  //get the category title table data
	var descelement = document.getElementById("catdesc" + id);  //get the category description paragraph
	var postelement = document.getElementById("catposts" + id);  //get the category post number paragraph
	var lastpostelement = document.getElementById("catlastpost" + id);  //get the category last post date paragraph
	var controlselement = document.getElementById("catcontrols" + id);  //get the admin button area td
	
	var title = titleelement.firstChild.nodeValue; //get the contents of the title
	var desc = descelement.firstChild.nodeValue; //get the contents of the description
	
	//inputs html into title area
	titleTD.innerHTML = "<span class='forumlink'>Title:&nbsp;</span><input type='text' maxlength='255' id='TBtitleedit" + id + "' value='" + title + "' />";
	//inputs html into description area
	descelement.innerHTML = "<span class='forumlink'>Description:</span><br/><textarea id='TAedit" + id + "' cols='60' rows='5'>" + desc + "</textarea>";
	//inputs new buttons into admin area
	controlselement.innerHTML = "<input id='BTNsave" + id + "' type='button' value='Save' onclick='categorysave(" + id + ")' />&nbsp;<input id='BTNcancel" + id + "' type='button' value='Cancel' onclick='categorycancel()' />";
	
}
function categorycancel(){
	window.location = "forum.aspx"; //simple redirect back to forum main page
}
function categorysave(id){
	//assigns hidden variables and html objects assosiated when the category we are saving to javascript variables
	//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
	//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
	var HDNcatid = document.getElementById("ctl00_cphContent_HFcatid");
	var HDNsubject = document.getElementById("ctl00_cphContent_HFsubject");
	var HDNmessage = document.getElementById("ctl00_cphContent_HFmessage");
	var TAdesc = document.getElementById("TAedit" + id);
	var TBtitle = document.getElementById("TBtitleedit" + id);
	
	//next save the ids passed to this function to the hidden variables
	HDNcatid.value = id;
	HDNsubject.value = TBtitle.value;
	HDNmessage.value = TAdesc.value;
	
	//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
	__doPostBack('SaveEditCat','');
}
//this function deletes a category from the forum
function categorydelete(id){
	//ask the user if they are sure they want to delete this category
	var answer = confirm("Are you sure would you like to delete this Category? This will delete all assosiated Topics and Posts and can not be undone!");
	//if the answer is yes
	if (answer){
		//assigns hidden variables assosiated when the category we are deleting to javascript variables
		//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
		//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
		var HDNcatid = document.getElementById("ctl00_cphContent_HFcatid");
		
		//next save the id passed in this function to the hidden variable
		HDNcatid.value = id;
	
		//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
		__doPostBack('DeleteCat','');
	}
}
//this function replaces a forum topic and it's edit / delete buttons with an editable areas and a save / cancel button combo when viewing as an admin
function topicedit(id,catid){
	var titleelement = document.getElementById("toptitle" + id);  //get the topic title paragraph
	var titleTD = document.getElementById("toptitleTD" + id);  //get the topic title table data
	var controlselement = document.getElementById("topcontrols" + id);  //get the admin button area td
	
	var title = titleelement.firstChild.nodeValue; //get the contents of the title	
	
	//inputs html into title area
	titleTD.innerHTML = "<span class='forumlink'>Subject:&nbsp;</span><br/><input type='text' maxlength='255' id='TBsubjectedit" + id + "' value='" + title + "' />";
	//inputs new buttons into admin area
	controlselement.innerHTML = "<input id='BTNsave" + id + "' type='button' value='Save' onclick='topicsave(" + id + ")' />&nbsp;<input id='BTNcancel" + id + "' type='button' value='Cancel' onclick='topiccancel(" + catid + ")' />";
}
function topiccancel(id){
	window.location = "forum.aspx?catid=" + id; //simple redirect back to forum main page
}
function topicsave(id){
	//assigns hidden variables and html objects assosiated when the topic we are saving to javascript variables
	//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
	//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
	var HDNsubject = document.getElementById("ctl00_cphContent_HFsubject");
	var HDNtopid = document.getElementById("ctl00_cphContent_HFtopid");
	var TBtitle = document.getElementById("TBsubjectedit" + id);
	
	//next save the ids passed to this function to the hidden variables
	HDNsubject.value = TBtitle.value;
	HDNtopid.value = id;
	
	//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
	__doPostBack('SaveEditTop','');
}
//this function deletes a topic from the forum
function topicdelete(id){
	//ask the user if they are sure they want to delete this topic
	var answer = confirm("Are you sure would you like to delete this Topic? This will delete all assosiated Posts and can not be undone!");
	//if the answer is yes
	if (answer){
		//assigns hidden variables assosiated when the topic we are deleting to javascript variables
		//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
		//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
		var HDNtopid = document.getElementById("ctl00_cphContent_HFtopid");
		
		//next save the id passed in this function to the hidden variable
		HDNtopid.value = id;
	
		//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
		__doPostBack('DeleteTop','');
	}
}
//this function replaces a forum topic and posts and it's edit / delete buttons with an editable areas and a save / cancel button combo when viewing topic details as an admin
function postedit(id,topid,catid,topic){	
	//this means this is the topic and not a post so we treat the ids a little differently
	if(topic == "true"){
		var postelement = document.getElementById("Tpostmessage" + id);  //get the post message paragraph
		var postTD = document.getElementById("TpostmessageTD" + id);  //get the post message table data
		var controlselement = document.getElementById("Tpostcontrols" + id);  //get the admin button area td
		
		var message = postelement.firstChild.nodeValue; //get the contents of the message
	
		//inputs html into message area, no difference
		postelement.innerHTML = "<span class='forumlink'>Message:</span><br/><textarea id='TAedit" + id + "' cols='60' rows='5'>" + message + "</textarea>";
		//inputs new buttons into admin area the only difference is the postsave variables
		controlselement.innerHTML = "<input id='BTNsave" + id + "' type='button' value='Save' onclick='postsave(" + id + ",\"true\")' />&nbsp;<input id='BTNcancel" + id + "' type='button' value='Cancel' onclick='postcancel(" + topid + "," + catid + ")' />";
	}
	else{
		var postelement = document.getElementById("Ppostmessage" + id);  //get the post message paragraph
		var postTD = document.getElementById("PpostmessageTD" + id);  //get the post message table data
		var controlselement = document.getElementById("Ppostcontrols" + id);  //get the admin button area td
		
		var message = postelement.firstChild.nodeValue; //get the contents of the message
		
		//inputs html into message area, no difference
		postelement.innerHTML = "<span class='forumlink'>Message:</span><br/><textarea id='TAedit" + id + "' cols='60' rows='5'>" + message + "</textarea>";
		//inputs new buttons into admin area the only difference is the postsave variables
		controlselement.innerHTML = "<input id='BTNsave" + id + "' type='button' value='Save' onclick='postsave(" + id + ",\"false\")' />&nbsp;<input id='BTNcancel" + id + "' type='button' value='Cancel' onclick='postcancel(" + topid + "," + catid + ")' />";
	}
}
function postcancel(topid,catid){
	window.location = "forum.aspx?catid=" + catid + "&topid=" + topid; //simple redirect back to forum topic page
}
function postsave(id,topic){
	//assigns hidden variables and html objects assosiated when the post we are saving to javascript variables
	//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
	//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
	var HDNmessage = document.getElementById("ctl00_cphContent_HFmessage");
	var HDNpostid = document.getElementById("ctl00_cphContent_HFpostid");
	var HDNtopid = document.getElementById("ctl00_cphContent_HFtopid");
	var TBmessage = document.getElementById("TAedit" + id);
	
	//next save the ids passed to this function to the hidden variables
	HDNmessage.value = TBmessage.value;
	
	if(topic == "true"){ //this means this is the topic and not a post so we treat the ids a little differently
		HDNtopid.value = id;
		HDNpostid.value = 0;
	}
	else{
		HDNpostid.value = id;
		HDNtopid.value = 0; //this is set so we know that 0 = not a topic
	}
	
	//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
	__doPostBack('SaveEditPost','');
}
//this function deletes a post from a topic
function postdelete(id,topic){
	if(topic == "true"){ //this means this is the topic and not a post so it affects the forum differently so the user must know this
		var alertmsg = "Are you sure would you like to delete this Topic? This will delete all assosiated Posts and can not be undone!";
	}
	else{
		var alertmsg = "Are you sure would you like to delete this Post? This can not be undone!";
	}
	//ask the user if they are sure they want to delete this topic
	var answer = confirm(alertmsg);
	//if the answer is yes
	if (answer){
		//assigns hidden variables assosiated when the topic we are deleting to javascript variables
		//the ids look weird because the hidden variables had to be declared in asp and asp modifies ids of controls that are runat=server for use in asp
		//for us to modify them in javascript we must referance them by their asp generated id, which is different from the one we set in asp itself.
		var HDNtopid = document.getElementById("ctl00_cphContent_HFtopid");
		var HDNpostid = document.getElementById("ctl00_cphContent_HFpostid");
		
		//next save the id passed in this function to the hidden variable
		if(topic == "true"){ //this means this is the topic and not a post so we treat the ids a little differently
			HDNtopid.value = id;
			HDNpostid.value = 0;
		}
		else{
			HDNpostid.value = id;
			HDNtopid.value = 0; //this is set so we know that 0 = not a topic
		}

		//call the postback function with the (asp)ID of the linkbutton, therefore tricking asp into thinking the linkbutton caused a postback
		__doPostBack('DeletePost','');
	}
}