   ///document.onLoad = setTimeout("getList('merchant_id')",1000);

function alphaNumSort(m,n){
        try{
            var cnt= 0, ax, tem;
            var a= m.toLowerCase();
            var b= n.tpLowerCase(); 
            if(a== b) return 0; 
            var x=/^(\.)?\d/;
                     
            var L= Math.min(a.length,b.length)+ 1;            
            while(cnt< L && a.charAt(cnt)=== b.charAt(cnt) && 
            x.test(b.substring(cnt))== false && x.test(a.substring(cnt))== false) cnt++;
            a= a.substring(cnt);
            b= b.substring(cnt);
                    
                if(x.test(a) || x.test(b)){        
                    if(x.test(a)== false)return (a)? 1: -1;
                    else if(x.test(b)== false)return (b)? -1: 1;
                    else{
                            tem= parseFloat(a)-parseFloat(b);
                            if(tem!= 0) return tem;
                            else tem= a.search(/[^\.\d]/);
                            if(tem== -1) tem= b.search(/[^\.\d]/);
                            a= a.substring(tem);
                            b= b.substring(tem);
                    }
                }
                if(a== b) return 0;            
            else return (a >b)? 1: -1;
    }
    catch(er){            
            return 0;
    }
}


/*	function sortList(a,b) {
		return ((a.toLowerCase() < b.toLowerCase()) ? -1 : ((a.toLowerCase() > b.toLowerCase()) ? 1 : 0));		
	}
	*/
	updateListField = null;
	
   ///RETRIEVE MERCHANT LIST
	function getList(target) {
		
		if(document.getElementById('merchantListUL').getElementsByTagName("LI").length == 2) {
			if(typeof target == 'string') {
				
				updateListField = target;
			}
			else {
				updateListField = target.id;
			}
			
         ///if(document.getElementById(updateListField).options.length == 2) {
			
			createRequest();
			var url = "/stores/ajax_menu/index.htm";
			request.open("post",url,true);
			request.onreadystatechange = populateList;
			request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			request.send(null);
		}
	}


   ///POPULATE MERCHANT LIST WITH DATA FROM GETLIST()
	var selectActive = false;
	var singleFocus = false;
	var clickClose = false;
	function populateList() {
		target = updateListField;
		if(request.readyState == 4) {
			if(request.status == 200) {
				var list = request.responseText;

				if(list) {
					var target = document.getElementById('merchantListUL');
					
               ///PARSE MERCHANT DATA
					listArray = list.split("^");
					for(i=0;i<listArray.length;i++) {
						listArray[i] = listArray[i].replace(/([^0-9|A-z|" "|\-|\||\%|\$|\.|\&])/g, "");
					}
					sortedListArray = listArray.sort(alphaNumSort);
					
               ///DETERMINE IF AGENT CAN DISPLAY BACKGROUND HIGHLIGHT ROLLOVER EFFECTS
					if((parseInt(navigator.appVersion.split('MSIE')[1]) && parseInt(navigator.appVersion.split('MSIE')[1]) == 6)) {
						var displayMenuEffects = false;
					}
					else {
						var displayMenuEffects = true;
					}
					
               ///REMOVE LOADING DIALOG ITEMS
					var initMerchantListLIs = target.getElementsByTagName("LI");
					for(i=0;i<initMerchantListLIs.length;i++) {
						if(initMerchantListLIs[i].className.match("loadingLI")) {
							target.removeChild(initMerchantListLIs[i]);
						}
					}
					
               ///GENERATE LIST ITEMS FOR EACH MERCHANT RECORD
					for(i=0;i<listArray.length;i++) {
						var optionRaw = listArray[i].split("|");
						var optionValue = optionRaw[2];
						var optionRebate = optionRaw[1];
						var optionText = optionRaw[0];
						
						var newLI = document.createElement("LI");
						newLI.id = optionValue;
							
						var newLIText = document.createTextNode(optionText);
						var newLIValue = document.createTextNode(optionRebate);
						
						var newTextSpan = document.createElement("span");
						newTextSpan.className = 'optionText';
						var newValueSpan = document.createElement("span");
						newValueSpan.className = 'optionValue';
						
						newTextSpan.appendChild(newLIText);
						newValueSpan.appendChild(newLIValue);
						newLI.appendChild(newTextSpan);
						newLI.appendChild(newValueSpan);

                  /*if(displayMenuEffects) {
							newLI.onmouseover = function() { this.className += 'over'; window.status = this.innerHTML.replace('optionValue>',' - ').replace(/<\S[^><]*>/g, "").replace("<SPAN class=","").replace("&amp;","\&"); };
                     newLI.onmouseout = function() { this.className = this.className.replace(/(over)/g,''); };  ##this.style.background = '#ffffff'
                  }*/
						
						if(displayMenuEffects) {
								newLI.onmouseover = function() { this.style.fontWeight = 'bold'; this.childNodes[0].style.color = '#000000'; window.status = this.innerHTML.replace('optionValue>',' - ').replace(/<\S[^><]*>/g, "").replace("<SPAN class=","").replace("&amp;","\&"); };
								newLI.onmouseout = function() { this.style.fontWeight = 'normal'; this.childNodes[0].style.color = '#7f7f7f'; };
						}
						else {
								newLI.onmouseover = function() { this.childNodes[0].style.color = '#000000'; window.status = this.innerHTML.replace('optionValue>',' - ').replace(/<\S[^><]*>/g, "").replace("<SPAN class=","").replace("&amp;","\&"); };
								newLI.onmouseout = function() { this.childNodes[0].style.color = '#7f7f7f'; };
						}

						newLI.onclick = function() {  var newWin = window.open('/mall_ctrl.do?merchant_id='+this.id+'&navigation_id=17999',this.id+'Win'); closeSelect2(1); newWin.focus(); };
						
						target.appendChild(newLI);
					}
				}
			}
		}
		else {

		}
	}
	
	
   ///SET MENU STATE TO ACTIVE AND APPEND LIST WITH LOADING ITEM(S)
	function openSelect(target) {
		if(target.className.match('active')) {
			target.className = target.className.replace(/(active)/g,'');
		}
		else {
			target.innerHTML += '<li class="loadingLI">Loading...</li>';
         document.getElementById('merchantListTopA').focus();  ///ACCOMMODATE FF BUG IN WHICH MENU SCROLL POINT IS RESTORED
			clickClose = false;
			getList('merchant_id');
			target.className += ' active';
		}
	}
	
   ///IF USER HAS NOT SELECTED AN OPTION, DELAY CLOSING MENU TO CHECK IF USER IS STILL OPERATING IT
	function closeSelect(target) {
		if(!clickClose) {
			setTimeout("closeSelect2()",4000);
			singleFocus = false;
		}
	}
	
   ///CLOSE MENU: RESTORE MENU TO INACTIVE STATE, RESET CONTENT, ASSIGN FOCUS TO DEFAULT/TOP ITEM
	function closeSelect2(closeSwitch) {
		if(closeSwitch && closeSwitch == 1) {
			clickClose = true;
			document.getElementById('merchantListUL').className = document.getElementById('merchantListUL').className.replace(/(active)/g,"");
			if(!singleFocus) {
				document.getElementById('merchantListUL').innerHTML = '<li class="merchantListTopLI"><span class="optionText"><a href="javascript: void(0);" id="merchantListTopA" name="merchantListTopA">Select a store</a></span><span class="optionValue"></span></li>';
				document.getElementById('merchantListTopA').focus();
				singleFocus = true;
			}
		}
		else {
			if(!selectActive && !clickClose) {
				document.getElementById('merchantListUL').className = document.getElementById('merchantListUL').className.replace(/(active)/g,"");
				if(!singleFocus) {
					document.getElementById('merchantListUL').innerHTML = '<li class="merchantListTopLI"><span class="optionText"><a href="javascript: void(0);" id="merchantListTopA" name="merchantListTopA">Select a store</a></span><span class="optionValue"></span></li>';
					document.getElementById('merchantListTopA').focus();
					singleFocus = true;
				}
			}
			else {
            ///setTimeout("closeSelect()",5000);
			}
		}
	}

	suckerfish(sfFocus, "INPUT");	