/* Simplified Add to Cart script for links that don't appear within normal areas. */
/* Assumptions:                                 
   1. Applies to links only.
   2. Link must have a class of "a2c" for add to cart, or "pdet" for tracking links to product detail
   3. Link must have id attribute in this format: id="area_pid_mpid_xcoord_ycoord"
   4. Ship to me only.
   5. Quantity is always 1. 
   6. Single Add to Cart only.
   7. Non paginated products only, unless a predetermined object is passed
   8. jsdefaultaddress must be defined on page.
   9. Links with a class of "pdet" are handled as "more info" links for site tracking.
   
   Pages that link to this script are automatically scanned, and onclick handlers added.
   Link hrefs should point to product detail page.*/
   
   
  

if (document.getElementsByTagName)
 {
   
   function add2CartLX()
    {
      var idvals  = this.id.split('_')
      var area    = idvals[0];
          area    = area.replace(/~/g,'_')
      var pid     = idvals[1];
      var mpid    = idvals[2];
      var xcoord  = idvals[3];
      var ycoord  = idvals[4];
      var mode = 'addtocart';
      if (this.className == 'pdet'){mode = 'choose'}
      targetform = document.defaultaddtocartform ;
      if(window.location.pathname != '/')
      {
        if (window.location.pathname !="/index.cfm") 
          {
            targetform.action = window.location.href;
          }
        var pagename = window.location.pathname;
       } 
     else
       {
        var pagename = "index.cfm";
       }
       
      targetform.mode.value = mode
      targetform.targetproductidlist.value = pid  ;
      targetform.targetaddressidlist.value = jsdefaultaddress;
      targetform.targetquantitylist.value  = 1   ;
      if (window.pc_verityObj)
        {
          targetform.maxcol.value  = pc_verityObj.maxcol;
          targetform.pagenumber.value = pc_verityObj.pagenum;  
          targetform.targetformtype.value = pc_verityObj.targetformtype
        }
      else
        {          
          targetform.maxcol.value  = 1   ;          
          targetform.pagenumber.value = 1;  
        }
      targetform.targetusepointpaylist.value  = 0; 
      targetform.targetformarea.value = area;
      targetform.mpid.value = mpid;
      targetform.targetformpage.value = pagename;
      targetform.targetposx.value = xcoord;
      targetform.targetposy.value = ycoord; 
      
      //if (mode == 'choose') targetform.action = "/product_detail.cfm?pid=" + pid;
      if (mode == 'choose') targetform.action = decodeURI(this.href);
      
      
      
      
      
      else if (js_gotocartafteradd) targetform.action =  pc_siteLocation.cart;
      targetform.submit() ;
      return false
         
    }
   
   function setUpLinks(domNode)
    {
      if (!domNode) {domNode = document}
      
      var masterLinkNodeList = document.getElementsByTagName("A")
      for (lx = 0; lx < masterLinkNodeList.length; lx++)
        {
          if(masterLinkNodeList.item(lx).className.match(/a2c|pdet/)) 
            {
              masterLinkNodeList.item(lx).onclick = add2CartLX;
            }// end if          
        }//end for
    }//end, fn setUpLinks
  
  setUpLinks() 
   
 }//end, outer object check
 
 
 function paginationFormObj(formref,startname,endname,maxcol,targetformtype)
   {
     this.form = formref
     this.startVal = this.form.elements[startname].value;
     this.maxVal = this.form.elements[endname].value
     this.pagenum = Math.floor(this.startVal/this.maxVal) + 1
     this.maxcol = maxcol
     this.targetformtype = targetformtype
   }
