﻿function CampaignMarketingURLCookie (queryparams, cookieage) {
		
	this.campaignMarketingParam = "c_m";
	this.querystringParams = queryparams;
	this.cookieName = "cas-campaign-marketing-cookie";
	this.cookieValue = "";
	
	// default 30 days, but allow for passed cookie age in function call
	if ((parseFloat(cookieage) == parseInt(cookieage)) && !isNaN(cookieage)) {
		this.cookieAge = cookieage;
	} else {
		this.cookieAge = 30;
	}

}

CampaignMarketingURLCookie.prototype.setCookie = function() {

	// only init cookie for current page location with Marketing Campaign url querystring param ("c_m")
	if ((this.querystringParams[this.campaignMarketingParam] !== undefined) && (this.querystringParams[this.campaignMarketingParam] !== "")) {
		
		var exdate = new Date();
		exdate.setDate(exdate.getDate() + this.cookieAge);
		
		this.cookieValue = "campaign=" + this.querystringParams[this.campaignMarketingParam] + "&cookie-age=" + this.cookieAge + "; expires="+exdate.toUTCString()+"; domain=calacademy.org; path=/";
		
		document.cookie = this.cookieName + "=" + this.cookieValue;
		
		//return this.cookieName + "&cookie-age=" + this.cookieAge;
		
	}
		
}
