function createCookie(name,value,days) // fn. for creating cookies
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		var expires = "";
		
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
	var flag = 0;

	var dcmntCookie = document.cookie.split(';'); // getting all cookies in the document and splitting them and storing in an array

	for(var i=0;i < dcmntCookie.length;i++) // looping through the cookies array
	{
		var ck = dcmntCookie[i];
		while (ck.charAt(0)==' ') // loop for removing space at the begining
		{
			ck = ck.substring(1,ck.length);
		}
		if(ck)
		{
			cparts = ck.split('='); // splitting the cookie. eg: mycookie="some message"

			if (cparts[0]==name)
			{
				flag=1;
				break;
			}
		}
	}
	
	if(!flag)
	{
		$('#popupdiv').fadeIn('slow');
		createCookie(name,"cookie 4 the day",1);
	}
}

window.onload = function() {
	readCookie('MyCookie');
}
