﻿
var RadGrid1;
function GetGridObject()
{
    RadGrid1 = this;
}

function showProduct(categoryID, productID)
{
    modalWindow("EditProduct.aspx?CategoryID=" + categoryID + "&" + "ProductID="+productID, "Edit Product" ,"900" ,"600");   
}

function getSelectedCategoryID(gridRow)
{
    var selectedMemberId = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "CategoryId").innerHTML;
    return selectedMemberId;
}

function getSelectedRowProductID(gridRow)
{
    var selectedMemberId = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "ProductId").innerHTML;
    return selectedMemberId;
}

function getSelectedRowProductName(gridRow)
{
    var selectedMemberId = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "ProductName").innerHTML;
    return selectedMemberId;
}

function getSelectedProductIdList()
{
   var SelectedList = "" ;
   var rows = RadGrid1.MasterTableView.SelectedRows;
   for(i=0;i<rows.length;i++)
   {
       SelectedList += getSelectedRowProductID(rows[i]) + ",";
   }
   SelectedList = SelectedList.substr(0,SelectedList.length-1);
   
   return SelectedList;
}

function addManyProducts()
{
    var categoryID = GetCategoryIDFromRowIndex(0);
     modalWindow("ProductAdder/Default.aspx?CategoryID="+categoryID , "Add Many Products", "640", "550");
}
function getSelectedProductNames()
{
   var SelectedList = "" ;
   var rows = RadGrid1.MasterTableView.SelectedRows;
   for(i=0;i<rows.length;i++)
   {
       SelectedList += getSelectedRowProductName(rows[i]) + ",";
   }
   SelectedList = SelectedList.substr(0,SelectedList.length-1);
   
   return SelectedList;
}


function GetProductIdFromRowIndex(rowIndex)
{   
    var gridRow = RadGrid1.MasterTableView.Rows[rowIndex];
    var selectedproductID = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "ProductId").innerHTML;
    return selectedproductID;
}

function GetCategoryIDFromRowIndex(rowIndex)
{
    var gridRow = RadGrid1.MasterTableView.Rows[rowIndex];
    var selectedcategoryID = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "CategoryId").innerHTML;
    return selectedcategoryID;
}

function RowDblClick(index)
{                
    var productID = GetProductIdFromRowIndex(index); 
    var categoryID = GetCategoryIDFromRowIndex(index); 
    showProduct(categoryID, productID);  
}

function moveToCategory()
{    
    var productIDs = getSelectedProductIdList();    
    if(productIDs.length == 0)
    {
        return;
    }
    var sUrl = "MoveProduct.aspx?IDList=" + productIDs ;       
    window.open(sUrl, "MoveProduct", 'height=400,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');
}

function copyToVcategory()
{
 var productIDs = getSelectedProductIdList();    
    if(productIDs.length == 0)
    {
        return;
    }
    var sUrl = "CopyProduct.aspx?IDList=" + productIDs ; 
    alert(sUrl);      
    window.open(sUrl, "CopyProduct", 'height=400,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');    

}

function RowSelected(gridRow)
{
    var cell = this.GetCellByColumnUniqueName(gridRow, "TemplateColumn");
    //document.write(cell); 

    if (!cell)
        return;

    var checkBox = GetCheckBox(cell);
    

    if (!checkBox)
        return;
                    
    gridRow.Selected ? checkBox.checked = true : checkBox.checked = false;
        
}

function RowDeselected(gridRow)
{
    var cell = this.GetCellByColumnUniqueName(gridRow, "TemplateColumn");

    if (!cell)
        return;

    var checkBox = GetCheckBox(cell);

    if (!checkBox)
        return;

    gridRow.Selected ? checkBox.checked = true : checkBox.checked = false;
}

function loadImage(Name, Type)
{
    ImagePickerCallBack.MakeCallback(Name, Type);
}
/* Vouchers */

function OpenVoucherWizard(VoucherId,IsNew){
    modalWindow("VoucherWizard/Default.aspx?VoucherId="+VoucherId+"&NewVoucher="+IsNew, "Voucher", "640", "550");
}

function OpenVoucherWizardByIndex(index)
{
    var Val = GetVoucherIdFromRowIndex(index)
    OpenVoucherWizard(Val,0);
}

function GetVoucherIdFromRowIndex(rowIndex){
    var gridRow = RadGrid1.MasterTableView.Rows[rowIndex];    
    var selectedMemberId = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "VoucherId").innerHTML;
    return selectedMemberId;
}


function RefreshVoucherGrid()
{
    CBLoadVouchers.MakeCallback("VoucherGrid", null);
}

function VoucherUpdate(){
   window.opener.document.getElementById('ButtLoadVouchers').click();   
   window.close();
}

function CloseVoucherWizard(){
    window.close();
}

function CloseAdderWizard(){
    window.opener.top.frames[2].RefreshDataGrid(window);
	        
    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
        CloseNow();            
    } 
   
} 

function CloseNow()
{
    window.close();
}       

/* Promotions */

function OpenPromotionWizard(PromotionId,IsNew){
    modalWindow("PromotionWizard/Default.aspx?PromotionId="+PromotionId+"&NewPromotion="+IsNew, "Promotion", "640", "550");
}

function OpenPromotionWizardByIndex(Index){
    Val = GetPromotionIdFromRowIndex(Index)
    OpenPromotionWizard(Val,0);
}

function GetPromotionIdFromRowIndex(rowIndex){
    var gridRow = RadGrid1.MasterTableView.Rows[rowIndex];
    var selectedMemberId = RadGrid1.MasterTableView.GetCellByColumnUniqueName(gridRow, "PromotionId").innerHTML;
    return selectedMemberId;
}



function PromotionUpdate(){
   window.opener.document.getElementById('ButtLoadPromotions').click();
   window.close();  
}

function ClosePromotionWizard(){
   window.close();  
}

/* SHIPPING */

function showSelectedShipping()
{
    if(mProductGrid != null)
    {
        if( mProductGrid.MasterTableView != null)
        {
            var rows = mProductGrid.MasterTableView.SelectedRows;
            if(rows.length >0)
            {
                var productID = getSelectedRowProductID(rows[0]);
                var categoryID = getSelectedCategoryID(rows[0]);
                showProduct(categoryID, productID);
            }
        }
    }
}

function deleteSelectedShipping()
{
    var msg = "Delete all selected shipping options?";
    if(confirm(msg))
    {
        rcbDeleteShipping.MakeCallback("ShippingGrid", getSelectedShippingIdList());
    }
}

function getSelectedShippingIdList()
{
   var SelectedList = "" ;
   var rows = mProductGrid.MasterTableView.SelectedRows;
   for(i=0;i<rows.length;i++)
   {
       SelectedList += getSelectedRowShippingID(rows[i]) + ",";
   }
   SelectedList = SelectedList.substr(0,SelectedList.length-1);
   
   return SelectedList;
}

function getSelectedRowShippingID(gridRow)
{
    var selectedMemberId = mProductGrid.MasterTableView.GetCellByColumnUniqueName(gridRow, "ShippingPriceId").innerHTML;
    return selectedMemberId;
}