/**
 * @package	GeoDatum
 * Proyecto	:	GeoDatum - Sistema de Información Territorial
 * Archivo	:	enc.js
 *
 * @link http://www.siigsa.cl
 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
 * @since 04-02-2010
 * @version 1.0.18
 * 
 * Archivo JS del sistema INICIO, se cargan funciones y prototipos genericos para todos
 * los formularios y paginas del sistema.
 *
 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl> 
 * @since 17-12-2008
 * @version 11
 * redir_popup();
 * 
 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
 * @since 17-03-2009
 * @version 12
 * seleccionarDeseleccionarBuscarContenido()
 *
 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
 * @since 23-04-2009
 * @version 13
 * setFormatoNumero()
 *
 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
 * @since 27-04-2009
 * @version 14
 * setFormatoNumero()
 *
 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
 * @since 01-07-2009
 * @version 15
 * redir()
 *
 * @author Gonzalo Arenas Flores
 * @since 05-08-2009
 * @version 16
 * seleccionarDeseleccionarCHK()
 *
 * @author Gonzalo Arenas Flores
 * @since 12-08-2009
 * @version 17
 * expandirContraerDivisor()
 *
 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
 * @since 04-02-2010
 * @version 18
 * redir()
 */

/*INSTANCIADO DE CLASES JS*/
var oTenc 			= new Tag();
var oNavegador 	= new Navegador();

/*****************************************************
 *																									 *
 *					VALIDACION DE NAVEGADORES								 *
 *																									 *
 *****************************************************/
	
	oNavegador.validarNavegador();
	
	/**
 	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.8
	 * 
	 * Prototipo que verifica espacios en Blanco
	 *
	 * @param string $string	:	texto con espacios
	 * @return string 
	 *
	 */
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };


	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
	 * Prototipo que valida valores numericos
   *
   * @param string $string	:	texto con valores numericos
   * @return boolean 
   *
   */
	String.prototype.isNumeric = function() { 
		var RegExp = /^[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?$/;
		var result = this.match(RegExp);
		if (result==null) result = false;
		else result = true;
		
		return result;
	};


	/**
	 * @link http://www.siigsa.cl
 	 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
 	 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
   * Prototipo que valida si un valor se encuentra en un arreglo
   *
   * @param mixed $obj	:	arreglo de entrada
   * @return boolean
   * 
   */
	Array.prototype.in_array = function ( obj ) {
		var len = this.length;
		for ( var x = 0 ; x <= len ; x++ ) {
			if ( this[x] == obj ) return true;
		}
		return false;
	}

	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
   * Protitpo que retorna el indice de un arreglo segun un valor
   *
   * @param mixed $obj	:	arreglo de entrada
   * @return mixed 
   *
   */
	Array.prototype.array_key = function ( obj ) {
		var len = this.length;
		for ( var x = 0 ; x <= len ; x++ ) {
			if ( this[x] == obj ) return x;
		}
		return false;
	}

	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.1
	 * 
   * Deshabilitacion del clack del mouse
   *
   * @return false 
   */
//	document.oncontextmenu = function() { return false; };


	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.1
	 * 
	 * Impide teclear valores no numericos
	 * 
	 *@param object $e	:	evento
	 *@param string	$objeto	:	referencia a objeto de html
	 *@param string	$tipo_dato	:	Si el 3er parametro (dato) es "float" se permite ingresar un punto para el valor decimal.
	 *
	 * Ejemplo uso onkeypress="return validarNumeros(event, this,'')"
	 *
	 */
	function validarNumeros(e, objeto, tipo_dato){
		
	  tecla = (document.all) ? e.keyCode : e.which;
	  teclasPermitidas = {0:0, 8:0, 13:0, 22:0, 37:0, 39:0};
	  teclasCTRLPermitidas = {c:0, x:0};
	  te = String.fromCharCode(tecla);
	  
	  if ( (tecla in teclasPermitidas) || (e.ctrlKey && (te in teclasCTRLPermitidas))) return true;
	  
	  expresion = "\\d";
	  
	  if (objeto.value.length == 0) {
			expresion += "|-";
	  }
	  
	  if (objeto.value.substr(0,1) == "-")
	  	posPermitirPunto = 1;
	  else 
	  	posPermitirPunto = 0;
	  	
//	  if(tipo_dato == "float" && objeto.value.indexOf(".") == -1 && objeto.value.length > posPermitirPunto) {
//			expresion += "|.";
//	  }

		_obj = objeto.value.split(".");
	  if(tipo_dato == "float" && tecla == 46 && tecla != 44 && _obj.length < 2){
			expresion += "|.";
	  }

	  patron = new RegExp(expresion);
	  return patron.test(te);
	}
	
	
	/**
	 * @link 			http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author 		Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 		01-10-2009
	 * @version 	1.0.1
	 * 
	 * Funcion que valida en ingreso de fecha a mano
	 * 
	 * @param event	e	:	Evento HTML
	 
	 * Ejemplo uso onkeypress = "return enc_validarFecha(event,this)"
	 *
	 */
	function enc_validarFecha(e, _obj) {
		
		tecla = (document.all) ? e.keyCode : e.which;
		
		teclasPermitidas 	= {8:0, 48:0, 49:0, 50:0, 51:0, 52:0, 53:0, 54:0, 55:0, 56:0, 57:0};
		
		if (tecla != 8){
			
			_largo = _obj.value.split('');
			
			/*VALIDACION DE DIAS*/
			if (_largo[0]+_largo[1] == 00 || _largo[0]+_largo[1] > 31){
				alert("No existe el dia. Digite la Fecha nuevamente");
				_obj.value = '';
				return false;
			}
			/*FIN VALIDACION DE DIAS*/
			
			/*VALIDACION DE MESES*/
			if (_largo[3]+_largo[4] == 00 || _largo[3]+_largo[4] > 12){
				alert("No existe el mes. Digite la Fecha nuevamente");
				_obj.value = '';
				return false;
			}
			/*FIN VALIDACION DE MESES*/
			
			/*VALIDACION DE AÑOS*/
			if ( _largo[6] < 1  || _largo[6] > 2 ){
				alert("Formato de año incorrecto. Ingrese fecha nuevamente");
				_obj.value = '';
				return false;
			}
			/*FIN VALIDACION DE AÑOS*/
				
			if (_largo.length == 2 || _largo.length == 5){ _obj.value = _obj.value + '-'; }
			
		}
		
		if ((tecla in teclasPermitidas)){ return true; }
		else { return false; }
		
	} 
	
	/**
	 * @copyright 2008 - SIIGSA
	 * @author Oscar Cardenas Albornoz <ocardenas@siigsa.cl>
	 * @since 04-11-2009
	 * @version 1.0.0
	 * 
	 * Valida que el largo de la fecha sea de 10 digitos
	 */
	function validaLargoFecha(_obj){
		
		if(_obj.value.trim().length != 10 && _obj.value.trim() != "" ){
			alert("Formato de fecha incorrecto. Ingrese nuevamente");
			_obj.value = "";
		}
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.1
	 * 
	 * Formatea un numero con decimales
	 * 
	 *@param string	expr	:	valores numericos
	 *@param string decplaces	:	cantidad de decimaes del numero a mostrar
	 *  
	 */
	function FormatNumber(expr, decplaces) {
	
		var str = "" + Math.round(eval(expr) * Math.pow(10,decplaces));
		while (str.length <= decplaces) {
			str = "0" + str;
		}
	
		var decpoint = str.length - decplaces;
	 
		return str.substring(0,decpoint) + "," + str.substring(decpoint, str.length);
	
	}
	
	
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
   * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
   * @since 27-04-2009
   * @version 1.0.1
   *
   * Da formato a un número.
   *
   * @param String	$numero			:		Número a formatear
   * @param String	$sep_miles	:		Separador de miles
   * @param String	$sep_dec		:		Separador de decimales
   * @param String	$num_dec		:		Número de decimales.
   *
   * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
   * @since 27-04-2009
   * @version 1.0.1
   * toLocaleString();
	 */
	function setFormatoNumero(numero, sep_miles, sep_dec, num_dec){
		
		if(typeof(numero) == "undefined")		{alert("Debe especificar un numero para aplicar el formato");return false;}
		if(typeof(sep_miles) == "undefined"){sep_miles = ".";}
		if(typeof(sep_dec) == "undefined")	{sep_dec = ",";}
		
		var num = '';
		numero += '';
		if(numero != 0){
			num = numero.split(".");
		}
		
		if(num.length > 1){
			return implode(num,'');
		}else{
		
			//Transforma el string del numero a un formato numérico
			//luego lo formatea al definido de forma local en el equipo
			numero_tmp = Number(numero).toLocaleString(); 
			if(isNaN(parseInt(numero_tmp))){return numero;}
			
			var num_tmp = '';
			num_tmp = numero_tmp.split(",");
			
			var entero = replace(num_tmp[0],',','.');
			
			if(num_dec > 0){
				numero = entero + sep_dec + num_tmp[1];
			}else{
				numero = entero;
			}
				
			return numero;
		
		}
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
	 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
	 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 04-02-2010
	 * @version 1.0.14
	 * 
   * Redirecciona pagina segun parametros de query desde GET a POST
   *
   * @param string $parametros	:	parametros de valores
   * @param string $cual	: si es ventana o popup
   *
	 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 28-04-2009
	 * @version 12
	 * Se agrega "/" en el action del form para que regrese siempre al inicio del sistema sin parametros de GET 
	 * 
	 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 01-07-2009
	 * @version 13
	 * Se modifica el codigo para que sea validado por la W3C 
	 * 
	 * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 04-02-2010
	 * @version 14
	 * Se modifica el codigo para que al volver atras con el boton del browser
	 * vuelva a la pagina desde donde fue llamado y no al formulario intermedio,
	 * de esta forma queda solucionado el doble click atras. 
	 * 
   */
	function redir(parametros, _cual){
		
		if (isNaN(_cual)) _cual = 1;
		
		var _param	= parametros.split('#');
		var _form		= "";
		var _var		= "";
		
		
		_form += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\" lang=\"es\"><head><title>" + GC_NOMBRE_APP + " - " + GC_SIGLA_APP + "</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" /></head><body onload='document.forms[0].submit();'><div style='position:relative;border:0px solid red;text-align:center;width:90%;height:50%;top:200px;'><img src='" + GC_WEB_IMG + "/cargando_datos.gif' style='border:0px solid red' alt='Cargando Datos...' title='Cargando Datos...' /></div>";
		_form += "<form method='post' action='/' style='visibility:hidden'><p>";
		
		for (i=0;i<_param.length;i++){
			_var = _param[i].split('=');
			_form += "<input type='hidden' name='" + _var[0] + "' value='" + _var[1] + "' />";
		}
		
		_form += "<input type='submit' value='Cargando' /></p>";
		//_form += "</form><script type='text/javascript'>setTimeout(\"document.forms[0].submit();\",1000);history.go(-1);</script></body></html>";
		_form += "</form><script type='text/javascript'>history.go(-1);</script></body></html>";
		
		if (_cual == 1){
			
			document.write(_form);
			document.forms[0].submit();
			
		}else if (_cual == 2){
			
			if (!window.opener){
				document.write(_form);
				document.forms[0].submit();
			}else{
				window.opener.document.write(_form);
				window.opener.document.forms[0].action = "/";
				window.opener.document.forms[0].submit();
			}
			
		}
		
		/*return true;*/
		
	}
	

	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 05-06-2008
	 * @version 1.0.3
	 * 
   * Abre una ventana segun parametros de definición
   *
   * @param string $_url
   * @param string $_target
   * @param string $_conf
   */
	function ventana(_url, _target, _conf){
		
		if (_target=="" || typeof(_target) == "undefined" )	var _target = "_blank";
		if (_conf=="" ||  typeof(_conf) == "undefined" )	  var _conf		= "toolbar=yes,location=yes,directories=yes,menubar=yes,status=yes,resizable=yes,scrollbars=yes,left=50,top=50,width=640,height=480";
		
		window.open(_url, _target, _conf);
		
//		return true;
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.1
	 * 
   * Deja visible o invisible un elemento con ID
   *
   * @param string $_ele	:	elemento HTML
   *
   */
	function ver(_ele){
		
		
		if (document.getElementById(_ele).style.visibility !=""){
			
			if (document.getElementById(_ele).style.visibility!="hidden"){
				document.getElementById(_ele).style.visibility = "hidden";
			}else{
				document.getElementById(_ele).style.visibility = "visible";
			}
			
		}else{
			
			if (document.getElementById(_ele).style.display!="none"){
				document.getElementById(_ele).style.display = "none";
			}else{
				document.getElementById(_ele).style.display = "";
			}
			
		}
			
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.3
	 * 
   * Llama a la direccion del RSS para leer su contenido
   *
   * @param string _url			:	URL de donde leer el RSS
   * @param string _param		:	Parametros de filtro
   * @param string _div			:	Divisor en donde poner el contenido
   *
   * @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 13-01-2010
	 * @version 4
	 * @param string _titulo	:	Titulo del divisor de listado de contenidos
	 *
   */
	function cargarContenido (_url, _param, _div, _titulo){
		
		_param = _param.replace(/#/g,"&");
		
		document.getElementById(_div).innerHTML = "<img src='" + GC_WEB_IMG + "/load_rss.gif' class='img' alt='Cargando...' /><b>Cargando...</b><br /><br />";
				
		ajax = ObjAjax();
		ajax.open("POST", _url, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(_param);
				
		ajax.onreadystatechange=function(){
			
			leerRSS(ajax, _div, undefined, GC_BULEANO_V, _titulo);
						
		}
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Cristián Gómez Mamani <cgomez@siigsa.cl>
	 * @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 27-08-2009
	 * @version 1.0.21
	 * 
   * Lee el contenido del rss, lo estructura y lo deja en un contenedor determinado
   *
   * @param object $ajax	  :	Objeto ajax creado en la funcion "cargarContendido"
   * @param string $_div	  :	Divisor en donde poner el contenido
   * @param string $buscar	:	Si este parámetro es distinto de vacío 
   * @param string $vermas	:	Parametro que permite saber si el listado de contenidos proviene del ver mas de los divisores
   *
   *
   * @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 27-08-2009
	 * @version 19
	 * Recate del tag <img></img> para poder colocar en los resultados la imagen correspondiente al contenido que se esta listando
	 *
	 * @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 02-12-2009
	 * @version 20
	 * Se agrego el parametro "vermas" que permite saber que el listado que se esta desplegando es de los contenidos que aparecen en el "ver mas" de
	 * los divisores de listados de contenidos
	 *
	 * @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	 * @since 26-02-2010
	 * @version 21
	 * Se cambio la estructura de los contenidos para una mejor visualizacion dentro de divisores de contenidos como de lectores de rss
	 *
   */	
	function leerRSS (ajax, _div, buscar, vermas, titulo){

		var _cont 		= "";

		if (ajax.readyState==4){

			if (ajax.status==200){
//				alert(ajax.responseText);
				var _xml = ajax.responseXML;
				var _its = _xml.getElementsByTagName("item").length;
				
				if (typeof(titulo) != 'undefined' ){
					_cont += '<table style="width:98%;text-align:justify;">';
					_cont += '<tr><td><label class="titulo2">'+ titulo +'</label></td></tr>';
					_cont += '</table>';
				}
				
				/*if (typeof(buscar) == 'undefined'){
					_cont += '<table style="width:98%;text-align:center;">';
					_cont += '<tr><td class="fondo_oscuro">&nbsp;</td></tr>';
					_cont += '</table>';
				}*/
				
				if (typeof(buscar) != 'undefined' && _its == 0){
					_cont += '<table style="width:98%;text-align:center;">';
					_cont += '<tr><td><b>No se encontraron contenidos para el texto ingresado.</b></td></tr>';
					_cont += '</table>';
				}
				
				if (typeof(buscar) != 'undefined' && _its > 0){
					_cont += '<table style="width:98%;text-align:left;">';
					_cont += '<tr><td class="fondo_oscuro" ><label><b>&nbsp;&nbsp;&nbsp;'+ _its +' Resultado(s) a su Búsqueda<br /></b></label></td></tr>';
					_cont += '</table><br />';
				}
				
				if (typeof(vermas) != 'undefined' && _its > 0){
					_cont += '<table style="width:98%;text-align:left;">';
					_cont += '<tr><td class="fondo_oscuro" >&nbsp;</td></tr>';
					_cont += '</table><br />';
				}
				
				for (i=1;i<=_its;i++){
					
					if (_xml.getElementsByTagName("divlist").item(0)){
						var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
						if (_divlist	==	GC_BULEANO_F){
							if (_xml.getElementsByTagName("catalogo").item(i)){
								if (typeof(buscar) != 'undefined' && _its > 0){
									_cont += "<div style='text-align:justify; float:left; width:100px; height:100px; padding-right:5px; padding-left:10px; padding-bottom:150px; padding-top:0px; border:0px solid red; '>";
								}else{
									_cont += "<div style='text-align:justify; float:left; width:100px; height:100px; padding-right:" + GC_PADDING_RIGHT_CATALOGO_RSS + "; padding-left:" + GC_PADDING_LEFT_CATALOGO_RSS + "; padding-bottom:" + GC_PADDING_BOTTOM_CATALOGO_RSS + "; padding-top:" + GC_PADDING_TOP_CATALOGO_RSS + "; border:0px solid red; '>";
								}
							}else{
								if (typeof(buscar) != 'undefined' && _its > 0){
									_cont += "<div style='text-align:justify; float:left; width:100px; height:100px; padding-right:5px; padding-left:10px; padding-bottom:150px; padding-top:0px; border:0px solid blue; '>";
								}else{
									_cont += "<div style='text-align:justify; float:left; width:100px; height:100px; padding-right:5px; padding-left:10px; padding-bottom:30px; padding-top:0px; border:0px solid blue; '>";
								}
							}
						}
					}
					
					var title			=	_xml.getElementsByTagName("title").item(i).firstChild.data;
					var url				= _xml.getElementsByTagName("link").item(i).firstChild.data;
					var guid_tmp	= _xml.getElementsByTagName("guid").item(i).firstChild.data;
					
					if ((typeof(buscar) != 'undefined') || (typeof(vermas) != 'undefined' && _its > 0)){
						if (GC_RSS_NT == GC_BULEANO_V) title = "<H3 style=\'color:orange;\'>" + title + "</H3>";
					}else{
						if (GC_RSS_NT == GC_BULEANO_V) title = "<b>" + title + "</b>";
					}
					
					if (_xml.getElementsByTagName("guid").item(i)){
						var pubDate	= _xml.getElementsByTagName("pubDate").item(i).firstChild.data;
					}else{
						var pubDate = "";
					}
					
					if (_xml.getElementsByTagName("divdesccont").item(i)){
						var _divdesccont = _xml.getElementsByTagName("divdesccont").item(i).firstChild.data;
						if (_divdesccont == GC_BULEANO_V){
							var description = _xml.getElementsByTagName("description").item(i).firstChild.data;
						}else{
							var description = "";
						}
					}else{
						//var description = ""; 
						/*
						pci 2009-10-22, si el RSS es externo y no es sistema nuestro, no va a existir el tag
						divdesccont por lo tanto siempre se muestra la descripcion
						*/
						var description = _xml.getElementsByTagName("description").item(i).firstChild.data;
					}
					
					if (description != ""){ var _verficha = ""; }
					else{ var _verficha = "<br />"; }
					
					if (_xml.getElementsByTagName("divext").item(0)){ 
						if (typeof(_xml.getElementsByTagName("divext").item(0).firstChild.data) == "undefined"){
							var _divext = 'false';
						}else{
							var _divext = _xml.getElementsByTagName("divext").item(0).firstChild.data;
						}
					}else{
						var _divext = 'false';
					}			
					
					var _divficlis	= _xml.getElementsByTagName("divficlis").item(0).firstChild.data;
					
					/*Id objeto*/
					if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){
						if (_xml.getElementsByTagName("idobj").item(i)){
							var _idobj = "<b>"+_xml.getElementsByTagName("idobj").item(i).firstChild.data + "</b><br />";
						}else{
							var _idobj = "";
						}
					}else{
						var _idobj = "";
					}
					
					pubDate = pubDate.split(" -");
					pubDate = pubDate[0];
					
					if (_xml.getElementsByTagName("guid").item(i)){
						var guid = _xml.getElementsByTagName("guid").item(i).firstChild.data;
						
						if (guid.isNumeric()){
							var _caccion = _xml.getElementsByTagName("caccion").item(i).firstChild.data;									
							var _modulo  = _xml.getElementsByTagName("modulo").item(i).firstChild.data;									
							
							if (GC_OBJETO_FICHA == GC_BULEANO_V){
								if (_divext == "true"){
									title = "<label style='cursor:pointer' onclick=\"ventana('" + url + "','_blank')\" >" + title + "</label>";
								}else{
									if (typeof(buscar) != 'undefined'){
										title = "<a href='javascript:;' style='cursor:pointer' onclick=\"redir_popup('/exp/ficha.php','oid=" + guid + "#cont_desde_bus="+ GC_BULEANO_V +"',2)\" ><label>" + title + "</label></a>";/*LA LECTURA NORMAL*/
									}else{
										title = "<label style='cursor:pointer' onclick=\"redir_popup('/exp/ficha.php','oid=" + guid + "',2)\" >" + title + "</label>";/*LA LECTURA NORMAL*/										
									}
									
								}
							}else if (GC_OBJETO_FICHA == GC_BULEANO_F){
								if (_divext == "true"){
									title = "<label style='cursor:pointer' onclick=\"ventana('" + url + "','_blank')\" >" + title + "</label>";
								}else{
									title = "<label style='cursor:pointer' onclick=\"redir('oid=" + guid + "#modaccion=visualizar_ficha')\" >" + title + "</label>";
								}
							}
							
							
							if (_xml.getElementsByTagName("ficha").item(i)){
								
								var _ficha 	 		= _xml.getElementsByTagName("ficha").item(i).firstChild.data;
								var _caccion 		= _xml.getElementsByTagName("caccion").item(i).firstChild.data;
								
								if (_divficlis == "true" || _divficlis.trim() == ""){
									if (_ficha == GC_BULEANO_V){
										if (_divext == "true"){
											_verficha += "<a href=\"javascript:;\" onclick=\"ventana('" + url + "','_blank')\" >" + GC_VER_FICHA + "</a><br />";
										}else{
											_verficha += "<a href=\"javascript:;\" onclick=\"redir_popup('/exp/ficha.php','oid=" + guid + "',2)\" >" + GC_VER_FICHA + "</a><br />";
											_verficha += "&nbsp;" + GC_SEPARADOR_FICHA_MAPA_RSS +"&nbsp;" + _caccion;
										}
									}else if (_ficha == GC_BULEANO_F){
										if (_divext == "true"){
											_verficha += "<a href=\"javascript:;\" onclick=\"ventana('" + url + "','_blank')\" >" + GC_VER_FICHA + "</a><br />";
										}else{
											_verficha += "<a href=\"javascript:;\" onclick=\"redir('oid=" + guid + "#modaccion=visualizar_ficha')\" >" + GC_VER_FICHA + "</a><br />";
											_verficha += "&nbsp;" + GC_SEPARADOR_FICHA_MAPA_RSS + "&nbsp;" + _caccion;
										}
									}
								}else{
									_verficha += "";
								}
								
							}else{
								
								if (_divficlis == "true" || _divficlis.trim() == ""){
									if (_divext == "true"){
										_verficha += "&nbsp;" + GC_SEPARADOR_FICHA_MAPA_RSS + "&nbsp;<a href=\"javascript:;\" onclick=\"ventana('" + url + "','_blank')\" >" + GC_VER_FICHA + "</a><br />";
									}else{
										_verficha += "<a href=\"javascript:;\" onclick=\"redir_popup('/exp/ficha.php','oid=" + guid + "#cont_desde_bus="+ GC_BULEANO_V +"',2)\" >" + GC_VER_FICHA + "</a>";/*LECTURA NORMAL*/
										if (typeof(_caccion) != 'undefined' && _caccion.trim() != ''){
											_verficha += "&nbsp;" + GC_SEPARADOR_FICHA_MAPA_RSS + "&nbsp;" + _caccion + "";	
										}
										if (typeof(_modulo) != 'undefined' && _modulo.trim() != ''){
											_verficha += "&nbsp;" + GC_SEPARADOR_FICHA_MAPA_RSS + "&nbsp;" + _modulo + "";
										}
									}
								}else{
									if (typeof(_modulo) != 'undefined' && _modulo.trim() != ''){
										_verficha += "&nbsp;" + _modulo + "&nbsp;";
									}else{
										_verficha += "";
									}
								}
							}
							
						}else{
							title 			 = "<label style='cursor:pointer' onclick=\"ventana('" + url + "')\" >" + title + "</label>";
							if (_divficlis == "true" || _divficlis.trim() == ""){
								_verficha += "<a href=\"" + url + "\" target=\"_blank\">" + GC_VER_FICHA + "</a><br /><br />";
							}else{
								_verficha += "";
							}
						}	
					}else{
						title 			 = "<label style='cursor:pointer' onclick=\"ventana('" + url + "')\" >" + title + "</label>";
						if (_divficlis == "true" || _divficlis.trim() == ""){
							_verficha += "<a href=\"" + url + "\" target=\"_blank\">" + GC_VER_FICHA + "</a><br /><br />";
						}else{
							_verficha += "";
						}
					}
					
					if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _br = ""; }
					else{	 _br = "<br />"; }
					
					if (_xml.getElementsByTagName("catalogo").item(i)){
						
						var _catalogo = _xml.getElementsByTagName("catalogo").item(i).firstChild.data;
						var _img			=	_xml.getElementsByTagName("img").item(i-1).firstChild.data;
						
						if (GC_RSS_FECHA == GC_BULEANO_V){
							if (description != ""){
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}else{
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}
						}else{
							if (description != ""){
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}else{
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}
						}
					
					}else{
						
						if (GC_RSS_FECHA == GC_BULEANO_V){
							
							var _img = "";
							if (_xml.getElementsByTagName("img").item(i-1)) _img	=	_xml.getElementsByTagName("img").item(i-1).firstChild.data;
							
							if (description != ""){
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}else{
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + pubDate + "<br />" + _idobj + title + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}
						}else{
							
							var _img = "";							
							if (_xml.getElementsByTagName("img").item(i-1)) _img	=	_xml.getElementsByTagName("img").item(i-1).firstChild.data;
							
							if (description != ""){
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _br + description + _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}else{
								if (_xml.getElementsByTagName("divlist").item(0)){
									var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
									if (_divlist	==	GC_BULEANO_V){
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title + _verficha + "</td></tr></table>";
									}else{
										_cont += "<table style='width:90%;' ><tr><td style='vertical-align:top;'>" + _img + "</td></tr><tr><td style='width:100%;text-align:justify;vertical-align:top;'>" + _idobj + title +  _verficha + "</td></tr></table>";
									}
								}
								if (typeof(buscar) != 'undefined' || typeof(vermas) != 'undefined'){ _cont += GC_SEPARADOR_LISTADO_CONTENIDOS_RSS; }else{ _cont += "<br />"; }
							}
						
						}
												
					}
					
					if (_xml.getElementsByTagName("divlist").item(0)){
						var _divlist = _xml.getElementsByTagName("divlist").item(0).firstChild.data;
						if (_divlist	==	GC_BULEANO_F){
							_cont += "</div>";
						}
					}
					
				}
		
				document.getElementById(_div).innerHTML = _cont;
				
			}else{
				
				document.getElementById(_div).innerHTML = "<img src='" + GC_WEB_IMG + "/atencion.gif' class='img' alt='Atenci&oacute;n' /><b>La informaci&oacute;n no ha podido ser recepcionada.</b>";
				
			}
			
		}else{
			
			document.getElementById(_div).innerHTML = "<img src='" + GC_WEB_IMG + "/load_rss.gif' class='img' alt='Cargando...' />Cargando...";
				
		}

	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 10-12-2008
	 * @version 1.0.6
	 * 
	 * Funcion que llama a una página en formato de popup
	 *
	 * @param string $pag					:	URL destino
	 * @param string $parametros	:	Parametros del redireccionamiento
	 */
	function redir_popup(pag,parametros,_cual){
		
		if (isNaN(_cual)) _cual = 1;
		
		var _param	= parametros.split('#');
		var _form		= "";
		var _var		= "";
		
		_form += "<div style='position:absolute;border:0px solid red;text-align:center;width:98%;height:0%;top:200px;'><img src='" + GC_WEB_IMG + "/cargando_datos.gif' border='0' alt='Cargando Datos...' /></div>";
		_form += "<form method='post' action='" + GC_WEB_DIR + pag + "' style='visibility:hidden'>";
	
		for (i=0;i<_param.length;i++){
			_var = _param[i].split('=');
			_form += "<input type='hidden' name='" + _var[0] + "' value='" + _var[1] + "' />";
		}
		
		_form += "<input type='submit' value='Cargando' />";
		_form += "</form><script type='text/javascript'>setTimeout(\"document.forms[0].submit();\",1000);</script>";
		
		var _op = "toolbar=no,location=no,directories=no,menubar=no,status=yes,resizable=yes,scrollbars=yes,left=200,top=200,width=640,height=600";
		
		if  (_cual == 1){
			
			if (window.opener){
				
				document.write(_form);
				document.forms[0].submit();
				
			}else{
				
				var _wo= window.open("",'',_op);
				_wo.focus();
				_wo.document.write(_form);
				_wo.document.forms[0].submit();
				
			}
			
		}else if (_cual == 2){
			
				var _wo= window.open("",'',_op);
				_wo.focus();
				_wo.document.write(_form);
				_wo.document.forms[0].submit();			
				
		}
				
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.13
	 * 
	 * Función para setear los valores del objeto ajax
	 * 
	 * @param string $direc	:	dirección de las operaciones
	 * @param string $parametros	:	valores de los parametros a setear
	 *
	 */
	function setoAjax(direc,parame){
		
		var _res;		
		var _oAjax = new ObjAjax();
		_oAjax.open("POST", direc , true);
		_oAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		_oAjax.send(parame);
		_oAjax.onreadystatechange=function(){
			
			if (_oAjax.readyState==4 && _oAjax.status==200){
				return 1;
			}
			
		}
		if (_oAjax.onreadystatechange == 1){
		 alert(_oAjax);
		}
	
	}

	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
	 * Funciòn que recibe un arreglo y retorna sus datos concatenados 
	 * con el separador enviado por paràmetros
	 *
	 * @param array $arreglo	:	Arreglo a transformar
	 * @param string $separador	:	texto separa los datos del arreglo
	 * 
	 */
	function implode(arreglo,separador){
  	this.arreglo = new Array(arreglo);
  	var s_resultado = '';
  	
  	for(i=0;i<arreglo.length;i++){
  		
  		if(s_resultado == ''){
  			
  			s_resultado = arreglo[i];
  			
  		}else{
  			
  			s_resultado += separador + arreglo[i];
  			
  		}
  		
  	}
  	  	
  	return s_resultado;
  	
  }
  
  
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
	 * Funcion que convierte un hex a numero entero
	 *
	 * @param string $Hex	:	Hexadecimal a transformar
	 * @return string $Value
	 *
	 */
	function GiveDec(Hex){
			
	   if(Hex == "A")
	      Value = 10;
	   else
	   if(Hex == "B")
	      Value = 11;
	   else
	   if(Hex == "C")
	      Value = 12;
	   else
	   if(Hex == "D")
	      Value = 13;
	   else
	   if(Hex == "E")
	      Value = 14;
	   else
	   if(Hex == "F")
	      Value = 15;
	   else
	      Value = eval(Hex);
	
	   return Value;
	   
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
	 * Funcion que convierte un hex a RGB decimal separado por comas
	 *
	 * @param string 	$Hex	:	Hexadecimal a transformar
	 * @return string	
	 *
	 */
	function HexToDec(Hex){
		
		Input = Hex;
		Input = Input.toUpperCase();
		
		a = GiveDec(Input.substring(0, 1));
		b = GiveDec(Input.substring(1, 2));
		c = GiveDec(Input.substring(2, 3));
		d = GiveDec(Input.substring(3, 4));
		e = GiveDec(Input.substring(4, 5));
		f = GiveDec(Input.substring(5, 6));
		
		x = (a * 16) + b;
		y = (c * 16) + d;
		z = (e * 16) + f;

		return x + "," + y + "," + z;
		
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Jose Meneses <jmeneses@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
 	 * Validar correo electronico
   * 
   * @param string $objeto : Input que traigo desde el HTML
   *
   * @see http://javascript.espaciolatino.com/lengjs/jsobjetos/obj_expreg.htm
   * @see http://javascript.espaciolatino.com/lengjs/jsobjetos/expreg/test.htm
   * @see http://www.elcodigo.net/tutoriales/jsavanzado/jsavanzado5.html
   * @see http://www.programacion.net/html/tutorial/js/16/
   * @see http://usuarios.lycos.es/barfak/noticia.php?id=42
   *
   */
	function validar_correo(objeto) {
	
		var s = objeto;
		//var filtro=/[A-Za-z][A-Za-z0-9_]@[A-Za-z0-9_]+\.[A-Za-z0-9_]+[A-za-z]$/;		Primera propuesta
		//var filtro=/^(.+\@.+\..+)$/;																								Segunda Propuesta
		//var filtro=/^[A-Za-z0-9._-]*@[A-Za-z0-9_]+\.[A-Za-z0-9_]+[A-za-z]$/;				Tercera Propuesta
		var filtro=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		
		if (filtro.test(s)) {
			return true;
		}	else {
			alert("Ingrese una dirección de correo válida");
			return false;
		}
	}


	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 27-08-2008
	 * @version 1.0.3
	 * 
 	 * Función que chequea o deschequea un elemento dependiendo del estado que llegue por parametro(true o false)
 	 *
 	 * @param string  $id      			:   ID del objeto a cambiar
 	 * @param string  $name    			:   Nombre en comun de los objeto a cambiar
 	 * @param boolean $estado  			:   Estado final del elemento
 	 * @param boolean $primero_sel  :   Estado final del elemento
 	 *
	 */
	function seleccionaDeseleccionar(id,name,estado,primero_sel){
	  
	  if(id != ''){
	    
	    document.getElementById(id).checked = estado;
	    
	  }else if(name != ''){ 
	    
	    var listado = document.getElementsByName(name);
	    
	    if(listado.length > 0){
	    	
	    	listado[0].checked = true;
		    
	    	if(typeof(primero_sel) != "undefined"){
		    	for(i=1;i<listado.length;i++){listado[i].checked = estado;}
	    	}else{
	    		for(i=0;i<listado.length;i++){listado[i].checked = estado;}
	    	}
	    
	    }
	    
	  }
	  
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 17-03-2009
	 * @version 1.0.0
	 * 
 	 * Función que chequea o deschequea un elemento dependiendo del estado que llegue por parametro(true o false)
 	 *
 	 * @param string  $tcs     			:   ID de los objetos a cabiar de estado
 	 * @param boolean $estado  			:   Estado final del elemento
 	 *
	 */
	function seleccionarDeseleccionarBuscarContenido(tcs,estado){
	  
		var array_tcs  = tcs.split(",");
		for(i=0;i<array_tcs.length;i++){
			
    	document.getElementById("tc_"+array_tcs[i]).checked = estado;
    	
		}
	    
	}

	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.2
	 * 
   * Expande o Contrae los divisores de acuerdo a la norma establecida en la empresa
   *
   * @param string id	:	ID del divisor en la base de datos
   * @param pxs     	:	valor del alto del divisor de posición
   * @param unidad  	:	unidad de medida del alto del parametro "pxs"
   *
   */
  function expandirContraerDivisorParcial(id,pxs,unidad,id_img){

   var img	= '';// imagen de fondo
   if(typeof(id_img) != 'undefined'){img = document.getElementById(id_img);}
  
   var div1 = document.getElementById("D"+id);//Divisor posición
   var div2 = document.getElementById("subD"+id);//Divisor rounded
   var div3 = document.getElementById("divisor"+id);//Divisor contenido
  
    if(div1.style.height == "30px"){//Si elige expandir
      
      div1.style.height = pxs+unidad;
      div2.style.height = (pxs-10)+unidad;
      div3.style.height = (pxs-40)+unidad;
      if(typeof(id_img) != 'undefined'){img.style.height = (pxs-8)+unidad;}
      
    }else{//Si elige contraer
      
      div1.style.height = "30px";
      div2.style.height = "20px";
      div3.style.height = "0px";
      if(typeof(id_img) != 'undefined'){img.style.height = "21px";}
      
    } 
    
  }
  
  
  /**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 20-05-2008
	 * @version 1.0.0
	 * @see http://lineadecodigo.com/2007/08/07/funcion-replace-en-javascript/
	 *
	 * Dado que el REPLACE de javascript solo reemplaza la primera coincidencia,
	 * busqué esta otra función.
	 */
	 function replace(texto,busqueda,reemplazo){
		return texto.split(busqueda).join(reemplazo);
	 }


 /**
	* @link http://www.siigsa.cl
  * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
  * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	* @author Cristián Gómez <garenas@siigsa.cl>
	* @since 20-05-2008
	* @version 1.0.1
	* @see http://snippets.dzone.com/posts/show/1480
	*
	* repite n veces un determinado caracter
	*
	* @param l string	:	Cantidad de veces que se desea repetir el caracter
	* 
	* @return string
	*/
	String.prototype.repeat = function(l) {
		return new Array(l+1).join(this);
	};
	
	
 /**
	* @link http://www.siigsa.cl
  * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
  * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	* @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	* @since 18-07-2008
	* @version 1.0.0
	*
	* Detecta el navegador en el cual nos encontramos. Si el Navegador es Microsoft Internet Explorer 'IE' la variable quedara en buleano verdadero.
	* Sin embargo si el navegador es distinto de 'IE' la variable sera buleano falso.
	*
	* @param buleano qNav	:	Variable que contiene en primera instancia el nombre del Navegador y que definitivamente se convierte en buleano
	*												y con valor determinado segun navegador que sea
	* 
	* @return string
	*/
	var qNav = navigator.appName;
	
	if (qNav == "Microsoft Internet Explorer"){ qNav = true; }
	else{ qNav = false; }
	
	
 /**
	* @link http://www.siigsa.cl
  * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
  * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	* @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	* @since 22-01-2009
	* @version 1.0.1
	* @see http://www.webtaller.com/construccion/lenguajes/javascript/lecciones/fecha-hora-javascript.php
	*
	* Funcion que retorna la fecha actual
	*
	* @param int _formato : Formato de Salida de Fecha. Si el formato de la fecha es '', la fecha sera '01-01-2000'; en cambio, si el formato
	*												de la fecha es '1', la fecha de sera 'Lunes 01 de Enero del 2000'
	*
	* @return date
	*
	*/
	function getFechaActual(_formato){
		
		var fecha = new Date();
	  	
  	/*FECHA*/
  	var _dia	= fecha.getDate();
  	var _mes	= fecha.getMonth() + 1;
		var _anio	= fecha.getFullYear();
		
		if (_dia < "10"){ _dia = "0" + _dia;	}
		if (_mes < "10"){ _mes = "0" + _mes;	}
		
		/*SABER EL DIA*/
		var _dias = new Array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves",	"Viernes", "Sabado");
		_dianomb = _dias[fecha.getDay()];

		/*SABER EL MES*/
		var _meses = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo",	"Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
		_mesnomb = _meses[fecha.getMonth()];
		
		if (_formato == ""){
			fecha_actual = _dia + "-" + _mes + "-" + _anio;
		}else if (_formato == 1){
			fecha_actual = _dianomb + " " + _dia + " de " + _mesnomb + " del " + _anio;
		}else{
			fecha_actual = _dia + "-" + _mes + "-" + _anio;
		}
		
		return fecha_actual;
		
	}
	
	
	/**
	* @link http://www.siigsa.cl
  * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
  * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	* @author Jose Meneses Gonzalez <jmeneses@siigsa.cl>
	* @since 22-01-2009
	* @version 1.0.1
	* @see http://www.webtaller.com/construccion/lenguajes/javascript/lecciones/fecha-hora-javascript.php
	*
	* Funcion que retorna la hora actual
	*
	* @return date
	*/
	function getHoraActual(){
		
		var fecha = new Date();
	  	
		/*HORA*/
		var _hora = fecha.getHours();
		var _min	= fecha.getMinutes();
		var _seg	= fecha.getSeconds();
		
		if (_hora < "10")	{	_hora = "0" + _hora;	}
		if (_min < "10")	{	_min = "0" + _min;		}
		if (_seg < "10")	{	_seg = "0" + _seg;		}
		
		hora_actual = _hora + ":" + _min + ":" + _seg;
		
		return hora_actual;
		
	}
	
	/**
 * Advierte que se debe elegir una opcion a lo menos
 * y deja checkeada la última opción en operación
 *
 * @param $nomb    :    Nombre de los TAG HTML que contienen las opciones
 * @param $obj     :    Objeto que gatilla la función
 * 
 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
 * @since 06-12-2007
 */
function debeElegirUno(nomb,obj){
  
  var sel = document.getElementsByName(nomb);
  var sel_chk = '';
  for(i=0;i<sel.length;i++){
    
    if(sel[i].checked == true){
      
      sel_chk = 1;
      
    }
    
  }
  
  if(sel_chk == ''){
    
    alert("Debe elegir una region a lo menos");
    obj.checked = true;
    
  }
  
}

  /**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Cristián Gómez Mamani <cgomez@siigsa.cl>
	 * @since 15-12-2008
	 * @version 1.0.0
	 *
	 * Verificar el RUT ingresado en el formulario
	 * 
	 *
	 * @param rut    :    RUT ingresado
	 * @param dv     :    Digito Verificador. Si se omite este parámetro la función devolverá el digito verificador del rut ingresado
	 *
	 * @return mixed
	 */
	function verificarRUT(rut,dv){
	 	
	 	var i = 0;
		var largo_rut = rut.length-1;
		var producto_tmp = 0;
	 	var caracter_actual = "";
	 	var factor = 2;
	 	var total_suma_factores = 0;
	 	
	 	for ( i=(rut.length-1); i>=0; i--) {
	 	  producto_tmp = factor * parseInt(rut.charAt(i));
		 	total_suma_factores += producto_tmp;
	 		if(factor == 7) {
	 			factor = 1;
	 		}
	 		factor++;
	 	}
	 	
	 	resto_modulo_11 = total_suma_factores % 11;
		resultado_final_tmp = 11 - resto_modulo_11;
		
		if(resultado_final_tmp == '11'){
			resultado_final = '0';
		}else if(resultado_final_tmp == '10'){
			resultado_final = "K";
		}else{
			resultado_final = resultado_final_tmp;
		}
		
		if (typeof(rut) != 'undefined' && typeof(dv) != 'undefined'){	
			if(resultado_final == dv.toUpperCase()){
				return true;
			}else{
				return false;	
			}	
	 	}else if(typeof(rut) != 'undefined'){
			return resultado_final;
	 	}
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Cristián Gómez Mamani <cgomez@siigsa.cl>
	 * @since 16-12-2008
	 * @version 1.0.0
	 *
	 * Verificar la existencia de un RUT en la base de datos
	 *
	 * @param tabla  :    Tabla Base de Datos
	 * @param rut    :    RUT ingresado
	 * @param dv     :    Digito Verificador. 
	 * @param url    :    url donde se debe dirigir para realizar la petición PHP a través de AJAX.
	 * @param pid    :    Id de Persona (si existe en el modaccion de PHP se filtra este id para no considerar el RUT de dicho ID)
	 *
	 * @return string
	 */
	function verificarExistenciaRUT(tabla,rut,dv,url,pid){
		_pid = '';
		if(typeof(pid) != 'undefined') {
			_pid = pid;
		}
		var oAjax 	= new ObjAjax();
		_param = "modaccion=verif_existencia_rut&tabla=" + tabla + "&rut=" + rut + "&dv=" + dv + "&pid=" + _pid;
		
		oAjax.open("POST", GC_WEB_DIR + "/" + url , false);
		oAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
		oAjax.onreadystatechange=function() {
			if (oAjax.readyState==4 && oAjax.status==200) {
				_res = oAjax.responseText;
				document.getElementById('existe_rut').value = _res;
				return;
			}
		}
		oAjax.send(_param);
	}
	
	
	/**
	 * @link http://www.siigsa.cl
   * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
   * @author Patricio Cifuentes Ithal <pcifuentes@siigsa.cl>
	 * @author Cristián Gómez Mamani <cgomez@siigsa.cl>
	 * @since 16-12-2008
	 * @version 1.0.0
	 *
	 * Verificar la existencia de un Código Institucional en la base de Datos según su tipo de objeto
	 *
	 * @param tabla  :    Tabla Base de Datos
	 * @param rut    :    RUT ingresado
	 * @param dv     :    Digito Verificador. 
	 * @param url    :    url donde se debe dirigir para realizar la petición PHP a través de AJAX. 
	 *
	 * @return string
	 */
	function verificarExistenciaCodigoInst(c_i,t_o,cid,desde_ficha){
		
		var oAjax 	= new ObjAjax();
		
		if(typeof(cid) != 'undefined') {
			_cid = cid;
		}
		
		_param = "modaccion=verif_existencia_codigo&" + "&c_i=" + c_i.value.trim() + "&t_o=" + t_o + "&cid=" + _cid;
		
		oAjax.open("POST", GC_WEB_DIR + "/adm/adm_contenido.php" , true);
		oAjax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oAjax.send(_param);
		
		oAjax.onreadystatechange=function() {
			if (oAjax.readyState==4 && oAjax.status==200){
				_res = oAjax.responseText;
				
				if(_res == 't'){
					alert('Código Institucional ya existe para este tipo de Contenido. Ingrese otro');
					c_i.value = '';
					c_i.focus();
					document.getElementById('guardar_objeto_codigo').innerHTML = '';
					return false;
				}else{
					if(typeof(desde_ficha) != 'undefined'){ficha_mostrarGuardar('guardar_objeto_codigo','objeto_codigo');}
				}
			}
		}
		
	}
	
	
	/**
	 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 05-08-2009
	 * @version 1.0.0
	 * 
	 * Selecciona o deselecciona un conjunto de checkboxs, el gatillador de la función debe ser un checkbox.
	 * La función rescata el value del gatillador y busca todos los objeto con este como nombre, por lo que solo los checkbox
	 * que se desea operar deben tener dicho texto en sus respectivos NAMEs.
	 *
	 * @param String $gatillador	:	CHK que detona la funcion
	 */
	function seleccionarDeseleccionarCHK(gatillador){
		
		var chks = oTenc.getTags(2,gatillador.value);
		
		for(i=0;i<chks.length;i++){
			chks[i].checked = gatillador.checked;
		}
		
	}
	
	
	/**
	 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 12-08-2009
	 * @version 1.0.0
	 * 
	 * expande o contrae un divisor al tamaño indicado en parámetros.
	 * EJ: 	si desea expandir -> $ancho = 100px; $alto = 100px
	 * EJ: 	si desea contraer -> $ancho = 0px; $alto = 10px
	 *
	 * si no se indica un valor para $alto o $ancho, al momento de expandir, este se asumira como 100%.
	 *
	 * @param String $ancho		:	valor que determina el ancho al contraer o expandir, sea este en PX o %.
	 * @param String $alto		:	valor que determina el alto al contraer o expandir, sea este en PX o %.
	 * @param String $id_div	:	ID del tag divisor que se desea trabajar.
	 */
	function expandirContraerDivisor(id_div,ancho,alto){
		
		var div_ec = oTenc.getTags(1,id_div); //Rescate del divisor
		
		if(typeof(ancho) == "undefined" || ancho == ''){ancho = "100%";}
		if(typeof(alto) == "undefined" || alto == ''){alto = "100%";}
		
		oTenc.setEstiloTag(div_ec,"width",ancho); //Seteo del ancho
		oTenc.setEstiloTag(div_ec,"height",alto); //Seteo del alto
			
		
	}
	
	
	/**
	 * @copyright ©SIIGSA - Registro Propiedad Intelectual Nº 172.560 - Derechos Reservados
	 * @author Gonzalo Arenas Flores <garenas@siigsa.cl>
	 * @since 20-08-2009
	 * @version 1.0.0
	 * 
	 * Imprime un sector
	 *
	 * @param String $id_sector		:	ID del Tag HTML (div,table, etc...)
	 */
	function imprimmirSector(id_sector){
		
		var sector = oTenc.getTags(1,id_sector); //Rescate
		var ventimp = window.open('','');
			  ventimp.document.write( sector.innerHTML );
			  ventimp.document.close();
			  ventimp.print( );
			  ventimp.close();
	  
	}
