function CustomerLookupDiv(oPositionAnchor /*:Anchor to use as position offset point */,
									oLeftOffset, oTopOffset, selFunction) {
    this.selectionNodeStartIndex = 1;
    this.cur = this.selectNodeStartIndex - 1;
    this.leftOffset = oLeftOffset;
    this.topOffset = oTopOffset;
    if (selFunction == null) {
      this.selectedFunction = '';
    } else {
      this.selectedFunction = selFunction;
    }    

    /**
     * The dropdown list layer.
     * @scope private
     */
    this.layer = null;
    
    /**
     * An anchor to use as an offset position point
     * @scope private
     */
    this.positionAnchor /*:HTMLInputElement*/ = oPositionAnchor;
   /**
     * The selected location code
     * @scope private
     */
   	this.cellPrefix = "";
   	this.cellSuffix = "&nbsp;";
   	
   	this.estScrollBarWidth = 26;

    //initialize the control
    this.init();
    
}
/**
 * Creates Layer
 * Initializes layer with event functions
 * auto suggest functionality.
 * @scope private
 */
CustomerLookupDiv.prototype.init = function () {

    //save a reference to this object
    var oThis = this;
    //create the suggestions dropdown
    this.createDiv();


    //assign onkeydown event handler
    this.layer.childNodes[1].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);
    };
    this.layer.childNodes[1].onmousedown = 
	this.layer.childNodes[1].onmouseup = 
	this.layer.childNodes[1].onclick = 
	this.layer.childNodes[1].onmouseover = function (oEvent) {
        oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;
       
        var eventX = oEvent.offsetX ? oEvent.offsetX : oEvent.layerX;
        var layerWidth = oThis.layer.childNodes[1].childNodes[0].offsetWidth;
        var eventY = oEvent.offsetY ? oEvent.offsetY : oEvent.layerY;
        var layerHeight = oThis.layer.childNodes[1].childNodes[0].offsetHeight;
			if (eventX > layerWidth || eventY > layerHeight) {
			   return;
			}
	    if (oTarget.nodeName != "TR") {
	    	oTarget = oThis.getSelectedRow(oTarget);
	    } 
	    //alert ("target=" + oTarget + " event="+ oEvent.type);
        if (oEvent.type == "mousedown" || oEvent.type == "click" || oEvent.type == "mouseup") {
        	//alert (" oTarget.rowIndex=" + oTarget.rowIndex + " selectionNodeStartIndex=" + oThis.selectionNodeStartIndex);
            if (oTarget.rowIndex >= oThis.selectionNodeStartIndex) {
        		oThis.setSelectionFields(oTarget);
        	}
        } else if (oEvent.type == "mouseover") {
            oThis.highlightSuggestion(oTarget);
        } else {
        	if (oTarget.rowIndex >= oThis.selectionNodeStartIndex) {
            	oThis.hideSuggestions();
        	}
        }
    };
};

/**
 * Creates the dropdown layer to display multiple suggestions.
 * @scope private
 */
CustomerLookupDiv.prototype.createDiv = function () {

	this.layer = document.getElementById('customerLookupDiv');
	if (!this.layer) {
    	//create the layer and assign styles
    	//create the lookup fields inputs
    	this.layer = document.createElement("div");
    	this.layer.id = "customerLookupDiv";
    	this.layer.className = "customerLookupDiv";
    	this.layer.style.visibility = "hidden";
   	    document.body.appendChild(this.layer);
        this.addLookupFields();
        var resultsDiv = document.createElement("div");
        resultsDiv.className = "customerResultsDiv";
        this.layer.appendChild(resultsDiv);
        var	tableEl = document.createElement("table");
    	tableEl.className = "lookupResults";
    	tableEl.id = "customerResults";
    	resultsDiv.appendChild(tableEl);
    }
	this.layer.style.left = this.getLeft() + "px";
    this.layer.style.top = this.getTop() + "px";
    this.layer.style.visibility = "visible";
};
/**
 * Creates the dropdown layer to display multiple suggestions.
 * @scope private
 */
CustomerLookupDiv.prototype.addLookupFields = function () {
    var tableEl = document.createElement("table");
    this.layer.appendChild(tableEl);
    var tbody = document.createElement("tbody");
    tableEl.appendChild(tbody);
    tbody.appendChild(this.getHeaderRow1());
    tbody.appendChild(this.getCustNameCity());
};
CustomerLookupDiv.prototype.getHeaderRow1 = function () {
    var oThis = this;
 	var tableRow = document.createElement("tr");
 	var cell = document.createElement("td");
 	cell.colSpan = 3;
 	cell.className = "titleText";
 	cell.id="closeCustLookup";
 	var closeWindow = document.createElement("img");
 	closeWindow.src = "/LTMSLite/images/closeLookup.gif";
 	closeWindow.width=150;
 	closeWindow.height=24;
 	closeWindow.hspace=25;
 	closeWindow.onclick = function (){
 		oThis.hideSuggestions();
 	}; 
	cell.appendChild(closeWindow);
	tableRow.appendChild(cell);
    return tableRow;
};
CustomerLookupDiv.prototype.getCustNameCity = function () {
    var searchRow = document.createElement("tr");
    var searchCell = document.createElement("td");
    searchCell.colSpan = 6;
	var cSearchTable = document.createElement("table");
    var cSearchTbody = document.createElement("tbody");
    cSearchTable.appendChild(cSearchTbody);
    var cErrorRow = document.createElement("tr");
    var cErrorCell = document.createElement("td");
    cErrorCell.colSpan = 6;
    cErrorCell.display = "none";
    cErrorCell.id  = "cSearchError";
    cErrorCell.className = "errors";
    cErrorRow.appendChild(cErrorCell);
    cSearchTbody.appendChild(cErrorRow);
	var tableRow = document.createElement("tr");	
 	var cell1 = document.createElement("td");
 	cell1.className = "searchlabel";
 	cell1.innerHTML  = "<nobr>Cust. Name</nobr>";
 	tableRow.appendChild(cell1);
 	var cell2 = document.createElement("td");
 	var textEl = document.createElement("input");
 	textEl.type = "text";
 	textEl.name="custName";
 	textEl.id = "custName";
 	textEl.className = "searchtext2";
 	textEl.onblur = function(){upCase(this)};
    cell2.appendChild(textEl);
    tableRow.appendChild(cell2);
    var cell3 = document.createElement("td");
    cell3.className = "searchlabel";
 	cell3.innerHTML  = "<nobr>City</nobr>";
	tableRow.appendChild(cell3);
    var cell4 = document.createElement("td");
 	var textEl2 = document.createElement("input");
 	textEl2.type = "text";
 	textEl2.name="custCity";
 	textEl2.id = "custCity";
 	textEl2.className = "searchtext2";
 	textEl2.onblur = function(){upCase(this)};
    cell4.appendChild(textEl2);    
	tableRow.appendChild(cell4);
	var cell5 = document.createElement("td");
	var anchor = document.createElement("a");
	anchor.className = "imageAnchor";
	anchor.href = "javascript:findCustomerByNameCity('"+ this.selectedFunction +"');";
	var image = document.createElement("img");
	image.id="cust_findByNameButton";
	image.src = "/LTMSLite/images/search.gif";
	image.height=24;
	image.width=83;
	image.border=0;
	image.onmousedown = "changeImage(this,'images/searchClicked.gif')";
	image.onmouseup = "changeImage(this,'images/search.gif')";
	anchor.appendChild(image);
	cell5.appendChild(anchor);
	tableRow.appendChild(cell5);
	cSearchTbody.appendChild(tableRow);
	searchCell.appendChild(cSearchTable);
	searchRow.appendChild(searchCell);
	return searchRow;
};
/**
 * Gets the left coordinate of the textbox.
 * @scope private
 * @return The left coordinate of the textbox in pixels.
 */
CustomerLookupDiv.prototype.getLeft = function () {

    var oNode = this.positionAnchor;
    var iLeft = 0;
    while(oNode.tagName != "BODY" && oNode.tagName != "HTML") {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;        
    }
    var retVal = iLeft + this.leftOffset;
    return iLeft + this.leftOffset;
};

/**
 * Gets the top coordinate of the textbox.
 * @scope private
 * @return The top coordinate of the textbox in pixels.
 */
CustomerLookupDiv.prototype.getTop = function ()  {

    var oNode = this.positionAnchor;
    var iTop = 0;
    
    while(oNode.tagName != "BODY" && oNode.tagName != "HTML") {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }
    var retVal = iTop + this.topOffset;
    return iTop + this.topOffset;
};
/**
 * Returns the table rows in the div
 * @scope private
 */
CustomerLookupDiv.prototype.getSelectionNodes = function ()  {
    return this.layer.childNodes[1].childNodes[0].childNodes[0].childNodes;
};

/**
 * Handles three keydown events.
 * @scope private
 * @param oEvent The event object for the keydown event.
 */
CustomerLookupDiv.prototype.handleKeyDown = function (oEvent /*:Event*/) {
 		oEvent = oEvent || window.event;
        oTarget = oEvent.target || oEvent.srcElement;
    switch(oEvent.keyCode) {
        case 38: //up arrow
            this.previousSuggestion();
            this.layer.childNodes[1].focus();
            break;
        case 40: //down arrow 
            this.nextSuggestion();
            this.layer.childNodes[1].focus();
            break;
        case 13: //enter
            this.setSelectionFields(this.getSelectionNodes()[this.cur]);
            this.hideSuggestions();
            break;
    }

};
CustomerLookupDiv.prototype.getSelectedRow = function(oTarget) {
    if (oTarget.nodeName == "TR") return oTarget;
	else if (oTarget.nodeName == "DIV" || oTarget.nodeName == "TABLE" || oTarget.nodeName == "TBODY") {
		return this.getSelectedRow(oTarget.childNodes[0]);
	} else {
	    return this.getSelectedRow(oTarget.parentNode);
	}
};

/**
 * Hides the suggestion dropdown.
 * @scope private
 */
CustomerLookupDiv.prototype.hideSuggestions = function () {
    this.layer.style.visibility = "hidden";
};

/**
 * Highlights the given node in the suggestions dropdown.
 * @scope private
 * @param oSuggestionNode The node representing a suggestion in the dropdown.
 */
CustomerLookupDiv.prototype.highlightSuggestion = function (tableRow) {
    //alert ("in highlight suggestion");
    var tableRows = this.getSelectionNodes();
    
    for (var i=this.selectionNodeStartIndex; i < tableRows.length; i++) {
        var oNode = tableRows[i];
        if (oNode == tableRow) {
            oNode.className = "currentSelection";
            this.cur = i;
        } else if (oNode.className == "currentSelection") {
            oNode.className = "";
        }
    }
    this.layer.childNodes[1].focus();
};



/**
 * Highlights the next suggestion in the dropdown
 * @scope private
 */
CustomerLookupDiv.prototype.nextSuggestion = function () {
   
    var cSuggestionNodes = this.getSelectionNodes();
    if (cSuggestionNodes.length > this.selectionNodeStartIndex && this.cur < cSuggestionNodes.length-1) {
        var oNode = cSuggestionNodes[++this.cur];
        this.highlightSuggestion(oNode);
    }
    this.layer.childNodes[1].focus();
};

/**
 * Highlights the previous suggestion in the dropdown
 * @scope private
 */
CustomerLookupDiv.prototype.previousSuggestion = function () {
    var cSuggestionNodes = this.getSelectionNodes();

    if (cSuggestionNodes.length > 0 && this.cur > this.selectionNodeStartIndex) {
        var oNode = cSuggestionNodes[--this.cur];
        this.highlightSuggestion(oNode);
    }
    this.layer.childNodes[1].focus();
};
/**
 * Builds the suggestion layer contents, moves it into position,
 * and displays the layer.
 * @scope private
 * @param aSuggestions An array of suggestions for the control.
 */
function showCustomerSuggestions (aSuggestions /*:Array*/) {
	var cellPrefix = "";
   	var cellSuffix = "&nbsp;";
    var customerDiv = document.getElementById('customerLookupDiv');
    var resultsDiv = customerDiv.childNodes[1];
    var tableEl = resultsDiv.childNodes[0];
    // to clear previous results
    if (tableEl.childNodes.length > 0)
    tableEl.removeChild(tableEl.childNodes[0]);
    var	tbody = document.createElement("tbody");
    tableEl.appendChild(tbody);
    tbody.appendChild(getCustomerHeaderRow2(cellPrefix,cellSuffix));
    for (var i=0; i < aSuggestions.length; i++) {
        tableRow = document.createElement("tr");
        tbody.appendChild(tableRow);
        for (var k = 0; k < aSuggestions[i].length; k++) {
            var nextCell = document.createElement("td");
            nextCell.className = "customerCol" + k;
            nextCell.style.whiteSpace = "nowrap";
            tableRow.appendChild(nextCell);
        	nextCell.innerHTML = cellPrefix + aSuggestions[i][k] + cellSuffix;
        }
    }
    if (tableEl.rows.length > 1) 
   	tableEl.rows[1].className =  "currentSelection";
   	resultsDiv.focus();
}
function getCustomerHeaderRow2 (cellPrefix, cellSuffix) {
 	var tableRow = document.createElement("tr");
    var header1 = document.createElement("td");
    header1.className="lookupHeader";
    header1.innerHTML = cellPrefix + 'Customer #' + cellSuffix;
    tableRow.appendChild(header1);
    var header2 = document.createElement("td");
    header2.className="lookupHeader";
    header2.innerHTML = cellPrefix + 'Name' + cellSuffix;
    tableRow.appendChild(header2);
    var header5 = document.createElement("td");
    header5.className="lookupHeader";
    header5.innerHTML = cellPrefix + 'City' + cellSuffix;
    tableRow.appendChild(header5);
    var header6 = document.createElement("td");
    header6.className="lookupHeader";
    header6.innerHTML = cellPrefix + 'State' + cellSuffix;
    tableRow.appendChild(header6);
    var header3 = document.createElement("td");
    header3.className="lookupHeader";
    header3.innerHTML = cellPrefix + 'Address 1' + cellSuffix;
    tableRow.appendChild(header3);
    var header4 = document.createElement("td");
    header4.className="lookupHeader";
    header4.innerHTML = cellPrefix + 'Address 2' + cellSuffix;
    tableRow.appendChild(header4);
    var header7 = document.createElement("td");
    header7.className="lookupHeader";
    header7.innerHTML = cellPrefix + 'Zip' + cellSuffix;
    tableRow.appendChild(header7);
    return tableRow;
}
CustomerLookupDiv.prototype.setSelectionFields = function (tableRow) {
    var custNum = tableRow.cells[0].innerHTML;
    if ("custLookup" != this.selectedFunction) {
	    setValue('customerNumber',custNum.substring(this.cellPrefix.length, custNum.length - this.cellSuffix.length));
   	 	findCustomerByNumber(false,false);
   	 	this.hideSuggestions();
   	}
};

