function loadStoreDivs()
{
    var ogs = "ogs-test";

    if (document.getElementById("CENTERDIV2") != null)
    {
        // loadStoreDivs() is already run
        return;
    }
    
    var tmpRow, tmpCell0, tmpCell1, tmpCell2;

    var nodep = document.getElementById("NODEP");
    nodep.innerHTML = '';

    var t  = CreateTable('375','495','NODEP', 'NODEPTABLE');
    document.getElementById('NODEPTABLE').className = "tabstyle1";

    tmpRow = AppendRow('NODEPTABLE', '-1');
    
    var tmpCell0 = AppendCell(tmpRow, '0');
    tmpCell0.className = "tdstyle1";
    tmpCell0.innerHTML = "<div ID=\"LEFTDIV2\" style=\"text-align:left;height:700px;border:0px solid red;overflow:auto;\"></div>";

//                         "<input type=\"hidden\" name=\"ogs\" id=\"ogs\" value=\"+ ogs + \">";

    tmpCell1 = AppendCell(tmpRow, '1');
    tmpCell1.className = "tdstyle2";
    tmpCell1.innerHTML = "<div id=\"CENTERDIV3\" style=\"text-align:center;height:50px;border:0px solid blue;\"></div>" +
                         "<div id=\"CENTERDIV4\" style=\"text-align:center;height:50px;border:0px solid green;\"></div>" +
                         "<div id=\"CENTERDIV2\" style=\"text-align:center;height:600px;border:0px solid black;overflow:auto;\"></div>";
    
    tmpCell2 = AppendCell(tmpRow, '2');
    tmpCell2.className = "tdstyle3";
    tmpCell2.innerHTML = "<div align=\"center\" id=\"RIGHTDIV1\" style=\"text-align:center;height:100px;border:0px solid red;\"></div>" +
                         "<div align=\"center\" id=\"RIGHTDIV2\" style=\"text-align:center;height:630px;border:0px solid blue;overflow:auto;\"></div>";
};

function loadTreeByStore(clr)
{
    loadStoreDivs();

    var cart     = document.getElementById("cart").value;
    
    if (cart > 1)
    {
        var ayenay = confirm("Do you like to discard the existing cart and shop with a new store?");
        
        if (! ayenay)
        {
            return -1;
        }
        document.getElementById("cart").value = 1;
        document.getElementById('CENTERDIV4').innerHTML = "";
    }

    var cityel   = document.getElementById("city");
    var areael   = document.getElementById("area");
    var storeel  = document.getElementById("store");

    var cid      = cityel.options[cityel.selectedIndex].text;
    var aid      = areael.options[areael.selectedIndex].text;
    var sid      = storeel.options[storeel.selectedIndex].text;

    if (cid == 'Select Delivery City' ||
        aid == 'Select Delivery Area' ||
        sid == 'Select Favorite Store')
    {
        alert('Please select city, area and a store');
        return;
    }

    loadStoreCode();
    
    var sc         = document.getElementById("SCODE").value;

    var dynjsele = document.getElementById('dynjs');
    var e, r;
    
    if (dynjsele == null)
    {
//        alert('first js replace');
        e = "dyntree.js";
    }
    else
    {
//        alert('later js replace');
        e = dynjsele.value;
    }
    
    r = "meta/" + cid + "/js/loadProd_" + sc + "\.js";

//    alert('existing: ' + e + ', replacing: ' + r);
//    replacejscssfile(e, r, "js");

    if (sc == 'B1000' ||
        sc == 'H1001')
    {
        document.getElementById('CENTERDIV3').innerHTML = "<b><font color=\"black\">The minimum order amount should be <font color=\"orange\">Rs. 200/-.</font> We will deliver in <font color=\"orange\">entire " + cid + "</font> city</font></b>";
    }
    else if (sc == 'UML101')
    {
        document.getElementById('CENTERDIV3').innerHTML = "<b><font color=\"black\">The minimum order amount should be <font color=\"orange\">USD. 10/-.</font> We will deliver in <font color=\"orange\">entire " + aid + "</font> city</font></b>";
    }
    else
    {
        document.getElementById('CENTERDIV3').innerHTML = "<b><font color=\"black\">The minimum order amount should be <font color=\"orange\">Rs. 200/-.</font> We will delivery up to <font color=\"orange\">2KMs</font> radius from the selected store</font></b>";
    }
    document.getElementById('CENTERDIV4').innerHTML = "";

//    document.getElementById('SELFAD').innerHTML = "";

    removeTree();
    ajaxTree();
    
    removeSummary();
    SummaryTable();

    removeCart();
    addCart();
    
    if (!clr)
    {
        removeLeafEvents();
    
        document.getElementById('CENTERDIV2').innerHTML  = "<br><br>We are actively updating the inventory to improve the product range and tie up with various stores that bring greater discounts to you<br><br><br><<-- Expand and select product categories list in the left panel for detailed listing of groceries of that product category.";
    }

//    document.getElementById('LEFTDIV2_1').innerHTML  = "<h2>SELECT PRODUCTS</h2>";
//    document.getElementById('RIGHTDIV1_1').innerHTML = "<h2>SHOPPING SUMMARY</h2>";
//    document.getElementById('RIGHTDIV2_1').innerHTML = "<h2>SHOPPING CART DETAILS</h2>";
    
//    centerHead();
    
};


function SummaryTable()
{
    document.getElementById('RIGHTDIV1').style.border = "2px solid black";
    document.getElementById('RIGHTDIV2').style.border = "2px solid black";
    document.getElementById('RIGHTDIV2').style.height = "500px";
    //document.getElementById('RIGHTDIV1').height = "625";

    
    CreateTable('245','100','RIGHTDIV1', 'RTABLE1');

//    var tmpRow3 = AppendRow('RTABLE1', '0');
    
//    var tmpCell3_1 = AppendCell(tmpRow3, '0');
//    tmpCell3_1.innerHTML = "<input type=\"button\" class=\"btn\" id=\"order\" name=\"checkout\" value=\"Check Out\" onclick=\"orderForm(\'Check Out\')\" /> ";

    var tmpRow2 = AppendRow('RTABLE1', '0');
    
    var tmpCell2_1 = AppendCell(tmpRow2, '0');
    tmpCell2_1.className = "style8_1";
    tmpCell2_1.align = "center";
    tmpCell2_1.innerHTML = "Grand Total&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

    var tmpCell2_2 = AppendCell(tmpRow2, '1');
    tmpCell2_2.className = "style8_2";
    tmpCell2_2.id = 'cell_gt';
    tmpCell2_2.innerHTML = "<input type=\"hidden\" value=\"0\" name=\"gt\" id=\"gt\" />" +
                           "<span id=\"SPANPROD\">&nbsp;&nbsp;&nbsp;&nbsp; 0 &nbsp;&nbsp;&nbsp;&nbsp;</span>";

//    var tmpCell2_3 = AppendCell(tmpRow2, '2');
//    tmpCell2_3.innerHTML = "<input type=\"button\" class=\"btn\" id=\"po\" value=\"Order, Now!\"/> ";

    var tmpRow1 = AppendRow('RTABLE1', '0');
    
    var tmpCell1_1 = AppendCell(tmpRow1, '0');
    tmpCell1_1.className = "style8_1";
    tmpCell1_1.align = "center";
    tmpCell1_1.innerHTML = "No. of items &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

    var tmpCell1_2 = AppendCell(tmpRow1, '1');
    tmpCell1_2.className = "style8_2";
    tmpCell1_2.id = 'cell_noi';
    tmpCell1_2.innerHTML = "<input type=\"hidden\" value=\"0\" name=\"noi\" id=\"noi\" />" + "<span id=\"SPANPROD\">&nbsp;&nbsp;&nbsp;&nbsp; 0 &nbsp;&nbsp;&nbsp;&nbsp;</span>";

    var tmpRow0 = AppendRow('RTABLE1', '0');
    
    var tmpCell0_1 = AppendCell(tmpRow0, '0');
    tmpCell0_1.innerHTML = "<b>Shopping Summary:</b>";

    var tmpCell0_2 = AppendCell(tmpRow0, '1');
    tmpCell0_2.innerHTML = "";

    CreateTable('245','100','RIGHTDIV1', 'STABLE1');

    var tmpRow3 = AppendRow('STABLE1', '0');
    
    var tmpCell3_1 = AppendCell(tmpRow3, '0');
    tmpCell3_1.align = "left";
    tmpCell3_1.innerHTML = "<span sytle=\"text-align:center;\" align=\"center\"><input type=\"button\" class=\"btn\" id=\"order\" name=\"checkout\" value=\"CheckOut\" onclick=\"orderForm(\'Check Out\')\" /><input type=\"button\" class=\"btn\" id=\"saveorder\" name=\"saveorder\" value=\"SaveOnly\" onclick=\"saveOrderForm()\" /></span>";

};

// Invoke this function upon clicking on the leaf node

function selectLeaf(msg) {

    document.getElementById('CENTERDIV3').innerHTML = "<div>CHOOSE QUANTITY AND CLICK ON 'CART' TO ADD PRODUCT TO THE CART</div>";
    document.getElementById('CENTERDIV3').style.display = 'block';

//    document.getElementById('CENTERDIV4').innerHTML = "<div ><b><span>ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRODUCT NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRICE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QTY&nbsp;&nbsp;&nbsp;ADD<hr></span></b></div>";

    document.getElementById('CENTERDIV4').innerHTML = "<b><span style=\"color:maroon;\">Didn't find a product you are looking for? <a href=\"#\" onclick=\"notFoundProdAdd(\'" + msg + "\'); return false;\">Click Here</a> to add</span></b>";

    document.getElementById('CENTERDIV4').style.display = 'block';


  removeLeafEvents();
  
//    document.getElementById('CENTERDIV2').innerHTML = "<div ><b><span>ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRODUCT NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PRICE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QTY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></b></div>";
//    document.getElementById('CENTERDIV2').style.display = 'block';

  var d   = document.getElementById('CENTERDIV2');
  
  var ct = centerHead();

//  getProducts(msg, ct);
//  ajaxGetProducts(msg, ct);
ajaxGetNewProducts(msg);
};

function centerHead()
{
    var ct  = CreateTable('375','495','CENTERDIV2', 'CTABLE');
    
//    return ct;
    
    var tmpRow, tmpCell0, tmpCell1, tmpCell2, tmpCell3;
    var tmpCell4, tmpCell5, tmpCell6, tmpCell7;

    tmpRow = AppendRow('CTABLE', '-1');
    
    var tmpCell0 = AppendCell(tmpRow, '0');
//    tmpCell0.wdith = "15";
    tmpCell0.className = "style9_1";
    tmpCell0.innerHTML = "<b>INFO</b>";

    tmpCell1 = AppendCell(tmpRow, '1');
//    tmpCell1.wdith = "150";
    tmpCell1.className = "style9_2";
    tmpCell1.innerHTML = "<b>PRODUCT NAME</b>";
//    tmpCell1.innerHTML = "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>";

    tmpCell2 = AppendCell(tmpRow, '2');
//    tmpCell2.wdith = "25";
    tmpCell2.className = "style9_3";
    tmpCell2.innerHTML = "<b>UNIT M.R.P.</b>";

    tmpCell3 = AppendCell(tmpRow, '3');
//    tmpCell3.wdith = "10";
    tmpCell3.className = "style9_4";
    tmpCell3.innerHTML = "<b>LESS</b>";

    tmpCell4 = AppendCell(tmpRow, '4');
//    tmpCell4.wdith = "25";
    tmpCell4.className = "style9_5";
    tmpCell4.innerHTML = "<b>QTY</b>";

    tmpCell5 = AppendCell(tmpRow, '5');
//    tmpCell5.wdith = "<a href=\"#\" onclick=\"return false;\">Click To Add</a>";
    tmpCell5.className = "style9_6";
    tmpCell5.innerHTML = "<b>MORE</b>";

    tmpCell6 = AppendCell(tmpRow, '6');
//    tmpCell6.wdith = "25";
    tmpCell6.className = "style9_7";
    tmpCell6.innerHTML = "<b>ADD TO CART</b>";

    tmpCell7 = AppendCell(tmpRow, '7');
    tmpCell7.className = "style9_8";
    tmpCell7.innerHTML = "<b>QTY-PRICE</b>";

    return ct;
};

// Add products on CENTERDIV2 and have events associated
// This needs a lot of enhancement.
// CENTERDIV2 is the most dynamic pane in the portal

function addLeafEvent(msg, ct, x, y) {

    var ni = document.getElementById('CENTERDIV2');
    
    var id, prod, price;

    var msgList1 = msg.split(';');
    var id       = (msgList1[0].split(':'))[1];
    var prod     = (msgList1[1].split(':'))[1];
    var price    = (msgList1[2].split(':'))[1];

//    ct.width = "700px";

    var tmpRow = AppendRow('CTABLE', '-1');
//    tmpRow.className = "style9";

//    alert('here1: ' + x + ' - here2: ' + y);
    var tmpCell0 = AppendCell(tmpRow, '0');
    tmpCell0.className = "style9_1";
//    tmpCell0.innerHTML = "<span onMouseOut=\"Hide()\" onMouseOver=\"Show(event, " + id + ", \'" + x + "\', \'" + y + "\')\" ><img src=\"question.gif\" class=\"iadd\" alt=\"product id:"+id+"\" /></span>";

    tmpCell0.innerHTML = "<span onMouseOut=\"Hide()\" onMouseOver=\"Show(event, " + id + ", \'" + x + "\', \'" + y + "\')\" ><img src=\"question.gif\" class=\"iadd\" /></span>";

    var tmpCell1 = AppendCell(tmpRow, '1');
//    tmpCell1.width    = "400";
    tmpCell1.className = "style9_2";
    tmpCell1.innerHTML = "<span>" + prod + "</span>";
    
    var tmpCell2 = AppendCell(tmpRow, '2');
    tmpCell2.className = "style9_3";
    tmpCell2.innerHTML = "<span>&nbsp;" + price + "/-</span>";
    
    var tmpCell3 = AppendCell(tmpRow, '3');
    tmpCell3.className = "style9_4";
    tmpCell3.innerHTML = "<span>&nbsp;<img src=\"minus.gif\" class=\"iadd\" onclick=\"decr(\'c_"+id+"\', \'d_"+id+"\', " + price + ")\" alt=\"Decrease Quantity\" /></span>";

    var tmpCell4 = AppendCell(tmpRow, '4');
    tmpCell4.className = "style9_5";
    tmpCell4.innerHTML = "<span><input type=\"text\" size=\"1\" id=\"c_" + id + "\" maxlength=\"1\" class=\"tf1\" value=\"1\"/></span>";

    var tmpCell5 = AppendCell(tmpRow, '5');
    tmpCell5.className = "style9_6";
    tmpCell5.innerHTML = "<span><img src=\"plus.gif\" class=\"iadd\" onclick=\"incr(\'c_"+id+"\', \'d_"+id+"\', " + price + ")\" alt=\"Increase Quantity\" /></span>";

    var tmpCell6 = AppendCell(tmpRow, '6');
    tmpCell6.className = "style9_7";
    tmpCell6.innerHTML = "<span><img src=\"shcrt2.jpg\" width=\"25\" class=\"iadd\" onclick=\"addCartEvent(\'"+msg+"\')\" alt=\"Add To Cart\" /></span>";
    
    var tmpCell7 = AppendCell(tmpRow, '7');
    tmpCell7.className = "style9_8";
    tmpCell7.innerHTML = "<div id=\"d_"+id+"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>";
    
//    var dhp = document.createElement('div');
//    dhp.className = "htmltooltip";
//    dhp.innerHTML = "html tool tip: " + y;
//    ni.appendChild(dhp);
    
};

function notFoundProdAdd(msg)
{
    removeLeafEvents();
  
    document.getElementById('CENTERDIV2').innerHTML = "<div ><span>Add products that are not listed in our website for the selected store. Include a complete product description with details like \"Product Name\", \"Brand Name\", \"Quantity (in gms/kg/ml/ltr etc)\".<br>Please note that the prodcuts added to cart using the following fields will not bear any price (0/-). The price of these products will be given in the bill at the time of delivery.<br><br></span></div>";
    document.getElementById('CENTERDIV2').style.display = 'block';

    var ct = centerHead();

    var ni = document.getElementById('CENTERDIV2');
    
    var id, prod, price;

    id = document.getElementById('nfid').value;
    id++;
    document.getElementById('nfid').value = id;
    
    id = ' ' + id;
    prod = "nfprod_" + id;
    price = "0";

    var tmpRow = AppendRow('CTABLE', '-1');
    tmpRow.className = "style9";

    var tmpCell0 = AppendCell(tmpRow, '0');
    tmpCell0.innerHTML = "<span>&nbsp;</span>";

    var tmpCell1 = AppendCell(tmpRow, '1');
    tmpCell1.width    = "230";
    tmpCell1.innerHTML = "<span>Enter Product:<input type=\"text\" name=\"name_" + prod + "\" id=\"name_" + prod + "\" class=\"tf\"></span>";
    
    var tmpCell2 = AppendCell(tmpRow, '2');
    tmpCell2.innerHTML = "<span>&nbsp;" + price + "/-</span>";
    
    var tmpCell3 = AppendCell(tmpRow, '3');
    tmpCell3.innerHTML = "<span>&nbsp;<img src=\"minus.gif\" class=\"iadd\" onclick=\"decr(\'c_"+id+"\', \'d_"+id+"\', " + price + ")\" alt=\"Decrease Quantity\" /></span>";

    var tmpCell4 = AppendCell(tmpRow, '4');
    tmpCell4.innerHTML = "<span><input type=\"text\" size=\"1\" id=\"c_" + id + "\" maxlength=\"1\" class=\"tf1\" value=\"1\"/></span>";

    var tmpCell5 = AppendCell(tmpRow, '5');
    tmpCell5.innerHTML = "<span><img src=\"plus.gif\" class=\"iadd\" onclick=\"incr(\'c_"+id+"\', \'d_"+id+"\', " + price + ")\" alt=\"Increase Quantity\" /></span>";

    var tmpCell6 = AppendCell(tmpRow, '6');
    tmpCell6.innerHTML = "<span><img src=\"shcrt2.jpg\" width=\"25\" class=\"iadd\" onclick=\"nfAddCartEvent()\" alt=\"Add To Cart\" /></span>";
    
    var tmpCell7 = AppendCell(tmpRow, '7');
    tmpCell7.innerHTML = "<div id=\"d_"+id+"\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>";
    
};

function nfAddCartEvent()
{
    var msg, id, name;
    
    id  =  document.getElementById('nfid').value;
    msg =  "ID: " + id + ";";
    
    var name = document.getElementById('name_nfprod_ ' + id).value;
    
    if (name.search(/[a-zA-Z]+/) == -1)
    {
        alert('Please enter a valid product name');
        return false;
    }
    msg += "NAME: " + name + ";";
    
    msg += "PRICE: 0";
    var msg1 = "\'" + msg + "\'";
    
//    var qty = document.getElementById('c_' + id).value;

    var msgList1 = msg1.split(';');
    var id       = (msgList1[0].split(':'))[1];
    var prod     = (msgList1[1].split(':'))[1];
    var price    = (msgList1[2].split(':'))[1];
    
    var lotprice;

//alert('product being added to cart: ' + msg);
//alert('add cart event id***' + id + '***');

//    var prodEle  = document.getElementById('c_'+prod);
    var prodEle  = document.getElementById('c_'+id);
    var qty      = prodEle.value;

//    alert('nf prod being added: ' + msg1 + ' ----- qty: ' + qty);
    addCartEvent(msg);
    
    notFoundProdAdd(msg);
};


// Everytime a leaf node is selected we need to remove
// all existing elements of CENTERDIV2
function removeLeafEvents() {
  var cell = document.getElementById('CENTERDIV2');
  
  if ( cell.hasChildNodes() )
  {
      while ( cell.childNodes.length >= 1 )
      {
          cell.removeChild( cell.firstChild );
      } 
  }

};

// Add elements and their events that got added
// to the shopping cart
function addCartEvent(msg) {
  var ni = document.getElementById('RIGHTDIV2');

  var tval = 0;
  
  var numi = document.getElementById('theValue');
  var num = (document.getElementById("theValue").value -1)+ 2;
  numi.value = num;
  
  var divIdName = "my"+num+"Div";
  var newdiv = document.createElement('div');
  newdiv.setAttribute("id",divIdName);
  
//  newdiv.innerHTML = msg + "<input type=\"button\" class=\"btn\" onclick=\"removeCartEvent(\'"+divIdName+"\')\" //value=\"<<R\" />";

//  newdiv.innerHTML = msg + "<img src=\"trash.gif\" class=\"iadd\" onclick=\"removeCartEvent(\'"+divIdName+"\')\" alt=\"Remove From Cart\" />";
//  ni.appendChild(newdiv);

    var id, prod, price;

    var gtid    = document.getElementById('gt');
    var noiid   = document.getElementById('noi');
    
    var gtval   = gtid.value;
    var noival  = noiid.value;

    var msgList1 = msg.split(';');
    var id       = (msgList1[0].split(':'))[1];
    var prod     = (msgList1[1].split(':'))[1];
    var price    = (msgList1[2].split(':'))[1];
    
    var lotprice;

//alert('product being added to cart: ' + msg);
//alert('add cart event: c_' + id);
//alert('add cart event id2***' + id + '***');

//    var prodEle  = document.getElementById('c_'+prod);
    var prodEle  = document.getElementById('c_'+id);
    var qty      = prodEle.value;
//alert('qty of ' + id + ' is: ' + qty);
    
//alert('add cart event: r_' + id);

    var exists   = document.getElementById('r_'+id);
    
    //alert('the price is: ' + price);
    //alert('the qty is: ' + qty);
    
    gtid.value   = parseFloat(parseFloat(gtval) + parseFloat(price) * parseFloat(qty));
    noiid.value  = parseFloat(parseFloat(noival) + parseFloat(qty));
    
    var tcell1 = document.getElementById('cell_gt');
    tcell1.innerHTML = "<input type=\"hidden\" value=" + gtid.value + " name=\"gt\" id=\"gt\" />" +
                       "<span id=\"SPANPROD\">&nbsp; " + gtid.value + " &nbsp;</span>";

    var tcell2 = document.getElementById('cell_noi');
    tcell2.innerHTML = "<input type=\"hidden\" value=" + noiid.value + " name=\"noi\" id=\"noi\" />" +
                       "<span id=\"SPANPROD\">&nbsp; " + noiid.value + " &nbsp;</span>";

    if (exists)
    {
        var exval    = exists.value;
//        alert(prod + ' is already in cart. Value:' + exval);

        qty          = parseFloat(qty) + parseFloat(exval);
//        exists.value = qty;
        var cellexists   = document.getElementById('cell_r_'+id);
        
        var ecval = document.getElementById('cnt_'+id).value;
        
        cellexists.innerHTML = "<input type=\"hidden\" id=\"r_" + id + "\" value=" + qty + " /><input type=\"hidden\" id=\"cnt_" + id + "\" value=" + ecval + " /><span id=\"SPANPROD\">&nbsp;&nbsp;" + qty + "&nbsp;</span>";
        
        tval = parseFloat(price) * parseFloat(qty);
//        alert('ecval: ' + ecval + 'price is: ' + price + ' total prod qty: ' + qty + ' total prod price: ' + tval);

        var cellexists2  = document.getElementById('cell_cart_'+id);
        cellexists2.innerHTML = prod + "<input type=\"hidden\" name=\"cart_" + ecval + "\" id=\"cart_" + ecval + "\" value=\"" + id + " :: " + prod + " :: " + price + "/- :: " + qty + " :: " + tval + "\" />";
        
        return ;
    }

    var tmpRow = AppendRow('RTABLE', '1');
    tmpRow.className = "style10";
    var cartid = document.getElementById('cart');
    var cval   = cartid.value;

    cartid.value = parseInt(cval) + 1;
    
//    alert('cartid value: ' + cartid.value);
    
    tval = parseFloat(price) * parseFloat(qty);
    
//    var tqty = document.getElementById('pqty' + cval);
    
    var tmpCell100 = AppendCell(tmpRow, '0');
    tmpCell100.id = "cell_cart_"+id;
    tmpCell100.innerHTML = prod + "<input type=\"hidden\" name=\"cart_" + cval + "\" id=\"cart_" + cval + "\" value=\"" + id + " :: " + prod + " :: " + price + "/- :: " + qty + " :: " + tval + "\" />";

//alert(prod + ' is added at cval: ' + cval);

    var tmpCell101 = AppendCell(tmpRow, '1');
//    tmpCell101.innerHTML = "<input type=\"text\" size=\"2\" maxlength=\"2\" id=\"r_" + id + "\" value="+qty+" />";
    tmpCell101.id = "cell_r_"+id;
    tmpCell101.innerHTML = "<input type=\"hidden\" id=\"r_" + id + "\" value=" + qty + " /><input type=\"hidden\" id=\"cnt_" + id + "\" value=" + cval + " /><span id=\"SPANPROD\">&nbsp;&nbsp;" + qty + "&nbsp;</span>";

//alert(prod + ' is the qty');

//alert(prod + ' can be deleted');

//    var tmpCell102 = AppendCell(tmpRow, '2');
//    tmpCell102.innerHTML = "<img src=\"page.gif\" class=\"iadd\" alt=\"Edit\" />";

//    var tmpCell103 = AppendCell(tmpRow, '3');
    var tmpCell103 = AppendCell(tmpRow, '2');
    tmpCell103.innerHTML = "<img src=\"red_ball.gif\" class=\"iadd\" onclick=\"removeCartEvent(this, 'RTABLE', '" + id + "', " + price + ");\" alt=\"Delete\" />";
};


//function removeCartEvent(r, t)
function removeCartEvent(r, t, id, price)
{
    var gtid    = document.getElementById('gt');
    var noiid   = document.getElementById('noi');
    
    var gtval   = gtid.value;
    var noival  = noiid.value;

//    alert('id of element being removed: ' + id);

    var qtyid   = document.getElementById('r_'+id);
    var qty     = qtyid.value;

//    alert('qty of element being removed: ' + qty);
//    alert('price of element being removed: ' + price);
    
    gtid.value  = parseFloat(parseFloat(gtval) - parseFloat(qty) * parseFloat(price));
    noiid.value = parseFloat(parseFloat(noival) - parseFloat(qty));

    var tcell1 = document.getElementById('cell_gt');
    tcell1.innerHTML = "<input type=\"hidden\" value=" + gtid.value + " name=\"gt\" id=\"gt\" />" +
                       "<span id=\"SPANPROD\">&nbsp; " + gtid.value + " &nbsp;</span>";

    var tcell2 = document.getElementById('cell_noi');
    tcell2.innerHTML = "<input type=\"hidden\" value=" + noiid.value + " name=\"noi\" id=\"noi\" />" +
                       "<span id=\"SPANPROD\">&nbsp; " + noiid.value + " &nbsp;</span>";

    var i=r.parentNode.parentNode.rowIndex;
    document.getElementById(t).deleteRow(i);
};

// Remove shopping cart summary
function removeSummary() {
  var cell = document.getElementById('RIGHTDIV1');
  
  if ( cell.hasChildNodes() )
  {
      while ( cell.childNodes.length >= 1 )
      {
          cell.removeChild( cell.firstChild );
      } 
  }

};

// Remove shopping cart Table
function removeCart() {
  var cell = document.getElementById('RIGHTDIV2');
  
  if ( cell.hasChildNodes() )
  {
      while ( cell.childNodes.length >= 1 )
      {
          cell.removeChild( cell.firstChild );
      } 
  }

};

// Add shopping cart Table
function addCart() {
    CreateTable('245','395','RIGHTDIV2', 'RTABLE');
    var tmpRow = AppendRow('RTABLE', '0');

    var tmpCell = AppendCell(tmpRow, '0');
    tmpCell.align = "left";
    tmpCell.innerHTML = "<b>Shopping Cart Details:</b>";
};


// Remove shopping cart summary
function removeTree() {
  var cell = document.getElementById('LEFTDIV2');
  
  if ( cell.hasChildNodes() )
  {
      while ( cell.childNodes.length >= 1 )
      {
          cell.removeChild( cell.firstChild );
      } 
  }

};

// Remove all the elements that DIV tag hosts
function removeDivElements(d) {
  var cell = document.getElementById(d);
  
  if ( cell.hasChildNodes() )
  {
      while ( cell.childNodes.length >= 1 )
      {
          cell.removeChild( cell.firstChild );
      } 
  }

};

function OrderNow()
{
//    window.open('order.html', 'SARINAPPS ONLINE GROCERY ORDER DELIVERY DETAILS');
//    window.open('order.html', '', 'location=no,menubar=no,directories=no');
submit();
};

function otherPages(page, i)
{
    loadStoreDivs();

    var cd2 = document.getElementById('CENTERDIV2');
    var heading = '';
    
    if (i == 1)
    {
        return;
    }
    else if (i == 2)
    {
        return;
    }
    else if (i == 3)
    {
        heading = "My GreenyTails Shopping Orders";
    }
    else if (i == 4)
    {
        heading = "Please Fill The Following Form";
    }
    else if (i == 5)
    {
        heading = "How To Use GreenyTails?";
    }
    else if (i == 6)
    {
        heading = "<br><br>GreenyTails Key n Unique Features/Advantages";
    }
    else if (i == 8)
    {
        heading = "GreenyTails Frequently Asked Questions";
    }
    else if (i == 9)
    {
        heading = "Please Fill The Following Form";
    }
    else if (i == 10)
    {
        heading = "Fill Following Form To Create/Update Your Own Virtual Store";
    }
    else if (i == 11)
    {
        return;
    }
    else if (i == 21)
    {
        heading = "<br><br>Quick Grocery Shopping";
    }
    else if (i == 23)
    {
        heading = "<br><br>Free Home Delivery";
    }
    else if (i == 24)
    {
        heading = "<br><br>Let The Mouse Do It";
    }
    else if (i == 25)
    {
        heading = "<br><br>Avail Special Discounts";
    }
    else if (i == 26)
    {
        heading = "<br><br>Only Cash On Delivery";
    }
    else if (i == 31)
    {
        heading = "<br><br>GreenyTails News";
    }
    else if (i == 32)
    {
        heading = "<br><br>GreenyTails Testimonials";
    }
    else if (i == 33)
    {
        heading = "<br><br>All About A GreenLet";
    }
    else if (i == 34)
    {
        heading = "<br><br>About Us";
    }
    else if (i == 41)
    {
        heading = "<br><br>Log-In with GreenyTails account";
	cd2.innerHTML = "<iframe src=\"http://greenytails.rpxnow.com/openid/embed\?token_url=http\%3A\%2F\%2Fwww.greenytails.com\%2Fcgi-bin\%2Fogs\%2Frpx.cgi\" scrolling=\"no\" frameBorder=\"no\" allowtransparency=\"true\" style=\"width:400px;height:240px\"></iframe>";
	return;
    }
    else
    {}
    
    removeDivElements('CENTERDIV2');
    removeDivElements('CENTERDIV3');
    removeDivElements('CENTERDIV4');

    if (i != 2)
    {
        document.getElementById('CENTERDIV3').innerHTML = "<font size=\"4\" color=\"black\"><b>" + heading + "</b></font>";
    }
    
    if (page == null)
    {
        return;
    }
    
    cd2.innerHTML = "<iframe name=\"test\" src=\"" + page + ".html\" width=\"550\" align=\"center\" height=\"550\" scrolling=\"auto\" frameborder=\"0\"></iframe>";
};