function overlaypopup() {
  PutVisits('sid');
  if(parseInt(GetCookie('sid')) == 2) {openpopup();} else {return;}
}

function openpopup(){
	document.getElementById('overlay_box').style.display ='block';
	document.getElementById('overlay_overlay').style.display ='block';
	document.getElementById('overlay_popcontent').style.display ='block';
}


function closeme(){
	document.getElementById('overlay_box').style.display ='none';
	document.getElementById('overlay_overlay').style.display ='none';
	document.getElementById('overlay_popcontent').style.display ='none';
}


function PutVisits(name) {
	if(!GetCookie(name)) {
		var value = 1;
	} else {
		var value = parseInt(GetCookie(name)) + 1;
	}
	PutCookie(name,value);
}

// generic function to write a cookie
function PutCookie(name,value) { 
	var exp = '';
	var now = new Date();
	then = now.getTime() + (365 * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' + now.toGMTString();
	document.cookie = name + "=" + value + exp + '; path=/; domain=savvymom.ca';
}

// function to retrieve a cookie
function GetCookie(name) {
	var cookiecontent = '0';
	if(document.cookie.length > 0) {
		var cookiename = name + '=';
		var cookiebegin = document.cookie.indexOf(cookiename);
		var cookieend = 0;
		if(cookiebegin > -1) {
			cookiebegin += cookiename.length;
			cookieend = document.cookie.indexOf(";",cookiebegin);
			if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
			cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
	return cookiecontent;
}

