function OnAddToBasket(form, ID, select, quantity)
{
  var itemLink, ok;
  
  ok = true;
  
  var qs = new Querystring(form.action);
  
  if(select.type == 'select-one')
  {
    if(select.selectedIndex == 0)
    {
      alert('You must select a size!');
      select.focus();
      ok = false;
    }
    else
    {
      ok = true;
      ItemLink = '&ItemLink=' + select.options[select.selectedIndex].value;
    }
  }
  else
  {
    ok = true;
    ItemLink = '&ItemLink=' + ID;
  }
    
        
  if(ok)
  {
    form.action = 'index.php?assoc=' + qs.get("assoc", "") + '&user=' + qs.get("user", "") + '&Item1=' + qs.get("Item1", "") + '&Item2=' + qs.get("Item2", "")  + '&Item3=' + qs.get("Item3", "")  + '&id=' + qs.get("id", "") + '&brand=' + qs.get("brand", "") + '&end=' + qs.get("end", "") + '&quantity=' + quantity.value + ItemLink;
    form.submit();
  }
}


function OnChangeBrand(form, brand, user)
{
  form.action += "&user=" + user + "&brand=" + brand.options[brand.options.selectedIndex].text;
  form.submit();
}


function OnClickAssociated(form)
{
}


function OnDeleteBasket(form, input)
{
  if(confirm('Are you sure that you want to delete this item from your shopping basket?'))
  {
    input.value = '0';
    form.submit();
  }
}


function OnQuantityPrice(ID, user)
{
  var width, height, left, top
  
  width = 350;
  height = 250;
  left = (screen.width-width)/2;
  top = ((screen.height-50)-height)/2;

  newwindow = window.open('quantity_price.php?user=' + user + '&ID=' + ID, 'win', 'height=' + height + ',width=' + width + ',alwaysLowered=1,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=0,left=' + left + ',top=' + top + ',z-lock=0');
  if (window.focus) { newwindow.focus(); }

  return false;
}


function OnReadMore(ID, user, Item1, Item2, Item3, form, id)
{
  var width, height, left, top
  
  width = 700;
  height = 500;
  left = (screen.width-width)/2;
  top = ((screen.height-50)-height)/2;

  window.open('readmore.php?product_id=' + ID + '&id=' + id + '&user=' + user + '&Item1=' + Item1 + '&Item2=' + Item2 + '&Item3=' + Item3, 'win', 'height=' + height + ',width=' + width + ',alwaysLowered=1,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,left=' + left + ',top=' + top + ', z-lock=0');
}


function OnViewMoreProducts(form, last_product, user)
{
  form.start.value = last_product;
  form.submit();
  return false;
}

/* Client-side access to querystring name=value pairs
	Version 1.2.2
	30 Mar 2005
	Adam Vandenberg
	
  var qs = new Querystring() // Get QS from page

  var qs = new Querystring("name1=value1&name2=value2")

  Individual values can be retreived by name using get(). If the name was not found in the querystring, get() returns null or a provided default value. 

  var v1 = qs.get("name1")
  var v3 = qs.get("name3", "default value")
	
*/
function Querystring(qs) // optionally pass a querystring to parse
{
  var pos = qs.lastIndexOf("?");
  
  if(pos != -1)
    qs = qs.substr(pos + 1);

	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
// parse out name/value pairs separated via &
	var args = qs.split('&')
	
// split out each name=value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=')
		name = unescape(pair[0])

		var value
		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) // 'default' defaults to null
{
  var undefined;
  
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null)
	  default_ = null;
	
	var value = this.params[key]
	
	if (value == null || value == undefined)
	{
	  value=default_;
	}
	
	return value
}