﻿// Displays the Currency Value
var Currency = function(v, p, record) {
    var template = '{1}';
    v = (Math.round((v - 0) * 100)) / 100;
    v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
    var x = String.format(template, 'black', (v));
    if (p.id == 'BudgetDifAmount') {
        if (v == 0)
            x = String.format(template, 'black', (v));
        else if (v > 0 && record.data.AccountTypeID == 1)
            x = String.format(template, 'green', (v));
        else if (v > 0 && record.data.AccountTypeID == 2)
            x = String.format(template, 'red', (v));
        else if (v < 0 && record.data.AccountTypeID == 1)
            x = String.format(template, 'red', (v));
        else if (v < 0 && record.data.AccountTypeID == 2)
            x = String.format(template, 'green', (v));
        else if (isNaN(record.data.AccountTypeID))
            x = String.format(template, 'blue', (v));
    }
    return x
}


    // Grid Renderer 
    var CreateImage = function(value, metadata, record, rowIndex, colIndex, store) {
        return '<a href="#" onclick="showProductDetail(' + record.data.ProductID + ');return false;"><img class="imageborder" src=' + record.data.CacheImage + '></a>'
    };
    
    var FullName = function(value, metadata, record, rowIndex, colIndex, store) {
        return '<b class="producttitle">' + record.data.Name + '</b><br />' + record.data.BlisterText;
    };

    var NewsItem = function(value, metadata, record, rowIndex, colIndex, store) {
        return '<b class="red">' + record.data.Title + '</b>' ;
    };

    var TransitItem = function(value, metadata, record, rowIndex, colIndex, store) {
        return '<b class="producttitle">' + record.data.Transit + '</b>' ;
    };


    var prepCommandBackorder = function (grid, command, record, row) {
        if (command.command == 'EditBackorder' && record.get("Transit") == false) {
            command.hidden = true;
        }            
    };

function showProductDetail(ProductID){
    top.addDetailWindow(ProductID,-1,'Produktdetail','short',-1)
}

// To find the Left position, 
function getPositionLeft(This){
    var el = This;var pL = 0;
    while(el){pL+=el.offsetLeft;el=el.offsetParent;}
return pL
}

// To find the top position, 
function getPositionTop(This){
    var el = This;var pT = 0;
    while(el){pT+=el.offsetTop;el=el.offsetParent;}
    return pT
}

//self.moveTo(0,0);
//self.resizeTo(screen.availWidth,screen.availHeight);




