function getCookie( oName ) {
	var splitcookie = document.cookie.split( "; " ), x, cookiepair;
	for( x = 0; x < splitcookie.length; x = x + 1 ) {
		cookiepair = splitcookie[x].split( "=" );
		if( cookiepair[0] === encodeURIComponent( oName ) ) {
			if( cookiepair[1] ) {
				return decodeURIComponent( cookiepair[1] );
			} else {
				return '';
			}
		}
	}
	return null;
}

function setCookie( oName, oValue, oDuration ) {
	if( oDuration ) {
		oDuration = new Date().getTime() + oDuration;
		oDuration = new Date( oDuration ).toGMTString();
	}
	document.cookie = encodeURIComponent( oName ) + "=" + encodeURIComponent( oValue ) + ( oDuration ? ( ";expires=" + oDuration ) : "" );
}

setCookie("foo", "bar", 30000);

setTimeout(function () {
	if (getCookie("foo") === "bar") {
		document.getElementById("cookie").style.backgroundColor='green';
	}
}, 500);
