EmergingTips = function()
{

var oDiv=null;
var oElement=null;
var oRegionElement=null;
var Name=null;
var Way=null;
var focused=false;
var focus_on=false;
var changed=false;
var oldValue=null;

    var getWidth = function ()
    {
      if(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1)
      {
        return oElement.offsetWidth-1*2;
      }
      else
      {
        return oElement.offsetWidth;
      }
    }

    var getParameter = function (s,na)
    {
      var wb=0;
      while(s)
      {
        wb+=s[na];
        s=s.offsetParent
      }
      return wb;
    }

    var getOffsetLeft = function (s)
    {
      return getParameter(s,"offsetLeft")
    }

    var getOffsetTop = function (s)
    {
      return getParameter(s,"offsetTop")
    }

    var setPosition = function ()
    {
      if(oDiv)
      {
        oDiv.style.left=getOffsetLeft(oElement)+"px";
        oDiv.style.top=getOffsetTop(oElement)+oElement.offsetHeight-1+"px";
        oDiv.style.width=getWidth()+"px";
      }
    }

    var setObj = this.setObj = function(extObj)
    {
      oElement=extObj;
    }

    var setRegionObj = this.setRegionObj = function(extObj)
    {
      oRegionElement=extObj;
    }

    var setName = this.setName = function(extName)
    {
      Name=extName;
    }
	 var setWay = this.setWay = function(extWay)
    {
      Way=extWay;
    }

    var addto = this.addto = function (str)
    {
      oElement.value=str;
    }

    var create = this.create = function()
    {
		//alert('create');
      //oDiv = document.getElementById("completeDiv");
      oDiv = document.createElement("DIV");
      oDiv.style.borderRight="black 1px solid";
      oDiv.style.borderLeft="black 1px solid";
      oDiv.style.borderTop="black 1px solid";
      oDiv.style.borderBottom="black 1px solid";
      setPosition();
      oDiv.style.zIndex="255";
      oDiv.style.paddingRight="0";
      oDiv.style.paddingLeft="0";
      oDiv.style.paddingTop="0";
      oDiv.style.paddingBottom="0";
      oDiv.style.visibility="visible";
      oDiv.style.position="absolute";
      oDiv.style.backgroundColor="white";
      document.body.appendChild(oDiv);
    }

    var setFocused = this.setFocused = function (v)
    {
      focused=v;
      focus_on=true;
    }

    var loadText = this.loadText = function (str)
    {
	
		//alert('load text' +str);
		var request             = getRequestObj();
        //request.getData('/_fetchers/getFio.php?str=' + str  + '&rand=' + Math.random(), getResult);
		request.getData(Way + str  + '&rand=' + Math.random(), getResult);
      
    }
	var getResult	= this.getResult = function (obj)
	{
		//alert('loaded text');
		//alert('got_response'+obj.responseText);
		if (obj.responseText.length > 0)
		{
			setText(obj.responseText);
		}
		else
		{
			setText('');
		}
        changed=false;
	}
	
    var setText = this.setText = function (oCities)
    {
	   if (oCities.length > 0)
	   {
		//alert('woot' + oCities);
		eval('oCities	='+oCities);

	  
			oDiv.innerHTML='';

			for (i = 0, count = oCities.length; i < count; i ++)
			{
				if(oCities[i] != null)
				{
					//alert(oCities[i]);
					oNewElement = document.createElement("a");
					oNewElement.setAttribute("href","javascript:"+Name+".addto('"+oCities[i]+"');");
					oNewElement.setAttribute("className","black_black");
					//oNewElement.setAttribute("style","font:normal 50px Arial;color:black;");
					oNewElement.appendChild(document.createTextNode(oCities[i]));
					oDiv.appendChild(oNewElement);
					oNewElement = document.createElement("BR");
					oDiv.appendChild(oNewElement);
				}

			}
		}
      //alert(oDiv.innerHTML);
    }

    var isChange = this.isChange = function ()
    {
		
      setPosition();
      if (oElement.value!=oldValue) {changed=true; oldValue=oElement.value;}

      if(focused){
        if (oElement.value.length > 1)
        {
		
          if((changed)||(focus_on)) {loadText(oElement.value); focus_on=false;}
          oDiv.style.visibility="visible";
        }
        else
          oDiv.style.visibility="hidden";
      }
      else oDiv.style.visibility="hidden";
	  //alert('woot' + Name);
      setTimeout(Name+'.isChange()',500);
    }
}
