<!--This is a basic demonstration of how to set, read and delete cookies.-->

<HTML>
<HEAD>
<TITLE>Basic Cookie Example II</TITLE>

<script language="JavaScript">
<!--
// Delete the cookie
function deleteCookie(name) {
document.cookie = name + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

// Set a cookie which can be accessed from subdomains within a domain:
function setDomainCookie(value,domain) {
// Set the domain value like .domain.com, so with a leading dot.
// Example: setDomainCookie('visits=0','.yourdomain.com');
document.cookie = value + '; path=/; domain=' + domain;
}

function Cookie() {
//set expiration date 7 days ahead
var expiration = new Date();
expiration.setTime(expiration.getTime() + 604800000);
var expire = expiration.toGMTString();

if (document.cookie.length > 0) {
// Define the variables
var dc = document.cookie;
var visitstring = 'counter=';
var begin = dc.indexOf('counter=')+visitstring.length;
var end = (dc.indexOf(';',begin) > -1) ? dc.indexOf(';',begin):dc.length;
var value = dc.substring(begin,end);

// Delete the cookie
// deleteCookie('counter=' + value);

// Update the cookie
value++;
document.cookie = 'counter=' + value + "; expires=" + expire;

// .. And return the value
return value;
} else {
// Set the cookie;
document.cookie = 'counter=0' + "; expires=" + expire;
return 0;
}
}

//-->
</script>


</HEAD>

<BODY>

<script language="JavaScript">
<!--
document.writeln('You have visited this page <b>' + Cookie() + '</b> times');
//-->
</script>


</BODY>
</HTML>