var objeto;
var module;
var conten;
var page;
var variables=Array();
var reservado=Array("hsbToRgb","rgbToHsb","rgbToHex","test","each","getLast","getRandom","include","merge","extend","associate","contains","remove","copy","hexToRgb","indexOf","some","every","map","filter","forEach"); //Varores existentes por defecto en un array
//AŅADE VARIABLE AL ARRAY DE VARIABLES;



function cargaCategoria(id,unidad){
						
			//window.document.getElementById("ContentBody").innerHTML="<table width='100%' ><tr ><td align='center' ><img src='./images/loading.gif'></td></tr></table>";
			//resetVariable();
			//setVariable("fpage","home/contenido_display");
			//setVariable("caegoria",id);
			//setVariable("unidad",unidad);
			//CargaComponente("ContentBody");
			if(unidad==0){
				if(id == 70){
					window.document.location.href="http://www.lafase.cl/";
				}else{
					window.document.location.href="./?seccion_id=CONTENIDO&idioma="+unidad+"&categoria="+id;
				}
			}else{
				if(id == 70){
					window.document.location.href="http://www.lafase.cl/";
				}else{
					window.document.location.href="./?seccion_id=CONTENI2&idioma="+unidad+"&categoria="+id;
				}
			}
	}

function setVariable(nom,val){
			this.variables[nom]=val;
		} 
//FIN


//RESETEA ARRAY DE VARIABLES		
function resetVariable(){
			this.variables=Array();			
		} 
//FIN

//FUNCION GENERICA PARA CARGAR UN AJAX
function CargaComponente(contenedor,onComplete){	
	var ajax = new sack();
	ajax.resetData();
	for(key in this.variables ){
			if(!reservado[key]){
				//alert(variables[key]);
				ajax.setVar(key,variables[key]); 
				
			}
			
		}

	ajax.setVar("print","1"); 
	if(onComplete){
		
			funcion="ajax.onCompletion = "+onComplete+";";
			
			eval(funcion);
		
		}
	ajax.requestFile = "./";
	ajax.method = 'GET';
	ajax.element = contenedor;
	ajax.runAJAX();		
	//alert(contenedor);

}
//FIN

//FUNCION PARA CARGAR VENTANAS
function llamaVentana(id){
		new Control.Modal($(id),{
			iframe: true,
			width: 400,
			height: 350
		});
	

}

		
//FIN
//FUNCION PARA CARGAR  FORMULARIO y MENU DE UN OBJETO
function CargaFormulario(mod,pag){
	this.module=mod;
	resetVariable();
	setVariable("bpage",mod+"/"+pag+"_m");
	CargaComponente("NOTICIAS_PORTAL");
	setVariable("bpage",mod+"/"+pag+"_f");
	CargaComponente("ContentBody");

}
//FIN

//FUNCION PARA CARGAR BUSCADOR , LISTADOR Y PROCESO
function CargaBuscador(mod,pag,obj){
		
	this.objeto=obj;	
	this.module=mod;
	this.page=pag;
	resetVariable();
	setVariable("bpage",mod+"/"+pag+"_b");
	CargaComponente("NOTICIAS_PORTAL","setupObjeto");

}





function setupObjeto(ord,obj,mod,pag){
		
		if(obj)
			objeto=obj;
		if(mod)
			module=mod;
		if(pag)
			page=pag;
		if(!ord)
			ord="";
document.getElementById('proceso').src="./?page=home/procesador&print=1&objeto="+objeto+"&mod="+module+"&pag="+page+"&order="+ord;
}
//FIN

//INCLUIR JS DEL MODULO CORRESPONDIENTE (se carga en el onLoad del Page)

function incluirJs(){ 
	var filename="./modules/"+module+"/js/script.js";
	var body = document.getElementsByTagName('body').item(0); 
	script = document.createElement('script'); 
	script.src = filename; 
	script.type = 'text/javascript'; 
	body.appendChild(script) 
	
}

//FIN


//FUNCION VOLVER 
function backList(obj){
	document.getElementById("listForm").style.display="none";
	document.getElementById("ShowroomForm").style.display="none";
	resetVariable();
	setVariable("bpage",module+"/"+obj+"_b");
	CargaComponente("NOTICIAS_PORTAL");
	resetVariable();
	setVariable("bpage",module+"/"+obj+"_L");
	CargaComponente("ContentBody");

	
}//FIN

//Funcion utilizada por  los paginadores
function changePage(page,mod){
		var ajax = new sack();
		x=document.getElementById("offset_list").value;	
		resetVariable();
		setVariable("bpage",mod+"/"+page);
		setVariable("fl",1);
		setVariable("offset_list",x);
		CargaComponente("ContentBody");
	}

//FIN


function cargarContenido(id){
	
		resetVariable();
		setVariable("fpage","home/contenido_display");
		setVariable("id",id);
		CargaComponente("ContentBody");
	}

//FUNCONES EXTRAS!!!!!!



function debug(s){
	
		if(s==1){
			window.document.getElementById("proceso").style.display="block";
			window.document.getElementById("procesoForm").style.display="block";
			window.document.getElementById("DEBUG").href="javascript:debug('-1');";
		
		}else{
			window.document.getElementById("proceso").style.display="none";
			window.document.getElementById("procesoForm").style.display="none";
			window.document.getElementById("DEBUG").href="javascript:debug('1');";
			
			}
			
		document.getElementById('proceso').style.position = "absolute";
		document.getElementById('proceso').style.zindex = "15000";
		document.getElementById('proceso').style.height = "91";
		document.getElementById('proceso').style.width = "563px";
		document.getElementById('proceso').style.border="double";
		document.getElementById('proceso').style.top = "11px";
		document.getElementById('proceso').style.left = (document.body.clientWidth/2-210)+'px';
		
		document.getElementById('procesoForm').style.position = "absolute";
		document.getElementById('procesoForm').style.zindex = "15000";
		document.getElementById('procesoForm').style.border="double";
		document.getElementById('procesoForm').style.height = "91";
		document.getElementById('procesoForm').style.width = "563px";
		document.getElementById('procesoForm').style.top = "620px";
		document.getElementById('procesoForm').style.left = (document.body.clientWidth/2-203)+'px';
		
		
	
}

function csv(objeto){
		
		window.document.getElementById('proceso').src="./?page=ajax/genera_csv&objeto="+objeto;
		
		
	
	}




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];}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


//FUNCIONES LOGIN//
function opciones_usuario(){
	//alert('jano');
	ajax.resetData();
	ajax.setVar("page","home/user_option"); // recomended method of setting data to be parsed.
	ajax.setVar("print","1"); // recomended method of setting data to be parsed.
	ajax.requestFile = "./";
	ajax.method = 'POST';
	ajax.element = 'LoginUsuario';
	ajax.runAJAX();

}

function onchange_optionUser(){
	option = document.getElementById('OptionUser').value;
	//alert(option);
	var ajax = new sack();
	if(option == 10){
		window.location.href="./?unidad=0&seccion_id=MIS_DATOS_F";
	}
	if(option == 20){
		window.location.href="./?unidad=1000";
	}
	if(option == 30)
		window.location.href="./?page=admin/index";

	if(option == 40){
		window.location.href="./?unidad=0&seccion_id=INTRANET_F";
	}
	
	if(option == 50){
		window.location.href="./?func=userLogout&unidad=0";
	}
}

//FIN FUNCIONES LOGIN//

function cargaIntra(dir,id_curso){
	
	//var ajax = new sack();
	resetVariable();
	setVariable("fpage","intranet/"+dir);
	setVariable("id_curso",id_curso);
	CargaComponente("RESULTADO");
	//alert(dir);
	
	
}

//FUNCION PARA LA AGENDA DE MI CURSO//


function cargaCalendario(id_curso,tipo){
	//alert(id_curso);
	m=document.getElementById("mes").value;
	//alert(m);
	resetVariable();
	if(tipo){
		setVariable("page","home/agenda_C");
	}else{
		t=document.getElementById("t_contenido").value;
		setVariable("t_cont",t);
		setVariable("fpage","intranet/agenda_C");
	}
	setVariable("mes",m);
	setVariable("id_curso",id_curso);
	
	CargaComponente("CALENDARIO");
}

function cargaContenido(anno,mes,dia,t_cont,id_curso,tipo){
	//alert(t_cont);
	resetVariable();
	if(tipo){
		setVariable("page","home/agenda_L");
	}else{
		setVariable("id_curso",id_curso);
		setVariable("fpage","intranet/agenda_L");
	}
	setVariable("anno",anno);
	setVariable("mes",mes);
	if(dia){
		setVariable("dia",dia);
	}
	setVariable("t_cont",t_cont);
	CargaComponente("listadoContenido");
}

function detalleAgenda(contenido_id,tipo){
	resetVariable();
	if(tipo){
		setVariable("page","home/agenda_D");
	}else{
		setVariable("fpage","intranet/agenda_D");
	}
	setVariable("contenido_id",contenido_id);
	CargaComponente("DivCuerpoF");
	cargaVentana("DivVentantaF","Detalle Actividad",550,230,310,250);
}

//FIN FUNCIONES AGENDA//

//FUNCIONES ALIANZA FRANCESA//
function Contenido(unidad){
	//alert('SIIII');

	//resetVariable();
	//setVariable("fpage","home/contenido_display");
	if(unidad){
		if(unidad==0)
			window.document.location.href="./?seccion_id=CONTENIDO&idioma="+unidad;
		else
			window.document.location.href="./?seccion_id=CONTENI2&idioma="+unidad;
	}else{
		window.document.location.href="./?seccion_id=CONTENIDO";
	}	
	//CargaComponente("contentBody");
	
}

function detalleContenido(id,ct,idioma){
	//resetVariable();
	//alert('SIIII');
	if(ct!='SIN'){
		if(idioma==0)
			window.document.location.href=".?seccion_id=DETALLE_CONTENIDO&idioma="+idioma+"&contenido_id="+id+"&categoria="+ct;
		else
			window.document.location.href=".?seccion_id=DETALLE_CONTENI2&idioma="+idioma+"&contenido_id="+id+"&categoria="+ct;
	//setVariable("categoria",ct);
	}else{
		if(idioma==0)
			window.document.location.href=".?seccion_id=DETALLE_CONTENIDO&idioma="+idioma+"&contenido_id="+id;
		else
			window.document.location.href=".?seccion_id=DETALLE_CONTENI2&idioma="+idioma+"&contenido_id="+id;
	}
	//setVariable("fpage","home/contenido_detalle");
	//setVariable("contenido_id",id);
	//CargaComponente("contentBody");
	
	
}


//FUNCION CAMBIA CURSO//
function changeCurso(){
	//alert('siii');
	cur=document.getElementById("curso_asig").value;
	//alert(cur);
	window.location.href="./?seccion_id=INTRANET_F&unidad=0&id_curso="+cur;	
	
}

function desplegar(){
			document.getElementById('despliega_formulario').style.height = "370";
			document.getElementById('despliega_formulario').style.width = "460";
			document.getElementById('despliega_formulario').style.top = "50";
			document.getElementById('despliega_formulario').style.left = document.body.clientWidth/2-200;
			document.getElementById('despliega_formulario').style.position = "absolute";
			document.getElementById('despliega_formulario').style.display = "block";
	}
//FIN FUNCION CAMBIA CURSO//

//CARGAR FORMULARIO//
function cargarFormulario(id){
	
	resetVariable();
	setVariable("page","home/formulario"); // recomended method of setting data to be parsed.
	setVariable("id_formulario",id);
	//setVariable("id_curso",id_curso);
	CargaComponente("despliega_formulario","desplegar");


}
//FIN CARGAR FORMULARIO

function FormularioContenido(anno,mes,dia,t_cont){
	alert(t_cont);
	document.getElementById('listadoContenido').style.height = "370";
	document.getElementById('listadoContenido').style.width = "460";
	document.getElementById('listadoContenido').style.top = "50";
	document.getElementById('listadoContenido').style.left = document.body.clientWidth/2-200;
	document.getElementById('listadoContenido').style.position = "absolute";
	document.getElementById('listadoContenido').style.display = "block";
	document.getElementById('listadoContenido').src = "./?page=home/agenda_L&unidad=0&print=1&t_cont="+t_cont+"&anno="+anno+"&mes="+mes+"&dia="+dia;

}

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];}
}

