﻿isIE = (document.all ? true : false);
reqInputArr = false;
function __doSubmit() {
    try {
        scrollpos = document.body.scrollTop;
        count = 0;
        if (reqInputArr) {
            for (i = 0; i < reqInputArr.length; i++) {
                __inputType = reqInputArr[i].split("||")[0];

                switch (__inputType) {
                    case "Password":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementById(__fieldName);
                        if (__field.value == "") {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            _minput = document.createElement("input");
                            _minput.name = __fieldName + "_new";
                            _minput.type = "password";
                            if (isIE) {
                                _minput.mname = __fieldName;
                                _minput.setAttribute("onkeyup", function() { __updateParent(this.value, this.mname); });
                            }
                            else
                                _minput.setAttribute("onkeyup", "__updateParent(this.value,'" + __fieldName + "')");
                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_minput);
                            _mcell1.style.textAlign = "left";
                        }
                        break;
                    case "CheckBox":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementById(__fieldName);
                        if (__field.checked == false) {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            _minput = document.createElement("input");
                            _minput.type = "checkbox";
                            _minput.name = __fieldName + "_new";
                            if (isIE) {
                                _minput.mname = __fieldName;
                                _minput.setAttribute("onclick", function() { __updateParent(this, this.mname, 'c'); });
                            }
                            else
                                _minput.setAttribute("onclick", "__updateParent(this,'" + __fieldName + "','c')");
                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_minput);
                            _mcell1.style.textAlign = "left";
                        }
                        break;
                    case "TextArea":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementById(__fieldName);
                        if (__field.value == "") {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            _minput = document.createElement("textarea");
                            _minput.style.width = __field.style.width;
                            _minput.style.height = __field.style.height;
                            _minput.name = __fieldName + "_new";
                            if (isIE) {
                                _minput.mname = __fieldName;
                                _minput.setAttribute("onkeyup", function() { __updateParent(this.value, this.mname); });
                            }
                            else
                                _minput.setAttribute("onkeyup", "__updateParent(this.value,'" + __fieldName + "')");
                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_minput);
                            _mcell1.style.textAlign = "left";
                        }
                        break;
                    case "TextBox":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementById(__fieldName);
                        if (__field.value == "") {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            _minput = document.createElement("input");
                            _minput.name = __fieldName + "_new";
                            _minput.type = "text";
                            if (isIE) {
                                _minput.mname = __fieldName;
                                _minput.setAttribute("onkeyup", function() { __updateParent(this.value, this.mname); });
                            }
                            else
                                _minput.setAttribute("onkeyup", "__updateParent(this.value,'" + __fieldName + "')");
                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_minput);
                            _mcell1.style.textAlign = "left";
                        }
                        break;
                    case "DropDownList":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementById(__fieldName);
                        if (__field.value == "") {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            _mselect = document.createElement("select");
                            _mselect.name = __fieldName + "_new";
                            if (isIE) {
                                _mselect.mname = __fieldName;
                                _mselect.setAttribute("onchange", function() { __updateParent(this.value, this.mname); });
                            }
                            else
                                _mselect.setAttribute("onchange", "__updateParent(this.value,'" + __fieldName + "')");
                            for (k = 0; k < __field.options.length; k++) {
                                var __optn = document.createElement("option");
                                __optn.text = __field.options[k].text;
                                __optn.value = __field.options[k].value;
                                _mselect.options.add(__optn);
                            }
                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_mselect);
                            _mcell1.style.textAlign = "left";
                        }
                        break;
                    case "RadioButtonList":
                        __fieldName = reqInputArr[i].split("||")[1];
                        __promptText = reqInputArr[i].split("||")[2];
                        __field = document.getElementsByName(__fieldName);
                        var __isChecked = false;
                        for (k = 0; k < __field.length; k++) {
                            if (__field[k].checked) {
                                __isChecked = true;
                                break;
                            }
                        }
                        if (!__isChecked) {
                            count++;
                            _mrow = document.getElementById("_tblmissinginfo").insertRow(document.getElementById("_tblmissinginfo").rows.length);
                            _mcell0 = _mrow.insertCell(0);
                            _mcell0.style.width = "50%";
                            _mcell0.style.verticalAlign = "top";
                            _mcell0.innerHTML = __promptText;
                            _mcell0.style.textAlign = "left";

                            // create table for radio buttons
                            _tbl = document.createElement("table");
                            for (k = 0; k < __field.length; k++) {
                                if (__field[k].type == "radio") {
                                    // create rows and add radio buttons to table
                                    _trow = _tbl.insertRow(_tbl.rows.length);
                                    _tcell0 = _trow.insertCell(0);
                                    // create radio button

                                    if (isIE) {
                                        _minput = document.createElement('<input type="radio" name="' + __fieldName + '_new" value="' + __field[k].value + '" onClick="__updateParent(this.value,\'' + __fieldName + '\',\'r\')">');
                                    }
                                    else {
                                        _minput = document.createElement("input");
                                        _minput.type = "radio";
                                        _minput.value = __field[k].value;
                                        _minput.name = __fieldName + "_new";
                                        _minput.setAttribute("onclick", "__updateParent(this.value,'" + __fieldName + "','r')");

                                    }
                                    _tcell0.appendChild(_minput);

                                    _tcell1 = _trow.insertCell(1);
                                    // now get the 'text' to add to the radio buttons
                                    _pn = __field[k].parentNode;
                                    _cn = _pn.childNodes;
                                    _lb = _cn[1];
                                    _tcell1.innerHTML = _lb.innerHTML;
                                }
                            }

                            _mcell1 = _mrow.insertCell(1);
                            _mcell1.style.width = "50%";
                            _mcell1.style.verticalAlign = "top";
                            _mcell1.appendChild(_tbl);
                            _mcell1.style.textAlign = "left";
                        }
                        break;

                }

            }
        }
        if (count > 0) {
            veil = document.getElementById("_veil");
            veil.style.display = "block";
            mi = document.getElementById("_missinginfodiv");
            mi.style.display = "block";
            mi.style.top = scrollpos + 50 + "px";
            return false;
        }
        return true;
    }
    catch (e) {
        return true;
    }
}

function __updateParent(val, where) {
    if (arguments[2]) {
        if (arguments[2] == "r") {
            _rbl = document.getElementsByName(where);
            for (i = 0; i < _rbl.length; i++) {
                if (_rbl[i].value == val) {
                    _rbl[i].checked = true;
                    return;
                }
            }
        }
        else {
            if (val.checked)
                document.getElementById(where).checked = true;
            else
                document.getElementById(where).checked = false;
        }
    }
    document.getElementById(where).value = val;
}

function __closeMissing() {
    document.getElementById("_missinginfodiv").style.display = "none";
    document.getElementById("_veil").style.display = "none";
    mt = document.getElementById("_tblmissinginfo");
    for (i = mt.rows.length - 1; i > -1; i--) {
        mt.deleteRow(i);
    }
}