/*LLAMA ARCHIVOS .JS EXTERNOS*/

document.write('<script language="Javascript1.2" src="js/global.js"></script>' +
'<script language="javascript" type="text/javascript" src="js/validacions.js"></script>' +
'<script language="javascript" type="text/javascript" src="js/tamano_texto.js"></script>');



/*LLAMA ARCHIVOS .JS EXTERNOS*/

/* Funcion GoLink: usada casi siempre en popups, haciendo que al clickear el link dentro */
/* del popup, éste se cierre y abra el enlace en otra ventana. */

function golink() {
   window.opener.location="http://direccion.web.com"; /* poner ahi la dirección real */
   window.close();
   return 1;
}



/*Funcion carga textos en TIPS*/

function tips(texto) {
	var pelicula=document.all? document.tip : document.embeds["tip"]; 
	pelicula.SetVariable('txt_tip',texto);
}




/* Funcion Precarga de imagenes */

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* Funciones para cambiar de comportamiento (colores de fondo) en TD's. Por ejemplo en titulos, menus. */

function mOvr(src,clrOver){ 
 if (!src.contains(event.fromElement)){ 
  src.style.cursor = 'hand'; 
  src.className = clrOver; 
 } 
} 
function mOut(src,clrIn){ 
 if (!src.contains(event.toElement)){ 
  src.style.cursor = 'hand'; 
  src.className = clrIn; 
 } 
}
function mClk(src) 
{
if(event.srcElement.tagName=='TD')
	{
 	src.children.tags('A')[0].click();
	}
}



/*Funcion pulldown menu*/
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/* Funcion Volver a la página anterior */

function volver(pag){
	window.history.go(pag)
	}

/* Funcion abre un popup */

function MM_openBrWindow(theURL,winName,features) { //v2.0
  	window.open(theURL,winName,features);
}

/* Funcion para limpiar un formulario */

function limpia_form(nombre){
	alert(nombre)
	//window.document[nom].reset();
}

/* Funcion para imprimir */

function imprimir(){
	window.print();
}

/* Funcion para introducir la fecha en una pagina */

function fecha(){
	mes = new Array();
	diasem = new Array();
	fechas = new Date();
	diasemana = fechas.getDay();
	diasem[0] = "Domingo";
	diasem[1] = "Lunes";
	diasem[2] = "Martes";
	diasem[3] = "Miercoles";
	diasem[4] = "Jueves";
	diasem[5] = "Viernes";
	diasem[6] = "Sabado";
	dia = fechas.getDate();
	nomes = fechas.getMonth();
	anio = fechas.getYear();
	mes[0] = 'Enero';
	mes[1] = 'Febrero';
	mes[2] = 'Marzo';
	mes[3] = 'Abril';
	mes[4] = 'Mayo';
	mes[5] = 'Junio';
	mes[6] = 'Julio';
	mes[7] = 'Agosto';
	mes[8] = 'Septiembre';
	mes[9] = 'Octubre';
	mes[10] = 'Noviembre';
	mes[11] = 'Diciembre';
	if (anio < 1000) anio = anio + 1900;
	document.write(diasem[diasemana]+" "+ dia +" de "+ mes[nomes] +" de "+ anio);
}

/* Funcion Random para imágenes - J. Yevenes */

function img_random() { 
var imgs = ["img1.gif", "img2.gif", "img3.gif"]; 
document.getElementById("foto").src = imgs[Math.floor(Math.random()*imgs.length)]; 
}

function cerrar(){
	window.close();
	}


/* Funcion Go To */
function go_to(pag){
 window.location=pag

}
//Para el buscador: Cuando haces click se limpian los campos
function limpiar(){
	if(document.busqueda.palabra.value=="¡ Busque Aquí !"){
		document.busqueda.palabra.value="";
	}
}

function llenar(){
	if(document.busqueda.palabra.value==""){
		document.busqueda.palabra.value="¡ Busque Aquí !";
	}
}

//Funcion pull down vitas
function gothere() {	
    var index=document.corporacion.vitas.selectedIndex;
    
    if (index !=0) {
		var remote=document.corporacion.vitas.options[index].value.substring(0,1);
	    var url=document.corporacion.vitas.options[index].value.substring(1);		
		if (remote == "a") {
			window.open(url,"newwindow","toolbar=yes,location=yes,derectories=yes,status=yes,menubar=yes,scrollbar=yes,resizable=yes");
		} else {				
			document.location.href = document.corporacion.vitas.options[index].value;
		}
	}
}

/*Búsqueda en Google*/
get0='google.com/';
get1='?ie=ascii&safe=';
function ges(){
if(document.gef.q.value=='') {
	alert('Ingrese texto de búsqueda por favor');
	document.gef.q.focus();
	return false;
}
gev=escape(document.gef.q.value);
{if (document.gef.p[0].checked==true)
{ge1='w';gep='http://www.google.cl/custom?sa=B%FAsqueda&client=pub-2657561339527273&forid=1&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%233165CE%3BVLC%3A52188C%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3AFFFFFF%3BALC%3A0000CC%3BLC%3A0000CC%3BT%3A000000%3BGFNT%3A7375CE%3BGIMP%3A000000%3BFORID%3A1%3B&hl=es&num=20&';}
else if (document.gef.p[1].checked==true)
{ge1='i';gep='http://images.'+get0+'images'+get1+'images&hl=es&'}
else {ge1='n';gep='http://news.'+get0+'news'+get1+'off&num=30&'}}
{
	gec='';
	//gec='cr=countryCL&'	//chile
}
{
	gel='';
	gel='lr=lang_es&' 	//espanol
}
{
	
	ger='q=';
	/*if (document.gef.r.checked==false){
		ger='q='
	}else {
		ger='as_epq='
	}*/
}
var geu=gep+gec+gel+ger+gev;
window.open(geu);
return false;
{
}
}


/*CARGA FECHAS EN LOS FORMULARIOS*/
function load_year(){
	var mydate=new Date();
	var year=mydate.getYear() - 14;
	var cantidad=year-1939;
	document.formulario.year.length=cantidad;
	var j=0;
	var ll;
	var a;
	for(i=year;i>=1940;i--){
		a=''+i;
		document.formulario.year.options[j].value=i;//a.substring(2,4);
		document.formulario.year.options[j].text=i;
		j++;
	}
}


function populate(objForm,selectIndex) {
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text, objForm.month.options[objForm.month.selectedIndex].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
objForm.day.length=daysInMonth;
//for (var i = 0; i < objForm.day.length; i++) {
//	objForm.day.options[0] = null;
//}
for (var i = 0; i < daysInMonth; i++) {
	//objForm.day.options[i] = new Option(i+1);
	objForm.day.options[i].value = i + 1;
	objForm.day.options[i].text = i + 1;
}
document.formulario.day.options[0].selected = true;
}
function getYears() {

var years = new Array(1997,1998,1999,2000,2001,2005)

for (var i = 0; i < document.formulario.year.length; i++) {
document.formulario.year.options[0] = null;
}
timeC = new Date();
currYear = timeC.getFullYear();
for (var i = 0; i < years.length; i++) {
document.formulario.year.options[i] = new Option(years[i]);
}
document.formulario.year.options[2].selected=true;
}
window.onLoad = getYears;









var cspbFO=true;
var cspbTL=0;
var cspbTD=0;
var cspbGDH=0;
var cspbGD;
var cspbEIA=false;

function Menu(llave, cantidad) {
	this.llave		= llave;
	this.cantidad	= cantidad;
	this.autoClose	= true;
	this.closeAll	= true;
	this.colaspseHeight = true;
	var iDelay = 3000 ;
	var sDisplayTimer = null;
	var oLastItem = true;
	var iNSWidth = 100;
	
	var enUso = false;
	var entrada		= new Array();
	var content		= new Array();
	
	isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
	isIE    = (document.all && !isOPERA)? true : false;
	isDOM   = (document.getElementById && !isIE)? true : false;
	
	this.initArray = function() {
		for (x=0; x < this.cantidad; x++) {
			entrada [this.llave + "_" + x] = true;
		}
	}
	
	this.make_menu = function(id){
		if(cspbEIA){
			return;
		}
		if(this.closeAll) {
			this.hide_all();
		}
		if (entrada[this.llave + "_" + id]) {
			this.show (id);
			for (x=0; x < this.cantidad; x++){
				entrada [this.llave + "_" + x] = true;
			}
			if(this.autoClose) {
				entrada[this.llave + "_" + id] = false;
			}
		}else{
			if(this.autoClose) {
				this.hide(id);
			}
			entrada[this.llave + "_" + id]=true;
		} 
	}	
	
	this.hide_all = function() {
		for (i=0; i<this.cantidad;i++){
			this.hide(i);
		}
	}
	
	this.hide = function(id){
		if (isDOM) {
			el	= document.getElementById(this.llave +  "_" + id);
		} else if (isIE) {
			el = document.all[this.llave + "_" + id];
		}
		cspbGD = el;

		el.style.display='none';
		return;
		
		if(this.colaspseHeight)
		{
			cspbGDH = el.offsetHeight;
		}
		else
		{
			cspbGDH = '';//el.offsetWidth;
		}
		objMenu = this;
		cspbEC(0);
	}
	
	
	this.show = function(id){
		
		if (isDOM) {
			el	= document.getElementById(this.llave +  "_" + id);
		} else if (isIE) {
			el = document.all[this.llave + "_" + id];
		}

		el.style.display = "inline";
		cspbGD=el;
		return;
		if(this.colaspseHeight)
		{
			cspbGDH = el.offsetHeight;
			el.style.height=1;
		}
		else
		{
			cspbGDH = el.offsetWidth;
			el.style.width=1;
		}
		objMenu = this;
		cspbEO(cspbGDH);
	}

	this.stopTimer = function () {
		clearTimeout(sDisplayTimer)
	}

	this.startTimer = function () {
	  this.stopTimer()
	  objMenu = this;
	  sDisplayTimer = setTimeout('callHideItem()',iDelay)
	}

	this.hideItem = function () {
		if (oLastItem) {
			this.hide_all();
		}
	}
}
var objMenu;
function callHideItem() {
	objMenu.hideItem();
}


function cspbEO(l){
	var RES=1;
	cspbEIA=true;
	cspbTL=l;

	if(cspbTL==0){
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height=cspbGDH;
		}
		else
		{
			cspbGD.style.width=cspbGDH;	
		}
		cspbEIA=false;
	} else{
		if(cspbTL<=RES){
			cspbTD=1;
		}else{
			cspbTD=parseInt(cspbTL/RES);
		}
		if(cspbGDH!=cspbTL){
			if(objMenu.colaspseHeight)
			{
				cspbGD.style.height=cspbGDH-cspbTL;
			}
			else
			{
				cspbGD.style.width=cspbGDH-cspbTL;
			}
		}
		setTimeout('cspbEO(cspbTL-cspbTD);',20);
	}
}

function cspbEC(l){
	var RES=6;
	cspbEIA=true;
	cspbTL=l;
	if(cspbGDH==cspbTL || cspbGDH<cspbTL){
		cspbGD.style.display='none';
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height=cspbGDH;
		}
		else
		{
			cspbGD.style.width=cspbGDH;
		}
		cspbEIA=false;
	}else{
		if((cspbGDH-cspbTL)<=RES){
			cspbTD=1;
		}else{
			cspbTD=parseInt((cspbGDH-cspbTL)/RES);
		}
		if(objMenu.colaspseHeight)
		{
			cspbGD.style.height = cspbGDH - cspbTL;
		}
		else
		{
			cspbGD.style.width = cspbGDH - cspbTL;
		}
		setTimeout('cspbEC(cspbTL+cspbTD);',10);
	}
}

function MakeMenu(llave, cantidad, colaspseHeight, initArray) {
	try
	{
		menu = new Menu(llave, cantidad);
		if(initArray)
		{
			menu.initArray();
		}
		menu.colaspseHeight = colaspseHeight;
		return menu;
	}
	catch(e)
	{
		return false;
	}
}
