﻿function CheckForNull(FormName, LabelName, FieldName, AlertMessage) {

    //var FieldRef=eval("document." + FormName +"." + FieldName);
    var FieldRef = document.getElementById(FieldName);
    var FieldValue = FieldRef.value
    FieldValue = LTrim(RTrim(FieldValue))
    //var MsgRef = eval("document." + FormName +".txtMessage");
    var counter = 0

    if (parseInt(FieldValue.length) < 1) {
        if (AlertMessage == '') {
            alert(LabelName + " must be entered.");
        }
        else {
            // alert(AlertMessage);
            document.getElementById(LabelName).innerHTML = AlertMessage;
        }
        //MsgRef.value = LabelName + " Must Be Entered!"
        document.getElementById(FieldName).focus();
        return false;
    }
    else {
        //Check Spaces in String 
        for (LintCount = 0; LintCount <= parseInt(FieldValue.length); LintCount++) {
            //If Space Found
            if (FieldValue.charAt(LintCount) == ' ') {
                counter = counter + 1
            }
        }
        //If Total Number of Spaces Equal to Total Length of String Then Return False
        if (parseInt(counter) == parseInt(FieldValue.length)) {
            if (AlertMessage == '') {
                alert(LabelName + " must be entered.");
            }
            else {
                //alert(AlertMessage);
                document.getElementById(LabelName).innerHTML = AlertMessage;
            }

            //MsgRef.value = LabelName + " Must Be Entered!"
            FieldRef.value = ''
            document.getElementById(FieldName).focus();
            return false;
        }
        else {
            FieldRef.value = FieldValue
            return true;
        }
    }
}
function LTrim(AStrInputString) {
    var LIntCtr
    var LStrOutputString
    LStrOutputString = ""
    for (LIntCtr = 0; LIntCtr < AStrInputString.length; LIntCtr++) {
        if (AStrInputString.charAt(LIntCtr) != ' ') {
            return AStrInputString.substring(LIntCtr);
        }
    }
    return LStrOutputString;
}

function RTrim(AStrInputString) {
    var LIntCtr
    var LStrOutputString
    LStrOutputString = ""
    for (LIntCtr = AStrInputString.length - 1; LIntCtr >= 0; LIntCtr--) {
        if (AStrInputString.charAt(LIntCtr) != ' ') {
            return AStrInputString.substring(0, LIntCtr + 1);
        }
    }
    return LStrOutputString;
}
function CompareValues(FormName, LabelName, FieldName) {

    var FieldRef = document.getElementById(FieldName);
    var FieldValue = FieldRef.value
    FieldValue = LTrim(RTrim(FieldValue))
    var LabelRef = document.getElementById(LabelName)
    var LabelValue = LabelRef.value
    LabelValue = LTrim(RTrim(LabelValue))
    if (FieldValue != LabelValue) {
        return false
    }
    return true

}