﻿function previewHTML(id) {
    var oNews = document.getElementById(id + 'S');
    var oSource = document.getElementById("source");
    var oPreview = document.getElementById('td' + id);

    oSource.appendChild(document.createTextNode(oNews.value));
    //oPreview.innerHTML = oNews.value;
}
var req;
var browser;

var baseURL = document.location.protocol + "//" + document.location.hostname; // 'http://dev.formhog.com/';
if (document.location.port != null) {
    if (document.location.port != '') {
        baseURL += ":" + document.location.port;
    }
}
baseURL += "/";
var popupWindow = null;
var currentAction = '';
function roundNumber(num, dec) {
    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
    return result;
}

//---------------------BEGIN of FY12 Interoffice Billing/Credit Advice ----------------------------------
var districtsComboBoxData = [];
var districtRow = 1;
var FY12BillingFormRecID = 0;
Ext.QuickTips.init();
function renderDistrictsComboBox(recID, DistrictID) {
    var renderTo = 'districtsComboBoxField' + recID;
    var id = 'cboDistrict' + recID;
    new Ext.form.ComboBox({
        renderTo: renderTo,
        id: id,
        width: 260,
        listWidth: 260,
        //tpl: '<tpl for="."><div ext:qtip="{text}" class="x-combo-list-item ux-lovcombo-item-text">{text}</div></tpl>',
        //tpl: '<tpl for="."><div ext:qtip="{text}" class="x-combo-list-item" onclick="this.style.fontWeight=\'bold\';">{text}</div></tpl>',
        store: new Ext.data.ArrayStore({
            fields: ['text', 'id'],
            data: districtsComboBoxData
        }),
        maxHeight: 200,
        resizable: true,
        typeAhead: true,
        hideOnSelect: false,
        triggerAction: 'all',
        valueField: 'id',
        displayField: 'text',
        mode: 'local',
        value: DistrictID,
        emptyText: '--Click to Select--',
        selectOnFocus: true,
        editable: true,
        listeners: {
            'select': function(combo, record, index) {
                //alert(Ext.encode(combo));
                //alert(combo.getValue());
                if (document.getElementById(combo.id)) {
                    document.getElementById(combo.id).style.fontWeight = 'bold';
                }
                fnSave(recID);
            }
        }
    });
}
function reSetSelectTextStyleBold(comboid) {
    if (document.getElementById(comboid)) {
        document.getElementById(comboid).style.fontWeight = 'bold';
    }
}
function fhSetDistrictBillingAmountField(val) {

    if (document.getElementsByName('Field1003713') != null) {
        if (!document.getElementsByName('Field1003713')[0].checked && !document.getElementsByName('Field1003713')[1].checked)
            document.getElementsByName('Field1003713')[0].checked = true;
    }

    if (val == 'Bill') {
        var TotalAmountCreditedTDs = document.getElementsByName('TotalAmountCredited');
        if (TotalAmountCreditedTDs.length > 0) {
            for (var i = 0; i < TotalAmountCreditedTDs.length; i++) {
                TotalAmountCreditedTDs[i].style.display = 'none';
                TotalAmountCreditedTDs[i].value = 0.00;
            }
        }
        var TotalAmountBilledTDs = document.getElementsByName('TotalAmountBilled');
        if (TotalAmountBilledTDs.length > 0) {
            for (var i = 0; i < TotalAmountBilledTDs.length; i++) {
                TotalAmountBilledTDs[i].style.display = 'block';
            }
        }
        if (document.getElementById('tdTotalAmountCredited')) {
            document.getElementById('tdTotalAmountCredited').innerHTML = '';
        }
        fnTotalAmountBilled();
    } else {
        var TotalAmountCreditedTDs = document.getElementsByName('TotalAmountCredited');
        if (TotalAmountCreditedTDs.length > 0) {
            for (var i = 0; i < TotalAmountCreditedTDs.length; i++) {
                TotalAmountCreditedTDs[i].style.display = 'block';
            }
        }
        var TotalAmountBilledTDs = document.getElementsByName('TotalAmountBilled');
        if (TotalAmountBilledTDs.length > 0) {
            for (var i = 0; i < TotalAmountBilledTDs.length; i++) {
                TotalAmountBilledTDs[i].style.display = 'none';
                TotalAmountBilledTDs[i].value = 0.00;
            }
        }
        if (document.getElementById('tdTotalAmountBilled')) {
            document.getElementById('tdTotalAmountBilled').innerHTML = '';
        }
        fnTotalAmountCredited();
    }
    fnAidableAmount();
}
function fnOnKeyPress(e) {
    var key;

    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
        return false;
    else
        return true;


}
function fnAddNewDistrictRow(previousRowId, isClickOnAddDistrictButton) {
    //alert('previousRowId:' + previousRowId + '\n' + 'districtRow:' + districtRow);

    districtRow = parseInt(districtRow) + 1;
    var rows = Ext.query('.entryRow');
    var valAmountBilled = 0;
    var valAmountCredited = 0;
    var valAidableAmount = 0;
    var rowTotalCount = (rows.length / 2);
    if (rows.length > 0) {
        Ext.each(rows, function(item, index) {
            if (item != null && index == 0) {
                valAmountBilled = document.getElementById('tbxTotalAmountBilled' + item.getAttribute('rowNo')).value;
                valAmountCredited = document.getElementById('tbxTotalAmountCredited' + item.getAttribute('rowNo')).value;
                valAidableAmount = document.getElementById('tbxAidableAmount' + item.getAttribute('rowNo')).value;
            }
        });
    }
    rowTotalCount = rowTotalCount + 1;
    var row = document.createElement("TR");
    row.setAttribute("id", "Row" + districtRow);
    row.setAttribute("rowNo", districtRow);
    //row.setAttribute("class", 'entryRow');
    row.className = 'entryRow';
    //row.name = 'entryRow';
    if (rowTotalCount % 2 == 0)
        row.setAttribute("style", "font-family:Arial;text-align:left;background-color:#D8F1FF;font-size:11px;");
    else
        row.setAttribute("style", "font-family:Arial;text-align:left;background-color:White;font-size:11px;"); //#F1FAFF

    var cellRecNO = document.createElement("TD");
    cellRecNO.setAttribute("style", "width:5px");
    cellRecNO.innerHTML = "<div class='RecNo' id='divRecord" + districtRow + "' >" + districtRow + ".</div>";
    cellRecNO.setAttribute("id", "RecNo" + districtRow);

    var cell1 = document.createElement("TD");
    cell1.setAttribute("align", "left");
    cell1.setAttribute("style", "width:260px;");
    cell1.innerHTML = "<div prevDistrictID=0 style='float:left;' id='districtsComboBoxField" + districtRow + "' onKeyPress='return fnOnKeyPress(event);' />";


    var cell2 = document.createElement("TD");
    cell2.setAttribute("align", "left");
    cell2.setAttribute("style", "width:80px");
    cell2.innerHTML = "<input type='text' id='tbxPO" + districtRow + "' name='tbxPO' maxlength='1000' onKeyPress='return fnOnKeyPress(event);' onChange='fnSave(" + districtRow + ");' />";

    var cell3 = document.createElement("TD");
    cell3.setAttribute("align", "left");
    cell3.setAttribute("style", "width:80px");
    cell3.innerHTML = "<input type='text' id='tbxTotalAmountBilled" + districtRow + "' name='TotalAmountBilled' maxlength='10' value='" + valAmountBilled + "' style='text-align:right;width:90%;padding-right:3px;' onKeyPress='return fnOnKeyPress(event);' onChange='fnTotalAmountBilled();UpdateAidableAmount(" + districtRow + ");fnSave(" + districtRow + ");' />";

    var cell4 = document.createElement("TD");
    cell4.setAttribute("align", "left");
    cell4.setAttribute("style", "width:80px");
    cell4.innerHTML = "<input type='text' id='tbxTotalAmountCredited" + districtRow + "' value='" + valAmountCredited + "' name='TotalAmountCredited' maxlength='10' style='text-align:right;width:90%;padding-right:3px;' onKeyPress='return fnOnKeyPress(event);' onChange='fnTotalAmountCredited();UpdateAidableAmount(" + districtRow + ");fnSave(" + districtRow + ");' />";

    var cell5 = document.createElement("TD");
    /*var inp5 = document.createElement("INPUT");
    inp5.setAttribute("type", "text");
    inp5.setAttribute("name", "AidableAmount");
    inp5.setAttribute("id", "tbxAidableAmount" + districtRow);
    inp5.setAttribute("maxlength", "10");
    inp5.setAttribute("style", "text-align:right;width:100%;");
    
    if(BillCredit=="Bill"){
    inp5.setAttribute("value", valAmountBilled);
    } else {
    inp5.setAttribute("value", valAmountCredited);
    }
    //inp5.size = 20;
    if (navigator.appName.indexOf("Microsoft") < 0)
    inp5.setAttribute("onblur", "javascript:fnAidableAmount();fnSave(" + districtRow + ");");
    else {
    inp5.onblur = function() { fnAidableAmount(); fnSave(districtRow); }
    }
   
    cell5.setAttribute("style", "text-align:right;padding-left:5px;width:80px;");
    cell5.appendChild(inp5);*/
    if (BillCredit == "Bill") {
        valAidableAmount = valAmountBilled;
    } else {
        valAidableAmount = valAmountCredited;
    }

    cell5.setAttribute("align", "left");
    cell5.setAttribute("style", "width:80px");
    cell5.innerHTML = "<input type='text' id='tbxAidableAmount" + districtRow + "' value='" + valAidableAmount + "' name='AidableAmount' maxlength='10' style='text-align:right;width:90%;padding-right:3px;' onKeyPress='return fnOnKeyPress(event);' onChange='fnAidableAmount();fnSave(" + districtRow + ");' />";

    var cellDelete = document.createElement("TD");
    cellDelete.setAttribute("style", "width:25px");
    cellDelete.innerHTML = "&nbsp;";

    row.appendChild(cellRecNO);
    row.appendChild(cell1);
    row.appendChild(cell2);
    row.appendChild(cell3);
    row.appendChild(cell4);
    row.appendChild(cell5);
    row.appendChild(cellDelete);
    //Append row into Table
    var rowTotal = document.getElementById('trTotals');
    document.getElementById("tblBillingDistrictTable").childNodes[0].removeChild(document.getElementById('trTotals'));
    document.getElementById("tblBillingDistrictTable").childNodes[0].appendChild(row);

    var rowContractNamePhoneEmail = document.createElement("TR");
    rowContractNamePhoneEmail.setAttribute("id", "RowNamePhoneEmail" + districtRow);
    rowContractNamePhoneEmail.setAttribute("rowNo", districtRow);
    rowContractNamePhoneEmail.className = 'entryRow';
    //rowContractNamePhoneEmail.setAttribute("style", "font-family:Arial;font-size:12px;text-align:left;");
    if (rowTotalCount % 2 == 0)
        rowContractNamePhoneEmail.setAttribute("style", "font-family:Arial;text-align:left;background-color:#D8F1FF;font-size:11px;");
    else
        rowContractNamePhoneEmail.setAttribute("style", "font-family:Arial;text-align:left;background-color:White;font-size:11px;");

    var cellRecNO1 = document.createElement("TD");
    cellRecNO1.setAttribute("style", "width:5px");
    cellRecNO1.innerHTML = "&nbsp;";
    //cellRecNO.setAttribute("id", "RecNo" + districtRow);
    rowContractNamePhoneEmail.appendChild(cellRecNO1);

    var cellName = document.createElement("TD");
    cellName.setAttribute("align", "left");
    cellName.setAttribute("style", "width:260px;");
    //cellName.innerHTML = "<span style='text-align:center;padding-left:65px;'><b>District Contact Name</b></span><br/><input type='text' style='width:260px' id='tbxContractName" + districtRow + "' name='tbxContractName' maxlength='1000' value='' onKeyPress='return fnOnKeyPress(event);' onChange='fnSave(" + districtRow + ");' />";
    cellName.innerHTML = "<input type='text' style='width:260px;font-style:italic;color:#666666;font-size:13px;' id='tbxContractName" + districtRow + "' name='tbxContractName' maxlength='1000' value='District Contact Name' onfocus='fnResetEmptyTextStyle(\"District Contact Name\",this,1);' onKeyPress='return fnOnKeyPress(event);' onChange='if(this.value!=\"District Contact Name\") fnSave(" + districtRow + ");' onblur='fnResetEmptyTextStyle(\"District Contact Name\",this,0);' />";
    rowContractNamePhoneEmail.appendChild(cellName);

    var cellEmail = document.createElement("TD");
    cellEmail.setAttribute("align", "left");
    cellEmail.setAttribute("colSpan", "2");
    //cellEmail.setAttribute("style", "width:80px");
    //cellEmail.innerHTML = "<span style='text-align:center;padding-left:110px;'><b>Email</b></span><br/><input type='text' style='text-align:left;width:95%;padding-right:3px;' id='tbxEmail" + districtRow + "' name='tbxEmail' maxlength='55' value='' onKeyPress='return fnOnKeyPress(event);' onChange='fnSave(" + districtRow + ");' />";
    cellEmail.innerHTML = "<input type='text' style='text-align:left;width:95%;padding-right:3px;font-style:italic;color:#666666;font-size:13px;' id='tbxEmail" + districtRow + "' name='tbxEmail' maxlength='55' value='Email' onfocus='fnResetEmptyTextStyle(\"Email\",this,1);' onKeyPress='return fnOnKeyPress(event);' onChange='if(this.value!=\"Email\") fnSave(" + districtRow + ");' onblur='fnResetEmptyTextStyle(\"Email\",this,0);' />";
    rowContractNamePhoneEmail.appendChild(cellEmail);

    var cellPhone = document.createElement("TD");
    cellPhone.setAttribute("align", "left");
    cellPhone.setAttribute("colSpan", "2");
    //cellPhone.colspan = 2;
    //cellPhone.setAttribute("style", "width:80px");
    //cellPhone.innerHTML = "<span style='text-align:center;padding-left:90px;'><b>Phone</b></span><br/><input type='text' style='text-align:left;width:95%;padding-right:3px;' id='tbxPhone" + districtRow + "' name='tbxPhone' maxlength='15' value='' onKeyPress='return fnOnKeyPress(event);' onChange='fnSetPhoneFormat(this,1,event);fnSave(" + districtRow + ");' />";
    cellPhone.innerHTML = "<input type='text' style='text-align:left;width:95%;padding-right:3px;font-style:italic;color:#666666;font-size:13px;' id='tbxPhone" + districtRow + "' name='tbxPhone' maxlength='25' value='Phone' onfocus='fnResetEmptyTextStyle(\"Phone\",this,1);' onKeyPress='return fnOnKeyPress(event);' onChange='fnSetPhoneFormat(this,1,event);if(this.value!=\"Phone\") fnSave(" + districtRow + ");' onblur='fnResetEmptyTextStyle(\"Phone\",this,0);' />";
    rowContractNamePhoneEmail.appendChild(cellPhone);

    var cell6Delete = document.createElement("TD");
    cell6Delete.setAttribute("id", "tdDelete" + districtRow);
    cell6Delete.setAttribute("style", "width:25px;text-align:center;");
    cell6Delete.innerHTML = "<a href='#' onclick='javascript:DeleteBillingDistrict(" + districtRow + ");'><img id='btn_DeleteAttachment' src='" + AmazonServerPath + "Content/Assets/icons/delete.png' ></a>";
    rowContractNamePhoneEmail.appendChild(cell6Delete);

    document.getElementById("tblBillingDistrictTable").childNodes[0].appendChild(rowContractNamePhoneEmail);

    document.getElementById("tblBillingDistrictTable").childNodes[0].appendChild(rowTotal);

    RecNoTDs = Ext.query('.RecNo');
    if (RecNoTDs.length > 0) {
        Ext.each(RecNoTDs, function(item, index) {
            if (item != null) {
                item.innerHTML = (index + 1) + '.';
            }
        });
    }

    renderDistrictsComboBox(districtRow, '');
    reSetSelectTextStyleBold('cboDistrict' + districtRow);
    fhSetDistrictBillingAmountField(BillCredit);
}
function fnResetEmptyTextStyle(emptyText, ctrl, isFocus) {
    if (emptyText == 'Email' && isFocus == 0) {
        var testEmail = new RegExp('\w+@([a-z0-9-_]+\.)+\w+');
        var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        //testEmail.compile();
        if (!filter.test(ctrl.value) && ctrl.value != '') {
            ctrl.style.backgroundColor = '#faafba';
        } else {
            ctrl.style.backgroundColor = 'white';
        }
    }
    if (ctrl.value == '') {
        ctrl.value = emptyText;
        ctrl.style.fontStyle = 'italic';
        ctrl.style.color = '#666666';
    } else {
        if (isFocus && ctrl.value == emptyText) {
            ctrl.value = '';
        }
        ctrl.style.fontStyle = 'normal';
        ctrl.style.color = '#000000';
    }
}
function fnSave(recNo) {
    var valDitrictID = Ext.getCmp('cboDistrict' + recNo).getValue();
    if (valDitrictID == null || Ext.util.Format.trim(valDitrictID) == '') {
        //alert('District is mandatory.');
        return;
    }
    var valPO = document.getElementById('tbxPO' + recNo).value;
    var valAmountBilled = document.getElementById('tbxTotalAmountBilled' + recNo).value;
    var valAmountCredited = document.getElementById('tbxTotalAmountCredited' + recNo).value;
    var valAidableAmount = document.getElementById('tbxAidableAmount' + recNo).value;
    var ContractName = document.getElementById('tbxContractName' + recNo).value;
    if (ContractName == 'District Contact Name') {
        ContractName = '';
    }
    var Phone = document.getElementById('tbxPhone' + recNo).value;
    if (Phone == 'Phone') {
        Phone = '';
    }
    var Email = document.getElementById('tbxEmail' + recNo).value;
    if (Email == 'Email') {
        Email = '';
    }

    var testEmail = new RegExp('\w+@([a-z0-9-_]+\.)+\w+');
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    //testEmail.compile();
    if (!filter.test(Email) && Email != '') {
        document.getElementById('tbxEmail' + recNo).style.backgroundColor = '#faafba';
        return;
    } else {
        document.getElementById('tbxEmail' + recNo).style.backgroundColor = 'white';
    }

    var prevDistrictID = '0';
    if (document.getElementById('districtsComboBoxField' + recNo)) {
        prevDistrictID = document.getElementById('districtsComboBoxField' + recNo).getAttribute('prevDistrictID');
        if (prevDistrictID != valDitrictID) {
            document.getElementById('districtsComboBoxField' + recNo).setAttribute('prevDistrictID', valDitrictID);
        }
        if (prevDistrictID == 0 || prevDistrictID == '0') {
            prevDistrictID = '';
        }
    } else {
        prevDistrictID = '';
    }
    //alert('valDitrictID:' + valDitrictID + '\n' + 'valPO:' + valPO + '\n' + 'valAmountBilled:' + valAmountBilled + '\n' + 'valAmountCredited:' + valAmountCredited + '\n' + 'valAidableAmount:' + valAidableAmount);
    //alert(document.getElementById('districtsComboBoxField' + recNo).getAttribute('prevDistrictID'));
    if (valAmountBilled == '') {
        valAmountBilled = 0;
    }
    if (valAmountCredited == '') {
        valAmountCredited = 0;
    }
    if (valAidableAmount == '') {
        valAidableAmount = 0;
    }
    //alert(prevDistrictID);
    Ext.Ajax.request({
        url: 'AccessRemoteWebService.aspx',
        method: 'POST',
        params: {
            DitrictID: valDitrictID,
            OprMode: 'SaveBillingDistrict',
            PO: valPO,
            AmountBilled: valAmountBilled,
            AmountCredited: valAmountCredited,
            AidableAmount: valAidableAmount,
            recId: FY12BillingFormRecID,
            UserID: UserID,
            prevDistrictID: prevDistrictID,
            ContractName: ContractName,
            Phone: Phone,
            Email: Email
        },
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        success: function(response, options) {
            if (response.responseText.length > 0) {
                if (response.responseText.indexOf('District already exist') >= 0) {
                    Ext.Msg.alert('ERROR', response.responseText);
                    if (document.getElementById('districtsComboBoxField' + recNo)) {
                        document.getElementById('districtsComboBoxField' + recNo).setAttribute('prevDistrictID', prevDistrictID);
                    }
                    Ext.getCmp('cboDistrict' + recNo).setValue(prevDistrictID);
                }
            }
        },
        failure: function(response, options) {
            //Ext.Msg.alert('ERROR', Ext.encode(response));
        }
    });
}

function DeleteBillingDistrict(recNo) {
    var valDitrictID = Ext.getCmp('cboDistrict' + recNo).getValue();
    Ext.Ajax.request({
        url: 'AccessRemoteWebService.aspx',
        method: 'POST',
        params: {
            OprMode: 'DeleteBillingDistrict',
            DitrictID: valDitrictID,
            recId: FY12BillingFormRecID,
            UserID: UserID
        },
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        success: function(response, options) {
            var rowTotal = document.getElementById('Row' + recNo);
            var RowNamePhoneEmail = document.getElementById('RowNamePhoneEmail' + recNo);
            var previousRow = rowTotal.previousSibling;
            var previousRowNo = 0;
            if (previousRow.getAttribute('rowNo') != null) {
                previousRowNo = parseInt(previousRow.getAttribute('rowNo'));
                var tdAidableAmount = document.getElementById('tbxAidableAmount' + previousRowNo);
                if (navigator.appName.indexOf("Microsoft") < 0) {
                    tdAidableAmount.setAttribute('onChange', "function(){};");
                    tdAidableAmount.setAttribute("onChange", "javascript:fnAidableAmount();fnSave(" + previousRowNo + ");");
                }
                else {
                    tdAidableAmount.onChange = function() { };
                    tdAidableAmount.onChange = function() { fnAidableAmount(); fnSave(previousRowNo); }
                }
            }
            document.getElementById("tblBillingDistrictTable").childNodes[0].removeChild(rowTotal);
            if (RowNamePhoneEmail != null) {
                document.getElementById("tblBillingDistrictTable").childNodes[0].removeChild(RowNamePhoneEmail);
            }
            RecNoTDs = Ext.query('.RecNo');
            if (RecNoTDs.length > 0) {
                Ext.each(RecNoTDs, function(item, index) {
                    if (item != null) {
                        item.innerHTML = (index + 1) + '.';
                        var rowid = item.id.substring(9);
                        if (document.getElementById('Row' + rowid)) {
                            if (parseInt((index + 1)) % 2 == 0) {
                                document.getElementById('Row' + rowid).style.backgroundColor = '#D8F1FF';
                                document.getElementById('RowNamePhoneEmail' + rowid).style.backgroundColor = '#D8F1FF';

                            } else {
                                document.getElementById('Row' + rowid).style.backgroundColor = 'White';
                                document.getElementById('RowNamePhoneEmail' + rowid).style.backgroundColor = 'White';
                            }
                        }
                    }
                });
            } else {
                if (document.getElementById('tdTotalAmountBilled')) {
                    document.getElementById('tdTotalAmountBilled').innerHTML = Ext.util.Format.usMoney(0);
                }
                if (document.getElementById('tdTotalAmountCredited')) {
                    document.getElementById('tdTotalAmountCredited').innerHTML = Ext.util.Format.usMoney(0);
                }
                if (document.getElementById('tdAidableAmount')) {
                    document.getElementById('tdAidableAmount').innerHTML = Ext.util.Format.usMoney(0);
                }
            }
            fhSetDistrictBillingAmountField(BillCredit);
        },
        failure: function(response, options) {
            Ext.Msg.alert('ERROR', Ext.encode(response));
        }
    });
}

function fnTotalAmountBilled() {
    var Total_AmountBilled = document.getElementsByName('TotalAmountBilled');
    if (Total_AmountBilled.length > 0) {
        var total = 0;
        for (var i = 0; i < Total_AmountBilled.length; i++) {
            if (!isNaN(Total_AmountBilled[i].value) && Total_AmountBilled[i].value != '') {
                total = total + parseFloat(Total_AmountBilled[i].value);
            } else {
                Total_AmountBilled[i].value = '';
            }
        }
        if (document.getElementById('tdTotalAmountBilled')) {
            document.getElementById('tdTotalAmountBilled').innerHTML = Ext.util.Format.usMoney(total);
        }
    }
}

function fnTotalAmountCredited() {
    var Total_TotalAmountCredited = document.getElementsByName('TotalAmountCredited');
    if (Total_TotalAmountCredited.length > 0) {
        var total = 0;
        for (var i = 0; i < Total_TotalAmountCredited.length; i++) {
            if (!isNaN(Total_TotalAmountCredited[i].value) && Total_TotalAmountCredited[i].value != '') {
                total = total + parseFloat(Total_TotalAmountCredited[i].value);
            } else {
                Total_TotalAmountCredited[i].value = '';
            }
        }
        if (document.getElementById('tdTotalAmountCredited')) {
            document.getElementById('tdTotalAmountCredited').innerHTML = Ext.util.Format.usMoney(total);
        }
    }
}

function fnAidableAmount() {
    var Total_AidableAmount = document.getElementsByName('AidableAmount');
    if (Total_AidableAmount.length > 0) {
        var total = 0;
        for (var i = 0; i < Total_AidableAmount.length; i++) {
            if (!isNaN(Total_AidableAmount[i].value) && Total_AidableAmount[i].value != '') {
                total = total + parseFloat(Total_AidableAmount[i].value);
            } else {
                Total_AidableAmount[i].value = '';
            }
        }
        if (document.getElementById('tdAidableAmount')) {
            document.getElementById('tdAidableAmount').innerHTML = Ext.util.Format.usMoney(total);
        }
    }
}

function UpdateAidableAmount(recno) {
    if (document.getElementById('tbxAidableAmount' + recno) != null
    //&& (document.getElementById('tbxAidableAmount' + recno).value == '' || document.getElementById('tbxAidableAmount' + recno).value == 0)
        ) {
        if (BillCredit == 'Bill') {
            document.getElementById('tbxAidableAmount' + recno).value = document.getElementById('tbxTotalAmountBilled' + recno).value;

        } else {
            document.getElementById('tbxAidableAmount' + recno).value = document.getElementById('tbxTotalAmountCredited' + recno).value;
        }
        fnAidableAmount();
    }
}

function AttachMore() {

    var val = 0;
    if (document.getElementById('fileBrowserCount')) {
        val = parseInt(document.getElementById('fileBrowserCount').value);
        val = parseInt(val) + 1;
        document.getElementById('fileBrowserCount').value = val;
    }
    var tr = document.createElement('TR');
    var cellDescription = document.createElement("TD");
    cellDescription.setAttribute("align", "right");
    //cellDescription.setAttribute("style", "width:80px");
    cellDescription.innerHTML = "Description&nbsp;&nbsp;";

    var cellFile = document.createElement("TD");
    cellFile.setAttribute("align", "left");
    cellFile.setAttribute("colspan", "2");
    cellFile.setAttribute("valign", "top");
    cellFile.innerHTML = "<input name='fileDescription" + val + "' style='width: 300px;' maxlength='1000' type='text' />" +
                 "<input name='uploadFileID" + val + "' size=40  type='file'/>";

    /*tr.innerHTML = "<td align='right'>Description&nbsp;&nbsp;</td><td colspan='2' align='left' valign='top'>" +
    "<input name='fileDescription" + val + "' style='width: 300px;' maxlength='1000' type='text' />" +
    "<input name='uploadFileID" + val + "' size=40  type='file'/></td>";*/

    tr.appendChild(cellDescription);
    tr.appendChild(cellFile);
    document.getElementById("tblAttachmentTable").childNodes[0].appendChild(tr);

}

function fnAddALLNASSAUDistrict(actionName) {
    var rows = Ext.query('.entryRow');
    var valAmountBilled = 0;
    var valAmountCredited = 0;
    var valAidableAmount = 0;
    var rowTotalCount = (rows.length / 2);
    if (rows.length > 0) {
        Ext.each(rows, function(item, index) {
            if (item != null && index == 0) {
                valAmountBilled = document.getElementById('tbxTotalAmountBilled' + item.getAttribute('rowNo')).value;
                valAmountCredited = document.getElementById('tbxTotalAmountCredited' + item.getAttribute('rowNo')).value;
                valAidableAmount = document.getElementById('tbxAidableAmount' + item.getAttribute('rowNo')).value;
            }
        });
    }

    var allAmount = 0;
    if (BillCredit == "Bill") {
        allAmount = valAmountBilled;
    } else {
        allAmount = valAmountCredited;
    }
    if (allAmount == 0 || allAmount == '0' || allAmount == '') {
        Ext.Msg.prompt('FormHog', 'Please enter amount:', function(btn, text) {
            if (btn == 'ok') {
                allAmount = text;
                if (Ext.util.Format.trim(allAmount).length == 0) {
                    alert('Amount is mandatory');
                    return;
                }
                if (document.getElementById('allAmount')) {
                    document.getElementById('allAmount').value = allAmount;
                }
                if (valAidableAmount == 0) {
                    valAidableAmount = allAmount;
                }
                if (document.getElementById('defaultAidableAmount')) {
                    document.getElementById('defaultAidableAmount').value = valAidableAmount;
                }
                if (document.getElementById('AddAllNASSAUDISTRICT')) {
                    document.getElementById('AddAllNASSAUDISTRICT').value = 'YES';
                }
                setAction(actionName);
            }
        });
    } else {
        if (document.getElementById('allAmount')) {
            document.getElementById('allAmount').value = allAmount;
        }
        if (valAidableAmount == 0) {
            valAidableAmount = allAmount;
        }
        if (document.getElementById('defaultAidableAmount')) {
            document.getElementById('defaultAidableAmount').value = valAidableAmount;
        }
        if (document.getElementById('AddAllNASSAUDISTRICT')) {
            document.getElementById('AddAllNASSAUDISTRICT').value = 'YES';
        }
        setAction(actionName);
    }
}

//---------------------END of FY12 Interoffice Billing/Credit Advice ----------------------------------

function fnShowNonApproverComboBox(approverUsersList, orgId, usersList) {
    //alert(usersList);
    var logConsultant = new Ext.form.ComboBox({
        renderTo: 'divNonApproverComboBox',
        tpl: new Ext.XTemplate('<tpl for="."><div class="search-item"><img id="{UserID}" name="imgOrgUsers" src="Scripts/ext_3_1_0/resources/images/default/menu/unchecked.gif" />{UserName}</div></tpl>'),
        itemSelector: 'div.search-item',
        store: new Ext.data.Store({
            proxy: new Ext.ux.AspNetHttpProxy({
                url: 'FormEntryListService.asmx/ListNonApproverOrgUsers'
            }),
            reader: new Ext.ux.aspNetJsonReader({
                root: 'data'
            },
                        [{ name: 'UserID', type: 'string' },
                        { name: 'UserName', type: 'string'}]
                   ),
            listeners: {
                beforeload: function(store, options) {
                    options.params.orgId = orgId;
                    options.params.approverUsersList = approverUsersList;
                },
                load: function() {
                    setTimeout(function() { fnSetCheckedToNonApproverComboBox(usersList); }, 500);
                    //alert(2);
                }
            }
        }),
        width: 350,
        mode: 'remote',
        triggerAction: 'all',
        displayField: 'UserName',
        valueField: 'UserID',
        emptyText: '--Click to Select--',
        selectOnFocus: true,
        editable: false,
        listeners: {
            'select': function(combo, record, index) {
                if (combo.getValue() != "") {
                    if (document.getElementById(combo.getValue()).src.indexOf("unchecked.gif") >= 0)
                        document.getElementById(combo.getValue()).src = "Scripts/ext_3_1_0/resources/images/default/menu/checked.gif";
                    else
                        document.getElementById(combo.getValue()).src = "Scripts/ext_3_1_0/resources/images/default/menu/unchecked.gif";
                    document.getElementById('cboNonApprover').value = "";
                    var len = document.getElementsByName('imgOrgUsers').length;
                    var imgSrc = '';
                    for (var i = 0; i < len; i++) {
                        if (document.getElementsByName('imgOrgUsers')[i].src.indexOf("unchecked.gif") < 0) {
                            document.getElementById('cboNonApprover').value += "," + document.getElementsByName('imgOrgUsers')[i].id;
                        }
                    }
                    //alert(combo.getValue());
                    //fnFillNotificationsForm(combo, record);
                }
            }
        }

    });

}
//if page is reopen for any error then make select checkbox of previoud selected nonapprovers.
function fnSetCheckedToNonApproverComboBox(usersList) {
    var len = document.getElementsByName('imgOrgUsers').length;
    //alert(len);
    var imgSrc = '';
    for (var i = 0; i < len; i++) {
        if (usersList.indexOf(":" + document.getElementsByName('imgOrgUsers')[i].id + ":") >= 0)
            document.getElementsByName('imgOrgUsers')[i].src = "Scripts/ext_3_1_0/resources/images/default/menu/checked.gif";
    }
}


function fnShowActionStepRoutersComboBox(orgId, sectionID) {
    //alert(usersList);
    var logConsultant = new Ext.form.ComboBox({
        renderTo: 'divActionStepRoutersComboBox' + sectionID,
        tpl: new Ext.XTemplate('<tpl for="."><div class="search-item"><img id="{UserID}" name="imgActionStepRouters' + sectionID + '" src="Scripts/ext_3_1_0/resources/images/default/menu/unchecked.gif" />{UserName}</div></tpl>'),
        itemSelector: 'div.search-item',
        store: new Ext.data.Store({
            proxy: new Ext.ux.AspNetHttpProxy({
                url: 'FormEntryListService.asmx/ListActionStepRouters'
            }),
            reader: new Ext.ux.aspNetJsonReader({
                root: 'data'
            },
                        [{ name: 'UserID', type: 'string' },
                        { name: 'UserName', type: 'string'}]
                   ),
            listeners: {
                beforeload: function(store, options) {
                    options.params.orgId = orgId;
                },
                load: function() {
                    //setTimeout(function() { fnSetCheckedToNonApproverComboBox(usersList); }, 500);
                    //alert(2);
                }
            }
        }),
        width: 300,
        mode: 'remote',
        triggerAction: 'all',
        displayField: 'UserName',
        valueField: 'UserID',
        emptyText: '--Click to Select--',
        selectOnFocus: true,
        editable: false,
        listeners: {
            'select': function(combo, record, index) {
                if (combo.getValue() != "") {
                    if (document.getElementById(combo.getValue()).src.indexOf("unchecked.gif") >= 0)
                        document.getElementById(combo.getValue()).src = "Scripts/ext_3_1_0/resources/images/default/menu/checked.gif";
                    else
                        document.getElementById(combo.getValue()).src = "Scripts/ext_3_1_0/resources/images/default/menu/unchecked.gif";
                    document.getElementById('cboActionStepRouters' + sectionID).value = "";
                    var len = document.getElementsByName('imgActionStepRouters' + sectionID).length;
                    var imgSrc = '';
                    for (var i = 0; i < len; i++) {
                        if (document.getElementsByName('imgActionStepRouters' + sectionID)[i].src.indexOf("unchecked.gif") < 0) {
                            document.getElementById('cboActionStepRouters' + sectionID).value += "," + document.getElementsByName('imgActionStepRouters' + sectionID)[i].id;
                        }
                    }
                    //alert(combo.getValue());
                    //fnFillNotificationsForm(combo, record);
                }
            }
        }

    });

}
//if page is reopen for any error then make select checkbox of previoud selected nonapprovers.
function fnSetCheckedToActionStepRoutersComboBox(usersList) {
    var len = document.getElementsByName('imgActionStepRouters').length;
    //alert(len);
    var imgSrc = '';
    for (var i = 0; i < len; i++) {
        if (usersList.indexOf(":" + document.getElementsByName('imgActionStepRouters')[i].id + ":") >= 0)
            document.getElementsByName('imgActionStepRouters')[i].src = "Scripts/ext_3_1_0/resources/images/default/menu/checked.gif";
    }
}
function popupHelp() {
    //alert( document.location.protocol + " -- " + document.location.hostname);
    var mypage = document.location.protocol + "//" + document.location.hostname;

    if (document.location.port != null) {
        mypage += ":" + document.location.port;
    }

    mypage += "/Help/HelpPopup.aspx";
    //mypage += "/FormHogDebugging/Help/HelpPopup.aspx";
    //mypage += "/FormHogOnProduction/Help/HelpPopup.aspx";


    var myname = "HelpPopup";
    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    popupWindow = window.open(mypage, myname, settings);

    popupWindow.focus();

}

function popupMERGE(contractId, FileAttachmentID, formId) {
    //alert( document.location.protocol + " -- " + document.location.hostname);
    var mypage = document.location.protocol + "//" + document.location.hostname;

    if (document.location.port != null) {
        if (document.location.port != '') {
            mypage += ":" + document.location.port;
        }
    }
    if (webSiteBaseURL != undefined && webSiteBaseURL.length > 0) {
        mypage = webSiteBaseURL;
    }
    mypage += "/Merge.aspx";
    mypage += "?F=" + formId + "&M=TEMPLATE&FY=FY12&contractId=" + contractId + "&FileAttachmentID=" + FileAttachmentID;
    //alert(mypage);
    var myname = "Merge";
    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    if (Ext.isIE) {
        Ext.Ajax.request({
            url: 'Merge.aspx',
            method: 'POST',
            params: { isIE8: true, F: formId, M: 'TEMPLATE', FY: 'FY12', contractId: contractId, FileAttachmentID: FileAttachmentID },
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            success: function(response, options) {
                if (response.responseText == "Docx" || response.responseText == "Doc") {
                    //window.open('DESE_Export.aspx?O=D&recId=' + contractId + '&ext=' + response.responseText, myname, settings);
                    location.href = 'DESE_Export.aspx?O=D&recId=' + contractId + '&ext=' + response.responseText;
                }
            },
            failure: function(response, options) {
                var res = Ext.decode(response.responseText);
                if (!res) {
                    Ext.Msg.alert('ERROR', 'Server-side failure unknown error');
                } else {
                    if (res.Message != null)
                        Ext.Msg.alert('ERROR', res.Message);
                    else
                        Ext.Msg.alert('ERROR', response.responseText);
                }
            }
        });
    } else {
        popupWindow = window.open(mypage, myname, settings);
        popupWindow.focus();
    }
}

/// <summary>
/// Launches the DatePicker page in a popup window, 
/// passing a JavaScript reference to the field that we want to set.
/// </summary>
/// <param name="strField">String. The JavaScript reference to the field that we want to set, in the format: FormName.FieldName
/// Please note that JavaScript is case-sensitive.</param>

function calendarPicker(strField) {
    window.open('DatePicker.aspx?field=' + strField, 'calendarPopup', 'width=250,height=190,resizable=yes');
}

function confirmDelete(approvalLevel) {
    var approvalLevel = approvalLevel || 0;
    var approval = true;
    if (approvalLevel > 1) {
        approval = confirm("The form has been approved by one of the approvers. Do you still want to delete?");
    }
    if (!approval) return;

    var conf = confirm("Are you sure you want to permanently DELETE this?");
    if (conf == true) {
        setAction("DELETE");
    }

}

///CREATE ON:30 JAN, 2012
///After Merge, form is rendering and call this function when click on save button. 
function confirmSave_AfterMerge() {
    Ext.Msg.show({
        title: 'FormHog',
        msg: 'This will reset the approval process.Are you sure you want to continue?',
        buttons: Ext.Msg.YESNO,
        closable: false,
        fn: function(btn) {
            if (btn == 'yes' && document.getElementById('MergeAction')) {
                document.getElementById('MergeAction').value = 'YES';
            } else if (document.getElementById('MergeAction')) {
                document.getElementById('MergeAction').value = 'NO';
            }
            setAction("SAVE");
        },
        animEl: 'elId',
        icon: Ext.MessageBox.INFO
    });
}

function confirmEdit_ScopeFY13() {
    Ext.Msg.show({
        title: 'FormHog',
        msg: 'This contract has been fully executed. Are you sure you want to edit?',
        buttons: Ext.Msg.OK,
        closable: false,
        fn: function(btn) {
            //alert(btn);
            setAction("EDIT");
        },
        animEl: 'elId',
        icon: Ext.MessageBox.INFO
    });
}

function confirmCopy() {
    var conf = confirm("Are you sure you want to make of COPY of this record?"); //  If you click OK, a copy will be created and you will return to the list of forms.
    if (conf == true) {
        setAction("COPY");
    }
}

function showDiv(idx) {
    var repeatID = "repeat" + idx;
    var twistyID = "twisty" + idx;
    var oDiv = document.getElementById(repeatID);
    var oImg = document.getElementById(twistyID);
    if (oDiv.style.display == "none") {
        oDiv.style.display = "";
        oImg.src = "./Content/Assets/Images/twisty-down.gif";
    }
    else {
        oDiv.style.display = "none";
        oImg.src = "./Content/Assets/Images/twisty-hidden.gif";
    }

}
var isSaveClick = false;
function setAction(action) {
    currentAction = action;
    if (isSaveClick) { return; }
    if (currentAction == 'SAVE' || currentAction == 'SUBMIT' || currentAction == 'DRAFT' || currentAction == 'DRAFT_PDF') {
        isSaveClick = true;
    }
    if (document.getElementById("action") != null) {
        var command = document.getElementById("action");
        command.value = action;
    }
    //            alert("action="+action + "  F=" + document.getElementById("F").value + " M=" + document.getElementById("M").value + "  I=" + document.getElementById("I").value);
    document.forms[0].submit();  //document.forms[0]
}


function setDESEAction(action) {
    currentAction = action;
    if (document.getElementById("action") != null) {
        var command = document.getElementById("action");
        command.value = action;
    }
    //            alert("action="+action + "  F=" + document.getElementById("F").value + " M=" + document.getElementById("M").value + "  I=" + document.getElementById("I").value);
    document.forms[1].submit();  //document.forms[0]
}



function PDFPopup(formID, recID) {
    var mypage = "FormsPDF.aspx?F=" + formID + "&M=P&I=" + recID;
    var myname = "PDFPopup";
    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
    if (recID > 0) {
        popupWindow = window.open(mypage, myname);

        popupWindow.focus();
    } else {
        /*//alert(document.getElementById('tableformWhite').innerHTML);
        params = "htmlBody=" + document.getElementById('tableformWhite').innerHTML + "&resultType=1";
        Initialize();
        if (req != null) {
        req.onreadystatechange = ResponseUpdateProperty;  // Set the callback function
        req.open("POST", 'http://localhost/FormHog/Services/HTMLToPDFService.asmx/GeneratePdf', true);     // Set the method to post to eliminate GET size limits
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(params);
        }*/
        setAction('DRAFT_PDF');
    }
}
function ResponseUpdateProperty() {
    //check wheather property has been updated or not
    //alert(req.readyState);
    if (req.readyState == 4)//If the readyState is in the "Ready" State
    {
        alert(req.statusText);
        if (req.status == 200)//If the returned status code was 200. Everything was OK.
        {
            alert(req.responseText);
        }
    }
}
function PDFPopupFY12(formID, recID) {
    var mypage = "FormsPDF.aspx?REDIR=DESE_Vendor12.aspx&F=" + formID + "&M=P&I=" + recID;
    var myname = "PDFPopup";
    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    popupWindow = window.open(mypage, myname);

    popupWindow.focus();

}
function PDFPopupFY13(formID, recID) {
    var mypage = "FormsPDF.aspx?REDIR=DESE_Vendor13.aspx&F=" + formID + "&M=P&I=" + recID;
    var myname = "PDFPopup";
    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    popupWindow = window.open(mypage, myname);

    popupWindow.focus();

}
/*-----------------------------------------------------------------
Function Name    : HiddenFieldsListPopup
Created          : March 20, 2008 TM
Purpose          : To Provide a popup window for a given filter
Parameters       : sectionID
: h - height in lines
: w - width in characters
Returns          :
-----------------------------------------------------------------*/
function HiddenFieldsList_Testing_NOTUSED(formID) {
    var mypage = "ShowHiddenFields_NOTUSED.aspx?FormID=" + formID;
    //Begin by coder Almighty on 26 March, 2009
    if (document.getElementById("chkChangeLayoutToAllUser") != null) {
        if (document.getElementById("chkChangeLayoutToAllUser").checked)
            mypage = mypage + "&chkChangeLayoutToAllUser=yes";
        else
            mypage = mypage + "&chkChangeLayoutToAllUser=no";
    }
    else
        mypage = mypage + "&chkChangeLayoutToAllUser=yes";
    //End by coder Almighty on 26 March, 2009
    var myname = "ShowHiddenFields";
    var w = 300;
    var h = 300;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0';
    popupWindow = window.open(mypage, myname, settings);

    popupWindow.focus();

}
/*-----------------------------------------------------------------
Function Name    : FilterPopup
Created          : March 20, 2008 TM
Purpose          : To Provide a popup window for a given filter
Parameters       : sectionID
: h - height in lines
: w - width in characters
Returns          :
-----------------------------------------------------------------*/
function FilterPopup(sectionID, w) {
    var mypage = "FilterPopup.aspx?S=" + sectionID + "&M=N";
    var myname = "FilterPopup";
    var h = 400;
    //w=350;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0';
    popupWindow = window.open(mypage, myname, settings);

    popupWindow.focus();

}

/*-----------------------------------------------------------------
Function Name    : NotePopup
Created          : September 21, 2008 TM
Purpose          : To Provide a popup window for a given Note
Parameters       : sectionID
Returns          :
-----------------------------------------------------------------*/
function NotePopup(title, target, formID, sectionID, recID) {
    var mypage = "Note.aspx?F=" + formID + "&S=" + sectionID + "&I=" + recID + "&ju=" + Math.random(1000);
    if (formID == 500289) {
        if (document.getElementsByName('FRECTITLE').length > 0) {
            //alert(document.getElementsByName('FRECTITLE')[0].value);
            mypage += '&Vendor=' + document.getElementsByName('FRECTITLE')[0].value;
        }
    }
    var myname = "NotePopup";
    var h = 375;
    var w = 500;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=1';
    popupWindow = window.open(mypage, myname, settings);

    popupWindow.focus();

}

function fileUpload(formID, recID, userID, fileSubType) {
    var mypage = "FormsUpload.aspx?F=" + formID + "&I=" + recID + "&U=" + userID + "&SUB=" + fileSubType;
    var myname = "uploadPopup";
    var w = 550;
    var h = 175;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;

    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=0,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=0';
    popupWindow = window.open(mypage, myname, settings);

    popupWindow.focus();

}

function updateFileUpload(field, v) {
    var obj = document.all ? document.all[field] : document.getElementById(field);

    if (obj != null) {

        if (document.getElementById(field).value.length > 0)
            document.getElementById(field).value = document.getElementById(field).value + "," + v;
        else
            document.getElementById(field).value = v;

    }
    if (document.getElementById("action") != null)
        document.getElementById("action").value = "noop";
    if (document.forms[0] != "undefined")
        document.forms[0].submit();  //document.forms[0]

}

function deleteAttachment(ID) {
    var obj = document.getElementById("dAttachID");

    if (obj != undefined)
        obj.value = ID;

    var conf = confirm("Are you sure you want to permanently DELETE this Attachment?");
    if (conf == true) {
        setAction("dAttach");
    }

}
function deleteFileAttachment(ID, sectionId) {
    var obj = document.getElementById("dAttachID" + sectionId);

    if (obj != undefined)
        obj.value = ID;

    var conf = confirm("Are you sure you want to permanently DELETE this Attachment?");
    if (conf == true) {
        setAction("dAttach");
    }

}
function deleteDESE_FileAttachment(ID, sectionId) {

    var obj = document.getElementById("dAttachID" + sectionId);

    if (obj != undefined)
        obj.value = ID;

    var conf = confirm("Are you sure you want to permanently DELETE this Attachment?");
    if (conf == true) {

        setDESEATTACHAction("deseDeleteAttach");
    }

}
function setDESEATTACHAction(action) {
    currentAction = action;
    if (document.getElementById("action") != null) {
        var command = document.getElementById("action");
        command.value = action;
    }
    //            alert("action="+action + "  F=" + document.getElementById("F").value + " M=" + document.getElementById("M").value + "  I=" + document.getElementById("I").value);
    if (document.URL.toString().toLowerCase().indexOf('iform.aspx') >= 0) {
        document.forms[0].submit();
    }
    else
        document.DESE_Vendor.submit();
}

////////////////
// StringBuilder
////////////////
function StringBuilder() {
    this.buffer = [];
}

StringBuilder.prototype.Append = function(str) {
    this.buffer[this.buffer.length] = str;
};

StringBuilder.prototype.ConvertToString = function() {
    return this.buffer.join('');
};




function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj == obj.offsetParent);
        return [curleft, curtop];
    }
}

//        function findPos(obj) {
//	        var curleft = curtop = 0;
//	        if (obj.offsetParent) {
//            	do {
//			    	curleft += obj.offsetLeft;
//				    curtop += obj.offsetTop;
//    			} while (obj = obj.offsetParent);
//	    	return [curleft,curtop];
//       	}
//        }

/////////////////////
// Approval Functions
/////////////////////
function selectApprover() {

    var approver = document.getElementById("selApprover");
    //alert(approver.options[approver.selectedIndex].value);
    document.getElementById("approverID").value = approver.options[approver.selectedIndex].value;
}

function setLevel(level, approverID) {
    //alert(approverID+"\n"+level);
    document.getElementById("approverLevel").value = level;
    if (approverID != "")
        document.getElementById("approverID").value = approverID;

    var obj = document.getElementById("selApprover");
    obj.options.length = 0;
    var name;
    var id;
    var opt;
    var x;
    var iFound = false;
    switch (level) {
        case 1:

            for (x = 0; x < userID1.length; x++) {
                if (approverID == userID1[x]) {
                    iFound = true;
                    opt = new Option(name1[x], userID1[x], true);
                    opt.selected = true;
                    obj.options[obj.options.length] = opt;
                }
                else
                    obj.options[obj.options.length] = new Option(name1[x], userID1[x], false);
            }
            if (!iFound) {
                document.getElementById("approverID").value = '';
            }
            break;

        case 2:

            for (x = 0; x < userID2.length; x++) {

                if (approverID == userID2[x]) {
                    iFound = true;
                    opt = new Option(name2[x], userID2[x], true);
                    opt.selected = true;
                    obj.options[obj.options.length] = opt;
                }
                else
                    obj.options[obj.options.length] = new Option(name2[x], userID2[x], false);

            }
            if (!iFound) {
                document.getElementById("approverID").value = '';
            }
            break;

        case 3:

            for (x = 0; x < userID3.length; x++) {
                if (approverID == userID3[x]) {
                    iFound = true;
                    opt = new Option(name3[x], userID3[x], true);
                    opt.selected = true;
                    obj.options[obj.options.length] = opt;
                }
                else
                    obj.options[obj.options.length] = new Option(name3[x], userID3[x], false);
            }
            if (!iFound) {
                document.getElementById("approverID").value = '';
            }
            break;

        case 4:

            for (x = 0; x < userID4.length; x++) {
                if (approverID == userID4[x]) {
                    iFound = true;
                    opt = new Option(name4[x], userID4[x], true);
                    opt.selected = true;
                    obj.options[obj.options.length] = opt;
                }
                else
                    obj.options[obj.options.length] = new Option(name4[x], userID4[x], false);

            }
            //Begin by coder Almighty on 25 JUNE, 2010
            //When user at level 3 open form in approval mode then user is selected at step-3,
            //Now if user select step-4 and no user is selected and then approved then user is set to approver at level 4 ,
            //wheather he is permitted or not for approval at level4.
            if (!iFound) {
                document.getElementById("approverID").value = '';
            }

            break;

        case 5:

            if (userID5 != null) {
                for (x = 0; x < userID5.length; x++) {
                    if (approverID == userID5[x]) {
                        opt = new Option(name5[x], userID5[x], true);
                        opt.selected = true;
                        obj.options[obj.options.length] = opt;
                    }
                    else
                        obj.options[obj.options.length] = new Option(name5[x], userID5[x], false);
                }
            } else {
                opt = new Option("APPROVAL IS COMPLETE", approverID, true);
                opt.selected = true;
                obj.options[obj.options.length] = opt;
            }

            break;

        // APPROVAL COMPLETE      
        case 6:

            //                obj.options.length=0;
            opt = new Option("APPROVAL IS COMPLETE", approverID, true);
            opt.selected = true;
            obj.options[obj.options.length] = opt;

            break;

    }
}

//var req;
//var browser;

function Initialize() {
    try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
        browser = "ff";
    }
    catch (e) {
        try {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            browser = "ie";
        }
        catch (oc) { req = null; }
    }

    if (!req && typeof XMLHttpRequest != "undefined") {
        req = new XMLHttpRequest();
        browser = "ff";
    }

}

function fhRequiredField(sectionID) {

    var ie = document.all;
    var fieldLen = 0;
    var field = document.getElementById(sectionID);

    //field.value = UltimateSpellAsYouTypes[sectionID].GetSpellText();
    //Almighty commented on `8 June, 2009
    //fieldLen = UltimateSpellAsYouTypes[sectionID].GetSpellText().length;
    fieldLen = field.value.length; //Written by Almighty on 18 June, 2009

    //  if (ie) {fieldLen = field.value.length;}
    //    else {fieldLen = sectionID.textContent.length;}
    //    alert('fieldLen=' + fieldLen);

    var imageID = sectionID.toString().replace('S', 'I');
    var sectionLabel = sectionID.toString().replace('S', 'L');
    if (fieldLen < 3) {

        document.getElementById(sectionLabel).innerHTML = 'Required';
        document.getElementById(imageID).style.visibility = 'visible';
        //Almighty commented on `8 June, 2009
        //UltimateSpellAsYouTypes[sectionID].style.backgroundColor = '#faafba';//Almigtyy
        document.getElementById(sectionID).style.backgroundColor = '#faafba';

    }
    else {
        document.getElementById(sectionLabel).innerHTML = '';
        document.getElementById(imageID).style.visibility = 'hidden';
        //Almighty commented on `8 June, 2009
        //UltimateSpellAsYouTypes[sectionID].isEnabled = false;//Almigtyy

        field.color = "white";
        field.style.cssText = "background:white;";
        field.style.cssText = "backgroundColor:white;";
        //Almighty commented on `8 June, 2009
        //UltimateSpellAsYouTypes[sectionID].isEnabled = true;//Almigtyy
    }
}

function fhSaveField(sectionID, sectionType, formID, recID, val) {
    //alert(val);

    var ie = document.all;
    var fieldLen = 0;
    var field;
    if (document.getElementById(sectionID))
        field = document.getElementById(sectionID);
    //alert(sectionType);
    //alert(val);
    var value = "";
    if ((val != null) && (val != "undefined")) value = val;

    switch (sectionType.toString().toUpperCase()) {
        case "S":  // Spell
            //Almighty commented on `8 June, 2009
            //value=UltimateSpellAsYouTypes[sectionID].GetSpellText(); //Almighty commenteds
            if (document.getElementById(sectionID))
                value = document.getElementById(sectionID).value;
            break;

        case "TA":
            //Begin by coder Almighty on 02 SEP, 2009
            //commented because document.getElementById(sectionID) returns value with format and also
            //return always old value not updated. 
            //if(document.getElementById(sectionID))
            //    value=document.getElementById(sectionID).value;
            //End by coder Almighty on 02 SEP, 2009
            break;
        case "T":
            //alert(document.getElementById(sectionID).value);
            if (document.getElementById(sectionID))
                value = document.getElementById(sectionID).value;
            break;
        case "C":
            if (value == "" && document.getElementById(sectionID)) {
                var combo = document.getElementById(sectionID);
                //                value=combo.options[combo.selectedIndex].value;
                for (var x = 0; x < combo.options.length; x++) {
                    if (combo.options[x].selected == true) {
                        value += combo.options[x].value + ","
                        break;
                    }
                }
                if (value.length > 0)
                    value = value.substr(0, value.length - 1);
            }
            break;
        case "CH":
            value = "";
            var f = document.forms[0];
            var check = f.elements[sectionID];
            for (var x = 0; x < check.length; x++) {
                if (check[x].checked)
                    value += check[x].value + ","
            }
            if (value.length > 0)
                value = value.substr(0, value.length - 1);

            break;
        //        case "S":       
        //                value=UltimateSpellAsYouTypes[sectionID].GetSpellText();      

        //        case "R":      
        //                var radio=document.getElementById(sectionID);      
        //                for (var x=0; x<radio.length; x++)       
        //                {      
        //                    if (radio[x].checked == true) {      
        //                      value = radio[x].value;       
        //                      break;      
        //                    }      
        //                }      

        //                break;      
        default:
            break;

    }

    //        fieldLen = value.length; 

    //alert("s=" + sectionID + " f=" + formID + " i=" + recID + " value=" + value);


    if (formID > 0) {
        var url = "";
        Ext.MessageBox.wait('Updating ...', 'FormHog');
        value = value.toString().replace(/&/g, "|");
        //        alert("Value="+value);
        if (value.toString().indexOf('&') >= 0) {
            value = RemoveCharsFromString(value, '&', '_AMP_');
        }
        if (value.toString().indexOf('#') >= 0) {
            value = RemoveCharsFromString(value, '#', '_HASH_');
        }
        var tempVal = '';

        if (recID > 0)
            url = "SectionSave.aspx?s=" + sectionID + "&f=" + formID + "&i=" + recID + "&v=" + value + "&ju=" + Math.random(1000);
        else
            url = "SectionCheck.aspx?s=" + sectionID + "&v=" + value;
        if (formID == 500013) {
            if (document.getElementById('hdnTableLookupComboBox1002166') != null)
                tempVal = '&ContractTitle=' + document.getElementById('hdnTableLookupComboBox1002166').value;
            var tempFiscal_Year = '';
            if (document.getElementsByName('Fiscal_Year').length > 0) {
                tempFiscal_Year = '&Fiscal_Year=' + document.getElementsByName('Fiscal_Year')[0].value;
            }
            url = url + tempVal + tempFiscal_Year;
        }
        //alert(url);
        timer = 0;
        Initialize();

        if (req != null) {
            req.onreadystatechange = textProcess;
            req.open("POST", url, true);
            req.send(null);
        }

    }

}
// This function will be called on KeyUp event of the textarea and textbox control, if isrequired=true
function fhKeyUpField(sectionID, sectionType, formID, recID, val) {
    var imageID = sectionID.toString().replace("S", "") + "I";
    if (val == '') {
        if (document.getElementById(imageID))
            document.getElementById(imageID).style.visibility = "visible";
        if (document.getElementById(sectionID)) {
            document.getElementById(sectionID).style.backgroundColor = "#faafba";
            //document.getElementById(sectionID).contentWindow.document.body.style.backgroundColor = "#faafba";
        }
        if (jspellControl != null && jspellControl != undefined) {
            jspellControl.style.backgroundColor = "#faafba";
        }
    } else if (val != '') {
        if (document.getElementById(imageID))
            document.getElementById(imageID).style.visibility = "hidden";
        if (document.getElementById(sectionID)) {
            document.getElementById(sectionID).style.backgroundColor = "#ffffff";
            //document.getElementById(sectionID).contentWindow.document.body.style.backgroundColor = "#ffffff";
        }
        if (jspellControl != null && jspellControl != undefined) {
            jspellControl.style.backgroundColor = "#ffffff";
        }
    }
}

function fhSetSaveField(sectionID, sectionType, formID, recID, val) {

    if ((timer > 0) & (timerSectionID == sectionID)) {
        clearTimeout(timer);
        timer = 0;
    }
    var exp = "fhSaveField('" + sectionID + "','" + sectionType + "','" + formID + "','" + recID + "','" + val + "')";
    timer = setTimeout(exp, 1500);
    timerSectionID = sectionID;

}




function textUpdate(sectionID) {
    timer = 0;
    var value = 0;
    if (document.getElementById(sectionID) != null)
        value = document.getElementById(sectionID).value;
    Initialize();
    var url = "SectionCheck.aspx?s=" + sectionID + "&v=" + value;

    if (req != null) {
        req.onreadystatechange = textProcess;
        req.open("GET", url, true);
        req.send(null);

    }

}

function getReply() {
}

function pwdUpdate(sectionID) {
    timer = 0;

    var currentPWD = document.getElementById("currentPWD").value;
    var newPWD = document.getElementById("newPWD").value;
    var retypePWD = document.getElementById("retypePWD").value;
    Initialize();
    var url = "SectionCheck.aspx?s=" + sectionID + "&v=&c=" + currentPWD + "&n=" + newPWD + "&r=" + retypePWD;

    if (req != null) {
        req.onreadystatechange = textProcess;
        req.open("GET", url, true);
        req.send(null);

    }

}
function radioUpdate(sectionID, value) {
    timer = 0;

    Initialize();
    var url = "SectionCheck.aspx?s=" + sectionID + "&v=" + value;

    if (req != null) {
        req.onreadystatechange = textProcess;
        req.open("GET", url, true);
        req.send(null);

    }

}

function comboUpdate(sectionID, fieldID) {
    timer = 0;

    var combo = document.getElementById(fieldID);
    var value = combo.options[combo.selectedIndex].value;
    Initialize();
    var url = "SectionCheck.aspx?s=" + fieldID + "&v=" + value;

    if (req != null) {
        req.onreadystatechange = textProcess;
        req.open("GET", url, true);
        req.send(null);

    }

}
var jspellControl = null;
function textProcess() {   //alert(req.readyState);
    Ext.MessageBox.hide();
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            if (req.responseText.toString().length > 0) {
                // DEBUG                    
                //                        document.getElementById("debugStatus").value = req.responseText.toString();

                var response = req.responseText.split("=");
                var sectionID = response[0];
                var imageID = sectionID.toString().replace("S", "") + "I";
                var sectionLabel = sectionID.toString().replace("S", "") + "L";
                var actions = response[1].split(";");
                var status = "";
                var style = "";
                var sectionObj;
                var useSpellCheck = false;
                //alert("textProcess sectionID=" + response[0] + " actions=" + response[1]);

                if (response[1].length > 0) {

                    for (x = 0; x < actions.length; x++) {
                        useSpellCheck = false;
                        var commands = actions[x].split(":");

                        if (commands[0] == "ERROR") {
                            style = "ALERT";
                            status = "Error Saving!";
                            alert("Error Saving Data: SectionID= " + sectionID + " Error=" + commands[1]);
                        }
                        else if (commands[0] == "STATUS")
                            status = commands[1];
                        else if (commands[0] == "STATUSSPELL") {
                            status = commands[1];
                            useSpellCheck = true;
                        }
                        else if (commands[0] == "STYLESPELL") {
                            style = commands[1];
                            useSpellCheck = true;
                        }
                        else if (commands[0] == "STYLE")
                            style = commands[1];
                        else if (commands[0] == "STATUS_CPWD") {
                            sectionID = "currentPWD";
                            imageID = "currentPWDI";
                            sectionLabel = "currentPWDL";
                            status = commands[1];

                        }
                        else if (commands[0] == "STYLE_CPWD") {
                            sectionID = "currentPWD";
                            imageID = "currentPWDI";
                            sectionLabel = "currentPWDL";
                            style = commands[1];

                        }
                        else if (commands[0] == "STATUS_NPWD") {
                            sectionID = "newPWD";
                            imageID = "newPWDI";
                            sectionLabel = "newPWDL";
                            status = commands[1];

                        }
                        else if (commands[0] == "STYLE_NPWD") {
                            sectionID = "newPWD";
                            imageID = "newPWDI";
                            sectionLabel = "newPWDL";
                            style = commands[1];

                        }
                        else if (commands[0] == "STATUS_RPWD") {
                            sectionID = "retypePWD";
                            imageID = "retypePWDI";
                            sectionLabel = "retypePWDL";
                            status = commands[1];

                        }
                        else if (commands[0] == "STYLE_RPWD") {
                            sectionID = "retypePWD";
                            imageID = "retypePWDI";
                            sectionLabel = "retypePWDL";
                            style = commands[1];

                        }
                        else if (commands[0] == "ErrorContract") {
                            style = commands[1];
                        }
                        else if (commands[0] == "Invoice_Frequency") {
                            //alert(commands[1]);
                            if (parent.document.getElementById('1004343S') != null) {
                                parent.document.getElementById('1004343S').value = commands[1];
                            }
                            if (parent.document.getElementById('Invoice_Frequency') != null) {
                                parent.document.getElementById('Invoice_Frequency').value = commands[1];
                            }
                        }

                        //    alert("label=" + sectionLabel + "  status=" + status);
                        //if (document.getElementById(sectionLabel))
                        //    document.getElementById(sectionLabel).innerHTML = status;
                        var temp = "";

                        if (style == "ALERT") {
                            if (useSpellCheck) {
                                //Almighty temp = UltimateSpellAsYouTypes[sectionID].usd1f;
                                //                                        temp = UltimateSpellAsYouTypes[sectionID].GetSpellText();
                                if (document.getElementById(sectionID))
                                    temp = document.getElementById(sectionID).value;
                                if (document.getElementById(imageID))
                                    document.getElementById(imageID).style.visibility = "visible";
                                //                                        document.getElementById(sectionID).style.backgroundColor = "#faafba";
                                //                                        document.getElementById(sectionID).style["background-color"]="#faafba";;
                                if (document.getElementById(sectionID))
                                    document.getElementById(sectionID).className = "spellAlert";
                                if (temp != "") //added by Almighty
                                    document.getElementById(temp).contentWindow.document.body.style.backgroundColor = "#faafba";
                                //Almighty: UltimateSpellAsYouTypes[sectionID].Position();
                                if (jspellControl != null && jspellControl != undefined) {
                                    jspellControl.style.backgroundColor = "#faafba";
                                }
                            } else {
                                if (document.getElementById(imageID))
                                    document.getElementById(imageID).style.visibility = "visible";
                                if (document.getElementById(sectionID))
                                    document.getElementById(sectionID).style.backgroundColor = "#faafba";
                            }
                        } else {
                            if (useSpellCheck) {
                                //Almighty temp = UltimateSpellAsYouTypes[sectionID].usd1f;
                                //                                        temp = UltimateSpellAsYouTypes[sectionID].GetSpellText();
                                if (document.getElementById(sectionID))
                                    temp = document.getElementById(sectionID).value;
                                if (document.getElementById(imageID))
                                    document.getElementById(imageID).style.visibility = "hidden";
                                //                                        document.getElementById(sectionID).style.backgroundColor = "#ffffff";
                                //                                        document.getElementById(sectionID).style["background-color"]="#ffffff";;
                                //                                        UltimateSpellAsYouTypes[sectionID].Position();
                                //                                        UltimateSpellAsYouTypes[sectionID].SetSpellText(temp);
                                //                                      temp = UltimateSpellAsYouTypes[sectionID].usd1f;

                                //                                        temp = UltimateSpellAsYouTypes[sectionID].usd1f;
                                //                                        document.getElementById(imageID).style.visibility = "hidden";
                                if (temp != "") {//added by Almighty
                                    if (document.getElementById(temp) != null) {
                                        document.getElementById(temp).contentWindow.document.body.style.backgroundColor = "#ffffff";
                                    }
                                }
                                if (document.getElementById(sectionID))
                                    document.getElementById(sectionID).className = "spellNone";
                                if (jspellControl != null && jspellControl != undefined) {
                                    jspellControl.style.backgroundColor = "#ffffff";
                                }
                                //UltimateSpellAsYouTypes[sectionID].Position();
                            }
                            else {
                                if (document.getElementById(imageID))
                                    document.getElementById(imageID).style.visibility = "hidden";
                                if (document.getElementById(sectionID))
                                    document.getElementById(sectionID).style.backgroundColor = "#ffffff";
                                if (style.indexOf('Scope already exists') >= 0) {
                                    alert(style);
                                }
                            }
                        }
                    }
                }
            }
        }
        else {
            if (currentAction != '') {
                return;
            }
            //alert("There was a problem retrieving data:<br>" + req.statusText);
            if (Ext.isChrome) {
                if (req.status != 0) {
                    alert("There was a problem retrieving data:<br>" + req.statusText);
                }
            } else {
                alert("There was a problem retrieving data:<br>" + req.statusText);
            }
        }
    }
}

var timer = 0;         // Javascript Timer
var timerSectionID = "";   // SectionID the timer is currently set for

// Function to delay the send request for 1 seconds, in case the user is typing
// quickly - it will wait for 1 seconds before sending
function textSend(sectionID) {

    // If we are waiting for the timer and another key is pressed - reset the counter
    if ((timer > 0) & (timerSectionID == sectionID)) {
        clearTimeout(timer);
        timer = 0;
    }
    var exp = "textUpdate('" + sectionID + "')";
    timer = setTimeout(exp, 1400);
    timerSectionID = sectionID;
}

function getWindowHeight() {

    var windowHeight = 0;

    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {

        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }

    }

    return windowHeight;
}


/////////////////
// Note Functions
/////////////////
var note = null;

function noteAppear(title, target, sectionID, recID) {
    var pos = findPos(target);
    var HTML = new StringBuilder();

    //            var temp = sectionID+"F";
    note = document.createElement("DIV");
    note.id = 'noteDiv' + sectionID;
    note.className = 'noteDiv';
    note.style.position = 'absolute';
    note.style.left = "200px";
    note.style.top = "0px";
    note.style.width = "150px";
    note.style.height = "200px";
    //	        //note.style.zIndex="999";
    //	        bringSelectedIframeToTop(true);
    //	        
    ///	        note.innerHTML = "<iframe id='note"+sectionID+"' name='note"+sectionID+"' width='200px' height='200px;' frameborder=1 src='Note.aspx?S="+sectionID+"&I="+recID+"&ju="+Math.random(1000)+"' />";
    //note.src="Note.aspx?S="+sectionID+"&I="+recID+"&ju="+Math.random(1000);;
    HTML.Append("<div id='noteTitle' class='noteTitle'>Note: " + title + "</div>");
    HTML.Append("<div class='noteDisappear' onclick='body.removeChild(note)' title='close'>&#215;</div>");
    HTML.Append("<div class='note'><div id='noteBody'></div></div>");
    HTML.Append("<div class='noteAdd'><b>Add Note:</b>");
    HTML.Append("<br><textarea id='newNote' style='height:35px;' cols='27' rows='2' name='newNote'></textarea>");
    HTML.Append("<br><b>Color:</b> ");
    //    
    //	        
    HTML.Append("<div id='colorPicker'>");

    HTML.Append("<div id='black' class='colorBox' style='background-color:Black;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='aqua' class='colorBox' style='background-color:Aqua;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='blue' class='colorBox' style='background-color:Blue;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='fuchsia' class='colorBox' style='background-color:Fuchsia;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='green' class='colorBox' style='background-color:Green;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='red' class='colorBox' style='background-color:Red;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='olive' class='colorBox' style='background-color:Olive;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("<div id='yellow' class='colorBox' style='background-color:Yellow;' onclick='colorSelect(this.id);'></div>");
    HTML.Append("</div>");

    HTML.Append("<input type='hidden' name='colorSelected' value='' />");
    HTML.Append("<input type='button' style='position:relative;left:15px;top:-10px;' value='Add'  onclick='javascript:noteAdd(" + sectionID + "," + recID + ");' />");
    HTML.Append("<input type='button' style='position:relative;left:20px;top:-10px;' value='Cancel' onclick='body.removeChild(note)' /></div>");

    note.innerHTML = HTML.ConvertToString();

    //	        note.setAttribute("class","noteDiv");
    //	        note.style.position = "absolute";
    //	        note.style.zIndex = "199";
    //	        
    note.style.left = (pos[0] + 20) + "px";
    note.style.top = (pos[1] - 80) + "px";
    //	        note.style.left = (pos[0])+"px"; 
    //	        note.style.top = (pos[1])+"px";
    //	        
    ////            if (window.parent != null)
    window.frames[1].document.getElementsByTagName('body')[0].appendChild(note);
    ////            else
    ////	            document.getElementsByTagName('body')[0].appendChild(note);
    //	        temp = sectionID+'S';
    //        document.getElementsById(temp).appendChild(note);

    //            document.getElementsByTagName('body')[0].appendChild(note);
    //            	        
    // Begin Ajax lookup
    Initialize();
    var url = "Note.aspx?S=" + sectionID + "&I=" + recID + "&M=E&ju=" + Math.random(1000);

    if (req != null) {
        req.onreadystatechange = noteReceive;
        req.open("GET", url, true);
        req.send(null);

    }

}



function setFooter() {

    if (document.getElementById) {

        var windowHeight = getWindowHeight();

        if (windowHeight > 0) {
            var headerHeight = 0;

            var contentHeight = document.getElementById('filterContent').offsetHeight;
            if (document.getElementById('header') != null)
                headerHeight = document.getElementById('header').offsetHeight;

            var footerElement = document.getElementById('footerFloat');
            var footerHeight = footerElement.offsetHeight;
            var content = document.getElementById('filterContent');

            if ((windowHeight - footerHeight - headerHeight) > 0)
                content.style.height = (windowHeight - footerHeight - headerHeight) + 'px';

        }
    }
}

var sourceListIDs = "";
////showServerActionList("CHECKBOX","FRECTITLE","T500022","100002, 100005, 100006, 100003","T500017");
function showServerActionList(sourceType, parentTableId, sourceIDs) {
    var sourceIDs = "";
    sourceListIDs = showListInDivIDs;
    sourceName = sourceTable + '.' + sourceName;
    if (sourceType == "CHECKBOX") {
        var source = document.getElementsByName(sourceName);
        if (source.length > 0) {
            for (var i = 0; i < source.length; i++) {
                if (source[i].checked) {
                    sourceIDs += "," + source[i].value;
                }
            }
        }
    } else if (sourceType == "COMBOBOX") {


    }
    if (sourceIDs.length > 1)
        sourceIDs = sourceIDs.substr(1);
    Initialize();
    var url = "CommonAJAX.aspx?opr=getServerActionList&dt=" + Math.random(1000);
    if (req != null) {
        var params = "sourceTable=" + sourceTable + "&sourceIDs=" + sourceIDs + "&listToTable=" + parentTableId;
        req.onreadystatechange = resultShowServerActionList;
        req.open("POST", url, true);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(params);
    }
}
function resultShowServerActionList() {
    if (req.readyState == 4) {
        if (req.status == 200) {
            //alert(req.responseText.toString());
            if (req.responseText.toString().length > 0) {
                //alert(sourceListIDs);
                if (sourceListIDs.indexOf(",") >= 0) {
                    var str = sourceListIDs.split(",");
                    if (str.length > 0) {
                        for (var i = 0; i < str.length; i++) {
                            if (document.getElementById('div' + str[i]) != null) {
                                document.getElementById('div' + str[i]).innerHTML = req.responseText.toString();
                            }
                        }
                    }
                } else {
                    //alert(document.getElementById('div'+sourceListIDs));
                    //divServerAction
                    var divServerAction = Ext.query('.divServerAction');
                    //alert(divServerAction.length);
                    if (divServerAction.length > 0) {
                        Ext.each(divServerAction, function(item, index) {
                            //if (item != null && item.parentNode != null)
                            //item.parentNode.innerHTML = "";
                            //alert(item.id);
                        });
                    }
                    //var iframeEl = document.getElementById('frameGoal');
                    //alert(iframeEl);
                    //var form = iframeEl.contentDocument.getElementById('formHog');
                    //alert(form.name);
                    if (parent.document.getElementById('div' + sourceListIDs) != null)
                        parent.document.getElementById('div' + sourceListIDs).innerHTML = req.responseText.toString();
                }
            }
        }
    }
}
function fhSaveServerActionField(sourceType, sourceName)//,sourceTable,showListInDivIDs,parentTableId,updateTableId,updateFieldName
{
    var sourceIDs = "";
    //sourceListIDs=showListInDivIDs;
    //sourceName=sourceTable+'.'+sourceName;
    var parentTableId = sourceName.split('.')[0];
    if (sourceType == "CHECKBOX") {
        var source = document.getElementsByName(sourceName);
        if (source.length > 0) {
            for (var i = 0; i < source.length; i++) {
                if (source[i].checked) {
                    sourceIDs += "," + source[i].value;
                }
            }
        }
    } else if (sourceType == "COMBOBOX") {

    }
    if (sourceIDs.length > 1)
        sourceIDs = sourceIDs.substr(1);
    //alert(sourceIDs);
    var divServerAction = Ext.query('.divServerAction');
    //alert(divServerAction.length);
    var sectionFieldName = "";
    if (divServerAction.length > 0) {
        var updateTableId = "";
        var updateFieldName = "";
        var updateFromTableId = parentTableId;
        var updateFromFieldName = updateFieldName;
        var recId = "";
        var divId = "";

        Ext.each(divServerAction, function(item, index) {
            //if (item != null && item.parentNode != null)
            //item.parentNode.innerHTML = "";
            //alert(item.id);
            updateTableId = item.getAttribute("updateTableId");
            updateFieldName = item.getAttribute("updateFieldName");
            recId = item.getAttribute("recID");
            divId = item.getAttribute("id");
            updateFromFieldName = updateFieldName;
            sectionFieldName = item.getAttribute("sectionFieldName");
            //setTimeout(function(){fnSaveServerAction(sourceIDs,updateTableId,updateFieldName,updateFromTableId,updateFromFieldName,recId,divId,'');},1000);
            //alert(sourceIDs + ":" + sectionFieldName);
            //alert(document.getElementById('hdn' + sectionFieldName));
            var hdnServerAction = Ext.query('.hdn');
            //alert(hdnServerAction.length);
            Ext.each(hdnServerAction, function(item, index) {
                //alert(item.getAttribute("name"));
                if (item.getAttribute("name") == sectionFieldName) {
                    item.value = sourceIDs;
                    //alert(item.value);
                }
            });

            fnSaveServerAction(sourceIDs, updateTableId, updateFieldName, updateFromTableId, updateFromFieldName, recId, divId, '');
        });
    }
    var divIds = parent.document.getElementsByTagName('div');
    var l = divIds.length;
    //alert(divIds.length);
    //alert(parent.id);
    if (l > 0) {
        for (var i = 0; i < l; i++) {
            //alert(divIds[i].getAttribute('name'));
            if (divIds[i].getAttribute('name') == parentTableId) {
                //alert(divIds[i].id);
                updateTableId = divIds[i].getAttribute("updateTableId");
                updateFieldName = divIds[i].getAttribute("updateFieldName");
                recId = divIds[i].getAttribute("recID");
                divId = divIds[i].id;
                updateFromFieldName = updateFieldName;
                sectionFieldName = divIds[i].getAttribute("sectionFieldName");
                var hdnIds = parent.document.getElementsByName(sectionFieldName);
                //alert(hdnIds.length);
                for (var j = 0; j < hdnIds.length; j++) {
                    //alert(hdnIds[j].getAttribute('id'));
                    if (hdnIds[j].getAttribute('id').indexOf('hdn') >= 0) {
                        //hdnIds[j].value = sourceIDs;
                    }
                    //alert(hdnIds[j].value);
                }
                //setTimeout(function(){fnSaveServerAction(sourceIDs,updateTableId,updateFieldName,updateFromTableId,updateFromFieldName,recId,divId,'Parent');},1000);
                setTimeout(function() { fnSaveServerAction(sourceIDs, updateTableId, updateFieldName, updateFromTableId, updateFromFieldName, recId, divId, 'Parent'); }, 1000);
            }
        }
    }
}
var reqSaveServerAction = null;
function GetInitializeRequest() {
    var reqSave;
    try { reqSave = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { reqSave = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (oc) { reqSave = null; }
    }

    if (!reqSave && typeof XMLHttpRequest != "undefined") {
        reqSave = new XMLHttpRequest();
    }
    return reqSave;
}
var divUpdateId = "";
var parentForm = "";
function fnSaveServerAction(sourceListIds, updateTableId, updateFieldName, updateFromTableId, updateFromFieldName, recID, divId, parentFormID) {
    divUpdateId = divId;
    parentForm = parentFormID
    reqSaveServerAction = GetInitializeRequest();
    var url = "CommonAJAX.aspx?opr=getSaveServerActionField&dt=" + Math.random(1000);
    if (reqSaveServerAction != null) {
        //alert(url);
        var params = "updateTableId=" + updateTableId + "&updateFieldName=" + updateFieldName + "&value=" + sourceListIds + "&recID=" + recID + "&updateFromTableId=" + updateFromTableId + "&updateFromFieldName=" + updateFromFieldName;
        reqSaveServerAction.onreadystatechange = resultSavewServerActionList;
        //reqSaveServerAction.open("POST", url, false);
        if (Ext.isGecko) {
            reqSaveServerAction.open("POST", url, true);
        } else {
            reqSaveServerAction.open("POST", url, false);
        }
        reqSaveServerAction.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        reqSaveServerAction.send(params);
    }
}
function resultSavewServerActionList() {
    //alert(reqSaveServerAction.readyState);
    if (reqSaveServerAction.readyState == 4 && reqSaveServerAction.status == 200) {
        //alert(parentForm);
        if (parentForm == "Parent" && divUpdateId != "") {
            if (parent.document.getElementById(divUpdateId) != null) {
                if (reqSaveServerAction.responseText.toString().indexOf("__|__") >= 0) {
                    parent.document.getElementById(divUpdateId).innerHTML = reqSaveServerAction.responseText.toString().split("__|__")[0];
                    if (parent.document.getElementById(divUpdateId).innerHTML == '') {
                        parent.document.getElementById(divUpdateId).innerHTML = '&nbsp;';
                    }
                    if (divUpdateId.length > 3) {
                        if (parent.document.getElementById('hdn' + divUpdateId.substr(3)) != null) {
                            parent.document.getElementById('hdn' + divUpdateId.substr(3)).value = reqSaveServerAction.responseText.toString().split("__|__")[1];
                        }
                    }
                } else
                    parent.document.getElementById(divUpdateId).innerHTML = reqSaveServerAction.responseText.toString();
            }
            //alert(reqSaveServerAction.responseText.toString());
        } else if (parentForm == "") {
            //alert(divUpdateId);
            if (document.getElementById(divUpdateId) != null)
                document.getElementById(divUpdateId).innerHTML = reqSaveServerAction.responseText.toString();
        }
    }
}

function showFormUpdates(FormId) {
    panelContent = new Ext.Panel({
        region: 'center',
        margins: '0 0 0 0',
        autoScroll: true,
        html: '<iframe style="overflow:auto;width:100%;height:100%;" frameborder="0"  src="FormUpdates.aspx?FormID=' + FormId + '"></iframe>'
    });
    browser = new Ext.Window({
        title: 'Form Updates',
        closable: true,
        closeAction: 'hide',
        width: 600,
        height: 600,
        border: false,
        plain: true,
        buttons: [{ text: 'Close', handler: function() { browser.close() } }],
        layout: 'border',
        items: [panelContent]
    });

    browser.show();
}

function deseNoveContractTemplateMergePopup(formID, fy, sectionID, recId) {
    var mergeID = document.getElementById(sectionID).value;
    var mode = 'TEMPLATE';

    var mypage = "Merge.aspx?F=" + formID + "&M=" + mode + "&fy=" + fy + "&I=" + mergeID + "&contractId=" + recId;
    var myname = "DESENOVA";

    var w = 715;
    var h = 402;

    var LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    var TopPosition = (screen.height) ? (screen.height - h) / 2 : 100;
    var settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=1,location=0,directories=0,status=0,menubar=0,toolbar=0,resizable=1';

    desePopupWindow = window.open(mypage, myname, settings);
    desePopupWindow.focus();

}

//DESE Contract FY12
function fnEnableDisableSendToList(cbo, approvalLevel) {
    if (document.getElementById('approverID')) {
        if (cbo.value == 500) {
            document.getElementById('approverID').disabled = false;
        } else
            document.getElementById('approverID').disabled = true;
    }
    if (cbo.value == 1 || cbo.value == 500 || cbo.value == 2000) {
        if (document.getElementById('cboApprovalLevel')) {
            document.getElementById('cboApprovalLevel').value = approvalLevel;
            document.getElementById('ApprovalLevel').value = approvalLevel;
            document.getElementById('cboApprovalLevel').disabled = true;
        }
    } else {
        document.getElementById('cboApprovalLevel').disabled = false;
    }
}

function fnChangeApprovalLevel(ctrl) {
    document.getElementById('ApprovalLevel').value = ctrl.value;
}

function fnEnableDisableApprovalLevel(cbo, approvalLevel) {
    if (document.getElementById('approverID')) {
        if (cbo.value == 500) {
            document.getElementById('approverID').disabled = false;
        } else
            document.getElementById('approverID').disabled = true;
    }
    if (cbo.value == 1 || cbo.value == 500 || cbo.value == 2000) {
        if (document.getElementById('cboApprovalLevel')) {
            document.getElementById('cboApprovalLevel').value = approvalLevel;
            document.getElementById('ApprovalLevel').value = approvalLevel;
            document.getElementById('cboApprovalLevel').disabled = true;
        }
    } else {
        document.getElementById('cboApprovalLevel').disabled = false;
    }
}

function fnChangeNovaContractApprovalLevel(ctrl) {
    document.getElementById('ApprovalLevel').value = ctrl.value;
}
function fnDateEmpty() {
    return;
}
function fhSetRequiredForIntended_Outcome(Intended_Outcome, val) {
    //textbox :1002196
    //
    //alert(val);
    if (val.indexOf('None') < 0) {
        if (document.getElementById('1002196S') && document.getElementById('1002196S').value == '') {
            if (document.getElementById('1002196I'))
                document.getElementById('1002196I').style.visibility = "visible";
            if (document.getElementById('1002196S'))
                document.getElementById('1002196S').style.backgroundColor = "#faafba";
        }
    } else {
        if (document.getElementById('1002196I'))
            document.getElementById('1002196I').style.visibility = "hidden";
        if (document.getElementById('1002196S'))
            document.getElementById('1002196S').style.backgroundColor = "#ffffff";
    }
}

function fnFillActivityType(val) {
    if (val == 'FY10') {
        window.frames["frameActivity"].FILL_ActivityTypeListFY10();
    } else if (val == 'FY11') {
        window.frames["frameActivity"].FILL_ActivityTypeListFY11();
    } else if (val == 'FY12') {
        window.frames["frameActivity"].FILL_ActivityTypeListFY12();
    } else if (val == 'FY13') {
        window.frames["frameActivity"].FILL_ActivityTypeListFY13();
    }
}
var MessageAlreadyDisplayInCalenday = false;
function fnCheckContractPeriod(value) {
    if (MessageAlreadyDisplayInCalenday) {
        MessageAlreadyDisplayInCalenday = false;
        return;
    }
    var beginDate = new Date(document.getElementById('ContractBeginDate').value);
    //alert(window.opener.document.getElementById('ContractBeginDate').value);
    //alert(window.opener.document.getElementById('ContractEndDate').value);
    var endDate = new Date(document.getElementById('ContractEndDate').value);
    if (new Date(value) < beginDate || new Date(value) > endDate) {
        alert('Date is outside of specified contract period. Do you want to accept this?');
    }
}

//It is used in PBS data collection management tool for Per Day Per Month Rate
function fnCalculatePerDay(id) {
    var day = document.getElementById(id + 'day').value;
    var month = document.getElementById(id + 'month').value;
    if (day == '') { return; }
    if (month == '') {
        document.getElementById(id + 'perday').value = '0';
        return;
    }
    if (isNaN(day) || day == '') {
        day = parseFloat(0.0);
    }
    if (isNaN(month) || month == '') {
        month = parseFloat(0.0);
    }

    // alert(parseFloat(month) / parseFloat(day));
    document.getElementById(id + 'perday').value = (parseFloat(month) / parseFloat(day)).toFixed(6);
    if (document.getElementsByName(id + 'perday')) {
        var ctrl = document.getElementsByName(id + 'perday');
        for (var i = 0; i < ctrl.length; i++) {
            if (document.getElementsByName(id + 'perday')[i]) {
                document.getElementsByName(id + 'perday')[i].value = document.getElementById(id + 'perday').value;
            }
        }
    }

    var data = [];
    data.push({
        name: 'August',
        data09_10: document.getElementById('aug9_10_perdayYear').value,
        data10_11: document.getElementById('aug10_11_perdayYear').value,
        data11_12: document.getElementById('aug11_12_perdayYear').value
    });
    data.push({
        name: 'September',
        data09_10: document.getElementById('sep9_10_perdayYear').value,
        data10_11: document.getElementById('sep10_11_perdayYear').value,
        data11_12: document.getElementById('sep11_12_perdayYear').value
    });
    data.push({
        name: 'October',
        data09_10: document.getElementById('oct9_10_perdayYear').value,
        data10_11: document.getElementById('oct10_11_perdayYear').value,
        data11_12: document.getElementById('oct11_12_perdayYear').value
    });

    data.push({
        name: 'November',
        data09_10: document.getElementById('nov9_10_perdayYear').value,
        data10_11: document.getElementById('nov10_11_perdayYear').value,
        data11_12: document.getElementById('nov11_12_perdayYear').value
    });

    data.push({
        name: 'December',
        data09_10: document.getElementById('dec9_10_perdayYear').value,
        data10_11: document.getElementById('dec10_11_perdayYear').value,
        data11_12: document.getElementById('dec11_12_perdayYear').value
    });

    data.push({
        name: 'January',
        data09_10: document.getElementById('jan9_10_perdayYear').value,
        data10_11: document.getElementById('jan10_11_perdayYear').value,
        data11_12: document.getElementById('jan11_12_perdayYear').value
    });

    data.push({
        name: 'February',
        data09_10: document.getElementById('feb9_10_perdayYear').value,
        data10_11: document.getElementById('feb10_11_perdayYear').value,
        data11_12: document.getElementById('feb11_12_perdayYear').value
    });

    data.push({
        name: 'March',
        data09_10: document.getElementById('march9_10_perdayYear').value,
        data10_11: document.getElementById('march10_11_perdayYear').value,
        data11_12: document.getElementById('march11_12_perdayYear').value
    });

    data.push({
        name: 'April',
        data09_10: document.getElementById('april9_10_perdayYear').value,
        data10_11: document.getElementById('april10_11_perdayYear').value,
        data11_12: document.getElementById('april11_12_perdayYear').value
    });

    data.push({
        name: 'May',
        data09_10: document.getElementById('may9_10_perdayYear').value,
        data10_11: document.getElementById('may10_11_perdayYear').value,
        data11_12: document.getElementById('may11_12_perdayYear').value
    });

    data.push({
        name: 'June',
        data09_10: document.getElementById('june9_10_perdayYear').value,
        data10_11: document.getElementById('june10_11_perdayYear').value,
        data11_12: document.getElementById('june11_12_perdayYear').value
    });

    data.push({
        name: 'July',
        data09_10: document.getElementById('july9_10_perdayYear').value,
        data10_11: document.getElementById('july10_11_perdayYear').value,
        data11_12: document.getElementById('july11_12_perdayYear').value
    });
    store1.loadData(data);

    var storeYear11_12Data = [];
    storeYear11_12Data.push({
        name: 'August',
        data11_12: document.getElementById('aug11_12_perdayYear11_12').value
    });
    storeYear11_12Data.push({
        name: 'September',
        data11_12: document.getElementById('sep11_12_perdayYear11_12').value
    });
    storeYear11_12Data.push({
        name: 'October',
        data11_12: document.getElementById('oct11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'November',
        data11_12: document.getElementById('nov11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'December',
        data11_12: document.getElementById('dec11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'January',
        data11_12: document.getElementById('jan11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'February',
        data11_12: document.getElementById('feb11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'March',
        data11_12: document.getElementById('march11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'April',
        data11_12: document.getElementById('april11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'May',
        data11_12: document.getElementById('may11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'June',
        data11_12: document.getElementById('june11_12_perdayYear11_12').value
    });

    storeYear11_12Data.push({
        name: 'July',
        data11_12: document.getElementById('july11_12_perdayYear11_12').value
    });
    storeYear11_12.loadData(storeYear11_12Data);
}

function fnCalculateBehavior(id) {
    var August = document.getElementById(id + 'August').value;
    var September = document.getElementById(id + 'September').value;
    var October = document.getElementById(id + 'October').value;
    var November = document.getElementById(id + 'November').value;
    var December = document.getElementById(id + 'December').value;
    var January = document.getElementById(id + 'January').value;
    var February = document.getElementById(id + 'February').value;
    var March = document.getElementById(id + 'March').value;
    var April = document.getElementById(id + 'April').value;
    var May = document.getElementById(id + 'May').value;
    var June = document.getElementById(id + 'June').value;
    var July = document.getElementById(id + 'July').value;
    if (August == '') {
        August = 0;
    }
    if (September == '') {
        September = 0;
    }
    if (October == '') {
        October = 0;
    }
    if (November == '') {
        November = 0;
    }
    if (December == '') { December = 0; }
    if (January == '') { January = 0; }
    if (February == '') { February = 0; }
    if (March == '') { March = 0; }
    if (April == '') { April = 0; }
    if (May == '') { May = 0; }
    if (June == '') { June = 0; }
    if (July == '') { July = 0; }
    var total = parseFloat(August) + parseFloat(September) + parseFloat(October) + parseFloat(November) + parseFloat(December) + parseFloat(January) + parseFloat(February) + parseFloat(March) + parseFloat(April) + parseFloat(May) + parseFloat(June) + parseFloat(July);
    document.getElementById(id + 'Total').value = parseFloat(total);
    document.getElementById(id + 'TotalChart').value = parseFloat(total);
    document.getElementById(id + 'MonthTotalTable1C').value = parseFloat(total);

    var data = [];
    data.push({
        name: 'Inappro. Lang',
        total: document.getElementById('InapproTotalChart').value
    });
    data.push({
        name: 'Aggression/Fight',
        total: document.getElementById('AggressionTotalChart').value
    });
    data.push({
        name: 'Disrespect',
        total: document.getElementById('DisrespectTotalChart').value
    });

    data.push({
        name: 'Lying',
        total: document.getElementById('LyingTotalChart').value
    });

    data.push({
        name: 'Harrass',
        total: document.getElementById('HarrassTotalChart').value
    });

    data.push({
        name: 'Disruption',
        total: document.getElementById('DisruptionTotalChart').value
    });

    data.push({
        name: 'Tardy',
        total: document.getElementById('TardyTotalChart').value
    });

    data.push({
        name: 'Skip',
        total: document.getElementById('SkipTotalChart').value
    });

    data.push({
        name: 'Prop Damage',
        total: document.getElementById('PropDamageTotalChart').value
    });

    data.push({
        name: 'Forgery/Theft',
        total: document.getElementById('ForgeryTheftTotalChart').value
    });

    data.push({
        name: 'Dress',
        total: document.getElementById('DressTotalChart').value
    });

    data.push({
        name: 'Tech',
        total: document.getElementById('TechTotalChart').value
    });

    data.push({
        name: 'Innapro. Affect.',
        total: document.getElementById('InnaproAffectTotalChart').value
    });
    data.push({
        name: 'Out Bounds',
        total: document.getElementById('OutBoundsTotalChart').value
    });
    data.push({
        name: 'Gang Display',
        total: document.getElementById('GangTotalChart').value
    });
    data.push({
        name: 'Tobacco',
        total: document.getElementById('TobaccoTotalChart').value
    });
    data.push({
        name: 'Alcohol',
        total: document.getElementById('AlcoholTotalChart').value
    });
    data.push({
        name: 'Drugs',
        total: document.getElementById('DrugsTotalChart').value
    });
    data.push({
        name: 'Combust',
        total: document.getElementById('combustTotalChart').value
    });
    data.push({
        name: 'Bomb',
        total: document.getElementById('BombTotalChart').value
    });
    data.push({
        name: 'Arson',
        total: document.getElementById('ArsonTotalChart').value
    });
    data.push({
        name: 'Weapons',
        total: document.getElementById('WeaponsTotalChart').value
    });
    data.push({
        name: 'Other',
        total: document.getElementById('OtherTotalChart').value
    });
    data.push({
        name: 'Unknown',
        total: document.getElementById('UnknownTotalChart').value
    });
    storeTotal.loadData(data);

}

function fnFillMotnValueInTableC(month) {
    var Inappro = document.getElementById('Inappro' + month).value;
    var Aggression = document.getElementById('Aggression' + month).value;
    var Disrespect = document.getElementById('Disrespect' + month).value;
    var Lying = document.getElementById('Lying' + month).value;
    var Harrass = document.getElementById('Harrass' + month).value;
    var Disruption = document.getElementById('Disruption' + month).value;
    var Tardy = document.getElementById('Tardy' + month).value;
    var Skip = document.getElementById('Skip' + month).value;
    var PropDamage = document.getElementById('PropDamage' + month).value;
    var ForgeryTheft = document.getElementById('ForgeryTheft' + month).value;
    var Dress = document.getElementById('Dress' + month).value;
    var Tech = document.getElementById('Tech' + month).value;
    var InnaproAffect = document.getElementById('InnaproAffect' + month).value;
    var OutBounds = document.getElementById('OutBounds' + month).value;
    var Gang = document.getElementById('Gang' + month).value;
    var Tobacco = document.getElementById('Tobacco' + month).value;
    var Alcohol = document.getElementById('Alcohol' + month).value;
    var Drugs = document.getElementById('Drugs' + month).value;
    var Combust = document.getElementById('combust' + month).value;
    var Bomb = document.getElementById('Bomb' + month).value;
    var Arson = document.getElementById('Arson' + month).value;
    var Weapons = document.getElementById('Weapons' + month).value;
    var Other = document.getElementById('Other' + month).value;
    var Unknown = document.getElementById('Unknown' + month).value;

    document.getElementById('InapproTotalInTable1B').value = Inappro;
    document.getElementById('AggressionTotalInTable1B').value = Aggression;
    document.getElementById('DisrespectTotalInTable1B').value = Disrespect;
    document.getElementById('LyingTotalInTable1B').value = Lying;
    document.getElementById('HarrassTotalInTable1B').value = Harrass;
    document.getElementById('DisruptionTotalInTable1B').value = Disruption;
    document.getElementById('TardyTotalInTable1B').value = Tardy;
    document.getElementById('SkipTotalInTable1B').value = Skip;
    document.getElementById('PropDamageTotalInTable1B').value = PropDamage;
    document.getElementById('ForgeryTheftTotalInTable1B').value = ForgeryTheft;
    document.getElementById('DressTotalInTable1B').value = Dress;
    document.getElementById('TechTotalInTable1B').value = Tech;
    document.getElementById('InnaproAffectTotalInTable1B').value = InnaproAffect;
    document.getElementById('OutBoundsTotalInTable1B').value = OutBounds;
    document.getElementById('GangTotalInTable1B').value = Gang;
    document.getElementById('TobaccoTotalInTable1B').value = Tobacco;
    document.getElementById('AlcoholTotalInTable1B').value = Alcohol;
    document.getElementById('DrugsTotalInTable1B').value = Drugs;
    document.getElementById('combustTotalInTable1B').value = Combust;
    document.getElementById('BombTotalInTable1B').value = Bomb;
    document.getElementById('ArsonTotalInTable1B').value = Arson;
    document.getElementById('WeaponsTotalInTable1B').value = Weapons;
    document.getElementById('OtherTotalInTable1B').value = Other;
    document.getElementById('UnknownTotalInTable1B').value = Unknown;

    document.getElementById('InapproMonthTable1C').value = Inappro;
    document.getElementById('AggressionMonthTable1C').value = Aggression;
    document.getElementById('DisrespectMonthTable1C').value = Disrespect;
    document.getElementById('LyingMonthTable1C').value = Lying;
    document.getElementById('HarrassMonthTable1C').value = Harrass;
    document.getElementById('DisruptionMonthTable1C').value = Disruption;
    document.getElementById('TardyMonthTable1C').value = Tardy;
    document.getElementById('SkipMonthTable1C').value = Skip;
    document.getElementById('PropDamageMonthTable1C').value = PropDamage;
    document.getElementById('ForgeryTheftMonthTable1C').value = ForgeryTheft;
    document.getElementById('DressMonthTable1C').value = Dress;
    document.getElementById('TechMonthTable1C').value = Tech;
    document.getElementById('InnaproAffectMonthTable1C').value = InnaproAffect;
    document.getElementById('OutBoundsMonthTable1C').value = OutBounds;
    document.getElementById('GangMonthTable1C').value = Gang;
    document.getElementById('TobaccoMonthTable1C').value = Tobacco;
    document.getElementById('AlcoholMonthTable1C').value = Alcohol;
    document.getElementById('DrugsMonthTable1C').value = Drugs;
    document.getElementById('combustMonthTable1C').value = Combust;
    document.getElementById('BombMonthTable1C').value = Bomb;
    document.getElementById('ArsonMonthTable1C').value = Arson;
    document.getElementById('WeaponsMonthTable1C').value = Weapons;
    document.getElementById('OtherMonthTable1C').value = Other;
    document.getElementById('UnknownMonthTable1C').value = Unknown;

    var data = [];
    data.push({
        name: 'Inappro. Lang',
        month: document.getElementById('InapproMonthTable1C').value,
        total: document.getElementById('InapproMonthTotalTable1C').value
    });
    data.push({
        name: 'Aggression/Fight',
        month: document.getElementById('AggressionMonthTable1C').value,
        total: document.getElementById('AggressionMonthTotalTable1C').value
    });
    data.push({
        name: 'Disrespect',
        month: document.getElementById('DisrespectMonthTable1C').value,
        total: document.getElementById('DisrespectMonthTotalTable1C').value
    });

    data.push({
        name: 'Lying',
        month: document.getElementById('LyingMonthTable1C').value,
        total: document.getElementById('LyingMonthTotalTable1C').value
    });

    data.push({
        name: 'Harrass',
        month: document.getElementById('HarrassMonthTable1C').value,
        total: document.getElementById('HarrassMonthTotalTable1C').value
    });

    data.push({
        name: 'Disruption',
        month: document.getElementById('DisruptionMonthTable1C').value,
        total: document.getElementById('DisruptionMonthTotalTable1C').value
    });

    data.push({
        name: 'Tardy',
        month: document.getElementById('TardyMonthTable1C').value,
        total: document.getElementById('TardyMonthTotalTable1C').value
    });

    data.push({
        name: 'Skip',
        month: document.getElementById('SkipMonthTable1C').value,
        total: document.getElementById('SkipMonthTotalTable1C').value
    });

    data.push({
        name: 'Prop Damage',
        month: document.getElementById('PropDamageMonthTable1C').value,
        total: document.getElementById('PropDamageMonthTotalTable1C').value
    });

    data.push({
        name: 'Forgery/Theft',
        month: document.getElementById('ForgeryTheftMonthTable1C').value,
        total: document.getElementById('ForgeryTheftMonthTotalTable1C').value
    });

    data.push({
        name: 'Dress',
        month: document.getElementById('DressMonthTable1C').value,
        total: document.getElementById('DressMonthTotalTable1C').value
    });

    data.push({
        name: 'Tech',
        month: document.getElementById('TechMonthTable1C').value,
        total: document.getElementById('TechMonthTotalTable1C').value
    });

    data.push({
        name: 'Innapro. Affect.',
        month: document.getElementById('InnaproAffectMonthTable1C').value,
        total: document.getElementById('InnaproAffectMonthTotalTable1C').value
    });
    data.push({
        name: 'Out Bounds',
        month: document.getElementById('OutBoundsMonthTable1C').value,
        total: document.getElementById('OutBoundsMonthTotalTable1C').value
    });
    data.push({
        name: 'Gang Display',
        month: document.getElementById('GangMonthTable1C').value,
        total: document.getElementById('GangMonthTotalTable1C').value
    });
    data.push({
        name: 'Tobacco',
        month: document.getElementById('TobaccoMonthTable1C').value,
        total: document.getElementById('TobaccoMonthTotalTable1C').value
    });
    data.push({
        name: 'Alcohol',
        month: document.getElementById('AlcoholMonthTable1C').value,
        total: document.getElementById('AlcoholMonthTotalTable1C').value
    });
    data.push({
        name: 'Drugs',
        month: document.getElementById('DrugsMonthTable1C').value,
        total: document.getElementById('DrugsMonthTotalTable1C').value
    });
    data.push({
        name: 'Combust',
        month: document.getElementById('combustMonthTable1C').value,
        total: document.getElementById('combustMonthTotalTable1C').value
    });
    data.push({
        name: 'Bomb',
        month: document.getElementById('BombMonthTable1C').value,
        total: document.getElementById('BombMonthTotalTable1C').value
    });
    data.push({
        name: 'Arson',
        month: document.getElementById('ArsonMonthTable1C').value,
        total: document.getElementById('ArsonMonthTotalTable1C').value
    });
    data.push({
        name: 'Weapons',
        month: document.getElementById('WeaponsMonthTable1C').value,
        total: document.getElementById('WeaponsMonthTotalTable1C').value
    });
    data.push({
        name: 'Other',
        month: document.getElementById('OtherMonthTable1C').value,
        total: document.getElementById('OtherMonthTotalTable1C').value
    });
    data.push({
        name: 'Unknown',
        month: document.getElementById('UnknownMonthTable1C').value,
        total: document.getElementById('UnknownMonthTotalTable1C').value
    });

    storeMonthTotalTable1C.loadData(data);


    var dataInTable1B = [];

    dataInTable1B.push({
        name: 'Inappro. Lang',
        total: document.getElementById('InapproTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Aggression/Fight',
        total: document.getElementById('AggressionTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Disrespect',
        total: document.getElementById('DisrespectTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Lying',
        total: document.getElementById('LyingTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Harrass',
        total: document.getElementById('HarrassTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Disruption',
        total: document.getElementById('DisruptionTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Tardy',
        total: document.getElementById('TardyTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Skip',
        total: document.getElementById('SkipTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Prop Damage',
        total: document.getElementById('PropDamageTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Forgery/Theft',
        total: document.getElementById('ForgeryTheftTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Dress',
        total: document.getElementById('DressTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Tech',
        total: document.getElementById('TechTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Innapro. Affect.',
        total: document.getElementById('InnaproAffectTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Out Bounds',
        total: document.getElementById('OutBoundsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Gang Display',
        total: document.getElementById('GangTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Tobacco',
        total: document.getElementById('TobaccoTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Alcohol',
        total: document.getElementById('AlcoholTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Drugs',
        total: document.getElementById('DrugsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Combust',
        total: document.getElementById('combustTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Bomb',
        total: document.getElementById('BombTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Arson',
        total: document.getElementById('ArsonTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Weapons',
        total: document.getElementById('WeaponsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Other',
        total: document.getElementById('OtherTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Unknown',
        total: document.getElementById('UnknownTotalInTable1B').value
    });
    storeInTable1B.loadData(dataInTable1B);
}


function fnCalculateLocation(id) {
    var August = document.getElementById(id + 'August').value;
    var September = document.getElementById(id + 'September').value;
    var October = document.getElementById(id + 'October').value;
    var November = document.getElementById(id + 'November').value;
    var December = document.getElementById(id + 'December').value;
    var January = document.getElementById(id + 'January').value;
    var February = document.getElementById(id + 'February').value;
    var March = document.getElementById(id + 'March').value;
    var April = document.getElementById(id + 'April').value;
    var May = document.getElementById(id + 'May').value;
    var June = document.getElementById(id + 'June').value;
    var July = document.getElementById(id + 'July').value;
    if (August == '') {
        August = 0;
    }
    if (September == '') {
        September = 0;
    }
    if (October == '') {
        October = 0;
    }
    if (November == '') {
        November = 0;
    }
    if (December == '') { December = 0; }
    if (January == '') { January = 0; }
    if (February == '') { February = 0; }
    if (March == '') { March = 0; }
    if (April == '') { April = 0; }
    if (May == '') { May = 0; }
    if (June == '') { June = 0; }
    if (July == '') { July = 0; }
    var total = parseFloat(August) + parseFloat(September) + parseFloat(October) + parseFloat(November) + parseFloat(December) + parseFloat(January) + parseFloat(February) + parseFloat(March) + parseFloat(April) + parseFloat(May) + parseFloat(June) + parseFloat(July);
    document.getElementById(id + 'Total').value = parseFloat(total);
    document.getElementById(id + 'TotalChart').value = parseFloat(total);
    //document.getElementById(id + 'MonthTotalTable1C').value = parseFloat(total);

    var data = [];

    data.push({
        name: 'Classroom',
        total: document.getElementById('ClassroomTotalChart').value
    });
    data.push({
        name: 'Playground',
        total: document.getElementById('PlaygroundTotalChart').value
    });
    data.push({
        name: 'Commons',
        total: document.getElementById('CommonsTotalChart').value
    });

    data.push({
        name: 'Hall/Breezeway',
        total: document.getElementById('HallBreezewayTotalChart').value
    });

    data.push({
        name: 'Cafeteria',
        total: document.getElementById('CafeteriaTotalChart').value
    });

    data.push({
        name: 'Bath/Restroom',
        total: document.getElementById('BathRestroomTotalChart').value
    });

    data.push({
        name: 'Gym',
        total: document.getElementById('GymTotalChart').value
    });

    data.push({
        name: 'Library',
        total: document.getElementById('LibraryTotalChart').value
    });

    data.push({
        name: 'Bus Loading',
        total: document.getElementById('BusLoadingTotalChart').value
    });

    data.push({
        name: 'Parking Lot',
        total: document.getElementById('ParkingLotTotalChart').value
    });

    data.push({
        name: 'Bus',
        total: document.getElementById('BusTotalChart').value
    });

    data.push({
        name: 'Special Event',
        total: document.getElementById('SpecialEventTotalChart').value
    });

    data.push({
        name: 'Off-Campus',
        total: document.getElementById('OffCampusTotalChart').value
    });
    data.push({
        name: 'Stadium',
        total: document.getElementById('StadiumTotalChart').value
    });
    data.push({
        name: 'Office',
        total: document.getElementById('OfficeTotalChart').value
    });
    data.push({
        name: 'Locker Room',
        total: document.getElementById('LockerRoomTotalChart').value
    });
    data.push({
        name: 'Other Location',
        total: document.getElementById('OtherLocationTotalChart').value
    });
    data.push({
        name: 'Unknown Location',
        total: document.getElementById('UnknownLocationTotalChart').value
    });

    storeTotal.loadData(data);


    //
    var dataInTable2B = [];

    dataInTable2B.push({
        name: 'Classroom',
        total: document.getElementById('ClassroomTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Playground',
        total: document.getElementById('PlaygroundTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Commons',
        total: document.getElementById('CommonsTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Hall/Breezeway',
        total: document.getElementById('HallBreezewayTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Cafeteria',
        total: document.getElementById('CafeteriaTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Bath/Restroom',
        total: document.getElementById('BathRestroomTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Gym',
        total: document.getElementById('GymTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Library',
        total: document.getElementById('LibraryTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Bus Loading',
        total: document.getElementById('BusLoadingTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Parking Lot',
        total: document.getElementById('ParkingLotTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Bus',
        total: document.getElementById('BusTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Special Event',
        total: document.getElementById('SpecialEventTotalInTable2B').value
    });

    dataInTable2B.push({
        name: 'Off-Campus',
        total: document.getElementById('OffCampusTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Stadium',
        total: document.getElementById('StadiumTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Office',
        total: document.getElementById('OfficeTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Locker Room',
        total: document.getElementById('LockerRoomTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Other Location',
        total: document.getElementById('OtherLocationTotalInTable2B').value
    });
    dataInTable2B.push({
        name: 'Unknown Location',
        total: document.getElementById('UnknownLocationTotalInTable2B').value
    });

    storeInTable2B.loadData(dataInTable2B);

}
function fnFillMotnValueInTable2CInLocationsData(month) {
    var Inappro = document.getElementById('Inappro' + month).value;
    var Aggression = document.getElementById('Aggression' + month).value;
    var Disrespect = document.getElementById('Disrespect' + month).value;
    var Lying = document.getElementById('Lying' + month).value;
    var Harrass = document.getElementById('Harrass' + month).value;
    var Disruption = document.getElementById('Disruption' + month).value;
    var Tardy = document.getElementById('Tardy' + month).value;
    var Skip = document.getElementById('Skip' + month).value;
    var PropDamage = document.getElementById('PropDamage' + month).value;
    var ForgeryTheft = document.getElementById('ForgeryTheft' + month).value;
    var Dress = document.getElementById('Dress' + month).value;
    var Tech = document.getElementById('Tech' + month).value;
    var InnaproAffect = document.getElementById('InnaproAffect' + month).value;
    var OutBounds = document.getElementById('OutBounds' + month).value;
    var Gang = document.getElementById('Gang' + month).value;
    var Tobacco = document.getElementById('Tobacco' + month).value;
    var Alcohol = document.getElementById('Alcohol' + month).value;
    var Drugs = document.getElementById('Drugs' + month).value;
    var Combust = document.getElementById('combust' + month).value;
    var Bomb = document.getElementById('Bomb' + month).value;
    var Arson = document.getElementById('Arson' + month).value;
    var Weapons = document.getElementById('Weapons' + month).value;
    var Other = document.getElementById('Other' + month).value;
    var Unknown = document.getElementById('Unknown' + month).value;

    document.getElementById('InapproTotalInTable1B').value = Inappro;
    document.getElementById('AggressionTotalInTable1B').value = Aggression;
    document.getElementById('DisrespectTotalInTable1B').value = Disrespect;
    document.getElementById('LyingTotalInTable1B').value = Lying;
    document.getElementById('HarrassTotalInTable1B').value = Harrass;
    document.getElementById('DisruptionTotalInTable1B').value = Disruption;
    document.getElementById('TardyTotalInTable1B').value = Tardy;
    document.getElementById('SkipTotalInTable1B').value = Skip;
    document.getElementById('PropDamageTotalInTable1B').value = PropDamage;
    document.getElementById('ForgeryTheftTotalInTable1B').value = ForgeryTheft;
    document.getElementById('DressTotalInTable1B').value = Dress;
    document.getElementById('TechTotalInTable1B').value = Tech;
    document.getElementById('InnaproAffectTotalInTable1B').value = InnaproAffect;
    document.getElementById('OutBoundsTotalInTable1B').value = OutBounds;
    document.getElementById('GangTotalInTable1B').value = Gang;
    document.getElementById('TobaccoTotalInTable1B').value = Tobacco;
    document.getElementById('AlcoholTotalInTable1B').value = Alcohol;
    document.getElementById('DrugsTotalInTable1B').value = Drugs;
    document.getElementById('combustTotalInTable1B').value = Combust;
    document.getElementById('BombTotalInTable1B').value = Bomb;
    document.getElementById('ArsonTotalInTable1B').value = Arson;
    document.getElementById('WeaponsTotalInTable1B').value = Weapons;
    document.getElementById('OtherTotalInTable1B').value = Other;
    document.getElementById('UnknownTotalInTable1B').value = Unknown;

    document.getElementById('InapproMonthTable1C').value = Inappro;
    document.getElementById('AggressionMonthTable1C').value = Aggression;
    document.getElementById('DisrespectMonthTable1C').value = Disrespect;
    document.getElementById('LyingMonthTable1C').value = Lying;
    document.getElementById('HarrassMonthTable1C').value = Harrass;
    document.getElementById('DisruptionMonthTable1C').value = Disruption;
    document.getElementById('TardyMonthTable1C').value = Tardy;
    document.getElementById('SkipMonthTable1C').value = Skip;
    document.getElementById('PropDamageMonthTable1C').value = PropDamage;
    document.getElementById('ForgeryTheftMonthTable1C').value = ForgeryTheft;
    document.getElementById('DressMonthTable1C').value = Dress;
    document.getElementById('TechMonthTable1C').value = Tech;
    document.getElementById('InnaproAffectMonthTable1C').value = InnaproAffect;
    document.getElementById('OutBoundsMonthTable1C').value = OutBounds;
    document.getElementById('GangMonthTable1C').value = Gang;
    document.getElementById('TobaccoMonthTable1C').value = Tobacco;
    document.getElementById('AlcoholMonthTable1C').value = Alcohol;
    document.getElementById('DrugsMonthTable1C').value = Drugs;
    document.getElementById('combustMonthTable1C').value = Combust;
    document.getElementById('BombMonthTable1C').value = Bomb;
    document.getElementById('ArsonMonthTable1C').value = Arson;
    document.getElementById('WeaponsMonthTable1C').value = Weapons;
    document.getElementById('OtherMonthTable1C').value = Other;
    document.getElementById('UnknownMonthTable1C').value = Unknown;

    var data = [];
    data.push({
        name: 'Inappro. Lang',
        month: document.getElementById('InapproMonthTable1C').value,
        total: document.getElementById('InapproMonthTotalTable1C').value
    });
    data.push({
        name: 'Aggression/Fight',
        month: document.getElementById('AggressionMonthTable1C').value,
        total: document.getElementById('AggressionMonthTotalTable1C').value
    });
    data.push({
        name: 'Disrespect',
        month: document.getElementById('DisrespectMonthTable1C').value,
        total: document.getElementById('DisrespectMonthTotalTable1C').value
    });

    data.push({
        name: 'Lying',
        month: document.getElementById('LyingMonthTable1C').value,
        total: document.getElementById('LyingMonthTotalTable1C').value
    });

    data.push({
        name: 'Harrass',
        month: document.getElementById('HarrassMonthTable1C').value,
        total: document.getElementById('HarrassMonthTotalTable1C').value
    });

    data.push({
        name: 'Disruption',
        month: document.getElementById('DisruptionMonthTable1C').value,
        total: document.getElementById('DisruptionMonthTotalTable1C').value
    });

    data.push({
        name: 'Tardy',
        month: document.getElementById('TardyMonthTable1C').value,
        total: document.getElementById('TardyMonthTotalTable1C').value
    });

    data.push({
        name: 'Skip',
        month: document.getElementById('SkipMonthTable1C').value,
        total: document.getElementById('SkipMonthTotalTable1C').value
    });

    data.push({
        name: 'Prop Damage',
        month: document.getElementById('PropDamageMonthTable1C').value,
        total: document.getElementById('PropDamageMonthTotalTable1C').value
    });

    data.push({
        name: 'Forgery/Theft',
        month: document.getElementById('ForgeryTheftMonthTable1C').value,
        total: document.getElementById('ForgeryTheftMonthTotalTable1C').value
    });

    data.push({
        name: 'Dress',
        month: document.getElementById('DressMonthTable1C').value,
        total: document.getElementById('DressMonthTotalTable1C').value
    });

    data.push({
        name: 'Tech',
        month: document.getElementById('TechMonthTable1C').value,
        total: document.getElementById('TechMonthTotalTable1C').value
    });

    data.push({
        name: 'Innapro. Affect.',
        month: document.getElementById('InnaproAffectMonthTable1C').value,
        total: document.getElementById('InnaproAffectMonthTotalTable1C').value
    });
    data.push({
        name: 'Out Bounds',
        month: document.getElementById('OutBoundsMonthTable1C').value,
        total: document.getElementById('OutBoundsMonthTotalTable1C').value
    });
    data.push({
        name: 'Gang Display',
        month: document.getElementById('GangMonthTable1C').value,
        total: document.getElementById('GangMonthTotalTable1C').value
    });
    data.push({
        name: 'Tobacco',
        month: document.getElementById('TobaccoMonthTable1C').value,
        total: document.getElementById('TobaccoMonthTotalTable1C').value
    });
    data.push({
        name: 'Alcohol',
        month: document.getElementById('AlcoholMonthTable1C').value,
        total: document.getElementById('AlcoholMonthTotalTable1C').value
    });
    data.push({
        name: 'Drugs',
        month: document.getElementById('DrugsMonthTable1C').value,
        total: document.getElementById('DrugsMonthTotalTable1C').value
    });
    data.push({
        name: 'Combust',
        month: document.getElementById('combustMonthTable1C').value,
        total: document.getElementById('combustMonthTotalTable1C').value
    });
    data.push({
        name: 'Bomb',
        month: document.getElementById('BombMonthTable1C').value,
        total: document.getElementById('BombMonthTotalTable1C').value
    });
    data.push({
        name: 'Arson',
        month: document.getElementById('ArsonMonthTable1C').value,
        total: document.getElementById('ArsonMonthTotalTable1C').value
    });
    data.push({
        name: 'Weapons',
        month: document.getElementById('WeaponsMonthTable1C').value,
        total: document.getElementById('WeaponsMonthTotalTable1C').value
    });
    data.push({
        name: 'Other',
        month: document.getElementById('OtherMonthTable1C').value,
        total: document.getElementById('OtherMonthTotalTable1C').value
    });
    data.push({
        name: 'Unknown',
        month: document.getElementById('UnknownMonthTable1C').value,
        total: document.getElementById('UnknownMonthTotalTable1C').value
    });

    storeMonthTotalTable1C.loadData(data);


    var dataInTable1B = [];

    dataInTable1B.push({
        name: 'Inappro. Lang',
        total: document.getElementById('InapproTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Aggression/Fight',
        total: document.getElementById('AggressionTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Disrespect',
        total: document.getElementById('DisrespectTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Lying',
        total: document.getElementById('LyingTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Harrass',
        total: document.getElementById('HarrassTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Disruption',
        total: document.getElementById('DisruptionTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Tardy',
        total: document.getElementById('TardyTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Skip',
        total: document.getElementById('SkipTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Prop Damage',
        total: document.getElementById('PropDamageTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Forgery/Theft',
        total: document.getElementById('ForgeryTheftTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Dress',
        total: document.getElementById('DressTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Tech',
        total: document.getElementById('TechTotalInTable1B').value
    });

    dataInTable1B.push({
        name: 'Innapro. Affect.',
        total: document.getElementById('InnaproAffectTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Out Bounds',
        total: document.getElementById('OutBoundsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Gang Display',
        total: document.getElementById('GangTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Tobacco',
        total: document.getElementById('TobaccoTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Alcohol',
        total: document.getElementById('AlcoholTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Drugs',
        total: document.getElementById('DrugsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Combust',
        total: document.getElementById('combustTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Bomb',
        total: document.getElementById('BombTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Arson',
        total: document.getElementById('ArsonTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Weapons',
        total: document.getElementById('WeaponsTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Other',
        total: document.getElementById('OtherTotalInTable1B').value
    });
    dataInTable1B.push({
        name: 'Unknown',
        total: document.getElementById('UnknownTotalInTable1B').value
    });
    storeInTable1B.loadData(dataInTable1B);
}
