var domain = window.location.host.substr(window.location.host.lastIndexOf(".", window.location.host.lastIndexOf(".")-1));
if (domain.indexOf(":")>0){
  domain = domain.substr(0,domain.indexOf(":"));
}
function Cookie(name, value)
{
  this.name = name;
  this.value = value;
  this.expires = new Date();
  this.path = "/";
  this.domain = domain;
  this.CookieSet = CookieSet;
  return this;
}
function CookieSet()
{  
  var ck = this.name + "=" + this.value.replace(/[=;%\t\f\r\n]/g, function(s){return encodeURIComponent(s);})

 	+ (this.path?"; path=" + this.path : "")

 	+ (this.domain?"; domain=" + this.domain:"")

 	+ (this.expires?"; expires=" + this.expires.toGMTString():"");

 	document.cookie = ck;
}
function CookieGet(name)
{
  var cookies = document.cookie;
  var pos1 = cookies.indexOf(name + "=");
  if (pos1==-1) return null;
  var pos2 = cookies.indexOf(";", pos1);  
  if (pos2!=-1) {
    return cookies.substring(pos1 + name.length + 1, pos2);
  } else {
    return cookies.substr(pos1 + name.length + 1);
  }
}
function CookieRemove(name,path){
    document.cookie = name + "="
	   	+ (path?"; path=" + path:"")
	   	+ (domain?"; domain=" + domain:"")
	   	+ "; expires= + Thu, 01-Jan-1970 00:00:01 GMT";
}
function getIdUser(name){
  var sContent = CookieGet(name);
  
  return unescape(sContent).split("_")[0];
}
function getUserNick(name){
  var sContent = CookieGet(name);
  
  return unescape(sContent).split("_")[1];
}
function isConnected(name){
	 	var bCommunity = false;	
	 	var items = document.cookie.split("; "), pair;

  	for (var i = 0; i < items.length; i++)
  	{
   		pair = items[i].split("=");

			if(pair[0]==name) {
				bCommunity = true;
			}			
  	}

		if(bCommunity){
			return true;
		}else{
			CookieRemove(name, "/");			
			return false;
		}		
}
