function AccordianToggle(e)
{
	(document.getElementById(e).style.display != "block") ? document.getElementById(e).style.display = "block" : document.getElementById(e).style.display = "none";
}

function AccordianToggle2(e)
{	
	if (document.getElementById(e + "_ul").style.display != "block")
	{
		document.getElementById(e + "_ul").style.display = "block";
		document.getElementById(e + "_title").innerHTML = "-";
	}
	else
	{
		document.getElementById(e + "_ul").style.display = "none";
		document.getElementById(e + "_title").innerHTML = "+";
	}
}

function $(id)
{
	return document.getElementById(id);
}

function IsNullOrEmpty(string)
{
	var result = true;
	
	if (string != null && string.length > 0)
	{
		result = false;
	}
	
	return result;
}

function LoginValidate()
{
	var username = $("username").value;
	var password = $("password").value;
	
	if (!IsNullOrEmpty(username) && !IsNullOrEmpty(password))
	{
		$("loginForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(username))
		{
			$("username_Error").style.display = "block";
		}
		else
		{
			$("username_Error").style.display = "none";
		}

		if (IsNullOrEmpty(password))
		{
			$("password_Error").style.display = "block";
		}
		else
		{
			$("password_Error").style.display = "none";
		}

	}
}

function GmMessageValidate()
{
	var title = $("gmTitle").value;
	var body = $("gmBody").value;
	
	if (!IsNullOrEmpty(title) && !IsNullOrEmpty(body))
	{
		$("gmMessageForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(title))
		{
			$("gmTitle_Error").style.display = "block";
		}
		else
		{
			$("gmTitle_Error").style.display = "none";
		}

		if (IsNullOrEmpty(body))
		{
			$("gmBody_Error").style.display = "block";
		}
		else
		{
			$("gmBody_Error").style.display = "none";
		}

	}
}

function GuildNewsValidate()
{
	var title = $("gnTitle").value;
	var body = $("gnBody").value;
	
	if (!IsNullOrEmpty(title) && !IsNullOrEmpty(body))
	{
		$("guildNewsForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(title))
		{
			$("gnTitle_Error").style.display = "block";
		}
		else
		{
			$("gnTitle_Error").style.display = "none";
		}

		if (IsNullOrEmpty(body))
		{
			$("gnBody_Error").style.display = "block";
		}
		else
		{
			$("gnBody_Error").style.display = "none";
		}

	}
}

function EditGuildNewsValidate()
{
	var title = $("edit_gnTitle").value;
	var body = $("edit_gnBody").value;
	
	if (!IsNullOrEmpty(title) && !IsNullOrEmpty(body))
	{
		$("edit_guildNewsForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(title))
		{
			$("edit_gnTitle_Error").style.display = "block";
		}
		else
		{
			$("edit_gnTitle_Error").style.display = "none";
		}

		if (IsNullOrEmpty(body))
		{
			$("edit_gnBody_Error").style.display = "block";
		}
		else
		{
			$("edit_gnBody_Error").style.display = "none";
		}

	}
}

function AccomplishmentsValidate()
{
	var body = $("accBody").value;
	
	if (!IsNullOrEmpty(body))
	{
		$("accomplishmentsForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(body))
		{
			$("accBody_Error").style.display = "block";
		}
		else
		{
			$("accBody_Error").style.display = "none";
		}

	}
}

function EditAccomplishmentsValidate()
{
	var body = $("edit_accBody").value;
	
	if (!IsNullOrEmpty(body))
	{
		$("edit_accomplishmentsForm").submit();
	}
	else
	{
		if (IsNullOrEmpty(body))
		{
			$("edit_accBody_Error").style.display = "block";
		}
		else
		{
			$("edit_accBody_Error").style.display = "none";
		}

	}
}

function DisplayModal(id, contents)
{	
	var displayVar = $(id).style.display;
	
	if (displayVar != "block")
	{
		//var children = $(id).childNodes;
		//children[1].innerHTML = contents;
		var children = $(id).getElementsByTagName("div");
		children[0].innerHTML = contents;
		$(id).style.display = "block";
	}
	else
	{
		//var children = $(id).childNodes;
		var children = $(id).getElementsByTagName("div");
		$(id).style.display = "none";
		//children[1].innerHTML = "";
		children[0].innerHTML = "";
	}
}

function PopulateModal(type, el, id, item)
{
	var contentItem;
	//var children;
	var contents = ""

	switch(type)
	{
		case "news":
		{
			contentItem = el.parentNode.parentNode.parentNode.parentNode;
			var title = contentItem.getElementsByTagName("h2")[0].innerHTML;
			var body = contentItem.getElementsByTagName("p")[0].innerHTML;
			//children = contentItem.childNodes;

			contents += "<h2 style=\"text-align: left\">Edit Item</h2>\n";
			contents += "<form action=\"admin_guildnews_edit.php\" method=\"post\"  id=\"edit_guildNewsForm\">\n";
			contents += "<table cellpadding=\"0\" cellspacing=\"0\">\n";
			contents += "<tr>\n";
			contents += "<td>\n";
			contents += "<label for=\"edit_gnTitle\">Title</label>\n";
			//contents += "<input type=\"text\" name=\"edit_gnTitle\" id=\"edit_gnTitle\" value=\"" + children[3-ieAdjust].innerHTML + "\" />\n";
			contents += "<input type=\"text\" name=\"edit_gnTitle\" id=\"edit_gnTitle\" value=\"" + title + "\" />\n";
			contents += "<label for=\"edit_gnTitle\" id=\"gnTitle_Error\" class=\"formError\" style=\"display: none\">This field is required!</label>\n";
			contents += "</td>\n";
			contents += "</tr>\n";
			contents += "<tr>\n";
			contents += "<td>\n";
			contents += "<label for=\"gmBody\">Body</label>\n";
			//contents += "<textarea name=\"edit_gnBody\" id=\"edit_gnBody\">" + children[5-ieAdjust].innerHTML + "</textarea>\n";
			contents += "<textarea name=\"edit_gnBody\" id=\"edit_gnBody\">" + body + "</textarea>\n";
			contents += "<label for=\"edit_gnBody\" id=\"edit_gnBody_Error\" class=\"formError\" style=\"display: none\">This field is required!</label>\n";
			contents += "</td>\n";
			contents += "</tr>\n";
			contents += "<tr>\n";
			contents += "<td>\n";
			contents += "<input type=\"hidden\" value=\"" + item + "\" name=\"edit_id\" id=\"edit_id\" />\n";
			contents += "<input type=\"button\" value=\"Submit\" onclick=\"EditGuildNewsValidate()\" />\n";
			contents += "<input type=\"button\" value=\"Cancel\" onclick=\"DisplayModal('editModal', '')\" />\n";
			contents += "</td>\n";
			contents += "</tr>\n";
			contents += "</table>\n";
			contents += "</form>\n";
			
			break;
		}
		
		case "accomplishment":
		{
			contentItem = el.parentNode.parentNode;
			children = contentItem.getElementsByTagName("span");
		
			//alert(children.innerHTML);
			
			contents += "<h2 style=\"text-align: left\">Edit Item</h2>\n";
			contents += "<form action=\"admin_accomplishments_edit.php\" method=\"post\"  id=\"edit_accomplishmentsForm\">\n";
			contents += "<table cellpadding=\"0\" cellspacing=\"0\">\n";
			contents += "<tr>\n";
			contents += "<td>\n";
			contents += "<label for=\"edit_accBody\">Body</label>\n";
			contents += "<textarea name=\"edit_accBody\" id=\"edit_accBody\">" + children[0].innerHTML + "</textarea>\n";
			contents += "<label for=\"edit_accBody\" id=\"edit_accBody_Error\" class=\"formError\" style=\"display: none\">This field is required!</label>\n";
			contents += "</td>\n";
			contents += "</tr>\n";
			contents += "<tr>\n";
			contents += "<td>\n";
			contents += "<input type=\"hidden\" value=\"" + item + "\" name=\"edit_id\" id=\"edit_id\" />\n";
			contents += "<input type=\"button\" value=\"Submit\" onclick=\"EditAccomplishmentsValidate()\" />\n";
			contents += "<input type=\"button\" value=\"Cancel\" onclick=\"DisplayModal('editModal', '')\" />\n";
			contents += "</td>\n";
			contents += "</tr>\n";
			contents += "</table>\n";
			contents += "</form>\n";
		
			break;
		}
	}
	
	DisplayModal(id, contents);
}
