/*
Base de Datos sobre La Region
Base da Datos de la Cultura en La Region
Base de Datos Cutural sobre La Region

*/
// Funciones de objglob.js
function oNavegador(  ) {
	this.nombre = navigator.appName;
	this.iniciar = iniciar;
	this.ponerModVer = ponerModVer;
	this.IE = this.nombre.toUpperCase().indexOf('MICROSOFT') >=0;
	this.NS = this.nombre.toUpperCase().indexOf('NETSCAPE') >=0;
	this.OP = this.nombre.toUpperCase().indexOf('OPERA') >= 0;
	this.XX = !this.IE && !this.NS && !this.OP;
	this.version = this.iniciar();
	this.Verent = parseInt(this.version);
	this.standard = (this.IE && this.Verent >=5) || (this.NS && this.Verent >=5);
	this.modVer = this.ponerModVer();
/* ======================================================================
	FUNCION:	iniciar( ), miembro de oNavegador
	ARGS: 		none.
	DEVUELVE:	nada
	DESCRIP:	Inicializa los valores del objeto
====================================================================== */
  function iniciar() {
  var ver = navigator.appVersion;
  if(ver+"" != "NaN")
	if (this.IE)
		{
		ver.match(/(MSIE)(\s*)([0-9].[0-9]+)/ig);
  		ver = RegExp.$3;
		}
  return ver;
  } //Termina la funcion iniciar el objeto
 //Selector para usar en sentencias switch
 //Los modelos de navegadores serán de la forma IE4, IE5, NS4, NS5 ...
  function ponerModVer()
  {
  if (this.IE) return "IE"+this.Verent;
  if (this.NS) return "NS"+this.Verent;
  if (this.OP) return "OP"+this.Verent;
  return "XXNN";
   }
}

window.miNavegador = new oNavegador();
window.miNavegador.iniciar();
var mie = "IE4, IE5, IE6, IE8, NS5".indexOf(miNavegador.modVer)>=0;
var version=navigator.appVersion, verex;

// Funciones Adicionadas
function isdefined(variable) {// Dice si una variable en javascript existe
    return (typeof(window[variable])=="undefined")? false: true;
}


function cambiar_style(id,style) { 
   //alert(id+"\n"+style);
   var objitem =  document.getElementById(id);
   objitem.className=style; 

}

function create_var(varsele,valor){
  var objitem =  document.getElementById(varsele);
  //alert(varsele+'='+valor);
  objitem.value=valor;
  
}
function set_var(varsele,valor){
  var objitem =  document.getElementById(varsele);
  //alert(varsele+'='+valor);
  objitem.value=valor;
  
}
function set_var(varsele,valor){
  var objitem =  document.getElementById(varsele);
  //alert(varsele+'='+valor);
  objitem.value=valor;
  
}

function div_show_hide(varsele,valor){
  var objitem =  document.getElementById(varsele);
  //alert(varsele+'='+valor);
  objitem.style.display=valor;
  
}
function nextvista_chtmsg(resultado){
    var objclass_txt_chtmsg =  document.getElementById(resultado+"_txt_chtmsg");
	if (objclass_txt_chtmsg.value!='') nextvista=0; else nextvista=1;
}
function div_scroll_move(varsele,valor){
  var divResultado = document.getElementById(varsele);
  //alert(varsele+'='+valor);
  divResultado.scrollTop=valor;
}
function set_var_cond(varsele,valor,cond){
  condicion=0;
  if ((cond!=null)&&(cond!="")) {
	 var objvar =  document.getElementById(cond);  
	 if (objvar!=null) condicion=eval(objvar.value);
  }
  var objitem =  document.getElementById(varsele);
  //alert(objvistas.value);
  if (condicion!=valor) objitem.value=condicion; else objitem.value=valor; 
}

function vista_facein(resultado,num_vista) { //***  Falta ver como pasar como parametro la opacidad y la variable de tiempo temp, que si son globales se puedan actualizar desde aqui y usar la funcion para diferentes variables de opacidad pasadas por parametro
// alert("resultado="+resultado+" |num_vista="+num_vista);
 /* */
var iddestino=resultado+'iddestino';
var tempin=resultado+'tempin';
if (num_vista=="") num_vista=1; else num_vista=1+num_vista; 
if ((semaforo==0)||(semaforo==num_vista)) {
	 
     semaforo=num_vista;
	 opacidad+=10;
	 if (opacidad>99) {
		  eval(tempin+"="+clearInterval(eval(resultado+'tempin')));
		  opacidad=100;
		  semaforo=0;
	  }
	  //alert("JGR_facein opacidad"+opacidad+" | semaforo"+semaforo);
	  obj = document.getElementById(eval(resultado+'iddestino'));
	  if (document.all)
		obj.style.filter = 'alpha(opacity='+opacidad+')';
	  else
		obj.style.MozOpacity = opacidad/100; 
 } // Fin if ((semaforo==0))&&(semaforo==1)) 
}

function vista_faceout(resultado,num_vista) {
 //eval(vartimeout+"="+clearTimeout(eval(resultado+'vartimeout')));
 // alert("iddestino="+iddestino+" | opacidad="+opacidad +"| temp="+temp);
/* */
 var iddestino=resultado+'iddestino';
 var tempout=resultado+'tempout';
 
 if (num_vista=="") num_vista=2;  else num_vista=2+num_vista; 
 if ((semaforo==0)||(semaforo==num_vista)) {
	  semaforo=num_vista;
	  opacidad-=10;
      if (opacidad<1) {
		  eval(tempout+"="+clearInterval(eval(resultado+'tempout')));
		  opacidad=0;
		  semaforo=0;
		  //clearInterval(temp);
	  }
	  //alert("JGR_faceout opacidad"+opacidad+" | semaforo"+semaforo);
	  obj = document.getElementById(eval(resultado+'iddestino'));
	  if (document.all) {
		obj.style.filter = 'alpha(opacity='+opacidad+')';
		//alert("JGR_00_opacidad alpha="+opacidad);
	  } else {
		obj.style.MozOpacity = opacidad/100; 
	    //alert("JGR_00_opacidad MozOpacity="+opacidad);
	  }
	  //alert("JGR_00_eval(resultadoiddestino)="+eval(resultado+'iddestino'));
 } // Fin if ((semaforo==0))&&(semaforo==2))
}

function vista_efecto_face_consulta(iddestino,datos,datos_encode,resultado,page,num_page,num_rec,limite_page,width_v,height_v,bgcolor_v,timewait)  {
 /**/
 var iddestino=resultado+'iddestino';
 var tempout=resultado+'tempout';
 var objtiposql =  document.getElementById(resultado+"_tipo_sql");
 if ((objtiposql.value=="6")||(objtiposql.value=="6,")||(objtiposql.value=="6,1")||(objtiposql.value=="7")||(objtiposql.value=="7,")||(objtiposql.value=="7,1"))  vistachat=1; else vistachat=0;
 if (num_page=="") num_vista=3; else num_vista=3+num_page; 
 if ((semaforo==0)||(semaforo==num_vista)) {
	  var tempin=resultado+'tempin';
	  semaforo=num_vista;
	  opacidad-=10;
      //alert(" vista_efecto_face_consulta-tempout=> "+"iddestino="+iddestino+" | opacidad="+opacidad +"| semaforo="+semaforo+"| num_page="+num_page+"| "+resultado+"tempout="+eval(resultado+'tempout'));
	  if (vistachat!=1)opacidad=-1;
	  if (opacidad<1) {
		  //alert(" vista_efecto_face_consulta-tempout=> "+"iddestino="+iddestino+" | opacidad="+opacidad +"| semaforo="+semaforo+"| num_page="+num_page+"| "+resultado+"tempout="+eval(resultado+'tempout'));	 
          eval(tempout+"="+clearInterval(eval(resultado+'tempout')));
		  
		  if (vistachat!=1) opacidad=0; else opacidad=100;
		  opacidad=0;
		  semaforo=0;
		  if ((eval(resultado+'tempin')==null)&&(eval(resultado+'tempout')==null)) 
		     mostrar_consulta(datos,datos_encode,resultado,page,num_page,num_rec,limite_page,width_v,height_v,bgcolor_v,timewait);
	  }
	  obj = document.getElementById(eval(resultado+'iddestino'));
	  if (vistachat!=1) {
		  if (document.all) obj.style.filter = 'alpha(opacity='+opacidad+')';
		  else obj.style.MozOpacity = opacidad/100; 
	  } else opacidad = 0;
 } // Fin if ((semaforo==0))&&(semaforo==2))
}

function call_p(intervalo) {
	alert("JGR_01");
}
function call_vista_efecto_consulta(intervalo,iddestino,datos,datos_encode,resultado,page,num_page,num_rec,limite_page,width_v,height_v,bgcolor_v,timewait) {
  // Por el momento existe uno solo pero debe ser un case de efectos, podria usarse como parametro para el case el iddestino que es el mismo que resultado
  //alert("iddestino="+iddestino+" | intervalo="+intervalo+" | resultado="+resultado+" | eval(resultado+tempin)="+eval(resultado+'tempin')+" | eval(resultado+tempout)="+eval(resultado+'tempout'));
  var tempout=resultado+'tempout';
  if (isdefined(resultado+'iddestino')) { 
	  if ((eval(resultado+'tempin')==null)&&(eval(resultado+'tempout')==null)){
		  //eval(tempout+"="+setInterval('call_p(40)',intervalo)); 
		  //alert(" timewait="+timewait); 
		  //alert(" isdefined(resultadoiddestino)="+isdefined(resultado+'iddestino')); 
		  //
		  //alert("num_page="+num_page); 
		  //alert("resultado="+resultado); 
		  //alert(eval(resultado+'iddestino')); 
		  eval(tempout+"="+setInterval('vista_efecto_face_consulta("'+resultado+'","'+datos+'","'+datos_encode+'","'+resultado+'","'+page+'",'+num_page+','+num_rec+','+limite_page+','+width_v+','+height_v+',"'+bgcolor_v+'",'+timewait+')',intervalo));
		   
	  } 
  } else  {
	  //alert(" false isdefined(resultadoiddestino)="+isdefined(resultado+'iddestino')); 
	  mostrar_consulta(datos,datos_encode,resultado,page,num_page,num_rec,limite_page,width_v,height_v,bgcolor_v,timewait);
  }
  //mostrar_consulta("'"+datos+"'","'"+datos_encode+"'","'"+resultado+"'","'"+page+"'",0,num_rec,limite_page,width_v,height_v,"'"+bgcolor_v+"'",timewait);
  
//"'"++"'"  //mostrar_consulta('"+datos+"','"+datos_encode+"','"+resultado+"','"+page+"',0,"+num_rec+","+limite_page+","+width_v+","+height_v+",'"+bgcolor_v+"',"+timewait+");
 
}


function objetoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
  		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


function mostrar_consulta(datos,datos_encode,resultado,page,num_page,num_rec,limite_page,width_v,height_v,bgcolor_v,timewait){
//Variables de la funcion mostrar_consulta(datos,var_adicional,resultado,page,num_page,num_rec,limite_page,width_v,height_v)
//Muestra consulta de la página 'datos' que puede tener parametros adicionales que se almacenan como parametro en 'var_adicional', el resultado de la consulta se pondrá en 'resultado', el número de página almacenado en la variable 'page' es el número 'num_page' si es que es>0, se mostraran por página una cantidad de elementos 'num_rec' con un límite de página 'limite_page', todo se muestra en un area de ancho 'width_v' y alto 'height_v'  
    //var test_var = 'Hello'; var var_name = 'test_var'; eval(var_name+"='Goodbye'"); 
    /* 	var i=1; eval('name' + i + ' = "Marco"'); document.write('got ' + name1);*/
	//alert('page_js='+page);
	//alert('JGR_00');
	//var vajax='ajax_'+resultado;
	var arr_ajax = new Array();
    
	var vartimeout=resultado+'vartimeout';
	var divResultado = document.getElementById(resultado);
	var divResultado_name = document.getElementsByTagName(resultado+"_00");
	var objfuncValues =  document.getElementById(page);
	var objtimeout =  document.getElementById(resultado+"_timeout");
	var objtipovistas =  document.getElementById(resultado+"_tipo_vista");
	var objtiposql =  document.getElementById(resultado+"_tipo_sql");
	
	var objvistasbtn =  document.getElementById(resultado+"_vistas_ini");
	var objvistasdiv =  document.getElementById(resultado+"_div_btn");
	var objclassvistas =  document.getElementById(resultado+"_class_vista");
	var aux_objfuncValues;
	var tempin=resultado+'tempin';
	var iddestino=resultado+'iddestino';
	var objclass_txt_chtmsg =  document.getElementById(resultado+"_txt_chtmsg");// Para enviar los textos escritos en txt_chatmsg
	var objtipo_mtdo =  document.getElementById(resultado+"_mtdo");
	var mtdo; // GET=> no refresca rapido  POST=> Refresca los datos en cada accion
	if (objtipo_mtdo!=null) mtdo=objtipo_mtdo.value;
	if ((mtdo!="GET")&&(mtdo!="POST")) mtdo="GET"; // Validar por si el valor no es valido
	var nextvista_aux;
	nextvista_aux=1;
	var vistachat=0;
	if ((objtiposql.value=="6")||(objtiposql.value=="6,")||(objtiposql.value=="6,1")||(objtiposql.value=="7")||(objtiposql.value=="7,")||(objtiposql.value=="7,1"))  {
		vistachat=1; //Var auxiliar, Es para saber si es la visa de chat
		//var nextvista_aux=1; // Variable auxiliar para saber si: 1=> se pasa la proxima vista ; 0=>Se queda en la misma vista
		if (nextvista<1) nextvista_aux=0;
	}
	
	var objclass_txt_trace =  document.getElementById("txt_trace");
	if (objclass_txt_trace!=null) 
	    objclass_txt_trace.value="height_v="+height_v+" | objfuncValues="+objfuncValues.value+" | vistachat="+vistachat;
	if (limite_page>0) objvistasdiv.style.display=''; else objvistasdiv.style.display='none';
	eval(vartimeout+"="+clearTimeout(eval(resultado+'vartimeout')));
	if ((timewait==null)||(timewait=="")||(timewait<=0)) {
		var objtimewait =  document.getElementById(resultado+"_timewait");
	    var objtimewait_ini =  document.getElementById(resultado+"_timewait_ini");
	    if ((timewait==0)&&(objtimewait_ini!=null)&&(objtimewait_ini.value!="")&&(objtimewait.value>0)) 
		   objtimewait.value = objtimewait_ini.value;
		if ((objtimewait==null)||(objtimewait.value=="")||(objtimewait.value<=0)) timewait=10000; else timewait=objtimewait.value;
	    
		//alert('JGR_01');
	}
    
	//Si num_page=0 se incrementa 1, Si num_page>0 se va esa pagina, Si num_page<0 se decrementa en 1, Si num_page="" solo se activa timeout
	//alert("objtimewait="+timewait);
	if ((num_page==0)&&(nextvista_aux==1)){
	   //if (objfuncValues) aux_objfuncValues = objfuncValues.value; else alert("JGR");
	   aux_not= parseInt(objfuncValues.value) + 1;
	   if (aux_not>limite_page) objfuncValues.value=1; else objfuncValues.value=aux_not;
	}
	if (num_page>0){
	   if (num_page>limite_page) objfuncValues.value=1; else objfuncValues.value=num_page;
	}
	if (num_page<0){
	   aux_not= parseInt(objfuncValues.value) - 1;
	   if (aux_not<=0) objfuncValues.value=limite_page; else objfuncValues.value=aux_not;
	}
		
	//Activar el GIF de actualizando en el boton seleccionado
	if ((num_page!=null)&&(objvistasbtn.value>0)) {
		for (i=1; i<limite_page+1; i++) {
			
			if (eval(objfuncValues.value) == i) {
				style="style_vistas_cargando"; 
			    result_vistas=resultado+"_a_vista_style_"+i;
			    cambiar_style(result_vistas,style);
			}
		}
	}
	if (num_page==0) num_page=objfuncValues.value;
	datos_aux=datos; 
	//alert("bgcolor_v="+bgcolor_v);
	//alert("objfuncValues_value="+objfuncValues.value);
	
	datos=datos+"&datos_encode="+datos_encode+"&resultado="+resultado+"&page="+page+"&"+page+"="+eval(objfuncValues.value)+"&num_page="+num_page+"&num_rec="+num_rec+"&limite_page="+limite_page+"&width_v="+width_v+"&height_v="+height_v+"&bgcolor_v="+bgcolor_v+"&timeout="+objtimeout.value+"&tipo_vista="+objtipovistas.value+"&tipo_sql="+objtiposql.value+"&timewait="+timewait;
	//Esto esun caso especial para los mensajes de chat
	if ((objtiposql.value=="7")||(objtiposql.value=="7,")||(objtiposql.value=="7,1"))  {
		//alert(" objclass_txt_chtmsg="+objclass_txt_chtmsg.value); 
		if (objclass_txt_chtmsg.value!='') datos=datos+"&txtchatmsg="+objclass_txt_chtmsg.value;
	    //divResultado.scrollBy(1,-20); 
		
		//alert(" objclass_txt_chtmsg="+objclass_txt_chtmsg.value); 
	}
	
	//divpage_not = document.getElementById('page_not');
	if (num_page!=null) {
		
		arr_ajax[resultado]=objetoAjax();
		arr_ajax[resultado]=objetoAjax();
		arr_ajax[resultado].open(mtdo, datos);
		arr_ajax[resultado].onreadystatechange=function() {
			if ((arr_ajax[resultado].readyState==4)) {
				//if (vistachat==1) {  eval(tempout+"="+setInterval('vista_faceout("'+resultado+'",1)',40)); }
				//if (vistachat==1) opacidad=0;
				divResultado.innerHTML = arr_ajax[resultado].responseText;
				//Actualizar los botones 
				if (objvistasbtn.value>0) {
					for (i=1; i<limite_page+1; i++) {
						if (eval(objfuncValues.value) != i) style=objclassvistas.value; else style=objclassvistas.value+'_select'; 
						//alert(resultado);
						result_vistas=resultado+"_a_vista_style_"+i;
						cambiar_style(result_vistas,style);
						//aux+="\n objfuncValues_value="+objfuncValues.value+"!=  i="+i+" style="+style;
					}
				     //alert("eval("+resultado+"iddestino)="+eval(resultado+'iddestino'));
					 /**/
					/* */
					
				}
				if (isdefined(resultado+'iddestino')) { 
						 //if ((isdefined(resultado+'tempin'))&&(isdefined(resultado+'tempout'))){
						   eval(tempin+"="+setInterval('vista_facein("'+resultado+'",1)',40));
							//eval(tempin+"="+setInterval('vista_facein(eval('+resultado+'iddestino),"'+resultado+'",1)',40));
						 //}
				}
				if ((objtiposql.value=="7")||(objtiposql.value=="7,")||(objtiposql.value=="7,1")) 
				   objclass_txt_chtmsg.value="";
				//alert(" objclass_txt_chtmsg="+objclass_txt_chtmsg.value); 
				
			}
		}
		arr_ajax[resultado].send(null);
		if (vistachat==1) { divResultado.scrollTop=width_v*height_v;} // Mover scroll del chat hasta el final
	}
    
	if (vistachat==1) { divResultado.scrollTop=width_v*height_v;} // Mover scroll del chat hasta el final
	if (objtimeout.value!=0) {
	   datos=datos_aux;
	   //alert("call_vista_efecto_consulta(40, | iddestino="+iddestino+", | rqesultado="+resultado);   
	   //alert(" timewait="+timewait); 	
	   if (num_page==null) num_page=objfuncValues.value;
	   if (nextvista_aux!=0) num_page_aux=0; // 0=> Continua hacia la proxima vista; >0 Va esa vista especifica
	   else num_page_aux=num_page; 
	   if (isdefined(resultado+'iddestino'))  resultado_aux=resultado+'iddestino'; else resultado_aux=resultado;
	   eval(vartimeout+"="+setTimeout("call_vista_efecto_consulta(40,'"+eval(resultado_aux)+"','"+datos+"','"+datos_encode+"','"+resultado+"','"+page+"',"+num_page_aux+","+num_rec+","+limite_page+","+width_v+","+height_v+",'"+bgcolor_v+"',"+timewait+")",timewait));
	}
}

function ini_div_result(resultado,w,h) { //Inicializar el Div de Resultado, por problemas de compatibilidad
//alert("resultado="+resultado+" |w="+w+" |h="+h); 
 if (isdefined(resultado+'iddestino')) {   
   var iddestino=resultado+'iddestino';
   switch (miNavegador.modVer){
		case "IE4":
		case "IE5":
		case "IE6":
		case "IE7":
		case "NS5":/**/
			obj = document.getElementById(eval(resultado+'iddestino'));
			obj.style.width = w;
			obj.style.height = h;
			obj.style.filter = 'alpha(opacity="100")';
			break;
	}/**/
 }
}


