	// JavaScript Document
	
	var ds1_SGS = function (pagina, variables) {
		
		this.paginaX = pagina; 
		this.variablesX = variables;
		this.nombreX = "sugerencia";
		this.nombreColumna ="";
		this.anchoX = "320px"; 
		this.largoX = "200px";
		this.tabindexX= "0";
		this.classX = "text";
		this.value = "";
		this.caracterX = 0;  
		this.styleX = "";
		
		this.onKeyDown = "";
		this.onBlur = "";
		this.onFocus = "";
		
		this.crearX = function() {

			var nombreColumna = this.nombreColumna;	
			var caracter = this.caracterX;
			if (caracter == 0) {caracter=1;}
			var objetoX = '<table border="0" cellpadding="0" cellspacing="0"><tr><td align="left">';
			
			objetoX = objetoX + '<input  type="text" '; 
			
			// Atributos
			objetoX = objetoX + ' name="'        + this.nombreX     + '" ';
			objetoX = objetoX + ' id="'          + this.nombreX     + '_txt" ';
			objetoX = objetoX + ' tabindex="'    + this.tabindexX   + '" ';
			objetoX = objetoX + ' class="'       + this.classX      + '" ';
			// Valor por defecto
			objetoX = objetoX + ' value="'       + this.value       + '" ';
			// Eventos
			objetoX = objetoX + ' onKeyDown="'   + this.onKeyDown   + '" ';
			objetoX = objetoX + ' onBlur="'      + this.onBlur      + '" ';
			objetoX = objetoX + ' onFocus="'     + this.onFocus     + '" ';			
			objetoX = objetoX + ' maxlength="7" ';			
			objetoX = objetoX + '    />'  
			
			objetoX = objetoX + '</td></tr><tr><td align="left" style="text-align:left" ><div id="' + this.nombreX + '_div" ></div>'; 
			objetoX = objetoX + '<input type="hidden" name="'+ this.nombreX +'_val" id="' + this.nombreX + '_val" />';
			objetoX = objetoX + '<input type="hidden" name="'+ this.nombreX +'_col" id="' + this.nombreX + '_col" value="'+ this.nombreColumna + '" /></td></tr></table>';
			
			document.write(objetoX);
			//alert(objetoX);
			
			var input = document.getElementById(this.nombreX+"_txt");
			input.style.width = this.anchoX;
			
			input.onkeyup=function(e){
				if(this.value!='') { 
					
					if (eval(this.value.length) >= eval(caracter)) {						
						sugerencia(this,nDiv,this.value,nombreColumna);
					} else {
						nDiv.style.display = "none";
					}  
					
					
				} else {
					nDiv.style.display = "none";
				}
			}
			
			var nDiv = document.getElementById(this.nombreX+"_div");
			nDiv.style.border = "1px solid #666";		
			nDiv.style.background = "#fff"; 
			nDiv.style.position = "absolute";  
 			nDiv.style.width = this.anchoX;   
			nDiv.style.height = this.largoX;
			nDiv.style.overflow = "auto";                            // div scroll
			nDiv.style.zIndex = "999999"; 
			nDiv.style.display = "none";				             // "none: invisible, block: visible"
			
			nDiv.onmouseout=function(e){
				this.style.display = "none";
			}
			
			nDiv.onmouseover=function(e){
				this.style.display = "block";
			}
			
			nDiv.ondblclick=function(e){ 
				this.style.display = "none";
			}

			function sugerencia(obj,div,valor,nombre) { 
				var consulta1 = new ds1_AJAX("");

				

				
				consulta1.open("POST",pagina,true);
				consulta1.onreadystatechange=function(){
					if (consulta1.readyState==4){
						 
						//alert(consulta1.responseText);
						eval(consulta1.responseText); 
						
						if (respuesta.encontrado == 1) {
							
							nDiv.style.display = "block";
							
							
							
							var datos  = respuesta.resultados; 
							var tabla  = "<TABLE border=\"0\" align=\"left\"  style=\"color:#000000;background-color:#FFFFFF;\" >";   
							//alert(datos.length)  
							for (var i=0; i < datos.length; i++) {
								var resultado = datos[i].split("<->");  								
								var valor = resultado[0];								
								var texto = resultado[1]; 
								//alert(texto)
								texto  = texto.replace(/<comillas>/g,"&quot;");	
								
								
								var marca = texto;
								var texto_marca = texto.toUpperCase();
								var marca_valor=obj.value.toUpperCase();
								
								marca = texto_marca.replace(marca_valor,"<STRONG>"+marca_valor+"</STRONG>");
								
								
								//Crea las filas de la sugerencia    
								tabla += "<tr align=\"left\"  style=\"color:#000000;background-color:#FFFFFF;\" ><td  style=\"cursor:pointer;background-color:#FFFFFF;text-align:left;\" onClick=\" selecciona('" + obj.name + "','" + texto + "','" + valor + "') \">"+marca+"</td></tr>";
							}
							tabla += "</TABLE>"; 
							div.innerHTML = tabla; 

						} else {							
						nDiv.style.display = "none";							
						} 
						
						selecciona = function(obj,texto,valor){ 
							document.getElementById(obj + "_txt").value = texto;
							document.getElementById(obj + "_val").value = valor;
						}
						
					} 	
				}  
				
				

				valor= valor.replace(/°/g,"<num>"); 
				valor= valor.replace(/º/g,"<num_>"); 
				valor= valor.replace("+","<mas>"); 
		
				consulta1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				consulta1.send("valor="+valor+"&valor_colum="+nombre);
			}

		} // Fin Crear Objeto
	} // Fín Funcion Objeto Sugerencias
