// Javascript functions to add an item to the cart, wishlist or favorites.

/**
* Show the add to cart
*
* @param object $ Our jQuery object
*/

function _add2cart($, nClipID, nStoreID) {

	$("#debug").hide();
	var box = $("<div/>");
	box.attr("id", "add_2_cart");
	box.addClass("jqmWindow");
	$("body").prepend(box);

	var close = function(h) {
		h.o.remove();
		h.w.hide();
	};


	//
	// Make our warning window poppable.
	//
	box.jqm({
		modal: true,
        ajax: add2cart_url + '?ClipID=' + nClipID + '&StoreID=' + nStoreID,
		onHide: close
		});

		box.jqmShow();

} // End of _add2cart()

function _add2wl($, nClipID, nStoreID) {
	
	$("#debug").hide();
	var box = $("<div/>");
	box.attr("id", "add2wl");
	box.addClass("jqmWindow");
	$("body").prepend(box);
	
	var close = function(h) {
		h.o.remove();
		h.w.hide();
	};


	//
	// Make our warning window poppable.
	//
	box.jqm({
		modal: false,
        ajax: add2wl_url + '?ClipID=' + nClipID + '&StoreID=' + nStoreID,
		onHide: close
		});

		box.jqmShow();

} // End of _add2wl()

function _add2fav($, sType, nItem) {

	$("#debug").hide();
	var box = $("<div/>");
	box.attr("id", "add2fav");
	box.addClass("jqmWindow");
	$("body").prepend(box);

	var close = function(h) {
		h.o.remove();
		h.w.hide();
	};


	//
	// Make our warning window poppable.
	//
	box.jqm({
		modal: false,
        ajax: add2fav_url + '?fvt=' + sType + '&itm=' + nItem,
		onHide: close
		});

		box.jqmShow();

} // End of _add2fav()

function add2wl(nClipID, nStoreID)
{
_add2wl(jQuery, nClipID, nStoreID);
// return false;
} // add2wl()

function add2fav(sType, nItem)
{
_add2fav(jQuery, sType, nItem);
} // add2fav()

function shouldAddClip(form, nClipID)
{
if (form.hdnCart.value.toString().length > 0)
  {
  arClip = form.hdnCart.value.toString().split(",");
  nFound = false;
  for (j = 0; j < arClip.length; j++)
    {
    if (nClipID == arClip[j])
      {
      nFound = true;
      }
    }
  }
else
  {
  nFound = false;
  }
return(!nFound);
} // shouldAddClip()

function add2cart(form, nClipID, nStoreID) {

_add2cart(jQuery, nClipID, nStoreID);

if (shouldAddClip(form, nClipID)) {

	  if (filename != "store.php" && filename != "storeclip.php") {
		  var nCount = new Number(document.getElementById("txtCartCount").innerHTML);
	  } else {
		  var nCount = new Number(document.getElementById("txtCartCount").value);
	  }
    
  var CartCount = nCount + 1;
  
  if (filename != "store.php" && filename != "storeclip.php") {

	  document.getElementById("txtCartCount").innerHTML=CartCount;
	  if (CartCount > 0) {
	  	document['shoppingbag'].src = "images/shopping_bag_full.png";
	  }
	  if (CartCount > 9) {
	  	document.getElementById("shoppingbag").className = "super_cart_size";
	  }
  } else {
		document.getElementById("txtCartCount").value = CartCount;
  }
  
  if (form.hdnCart.value.toString().length > 0)
    {
    form.hdnCart.value = form.hdnCart.value + "," + nClipID.toString();
    }
  else
    {
    form.hdnCart.value = nClipID.toString();
    }
  }
// return false;
} // add2cart()