function ClinchUtils() {
}

// Sets a cookie to expire in <days> days.
ClinchUtils.setCookie = function(name, value, days, path, domain, secure) {
	//console.log("Creating cookie " + name + "=" + value + " for " + days + " days.");
	
	var c = escape(name) + "=" + escape(value);
	if (days) {
		var d = new Date();
		d.setDate(d.getDate() + days);
		c += "; expires=" + d.toUTCString();
	}
	
	if (path) {
		c += "; path=" + escape(path);
	}
	
	if (domain) {
		c += "; domain=" + escape(domain);
	}
	
	if (secure) {
		c += "; secure";
	}
	
	//console.log(c);
	document.cookie = c;
	
}

ClinchUtils.getCookie = function(name) {
  var results = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );

  if (results) {
    return ( unescape ( results[2] ) );
	}
	
  else {
    return null;
	}
}

ClinchUtils.clearCookie = function(name) {
	//console.log("Clearing cookie: " + name);
  var d = new Date ();
  d.setTime ( d.getTime() - 1 );
  document.cookie = name += "=; expires=" + d.toGMTString();
}


