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));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function step1(partner) {
	setCookie('partner', partner,null,null,null,null);
	setCookie('laststep', '1',null,null,null,null);
}
function step2() {
	setCookie('pizza', getCheckedValue(document.pizza.p),null,null,null,null);
	setCookie('laststep', '2',null,null,null,null);
}
function step3() {
	setCookie('size', getCheckedValue(document.size.s),null,null,null,null);
	setCookie('laststep', '3',null,null,null,null);
}
function step4() {
	setCookie('laststep', '4',null,null,null,null);
}

function additive(id) {
	setCookie('add['+id+']', document.additives.add.value,null,null,null,null);
}

function update() {
	var ids = "";
	var asd = "";
	for(i=0; i<document.other.elements.length; i++){
		ids = ids + ","+document.other.elements[i].id;
		asd = asd + ","+document.other.elements[i].value;

   }
	setCookie('other[ids]', ids,null,null,null,null);
	setCookie('other[vals]', asd,null,null,null,null);
}

function laststep(step) {
	setCookie('laststep', step,null,null,null,null);
}

function add(id, n) {
	el = document.getElementById(id);
	i = Number(el.value) + n;
	if (i >= 0) {
		el.value = i;
	}
}

function addp(id1, id2, n) {
	el = document.getElementById(id1+"-"+id2);
	i = Number(el.value) + n;
	if (i >= 0) {
		el.value = i;
	}
}
