/*  Intellisearch versino 2007-12-03
 *  (c) 2007 ettl-software KEG - Michael Ettl 
 *
 *  Please keep in mind that this code is not OpenSource
 *   please get in contact with the programmer for licenses
 *   office@ettl.com
 *--------------------------------------------------------------------------*/

	if (typeof(Prototype)!='object') {
	 	alert("Missing Prototype Library !! "+typeof(Prototype));
	 	//return;
	}
	
	intellisearch =	Class.create({
	  	initialize: function(options) {
		    baseoptions = $H({
			    method:       'post',
			    startlength: 	2,
			    country:'',
			    sprache:'',
			    SID:''
	 	    });
	 	    this.options=baseoptions.merge(options).toObject();
	 	    myAlert("INIT: "+this.options.startlength);
	  		this.oldword='X';
	  	},
	  	softsearch: function(myWord) {
			if (myWord.length <=  this.options.startlength) {
				myAlert('Length to short ('+myWord+":"+myWord.length+")");
				this.oldword="X";
				return;
			}
			if(myWord==this.oldword) {
				myAlert("Same words ("+myWord+":"+this.oldword+")");
				return;
			}
			// Check if new Entry matches the old one e.g. user continues typing
			if (myWord.substr(0,this.oldword.length)==this.oldword) {
				lastcnt=$(this.options.div).readAttribute("cnt");
				myAlert('Old ('+this.oldword+') and New ('+myWord+') match ('+this.oldword.length+') - Checking old Hits:'+lastcnt);
				/* No need to search again if nothing similar was found during last search */
				if(lastcnt==0 || lastcnt==1) {
					this.oldword=myWord;
					if(lastcnt==1)
						is_show();
					return;
				}
			}
			this.oldword=myWord;
			this.send_ax_Request("../html/ax_intellisearch.php",'word='+myWord+'&'+this.options.SID+"&sprache="+this.options.sprache+"&country="+this.options.country);
	  	},
		send_ax_Request: function (url,paramstring) {
		  myAlert("AJAX: "+paramstring);
	      new Ajax.Request(url, {
		 	 method: 'post',
		 	 postBody: paramstring,
		 	 onSuccess: is_cbhandler,
		     onFailure: function(AXrequest) { customHandler("Error in interpret_ax_Request: Request.status != 200 ("+AXrequest.status+")",document.location.href,0,0); }
	     });
	    }
	});
	
	function myAlert(c) {
		//alert(c);
		//$('vb_test').insert(c+"<br/>");
	}