
/**
 * An autosuggest textbox control.
 * @class
 * @scope public 
 */
function AutoSuggestControl(oTextbox /*:HTMLInputElement*/, 
                            oProvider /*:SuggestionProvider*/) {
    
    /** 
     * The currently selecteeed suggestions.
     * @scope private
     */   
    this.cur /*:int*/ = -1;

    /**vv
     * The dropdown list layer.
     * @scope private
     */
    this.layer = null;
    
    /**
     * Suggestion provider for the autosuggest feature.
     * @scope private.
     */
    this.provider /*:SuggestionProvider*/ = oProvider;
    
    /**
     * The textbox to capture.
     * @scope private
     */
    this.textbox /*:HTMLInputElement*/ = oTextbox;
    
    /**
     * Timeout ID for fast typers.
     * @scope private
     */
    this.timeoutId /*:int*/ = null;

    /**
     * The text that the user typed.
     * @scope private
     */
    this.userText /*:String*/ = oTextbox.value;

    /**
     * @scope private
     */
    this.separatorsTranslations /*:Array*/ = new Array();

    /**
     * Contains loc_id,center_location_lat
     * and center_location_lng for each destination
     * @scope private
     */
    this.destinationsParams /*:Array*/ = new Array();

    this.selectedDestination /*:Array*/ = new Array();

    /**
     * Corresponds to 
     * coddest:destination:type:nboffres:lat:lng //Country case
     * retrieved from the server	
     * @scope private
     */
    /*this.minDestinationDataLength*/ /*:Array*/ /*= 6;*/
    
    /**
     * Corresponds to 
     * coddest:destination:type:lat:lng //Country case
     * retrieved from the server	
     * @scope private
     */
    this.minDestinationDataLength /*:Array*/ = 5;
    
    //initialize the control
    this.init();
    
    
    stop_sujjest=0;
    
}

/**
 * Autosuggests one or more suggestions for what the user has typed.
 * If no suggestions are passed in, then no autosuggest occurs.
 * @scope private
 * @param aSuggestions An array of suggestion strings.
 * @param bTypeAhead If the control should provide a type ahead suggestion.
 */
AutoSuggestControl.prototype.autosuggest = function (aSuggestions /*:Array*/,
                                                     bTypeAhead /*:boolean*/) {
                             
    globals.loc_id = 0;
    globals.location_name = '';
    
    //re-initialize pointer to current suggestion
    this.cur = -1;
    //alert(aSuggestions);
    //make sure there's at least one suggestion
    //if (aSuggestions.length > 0) {
    if (aSuggestions && aSuggestions.length > 1) {
    //if (aSuggestions.length > 0) {
        if (bTypeAhead) {
           //this.typeAhead(aSuggestions[0]);
	     //this.typeAhead(this.removeNbAnnonces(this.translateSuggestionData(aSuggestions[1])));
        }
        this.showSuggestions(aSuggestions);
      
    } else {
        globals.loc_id = 0;
        globals.location_name = '';
    
        this.hideSuggestions();  
        //jQuery.popups(js_popup_autosuggest_message_destination_bad);
        //this.textbox.focus();
    }
    
    //if (aSuggestions.length === 2 && this.textbox.value == this.removeNbAnnonces(this.translateSuggestionData(aSuggestions[1]))) {
    //if (aSuggestions.length == 2 && this.textbox.value == this.removeNbAnnonces(this.translateSuggestionData(aSuggestions[1]))) {
    //if (aSuggestions.length == 2 && this.textbox.value == this.translateSuggestionData(aSuggestions[1])) {
    if (aSuggestions.length == 2) {
        
        text_loc_id=aSuggestions[1].split(':');
        globals.loc_id = text_loc_id[0];
        //globals.location_name = this.removeNbAnnonces(this.translateSuggestionData(aSuggestions[1]));
        globals.location_name = this.translateSuggestionData(aSuggestions[1]);
		
		this.textbox.value = globals.location_name;
        //alert(globals.loc_id+' '+globals.location_name);
        //this.hideSuggestions();
        this.showSuggestions(aSuggestions);
    }
 
};

/**
 * Sets the userText property.
 * @scope public
 * @param myText a string equals to oTextbox value
 */
AutoSuggestControl.prototype.setUsertext = function(myText) {
	this.userText = myText;
}

/**
 * Creates the dropdown layer to display multiple suggestions.
 * @scope private
 */
 
 AutoSuggestControl.prototype.showSuggestions2 = function () {  
  this.layer.style.visibility = "visible"; 
 }
 
AutoSuggestControl.prototype.createDropDown = function () {


    //create the layer and assign styles
    this.layer = document.createElement("div");
    this.layer.className = "suggestions";
    this.layer.style.visibility = "hidden";
    this.layer.style.width = this.textbox.offsetWidth;
    this.layer.style.zIndex = "20";//Added for correcting fullpagebranding bug
    document.body.appendChild(this.layer);    
    
    //when the user clicks on the a suggestion, get the text (innerHTML)
    //and place it into a textbox
    var oThis = this;
    this.layer.onmousedown = 
    this.layer.onmouseup = 
    this.layer.onmouseover = function (oEvent) {
        oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;
        
        suggestionText=oTarget.firstChild.nodeValue;
        
        if(suggestionText != null)
        {

                if (oEvent.type == "mousedown") 
                {
                    //oThis.textbox.value = oTarget.firstChild.nodeValue;
		
		            //suggestionText=oTarget.firstChild.nodeValue;

	
		            /*suggestionText=null;		

		            if(oTarget.firstChild.firstChild!=null)	
		                suggestionText=oTarget.firstChild.firstChild.nodeValue;*/

		            isSeparator = 0;

		            for(var separator in oThis.separatorsTranslations)
		            {	
			            separatorText = oThis.separatorsTranslations[separator];

			            if(suggestionText==separatorText)
				            isSeparator = 1;
		            }		

		            if(isSeparator==0)
		            {	
			            //if(suggestionText!=null)
				            //oThis.textbox.value = oThis.removeNbAnnonces(suggestionText);
				            oThis.textbox.value = suggestionText;
				    
		            }
		            //suggestionId=oTarget.getAttribute("id");
		            //suggestionHiddenFieldId=suggestionId+"_id";
		            //alert(document.getElementById(suggestionHiddenFieldId).value);
                    oThis.hideSuggestions();
                    //afficher la destination si possible sur carte en temps reel
                    go_location(oThis.textbox.value, 'no');
           
                } 
                else if (oEvent.type == "mouseover") 
                {
                    oThis.highlightSuggestion(oTarget);
                              
                    /*if(oTarget.firstChild.nodeValue != null && oTarget.firstChild.nodeValue != oThis.separatorsTranslations["__Pays"] 
                    &&  oTarget.firstChild.nodeValue != oThis.separatorsTranslations["__Villes"] 
                    && oTarget.firstChild.nodeValue !=  oThis.separatorsTranslations["__Separator"] 
                    &&  oTarget.firstChild.nodeValue != oThis.separatorsTranslations["__RegionDept"]) 
                    {
                        oThis.textbox.value = oThis.removeNbAnnonces(oTarget.firstChild.nodeValue);
                        globals.location_name = oThis.textbox.value;
                    }*/
                    
                    isSeparator = 0;

		            for(var separator in oThis.separatorsTranslations)
		            {	
			            separatorText = oThis.separatorsTranslations[separator];

			            if(suggestionText==separatorText)
				            isSeparator = 1;
		            }		

		            if(isSeparator==0)
		            {	
			            /*oThis.textbox.value = oThis.removeNbAnnonces(suggestionText);
				        globals.location_name = oThis.removeNbAnnonces(suggestionText);*/
				        oThis.textbox.value = suggestionText;
				        globals.location_name = suggestionText;
		            }
                    
                } 
                else 
                {
                    oThis.textbox.focus();
           
                }
                
        }
         
    };
    
};

/**
 * Gets the left coordinate of the textbox.
 * @scope private
 * @return The left coordinate of the textbox in pixels.
 */
AutoSuggestControl.prototype.getLeft = function () /*:int*/ {

    var oNode = this.textbox;
    pos= findPos(oNode);
pos= pos[0];

/*
    var iLeft = 0;

    
    while(oNode.tagName != "BODY") {
        iLeft += oNode.offsetLeft;
        alert(iLeft);
        oNode = oNode.offsetParent;
        alert(oNode);      
    }
   */ 
    return pos;
};

/**
 * Gets the top coordinate of the textbox.
 * @scope private
 * @return The top coordinate of the textbox in pixels.
 */
AutoSuggestControl.prototype.getTop = function () /*:int*/ {

    var oNode = this.textbox;
    //var iTop = 0;
pos= findPos(oNode);
pos= pos[1];

    
  /*  
    while(oNode.tagName != "BODY") {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
   */
    return pos;
};


function findPos(obj) {
	var curleft = curtop = 0;

//If the browser supports offsetParent we proceed.

	if (obj.offsetParent) {

//Every time we find a new object, we add its offsetLeft and offsetTop to curleft and curtop.

	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;

////The tricky bit: return value of the = operator

//Now we get to the tricky bit:
		} while (obj = obj.offsetParent);

	return [curleft,curtop];
}
}


/**
 * Highlights the next or previous suggestion in the dropdown and
 * places the suggestion into the textbox.
 * @param iDiff Either a positive or negative number indicating whether
 *              to select the next or previous sugggestion, respectively.
 * @scope private
 */
AutoSuggestControl.prototype.goToSuggestion = function (iDiff /*:int*/) {
    var cSuggestionNodes = this.layer.childNodes;
    
    if (cSuggestionNodes.length > 0) {
        var oNode = null;
    
        if (iDiff > 0) {
            if (this.cur < cSuggestionNodes.length-1) {
                oNode = cSuggestionNodes[++this.cur];
            }        
        } else {
            if (this.cur > 0) {
                oNode = cSuggestionNodes[--this.cur];
            }    
        }
        
        if (oNode) {
            this.highlightSuggestion(oNode);

		//this.textbox.value = oNode.firstChild.nodeValue;
		
		suggestionText=oNode.firstChild.nodeValue;

				
		isSeparator = 0;

		for(var separator in this.separatorsTranslations)
		{	
			separatorText = this.separatorsTranslations[separator];

			if(suggestionText==separatorText)
				isSeparator = 1;
		}

		if(isSeparator==0)
		{	
			if(suggestionText!=null)
				//this.textbox.value = this.removeNbAnnonces(suggestionText);
				this.textbox.value = suggestionText;
		}
		
        }
    }
};

/**
 * Handles three keydown events.
 * @scope private
 * @param oEvent The event object for the keydown event.
 */
AutoSuggestControl.prototype.handleKeyDown = function (oEvent /*:Event*/) {

    switch(oEvent.keyCode) {
        case 38: //up arrow
            this.goToSuggestion(-1);
            globals.location_name=this.textbox.value;
            break;
        case 40: //down arrow 
            this.goToSuggestion(1);
            globals.location_name=this.textbox.value;
            break;
        case 27: //esc
            this.textbox.value = this.userText;
            this.selectRange(this.userText.length, 0);
            
            /* falls through */
        case 13: //enter
           // this.textbox.value = this.userText;
            //globals.location_name=this.textbox.value;
            oEvent.returnValue = false;
            if (oEvent.preventDefault) {
                oEvent.preventDefault();
            }
            this.hideSuggestions();
            //alert (globals.location_name);
            document.getElementById("button_go").focus();
            break;
    }

};

/**
 * Handles keyup events.
 * @scope private
 * @param oEvent The event object for the keyup event.
 */
AutoSuggestControl.prototype.handleKeyUp = function (oEvent /*:Event*/) {

    var iKeyCode = oEvent.keyCode;
    var oThis = this;
  
    var withAccents = new Array('è','ê','î','ï','à','â','ä','ù','ü','û','ç','ô','ö','ò');
    var withoutAccents = new Array('e','e','i','i','a','a','a','u','u','u','c','o','o','o');
    //get the currently entered text
    //this.userText = this.textbox.value.replace(/^\s+|\s+$/g, '');//on trim !
    tmpText = this.textbox.value;
    for(var i=0;i < withAccents.length;i++)
    {    
        tmpText = tmpText.replace(withAccents[i],withoutAccents[i]); 
    }  
          
    this.userText = tmpText;

    if(this.userText.length>=1 && this.userText.length!==''){
    	
   
 clearTimeout(this.timeoutId);
//alert(iKeyCode)
    
    /*if (iKeyCode == 32 ) {stop_sujjest = 1};*/
    if (iKeyCode == 8 || iKeyCode == 46) {stop_sujjest = 0};
    
   if (stop_sujjest==0){
   	
  
    //for backspace (8) and delete (46), shows suggestions without typeahead
    if (iKeyCode == 8 || iKeyCode == 46) {
       
        this.timeoutId = setTimeout( function () {
            oThis.provider.requestSuggestions(oThis, false);
        }, 2);
        
    //make sure not to interfere with non-character keys
    } else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode < 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
        //ignore
    } else {
        //request suggestions from the suggestion provider with typeahead
        this.timeoutId = setTimeout( function () {
            oThis.provider.requestSuggestions(oThis, true);
        }, 2);
    }
    
  }
    
     }
};

/**
 * Hides the suggestion dropdown.
 * @scope private
 */
AutoSuggestControl.prototype.hideSuggestions = function () {
    this.layer.style.visibility = "hidden";

if(this.selectedDestination!=null)
	
    if(document.getElementById("search_zone") != null) {

	    if( globals.loc_id != null ){
	        var loc_idsize = globals.loc_id.length;//alert(loc_idsize);
	        
			var varName = document.getElementById("search_zone").getAttribute('varName');
			var selectBoxInstance = null;
			if (varName != null) { //alert(varName);
			
	        	selectBoxInstance = getSelectBoxInstance(varName);//alert(selectBoxInstance);
	        	
			}

			if (selectBoxInstance != null) {
//cas pays ou region blocker champ proximite dans les filtres
                if(loc_idsize == 2 || loc_idsize == 5 ) {
                
				    selectBoxInstance.loadItem(0);
				    selectBoxInstance.disable(true);

	            } else {

				    selectBoxInstance.disable(false);
    				
	            }
	            
	        }
	  
        }
    }

};

/**
 * Highlights the given node in the suggestions dropdown.
 * @scope private
 * @param oSuggestionNode The node representing a suggestion in the dropdown.
 */
AutoSuggestControl.prototype.highlightSuggestion = function (oSuggestionNode) {
    
    for (var i=0; i < this.layer.childNodes.length; i++) {
        var oNode = this.layer.childNodes[i];
        if (oNode == oSuggestionNode) {
            oNode.className = "current";
		
		
		suggestion_id=oNode.getAttribute("id");

		if(suggestion_id!=null)
		{
			
			
			
			
			this.selectedDestination=this.destinationsParams[suggestion_id];
			if(this.selectedDestination!=null) {
			    globals.loc_id = this.selectedDestination["loc_id"];
			}
			//alert(this.selectedDestination["loc_id"])
			
		}
		

        } else if (oNode.className == "current") {
            oNode.className = "";
        }
    }
};

/**
 * Initializes the textbox with event handlers for
 * auto suggest functionality.
 * @scope private
 */
AutoSuggestControl.prototype.init = function () {

    //save a reference to this object
    var oThis = this;
   
    //assign the onkeyup event handler
    this.textbox.onkeyup = function (oEvent) {
    
    	
    	
    	
        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyUp() method with the event object 
       
        oThis.handleKeyUp(oEvent);
    };
    
    //assign onkeydown event handler
    this.textbox.onkeydown = function (oEvent) {

        //check for the proper location of the event object
        if (!oEvent) {
            oEvent = window.event;
        }    
        
        //call the handleKeyDown() method with the event object
        oThis.handleKeyDown(oEvent);
    };
    
    //assign onblur event handler (hides suggestions)    
    this.textbox.onblur = function () {
        document.getElementById("button_go").focus();
        oThis.hideSuggestions();
        
    };
    
    //create the suggestions dropdown
    this.createDropDown();

    oThis.separatorsTranslations["__Pays"] = js_pays;
    oThis.separatorsTranslations["__RegionDept"] = js_dep_regions;
    oThis.separatorsTranslations["__Villes"] = js_villes;
    oThis.separatorsTranslations["__Separator"] = "--------------------------------";

};

/**
 * Selects a range of text in the textbox.
 * @scope public
 * @param iStart The start index (base 0) of the selection.
 * @param iEnd The end index of the selection.
 */
AutoSuggestControl.prototype.selectRange = function (iStart /*:int*/, iEnd /*:int*/) {

    //use text ranges for Internet Explorer
    if (this.textbox.createTextRange) {
        var oRange = this.textbox.createTextRange(); 
        oRange.moveStart("character", iStart); 
        oRange.moveEnd("character", iEnd - this.textbox.value.length);      
        oRange.select();
        
    //use setSelectionRange() for Mozilla
    } else if (this.textbox.setSelectionRange) {
        this.textbox.setSelectionRange(iStart, iEnd);
    }     

    //set focus back to the textbox
    this.textbox.focus();      
   //document.getElementById("button_go").focus();
}; 

/**
 * Returns a understandable text from suggestion data
 * @scope private
 * @param unparsed string containing suggestion data.
 */
AutoSuggestControl.prototype.translateSuggestionData = function(suggestionData /*:string*/)
{
	destinationInfos=suggestionData.split(':');
	coddest=destinationInfos[0];
	destination=destinationInfos[1];
	type=destinationInfos[2];
	
	var nomregion = null;
	if (destinationInfos[6] && destinationInfos[6]!='inconnu'){
	nomregion=destinationInfos[6];
	}
	var nomdept = null;
	if (destinationInfos[7] && destinationInfos[7]!='inconnu'){
	nomdept=destinationInfos[7];
	}
	
	var coddestlocal = '';
	if (destinationInfos[8] && destinationInfos[8]!=''){
	coddestlocal = ' ('+destinationInfos[8]+')';
	}
	
	destination += coddestlocal;
	//nboffres=destinationInfos[3];

	result="";

	if(destinationInfos.length==this.minDestinationDataLength)
	{	
	    //result=destination+" - "+nboffres+" "+"annonce(s)";
	    result=destination;
	}
	else
	{	
	    //nompays=destinationInfos[4];
	    nompays=destinationInfos[3];
		//result=destination+" - "+nompays+" - "+nboffres+" "+"annonce(s)";
		
	if (!nomregion && !nomdept) {		
		result=destination+" - "+nompays;
		} 
	
	if (nomdept && nomregion) {
		result=destination+" - "+nomregion+" - "+nompays;
		} 
		
			
	if (nomregion && !nomdept) {
		result=destination+" - "+nomregion+" - "+nompays;
		
		}
		
		
		if (!nomregion && nomdept) {
		result=destination+" - "+nomdept+" - "+nompays;
		
		}
		
		
		
		
	} //end if - else
	
	return result;
}//end function





AutoSuggestControl.prototype.removeNbAnnonces = function(suggestionText /*:string*/)
{
	onlyDestination=suggestionText.split(" - ");
	destination=onlyDestination[0];
	

	result="";

	if(onlyDestination.length==2)
	{	result=destination; }
	else
	{	nompays=onlyDestination[1];
		result=destination+" - "+nompays;
	}
	
	return result;
}


/**
 * Builds the suggestion layer contents, moves it into position,
 * and displays the layer.
 * @scope private
 * @param aSuggestions An array of suggestions for the control.
 */
AutoSuggestControl.prototype.showSuggestions = function (aSuggestions /*:Array*/) {
    
    var oDiv = null;
    this.layer.innerHTML = "";    
    
    
    for (var i=0; i < aSuggestions.length; i++) {

	  isSeparator = 0;

	  for(var separator in this.separatorsTranslations)
	  {	
		if(aSuggestions[i]==separator)
				isSeparator = 1;
	  }

	  if(isSeparator==1) {
	    	if(aSuggestions[i]=="__Separator")
	    	{
	    		oDiv = document.createElement("SPAN");
			    oDiv.innerHTML = "--------------------------------<br/>";		
	  		    this.layer.appendChild(oDiv);
 	    	} else {

	    	    oDiv = document.createElement("SPAN");
	    	    //oDiv.setAttribute("style","font-size:10pt;font-weight:bold");	
			    oDiv.style.fontSize="10px";
			    oDiv.style.fontWeight="bold";
			    oDiv.style.fontFamily="verdana";
			    //oDiv.setAttribute("class","Property_WhereTitle");
	      	    oDiv.appendChild(document.createTextNode(this.separatorsTranslations[aSuggestions[i]]));
          	    this.layer.appendChild(oDiv);
		    }
	  } else  {	
		oDiv = document.createElement("div");
		oDiv.setAttribute("id","destination"+i);
	      //oDiv.setAttribute("style","font-size:10pt");
		oDiv.style.fontSize="10px";
		oDiv.style.fontFamily="verdana";
		oDiv.appendChild(document.createTextNode(this.translateSuggestionData(aSuggestions[i])));
	  	this.layer.appendChild(oDiv);
            
	  }
    }

    this.destinationsParams = new Array();

    for (var i=0; i < aSuggestions.length; i++) {

		destination_id="destination"+i;

		isSeparator = 0;

	  	for(var separator in this.separatorsTranslations)
	  	{	
			if(aSuggestions[i]==separator)
				isSeparator = 1;
	  	}

		if(isSeparator==0)
		{
			destinationInfos=aSuggestions[i].split(':');
			coddest=destinationInfos[0];
			lat="";lng="";
			
			if(destinationInfos.length==this.minDestinationDataLength)
			{	
				/*lat=destinationInfos[4];
				lng=destinationInfos[5];*/
				lat=destinationInfos[3];
				lng=destinationInfos[4];
			}
			else
			{	
				/*lat=destinationInfos[5];
				lng=destinationInfos[6];*/
				lat=destinationInfos[4];
				lng=destinationInfos[5];
			}
			
			
			this.destinationsParams[destination_id]=new Array();
			this.destinationsParams[destination_id]["loc_id"]=coddest;
			this.destinationsParams[destination_id]["center_location_lat"]=lat;
			this.destinationsParams[destination_id]["center_location_lng"]=lng;
			/*oHiddenField = document.createElement("input");
			oHiddenField.setAttribute("type","hidden");
			oHiddenField.setAttribute("id","destination"+i+"_id");
			oHiddenField.setAttribute("value",coddest);
		
			this.layer.appendChild(oHiddenField);*/
			
		}

		
    }

    
    this.layer.style.left = this.getLeft() + "px";
    this.layer.style.top = (this.getTop()+this.textbox.offsetHeight) + "px";
    this.layer.style.visibility = "visible";
   

};

/**
 * Inserts a suggestion into the textbox, highlighting the 
 * suggested part of the text.
 * @scope private
 * @param sSuggestion The suggestion for the textbox.
 */
AutoSuggestControl.prototype.typeAhead = function (sSuggestion /*:String*/) {

    //check for support of typeahead functionality
  
    if (this.textbox.createTextRange || this.textbox.setSelectionRange){
             
    	//if (sSuggestion!=='--Villes--' && sSuggestion!==''){
       var iLen = this.textbox.value.length; 
       this.textbox.value = sSuggestion; 
       this.selectRange(iLen, sSuggestion.length);
        //}
       
    }
    
};

/**
 * Provides suggestions for state/province names.
 * @class
 * @scope public
 */
function SuggestionProvider() {
    //
	
this.http = zXmlHttp.createRequest(); 
//console.log("hi");
    //this.http = $.ajax();
}

/**
 * Request suggestions for the given autosuggest control. 
 * @scope protected
 * @param oAutoSuggestControl The autosuggest control to provide suggestions for.
 */
SuggestionProvider.prototype.requestSuggestions = function (oAutoSuggestControl /*:AutoSuggestControl*/,
                                                            bTypeAhead /*:boolean*/) {

    var oHttp = this.http;
                                   
    //cancel any active requests                          
    if (oHttp.readyState != 0 && oHttp) {
       oHttp.abort();
    }                 
    
	myText = oAutoSuggestControl.userText.replace(/^\s+|\s+$/g, '');
	
    //define the data
    var oData = { 
        requesting: "Regions", 
        text: myText,
        limit: 5
    };
    
	
    //open connection to server
    if(oHttp && (myText!=globals.langs_indifferent) && (myText.length > 1)) {
		oHttp.open('GET', globals.server+globals.lang+"/ws_auto/wsauto_text/"+encodeURI(myText), true);
		oHttp.onreadystatechange = function () {
			if (oHttp.readyState == 4 && oHttp.responseText) {
			//if (oHttp.readyState == 4) {
				//if(oHttp.status == 200 || oHttp.status == 304)
				//{
					//evaluate the returned text JavaScript (an array)
					var aSuggestions = JSON.parse(oHttp.responseText);
					//provide suggestions to the control
					//alert(aSuggestions);
					oAutoSuggestControl.autosuggest(aSuggestions, bTypeAhead);
				//}       
			}    
		};

		//send the request
		oHttp.send(JSON.stringify(oData));
	} else {
	
		oAutoSuggestControl.hideSuggestions();
		
	}
	
	if(myText=='')
	{
		globals.location_name='';
		globals.loc_id = 0;
	}
};