function isBlank(strFormName, strFieldName) {
	var strReturned = new String(noSpace(document.forms[strFormName].elements[strFieldName].value));
	if (strReturned.length > 0) {
		return false;
	}
return true;
}

function noSpace(strInText) {
	var strOutText = '';
	var strArrayOfText = strInText.split(' ');
	for (var intCounter = 0;  intCounter < strArrayOfText.length; intCounter++) {
		strOutText = strOutText + strArrayOfText[intCounter];
	}
 return strOutText;
}

function isValidFilename(strInText) {
	// search for \ (NS has problems searching for this character in a regular expression)
  if (strInText.indexOf("\\") != -1) {
  	return false;
  } else {
	// search for ', /, :, *, ?, ", <, >, |, or .
	var strFlags = new String('gi') // g: global match, i: ignore case, gi: both
	var strPattern = new String('[\/:\*?"<>|.\']');
	// IE 5.0 has a problem dealing without a variable being set for the regular expression
	var re = new RegExp(strPattern, strFlags);
	return (!re.test(strInText));
  }
}

function isDate(strFormName, strFieldName) {
	var strInText = new Date(document.forms[strFormName].elements[strFieldName].value)
	strInText = new String(strInText);
	if ((strInText.toUpperCase().indexOf("INVALID") != -1) || (strInText.toUpperCase().indexOf("NAN") != -1) ) {
		return false;
	}
	return true;
}
function checkMonthLength(mm,dd){
 if ((mm==4 || mm ==6 || mm==9 || mm==11) && dd > 30){
	 return false
	}else if (dd > 31){
		 return false
	}
	return true
}
		// entered month to high a value

// check February date to high a value
function checkLeapMonth(mm,dd,yyyy)
{
	if (yyyy %4  > 0 && dd > 28){
		return false;
	}else if (dd > 29){
		return false;
	}
return true;
}
function isDateVal(strVal)
{
	var inputStr=strVal;
	
	var zMonth = new Array                  // Array of months (for date mask)
		('January','February','March',
		 'April','May','June','July',
		 'August','September','October',
		 'November','December');
	//alert(inputStr);
	if (inputStr==""){
		return false;
	}
	
	if ((inputStr.indexOf("-") == -1) && (inputStr.indexOf("/") == -1)){
		// there are NO delimiters extract components
		var dd = parseInt(inputStr.substring(0,2));
		var testmm = new String(inputStr.substring(3,6));
		
		if (testmm.length == 3){
			for (var i = 0; i <= 11; i++)
			{
			 var teststring=zMonth[i].substring(0,3)
				if (teststring.toUpperCase() == testmm.toUpperCase()){
				 mm=parseInt(i+1,10);
				}
			}
		}
		else
		{
			var mm = parseInt(testmm,10);
		}
		var yyyy = parseInt(inputStr.substring(7,inputStr.length));
		var delim1 = -1;
	}	
	
	//convert hyphen delimiters to slashes
	while (inputStr.indexOf("-") != -1){
		inputStr = inputStr.replace("-","/")		
	}
	
	//check gross format
	var delim1 = inputStr.indexOf("/");
	var delim2 = inputStr.lastIndexOf("/");
	if (delim1 != -1 && delim1 == delim2){
		// only one delimiter in string
		return false;
	}
	
	//specify base 10 conversions because two digit entries might contain zeros
	if (delim1 != -1){
	// there are delimiters extract components
		var dd = parseInt(inputStr.substring(0,delim1),10);

		var testmm = new String(inputStr.substring(delim1+1,delim2));
		if (testmm.length == 3){
			for (var i = 0; i <= 11; i++)
			{
			 var teststring=zMonth[i].substring(0,3)
				if (teststring.toUpperCase() == testmm.toUpperCase()){
				 mm=parseInt(i+1,10);
				}
			}
		}
		else
		{
			var mm = parseInt(testmm,10);
		}
		var yyyy = parseInt(inputStr.substring(delim2+1,inputStr.length),10);
	}
	//alert("month" +mm);
	//alert("day"+dd);
	//alert("year"+yyyy);
	if(isNaN(mm) || isNaN(dd) || isNaN(yyyy)){
	// there is a non numeric character  in one of the components
		//alert("help non numeric");
		return false;
	}
	// validate month
	if (mm < 1 || mm >12) {
		// month value is not 1 to 12
		//	alert("help non numeric");
		return false;
	}
	//validate day
	if (dd < 1 || dd >31) {
		//alert("validate day");
		// date value is not 1 to 31
		return false;
	}
	if (!checkMonthLength(mm,dd)){
		//alert("help checkMonthLength");
		return false;
	}
	if (mm == 2){
		if (!checkLeapMonth(mm,dd,yyyy)){
		//alert("help checkLeapMonth");
		return false;
		}
	}
	var strInText = new Date(strVal);
	theYear = strInText.getFullYear();
	if (parseInt(theYear) < 1900) {
		return false;
	}
	return true;
}
function isCurrency(strInput) {
 var oRegExp = /\d+\.?\d{0,2}/
 strInput = strInput.replace(",", "");
 return (strInput == oRegExp.exec(strInput));
}

function setBgColor(strFormName, strFieldName) {
	document.forms[strFormName].elements[strFieldName].style.backgroundColor='salmon';
}

function stripInvalid(oField) {
	var oRegExp = /[^\\ABCDEFGHIJKLMNOPQRSTUVWXYZ/n0123456789\.\$\#\,\&\(\)\-\_ \:\;]/gi
	oField.value = oField.value.replace(oRegExp, '');
}

function stopVerbose(oField, iMaxLength) {
	var iFieldLength = oField.value.length
	if (iFieldLength > iMaxLength) oField.value = oField.value.substring(0, iMaxLength);
}

function isZero(strFormName, strFieldName) {
	if(parseInt(document.forms[strFormName].elements[strFieldName].value) == 0) {
		return true;
	}
	return false;
}

function isNumeric(strFormName, strFieldName) {
	return (!isNaN(new Number(document.forms[strFormName].elements[strFieldName].value)));
}

function isNumericVal(strVal) {
	return (!isNaN(new Number(strVal)));
}

function doKeyValidationPress()
{
     var iKeyCode
     if (window.event) 
     {
          
          iKeyCode = window.event.keyCode;
     }
	else if (e) 
     {
          iKeyCode = e.which;
     }
	else 
     {
          return;
	}

	if ( ! ( (iKeyCode == 32)  || (iKeyCode >= 34 && iKeyCode <= 41) ||  (iKeyCode >= 44 && iKeyCode <= 57) || (iKeyCode >= 65 && iKeyCode <= 90) || (iKeyCode >= 96 && iKeyCode <= 122)  ) ) 
	{
          window.event.returnValue = false;
	}

}
