function CheckField (theField, FieldName, NotValidSet, CheckNull)
{
	var inLenNVS = NotValidSet.length;
	var inStr, inLen, Value, ValueNVS;

	if (!theField)
		return (true);

	inStr = theField.value;
	inLen = inStr.length;
	if (CheckNull && inLen == 0) {
			alert ("Field "+FieldName+ " is Null");
		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) {
				alert ("Invalid characters");
				return (false);
			}
		}
	}	
	return (true);
}	

function CheckNumField (theField, FieldName, CheckNull)
{
	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) {
		alert ("Field "+FieldName+ " is Null");
		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) {
		alert ("Field "+FieldName+ " too long");
		return (false);
	}
	return (true);
}

function LengthControl (theField, nLength, FieldName)
{
	if (!theField)
		return (true);
	var strDigited = theField.value;
	
	if (strDigited.length > nLength) {
		alert ('You have exceeded the maximum number of characters for field' + FieldName);
		return (false);
	}
	return (true);
}

function CheckISOCode (theField)
{
	var inStr, nValue;
	var nLen;

	inStr = theField.value;
	nLen = inStr.length;
	nNumericalDigits = 0 ;
	for (i=0; i < nLen; i++) {
		if (inStr.charAt (i) >= '0' && inStr.charAt (i) <= '9')
			nNumericalDigits++
	}
	if ( nNumericalDigits == nLen ) {
			alert('Document code must contain at least one alphanumeric character');
			return(false);
	}

	if (!CheckField (theField, 'Document code', '|#', true))
		return(false);
	return(true);
}

function SetHTMLConv(TheForm)
{
	if (TheForm.HTMLConv.checked)
		TheForm.MakeHTMLConv.value = "1";
	else
		TheForm.MakeHTMLConv.value = "0";
}
