// "Internal" function to return the decoded value of a cookie
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

/*********FUNCTION TO GET A SPECIFIC COOKIE*************/
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg){return getCookieVal (j)}
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}

/*********FUNCTION TO GET A SET A COOKIE*************/
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
 ((expires) ? "; expires=" + expires.toGMTString() : "") +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
}

//set expiration data for 1 year;
var expdate = new Date ();
expdate.setTime (expdate.getTime() + ( (24 * 60 * 60 * 1000) * 365)); 


var lastad = GetCookie('lastad');
if (!lastad) {
	SetCookie('lastad','1',expdate,'/',null,null)
	lastad = 1;
} else {
	if (lastad >= 13) {
		lastad = 1;
		SetCookie('lastad',lastad,expdate,'/',null,null);
	} else {
		SetCookie('lastad',parseInt(lastad)+1,expdate,'/',null,null);
	}
}
var wHTMLLine="<IMG SRC=\"images\\" + [lastad] + ".jpg\" >";
document.write(wHTMLLine);