function CookieUtil()
{}

CookieUtil.setCookie = function(name,value,expiry,path,domain,secure)
{
var nameString = name + "=" + value;
var expiryString = (expiry == null) ? "" : " ;expires = "+ expiry.toGMTString();
var pathString = (path == null) ? "" : " ;path = "+ path;
var domainString = (path == null) ? "" : " ;domain = "+ domain;
var secureString = (secure) ?";secure" :"";
document.cookie = nameString + expiryString + pathString + domainString + secureString;
}

CookieUtil.getCookie= function(name) 
{
var CookieFound = false;
var start = 0;
var end = 0;
var CookieString = document.cookie;
var i = 0;

while (i <= CookieString.length) 
{
start = i ;
end = start + name.length;
if (CookieString.substring(start, end) == name){
CookieFound = true;
break; 
}
i++;
}

if (CookieFound){
start = end + 1;
end = CookieString.indexOf(";",start);
if (end < start)
end = CookieString.length;
return unescape(CookieString.substring(start, end));
}
return "";
}

CookieUtil.IsExistCookie = function (name)
{
	if(document.cookie && document.cookie!="")
	{
		cookies=document.cookie;
		cookie_pos=cookies.indexOf(name);
		if(cookie_pos!=-1)
			return true;
		else
			return false;
	}
	else
	{
		return false;
	}
}
CookieUtil.deleteCookie = function (name)
{
	var expiry = new Date();
	expiry.setTime (expiry.getTime() - 1);
	alert(expiry.toDateString());
	CookieUtil.setCookie( name , "Delete Cookie", expiry,null,null,false);
} 

CookieUtil.deleteAllCookie = function ()
{
	
	var expires = new Date();
	expires.setTime (expires.getTime() - 1);
	//alert(document.cookie);
	cookies=document.cookie.split(';');
	//alert("all length: " + cookies.length);
	for(var i=0;i<cookies.length;i++)
	{
		arr=new Array();
		arr=cookies[i].split('=');
		name=arr[0];
		//alert("cooke name: " + name.trim())
		if(name!="")
			CookieUtil.setCookie( name, "Delete Cookie", expires,null,null,false);
	}
} 

String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.trimLeft = function()
{
	return this.replace(/^\s*/);
}
String.prototype.trimRight = function()
{
	return this.replace(/\s*$/);
}



