function checkField(sField,sValue,bRequired,iMin,iMax)
{
	var strError = "";
	var sStrip = sValue;
	sStrip = sStrip.replace(/ /g, "");
	if (sStrip.length == 0 && bRequired)
	{
		strError += "\t" + sField + " field is required\n";
		return strError;
	}
	if (sValue.length > 0)
	{
		if (iMin > 0 && sValue.length < iMin)
			strError += "\t" + sField + " field should have min. " + iMin + " chars\n";
		else if (iMax > 0 && sValue.length > iMax)
			strError += "\t" + sField + " field should have max. " + iMax + " chars\n";
	}
	return strError;
}
function checkSelectField(sField,iIndex)
{
	var strError = "";
	if (iIndex == 0)
		strError += "\t" + sField + " field is required\n";
	return strError;
}
function checkIntField(sField,sValue,bRequired,iMin,iMax)
{
	var strError = "";
	var sStrip = sValue;
	sStrip = sStrip.replace(/ /g, "");
	if (sStrip.length == 0 && bRequired)
	{
		strError += "\t" + sField + " field is required\n";
		return strError;
	}

	var iValue = parseInt(sValue);
	if (isNaN(iValue)) {
		strError += "\t" + sField + " field should be an integer number\n";
		return strError;
	}

	if (sValue.indexOf(".") > -1) {
		strError += "\t" + sField + " field should be an integer number\n";
		return strError;
	}

	if (iValue < iMin)
		strError += "\t" + sField + " field should not be less than " + iMin + "\n";
	else if (iValue > iMax)
		strError += "\t" + sField + " field should not be more than " + iMax + "\n";
	return strError;
}
function checkFloatField(sField,sValue,bRequired,iMin,iMax)
{
	var strError = "";
	var sStrip = sValue;
	sStrip = sStrip.replace(/ /g, "");
	if (sStrip.length == 0 && bRequired)
	{
		strError += "\t" + sField + " field is required\n";
		return strError;
	}

	var iValue = parseFloat(sValue);
	if (isNaN(iValue)) {
		strError += "\t" + sField + " field should be a number\n";
		return strError;
	}

	if (iValue < iMin)
		strError += "\t" + sField + " field should not be less than " + iMin + "\n";
	else if (iValue > iMax)
		strError += "\t" + sField + " field should not be more than " + iMax + "\n";
	return strError;
}

function checkEmailField(sField, sValue, bRequired, iMin, iMax)
{
	var strError = checkField(sField, sValue, bRequired, iMin, iMax);
	if (strError.length > 0) return strError;
	var sStrip = sValue;
	sStrip = sStrip.replace(/ /g, "");
	if (bRequired || sStrip.length > 0)
	{
		var p = sStrip.indexOf("@");
		if (p >= 0)
		{
			if (sStrip.substring(p + 1).indexOf(".") >= 0)
				return "";
		}
		return "\t" + sField + " field should be valid e-mail address\n";
	}
	return "";
}


