function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
     ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
	var basket_link="";
	var basket_counter_cookie="basket_counter";
	var basket_items_cookie="basket_items";
	var basket_count=0;
	basket_count = getCookie(basket_counter_cookie);
	basket_items = getCookie(basket_items_cookie);

	if(!basket_count||basket_count==null||basket_count=="undefined"){
		resetBasketCounter();
	}
	function resetBasketCounter(){
			setCookie(basket_counter_cookie,0,null,'/');
			setCookie(basket_items_cookie,'',null,'/');
			basket_count=0;
			location.reload();
	}
	if(basket_count<10){
		basket_class = "basket_button";
	}else{
		basket_class = "basket_button2";
	}

function basketAdd(item){
	var curr_basket = getCookie(basket_items_cookie);
	
	if(curr_basket!=null){
		//Don't waste cookie space by adding duplicate items to the basket.
		var bs_array=curr_basket.split(",");
		for(i=0;i<bs_array.length;i++)
		 {
			if (escape(bs_array[i]) == escape(item)){  
				alert(item + " is already in your order list.  Specify the required quantity on the 'Finish Order' page.");
				return;
			}
		}
	}
		
	if(curr_basket==null)curr_basket="";
		var all_items = curr_basket + item + ",";
		basket_count_cookie=getCookie(basket_counter_cookie);
		if(basket_count_cookie<basket_count)basket_count=basket_count_cookie; //must have lost some on the next page...
		basket_count++;

		if (basket_count>30){ 
			basket_count=30;
			alert("Cannot add more than 30 different items in one order.\nPlease submit the order before adding any more items.");
			return;
		}
		setCookie(basket_counter_cookie,basket_count,null,'/');
		setCookie(basket_items_cookie,all_items,null,'/');
		if(document.getElementById('num_sel')){document.getElementById('num_sel').innerHTML = basket_count;}
		if(document.getElementById('num_sel')){document.getElementById('num_sel2').innerHTML = basket_count;}
		//document.getElementById('basket_b').innerHTML = basket_count;
		alert("Thank you. "+item+" was added to your order.\nNumber of item(s) selected: " + basket_count);
	if (multif&&multif!=null&&!multif.closed){
		multif.focus();
	}
}

function popup(url, width, height) {
	var win = window.open(url, 'popup', 'height=' + height + ', width=' + width + ', status=no, resizable=no, toolbar=no, menubar=no, location=no, scrollbars=yes');
	win.focus();
}
function viewDescription() {

var name=viewDescription.arguments[0];
var title = "?title=";
var inc_dir = "/site/content/include/order_literature/";

	if (viewDescription.arguments.length > 1){
		title = title + viewDescription.arguments[1];
	}
	if (name.indexOf(".htm")==-1){
		name=name+".htm";
	}
	
	name=name+title;
		popup(inc_dir + name, 430, 200);
}

function changeLitPage(dd_id){
	if(document.getElementById(dd_id)){
		if(document.getElementById(dd_id).options[document.getElementById(dd_id).selectedIndex].value!=''){
			document.location.href=document.getElementById(dd_id).options[document.getElementById(dd_id).selectedIndex].value
		}
	}
}


