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"); 
} 

var idContenedor = "miCalendario"
var hoy = new Date()
var mes = hoy.getMonth()
var dia = 1
var anio = hoy.getFullYear()
var diasSemana = new Array ('L','M','M','J','V','S','D')
var meses = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre')
var tunIex=navigator.appName=="Microsoft Internet Explorer"?true:false;

if(tunIex && navigator.userAgent.indexOf('Opera')>=0){tunIex = false}
tunOp = navigator.userAgent.indexOf('Opera')>=0 ? true: false;

function tunCalendario(){
	dia2 = dia
	tab = document.createElement('table')
	tab.id = 'calendario'
	document.getElementById(idContenedor).appendChild(tab)
	tcabeza = document.createElement('thead')
	tab.appendChild(tcabeza)
	fi2 = document.createElement('tr')
	fi2b = document.createElement('th')
	fi2b.colSpan = 7
	fi2.id = 'mesCalendario'
	fi2b.appendChild(document.createTextNode(meses[mes] + "  -  " 

+ anio))
	fi2.appendChild(fi2b)
	tcabeza.appendChild(fi2)
	fi = document.createElement('tr')
	tcabeza.appendChild(fi)
	for(m=0;m<7;m++){
		ce = document.createElement('th')
		ce.appendChild(document.createTextNode(diasSemana[m]))
		fi.appendChild(ce)
		if(m == 6){ce.style.marginRight = 0}
		}
		var escribe = false
		var escribe2 = true
	fecha = new Date(anio,mes,dia)
	var d = fecha.getDay()-1 //dia semana
	if(d<0){d = 6}
	tcuerpo = document.createElement('tbody')
	tab.appendChild(tcuerpo)
	while(escribe2){
		fi = document.createElement('tr')
		co = 0
		for(t=0;t<7;t++){
			ce = document.createElement('td')
			if(escribe && escribe2){
			fecha2 = new Date(anio,mes,dia)
			
				if(fecha2.getMonth() != mes){escribe2 

= false;}
				else{ce.appendChild

(document.createTextNode(dia));dia++;co++}
			}
			if(d == t && !escribe){
			ce.appendChild(document.createTextNode(dia))
			dia++;co++
			escribe = true
			}
			fi.appendChild(ce)
			if(hoy.getDate()+1 == dia && mes == 

hoy.getMonth() && anio == hoy.getFullYear()){ce.className = "Hoy"}
			}
			
		if(co>0){tcuerpo.appendChild(fi)}
		
		}
	dia = dia2
}

function borra(){
document.getElementById(idContenedor).removeChild

(document.getElementById('calendario'))
}

function establecerFecha(){
tunFe = new Date()
document.getElementById('tunMes').options[tunFe.getMonth()].selected = 

true
document.getElementById('tunAnio').value = tunFe.getFullYear()
}

