$(function(){
  // Document is ready
  $("#heaviness>*>input:checkbox").click(function(){
  	var id = $(this).attr('id');
  	var checked = $(this).attr("checked");
  	setCookie('state_hinder' + id.toString() , (checked) ? 1 : 0);
  });
  
  $("#time_period>*>input:checkbox").click(function(){
		var id = $(this).attr('id');
  		var checked = $(this).attr("checked");
  		setCookie('state_timeperiod' + id.toString() , (checked) ? 1 : 0);
  });
  
  $("#period").change(function (){
		setCookie('state_period', $(this).val());
  });
});


function setCookie(sName, sValue, oExpires, sPath, sDomain, bSecure) {
	var sCookie = sName + "=" + encodeURIComponent(sValue);
	if (oExpires) {
		sCookie += "; expires=" + oExpires.toGMTString();
	}
	if (sPath) {
		sCookie += "; path="+ sPath;
	}
	if (sDomain) {
		sCookie += "; domain=" + sDomain;
	}
	if (bSecure) {
		sCookie += "; secure";
	}
	document.cookie = sCookie;
}

function getCookie(sName) {
	var sRE = "(?:; )?" + sName + "=([^;]*);?"
	var oRE = new RegExp(sRE);
	if (oRE.test(document.cookie)) {
		return decodeURIComponent(RegExp["$1"]);
	} else {
		return null;
	}
}