business_array = new Array();
address_array = new Array();
function AutoSuggestControl(oTextbox, oProvider ) {
    this.provider  = oProvider;
    this.textbox  = oTextbox;
    this.init();    
}

AutoSuggestControl.prototype.autosuggest = function (aSuggestions) {
    if (aSuggestions.length > 0) {
        this.typeAhead(aSuggestions[0]);
    }
};

AutoSuggestControl.prototype.handleKeyUp = function (oEvent) {
    var iKeyCode = oEvent.keyCode;
    if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
    } else {
        this.provider.requestSuggestions(this);
    }
};

AutoSuggestControl.prototype.init = function () {
    var oThis = this;
    this.textbox.onkeyup = function (oEvent) {
        if (!oEvent) {
            oEvent = window.event;
        }    
        oThis.handleKeyUp(oEvent);
    };
};

AutoSuggestControl.prototype.selectRange = function (iStart, iLength) {
    if (this.textbox.createTextRange) {
        var oRange = this.textbox.createTextRange(); 
        oRange.moveStart("character", iStart); 
        oRange.moveEnd("character", iLength - this.textbox.value.length);      
        oRange.select();
    } else if (this.textbox.setSelectionRange) {
        this.textbox.setSelectionRange(iStart, iLength);
    }     
    this.textbox.focus();      
}; 

AutoSuggestControl.prototype.typeAhead = function (sSuggestion) {
    if (this.textbox.createTextRange || this.textbox.setSelectionRange){
        var iLen = this.textbox.value.length; 
        this.textbox.value = sSuggestion; 
        this.selectRange(iLen, sSuggestion.length);
    }
};


function Suggestions() {
	this.business = populatearray(1);
}

Suggestions.prototype.requestSuggestions = function (oAutoSuggestControl) {
    var aSuggestions = [];
    var sTextboxValue = oAutoSuggestControl.textbox.value;
  
    if (sTextboxValue.length > 0){
        for (var i=0; i < this.business.length; i++) { 
            if (this.business[i].indexOf(sTextboxValue) == 0) {
                aSuggestions.push(this.business[i]);
            } 
        }
    }
    oAutoSuggestControl.autosuggest(aSuggestions);
};

function populatearray(value){
	if(document.cookie){
		ind_del=document.cookie.indexOf("deliverystring");
		if (ind_del != -1){
			startstr=(document.cookie.indexOf("=",ind_del))+1;
			endstr=document.cookie.indexOf(";",ind_del);
		if(endstr==-1){
			endstr = document.cookie.length;
		}
		data_del=document.cookie.substring(startstr,endstr);
		if(data_del=='deliverystring'){
			data_del='';
		}
		if(data_del != ''){
			myarray = data_del.split('#');
			for(i=0;i<myarray.length-1;i++){
				final_array = myarray[i].split("~");
					business_array.push(final_array[0]);
					for(j=0;j<final_array.length;j++){
						address_array.push(final_array[j]);
					}

			}
		}
	}
	if(value == 1)
		return business_array;
	else
		return address_array;			
}
	else{
		return false;			
	}
}

function filladdress(){
	value1 = document.getElementById("txt1").value;
	address = populatearray(2);
	if(address != ''){
		add_index = address.indexOf(value1);
		if (add_index != -1){
			busdelcity = address[add_index + 2];
			document.form1.Del_Address.value=address[add_index + 1] ;
			document.form1.Del_City.options[busdelcity].selected=true;
		}
	}
}
