function validate_num(strNum, fldName, fldLabel)
{

	if(!strNum == "")
	{
		if(strNum.indexOf("$") > -1 || strNum.indexOf(",") > 0)
		{
			window.alert(fldLabel + " must be a Number, No $ or ,")
			return false;
		}
		if(isNaN(strNum)) {
			window.alert(fldLabel + " must be a Number.")
			return false;
		}
	}
	return true;
}


function validate_memo(strMemo, fldName, fldLabel, fldSize)
{
	if(!strMemo == "")
	{
		if(strMemo.length > fldSize)
		{
			alert(fldLabel + " must be Less than " + fldSize )
			return false;
		}
	}
	return true;
}


function validate_date(strDate, fldName, fldLabel)
{
	var x
	var strSplit = new String(strDate)
	var date_array = new Array();
	var testDate;
	
	date_array = strSplit.split(" ")
	date_array = date_array[0].split("/")

	if(!strDate == "")
	{
		
		x = Date.parse(strDate);
		

		if(isNaN(x) || date_array.length != 3)
		{
			
			alert(fldLabel + " must be a date.")
			return false;
		}
		
		if(date_array[0].length < 1 || date_array[0].length > 2)
		{
			alert(fldLabel + " has an invalid month.")
			return false;
		}

		if(date_array[2].length > 4 || date_array[2].valueOf() < 0)
		{
			alert(fldLabel + " has an invalid year.")
			return false;
		}


		
		testDate = new Date(date_array[2], date_array[0] - 1, date_array[1]);
		if (testDate.getMonth() != date_array[0] - 1)
		{
			alert(fldLabel + " must be a date.")
			return false;
		}
	}
	
	return true;
}


function validate_date_time(strMonth, strDay, strYear, strHour, strMinute, strAMPM, fldLabel, hidBox, required)
{
	var x
	var y
	var strDate = new String(strMonth + "/" + strDay + "/" + strYear + " " + strHour + ":" + strMinute + ":00 " + strAMPM)
	// alert(strDate)
	if(strDate.length == 22)
	{

		x = new Date(strYear, strMonth - 1, strDay)

		if(x.getMonth() != strMonth - 1)
		{
			alert(fldLabel + " must be a date.")

			hidBox.value = "";
			return false;
		}
		hidBox.value = strDate;
	}
	else
	{
		if(strDate.length != 8) {
			alert("Invalid " + fldLabel)
			hidBox.value = "";
			return false;
		}
		if(required == true) {
			alert("You must enter a " + fldLabel)
			hidBox.value = "";
			return false;
		}
	}

	return true;
}

function validate_date_dd(strMonth, strDay, strYear, fldLabel, hidBox, required)
{
	var x
	var y
	var strDate = new String(strMonth + "/" + strDay + "/" + strYear)
	// alert(strDate)
	if(strDate.length == 10)
	{

		x = new Date(strYear, strMonth - 1, strDay)

		if(x.getMonth() != strMonth - 1)
		{
			
			alert(fldLabel + " must be a date.")
			hidBox.value = "";
			return false;
		}
		hidBox.value = strDate;
	}
	else
	{
		if(strDate.length != 2) {
			alert("Invalid " + fldLabel)
			hidBox.value = "";
			return false;
		}
		
		if(required == true) {
			alert("You must enter a " + fldLabel)
			hidBox.value = "";
			return false;
		}
	}

	return true;
}



function ltrim(strTrim)
{
	var str = new String(strTrim);
	var retstr = new String("");
	for (k = 0; k < str.length; k++)
	{
		if (str.charAt(k) != " ")
   		{
			retstr = str.substr(k);
			break;
 		}
	}
	return retstr;
}


function rtrim(strTrim)
{
	var str = new String(strTrim);
	var retstr = new String("");
	for (k = str.length - 1; k >= 0; k--)
	{
		if (str.charAt(k) != " ")
   		{
			retstr = str.substr(0,k+1);
			break;
 		}
	}
	return retstr;
}

function trim(strTrim)
{
	var x = new String(strTrim)
	x = ltrim(x)
	x = ytrim(x)
	return x;
}



function replace_norm(ser, strFind, rep)
{
	var y = new Array()
	var i
	var mainString = new String(ser)
	var newStr = new String("")
	var strSearch = new String(strFind)
	var strReplace = new String(rep)
	
	y = mainString.split(strSearch)

	for(i = 0; i < y.length; i++)
	{
		newStr = newStr + y[i] + strReplace

	}
	newStr = newStr.substr(0, newStr.length - strReplace.length)

	return newStr;

}
