	function getItemQuantity( productID ){
		var qtyField = document.getElementById( "qty" + productID );
		var itemQty = 0;
		if( qtyField != null ){
			if( qtyField.type == "text" ){
				itemQty = qtyField.value;
			} else {
				itemQty = qtyField.options[qtyField.selectedIndex].text;
			}
		}
		return itemQty;
	}
	function updateQuantity( productID, quantity ){
		setQuantityCookie( productID, quantity );
		if( productID == "D04" ){
      unselectAllStrategies();
    }
	}
	function setQuantityCookie( productID, quantity ){
		//e.g. S01:1|B02:4|
		var cookieQty = getCookie( "qty" );
		var newCookieQty = "";
		if( cookieQty != null ){
			var quantities = cookieQty.split("|");
			for( q = 0; q < quantities.length - 1; q++ ){
				var quantityString = quantities[q];
				if( quantityString.indexOf(productID + ":" ) != 0 ){
					newCookieQty += quantities[q] + "|";
				}
			}
		}
		newCookieQty += productID + ":" + quantity + "|";		
		setCookie( "qty", newCookieQty, 1 );
		//setCookie("qty","");
	}
	function getCookie( cookieName ){
		var start = document.cookie.indexOf( cookieName + "=" );
		var len = start + cookieName.length + 1;
		if ( ( !start ) && ( cookieName != document.cookie.substring( 0, cookieName.length ) ) ){
			return null;
		}
		if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ";", len );
		if ( end == -1 ) end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );	
	}
	function setCookie( cookieName, value, days ){
		//alert( "setting cookie " + cookieName + " to " + value );
		var today = new Date();
		var expire = new Date();
		if (days==null || days==0) days=1;
		expire.setTime(today.getTime() + 3600000*24*days);
		document.cookie = cookieName+"="+escape(value) + ";expires="+expire.toGMTString()+";path=/";
		
	}
	function togglepurchase( id ){
		var div = document.getElementById( "Purchase" + id );
		if( div != null ){
			var qtyField = document.getElementById( "qty" + id );
			var qty = 0;
			if( qtyField != null ){
				qty = qtyField.value;
			}
			if( div.className == "purchaseboxcontent" ){
				div.className = "purchaseboxcontentshow";
			} else if( qty == "" || qty == 0 ){
				div.className = "purchaseboxcontent";
			}
		}
	}
	function formatPrice( theCountry, flPrice ){
		var strPrice = new String(Math.floor((flPrice * 100))); 
		strPrice = strPrice.substring(0, strPrice.length - 2) +"." + strPrice.substring(strPrice.length - 2, strPrice.length)
	  
        if( theCountry == "United Kingdom" ) {
                var strPrice = "£" + strPrice;
        } else {
			if( theCountry == 'Europe' ){
				strPrice = "€" + strPrice;
			} else {
                strPrice = "$" + strPrice;
			}
        }
        switch( theCountry ) {
                case "Australia":
                        strPrice += " AUD";
                        break;
                case "Canada":
                        strPrice += " CAD";
                        break;
                case "United Kingdom":
                        strPrice += " GBP";
                        break;
                case "New Zealand":
                        strPrice += " NZD";
                        break;
		case "Europe":
			strPrice += " EUR";
			break;
                default:
                        strPrice += " USD";
        }
        return strPrice
    }
    
function updateStrategies(){
    var selected = "";
    var total = 0;
    var selectAll = document.getElementById('allstrategies');
    if( selectAll != null ){
      for( var s = 1; s <= 55; s++ ){
        var checkbox = document.getElementById( getStrategyCheckboxID(s) );
        if( checkbox != null && checkbox.checked ){
          selected = selected + checkbox.value + ",";
          total++;
        }
      }
    } else {
      var qty = document.getElementById('qtyD04').options[document.getElementById('qtyD04').selectedIndex].value;
      if( qty == 55 ){
        selected = "01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,";
        total = 55;
      }
    }
    setCookie( "selectedStrategies", selected, 1 );
    var purchaseBox = document.getElementById('qtyD04');
    if( purchaseBox != null ){
      if( total >0 && total < 10 ){
        total = 10;
      }
      purchaseBox.options[1].text = total;
      purchaseBox.options[1].value = total;
      purchaseBox.options[1].selected = true;
      updateQuantity('D04', getItemQuantity('D04'), 1);
    }
  }
  function unselectAllStrategies(){
    var selectBox = document.getElementById('qtyD04');
    if( selectBox.selectedIndex == 0 ){
      var selectAll = document.getElementById('allstrategies');
      if( selectAll != null ){
        selectAll.checked = false;
      }
      selectAllStrategies();
      selectBox.options[1].value="0";
      selectBox.options[1].text = "0";
    }
  }
  function selectAllStrategies(){
    var selectAll = document.getElementById('allstrategies');
    if( selectAll != null ){
      checked = selectAll.checked;
      for( var s = 1; s <= 55; s++ ){
        var checkbox = document.getElementById( getStrategyCheckboxID(s) );
        if( checkbox != null ){
          checkbox.checked = checked;
        }
      }
    }
    updateStrategies();
  }
  function getStrategyCheckboxID( num ){
    if( num > 9 ){
      return 'strategy' + num;
    } else {
      return 'strategy0' + num;
    }
  }