﻿//***************** Active Menu Highlight ************************
function scriptInit() 
{
    if (!document.getElementById) 
    {
        return;
    }
}

//assigning checkActive function to window as addEventListener, or attachEvent, or event
function addEvent(elm, evType, fn, useCapture) 
{
    if (elm.addEventListener) 
    {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    } 
    else if (elm.attachEvent) 
    {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }
    else 
    {
        elm['on' + evType] = fn;
    }
}

//checkActive will go thru all the menu items and get the current windows href and set that particular link as active.
function checkActive() 
{
    var lilist = document.getElementById('mainmenu');
    var alink = lilist.getElementsByTagName("a");
    if (window.location.href.substr(location.href.length - 1, 1) == '/') 
    {
        //if no file specified for the url, then append default page name.
        var loc = window.location.href + 'default.aspx';
    }
    else 
    {
        var loc = window.location.href;
    }

    for (var i = 0; i < alink.length; i++) 
    {
        if (loc == alink[i].href) 
        {
            alink[i].setAttribute("class", "active");
            alink[i].setAttribute("className", "active");
            break;
        }
    }
}

// add load event to 
addEvent(window, 'load', checkActive, false);

//***************** End Active Menu Highlight script************************

//****************************** Script for Dynamic grid *******************
$("document").ready(function()
{

    $(".addRow1").btnAddRow({ oddRowCSS: "oddRow", evenRowCSS: "evenRow", hiddenColClass: "hiddenCol", footerRowClass: "footerRow", spinButtonClass: "spinBtn" }, onRowQtyChanged);
    $(".delRow1").btnDelRow(onRowQtyChanged);

    $(".addRow2").btnAddRow({ oddRowCSS: "oddRow", evenRowCSS: "evenRow", hiddenColClass: "hiddenCol", footerRowClass: "footerRow", IDColumnName: "PartnerLevelID" }, onRowQtyChanged);
    $(".delRow2").btnDelRow(onRowQtyChanged);

    $(".addRow3").btnAddRow({ oddRowCSS: "oddRow", evenRowCSS: "evenRow", hiddenColClass: "hiddenCol", footerRowClass: "footerRow" }, onRowQtyChanged);
    $(".delRow3").btnDelRow(onRowQtyChanged);

    $(".dataNum").format({ precision: 2, allow_negative: false, autofix: true });

});

function onRowQtyChanged(row)
{

    try
    {

        $(".spinBtn").format({ precision: 0, allow_negative: false, autofix: true });

        $(".grdTextBox").format({ precision: 0, allow_negative: false, autofix: true });
        $(".grdTextBoxDecimal").format({ precision: 2, allow_negative: false, autofix: true });

        //var sum = SumUpTableRowsByColIndex("DynamicTable", 4);

        //document.getElementById("txtTotal").value = sum;
        //document.getElementById("txtTotal2").innerHTML = sum;

    }
    catch (Error)
    {
        //document.location.href = "Error.aspx?Module=StockItem.js&Method=onRowQtyChanged&Message=Error trying to load stock item grid";
    }

}

//****************************** End Script for Dynamic grid *******************