function editComment(id)
{
	document.main.action = "showPage.php?ID="+id+"&EDITCOMMENT=1";
	
	document.main.submit();
}



function previewComment(id)
{
	document.main.action = "showPage.php?ID="+id+"&PREVIEWCOMMENT=1";
	document.main.submit();
	
}

function saveComments(id)
{
	document.main.action="saveComments.php?ID="+id;
	document.main.submit();
	
}

function loginCommentsUser()
{
	var commentPassword = document.getElementById("commentPassword");
	var commentUsername = document.getElementById("commentUsername");
	
	if (commentUsername.value.length==0)
	{
		alert("Please enter your username.");
		commentUsername.focus();
		
		return false;	
	}
	
	if (commentPassword.value.length==0)
	{
		alert("Please enter your password.");
		commentUsername.focus();
		
		return false;	
	}
	
	document.main.action="loginCommentUser.php";
	document.main.submit();
}

function forgotPassword()
{
	
	MM_openBrWindow('forgotPassword.php','','resizable=no,scrollbars=yes,width=500,height=500');
	
}

function addNewUser()
{
	
	MM_openBrWindow('addNewCommentsUser.php','','resizable=no,scrollbars=yes,width=500,height=500');
	
}
function checkPasswords()
{
	var password = document.getElementById("commentPassword");
	var confirmPassword = document.getElementById("commentConfirmPassword");
	
	if (password.value!=confirmPassword.value)
	{
		alert("Passwords do not match");
		return false;
	}
	
	return true;
}
function validateUserForm()
{
	var formFields = ["commentUsername","commentPassword","commentConfirmPassword","commentName","commentSurname","commentEmail"];
	
	for (i = 0;i<formFields.length;i++)
	{
		var field = document.getElementById(formFields[i]);
		
		if (field==null)
			alert("ERROR");
		else
		{
			if (field.value.length==0)
			{
				var label = document.getElementById(formFields[i]+"Label");
				
				alert("Please enter value for "+label.innerHTML.replace(/:/, ""));
				field.focus();
				
				return false;
			}
			
			if (formFields[i]=="commentPassword")
			{
				if (field.value.length<8)
				{
					alert("Passwords should be at least 8 characters long.");
					return false;
				}
			}
		}
	}
	
	if (!checkPasswords())
	{
		return false;
	}
	
	
	return true;
}

function validateForgotForm()
{
	var formFields = ["commentUsername","commentEmail"];
	
	for (i = 0;i<formFields.length;i++)
	{
		var field = document.getElementById(formFields[i]);
		
		if (field==null)
			alert("ERROR");
		else
		{
			if (field.value.length==0)
			{
				var label = document.getElementById(formFields[i]+"Label");
				
				alert("Please enter value for "+label.innerHTML.replace(/:/, ""));
				field.focus();
				
				return false;
			}
			
			if (formFields[i]=="commentPassword")
			{
				if (field.value.length<8)
				{
					alert("Passwords should be at least 8 characters long.");
					return false;
				}
			}
		}
	}
	
	if (!checkPasswords())
	{
		return false;
	}
	
	
	return true;
}