/***************************************************************************

	Author 			:Charles B. Cossé 
	
	Email			:ccosse@asymptopia.org
	
	Website			:http://www.asymptopia.org
	
	Copyright		:(C) 2004-2005 Asymptopia Software.
	
 ***************************************************************************/
						//file:mv02.js
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version. (Please note that if you use this *
 *   code you must give credit by including the Author and Copyright       *
 *   info at the top of this file).                                        *
 ***************************************************************************/
function Cookie(document,name){
	this.$document=document;
	this.$name=name;
	this.$path="/";
	//if(hours)
	//	this.$expiration=new Date((new Date()).getTime()+hours*36);//extendthis
	//else this.$expiration=null;
	this.$expiration=new Date((new Date()).getTime()+50000000*36);
	//alert("init complete");
}
Cookie.prototype.store=function(){
	//alert('storing:'+this.$name);
	var cookieval="";
	for(var prop in this){
		//alert("prop="+prop+" + "+escape(this[prop]));
		if((prop.charAt(0)=='$') || (typeof this[prop]) == 'function')
			continue;
		if(cookieval != "")cookieval += '&';
		cookieval +=prop+':'+escape(this[prop]);//this is where the $ is necessary
		
	}
	var cookie=this.$name+'='+cookieval;
	//alert("cookie so far="+cookie);
	if(this.$expiration)
		cookie+=';expires='+this.$expiration.toGMTString();
	//if(this.$times)
	//	cookie+=';times='+this.$times;
	if(this.$domain)cookie+=';domain='+this.$domain;
	if(this.$secure)cookie+=';secure';
	//alert("final cookie="+cookie);
	this.$document.cookie=cookie;
}
Cookie.prototype.load=function(){
	var allcookies=this.$document.cookie;
	//alert("allcookies="+allcookies);
	if(allcookies=="")return false;
	var start=allcookies.indexOf(this.$name+'=');
	if(start==-1){
		//alert('Cookie not defined for this page');
		return false;//
	}
	start+=this.$name.length+1;
	var end=allcookies.indexOf(';',start);
	if(end==-1)end=allcookies.length;

	var cookieval=allcookies.substring(start,end);
	var a=cookieval.split('&');
	for(var i=0;i<a.length;i++)
		a[i]=a[i].split(':');
	
	for(var i=0;i<a.length;i++)
		this[a[i][0]]=unescape(a[i][1]);
	
	return true;
}
Cookie.prototype.remove=function(){
	var cookie;
	cookie=this.$name+'=';
	if(this.$path)cookie+=';path='+this.$path;
	if(this.$domain)cookie+=';domain='+this.$domain;
	cookie+=';expires=Fri, 02-Jan-1970 00:00:00 GMT';
	this.$document.cookie=cookie;
}
