function shopConfirmDelete(id) {
    openWindow('deleteProductConfirm', true);
    document.getElementById('productId-deleteProduct').value = id;
}
function shopEdit(id) {
    document.getElementById('shopAddInnerForm').innerHTML = 
        document.getElementById('shopModifyProduct-'+id).innerHTML;
    tinyMCE.get('shopdescriptionmod').setContent(
        document.getElementById('shopmodifydescription-'+id).innerHTML);
    openWindow('shopModifyProduct');
}
function shopSuspend(id) {
    document.getElementById('shopSuspendForm-'+id).submit();
}
function shopAddCategory() {
    var inputs = document.getElementById('shopCategoriesAddForm')
                 .getElementsByTagName("input");
    var url = "add";
    for (i in inputs) {
        if (inputs[i].name && inputs[i].name.indexOf('name') != -1) {
          url += "&" + inputs[i].name + "=" + inputs[i].value;
        }
    }
    ajax(actionPath + "shopAddCategory?"+url, shopCategoryAdded);
}

function shopCategoryAdded(name) {
    var inputs = document.getElementById('shopCategoriesAddForm')
                 .getElementsByTagName("input");
    for (i in inputs) {
        if (inputs[i].name && inputs[i].name.indexOf('name') != -1) {
          inputs[i].value = "";
        }
    }
    var values = name.split(",");
    var id = values[0];
    closeWindow('shopCategoriesAdd');
    var table = document.getElementById('shopCategoriesTable');
    var row = table.insertRow(table.rows.length);
    row.id = 'shopCategory' + id;
    var leftCell = row.insertCell(0);
    leftCell.className = "shopCatTdNotHighlighted";
    leftCell.innerHTML = values[1];
    var rightCell = row.insertCell(1);
    rightCell.className = "shopCatTdNotHighlighted";
    
    var html =
        ' <a href="javascript:shopModifyCategoryOpen(\''+id+'\');"'+
        'class="foxoneA"><img src="/shared/img/2/modify_icon.png" '+
        'alt="" style="border: none;"/></a> '+
        '<a href="javascript:shopDeleteCategoryOpen(\''+id+'\');" '+
        'class="foxoneA"><img src="/shared/img/2'+
        '/delete_intree_icon.png" alt="" style="border: none;"/></a>';
    rightCell.innerHTML = html;
}

var delShopCategoryId = null;
function shopCategoryDeleted() {
    document.getElementById('shopCategory'+delShopCategoryId).innerHTML = "";
    delShopCategoryId = null;
    closeWindow('shopCategoriesDelete');
}

function shopCategoryModified(name) {
    try {
      var html = document.getElementById('shopCategory'+modShopCategoryId)
        .getElementsByTagName("TD")[0].innerHTML;
      html = (""+html).split(modShopCategoryName).join(name);
      document.getElementById('shopCategory'+modShopCategoryId)
        .getElementsByTagName("TD")[0].innerHTML = html;
    } catch (exception) { 
    }
    modShopCategoryId = null;
    modShopCategoryName = null;
    closeWindow('shopCategoriesModify');
}
function shopDeleteCategoryOpen(categoryId) {
    delShopCategoryId = categoryId;
    openWindow('shopCategoriesDelete', true);
}
function shopDeleteCategory() {
    ajax(actionPath + "shopDeleteCategory?categoryId="+delShopCategoryId, 
        shopCategoryDeleted);
}
var modShopCategoryId = null;
var modShopCategoryName = null;
function shopModifyCategoryOpen(categoryId) {
    var html = document.getElementById('shopCategory'+categoryId).innerHTML;
    var name = null;
    if(navigator.userAgent.indexOf("Firefox")!=-1) {
      name = html.substring(html.indexOf("<td")+36, html.indexOf('</td>'));
    } else {
      name = html.substring(html.indexOf("<TD")+34, html.indexOf('</TD>'));
    }
    document.getElementById('modifyShopCategoryNameInput').value = name;
    modShopCategoryId = categoryId;
    modShopCategoryName = name;
    openWindow('shopCategoriesModify', true);
}

function shopModifyCategory() {
    ajax(actionPath + "shopAddCategory?categoryId="+modShopCategoryId+"&name="+
        document.getElementById('modifyShopCategoryNameInput').value,
        shopCategoryModified);
}

