author = email = url = comment = 0;

function checkForm(val)
{
	if(val==0)
	{
		//check name
		if(document.getElementById("author").value == "")
		{
			author = 0;
			document.getElementById("author").setAttribute('style', 'border-color:#FF0000;border-width:2px;');
		}
		else
		{
			author = 1;
			document.getElementById("author").setAttribute('style', 'border-width: 1px;border-color: #C8C8C8;');
			finalCheck();
		}
		//check email
		if(document.getElementById("email").value == "")
		{
			email = 0;
			document.getElementById("email").setAttribute('style', 'border-color:#FF0000;border-width:2px;');
		}
		else
		{
			email = document.getElementById("email").value
			AtPos = email.indexOf("@")
			StopPos = email.lastIndexOf(".")
			
			if (AtPos == -1 || StopPos == -1) 
			{
				email = 0;
				document.getElementById("email").setAttribute('style', 'border-color:#FF0000;border-width:2px;');
			}
			else
			{
				email = 1;
				document.getElementById("email").setAttribute('style', 'border-width: 1px;border-color: #C8C8C8;');
				finalCheck();
			}
		}
		//check comment
		if(document.getElementById("comment").value == "")
		{
			comment = 0;
			document.getElementById("comment").setAttribute('style', 'border-color:#FF0000;border-width:2px;');
		}
		else
		{
			comment = 1;
			document.getElementById("comment").setAttribute('style', 'border-width: 1px;border-color: #C8C8C8;');
			finalCheck();
		}
	}
	else if(val==1)
	{
		//check comment
		if(document.getElementById("comment").value == "")
		{
			comment = 0;
			document.getElementById("comment").setAttribute('style', 'border-color:#FF0000;border-width:2px;');
		}
		else
		{
			comment = 1;
			document.getElementById("comment").setAttribute('style', 'border-width: 1px;border-color: #C8C8C8;');
			finalCheck2();
		}
	}
}

function finalCheck()
{
	if(author==1 && email==1 && comment==1)
	{
		var formObj = document.getElementById('commentform');
		formObj.submit();	
	}
}

function finalCheck2()
{
	if(comment==1)
	{
		var formObj = document.getElementById('commentform');
		formObj.submit();	
	}
}
