/* JMS updated 9/28/06 added s_id to wish and compare basket location replacements */
/* MSR updated 8/09/07 changed href for continue shopping link from "product.asp" to "javascript:;" so it doesn't go to the home page (of s_id=0 on multistores ) on click */
/* MSR updated 10/16/07 Added ToggleSelects() function to handle multiple IE6 select fix divs, added call to ToggleSelects() in check_add_basket */

//floating basket code
var added_cart_msg;

function check_add_basket()
{

	var query = window.location.search.substring(1);

	if(query.indexOf('addto=4') != -1)
	{
	  //redirect to wish_basket
	  window.location.replace("wish_basket.asp?s_id="+s_id);
	}
	
	if(query.indexOf('addto=2') != -1)
	{
	  //redirect to basket_compare
	  window.location.replace("compare_basket.asp?s_id="+s_id);
	}
	
	if((query.indexOf('&addfrom=product&msg=added&')>0)&&(query.indexOf('addto=1')!= -1)&&(query.indexOf('&error=')<=0) && (shopping_basket.no_items > 0))
	{
		var cart_pop_fill = "";
		cart_pop_fill += "<div class=\"outermostpop\">";
		cart_pop_fill += "	<div class=\"outerpop\">";
		cart_pop_fill += "		<div class=\"innerbg\" align=\"center\">";
		cart_pop_fill += "			<div style=\"text-align: center;\">";
		cart_pop_fill += "				<img src=\"assets/product_images/" + shopping_basket.items[shopping_basket.items.length - 1].image + "\" border=\"0\" /><br>";
		//cart_pop_fill += "				<img src=\"assets/product_images/bobbyjones/thumbnails/" + pf_id + "_sm.jpg\" border=\"0\" /><br>";
		cart_pop_fill += "			</div>";
		cart_pop_fill += "			<p style=\"text-align: center; text-transform: uppercase; \"><b>" + shopping_basket.items[shopping_basket.items.length-1].name + "</b><br>has been added to your bag!<br></p>";
		cart_pop_fill += "			<div style=\"text-align: center;margin-bottom: 5px; height: 24px; padding-top: 11px;\">";
		cart_pop_fill += "				" + shopping_basket.no_items + " item(s) in cart - $" + OKStrOfPenny(shopping_basket.sub_total);
		cart_pop_fill += "			</div>";
		//cart_pop_fill += draw_pop_table();
		cart_pop_fill += draw_pop_buttons();
		cart_pop_fill += "		</div>";
		cart_pop_fill += "	</div>";
		cart_pop_fill += "</div>";
    	document.getElementById("cartpop").innerHTML = cart_pop_fill;
		// Hide selects for IE6
		ToggleSelects("Hide");
	}else{
		document.getElementById("cartpop").style.height = 0;
	}

} //end check_add_basket

function draw_pop_table()
{
  var cart_pop_tbl = "";
	if(shopping_basket.no_items > 0)
	{
		cart_pop_tbl += "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"inneredge\">";
		cart_pop_tbl += "<tr><td><table cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">";
		cart_pop_tbl += "<tr class=\"innerheader\"><td align=\"center\">Item</td>";
		cart_pop_tbl += "<td width=160>Name / Attributes</td>";
		cart_pop_tbl += "<td align=\"center\">Qty</td>";
		cart_pop_tbl += "<td align=\"center\">Price Each</td>";
		cart_pop_tbl += "<td align=\"center\">Total</td></TR>";
		for (atn=0;atn< shopping_basket.items.length ;atn++)
		{
			cart_pop_tbl += "<tr bgcolor=\"#FFFFFF\"><TD class=cart_list_item align=center>";
	    cart_pop_tbl += "<img border=0 width=50 alt=\"\" src=\"assets/product_images/" + shopping_basket.items[atn].image + "\">";
			cart_pop_tbl += " </TD> ";
			cart_pop_tbl += "<TD class=cart_list_item>";
      cart_pop_tbl += shopping_basket.items[atn].name;
			cart_pop_tbl += " <span class=\"cart_item_attr\">";
			var tempstr ="";

			if (shopping_basket.items[atn].attr_value1 !=""){ tempstr = shopping_basket.items[atn].attr_value1; }
			if (shopping_basket.items[atn].attr_value2 !=""){ tempstr += ", " + shopping_basket.items[atn].attr_value2; }
			if (shopping_basket.items[atn].attr_value3 !=""){ tempstr += ", " + shopping_basket.items[atn].attr_value3; }
			if (shopping_basket.items[atn].attr_value4 !=""){ tempstr += ", " + shopping_basket.items[atn].attr_value4; }
			if (shopping_basket.items[atn].attr_value5 !=""){ tempstr += ", " + shopping_basket.items[atn].attr_value5; }
      if (shopping_basket.items[atn].info_attr1 !=""){ tempstr += ", " + shopping_basket.items[atn].info_attr1; }
      if (shopping_basket.items[atn].info_attr2 !=""){ tempstr += ", " + shopping_basket.items[atn].info_attr2; }
      if (shopping_basket.items[atn].info_attr3 !=""){ tempstr += ", " + shopping_basket.items[atn].info_attr3; }
			cart_pop_tbl += tempstr;
			cart_pop_tbl += "</span></TD>";
			cart_pop_tbl += "<TD class=cart_list_item  ALIGN=CENTER>" + shopping_basket.items[atn].quantity + "</TD>";
			cart_pop_tbl += "<TD class=cart_list_item  ALIGN=CENTER> $" + OKStrOfPenny(shopping_basket.items[atn].item_price) +" </TD>";
			cart_pop_tbl += "<TD class=cart_list_item  ALIGN=CENTER> $" + OKStrOfPenny(shopping_basket.items[atn].item_total) +" </TD>";
      cart_pop_tbl += "</TR>";
		}

    cart_pop_tbl += "<tr class=\"tablebgcolor\"><td colspan=\"4\" align=\"right\"><span class=\"cart_list_total\">Sub-Total:</span></td><td ALIGN=CENTER><span class=\"cart_list_total\">";
		cart_pop_tbl += " $"+ OKStrOfPenny(shopping_basket.sub_total) +" </TD></TR>";
		cart_pop_tbl += "</TABLE></td></tr><tr><td height=\"2\" class=\"tablebgcolor\"></td></tr></table>";
	}
	return cart_pop_tbl;
}
function draw_pop_buttons()
{
	var cart_pop_btns = "";
	if(shopping_basket.no_items > 0)
	{
		//cart_pop_btns += "<TABLE width=100% BORDER=0 CELLPADDING=3 CELLSPACING=0><TR><td align=center>";
		cart_pop_btns += "<a href=\"javascript:;\" onClick=\"document.getElementById('cartpop').style.visibility = 'hidden'; ToggleSelects('Show'); return false;\"><img src=\"assets/images/bobbyjones/buttons/btn_continue_shopping.gif\" alt=\"Keep Shopping\" border=\"0\"></a><br><br>";
		cart_pop_btns += "<a href=\"basket.asp\" onClick=\"return(visitargs('basket.asp','','URL'));\"><img src=\"assets/images/bobbyjones/buttons/btnnext2.gif\" alt=\"Click to Checkout\" border=\"0\"></a>";
	    //cart_pop_btns += "</td></TR></TABLE>";
	}
	return cart_pop_btns;
}

function chk_qty()
{
  var qty_val = document.getElementById("qty").value;
  var sku_val = document.getElementById("sku").value;
  var bskt_val = 0;
  //check for existing qty in basket
  if (shopping_basket.items.length > 0)
  {
    for (h=0;h<shopping_basket.items.length;h++)
    {
      if (sku_val == shopping_basket.items[h].sku)
      {
        bskt_val = shopping_basket.items[h].quantity;
      }
    }
  }
  var des_total = Number(qty_val) + Number(bskt_val);
	var limit_num;
	var x;
  //this is only used if site is set to listen to inventory
  if (i_jscript_uu_invmode != "1")
  {
    //check to see if total desired is more than avail
    for (i=0;i<product_var.length;i++)
    {
      if (sku_val == product_var[i].sku)
      {
  		  //use number available in stock
  		  limit_num = Number(product_var[i].avail);
        if (des_total > limit_num)
        {
          var new_qty = limit_num - bskt_val;
          if (new_qty <= 0)
          {
            alert("Your desired quantity exceeds the quantity available for this product. No additional product has been added to your cart.");
            return false;
          }
          document.getElementById("qty").value = new_qty;
          alert("Your desired quantity is more than the quantity available for this product. It has been adjusted.");

        }
      }
    }
  }
  return true;
}

// Select tag fix for IE6 (adapted for multiple selects)
// If there is more than one element with the same ID ("ddDiv"), only the first will be hidden
// So we have to give each "fix" div a unique ID (ddDiv1, ddDiv2, etc.) and check for them here
function ToggleSelects(ToggleCommand)
{

	// If the default div exists (backward compatibility)...
	if(document.getElementById('ddDiv' + i)){
		
		// Hide it
		document.getElementById('ddDiv').style.visibility = "hidden";
	
	}

	// For each possible div...
	for(i = 0; i <= 1; i++){
		
		// If the element exists...
		if(document.getElementById('ddDiv' + i)){
			
			// If we're hiding it...
			if(ToggleCommand == "Hide"){
				
				// Hide it
				document.getElementById('ddDiv' + i).style.visibility = "hidden";
				
			// If we're showing it...
			} else if(ToggleCommand == "Show"){
				
				// Show it
				document.getElementById('ddDiv' + i).style.visibility = "visible";
				
			}
		}
	}
}