//=================================================================================
//	101 Media Ltd - SmartWebb
//	(c) 2000 101 Media Ltd
//	http://www.101ltd.com
//=================================================================================

var objForm = document.forms[document.forms.length - 1];

//-----------------------------------------------------------------------------
// Validation functions
//-----------------------------------------------------------------------------

function TooShort(objTest, intSize, strWarning)
{
	if (objTest.value.length < intSize)
	{
		window.alert(strWarning);
		objTest.focus();
		objTest.select();
		return true;
	}
	return false;
}

function TooLong(objTest, intSize, strWarning)
{
	if (objTest.value.length > intSize)
	{
		window.alert(strWarning);
		objTest.focus();
		objTest.select();
		return true;
	}
	return false;
}

function BadText(objTest)
{
	if (objTest.value.indexOf('&') > 0 || objTest.value.indexOf('#') > 0)
	{
		window.alert("'&' and '#' signs are not allowed in text fields.");
		objTest.focus();
		objTest.select();
		return true;
	}
	return false;
}

function BadSQL(objTest)
{
	if (objTest.value != "")
	{
		if (objTest.value.indexOf("%") >= 0 || objTest.value.indexOf("#") >= 0)
		{
			window.alert("Please remove % and # characters");
			objTest.focus();
			objTest.select();
			return true;
		}
	}
	return false;
}

function BadEmail(objTest)
{
	var ixAt = objTest.value.indexOf("@");
	var ixDot = objTest.value.indexOf(".");
	var lenObj = objTest.value.length;
	if (objTest.value == "" || ixAt < 1 || ixDot < 1 || lenObj < (ixDot + 2))
	{
		window.alert("Please enter a valid Email address");
		objTest.focus();
		objTest.select();
		return true;
	}
	return false;
}

function BadItem(objTest, strWarning)
{
	if (objTest.selectedIndex == 0)
	{
		window.alert(strWarning);
		objTest.focus();
		return true;
	}
	return false;
}

function BadItems(objTest, objTest2, strWarning)
{
	if (objTest.selectedIndex == 0 && objTest2.selectedIndex == 0  )
	{
		window.alert(strWarning);
		objTest.focus();
		return true;
	}
	return false;
}


function BadNumber(objTest, strWarning)
{
	var strMask = /^[ ]*[+-]?\d*\.?\d*([eE][+-]?\d+)?[ ]*$/;

	if (strMask.test(objTest.value) == false)
	{
		window.alert(strWarning);
		objTest.focus();
		objTest.select();
		return true;
	}
	return false;
}

function BadDate(objTest)
{
	var strDate = objTest.value;
	var vOut = strDate.split(new RegExp("[/]"));

	if (vOut.length == 3)
	{
		var vNewDate = new Date(vOut[2],vOut[1]-1,vOut[0])
		if (vNewDate.getFullYear() == parseInt(vOut[2],10) && vNewDate.getMonth() == (parseInt(vOut[1],10) - 1) && vNewDate.getDate() == parseInt(vOut[0],10))
		{
			if (vNewDate.getFullYear() > 1990 && vNewDate.getFullYear() < 2099)
			{
				return false;
			}
			else
			{
				window.alert("Please enter a date between 1990 and 2099");
			}	
		}
		else
		{
			window.alert("Please enter a valid date in the format dd/mm/yyyy");
		}
	}
	else
	{
		window.alert("Please enter a date in the format dd/mm/yyyy");
	}

	objTest.focus();
	objTest.select();
	return true;
}

function ConvertDate(strDate)
{
	var intOut = strDate.split(new RegExp("[/]"));
	if (intOut.length == 3)
	{
		return (new Date(intOut[2],intOut[1]-1,intOut[0]));
	}
	else	
	{
		return new Date();
	}
}

function BadTime(objTest)
{
	var strTime = objTest.value
	var vRes = strTime.split(new RegExp("[:]"));
	
	if (vRes.length == 2)
	{
		if (vRes[0] <= 23 && vRes[0] >= 00)
		{
			if (vRes[1] <= 59 && vRes[1] >= 00)
			{
				return false;
			}
			else
			{
				window.alert("Please enter a valid time in the format hh:mm");
			}
		}
		else
		{
			window.alert("Please enter a valid time in the format hh:mm");
		}
	}
	else
	{
		window.alert("Please enter the time in the format hh:mm");
	}
	
	objTest.focus();
	objTest.select();
	return true;	
}
