//---Constructor---
function CookieObj(domain,path){
	if(!domain) domain=document.domain;
	if(!path) path='';
	this.cookieDomain=domain;
	this.cookiePath=path;
}


//---Property---
//Accept Cookie Domain
CookieObj.prototype.cookieDomain=null;
//Accept Cookie Path
CookieObj.prototype.cookiePath=null;


//---Method---
//Write Cookie
CookieObj.prototype.setCookie=function(name,value,day){
	if((name != null) && (value != null)){
		if(!isNaN(day)){
			day=parseFloat(day);
			var setDay=new Date();
			setDay.setTime(setDay.getTime()+(day*1000*60*60*24));
			expDay=setDay.toGMTString();
		}
		else expDay=0;
		
		var theCookieValueArr=document.cookie.split('; ');
		for(var i=1;i<theCookieValueArr.length;i++){
			var cookieValue=theCookieValueArr[i].split('=');
			if(cookieValue[0] != name){
				var cookieStr=cookieValue[0]+'='+cookieValue[1];
				if(expDay) cookieStr+=';expires='+expDay;
				document.cookie=cookieStr
			}
		}
		if(typeof(encodeURI) == 'function') value = encodeURI(value);
		else value =escape(value);
		var cookieStr=name+'='+value;
		if(expDay) cookieStr+=';expires='+expDay;
		if(this.cookieDomain) cookieStr+=';domain='+this.cookieDomain;
		if(this.cookiePath) cookieStr+=+';path='+this.cookiePath;
		document.cookie=cookieStr;
		return true;
	}
	return false;
}


//Delete Cookie
CookieObj.prototype.deleteCookie=function(name){
	var cookieStr=name+'=;expires=Thu, 01 Jan 1970 00:00:01 GMT';
	document.cookie=cookieStr;
	return true;
}


//Read Cookie
CookieObj.prototype.getCookie=function(name){
	name+='=';
	var theCookie=document.cookie+';';
	var start=theCookie.indexOf(name);
	if(start != -1){
		var end=theCookie.indexOf(';',start);
		if(typeof(decodeURI) == 'function') return decodeURI(theCookie.substring(start+name.length,end));
		else return unescape(theCookie.substring(start+name.length,end));
	}
	return false;
}


//Getter,Setter
CookieObj.prototype.setCookieDomain=function(cookieDomain){
	this.cookieDomain=cookieDomain;
}

CookieObj.prototype.getCookieDomain=function(){
	return this.cookieDomain;
}

CookieObj.prototype.setCookiePath=function(cookiePath){
	this.cookiPath=cookiePath;
}

CookieObj.prototype.getCookiePath=function(){
	return this.cookiePath;
}