function checkString(qstrName, qstrValue, qiMinLength, qiMaxLength)
{
	if (qstrValue.length < qiMinLength || qstrValue.length > qiMaxLength)
	{
		alert(qstrName+" must be "+qiMinLength+" - "+qiMaxLength+" characters long");
		return false;
	}
	return true;
}

function checkInt(qstrName, qstrValue, qiMin, qiMax)
{
	if (qstrValue != '')
	{
		iValue = parseInt(qstrValue);
		if (isNaN(iValue))
		{
			alert(qstrName+" must be numeric");
			return false;
		}
		else
		{
			if (iValue < qiMin || iValue > qiMax)
			{
				alert(qstrName+" must be in range "+qiMin+" - "+qiMax);
				return false;
			}
		}
	}
	return true;

}

function checkMoney(qstrName, qstrValue, qfMin, qfMax)
{
	if (qstrValue != '')
	{
		fValue = parseFloat(qstrValue);
		if (isNaN(fValue))
		{
			alert(qstrName+" must be numeric");
			return false;
		}
		else
		{
			if (fValue < qfMin || fValue > qfMax)
			{
				alert(qstrName+" must be in range "+qfMin+" - "+qfMax);
				return false;
			}
		}
	}
	return true;

}

function checkFloat(qstrName, qstrValue, qfMin, qfMax)
{
	if (qstrValue != '')
	{
		fValue = parseFloat(qstrValue);
		if (isNaN(fValue))
		{
			alert(qstrName+" must be numeric");
			return false;
		}
		else
		{
			if (fValue < qfMin || fValue > qfMax)
			{
				alert(qstrName+" must be in range "+qfMin+" - "+qfMax);
				return false;
			}
		}
	}
	return true;

}

function checkPassword(qstrName, qstrValue, qiMin, qiMax, qiAction)
{
	if (qiAction == 1 && qstrValue.length == 0)
	{
		alert(qstrName+" cannot be blank");
		return false;
	}
	else
	{
		if (qstrValue != "")
		{
			if (qstrValue.length < qiMin || qstrValue.length > qiMax)
			{
				alert(qstrName+" must be "+qiMin+" - "+qiMax+" characters long");
				return false;
			}
			else
			{
				if (hasIllegal(qstrValue))
				{
					alert(qstrName+" contains illegal character(s)");
					return false;
				}
			}
		}
	}
	return true;
}

function hasIllegal(qstr)
{
	if (qstr.indexOf('\'') > -1 || qstr.indexOf('"') > -1 || qstr.indexOf('%') > -1 || qstr.indexOf('_') > -1)
		return true;
	return false;	
}

function comparePasswords(qstrPword1, qstrPword2)
{
	if  (qstrPword1 != qstrPword2)
	{
		alert("Repeat password doesn't match original");
		return false;
	}
	return true;
}

function checkEmail(qstrName, qstrValue)
{
	if (qstrValue.length < 7)
	{
		alert(qstrName+" must be at least 7 characters long");
		return false;
	}
	else
	{
		iAt = qstrValue.indexOf("@");
		if (iAt == -1)
		{
			alert(qstrName+" invalid, no @");
			return false;
		}
		else
		{
			iDot = qstrValue.lastIndexOf(".");
			if (iDot - iAt < 2)
			{
				alert(qstrName+" invalid, no dot after @");
				return false;
			}
		}
	}
	return true;
}

function checkConfirm(qstrName, qbValue)
{
	if (!qbValue)
	{
		alert("You must tick the "+qstrName);
		return false;
	}
	return true;
}

function checkPhone(qstrName, qstrValue)
{
	if (qstrValue == "" || qstrValue.match(/[0-9\. \-\(\)\+]+/))
		return true;
	else
		alert(qstrName+" contains invalid characters");
	return false;
}

function checkRadio(qstrName, qrads)
{
	for (i = 0; i < qrads.length; i++)
	{
		if (qrads[i].checked)
			return true;
	}
	alert("You must select an option on "+qstrName);
	return false;
}

function checkNumString(qstrName, qstrValue, qiMinLength, qiMaxLength)
{
	iLength = qstrValue.length;
	if (iLength < qiMinLength || iLength > qiMaxLength)
	{
		alert(qstrName+" must be "+qiMinLength+" - "+qiMaxLength+" characters long");
		return false;
	}
	else
	{
		if (iLength > 0)
		{
			iValue = parseInt(qstrValue);
			if (isNaN(iValue))
			{
				alert(qstrName+" must be a number");
				return false;
			}
		}
	}
	return true;
}
//
//	--- create an XMLHTTP object for AJAX
//
function createRequestObject()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if (browser == "Microsoft Internet Explorer")
	{
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}
//
//	--- find a form object through the DOM
//
function findDOM(qstrObjId)
{
	if (document.getElementById)
		return document.getElementById(qstrObjId);		// W3C Id DOM
	else
	{
		if (document.all)
			return document.all[qstrObjId];				// IE all DOM
		else
		{
				return document.layers[qstrObjId];		// Netscape layers DOM
		}
	}
}

