﻿/*
*
*ysw edit
*
*/
var currentWattage, optiledWattage, currentLifetime, optiledLifetime, currentLaborCost, optiedLaborCost, currentFixtureCost, optiledFixtureCost, currentLampcost, optiledLampcost, quantity, electricalCost, averageDailyUse, dayUseYear, TotalAnnualSaving;
//initial cost
var currentInitialCost, optiledInitialCost, savingInitialCost;
// Ballast Loss
var currentBallastLoss, optiledBallastLoss;
//Annual Energy Cost
var currentAnnualEnergyCost, optiledAnnualEnergyCost, savingAnnualEnergyCost;
//Annual Lamp Cost
var currentAnnualLampCost, optiledAnnualLampCost, savingAnnualLampCost;
//Annual Labor Cost
var currentAnnualLaborCost, optiledAnnualLaborCost, savingAnnualLaborCost;
//Total Annual Cost
var currentTotalAnnualCost, optiledTotalAnnualCost, savingTotalAnnualCost;
//Total Power Per Year
var currentTotalPowerPerYear, optiledTotalPowerPerYear, AnnualHoursOfOperation;
// Material Cost
var currentMaterialCost, optiledMaterialCost;
//Labor cost to replace a lamp
var currentLaborCostToReplaceALamp;
// Electricity Bill yearly ( include current and optiled)
var currentElectricityBillYearly, optiledElectricitybillyearly;
// Electricity Bill
var currentElectricityBill, optiledElectricityBill;
var calc, oalc;
var totalYears,BillSaved;
//Data source
var ds, store;
var grid, grid1;
var data, dataSource;
var _ExportExcelMsg

function _inputValue() {    
    currentWattage = parseFloat(Ext.get("ipt_wattage").getValue());
    optiledWattage = parseFloat(document.getElementById("ipt_optiledWattage").value);

    quantity = parseInt(Ext.get("ipt_quantity").getValue());

    currentLifetime = parseFloat(Ext.get("ipt_lifetime").getValue());
    optiledLifetime = parseFloat(Ext.get("ipt_optiledLifetime").getValue());

    dayUseYear = Ext.get("ipt_daysUseYear").getValue();
    totalYears = parseFloat(dayUseYear / 365);

    currentBallastLoss = parseFloat(Ext.get("ipt_currentBallastLoss").getValue());
    optiledBallastLoss = parseFloat(Ext.get("ipt_optiledBallastLoss").getValue());

    currentFixtureCost = parseFloat(Ext.get("ipt_fixtureCost").getValue());
    optiledFixtureCost = parseFloat(Ext.get("ipt_optiledFixtureCost").getValue());
    currentLampcost = parseFloat(Ext.get("ipt_lampCost").getValue());
    optiledLampcost = parseFloat(Ext.get("ipt_optiledLampCost").getValue());

    electricalCost = parseFloat(Ext.get("ipt_electricalCost").getValue());
    averageDailyUse = parseFloat(Ext.get("ipt_averageDailyUse").getValue());

    currentLaborCostToReplaceALamp = parseFloat(Ext.get("ipt_currentLaborCostToReplaceALamp").getValue());

    AnnualHoursOfOperation = dayUseYear * averageDailyUse;

    // total power per year ( include current and optiled )
    currentTotalPowerPerYear = (((currentWattage * quantity) + currentBallastLoss) / 1000) * AnnualHoursOfOperation;
    optiledTotalPowerPerYear = (((optiledWattage * quantity) + optiledBallastLoss) / 1000) * AnnualHoursOfOperation;
    //Electricity Bill Yearly
    currentElectricityBillYearly = currentTotalPowerPerYear * electricalCost; //电费
    optiledElectricitybillyearly = optiledTotalPowerPerYear * electricalCost;
    //Electricity Bill
    
   
    
    currentElectricityBill = currentElectricityBillYearly / quantity;
    optiledElectricityBill = optiledElectricitybillyearly / quantity;
    
    //Bill Saved
    BillSaved = currentElectricityBillYearly - optiledElectricitybillyearly;

    // Annual lamp changes
    calc = AnnualHoursOfOperation / currentLifetime; 
    oalc = AnnualHoursOfOperation / optiledLifetime;

    //modify 20100608
    // currentMaterialCost = (AnnualHoursOfOperation / currentLifetime) * (currentLampcost + currentLaborCostToReplaceALamp);
    currentMaterialCost = (AnnualHoursOfOperation / currentLifetime) * currentLampcost;
    //optiledMaterialCost = (AnnualHoursOfOperation / optiledLifetime) * (optiledLampcost + optiledFixtureCost);
    optiledMaterialCost = (AnnualHoursOfOperation / optiledLifetime) * (optiledLampcost + optiledFixtureCost);

   
   // currentLaborCost = parseFloat(_subString(calc)) * currentLaborCostToReplaceALamp * quantity;
     currentLaborCost = parseFloat(_subString(calc)) * currentLaborCostToReplaceALamp;
    optiledLaborCost = 0; //parseFloat(Ext.get("ipt_optiledAnnualLampChanges").getValue()) * parseFloat(Ext.get("ipt_optiledLaborCostToReplaceALamp").getValue()) * quantity;
}

function getTotalSaving() {

    _inputValue();
    document.getElementById("ipt_billsaved").value = _subString(BillSaved);
    document.getElementById("ipt_currentInitialCostTotal").value = currentFixtureCost + currentLampcost;
    document.getElementById("ipt_optiledInitialCostTotal").value = optiledFixtureCost + optiledLampcost;
    document.getElementById("ipt_currentAnnualLampChanges").value = _subString(calc);
    document.getElementById("ipt_currentMaterialCost").value = _subString(currentMaterialCost);
    
    var backYears = parseInt(totalYears);
    var backMonths = parseInt((dayUseYear - (backYears * 365)) / 30);
    var backDays = dayUseYear - (backYears * 365) - (backMonths * 30);
    
    var totalQuantity = quantity * totalYears;
    var totalCurrentWattage = currentWattage * totalYears;
    var totalOptiledWattage = optiledWattage * totalYears;

    document.getElementById("ipt_currentAnnualHoursOfOperation").value = AnnualHoursOfOperation;
    document.getElementById("ipt_optiledAnnualHoursOfOperation").value = AnnualHoursOfOperation;    
   
   // document.getElementById("ipt_laborcost").value = _subString(parseFloat(_subString(calc)) * currentLaborCostToReplaceALamp * quantity);
    document.getElementById("ipt_laborcost").value = _subString(parseFloat(_subString(calc)) * currentLaborCostToReplaceALamp);
    document.getElementById("ipt_optiledLaborcost").value = _subString(optiledLaborCost);   
   
    document.getElementById("ipt_currentTotalPowerPerYear").value =_subString( currentTotalPowerPerYear);
    document.getElementById("ipt_optiledTotalPowerPerYear").value =_subString( optiledTotalPowerPerYear);

    var totalYearsCurrentTotalPowerPerYear = currentTotalPowerPerYear * totalYears;
    var totalYearsOptiledTotalPowerPerYear = optiledTotalPowerPerYear * totalYears;   
    
    document.getElementById("ipt_currentElectricityBillYearly").value = _subString(currentElectricityBillYearly);
    document.getElementById("ipt_optiledElectricityBillYearly").value = _subString(optiledElectricitybillyearly);
    

    var totalYearsCurrentElectricityBillYearly = currentElectricityBillYearly * totalYears;
    var totalYearsOptiledElectricityBillYearly = optiledElectricitybillyearly * totalYears;
    
    var ctl = currentMaterialCost + currentLaborCost + currentElectricityBill, otl = parseFloat(Ext.get("ipt_optiledMaterialCost").getValue()) + optiledLaborCost + optiledElectricityBill;
    document.getElementById("ipt_currentTotalAll").value = _subString(ctl);
    document.getElementById("ipt_optiledTotalAll").value = _subString(otl); 

    // Annual lamp changes
    //var currentAnnualLampChanges, optiledAnnualLampChanges;
//    var clt=AnnualHoursOfOperation / currentLifetime;
//    var olt=AnnualHoursOfOperation / optiledLifetime;
//    currentAnnualLampChanges = clt;
//    optiledAnnualLampChanges = olt;

    // Annual Fixture changes
    var currentAnnualFixtureChanges = 0.20, optiledAnnualFixtureChanges = 0.00;    
    
    document.getElementById("ipt_currentElectricityBill").value = _subString(currentElectricityBill);
   
    document.getElementById("ipt_optiledElectricityBill").value = _subString(optiledElectricityBill);

    var totalYearsCurrentElectricityBill = currentElectricityBill * totalYears;
    var totalYearsOptiledElectricityBill = optiledElectricityBill * totalYears;   
    
    //document.getElementById("ipt_optiledMaterialCost").value = optiledMaterialCost;
    
    var totalYearsCurrentMaterialCost = currentMaterialCost * totalYears;
    var totalYearsOptiledMaterialCost = optiledMaterialCost * totalYears;
    

    // Total
    var currentTotal, optiledTotal;
    currentTotal = parseFloat(currentLaborCost) + parseFloat(currentElectricityBill) + parseFloat(currentMaterialCost);
    optiledTotal = optiledLaborCost + optiledElectricityBill + optiledMaterialCost;

    // total Annual Operation Costs
    var currentTotalAnnualOperationCosts, optiledTotalAnnualOperationCosts;
    currentTotalAnnualOperationCosts = currentTotal * quantity;
    optiledTotalAnnualOperationCosts = optiledTotal * quantity;

    var totalYearsCurrentTotalAnnualOperationCosts = currentTotalAnnualOperationCosts * totalYears;
    var totalYearsOptiledTotalAnnualOperationCosts = optiledTotalAnnualOperationCosts * totalYears;

    // Total Annual Saving
    TotalAnnualSaving = currentTotalAnnualOperationCosts - optiledTotalAnnualOperationCosts;

    var totalYearsTotalAnnualSaving = _subString(TotalAnnualSaving);

    // Payback Year
    var PaybackYear = ((optiledLampcost + optiledFixtureCost) - (currentLampcost + currentFixtureCost)) / TotalAnnualSaving;


    // Time Until Payback (Years, Months, Days)
    var TimeUntilPayback = PaybackYear * 12;

    // CO2 Emission
    var currentCO2Emission, optiledCO2Emission;
    currentCO2Emission = currentTotalPowerPerYear * 0.69;
    optiledCO2Emission = optiledTotalPowerPerYear * 0.69;
    var savingCO=currentCO2Emission - optiledCO2Emission;
    var pointCO = ((currentCO2Emission - optiledCO2Emission) / currentCO2Emission) * 100;
    document.getElementById("ipt_currentCOEmission").value = _subString(currentCO2Emission);
    document.getElementById("ipt_optiledCOEmission").value = _subString(optiledCO2Emission);
    document.getElementById("ipt_savingCOEmission").value = _subString(savingCO);
    document.getElementById("ipt_savingEmissionPoint").value = _subString(pointCO)+"%";

    // Reduction in CO2 Emission
    var ReductionInCO2Emission = currentCO2Emission - optiledCO2Emission;
    //initial cost
    currentInitialCost = (currentFixtureCost + currentLampcost) * totalYears;
    optiledInitialCost = (optiledFixtureCost + optiledLampcost) * totalYears;
    savingInitialCost = optiledInitialCost - currentInitialCost;

    //Annual Energy Cost
    //var currentAnnualEnergyCost, optiledAnnualEnergyCost, savingAnnualEnergyCost;
    currentAnnualEnergyCost = totalYearsCurrentElectricityBill * totalQuantity;
    optiledAnnualEnergyCost = totalYearsOptiledElectricityBill * totalQuantity;
    savingAnnualEnergyCost = currentAnnualEnergyCost - optiledAnnualEnergyCost;

    //Annual Lamp Cost
    //var currentAnnualLampCost, optiledAnnualLampCost, savingAnnualLampCost;
    currentAnnualLampCost = currentMaterialCost * quantity * totalYears;
    optiledAnnualLampCost = optiledMaterialCost * quantity * totalYears;
    savingAnnualLampCost = optiledAnnualLampCost - currentAnnualLampCost;

    //Annual Labor Cost
    //var currentAnnualLaborCost, optiledAnnualLaborCost, savingAnnualLaborCost;
    currentAnnualLaborCost = currentLaborCost * quantity;
    optiledAnnualLaborCost = optiledLaborCost * quantity;
    savingAnnualLaborCost = optiledAnnualLaborCost - currentAnnualLaborCost;

    //Total Annual Cost
    //var currentTotalAnnualCost, optiledTotalAnnualCost, savingTotalAnnualCost;
    currentTotalAnnualCost = currentInitialCost + currentAnnualEnergyCost + currentAnnualLampCost + currentAnnualLaborCost;
    optiledTotalAnnualCost = optiledInitialCost + optiledAnnualEnergyCost + optiledAnnualLampCost + optiledAnnualLaborCost;
    savingTotalAnnualCost = optiledTotalAnnualCost - currentTotalAnnualCost;

    //Saving by year
    var currenini, currenttal, optiledini, optiledtal;
    currenini = "currentini="+currentInitialCost;//.toString().substring(0, currentInitialCost.toString().indexOf(".") - 1);
    optiledini = "optiledini="+optiledInitialCost;//.toString().substring(0, optiledInitialCost.toString().indexOf(".") - 1);
    currenttal = "currenttal="+currentTotalAnnualCost;//.toString().substring(0, currentTotalAnnualCost.toString().indexOf(".") - 1);
    optiledtal = "optiledtal=" + optiledTotalAnnualCost; //.toString().substring(0, optiledTotalAnnualCost.toString().indexOf(".") - 1);
    
    setValueNaN();
//    document.cookie = currenini;
//    document.cookie = optiledini;
//    document.cookie = currenttal;
//    document.cookie = optiledtal;

    //document.getElementById("ctl00_ContentPlaceHolder_Middle_Hidden1").value = document.cookie;
}

//function details() {
//    var cm = new Ext.grid.ColumnModel([
//                { header: 'Basic Lighting Costs', dataIndex: 'basiclightingcosts', sortable: true, width: 200 },
//                { header: 'Current Solution', dataIndex: 'currentsolution', sortable: false, width: 150 },
//                { header: 'CREE LED Light', dataIndex: 'creeledlight', sortable: false, width: 150 },
//                { header: 'Savings', dataIndex: 'savings', sortable: false, width: 150 }
//                ]);
//    data = [
//                ['Initial Cost Differential', '$ ' + currentInitialCost, '$ ' + optiledInitialCost, '$ ' + savingInitialCost],
//                ['Annual Eneragy', '$ ' + currentAnnualEnergyCost, '$ ' + optiledAnnualEnergyCost, '$ ' + savingAnnualEnergyCost],
//                ['Annual Lamping Costs', '$ ' + currentAnnualLampCost, '$ ' + optiledAnnualLampCost, '$ ' + savingAnnualLampCost],
//                ['Annual Labor Costs', '$ ' + currentAnnualLaborCost, '$ ' + optiledAnnualLaborCost, '$ ' + savingAnnualLaborCost],
//                ['Total Annual Cost', '$ ' + currentTotalAnnualCost, '$ ' + optiledTotalAnnualCost, '$ ' + savingTotalAnnualCost]
//                ];
//    ds = new Ext.data.Store({
//        proxy: new Ext.data.MemoryProxy(data),
//        reader: new Ext.data.ArrayReader({}, [
//                { name: 'basiclightingcosts' },
//                { name: 'currentsolution' },
//                { name: 'creeledlight' },
//                { name: 'savings' }
//                ])
//    });
//    ds.load();
//    grid = new Ext.grid.GridPanel({
//        title: "Additional Analysis",
//        ds: ds,
//        cm: cm,
//        height: 160,
//        width: 654
//    });
//    grid.render('grid');
//}

//function savingByYear() {
//    
//    var colModel = new Ext.grid.ColumnModel([
//	{ header: "Years", dataIndex: 'years', width: 110, sortable: false },
//	{ header: "Current Lamp", dataIndex: 'currentlamp', width: 180, sortable: false },
//	{ header: "OPTILED LED Lighting", dataIndex: 'optiledledlighting', width: 180, sortable: false },
//	{ header: "Savings", dataIndex: 'savings', width: 250, sortable: false }
//    ]);   
//	
////	var a=currentInitialCost + currentTotalAnnualCost;
////	var b=optiledInitialCost + optiledTotalAnnualCost;
////	var c = a - b;
////	var dataArray = new Array(1, a, b, c);
////	
////	for (var i = 1; i < totalYears; i++) {

////	    dataArray = new Array(i, a, b, c);
////        
////    }

//    dataSource = [
//	['1', '$ ' + (currentInitialCost + currentTotalAnnualCost), '$ ' + (optiledInitialCost + optiledTotalAnnualCost), '$ ' + ((currentInitialCost + currentTotalAnnualCost) - (optiledInitialCost + optiledTotalAnnualCost))]
//	];
//    store = new Ext.data.Store({
//        proxy: new Ext.data.MemoryProxy(dataSource),
//        reader: new Ext.data.ArrayReader({}, [
//	           { name: 'years' },
//	           { name: 'currentlamp' },
//	           { name: 'optiledledlighting' },
//	           { name: 'savings' }
//	            ])
//    });
//    store.load();
//    grid1 = new Ext.grid.GridPanel({
//        autoHeight: true,
//        width: 654,
//        colModel: colModel,
//        store: store

//    });
//    grid1.render('gridbyYears');
//}

Ext.onReady(function() {

    var ipt = document.getElementsByTagName("input");
    for (var i = 0; i < ipt.length; i++) {
        if (ipt[i].type == "text")
            ipt[i].value = "";
    }
    document.getElementById("ipt_optiledLifetime").value = 35000;

    Ext.get("ipt_refresh").on("click", function() { _refresh() });
    Ext.get("ipt_calculate").on("click", function() {
    getTotalSaving();
        if (_alert()) {
            var yy = (parseFloat(Ext.get("ipt_optiledInitialCostTotal").getValue()) - parseFloat(Ext.get("ipt_currentInitialCostTotal").getValue())) / (parseFloat(Ext.get("ipt_currentTotalAll").getValue()) - parseFloat(Ext.get("ipt_optiledTotalAll").getValue()));
            var mm = yy * 12;
            document.getElementById("ipt_backYears").value = _subString(yy); //yy.toString().substring(0, yy.toString().indexOf(".") + 3);
            document.getElementById("ipt_backMonths").value = parseInt(mm); //mm.toString().indexOf(".") > 0 ? mm.toString().substring(0, mm.toString().indexOf(".")) : mm;
           
            var aa_totalsaving = parseFloat(Ext.get("ipt_currentTotalAll").getValue()) - parseFloat(Ext.get("ipt_optiledTotalAll").getValue()); //TotalAnnualSaving.toString();
            var sav = aa_totalsaving.toString();
            var point = aa_totalsaving / parseFloat(Ext.get("ipt_currentTotalAll").getValue()) * 100;

            document.getElementById("ltl_totalSaving").value = "$ " + _subString(sav); // (sav.indexOf(".") > 0 ? sav.substring(0, sav.indexOf(".") + 3) : sav);
            document.getElementById("result_total").value = _subString(point) + "%"; // point.toString().substring(0, point.toString().indexOf(".") + 2) + "%";

            setValueNaN();
            _GetExportExcelMsg();
        }
    });

    Ext.get("ipt_wattage").on("keyup", function() { fBillSaved("ipt_wattage") });
    Ext.get("ipt_quantity").on("keyup", function() { fBillSaved("ipt_quantity") });
    Ext.get("ipt_lifetime").on("keyup", function() { fBillSaved("ipt_lifetime") });
    Ext.get("ipt_daysUseYear").on("keyup", function() { AnnualHoursOfOperation_ss("ipt_daysUseYear"); });
    Ext.get("ipt_averageDailyUse").on("keyup", function() { AnnualHoursOfOperation_ss("ipt_averageDailyUse"); });
    Ext.get("ipt_currentBallastLoss").on("keyup", function() { TotalPowerPerYear("ipt_currentBallastLoss") });
    Ext.get("ipt_optiledBallastLoss").on("keyup", function() { TotalPowerPerYear("ipt_optiledBallastLoss") });
    Ext.get("ipt_electricalCost").on("keyup", function() { getTotalSaving(); });

    Ext.get("ipt_lampCost").on("keyup", function() { initialTotal("ipt_lampCost"); });
    Ext.get("ipt_optiledLampCost").on("keyup", function() { initialTotal("ipt_optiledLampCost"); });
    Ext.get("ipt_fixtureCost").on("keyup", function() { initialTotal("ipt_fixtureCost"); });
    Ext.get("ipt_optiledFixtureCost").on("keyup", function() { initialTotal("ipt_optiledFixtureCost"); });

    Ext.get("ipt_currentLaborCostToReplaceALamp").on("keyup", function() {
        _replace("ipt_currentLaborCostToReplaceALamp");
        document.getElementById("ipt_optiledLaborCostToReplaceALamp").value = 0;
        document.getElementById("ipt_optiledAnnualLampChanges").value = 0;
        document.getElementById("ipt_optiledMaterialCost").value = 0;
        total2();
    });
});

function TotalPowerPerYear(Id) {

    _replace(Id);
    _inputValue();
    document.getElementById("ipt_currentTotalPowerPerYear").value = _subString(currentTotalPowerPerYear); // currentTotalPowerPerYear;
    document.getElementById("ipt_optiledTotalPowerPerYear").value = _subString(optiledTotalPowerPerYear); //optiledTotalPowerPerYear;
    document.getElementById("ipt_billsaved").value = _subString(BillSaved);
    
    setValueNaN();
}

function fBillSaved(Id) {

    _replace(Id);
    _inputValue();    
    
    document.getElementById("ipt_billsaved").value = _subString(BillSaved);
    
    setValueNaN();
}

function initialTotal(Id) {
    _replace(Id);
    _inputValue();

    document.getElementById("ipt_currentInitialCostTotal").value = currentFixtureCost + currentLampcost;
    document.getElementById("ipt_optiledInitialCostTotal").value = optiledFixtureCost + optiledLampcost;
    document.getElementById("ipt_currentMaterialCost").value = _subString(currentMaterialCost);

    var ctl = currentMaterialCost + currentLaborCost + currentElectricityBill, otl = parseFloat(Ext.get("ipt_optiledMaterialCost").getValue()) + optiledLaborCost + optiledElectricityBill;
    document.getElementById("ipt_currentTotalAll").value = _subString(ctl);
    document.getElementById("ipt_optiledTotalAll").value = _subString(otl); 
    
    setValueNaN();
}

function total2() {

    getTotalSaving();
}

function AnnualHoursOfOperation_ss(Id) {
    _replace(Id);
    var days = Ext.get("ipt_daysUseYear").getValue();
    var hours = Ext.get("ipt_averageDailyUse").getValue();
    var dd = days != null ? parseInt(days) : 0;
    var hh = hours = hours != null ? parseInt(hours) : 0;
    document.getElementById("ipt_currentAnnualHoursOfOperation").value = document.getElementById("ipt_optiledAnnualHoursOfOperation").value = dd * hh;
    setValueNaN();
}

function setValueNaN() {
    var a = document.getElementsByTagName("input");
    for (var i = 0; i < a.length; i++) {
        if (a[i].type == "text" && (a[i].value == "N" || a[i].value == "Na" || a[i].value == "NaN" || a[i].value == "N%" || a[i].value == "Na%" || a[i].value == "NaN%" || a[i].value == "$ Na" || a[i].value == "$ NaN")) {
            a[i].value = "";
        }
    }
}
function _refresh() {
    var a = document.getElementsByTagName("input");
    for (var i = 0; i < a.length; i++) {
        if (a[i].type == "text" && i!=7)
            a[i].value = "";
    }
    document.getElementById("ipt_optiledLifetime").value = 35000;
}
function _alert() {
    var _b = false;
    _inputValue();
    if (isNaN(currentWattage) || isNaN(optiledWattage))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Wattage is null"); return _b; }
    
    if (isNaN(quantity))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Quantity of Lamp/ Fixture is null"); return _b; }
    
    if (isNaN(currentLifetime))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Current Lifetime is null"); return _b; }
    
    if (isNaN(dayUseYear))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Days a year is null"); return _b; }

    if (isNaN(averageDailyUse))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Hours a day is null"); return _b; }

    if (isNaN(currentBallastLoss) || isNaN(optiledBallastLoss))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Ballast loss is null"); return _b; }

    if (isNaN(electricalCost ))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Energy rate is null"); return _b; }

    if (isNaN(currentLampcost) || isNaN(optiledLampcost))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Cost of a lamp cost is null"); return _b; }

    if (isNaN(currentFixtureCost) || isNaN(optiledFixtureCost))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Light fixtures cost is null"); return _b; }

    if (isNaN(currentLaborCostToReplaceALamp))
    { Ext.MessageBox.alert("Message", "<br/>Please fill in the required fields<br/><br/>--&raquo; Labor cost to replace a lamp is null"); return _b; }
    
    return true;
}

function _subString(values) {   
    var v = values.toString();
    var rv;
    if (v.indexOf(".") > 0) {
        v += '00';
        rv = v.substring(0, v.indexOf(".") + 3);
    }
    else
        rv = v;
    return rv;
}

function _replace(documentId) {
    var s = Ext.get(documentId).getValue();
    var patt1 = /[^0123456789.]/g;
    if (s.match(patt1) != null)
        document.getElementById("msg_input").style.display = "";
    else
        document.getElementById("msg_input").style.display = "none";
    //document.getElementById(documentId).value = s.toString().replace(/\D/g, ''); //^[0-9]+(.[0-9]{2})?$    //   /\D/g
}


function _GetExportExcelMsg() {
    var sel = document.getElementById("slt_products");
    _ExportExcelMsg = Ext.get("ipt_type").getValue() + "," + sel.options[sel.selectedIndex].text//Ext.get("slt_products").getValue()
    + "," + Ext.get("ipt_wattage").getValue() + "," + Ext.get("ipt_optiledWattage").getValue()
    + "," + Ext.get("ipt_quantity").getValue()
    + "," + Ext.get("ipt_lifetime").getValue() + "," + Ext.get("ipt_optiledLifetime").getValue()
    + "," + Ext.get("ipt_currentAnnualHoursOfOperation").getValue() + "," + Ext.get("ipt_optiledAnnualHoursOfOperation").getValue()
    + "," + Ext.get("ipt_currentBallastLoss").getValue() + "," + Ext.get("ipt_optiledBallastLoss").getValue()
    + "," + Ext.get("ipt_currentTotalPowerPerYear").getValue() + "," + Ext.get("ipt_optiledTotalPowerPerYear").getValue()
    + "," + Ext.get("ipt_currentElectricityBillYearly").getValue() + "," + Ext.get("ipt_optiledElectricityBillYearly").getValue()
    + "," + Ext.get("ipt_billsaved").getValue()
    + "," + Ext.get("ipt_lampCost").getValue() + "," + Ext.get("ipt_optiledLampCost").getValue()
    + "," + Ext.get("ipt_fixtureCost").getValue() + "," + Ext.get("ipt_optiledFixtureCost").getValue()
    + "," + Ext.get("ipt_currentInitialCostTotal").getValue() + "," + Ext.get("ipt_optiledInitialCostTotal").getValue()
    + "," + Ext.get("ipt_currentLaborCostToReplaceALamp").getValue() + "," + Ext.get("ipt_optiledLaborCostToReplaceALamp").getValue()
    + "," + Ext.get("ipt_currentAnnualLampChanges").getValue() + "," + Ext.get("ipt_optiledAnnualLampChanges").getValue()
    + "," + Ext.get("ipt_laborcost").getValue() + "," + Ext.get("ipt_optiledLaborcost").getValue()
    + "," + Ext.get("ipt_currentElectricityBill").getValue() + "," + Ext.get("ipt_optiledElectricityBill").getValue()
    + "," + Ext.get("ipt_currentMaterialCost").getValue() + "," + Ext.get("ipt_optiledMaterialCost").getValue()
    + "," + Ext.get("ipt_currentTotalAll").getValue() + "," + Ext.get("ipt_optiledTotalAll").getValue()
    + "," + Ext.get("ipt_backYears").getValue() + "," + Ext.get("ipt_backMonths").getValue()
    + "," + Ext.get("ltl_totalSaving").getValue() + "," + Ext.get("result_total").getValue()
    + "," + Ext.get("ipt_currentCOEmission").getValue() + "," + Ext.get("ipt_optiledCOEmission").getValue()
    + "," + Ext.get("ipt_savingCOEmission").getValue() + "," + Ext.get("ipt_savingEmissionPoint").getValue()
    + "," + Ext.get("ipt_daysUseYear").getValue() + "," + Ext.get("ipt_averageDailyUse").getValue() + "," + Ext.get("ipt_electricalCost").getValue()
    ;
}
