/******************** DOCUMENT SHOP LIST JAVASCRIPT LIBRARY *********************************/
/************ NOTES START *******************************************************************************************
* 
* Date: 09/05/07
* Purpose: Shop list JavaScript functions
* Instructions:
* Prerequisites: (note required versions on top of the page)
*   1.1.5  jseone/prototype/prototype.js
************* NOTES END *********************************************************************************************/
/* Ajax functions */
// Parameters: linkType, sequence, title
function ajaxShopListUpdateList(linkType, sequence, title, desc) {
  var url = '/ajax/com.eonegroup.eonecommerce.ajax.AJAXShopListUpdateList';
  var parms = "linkType=" + linkType + "&sequence=" + sequence + "&title=" + escape(title) + "&desc=" + escape(desc);
  var myAjax = new Ajax.Request( url, {postBody:parms} );
}
// Parameters: linkType, itemId, sequence, quantity
function ajaxShopListAddItem(itemId, linkType, sequence, quantity) {
  ajaxShopListAddItem(itemId, linkType, sequence, quantity, "");
}

// Parameters: linkType, itemId, sequence, quantity
function ajaxShopListAddItem(itemId, linkType, sequence, quantity, listName) {
  if (!quantity || quantity.length==0) {
    quantity=1;
  }
  var url = '/ajax/com.eonegroup.eonecommerce.ajax.AJAXShopListAddItem';
  var parms = "linkType=" + linkType + "&itemId=" + escape(itemId) + "&itemseq=" + sequence + "&sequence=" + sequence + "&quantity=" + quantity + "&listName=" + escape(listName);
  var myAjax = new Ajax.Request( url, { postBody:parms, onComplete: ajaxShopListAddItemResponse });
}
function getContextPath() {
  var path="";
  var index = location.pathname.lastIndexOf('/')+1;
  if (index<=0) {
    index = location.pathname.length-1;
  }
  if (location.pathname.lastIndexOf('/')==0) {
    path = location.pathname.substring(1,index);
  } else {
    path = location.pathname.substring(0,index);
  }
  return path;
}

/* Ajax Response */
function ajaxShopListAddItemResponse(req) {
  var success = req.responseXML.getElementsByTagName('success').item(0).firstChild.nodeValue;
  var linkType = req.responseXML.getElementsByTagName('linkType').item(0).firstChild.nodeValue;
  var itemId = req.responseXML.getElementsByTagName('itemId').item(0).firstChild.nodeValue;
  if (success=='true') {
    $('list_response_' + linkType + "_" + itemId).innerHTML='This item has been added to your wishlist';
    //$('list_response_' + linkType + "_" + itemId).innerHTML=' <img src="/images/content/check_clear.gif" border="0"/>';
  } else {
    // $('list_response_' + linkType).innerHTML=' (item not added)';
  }
}