// Declare methods first
//
function setCookie() {
  var curCookie = this.name + "=" + escape(this.value) +
      ((this.expires) ? "; expires=" + this.expires.toGMTString() : "") +
      ((this.path) ? "; path=" + this.path : "; path='/'") +
      ((this.domain) ? "; domain=" + this.domain : "") +
      ((this.secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookieCount()
{
  if (this.doescookieexist())
  {
  var dc = document.cookie;					// get all cookies
  var prefix = this.name + "=";				// set patten of cookie in question
  var begin = dc.indexOf("; " + prefix);	// search for the start of cookie
  if (begin == -1) {
    begin = dc.indexOf(prefix);				// search for the start of cookie
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);		// end of cookie string
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));	// unpack the cookie
  }
  else
  {
	  alert('No cookie name supplied')
	  return -1
  }
}

// This method increase the counter by "inc" for that cookie and return that value
//
// Parameters are:
//		ndays		 ==> How many days the cookie should exist. (Optional  30 days by default)
//		inc		 ==> How many days the cookie should exist. (default one)

function incCookieCount(inc,ndays)
{
inc = (inc == null ) ? 1 : inc									// default 1 for increase in the cookie

this.setdays()

var visits = this.getCookieCount();
// if the cookie wasn't found, this is your first visit
this.value = (!visits) ?  1 : parseInt(visits) + inc;
// set the new cookie or update counter
this.setCookie();
return this.value ;
}

function deleteCookie()
{
 if (this.doescookieexist())
  {
     if (this.getCookieCount(this.name))
		 {
			document.cookie = this.name + "=" + 
			((this.path) ? "; path=" + this.path : "") +
			((this.domain) ? "; domain=" + this.domain : "") +
			 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		 }
  }
  else
  {
	  alert('No cookie name supplied')
	  return null
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function ifcookieexist(name)
{
  var dc = document.cookie;					// get all cookies
  var prefix = name + "=";					// set patten of cookie in question
  var begin = dc.indexOf("; " + prefix);	// search for the start of cookie
  if (begin == -1) {
    begin = dc.indexOf(prefix);				// search for the start of cookie
	}
return (begin < 0) ?  false : true ;
}


function doescookieexist()
{
  var dc = document.cookie;					// get all cookies
  var prefix = this.name + "=";					// set patten of cookie in question
  var begin = dc.indexOf("; " + prefix);	// search for the start of cookie
  if (begin == -1) {
    begin = dc.indexOf(prefix);				// search for the start of cookie
	}
return (begin < 0) ?  false : true ;
}


function display()
{
	str= 'name='+this.name
    str=str+ '  value='+this.value
    str=str+ '  path='+this.path
	str=str+ ' expires='+this.expires
	alert(str)
}

function setdays(ndays)
	{
var now = new Date();
fixDate(now);		// fix the bug in Navigator 2.0, Macintosh
now.setTime(now.getTime() + this.ndays * 24 * 60 * 60 * 1000);
this.expires=(this.ndays) ? now : ""		// default the seesion otherwise ndays
return
	}

//  cookieClass
//  Where:
//		name - name of the cookie
//		value - value of the cookie (defaults to 1)
//		[expires] - expiration date of the cookie (defaults to 30 days)
//		[path] - path for which the cookie is valid (defaults to website)
//		[domain] - domain for which the cookie is valid (defaults to domain of calling document)
//		[secure] - Boolean value indicating if the cookie transmission requires a secure transmission
//		* an argument defaults when it is assigned null as a placeholder
//		* a null placeholder is not required for trailing omitted arguments
function cookieClass(name)
{

}
function cookieClass(name, value, path ,  ndays , domain ,  secure)
{ 
	// Define properties
	
	if (name) { this.name=name }
	else 
		{ alert('Need a name for the cookie');
		   return null
	    }
    this.value=(value) ?  value : 0  ;		// default counter in zero
    this.path=(path) ? path : '/'   ;			// default visibility is the whole website
    this.ndays=(ndays) ?  ndays : 0  ;		// default counter in zero
    this.domain=(domain) ? domain : null ;
    this.secure=(secure) ? secure : null ;
	this.expires=''

// Define methods for this class
	this.setCookie=setCookie ;					// set cookie with the values in the properties
	this.getCookieCount=getCookieCount ;		// get cookie count
	this.incCookieCount=incCookieCount ;		// increase counter by "inc" and make it last ndays
	this.deleteCookie=deleteCookie ;			// delete this cookie
	this.fixDate=fixDate ;						// fix inconsistancy problems with dates in diff browsers
	this.setdays=setdays ;						// convert to correct date form for the cookie
	this.doescookieexist=doescookieexist ;		// returns true/false if the name of the cookie exist
	this.display=display;

// end of properties and methods


// Initial setup for this class
	this.setdays()  ;							// default cookie last for this session
	if (this.doescookieexist())
	{
		this.value=this.getCookieCount()		// if cookie exist then get the counter
	}
	else
	{
		this.setCookie()						// set  first time cookie
	}

    return this 
} 

/* How to create objects with this class:

i.e. var  mycookie = new cookieClass('test')   
				cookie name = 'test'
				last only for the session 
				counter starts in zero
				visible in each page in the website

i.e. var  mycookie = new cookieClass('test',10)   
				cookie name = 'test'
				last only for the session 
				counter starts in 10
				visible in each page in the website

i.e. var  mycookie = new cookieClass('test',,'/catalog')   
				cookie name = 'test'
				last only for the session 
				counter starts in zero
				if this cookie is created by http://airage.com/catalog/widgets/index.asp
				then the visibity of the cookie is FROM http://airage.com/catalog/ and any sublevel

i.e. var  mycookie = new cookieClass('test',5,,32)   
				cookie name = 'test'
				last for 32 days
				counter starts in 5
				visible in each page in the website
*/
function makepop() {
return ;
window.open('/pop_window/'+popname,'mpop1','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=310,height=275,left=60,top=30');
};

