function CreateXmlHttpL(DivDropDownList, SelectedTextLabel, SearchOptionField, EntityFieldId, DataTypeFieldId, URL, indicatorImgPath)
{                                
    var that = this;                                                    
    this.updating = false;                                            
    this.callback = function () {}                                   

    this.update = function() 
    {                              
        if (that.updating == true) 
        { 
            return false; 
        }    

        that.updating = true;                                           
        var xmlHttp = null;          

        if (window.XMLHttpRequest) 
        {                                 
            xmlHttp = new XMLHttpRequest();                                
        } 
        else 
        {                                                             
            try
            {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(e)
            {
                try
                {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(oc)
                {
                    xmlHttp = null;
                }
            }      
        }                                                              

        if (xmlHttp == null) 
        {                                             
            return false;                                               
        } 
        else 
        {             
            xmlHttp.onreadystatechange = function() 
            {                               
                if (xmlHttp.readyState == 4) 
                { 
                    that.updating = false;                        
                    if (xmlHttp.status == 200) 
                    { 
                        //parseXML
                        ParseJSONandCreateDropDownList(DivDropDownList, SelectedTextLabel, SearchOptionField, EntityFieldId, DataTypeFieldId, xmlHttp.responseText);
                    } 
                    else 
                    {
                        DivDropDownList.innerHTML = '<p style=\"padding:5px 5px 5px 2px;display:block;width:auto;\">Failed to get the feed you requested</p>';
                    }       
                    delete xmlHttp;         
                } 
                else
                {                            
                    if (indicatorImgPath != "")
                    {
                        DivDropDownList.innerHTML = "<img src='" + indicatorImgPath + "'> loading...";
                    }
                } 
            }                                   
        }    

        var uri = urlCall;  
        xmlHttp.open("GET", uri, true);                            
        xmlHttp.send('');                                        
        return true;                                                                                                                   
    }

    // This area set up on constructor calls.
    var urlCall = URL;                                               
} 

var DivDropDownListIdGlobal;
var SelectedTextLabelIdGlobal;

function GetList(mEvent, DivDropDownListId, SearchOptionFieldId, EntityFieldId, DataTypeFieldId, indicatorImgPath, applicationpath)
{
    //this is used in the document.onclick event
    DivDropDownListIdGlobal = DivDropDownListId;    
    
    var DivDropDownList = document.getElementById(DivDropDownListId);
    var SearchOptionField = document.getElementById(SearchOptionFieldId);           
    var SelectedTextLabel;
    
    //IE
    if (mEvent.srcElement)
    {
        SelectedTextLabel = mEvent.srcElement;
    }
    //Firefox
    else if (mEvent.target)
    {
        SelectedTextLabel = mEvent.target;
    }    
    
    SelectedTextLabelIdGlobal = SelectedTextLabel.id;
    
    DivDropDownList.innerHTML = "";

    var URL = "AJAX.aspx?method=HeaderMultiSearch";

    divtofill = new CreateXmlHttpL(DivDropDownList, SelectedTextLabel, SearchOptionField, EntityFieldId, DataTypeFieldId, URL, indicatorImgPath);      
    divtofill.update();
    DivDropDownList.style.display = "block";                            
}

function ParseJSONandCreateDropDownList(DivDropDownList, SelectedTextLabel, SearchOptionField, EntityFieldId, DataTypeFieldId, JSONData) 
{
    var itms = eval('(' + JSONData + ')');
    
    var ListDisplay; 
    var SelectedDisplay; 
    var SearchOption; 
    var i = 0;
    
    DivDropDownList.innerHTML = "";
    
    while (itms.ListItems[i] != null)
    {
        ListDisplay = itms.ListItems[i].ListDisplay; 
        SelectedDisplay = itms.ListItems[i].SelectedDisplay; 
        SearchField = itms.ListItems[i].SearchField;
        Entity = itms.ListItems[i].Entity;
        DataType = itms.ListItems[i].DataType;

        DivDropDownList.innerHTML += "<a href=\"#\" style=\"padding:5px 5px 5px 2px;display:block;width:auto;\""
        + "onkeyup=\"KeyCheckL(event, '" + SelectedDisplay + "', '" + SearchField + "', '" + SearchOptionField.id + "', '" + DivDropDownList.id + "', '" + SelectedTextLabel.id + "','" + EntityFieldId + "','" + Entity + "','" + DataTypeFieldId + "','" + DataType + "')\" "
        + "onclick=\"replaceTEXTL('" + SelectedDisplay + "', '" + SearchField + "', '" + SearchOptionField.id + "', '" + DivDropDownList.id + "', '" + SelectedTextLabel.id + "','" + EntityFieldId + "','" + Entity + "','" + DataTypeFieldId + "','" + DataType + "')\">" 
        + ListDisplay + "</a>";
        
        i++;
    }                              
}

function replaceTEXTL(SelectedDisplay, SearchField, SearchOptionFieldId, DivDropDownListId, SelectedTextLabelId, EntityFieldId, Entity, DataTypeFieldId, DataType)
{    
    SearchOptionField = document.getElementById(SearchOptionFieldId);
    DivDropDownList = document.getElementById(DivDropDownListId);
    SelectedTextLabel = document.getElementById(SelectedTextLabelId);
    EntityField = document.getElementById(EntityFieldId);
    DataTypeField = document.getElementById(DataTypeFieldId);
    
    SelectedTextLabel.innerHTML = SelectedDisplay;
    DivDropDownList.style.display = "none";    
    SearchOptionField.value = SearchField;
    EntityField.value = Entity;
    DataTypeField.value = DataType;
}

function CheckKeyPressL(mEvent, DivDropDownListId)
{
    DivDropDownList = document.getElementById(DivDropDownListId);
    if (DivDropDownList.style.display == "block")
    { 
        if (mEvent.keyCode == 40) //Arrow Down;
        {
            SearchBoxUpDownArrowPress(DivDropDownList);
            return;
        }
        else if (mEvent.keyCode == 27) //escape;
        {
            DivDropDownList.style.display = "none";
            return;
        }
    } 
}

function KeyCheckL(mEvent, SelectedDisplay, SearchOption, SearchOptionFieldId, DivDropDownListId, SelectedTextLabelId, DataTypeFieldId, DataType)
{   
    var nextObject;
    var that;
    
    //IE
    if (mEvent.srcElement)
    {
        that = mEvent.srcElement;
    }
    //Firefox
    else if (mEvent.target)
    {
        that = mEvent.target;
    }  
    
    switch(mEvent.keyCode)
    {
        case 13: //Enter;
        	replaceTEXTL(SelectedDisplay, SearchOption, SearchOptionFieldId, DivDropDownListId, SelectedTextLabelId, DataTypeFieldId, DataType);
            break;
        case 27: //escape;
            document.getElementById(DivDropDownListId).style.display = "none";
            break;
        case 38: //Arrow Up;
        
            if (that.previousSibling)
            {
                if (that.previousSibling.tagName == "A")
                {
                    //disable the document's key events to avoid scrolling by pressing the arrow keys
                    //these events are reanabled one we click somewhere inside the document
                    document.onkeyup = function () { return false; }
                    document.onkeydown = function () { return false; }
                    
                    nextObject = that.previousSibling;
                    nextObject.focus();
                    //use javascript to apply style to the focused item in IE 6
                    if (document.all)
                    {
                        nextObject.className = "focus";
                        nextObject.nextSibling.className = "notfocus";
                    }
                }
            }
            break;
        case 40: //Arrow Down;
        
            if (that.nextSibling)
            {
                if (that.nextSibling.tagName == "A")
                {
                    //disable the document's key events to avoid scrolling by pressing the arrow keys
                    //these events are reanabled one we click somewhere inside the document
                    document.onkeyup = function () { return false; }
                    document.onkeydown = function () { return false; }
                    
                    nextObject = that.nextSibling;
                    nextObject.focus();
                    //use javascript to apply style to the focused item in IE 6
                    if (document.all)
                    {
                        nextObject.className = "focus";
                        nextObject.previousSibling.className = "notfocus";
                    }
                }
            }
            break;
    }
}

function SearchBoxUpDownArrowPress(resultsContainer)
{
    //var resultsContainer = document.getElementById("SearchResults");
    var firstResult;
    
    firstResult = resultsContainer.childNodes[0];
    
    //use javascript to apply style to the focused item in IE 6
    if (document.all)
    {
        firstResult.className = "focus";
    }
    
    firstResult.focus();
    
    //disable the document's key events to avoid scrolling by pressing the arrow keys
    //these events are reanabled one we click somewhere inside the document                
    document.onkeyup = function () { return false; }
    document.onkeydown = function () { return false; }
}

//document.onclick += docOnclickEventLabel;

//IE
if (window.ActiveXObject)
{
    document.attachEvent('onclick',docOnclickEventLabel);
}
//Firefox
else
{
    document.addEventListener('click',docOnclickEventLabel,true);
}

function docOnclickEventLabel(e)
{
    var that;
    if (!e) var e = window.event;
    if (e.srcElement)
    {
        that = e.srcElement;
    }
    //Firefox
    else if (e.target)
    {
        that = e.target;
    }  
    
    if (that.id != DivDropDownListIdGlobal && that.id != SelectedTextLabelIdGlobal)
    {      
        document.onkeyup = function () { return true; }
        document.onkeydown = function () { return true; }
        if (document.getElementById(DivDropDownListIdGlobal))
        {
            document.getElementById(DivDropDownListIdGlobal).style.display = "none";
        }
    }
}