var caution = false

function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "")
if (!caution || (name + "=" + escape(value)).length <= 4000)
document.cookie = curCookie
else
if (confirm("Cookie exceeds 4KB and will be cut!"))
document.cookie = curCookie
}

function getCookie(name) {
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

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 fixDate(date) {
var base = new Date(0)
var skew = base.getTime()
if (skew > 0)
date.setTime(date.getTime() - skew)
}


function getFecha() {
  var months=new Array(13);
  months[1]="enero";
  months[2]="febrero";
  months[3]="marzo";
  months[4]="abril";
  months[5]="mayo";
  months[6]="junio";
  months[7]="julio";
  months[8]="agosto";
  months[9]="septiembre";
  months[10]="octubre";
  months[11]="noviembre";
  months[12]="diciembre";
  var time=new Date();
  var lmonth=months[time.getMonth() + 1];
  var date=time.getDate();
  var year=time.getYear();
  if (year < 2000)    // Y2K Fix, Isaac Powell
  year = year + 1900; // http://onyx.idbsu.edu/~ipowell
  return ("" + date + " de " + lmonth + " de " + year + "");
}

function nRand(x) {
 var now = new Date()
 var a = now.getTime(); 
 with (Math)
 {
  b = a / x;
  c = ceil((b - floor(b)) * x) + 1;
 }
 return c;
}

function Ask4UserId(flag) {
  var now = new Date()
  fixDate(now)
  var a = now.getTime(); 
  now.setTime(now.getTime() + 31 * 24 * 60 * 60 * 1000)

  var userid = getCookie("ck_userId")

  sQueryHome = hp.isHomePage("http://www.portalchile.com/");
  if(sQueryHome){	
    setCookie("hpage", 's', now)
  }
   else {
    setCookie("hpage", 'n', now)
  }

  return (userid);
}

function setPage() { 
if (!hp.isHomePage("http://www.portalchile.com")) 
  hp.setHomePage("http://www.portalchile.com"); 
} 

