﻿function BuscaCombo(ori, des, ind, tit) {
	this.temp = null;
	this.obj_ori = document.getElementById(ori);
	this.obj_des = document.getElementById(des);
	this.ind = ind;
	var self = this;
	this.obj_ori.style.fontStyle = "italic";
	this.obj_ori.style.color = "#666666";
	this.obj_ori.value = "Buscar...";
	this.displayOn = (Util.isIE()) ? "inline" : "table-row";
	//this.displayOn = "inline";
	if (tit) {
		this.tit = true;
	} else {
		this.tit = false;
	}
	this.obj_ori.onkeyup = function() {
		self.preBuscar();
	}
	this.obj_ori.onfocus = function() {
		self.focusOnTxt();
	}
	this.obj_ori.onblur = function() {
		self.focusOutTxt();
	}	
	this.preBuscar = function() {
		window.clearTimeout(this.temp);
		temp = window.setTimeout(self.buscar, 200);
	}
	this.buscar = function() {
		var ini;
		if (self.tit) {
			ini = 1;
		} else {
			ini = 0;
		}
		for (var i = ini; i < self.obj_des.rows.length; i++) {
				if (self.obj_des.rows[i].cells[ind].innerHTML.substr(0, self.obj_ori.value.length).toUpperCase() 
					== self.obj_ori.value.toUpperCase()) {
				self.obj_des.rows[i].style.display = self.displayOn;
			} else {
				self.obj_des.rows[i].style.display = "none";
			}
		}
	}
	this.mostrarTodo = function() {
		var ini;
		if (self.tit) {
			ini = 1;
		} else {
			ini = 0;
		}
		for (var i = ini; i < self.obj_des.rows.length; i++) {
			self.obj_des.rows[i].style.display = self.displayOn;
		}
	}
	this.focusOnTxt = function() {
		window.clearTimeout(self.temp);
		self.obj_ori.style.color = "#000000";
		self.obj_ori.style.fontStyle = "normal";
		self.obj_ori.value = '';
		self.mostrarTodo();
	}
	this.focusOutTxt = function() {
		window.clearTimeout(self.temp);
		self.obj_ori.style.color = "#666666";
		self.obj_ori.style.fontStyle = "italic";
		self.obj_ori.value = 'Buscar...';
	}
	//this.mostrarTodo();
}

