//floating basket code
var added_cart_msg = "The <b>" + product_name + "</b> has been added to your GolfGalaxy cart!<br>";

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");
	}
	
	if(query.indexOf('addto=2') != -1)
	{
	  //redirect to basket_compare
	  window.location.replace("compare_basket.asp");
	}
	
	
	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 += "<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" width=\"480\" class=\"outermostpop\"><tr><td align='center'><table cellpadding='0' width='100%' cellspacing='10' border='0' class=\"outerpop\"><tr><td>";
		cart_pop_fill +=added_cart_msg
		cart_pop_fill +="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" id=\"info_box_no_bottom\">";
		cart_pop_fill +="<tr><td class='info_box_title_nopad'>";
		
		cart_pop_fill += draw_pop_table();
		cart_pop_fill += "</td></tr></table>";
		
		cart_pop_fill += draw_pop_buttons();		
		cart_pop_fill += "</td></tr></table></td></tr></table>";
		
		
		document.getElementById("cartpop").innerHTML = cart_pop_fill;
		
	}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=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\" class='info_box_below_title'>";						
		cart_pop_tbl += "<tr>";
		cart_pop_tbl += "<td align=\"center\" class='info_box_table_heading'>Item</td>";
		cart_pop_tbl += "<td align=\"left\" class='info_box_table_heading'>Product Description</td>";
		cart_pop_tbl += "<td align=\"center\" class='info_box_table_heading'>Price</td>";
		cart_pop_tbl += "<td align=\"center\" class='info_box_table_heading'>Qty</td>";
		cart_pop_tbl += "<td align=\"center\" class='info_box_table_heading' style='border-right:0px none #FFFFFF;'>Total</td></TR>";
		for (atn=0;atn< shopping_basket.items.length ;atn++)
		{
			cart_pop_tbl += "<TR VALIGN=TOP><TD class=cart_list_item align=\"center\">";
			var pf_to_use = shopping_basket.items[atn].pf_id;
			if(shopping_basket.items[atn].image !="" && shopping_basket.items[atn].image.indexOf("t.jpg")==-1)
				pf_to_use = shopping_basket.items[atn].image;
			
			cart_pop_tbl += get_S7_image(pf_to_use, "s7thumb",shopping_basket.items[atn].name);
			cart_pop_tbl += " </TD> ";
			cart_pop_tbl += "<TD class=cart_list_item align=\"left\">";
      		cart_pop_tbl += shopping_basket.items[atn].name;
			cart_pop_tbl += " <span class=\"cart_item_attr\">";
			var tempstr ="";
      		//this removes the last attribute from view on the floating basket
      		var attr_limit = null;
			if (shopping_basket.items[atn].attr_value1 != "")
			{
				attr_limit = 1;
			}
			if (shopping_basket.items[atn].attr_value2 != "")
			{
				attr_limit = 2;
			}
			if (shopping_basket.items[atn].attr_value3 != "")
			{
				attr_limit = 3;
			}
			if (shopping_basket.items[atn].attr_value4 != "")
			{
				attr_limit = 4;
			}
			if (shopping_basket.items[atn].attr_value5 != "")
			{
				attr_limit = 5;
			}

			if (shopping_basket.items[atn].attr_value1 !=""){ tempstr = shopping_basket.items[atn].attr_value1; }
			if (shopping_basket.items[atn].attr_value2 !="" && attr_limit != 1){ tempstr += ", " + shopping_basket.items[atn].attr_value2; }
			if (shopping_basket.items[atn].attr_value3 !="" && attr_limit != 2){ tempstr += ", " + shopping_basket.items[atn].attr_value3; }
			if (shopping_basket.items[atn].attr_value4 !="" && attr_limit != 3){ tempstr += ", " + shopping_basket.items[atn].attr_value4; }
			if (shopping_basket.items[atn].attr_value5 !="" && attr_limit != 4){ 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\"> $" + OKStrOfPenny(shopping_basket.items[atn].item_price) +" </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\" style='border-right:0px none #FFFFFF;'> $" + OKStrOfPenny(shopping_basket.items[atn].item_total) +" </TD>";
      		cart_pop_tbl += "</TR>";
		}//end for

    	//subtotal
      	cart_pop_tbl += "<TR><TD COLSPAN='4' ALIGN='RIGHT'><span class='field_label'>Subtotal</span></TD><TD ALIGN='RIGHT' class='cart_price_total'>$"+ OKStrOfPenny(shopping_basket.sub_total) +"</TD></TR>";

		cart_pop_tbl += "</TABLE>";
	}
	return cart_pop_tbl;
}
function draw_pop_buttons()
{
	var cart_pop_btns = "";
	if(shopping_basket.no_items > 0)
	{
		cart_pop_btns +='<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>';
		cart_pop_btns +='<td valign="top" width="8" align="left"><img src="Assets/images/info_box/info_box_higher_bottom_left2.gif" /></td><td class="info_box_higher_bottom2" align="right">';
		
		cart_pop_btns += "<a href=\"product.asp\" onClick=\"document.getElementById('cartpop').style.visibility = 'hidden';return false;\"><img src=\"assets/images/continue_shopping.gif\" alt=\"click to return to the catalog\" border=\"0\"></a>";
		cart_pop_btns += "<a href=\"basket.asp\" onClick=\"return(visitargs('basket.asp','','URL'));\"><img src=\"assets/images/btnupdatebskt2.gif\" alt=\"click to update cart\" border=\"0\"></a>";
		cart_pop_btns += "<a href=\"basket.asp\" onClick=\"return(visitargs('basket.asp','','URL'));\"><img src=\"assets/images/btnnext2.gif\" alt=\"click to checkout\" border=\"0\"></a>";
    	
		cart_pop_btns += '</td><td valign="top" width="7" align="right"><img src="Assets/images/info_box/info_box_higher_bottom_right2.gif" /></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 regex;
	var limit_num;
	var result;
	var x;
	regex = new RegExp("[Ll]imit of (\\d+)");


  //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)
    {
      //check for quantity limiting
		  result = regex.exec(product_var[i].avail_msg);
  		if (result != null)
  		{
  			limit_num = result[1];
        if (des_total > limit_num)
        {
          var new_qty = limit_num - bskt_val;
          if (new_qty <= 0)
          {
            alert("Your desired quantity exceeds the quantity available or allowed 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 or allowed for this product. It has been adjusted.");

        }
  		}
    }
  }

  return true;
}