function PackString (szString, cCharToRemove)
{
    var inLen = szString.length;
    var szTmp = "";
    var iInit, iEnd, i;

    for (iInit = 0; iInit < inLen && szString.charAt (iInit) == cCharToRemove; 
																	iInit++);
    if (iInit < inLen) {
        for (iEnd = inLen - 1; iEnd > 0 && 
							szString.charAt (iEnd) == cCharToRemove; iEnd--);
        for (i = iInit; i <= iEnd; i++)
            szTmp += szString.charAt (i);
    }
    return (szTmp);
}

function CheckNumField (theField, FieldName, CheckNull, UseLocalAlerts)
{
	var inStr, nValue;
	var nLen;

	
	if (!theField)
		return (true);

	if (theField.type == "select-one") {
        if (theField.selectedIndex != -1)
            inStr = theField.options[theField.selectedIndex].value;
        else
            inStr = theField.options[0].value;
    }
	else
		inStr = theField.value;
	nLen = inStr.length;
	if (CheckNull && !nLen) {
		if (UseLocalAlerts)
			alert (Sprintf(szMsgField, FieldName));
		return (false);
	}
	for (i = 0; i < nLen; i++) {
		if (inStr.charAt (i) < '0' || inStr.charAt (i) > '9')
			if  (i || inStr.charAt (i) != '-')
				break;
	}
	if (i < nLen) {
		if (UseLocalAlerts)
			alert (Sprintf(szMsgInt, FieldName)) ;
		return (false);
	}
	return (true);
}

function CheckField (theField, FieldName, NotValidSet, CheckNull, UseLocalAlerts, Packing)
{
	var inLenNVS = NotValidSet.length;
	var inStr, inLen, Value, ValueNVS;

	if (!theField)
		return (true);
	if (Packing)
		theField.value = PackString (theField.value, ' ');
	inStr = theField.value;
	inLen = inStr.length;
	if (CheckNull && inLen == 0) {
		if (UseLocalAlerts)
			alert (Sprintf(szMsgField, FieldName));
		return (false);
	}
	for (i = 0; i < inLen; i++) {
		Value = inStr.charAt(i);
		for (j = 0; j < inLenNVS; j++) {	
			ValueNVS = NotValidSet.charAt(j);
			if (Value == ValueNVS) {
				if (UseLocalAlerts) {
					szMsg = Sprintf(szMsgContent, FieldName) ;
					szMsg += NotValidSet;
					alert(szMsg);
				}
				return (false);
			}
		}
	}	
	return (true);
}	

function LengthControl (theField, nLength, FieldName)
{
	if (!theField)
		return (true);
	var strDigited = theField.value;
	
	if (strDigited.length > nLength) {	
		var strBuff = Sprintf(szMsgField1, FieldName) ;
		strBuff += Sprintf(szMsgField2, strDigited.length) ;
		strBuff += Sprintf(szMsgField3, nLength) ;
		alert (strBuff);
		theField.focus ();
		return (false);
	}
	return (true);
}

function MinLengthControl (theField, nLength, FieldName, bCheckIfNull)
{
	if (!theField)
		return (true);
	var strDigited = theField.value;
	
	if (strDigited.length < nLength) {	
		if (!bCheckIfNull && strDigited.length == 0)
			return (true);
		var strBuff = Sprintf(szMsgField4, FieldName) ;
		strBuff += Sprintf(szMsgField2, strDigited.length) ;
		strBuff += Sprintf(szMsgField5, nLength) ;
		alert (strBuff);
		theField.focus ();
		return (false);
	}
	return (true);
}


