
//
//	User JavaScript Validator File
//
//	Version 1.01.0001 (13.05.2006)
//
//	Copyright(c) 2006 by Petio Tonev
//
//	Revision history:
//
//		13.05.2006 -- initial version
//
//	Internal identifiers start with: __
//

//
//	stringTrim(string)
//
function stringTrim(str)
{
	s = str.replace(/^(\s)*/, '');
	s = s.replace(/(\s)*$/, '');

	return s;
}

//
//	validateEMail(string)
//
function validateEMail(str)
{
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//
//	formRegisterValidate(form)
//
function formRegisterValidate(form)
{
	//
	//	check editLogin field
	var text = new String(form.editLogin.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid login name.\n\r');

		return false;
	}

	//
	//	check editPassword field
	var text = new String(form.editPassword.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid password.\n\r');

		return false;
	}

	//
	//	check editPassword field
	var text2 = new String(form.editPassword2.value);
	text2 = stringTrim(text2);

	if(text2.length == 0)
	{
		alert('\n\r - Invalid password (check).\n\r');

		return false;
	}

	//
	//	check editPassword = editPassword2 field
	if(text != text2)
	{
		alert('\n\r - Invalid password (check).\n\r');

		return false;
	}

	//
	//	check editName field
	var text = new String(form.editName.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid full name.\n\r');

		return false;
	}

	//
	//	check editEmail field
	var text = new String(form.editEmail.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid email.\n\r');

		return false;
	}

	if(!validateEMail(text))
	{
		alert('\n\r - Invalid email.\n\r');

		return false;
	}

	return true;
}

//
//	formLoginValidate(form)
//
function formLoginValidate(form)
{
	//
	//	check editLogin field
	var text = new String(form.editLogin.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid login name.\n\r');

		return false;
	}

	//
	//	check editPassword field
	var text = new String(form.editPassword.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid password.\n\r');

		return false;
	}

	return true;
}

//
//	formRememberValidate(form)
//
function formRememberValidate(form)
{
	//
	//	check editLogin field
	var text = new String(form.editLogin.value);
	text = stringTrim(text);

	if(text.length == 0)
	{
		alert('\n\r - Invalid login name.\n\r');

		return false;
	}

	return true;
}