// The GetCookie() function returns the number of times a 
//    cookie with a specific name has been set on the 
//    visitor's computer.

// How many days shall the cookie live on your user's computer?
DaysToLive = 365;


// No other customizations required.
// This function looks for a cookie with a specific name on the visitor's hard drive.
function GetCookie(name) {
// Start by assuming no cookie exists.
var cookiecontent = '0';
// The browser's cookies can hold data we're not interested in, all in one 
//     long string of characters. Thus, we need to find out where our specific
//     cookie begins and ends (provided the one we want actually exists).
//
// If any cookies are available ...
if(document.cookie.length > 0) {
	// Determine begin position of the cookie with the specified name.
	var cookiename = name + '=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	// Initialize the end position at zero.
	var cookieend = 0;
	// If a cookie with the specified name is actually available ...
	if(cookiebegin > -1) {
		// Offset the begin position of the cookie by the lengh of the cookie name.
		cookiebegin += cookiename.length;
		// Determine the end position of the cookie.
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		// Put the cookie into our own variable "cookiecontent".
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
	}
}
// Increment cookie content by 1 and store in variable "value".
var value = parseInt(cookiecontent) + 1;
// Put the incremented value as a new cookie on the visitor's hard drive.
PutCookie(name,value);
// Return the incremented value to the calling line of code.
return value;
}

// This function puts the cookie on the visitor's hard drive.
function PutCookie(n,v) {
// Begin by assuming no expiration date is applicable.
var exp = '';
// If an expiration date is applicable, determine the future date 
//      and store the date in variable "exp" in the correct format.
if(DaysToLive > 0) {
	var now = new Date();
	then = now.getTime() + (DaysToLive * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' +
	now.toGMTString();
}
// Put the cookie on the user's hard drive with path set to root 
//     and with any applicable expiration date.
document.cookie = n + "=" + v + '; path=/' + exp;
}

///////////////////////////////////////////////
///////////////////////////////////////////////
// show overlay
function showBox(){
visits = GetCookie('CHW');
	if(visits <= 1) {
		$(document).ready(function(){
			tb_show("overlay", "#TB_inline?height=295&width=620&inlineId=overlay&modal=true", false);
		});
	}
}
