function GPS(){
	this._pts = 0;
	this.nexts = [];
	this.results = [];
	this.nb = 0;
	this.nbstart = 0;
	this.disableds = {};
	this.scurrent = "";
	this.txt = null;
	this.tip = null;
	this._sleep = null;
	this.loadData = function(raw,me){
		try{
			if(raw != ""){
				var lines = raw.split("\n");
				me.nexts = lines[0].split("|||");me.results = lines[1].split("|||");me.nb = lines[2];
				me.refreshKeyboard();me.refreshResults();
			}
			else{me.nb = 0;}
		}
		catch(e){}
	}
	this.goData = function(str){
		var d = new Date();
		this.aj.abort();
		var u = "gps.ajax.php?s=" + str + "&max=16&start="+this.nbstart+"&max=20&ts=" + d.getDate() + d.getMonth() + d.getYear();
		if(mmz == "ul") u += "&f=1";
		this.aj.call(u);
	}
	this.checkData = function(){
		var is_call = false;
		if(this.txt){
			if(this.txt.value != ""){
				is_call = true;
				if(this.tip){this.tip.style.display = "none";}
			}
			this.goData(this.txt.value);
		}
		if(!is_call){this.clearAll(true);}
	}
	this.txtChanged = function(o){
		/*var k = event.keyCode;
		if(k != 42 && (k < 65 || (k > 90 && k < 97) || k > 122)){
			o.value += "*";
			event.returnValue = false;
			return false;
		}*/
	}
	this.txtUp = function(o){
		o.value = o.value.toUpperCase();
		clearTimeout(this._sleep);
		this._sleep = setTimeout("_GPS.nbstart = 0;_GPS.checkData()", 200);
	}
	this.addLetter = function(l){
		if(!this.disableds[l]){
			if(this.txt){this.txt.value += l;this.scurrent = this.txt.value;this.nbstart = 0;}
			this.checkData();
		}
		return false;
	}
	this.delLetter = function(){
		if(this.txt){
			str = this.txt.value;this.txt.value = str.substr(0,str.length - 1);this.scurrent = this.txt.value;this.nbstart = 0;this.checkData();
		}
		return false;
	}
	this.refreshKeyboard = function(){
		for(var i = 65 ; i <= 90 ; i++){
			var l = String.fromCharCode(i);
			var disabled = true;
			for(var j = 0 ; j < this.nexts.length ; j++){
				if(l == this.nexts[j]) disabled = false;
			}
			this.disableds[l] = disabled;
			if(a = gel("gps_" + l)){
				if(disabled){a.className = "gpsloff";}
				else{a.className = "gpsl";}
			}
		}
		var disabled = true;
		for(var j = 0 ; j < this.nexts.length ; j++){
			if("*" == this.nexts[j]) disabled = false;
		}
		this.disableds["*"] = disabled;
		if(a = gel("gps_0")){
			if(disabled){a.className = "gpsloff";}
			else{a.className = "gpsl";	}
		}
	}
	this.resetKeyboard = function(){
		this.nexts = [];
		this.disableds = {};
		for(var i = 65 ; i <= 90 ; i++){
			var l = String.fromCharCode(i);
			if(a = gel("gps_" + l)){a.className = "gpsl";}
		}
	}
	this.colResults = function(col){
		if(col == 1) start = 0;
		else start = 10;
		var h = "";
		for(var i = start ; i < start + 10 ; i++){
			if(i < this.results.length){
				var re = /^(.*)\{(.*)\}$/;
				var disp, id;
				if(matches = re.exec(this.results[i])){disp = matches[1];	id = matches[2];}
				else{disp = this.results[i];id = 0;}
				//if(disp.length > 22) disp = disp.substr(0,22)+"...";
				h += "<div class=\"gpsresult\" id=\"gps_res_" + i + "\"><a href=# onclick=\"return _GPS.clickResult(this,'"+id+"')\">" + disp + "</a></div>";
			}
		}
		if(d = gel("dirresults" + col)){
			d.innerHTML = h;
			d.style.display = "block";
		}
	}
	this.refreshResults = function(){
		var h = "";
		if(this.dresults){
			if(this.results.length > 0){
				this.dresults.style.display = "block";
				this.colResults(1);
				this.colResults(2);
				this.refreshPages();
			}
			else if(d = gel("dirresults1")){
				d.innerHTML = _localizer.tr('widgets/catalognoresult');
			}
		}
		//setArray();
	}
	this.refreshPages = function(){
		if(this.dpages){
			if(up = document.getElementById("gpsup")){
				if(this.nbstart == 0){up.className = "gpspgoff";}
				else{up.className = "gpspg"}
			}
			if(down = document.getElementById("gpsdown")){
				if(this.nbstart + 20 >= this.nb){down.className = "gpspgoff";}
				else{down.className = "gpspg";}
			}
			this.dpages.style.display = "block";
		}
		if(d = gel("gpsnb")){
			if(this.nb == 0) d.innerHTML = "";
			else d.innerHTML = _localizer.tr('widgets/catalogcount', this.nbstart+1, this.nbstart+Math.min(20,this.results.length), this.nb);
		}
	}
	this.resetResults = function(){
		this.results = [];
		if(this.dresults){this.dresults.style.display = "none";}
		if(this.dpages){this.dpages.style.display = "none";}
	}
	this.clearAll = function(clearTxt){
		this.resetKeyboard();
		this.resetResults();
		if(clearTxt){
			if(this.txt){this.txt.value = "";}
			if(this.tip){this.tip.style.display = "block";}
		}
		return false;
	}
	this.nextPage = function(){
		if(this.nbstart + this.results.length < this.nb){
			this.nbstart += 20;
			this.goData(this.scurrent);
		}
		return false;
	}
	this.prevPage = function(){
		if(this.nbstart > 0){
			this.nbstart -= 20;
			this.goData(this.scurrent);
		}
		return false;
	}
	this.clickResult = function(ores, id){
		var art = ores.innerText;
		document.location.href = "/artist.php?idid=" + id;
		return false;
	}
	this.init = function(txt_id,tip_id,res_id,pg_id){
		var str = "";
		if(t = gel(txt_id)){
			this.txt = t;
			str = t.value;
		}
		if(tip = gel(tip_id)) this.tip = tip;
		this.aj = new ajax();
		this.aj.setResultHandler(this.loadData,this);
		if(str != ""){if(this.tip) this.tip.style.display = "none";this.goData(str);}
		if(dresults = gel(res_id)){this.dresults = dresults;}
		if(dpages = gel(pg_id)){this.dpages = dpages;}
	}
	//this.init();
}