function isEmpty(formField)
{
	if (document.getElementsByName(formField)[0].value == "")
		return true;
	else
		return false;
}

function isNumber(formField)
{
	var d = document.getElementsByName(formField)[0].value;

	if (isNaN(Number(d)))
		return false;
	else
		return true;
}

function isValidYear(formField)
{
	var d = document.getElementsByName(formField)[0].value;

	if (isNaN(Number(d)))
		return false;

	var a = Number(document.getElementsByName(formField)[0].value);

	var d = new Date();
	var y = d.getFullYear() + 1;

	if (a < 1960)
		return false;

	if (a > y)
		return false;

	return true;
}

function validateAdvancedSearchForm(mainCriteria, yFrom, yTo)
{
	if (isEmpty(mainCriteria) == true)
	{
		alert('Search stopped! You must specify a search criteria.');
		return false;
	}

	if (isEmpty(yFrom) == false)
	{
		if (isValidYear(yFrom) == false)
		{
			alert('Search stopped! The YEAR (from) you specified is out of valid range.');
			return false;
		}
	}
	
	if (isEmpty(yTo) == false)
	{
		if (isValidYear(yTo) == false)
		{
			alert('Search stopped! The YEAR (to) you specified is out of valid range.');
			return false;
		}
	}
	
	if (isEmpty(yFrom) == false && isEmpty(yTo) == false)
	{
		var a = Number(document.getElementsByName(yFrom)[0].value);
		var b = Number(document.getElementsByName(yTo)[0].value);
		
		if (a > b)
		{
			alert('Search stopped! The YEAR from and to are not in valid order.');
			return false;
		}
	}
	
	return true;
}

function validateBasicSearchForm(mainCriteria)
{
	if (isEmpty(mainCriteria) == true)
	{
		alert('Search stopped! You must specify a search criteria.');
		return false;
	}
	
	return true;
}

function validateLoginForm(uname, passwd)
{
	if (isEmpty(uname) == true)
	{
		alert('Login stopped! You must specify a username.');
		return false;
	}
	
	if (isEmpty(passwd) == true)
	{
		alert('Login stopped! You must specify a password.');
		return false;
	}
	
	return true;
}

function validateProfileForm(passwd, titl, nam, comp, countr, em)
{
	if (isEmpty(passwd) == true)
	{
		alert('Update stopped! You must specify your current password.');
		return false;
	}

	if (isEmpty(nam) == true)
	{
		alert('Update stopped! You must specify your name.');
		return false;
	}

	if (isEmpty(comp) == true)
	{
		alert('Update stopped! You must specify your company.');
		return false;
	}
		
	if (isEmpty(em) == true)
	{
		alert('Update stopped! You must specify your e-mail.');
		return false;
	}
		
	return true;
}