/****************************************************************
* Author:	Boyan B. Boychev
* Website:	http://www.boyan-bg.com/
* Contact:	http://www.boyan-bg.com/Autobiography.php#Contact_Information
*			Errors, suggestions or comments
* Date:		02 July 2009
* Version:	1.2
* Purpose:	Validate comment form
* Use:		You are free to use this script in non-commercial
*			applications. You are however required to leave
*			this comment at the top of this file.
*
*			I'd love an email if you find a use for it on your 
*			site, though not required.
****************************************************************/

function validateALL(admin)
{
if (validateAuthor(document.commentform.author.id, admin) == true)
	if (validateEmail(document.commentform.email.id) == true)
		if (validateComment(document.commentform.comment.id) == true)
			validateAuth_Number(document.commentform.auth_number.id);

return true;
}

function validateAuthor(x, admin)
{
var y = document.getElementById(x).value;
var match1 = /Boyan/i.test(y); /* true */
var match2 = /Boychev/i.test(y); /* true */

var match3 = /Боян/i.test(y); /* true */
var match4 = /Бойчев/i.test(y); /* true */

if (y == "")
	{
	document.getElementById(x).value="";
	alert ("Моля въведете име!");
	return false;
	}
else
	if (admin == "no") {
		if ((match1 == true && match2 == true) || (match3 == true && match4 == true))
			{
			document.getElementById(x).value="";
			alert ("Използвайте име различно от Боян Бойчев/Boyan Boychev!");
			return false;
			}
		else return true;
	}
	return true;
}

function validateEmail(x)
{
var y = document.getElementById(x).value;
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

if (emailPattern.test(y) != true)
	{
	document.getElementById(x).value="";
	alert ("Грешка! Неправилен e-mail адрес. Моля опитайте отново.");
	return false;
	}
else return true;
}

function validateComment(x)
{
var y = document.getElementById(x).value;

if (y == "")
	{
	document.getElementById(x).value="";
	alert ("Моля въведете коментар!");
	return false;
	}
else return true;
}

function validateAuth_Number(x)
{
var y = document.getElementById(x).value;

if (y == "")
	{
	document.getElementById(x).value="";
	alert ("Моля въведете изобразения код!");
	return false;
	}
else return true;
}

