﻿// JScript File

var Rank = -1;
var MaxRank = -1;

function RestrictShipPopup(link)
{
    window.open(link,null, 'height=300, width=500, status=yes, toolbar=no, menubar=no, location=no, scrollbars=yes'); void('');
}

function Toggle(node)
{
    var divArray = node.getElementsByTagName("img");

    switch (node.id)
    {
        case "proddesc":
        element = document.getElementById('divproddesc').style;
        break;

        case "specification":
        element = document.getElementById('divspecification').style;
        break;

        case "resources":
        element = document.getElementById('divresources').style;
        break;

        case "manufacturerinfo":
        element = document.getElementById('divmanufacturerinfo').style;
        break;

        case "similaritems":
        element = document.getElementById('divsimilaritems').style;
        break;

        case "customerdiscussion":
        element = document.getElementById('divcustomerdiscussion').style;
        break;
        
        case "engravingitems":
        element = document.getElementById('divengravingitems').style;
        break;
    }

    if (element.display == "block")
    {
        element.display = "none";
        divArray[0].src = "Images/expand.jpg";
        divArray[0].alt = "Expand";
    }
    else
    {
        element.display = "block";
        divArray[0].src = "Images/collapse.jpg";
        divArray[0].alt = "Collapse";
    }
}

function ToggleCheck(node)
{
   if(node.value == 0)
   {
      node.checked = true;
      node.value = 1;
   }
   else if(node.value == 1)
   {
      node.checked = false;
      node.value = 0;
   }
      
}

function ToggleCustDiscussionDesc(node)
{
    elementshort = document.getElementById('divdescshort' + node.id).style;
    elementfull = document.getElementById('divdescfull' + node.id).style;
    if (elementfull.display == "block")
    {
        elementfull.display = "none"
        elementshort.display = "block"
        node.alt = "Expand";
        
    }
    else
    {
        elementfull.display = "block"
        elementshort.display = "none"
        node.alt = "Collapse";
    }

}

function ValidateQty(node, position, cartlimit, minqty) 
{
    if (node.value == '') return;
    if (node.value < minqty) 
    {
        if (position == 0)
            document.getElementById('divQtyMin').style.display = 'block';
        else
            document.getElementById('gcdivminqty' + position).style.display = 'block';
    }
    else if (node.value > cartlimit && cartlimit != -1) 
    {
        if (position == 0)
            document.getElementById('divCartLimit').style.display = 'block';
        else
            document.getElementById('gcdivcartlimit' + position).style.display = 'block';
    }
    else
    {
        if (position == 0) {
            document.getElementById('divQtyMin').style.display = 'none';
            document.getElementById('divCartLimit').style.display = 'none';
        }
        else {
            document.getElementById('gcdivcartlimit' + position).style.display = 'none';
            document.getElementById('gcdivminqty' + position).style.display = 'none';
        }
    }
}

function Popup(node)
{
    if(node.id.substring(0,1) == 'T')
    {
        var id = 'DT' + node.id.substring(1);
        ToolTip_Show(node, document.getElementById(id).innerHTML, '');
    }
    else if(node.id.substring(0,1) == 'R')
    {
        var id = 'DR' + node.id.substring(1);
        ToolTip_Show(node, document.getElementById(id).innerHTML, '');
    }
}


function ToolTip_Show(zxcobj,zxcdesc,zxcimg)
{
    intIndexOfMatch = 0;
    var zxctxt;
    
    if(zxcdesc != '' || zxcimg != '')
    {
        while (intIndexOfMatch != -1)
        {
            // Relace out the current instance.
            zxcdesc = zxcdesc.replace("¿", "'");
            // Get the index of any next matching substring.
            intIndexOfMatch = zxcdesc.indexOf( "¿" );
        }
        
       if(zxcimg == '')
         zxctxt = "<table><tr><td>" + zxcdesc + "</td></tr></table>";
       else
        zxctxt = "<table><tr valign='top'><td><img alt='' src='" + zxcimg + "'/>" + "</td><td>" + zxcdesc + "</td></tr></table>";
        
        zxcobj.tt=new zxcOOPToolTip(zxcobj,zxctxt);
        clearTimeout(zxcobj.tt.to);
        zxcobj.tt.setTimeOut('show()',0); 
    }
}

function zxcOOPToolTip(zxcobj,zxctxt)
{
    var tooltip = document.getElementById('divtooltip'); 
    tooltip.innerHTML = "<div style='text-align:right;'><img src='Images/close.gif' alt='' onclick='Tooltip_Hide()' /></div>" +   zxctxt;
    var leftPos = (Tooltip_getLeftPos(zxcobj) + zxcobj.offsetWidth);
    var topPos = Tooltip_getTopPos(zxcobj);
    tooltip.style.left = leftPos + 'px';
    tooltip.style.top = topPos + 'px';
    
    this.tt = tooltip;
    this.ref='zxcooptt';
    window[this.ref]=this;
    this.to=null;
}


zxcOOPToolTip.prototype.show=function()
{
    //zxcStyle(this.tt,{visibility:'visible'});
    this.tt.style.display = 'block';
}

zxcOOPToolTip.prototype.hide=function()
{
    //zxcStyle(this.tt,{visibility:'hidden'});
    this.tt.style.display = 'none';
}

zxcOOPToolTip.prototype.setTimeOut=function(zxcf,zxcd)
{
    this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}

function Tooltip_getTopPos(node)
{		
  var returnValue = node.offsetTop;
  while((node = node.offsetParent) != null)
  {
  	if(node.tagName!='HTML')returnValue += node.offsetTop;
  }
  return returnValue;
}

function Tooltip_getLeftPos(node)
{
  var returnValue = node.offsetLeft;
  while((node = node.offsetParent) != null)
  {
  	if(node.tagName!='HTML')returnValue += node.offsetLeft;
  }
  return returnValue;
}

function Tooltip_Hide()
{
    if(document.getElementById('divtooltip') != null)
    {
       document.getElementById('divtooltip').style.display = 'none';
    }
}


function CustDiscussionOnClick(itemno, pgindex)
{
    MC.ENET.ItemService.GetCustDiscussion(itemno, pgindex, OnCustDiscussionSucceeded, OnCustDiscussionFailed); 
    return false;  	
}

function OnCustDiscussionFailed()
{
}
function OnCustDiscussionSucceeded(result)
{
   ele = document.getElementById('divcustomerdiscussion');
   ele.innerHTML = result;
}

function DropDownListCompSelected(parentitemno, node, sourcecode)
{
   var pricedisplay = false;
   var pricematchid = 0;
   
   var value = node.options[node.selectedIndex].value;
   var title = node.options[node.selectedIndex].title; 
   var index = title.indexOf('¿', 0);

   if(index >= 0)
   {
       pricedisplay = title.substring(0,index);
       pricematchid = title.substring(index + 1);
   }
   
     
    for (row = document.getElementById("tblListComp").rows[0]; row != null; row = row.nextSibling)
    {
        if (row.nodeType == 1)
        {
             for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
             {
                if (cell.nodeType == 1)
                {
                   for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                   {
                        if(ctl.name == 'crdcomp')
                        {
                           if(ctl.value == value)
                           {
                              ctl.checked = true;
                              break;
                           }
                        }
                   }
                   
                }
             }
        }
    }
    ListCompSelectionChange(parentitemno, value, sourcecode, pricedisplay, pricematchid);
    
}

function RadioListCompSelected(parentitemno, node, sourcecode, pricedisplay, pricematchid)
{
    var value = node.value;
    
    var ddvalues = document.getElementById("ddlistcomp").options;
    for(i = 0; i < ddvalues.length; i++)
    {
      if(ddvalues[i].value == value)
      {
         ddvalues[i].selected = true;
      }
    }
    
    ListCompSelectionChange(parentitemno, value, sourcecode, pricedisplay, pricematchid);

}

function ListCompSelectionChange(parentitemno, selectedcompitemno, sourcecode, pricedisplay, pricematchid)
{
    MC.ENET.ItemService.GetSelectedListComp(parentitemno, selectedcompitemno, sourcecode, pricedisplay, pricematchid, OnListCompSelectionChangeSucceeded, OnListCompSelectionChangeFailed); 
    return false;  	
}

function OnListCompSelectionChangeFailed()
{
}
function OnListCompSelectionChangeSucceeded(result)
{
    if(result != null)
    {
        for (row = document.getElementById("tblitem").rows[0]; row != null; row = row.nextSibling)
        {
            if (row.nodeType == 1)
            {
                 for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                 {
                    if (cell.nodeType == 1)
                    {
                       for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                       {
                           if(ctl.id != null && ctl.id != '')
                           {
                               if(ctl.id.indexOf("segshortdesc", 0) != -1)
                                  ctl.innerHTML = result[0];
                                  
                               if(ctl.id.indexOf("segresourcepromo", 0) != -1)
                               {
                                  if(result[1] != null && result[1] != '')
                                  {
                                    ctl.innerHTML = result[1];
                                    ctl.style.display = "block";
                                  }
                                  else
                                    ctl.style.display = "none";
                               }
                                  
                               if(ctl.id.indexOf("segimage", 0) != -1)
                                  ctl.innerHTML = result[2];
                                  
                               if(ctl.id.indexOf("segranking", 0) != -1)
                                  ctl.innerHTML = result[3];

                               if(ctl.id.indexOf("segresources", 0) != -1)
                               {
                                  if(result[4] != null && result[4] != '')
                                  {
                                    ctl.innerHTML = result[4];
                                    ctl.style.display = "block";
                                  }
                                  else
                                    ctl.style.display = "none";
                               }

                               if(ctl.id.indexOf("segmanfinfo", 0) != -1)
                               {
                                  if(result[5] != null && result[5] != '')
                                  {
                                    ctl.innerHTML = result[5];
                                    ctl.style.display = "block";
                                  }
                                  else
                                    ctl.style.display = "none";
                               }
                                  
                               if(ctl.id.indexOf("segqty", 0) != -1)
                                  ctl.innerHTML = result[6];

                               if(ctl.id.indexOf("segcustomization", 0) != -1)
                               {
                                  if(result[7] != null && result[7] != '')
                                  {
                                    ctl.innerHTML = result[7];
                                    ctl.style.display = "block";
                                  }
                                  else
                                   ctl.style.display = "none";
                               }
                               
                           }
                       }
                       
                    }
                 }
            }
        }
    }
}


function VKitSelectionChange(parentitemno, pricedisplay, pricematchid, sourcecode) 
{
    var vkitcompItemNos = '';

    for (row = document.getElementById("tbQty").rows[0]; row != null; row = row.nextSibling)
    {
        if (row.nodeType == 1)
        {
             for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
             {
                if (cell.nodeType == 1)
                {
                   for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                   {
                        if(ctl.name == 'ddvkitcomp')
                        {
                           vkitcompItemNos += '¿' + ctl.options[ctl.selectedIndex].value;
                        }
                   }
                   
                }
             }
        }
    }
    
    if(vkitcompItemNos != '')
    {
        MC.ENET.ItemService.GetVKitCompPriceandAvail(parentitemno, vkitcompItemNos, pricedisplay, pricematchid, sourcecode, OnVKitSelectionChangeSucceeded, OnVKitSelectionChangeFailed); 
        return false;  	

    }
}

function OnVKitSelectionChangeFailed()
{
}
function OnVKitSelectionChangeSucceeded(result)
{
    for (row = document.getElementById("tblitem").rows[0]; row != null; row = row.nextSibling)
    {
        if (row.nodeType == 1)
        {
             for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
             {
                if (cell.nodeType == 1)
                {
                   for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                   {
                       if(ctl.id != null && ctl.id != '')
                       {
                           if(ctl.id.indexOf("segprice", 0) != -1)
                           {
                              ctl.innerHTML = result;
                              setPostBackPrice();
                           }
                           
                       }
                   }
                   
                }
             }
        }
    }

}

function StyleSelectionChange(parentitemno, pricedisplayandpricematchid, sourcecode, errmsg) 
{
    var selectedpropvals = '';
    var selectedpropText = '';
    
    for (row = document.getElementById("tbQty").rows[0]; row != null; row = row.nextSibling)
    {
        if (row.nodeType == 1)
        {
             for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
             {
                if (cell.nodeType == 1)
                {
                   for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                   {
                        if(ctl.name == 'ddstyles')
                        {
                           selectedpropvals += '¿' + ctl.options[ctl.selectedIndex].value;
                           selectedpropText += ' ' + ctl.options[ctl.selectedIndex].title;
                        }
                   }
                   
                }
             }
        }
    }
    
    if(selectedpropvals != '')
    {
        MC.ENET.ItemService.GetSelectedStyleComp(parentitemno, selectedpropvals, selectedpropText, pricedisplayandpricematchid, sourcecode, errmsg, OnStyleSelectionChangeSucceeded, OnStyleSelectionChangeFailed); 
        return false;  	

    }
}

function OnStyleSelectionChangeFailed()
{
}
function OnStyleSelectionChangeSucceeded(result)
{
    if(result.length == 1)
    {
       var err = document.getElementById("segstyleerr");
       err.innerHTML = result[0];
       err.style.display = "block";
       err.style.background = 'ivory';
       err.style.color = 'red';
       
    }
    else
    {
       var err = document.getElementById("segstyleerr");
       err.style.display = "none";

        for (row = document.getElementById("tblitem").rows[0]; row != null; row = row.nextSibling)
        {
            if (row.nodeType == 1)
            {
                 for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                 {
                    if (cell.nodeType == 1)
                    {
                       for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                       {
                           if(ctl.id != null && ctl.id != '')
                           {
                               if(ctl.id.indexOf("segshortdesc", 0) != -1)
                                  ctl.innerHTML = result[0];
                                  
                               if(ctl.id.indexOf("segimage", 0) != -1)
                                  ctl.innerHTML = result[1];
                                  
                               if(ctl.id.indexOf("segranking", 0) != -1)
                                  ctl.innerHTML = result[2];

                               if(ctl.id.indexOf("segprice", 0) != -1)
                               {
                                  ctl.innerHTML = result[3];
                                  setPostBackPrice();
                               }   

                               if(ctl.id.indexOf("segqty", 0) != -1)
                                  ctl.innerHTML = result[4];
                                  
                               if(ctl.id.indexOf("segcustomization", 0) != -1)
                               {
                                  if(result[5] != null && result[5] != '')
                                  {
                                    ctl.innerHTML = result[5];
                                    ctl.style.display = "block";
                                  }
                                  else
                                   ctl.style.display = "none";
                               }
                           }
                       }
                       
                    }
                 }
            }
        }
    }

}

function EngSelectionChange(retailprice) 
{
    var engWebPrice = 0.0;

    for (row = document.getElementById("tbEngraving").rows[0]; row != null; row = row.nextSibling)
    {
        if (row.nodeType == 1)
        {
             for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
             {
                if (cell.nodeType == 1)
                {
                   for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                   {
                        if(ctl.name == 'ddengvkitcomp')
                        {
                           engWebPrice += ctl.options[ctl.selectedIndex].title;
                        }
                   }
                   
                }
             }
        }
    }
    
    MC.ENET.ItemService.EngItemPriceFormat(engWebPrice, OnEngPriceFormatSucceeded, OnEngPriceFormatFailed); 
    return false;  	
    
}

function OnEngPriceFormatFailed()
{
}
function OnEngPriceFormatSucceeded(result)
{
    var element = document.getElementById("divengprice");
    element.innerHTML = "<label class='ourprice4'>" + result + "</label>"
}


function AddToButtonClick(itemtype, id, itmno, minqty)
{
    var row;
    var cell;
    var ctl; 
    var itemno = '';
    var qty = '';
    var addtoorderitems = '';
    var webprice = 0;
    var surchrg = 0;
    var stock = false;
    var priceOvrdFlag = 0;
    var priceOvrdAmt = 0;
    var priceMatchId = 0;
    var customization = '';
    var vkitcompItemNos = '';
    var engitemno = '';
    var engqty = 1;
    var engitemtype = 1;
    var engcustomization = '';
    var engvkits = '';
    var checked = false;
    var MultiArray = new Array();
    var selected = false;
    var reg = new RegExp("[1-9]");

    
    if(id == "CART" || id == "WISHLIST")
    {
        itemno = document.getElementById("itemno").title;
        qty = document.getElementById("txtQuantity").value;
    }
    if(id == "EKITCART")
    {
       itemno = itmno
       qty = minqty;
    }
    
 //get Recommended ItemNos if checked to add to cart
  
  if(id == "CART" || id == "GRIDCART" || id == "EKITCART")  
  {

      if(document.getElementById("tblRecItems") != null)
      {
            for (row = document.getElementById("tblRecItems").rows[0]; row != null; row = row.nextSibling)
            {
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.name == 'ckaddrectoorder')
                                {
                                    if(ctl.value == 1)
                                    {
                                        addtoorderitems += '¿' + ctl.id;
                                    }
                                }
                           }
                           
                        }
                     }
                }
            }
      }
       
        
       //get TopSelling ItemNos if checked to add to cart
        
      if(document.getElementById("tblTopSelling") != null)
      {
            for (row = document.getElementById("tblTopSelling").rows[0]; row != null; row = row.nextSibling)
            {
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.name == 'ckaddtoptoorder')
                                {
                                    if(ctl.value == 1)
                                    {
                                        addtoorderitems += '¿' + ctl.id;
                                    }
                                }
                           }
                           
                        }
                     }
                }
            }
        }
      
      
      
  }
  
  
  if(id == "CART" || id == "WISHLIST")
  {
      //get price for list items with multiple comps

      if(document.getElementById("tblListComp") != null)
      {
          
          for (row = document.getElementById("tblListComp").rows[0]; row != null; row = row.nextSibling)
          {
                
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.name == 'crdcomp')
                                {
                                   if(ctl.checked == true)
                                      selected = true;
                                }
                                if(ctl.id != null && ctl.id != '')
                                {
                                    if(ctl.id.indexOf("cwebprice", 0) != -1)
                                    {
                                       if(selected == true)
                                         webprice = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("cexclvatprice", 0) != -1) 
                                    {
                                        if (selected == true)
                                            webprice = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("csurchrg", 0) != -1) 
                                    {
                                        if (selected == true)
                                            surchrg = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("cexclvatsurchrg", 0) != -1) 
                                    {
                                        if (selected == true)
                                            surchrg = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("cpriceoverride", 0) != -1)
                                    {
                                       if(selected == true)
                                       {
                                          priceOvrdFlag = 1;
                                          priceOvrdAmt = ctl.value.trim();
                                          if (!reg.test(priceOvrdAmt)) 
                                          {
                                              ctl.style.color = "red";
                                              ctl.focus();
                                              return;
                                          }
                                       }                            
                                    }
                                    if(ctl.id.indexOf("cpricematch", 0) != -1)
                                    {
                                       if(selected == true)
                                       {
                                           priceOvrdFlag = 2;
                                           priceOvrdAmt = (ctl.innerText || ctl.textContent).trim();
                                       }
                                    }
                                }
                                    
                                if(ctl.name == 'cpricematchid')
                                {
                                   if(selected == true)
                                   {
                                       priceMatchId = ctl.value;
                                   } 
                                }
                            
                                if(ctl.name == 'cavail')
                                {
                                   if(selected == true)
                                   {
                                      stock = ctl.value;
                                      selected = false;
                                   }                            
                                }
                           }
                           
                        }
                     }
                }
          }
      }
     
      // get price for non list items and list item with 1 comp
      else
      {
            for (row = document.getElementById("tbprice").rows[0]; row != null; row = row.nextSibling)
            {
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.id == 'webprice')
                                {
                                   webprice = (ctl.innerText || ctl.textContent).trim();
                                }
                                if (ctl.id == 'exclvatprice') 
                                {
                                    webprice = (ctl.innerText || ctl.textContent).trim();
                                }
                                if (ctl.id == 'surchrg') 
                                {
                                    surchrg = (ctl.innerText || ctl.textContent).trim();
                                }
                                if (ctl.id == 'exclvatsurchrg') 
                                {
                                    surchrg = (ctl.innerText || ctl.textContent).trim();
                                }
                                if (ctl.id == 'avail')
                                {
                                   stock = ctl.value;
                                }
                                if(ctl.id == 'priceoverride')
                                {
                                   priceOvrdFlag = 1;
                                   priceOvrdAmt = ctl.value.trim();
                                   if (!reg.test(priceOvrdAmt))
                                   {
                                        ctl.style.color = "red";
                                        ctl.focus();
                                        return;
                                   }
                                   
                                }
                                if(ctl.id == 'pricematch')
                                {
                                   priceOvrdFlag = 2;
                                   priceOvrdAmt = (ctl.innerText || ctl.textContent).trim();
                                }
                                if(ctl.id == 'pricematchid')
                                {
                                   priceMatchId = ctl.value;
                                }
                                
                           }
                           
                        }
                     }
                }
            }
     }
     
 }

 if (id == "CART") 
 {

      // capture customization

      if (document.getElementById("tblCust") != null) {
          for (row = document.getElementById("tblCust").rows[0]; row != null; row = row.nextSibling) {
              if (row.nodeType == 1) {
                  for (cell = row.firstChild; cell != null; cell = cell.nextSibling) {
                      if (cell.nodeType == 1) {
                          for (ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling) {
                              if (ctl.name == 'txtCustParam') {
                                  customization += '¿' + ctl.value;
                              }
                          }

                      }
                  }
              }
          }
      }

      //capture variablekit  

      if (document.getElementById("tbQty") != null) {
          for (row = document.getElementById("tbQty").rows[0]; row != null; row = row.nextSibling) {
              if (row.nodeType == 1) {
                  for (cell = row.firstChild; cell != null; cell = cell.nextSibling) {
                      if (cell.nodeType == 1) {
                          for (ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling) {
                              if (ctl.name == 'ddvkitcomp') {
                                  vkitcompItemNos += '¿' + ctl.options[ctl.selectedIndex].value;
                              }
                          }

                      }
                  }
              }
          }
      }

      //capture Engraving
      if(document.getElementById("tbEngraving") != null)
      {
            for (row = document.getElementById("tbEngraving").rows[0]; row != null; row = row.nextSibling)
            {
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.id == 'ckengraving')
                                {
                                   if(ctl.value == 1)
                                      checked = true;
                                }
                                if(ctl.id == 'eitemno')
                                {
                                   if(checked == true)
                                    engitemno = ctl.value;
                                }
                                if(ctl.id == 'eitemtype')
                                {
                                   if(checked == true)
                                    engitemtype = ctl.value;
                                }
                                if(ctl.name == 'txtCustParam')
                                {
                                   if(checked == true)
                                     engcustomization += '¿' + ctl.value;
                                }
                                if(ctl.name == 'ddengvkitcomp')
                                {
                                   if(checked == true)
                                      engvkits += '¿' + ctl.options[ctl.selectedIndex].value;
                                }
                           }
                           
                        }
                     }
                }
            }
     } 
} 

  if(id == "GRIDCART" || id == "GRIDWISHLIST")  
  {
      var i = 0; 

      if(document.getElementById("tbgridcomp") != null)
      {
            for (row = document.getElementById("tbgridcomp").rows[0]; row != null; row = row.nextSibling)
            {
                if (row.nodeType == 1)
                {
                     for (cell = row.firstChild; cell != null; cell = cell.nextSibling)
                     {
                        if (cell.nodeType == 1)
                        {
                           for(ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling)
                           {
                                if(ctl.id != null && ctl.id != '')
                                {
                                    if(ctl.id.indexOf("gcitemno", 0) != -1)
                                    {
                                       itemno = ctl.title;
                                    }
                                    if(ctl.id.indexOf("gcpricematch", 0) != -1)
                                    {
                                       priceOvrdFlag = 2;
                                       priceOvrdAmt = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if(ctl.id.indexOf("gcpriceoverride", 0) != -1)
                                    {
                                       priceOvrdFlag = 1;
                                       priceOvrdAmt = ctl.value.trim();
                                       if (!reg.test(priceOvrdAmt)) 
                                       {
                                           ctl.style.color = "red";
                                           ctl.focus();
                                           return;
                                       }
                                       
                                    }
                                    if(ctl.id.indexOf("gcwebprice", 0) != -1)
                                    {
                                       webprice = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("gcexclvatprice", 0) != -1) 
                                    {
                                        webprice = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("gcsurchrg", 0) != -1)
                                    {
                                        surchrg = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("gcexclvatsurchrg", 0) != -1) 
                                    {
                                        surchrg = (ctl.innerText || ctl.textContent).trim();
                                    }
                                    if (ctl.id.indexOf("gctxtQuantity", 0) != -1) 
                                    {
                                        qty = ctl.value;
                                        if (qty > 0) 
                                        {
                                            MultiArray[i] = new Array(9);
                                            MultiArray[i][0] = itemno;
                                            MultiArray[i][1] = itemtype;
                                            MultiArray[i][2] = qty;
                                            MultiArray[i][3] = priceOvrdFlag;
                                            MultiArray[i][4] = priceOvrdAmt;
                                            MultiArray[i][5] = priceMatchId;
                                            MultiArray[i][6] = webprice;
                                            MultiArray[i][7] = stock;
                                            MultiArray[i][8] = surchrg;
                                            i++;
                                        }
                                    }
                                    
                                }
                                if(ctl.name == 'gcitemtype')
                                {
                                   itemtype = ctl.value;
                                }
                                if(ctl.name == 'gcpricematchid')
                                {
                                   priceMatchId = ctl.value;
                                }
                                if(ctl.name == 'gcavail')
                                {
                                   stock = ctl.value;
                                }
                           }
                           
                        }
                     }
                }
            }
     }

  }
  
 if(id == "CART" || id == "EKITCART")
 {
     MC.ENET.ItemService.AddItemToCart(itemno, itemtype, qty, addtoorderitems, priceOvrdFlag, priceMatchId, priceOvrdAmt, customization, vkitcompItemNos, engitemno, engqty, engitemtype, engcustomization, engvkits, OnAddToCartSucceeded, OnAddToCartFailed); 
 }
 else if(id == "GRIDCART")
 {
     MC.ENET.ItemService.AddItemsToCart(MultiArray, addtoorderitems, OnAddToCartSucceeded, OnAddToCartFailed); 
 }
 else if(id == "WISHLIST")
 {
     MC.ENET.ItemService.AddItemToWishList(itemno, itemtype, qty, webprice, surchrg, stock, priceOvrdAmt, OnAddToWishListSucceeded, OnAddToWishListFailed); 
 }
 else if(id == "GRIDWISHLIST")
 {
    MC.ENET.ItemService.AddItemsToWishList(MultiArray, OnAddToWishListSucceeded, OnAddToWishListFailed); 
 }
 return false;  	

}

function OnAddToCartFailed()
{
}
function OnAddToCartSucceeded(result)
{
    
    if (result!=null || result.length>0)
    {
         window.location.href = "CartPage" + result;
    }
    else
         window.location.href = "CartPage.aspx";
}

function OnAddToWishListFailed()
{
}
function OnAddToWishListSucceeded(result)
{
   window.location.href = "Members/WishListUpdate.aspx" ;
}


function ToggleRateIt(node)
{
   var val = node.options[node.selectedIndex].value;
   Rank = val;
   MaxRank = node.length - 1;
   var div = document.getElementById('divcustrating');
   var i ;
   
   if(div != null)
   {
       for (i = 0; i < div.childNodes.length; i++) 
       {
           var child = div.childNodes.item(i);
           if (child.nodeName == "IMG")
           {
                if (val == -1) 
                    child.style.visibility = "hidden";
                else  
                    child.style.visibility = "visible";
                    
                break;
           }
       }
    }
       
}

function RateItOnClick(itemno)
{
    MC.ENET.ItemService.InsertItemOverallRanking(itemno, Rank, MaxRank, OnRateItSucceeded, OnRateItFailed); 
    return false;  	
}
function OnRateItFailed()
{
}
function OnRateItSucceeded(result)
{
   window.location.href = result ;
}
