$(document).ready(function() {
	var cookieFTU = $.cookie('HH_FIRST-TIME-USER');
	//var promoName ---> the value of promoName here is dynamically retrieved from the application contect xml.. see SignUpAndPromoPopup.java file to see how it is retrieved.
	
	if (cookieFTU == null) {
		//NO cookie by the name 'HH_FIRST-TIME-USER' was found!
		//approx. 1 year
		//raw: true ... so that the "promoName=SIGNUP-FOR-SAVINGS" will not become "promoName%3DSIGNUP-FOR-SAVINGS"!
		
		$.cookie('HH_FIRST-TIME-USER', ('promoName='+promoName+'|showPopup=true'), { expires: 365, path: '/', raw: true });
	} else {
		//A cookie  by the name 'HH_FIRST-TIME-USER' was found!
		//now check the Application Contexts against the promoName of the current cookie value
		var thereIsANewPromo = false;
		if (cookieFTU.indexOf('|') > -1) {
			var firstSplit = the_cookie.split('|');
			for (i=0;i<(firstSplit.length);i++) {
				var keyName = dbbGetKey('=', firstSplit[i]);
				
				if ((keyName == 'promoName') && (dbbGetValue('=', firstSplit[i]) != promoName)) {
					thereIsANewPromo = true;
				}
			} 
		} else {
			if (dbbGetKey('=', cookieFTU) == 'promoName') {
				if (dbbGetValue('=', cookieFTU) != promoName) {
					thereIsANewPromo = true;
				}
			}
		}

		if (thereIsANewPromo) {
			//delete cookie and add a new one
			$.cookie('HH_FIRST-TIME-USER', null, { expires: 365, path: '/', raw: true });		//deleting cookie should be like this.. see https://github.com/carhartl/jquery-cookie/issues/21
			$.cookie('HH_FIRST-TIME-USER', ('promoName='+promoName+'|showPopup=true'), { expires: 365, path: '/', raw: true });
		} else {
			//do nothing.. let the cookie stay there..
			//this ELSE branch is not really needed, but i just want to see where the last logic went!
		}
	}
});
