var kUsuario = 'p1';
var kIdioma = 'p2';
var kRegistrado = 'p3';
var kAnonymous = 1;
var kPathCookie = '/';
var kDomain = fGetDomain();

function getCookieVal(offset)
{
 var endstr = document.cookie.indexOf(";",offset);
 
 if (endstr == -1) endstr = document.cookie.length;
 
 return (unescape(document.cookie.substring(offset,endstr)));
}

function FixCookieDate (date)
{
 var base = new Date(0);
 var skew = base.getTime();
 
 if (skew > 0) date.setTime(date.getTime() - skew);
}

function GetCookie (name)
{
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0, j;
 
 while (i < clen)
 {
  j = i + alen;
  
  if (document.cookie.substring(i,j) == arg) return getCookieVal(j);
  i = document.cookie.indexOf(" ",i) + 1;
  if (i == 0) break;
 }
 
 return null;
}

function SetCookie (name,value,expires,path,domain,secure)
{
	var s = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
	
	document.cookie = s;
}

function DeleteCookie (name,path,domain)
{
 if (GetCookie(name))
 {
  document.cookie = name + "=" +
   ((path) ? "; path=" + path : "") +
   ((domain) ? "; domain=" + domain : "") +
   "; expires=Thu, 01-Jan-70 00:00:01 GMT";
 }
}

function GetIdioma ()
{
 return (GetCookie(kIdioma));
}

function SendIdioma (pValue)
{
	var dHoy = new Date()
	with (new Date()) {
		var y1 = getFullYear() // ; y1=(y1<100?1900+y1:y1)
		//alert(y1)
		var m1 = getMonth()+1
		var d1 = getDate()
	}
	var dData = new Date(y1,m1,d1,12,30,30);	//caduca d'aqui 1 mes
	
	SetCookie(kIdioma,pValue,dData,kPathCookie,null,null);
}

function fGetDomain ()
{
 var wUrl = top.location.href;
 var wPosIni = wUrl.indexOf('.');
 wPosIni = wPosIni+1;
 wPosFin = wUrl.indexOf('/',wPosIni);
  
 if (wPosFin == -1) wPosFin = wUrl.length;
 return (wUrl.substr(wPosIni,wPosFin - wPosIni));
}