dCompletor = Class.create();
dCompletor.prototype = {
	initialize: function($htmlElement, $appendScript, $tip ,$oricare , $passValues)
	{	
		this.td = document.getElementById($htmlElement + "_js");
		//alert(document.getElementById("hahah"));

		this.htmlElement = $($htmlElement);
//		alert(this.htmlElement.innerHTML);
		this.script = $appendScript;
		this.displayResults = this.createResultDiv();
		
		this.passValues = $passValues;
		
		this.tip = $tip;
		this.oricare = $oricare;
		
		if (this.htmlElement) this.htmlElement.onchange = this.cChange.bind(this);
		this.cChange();
		

	},

	createResultDiv: function() 
	{
		tempDiv = document.createElement("span");
		
//		tempDiv = document.createElement("span");
//		tempDiv.className="inlineDiv"
//		

//		this.htmlElement.parentNode.parentNode.innerHTML = this.htmlElement.parentNode.parentNode.innerHTML + "<td>";
		if (this.htmlElement) this.htmlElement.parentNode.insertBefore(tempDiv, this.htmlElement.nextSibling);
//		this.htmlElement.parentNode.parentNode.innerHTML = this.htmlElement.parentNode.parentNode.innerHTML + "</td>";

		return tempDiv;
	},
	
	cChange: function(evt)
	{
	   var tmp="";
	   if (this.htmlElement) tmp = this.htmlElement.value;
		$postBody = "id_prod="+tmp+"&" +
									"tip="+this.tip+"&oricare="+this.oricare+"&";

		for($value in this.passValues) {
			$postBody += $value + "=" + this.passValues[$value] + "&";
		}
		
		new Ajax.Request(
			this.script,
			{
				postBody: $postBody,
				onSuccess: function(obj, header) {
					this.td.innerHTML = obj.responseText;
					//this.displayResults.innerHTML = obj.responseText;
					//alert(this.displayResults.outerHTML);
				}.bind(this)
			}
		);
	}
}

