﻿
var controlFromWhichSubmitCame = null;
var groupName = null;
var errorList = null;

function validate_form(thisForm) {

    if (controlFromWhichSubmitCame != null) {

        var inputList = thisForm.getElementsByTagName("Input");

        for (var count = 0; count < inputList.length; count++) {

            if ((inputList[count].type == "text") && (inputList[count].type != "hidden")) {

                if ((inputList[count].getAttribute("CosmosValidationGroup") != null) && (inputList[count].getAttribute("CosmosValidationType") != null)) {

                    if (inputList[count].getAttribute("CosmosValidationGroup").toString() == groupName) {

                        ValdationSelector(inputList[count], inputList[count].getAttribute("CosmosValidationType").toString());
                    }
                }
            }
        }

        var txtAreaList = thisForm.getElementsByTagName("TextArea");

        for (var count = 0; count < txtAreaList.length; count++) {

            if ((txtAreaList[count].getAttribute("CosmosValidationGroup") != null) && (txtAreaList[count].getAttribute("CosmosValidationType") != null)) {

                if (txtAreaList[count].getAttribute("CosmosValidationGroup").toString() == groupName) {

                    ValdationSelector(txtAreaList[count], txtAreaList[count].getAttribute("CosmosValidationType").toString());
                }

            }
        }

        // Clear control ref.
        controlFromWhichSubmitCame = null;
        grpName = null;

        if (errorList.length > 0) {

            //Has errors and build message list
            $.fn.notificationBar.showMessage({ MsgTitle: 'Required information has not been provided.', TitleIcon: 'Remove', MsgList: errorList, DefaultIcon: 'Remove', Time: 8000 });

            return false;
        }
        else {

            // no errors 
            return true;
        }
    }
    else {

        return true;
    }

}

function validate_Submit(grpName, control) {

    controlFromWhichSubmitCame = control;
    groupName = grpName;
}

function ValdationSelector(control, typeOfValidation) {

    errorList = new Array();
    errorList.push({ Msg: 'The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.' });  
}
