
var AlertItemCode = "Please enter the Item Code.";
var AlertItemName = "Please enter the Item name.";
var AlertItemDesc = "Please enter the Item Description.";
var AlertOpenQty = "Please enter the Open Quantity.";
var AlertReorderQty = "Please enter the Reorder Quantity.";
var AlertUnitprice = "Please enter the Unit Price.";
var AlertItemtype = "Please select the Item Category.";
var AlertItemTypeDesc = "Please enter the equipment Description.";

var AlertItemTypeName = "Please enter the equipment name.";

function ValidateItemInfo() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    var dtCurrentDate = new Date();

    var ddlDHT = document.getElementById('ddlDHT');
    var txtItemName = document.getElementById('txtItemcode');
    var txtItemName = document.getElementById('txtItemName');
    //var txtItemDesc = document.getElementById('txtItemDesc');
    var txtOpenQty = document.getElementById('txtOpenQty');
    var txtReorderQty = document.getElementById('txtReorderQty');
    var txtunitprz = document.getElementById('txtunitprz');
    //var FileUploader = document.getElementById('fupImage');
    var GetImage = document.getElementById('hdfImage');

    var SNo = document.getElementById('txtSNo');
    //$('#hdnCancelsts').val("SaveUpdate");
    if (RemoveSpaces(txtItemcode).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemCode;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemcode;
        }
        txtItemcode.style.backgroundColor = 'lightyellow';
    }
    else {
        txtItemName.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtItemName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemName;
        }
        txtItemName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtItemName.style.backgroundColor = 'white';
    }

    //if (RemoveSpaces(txtItemDesc).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemDesc;
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtItemDesc;
    //    }
    //    txtItemDesc.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtItemDesc.style.backgroundColor = 'white';
    //}

    //    if (RemoveSpaces(txtOpenQty).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertOpenQty;
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtOpenQty;
    //        }
    //        txtOpenQty.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtOpenQty.style.backgroundColor = 'white';
    //    }

    //    if (RemoveSpaces(txtReorderQty).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertReorderQty;
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtReorderQty;
    //        }
    //        txtReorderQty.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtReorderQty.style.backgroundColor = 'white';
    //    }

    if (ddlDHT != null) {
        if (!CheckIsSelected(ddlDHT.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemtype;
            isError = true;
            controlToBeFocused = ddlDHT;
            ddlDHT.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlDHT.style.backgroundColor = 'white';
        }
    }
    if (RemoveSpaces(SNo).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Serial No.";
        if (!isError) {
            isError = true;
            controlToBeFocused = SNo;
        }
        SNo.style.backgroundColor = 'lightyellow';
    }
    else {
        SNo.style.backgroundColor = 'white';
    }
    //if (RemoveSpaces(GetImage).length == 0) {
    //    if (RemoveSpaces(FileUploader).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Item photo.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = FileUploader;
    //        }
    //    }
    //}

    //    if (RemoveSpaces(txtunitprz).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertUnitprice;
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = txtunitprz;
    //        }
    //        txtunitprz.style.backgroundColor = 'lightyellow';
    //    }
    //    else {
    //        txtunitprz.style.backgroundColor = 'white';
    //    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}


function ValidateItemTypeInfo() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var dtCurrentDate = new Date();
    var txtItemName = document.getElementById('txtItemtypeName');
    //var txtItemDesc = document.getElementById('txtItemDesc');
    var FileUploader = document.getElementById('fupImage');
    var GetImage = document.getElementById('hdfImage');
    var hiddenTestBoxlist = document.getElementById('hdnTextBoxList');
    var TextBoxlit = hiddenTestBoxlist.value.split(",");
    //var hdnItem = document.getElementById('hdnItem');
    if (RemoveSpaces(txtItemName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemTypeName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemName;
        }
        txtItemName.style.backgroundColor = 'lightyellow';
    }
    else {
        txtItemName.style.backgroundColor = 'white';
    }
    var Intval = 0;
    for (var i = 0; i < TextBoxlit.length; i++) {
        var valijn = TextBoxlit[i];
        var txtval = document.getElementById(TextBoxlit[i]);
        if (txtval != null) {
            if (txtval.value == "") {
                if (Intval == 0)
                    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Serial No.";
                if (!isError) {
                    isError = true;
                    controlToBeFocused = txtval;
                }
                txtval.style.backgroundColor = 'lightyellow';
                Intval = 1;
            }
        }
    }

    //if (RemoveSpaces(txtItemDesc).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemTypeDesc;
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtItemDesc;
    //    }
    //    txtItemDesc.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    txtItemDesc.style.backgroundColor = 'white';
    //}
    //if (RemoveSpaces(GetImage).length == 0) {
    //    if (RemoveSpaces(FileUploader).length == 0) {
    //        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the equipment photo.';
    //        if (!isError) {
    //            isError = true;
    //            controlToBeFocused = FileUploader;
    //        }
    //    }
    //}

    if (RemoveSpaces(hdnItem).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Item to be assign.';
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemName;
        }
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}


function ValidateSpeareRequest() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var txtItemName = document.getElementById('hdnAddItem');
    if (txtItemName.value == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Spare item(s) list cannot be empty.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemName;
        }
    }
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}



function ValidateAlarmConfig() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var dtCurrentDate = new Date();
    var ddlCustomer = document.getElementById('ddlAlarms');
    
    var TxtReason = document.getElementById("TxtReason");
    var TxtCrctvactn = document.getElementById("TxtCrctvactn");
    


    if (!CheckIsSelected(ddlCustomer.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Alarm name.';
        isError = true;
        controlToBeFocused = ddlCustomer;
        ddlCustomer.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlCustomer.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(TxtReason).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Reason';
        if (!isError) {
            isError = true;
            controlToBeFocused = TxtReason;
        }
    }
    else {
        TxtReason.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(TxtCrctvactn).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please enter the Corrective Action';
        if (!isError) {
            isError = true;
            controlToBeFocused = TxtCrctvactn;
        }
    }
    else {
        TxtCrctvactn.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}




function ValidateSystemConfig() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var dtCurrentDate = new Date();
    var ddlCustomer = document.getElementById('ddlCustomer');
    var ddlDevice = document.getElementById('ddlDevice');
    var hdnItemsCount = document.getElementById('hdnItemsCount');


    if (!CheckIsSelected(ddlCustomer.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Customer Name.';
        isError = true;
        controlToBeFocused = ddlCustomer;
        ddlCustomer.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlCustomer.style.backgroundColor = 'white';
    }
    if (!CheckIsSelected(ddlDevice.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Device Name.';
        isError = true;
        controlToBeFocused = ddlDevice;
        ddlDevice.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlDevice.style.backgroundColor = 'white';
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}

function ValidateSparesRequest() {
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var ddlBoxId = document.getElementById('ddlDevice');
    var ddlEquipment = document.getElementById('ddlEquipment');
    var ddlCustomerID = document.getElementById('ddlCustomerID');
    var hdfItemTypeID = document.getElementById('hdfItemTypeID');
    var divCustomer = document.getElementById('divCustomer');

    if (divCustomer.style.display != "none") {
        if (!CheckIsSelectedZero(ddlCustomerID.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Equipment Name.';
            isError = true;
            controlToBeFocused = ddlCustomerID;
            ddlCustomerID.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlCustomerID.style.backgroundColor = 'white';
        }
    }
    if (!CheckIsSelected(ddlBoxId.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Device Name.';
        isError = true;
        controlToBeFocused = ddlBoxId;
        ddlBoxId.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlBoxId.style.backgroundColor = 'white';
    }


    if (!CheckIsSelected(ddlEquipment.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Equipment Name.';
        isError = true;
        controlToBeFocused = ddlEquipment;
        ddlEquipment.style.backgroundColor = 'lightyellow';
    }
    else {
        ddlEquipment.style.backgroundColor = 'white';
    }

    //if (RemoveSpaces(hdfItemTypeID).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please choose the item(s).';
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = hdfItemTypeID;
    //    }
    //    hdfItemTypeID.style.backgroundColor = 'lightyellow';
    //}
    //else {
    //    hdfItemTypeID.style.backgroundColor = 'white';
    //}
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}
function CheckIsSelectedZero(dropdownvalue) {
    return dropdownvalue != '0' ? true : false;
}


function ValidateImportItemInfo() {

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    var FileUploader = document.getElementById('fp_ImportFilePath');
    if (RemoveSpaces(FileUploader).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + 'Please select the Item file to be imported.';
        if (!isError) {
            isError = true;
            controlToBeFocused = FileUploader;
        }
    }
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        ShowPopUp();
        return true;
    }
}

//-------------------------------------------------- Invoice Entry ---------------------------------------------------------------------
function fun_val(txtval, tbxName) {
    var txtAmount, txtTaxAmount, txtRevdQty, lblTotalAmt, totamt;
    if (tbxName == 'txtAmount') {
        txtAmount = txtval.id;
        // txtTaxAmount = txtAmount.replace(tbxName, "txtTaxAmount");
        txtRevdQty = txtAmount.replace(tbxName, "txtRevdQty");
        lblTotalAmt = txtAmount.replace(tbxName, "lblTotalAmt");
        totamt = (document.getElementById(txtAmount).value) * (document.getElementById(txtRevdQty).value);
        document.getElementById(lblTotalAmt).innerHTML = totamt.toFixed(2);
    }
    if (tbxName == 'txtRevdQty') {
        chk_Qty(txtval, tbxName);
        txtRevdQty = txtval.id;
        // txtTaxAmount = txtAmount.replace(tbxName, "txtTaxAmount");
        txtAmount = txtRevdQty.replace(tbxName, "txtAmount");
        lblTotalAmt = txtRevdQty.replace(tbxName, "lblTotalAmt");
        totamt = (document.getElementById(txtAmount).value) * (document.getElementById(txtRevdQty).value);
        document.getElementById(lblTotalAmt).innerHTML = totamt.toFixed(2);
    }
    if (tbxName == 'txtTaxAmt') {
        txtbx = document.getElementById(tbxName).value
        hdn = document.getElementById('hdnTotalAmt').value
        if (txtbx == "")
            txtbx = 0;
        if (hdn == "")
            hdn = 0;
        totamt = parseFloat(hdn) + parseFloat(txtbx);
        document.getElementById('txtTotInvAmt').value = totamt.toFixed(2).replace(/./g, function (c, i, a) {
            return i && c !== "." && !((a.length - i) % 3) ? ',' + c : c;
        });
    }
    if (tbxName == 'txtQty') {
        txtRevdQty = txtval.id;
        var unitprice = document.getElementById('txtUnitprice').value;
        totamt = (document.getElementById(txtRevdQty).value) * unitprice;
        document.getElementById('txtTolAmt').value = totamt.toFixed(2);
    }
    if (tbxName == 'txtItemname') {
        var unitprice = document.getElementById('txtUnitprice').value;
        totamt = (document.getElementById('txtQty').value) * unitprice;
        document.getElementById('txtTolAmt').value = totamt.toFixed(2);
    }
}

function chk_Qty(txtval, tbxName) {
    var txtOrderQty, txtRevdQty, Alert;

    if (tbxName == 'txtOrderQty') {
        txtOrderQty = txtval.id;
        txtRevdQty = txtOrderQty.replace(tbxName, "txtRevdQty");
        Alert = 'Ordered quantity cannot be less than Received quantity!';
    }
    if (tbxName == 'txtRevdQty') {
        txtRevdQty = txtval.id;
        txtOrderQty = txtRevdQty.replace(tbxName, "txtOrderQty");
        Alert = 'Received quantity cannot be greater than Ordered quantity!';
    }
    if (Trim(document.getElementById(txtOrderQty).value) != "" && Trim(document.getElementById(txtRevdQty).value) != "") {
        if (parseInt(document.getElementById(txtOrderQty).value) < parseInt(document.getElementById(txtRevdQty).value)) {
            TrinetraCustomAlerts(Alert); return false;
        }
    }
}

function fun_ItemCode(txtbxval, tbxname) {

    //alert(document.getElementById("hdnItemNo").value);
    var txtItemname, lblItemcode, txtUnitprice, lblUoM;
    txtItemname = txtbxval.id;
    lblItemcode = txtItemname.replace(tbxname, "lblItemcode");
    txtUnitprice = txtItemname.replace(tbxname, "txtUnitprice");
    lblUoM = txtItemname.replace(tbxname, "lblUoM");
    document.getElementById(lblItemcode).lblUoM = "";
    document.getElementById(lblItemcode).innerHTML = "";
    document.getElementById(txtUnitprice).value = "";
    if (document.getElementById("hdnItemNo").value != "") {
        document.getElementById(lblItemcode).innerHTML = document.getElementById("hdnItemNo").value;
    }
    if (document.getElementById("hdnUnitPrice").value != "") {
        document.getElementById(txtUnitprice).value = document.getElementById("hdnUnitPrice").value;
    }
    if (document.getElementById("hdnUoM").value != "") {
        document.getElementById(lblUoM).innerHTML = document.getElementById("hdnUoM").value;
    }
    else {
        document.getElementById(txtItemname).value = "";
    }

}
//-------------------------------------------------Invoice Entry page grid details
function fun_ItemSave(ctrlval, ctrlId) {
    //alert(document.getElementById("hdnItemNo").value);
    var lnk_save, txtItemname, txtOrderQty, txtRevdQty, txtUnitprice, txtAmount;
    lnk_save = ctrlval.id;
    txtItemname = document.getElementById(lnk_save.replace(ctrlId, "txtItemname"));
    txtOrderQty = document.getElementById(lnk_save.replace(ctrlId, "txtOrderQty"));
    txtRevdQty = document.getElementById(lnk_save.replace(ctrlId, "txtRevdQty"));
    txtUnitprice = document.getElementById(lnk_save.replace(ctrlId, "txtUnitprice"));
    txtAmount = document.getElementById(lnk_save.replace(ctrlId, "txtAmount"));

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtItemname).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemname;
        }
    }
    if (RemoveSpaces(txtOrderQty).length == 0 || Trim(txtOrderQty.value) == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Ordered Quantity.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtOrderQty;
        }
    }
    if (RemoveSpaces(txtRevdQty).length == 0 || Trim(txtRevdQty.value) == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Received Quantity.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtRevdQty;
        }
    }
    //if (RemoveSpaces(txtUnitprice).length == 0) {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertUnitprice;
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = txtUnitprice;
    //        document.getElementById(txtUnitprice).value = "0";
    //    }
    //}

    if (RemoveSpaces(txtAmount).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Net Price.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtAmount;
        }
    }

    if (parseInt(txtOrderQty.value) < parseInt(txtRevdQty.value)) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Received quantity cannot be greater than Ordered quantity!";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtRevdQty;
        }
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}



function fun_MachineSave(ctrlval, ctrlId) {
    var lnk_save, txtItemname, txtOrderQty, txtRevdQty, txtUnitprice, txtAmount;
    lnk_save = ctrlval.id;
    txtMachineName = document.getElementById(lnk_save.replace(ctrlId, "txtMachineName"));
    txtMachineVolume = document.getElementById(lnk_save.replace(ctrlId, "txtMachineVolume"));

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtMachineName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the machine name.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtMachineName;
        }
    }
    if (RemoveSpaces(txtMachineVolume).length == 0 || Trim(txtMachineVolume.value) == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Machine Volume.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtMachineVolume;
        }
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

 
function fun_alarmSave(ctrlval, ctrlId) {
    var lnk_save, txtItemname, txtOrderQty, txtRevdQty, txtUnitprice, txtAmount;
    lnk_save = ctrlval.id;
    txtMachineName = document.getElementById(lnk_save.replace(ctrlId, "txtMachineName"));
    txtMachineVolume = document.getElementById(lnk_save.replace(ctrlId, "txtMachineVolume"));
 
    ddl_defect = document.getElementById(lnk_save.replace(ctrlId, "ddl_defect")); 
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtMachineName).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Reason.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtMachineName;
        }
    }
    if (RemoveSpaces(txtMachineVolume).length == 0 || Trim(txtMachineVolume.value) == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Corrective Action.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtMachineVolume;
        }
    }
 
    if (ddl_defect.value == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the alarm.";
        if (!isError) {
            isError = true;
            controlToBeFocused = ddl_defect;
        }
    }
 
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
} 
  
 

function ValidateAlarmConfig() {
    var TxtReason = document.getElementById("TxtReason");
    var TxtCrctvactn = document.getElementById("TxtCrctvactn");

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';

    //if (ddl_defect.value == "0") {
    //    alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the alarm.";
    //    if (!isError) {
    //        isError = true;
    //        controlToBeFocused = ddl_defect;
    //    }
    //}
    if (RemoveSpaces(TxtReason).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the reason.";
        if (!isError) {
            isError = true;
            controlToBeFocused = TxtReason;
            TxtReason.style.backgroundColor = 'lightyellow';
        }
    }
    else {
        TxtReason.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(TxtCrctvactn).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the corrective action.";
        if (!isError) {
            isError = true;
            controlToBeFocused = TxtCrctvactn;
        }
        TxtCrctvactn.style.backgroundColor = 'lightyellow';
    }
    else {
        TxtCrctvactn.style.backgroundColor = 'white';
    }


    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function fun_InvoiceSave(Btn) {
    var ddlVendor = document.getElementById('ddlVendor');
    var txtInvc = document.getElementById('txtInvc');
    var txtInvcDate = document.getElementById('txtInvcDate');
    var txtDueDate = document.getElementById('txtDueDate');
    var hdnItemsCount = document.getElementById('hdnItemsCount');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtInvc).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Receipt #";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtInvc;
        }
        txtInvc.style.backgroundColor = 'lightyellow';
    }
    else {
        txtInvc.style.backgroundColor = 'white';
    }
    if (RemoveSpaces(txtInvcDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Receipt Date.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtInvcDate;
        }
        txtInvcDate.style.backgroundColor = 'lightyellow';
    }
    else {
        txtInvc.style.backgroundColor = 'white';
    }
    //alert(hdnItemsCount.value);
    if (RemoveSpaces(hdnItemsCount).length == 0 || hdnItemsCount.value == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the items purchased.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtInvc;
        }
    }

    if (ddlVendor != null) {
        if (!CheckIsSelected(ddlVendor.value)) {
            alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the Vendor.";
            isError = true;
            controlToBeFocused = ddlVendor;
            ddlVendor.style.backgroundColor = 'lightyellow';
        }
        else {
            ddlVendor.style.backgroundColor = 'white';
        }
    }
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        TrinetraConfirm(Btn, 'Are your sure you have verified the above details and continue to save this Receipt?'); return false;
    }
}

//------------------------------- Order Request ---------------------------------------------
function fun_OdrItemSave() {
    //alert(document.getElementById("hdnItemNo").value);
    var lnk_save, txtItemname, txtOrderQty, txtRevdQty, txtUnitprice, txtAmount;
    //lnk_save = ctrlval.id;
    txtItemname = document.getElementById("txtItemname");
    txtOrderQty = document.getElementById("txtQty");
    //txtRevdQty = document.getElementById(lnk_save.replace(ctrlId, "txtRevdQty"));
    //txtUnitprice = document.getElementById(lnk_save.replace(ctrlId, "txtUnitprice"));
    //txtAmount = document.getElementById(lnk_save.replace(ctrlId, "txtAmount"));

    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtItemname).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + AlertItemName;
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemname;
        }
    }
    if (RemoveSpaces(txtOrderQty).length == 0 || Trim(txtOrderQty.value) == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the Required Quantity.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtOrderQty;
        }
    }

    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}

function OrderSave() {
    var hdnItemsCount = document.getElementById('hdnItemsCount');
    txtItemname = document.getElementById("txtItemname");
    var txtDueDate = document.getElementById('txtDueDate1');
    var isError = false;
    var controlToBeFocused;
    var alertMessage = '';
    if (RemoveSpaces(txtDueDate).length == 0) {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please select the Due Date.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtDueDate;
        }
    }
    if (RemoveSpaces(hdnItemsCount).length == 0 || hdnItemsCount.value == "0") {
        alertMessage += (alertMessage.length > 0 ? '</br>' : '') + "Please enter the items to make an order.";
        if (!isError) {
            isError = true;
            controlToBeFocused = txtItemname;
        }
    }
    if (isError) {
        controlToBeFocused.focus();
        TrinetraCustomAlerts(alertMessage);
        return false;
    }
    else {
        return true;
    }
}