/*  IMPORTANT DWR INSTRUCTIONS:
    In order for dwr to work, please be sure that the following line
    exists in the httpd.conf file in the apache server conf directory:
    <Location "/est/dwr/*">
	    JkMount worker1
    </Location>
*/

var searchType;
var searchParameter;
var objChecked;
var containingDiv; //the container that will hold all of the search controls
var backMode = STARTOVER;
var selectedDOE;
var selectedIssue;
var effectsLU;
var issuesLU;

var STARTOVER       = 1;
var AUTOCOMPLETE    = 2;
var PROJECT_LIST    = 3;
var EFFECT_LIST     = 4;
var ISSUE_LIST      = 5;
var DROPDOWN        = 6;



function search_initializeSearch()
{
    //Dependencies:  scrollingDiv.js
    containingDiv = document.createElement("div"); //containingDiv gets initialized here.
    var parentContainer = $(g_searchSection);
    if(parentContainer != null)
    {
        var sContainer = new ScrollingDiv(g_searchControlName);
        sContainer.setHeaderTitle("Project Search");
        sContainer.setHeight(200);
        sContainer.setWidth(200);
        if(app.getDefaultProject().id == -1)
        {
            //alert("no project defined");
            var obj = projectSearchOptions();
            sContainer.addElement(parentContainer, obj);
        }
        else
        {
            backMode = STARTOVER;
            showProjectDetail(app.getDefaultProject());
        }

        //initialize "Start Over" button:
        var lnk = document.createElement("input");
        lnk.type="button";
        lnk.style.width = "75px";
        lnk.style.fontSize = "0.8em";
        lnk.id = "new search";
        lnk.value = "new search";
        lnk.className = "submitButton";
        lnk.onclick = function() { search_startOver(); }
        sContainer.addHeaderControl(lnk);
    }
}

function search_startOver()
{
    //alert("back1()");
    var parentContainer = $(g_searchSection);
    var hContainer = new ScrollingDiv(g_searchControlName);
    obj = projectSearchOptions();
    hContainer.addElement(parentContainer, obj);
    if(objChecked != null)
    {
        $(objChecked.id).style.backgroundColor = "#EEEEEE";
    }
}

function projectList(e)
{
    switch(searchType)
    {
        case "prjNumber":
            ProjectLookup.getProjectById(fillTable, searchParameter);
            break;
        case "prjName":
            ProjectLookup.getProjectsByName(fillTable, searchParameter);
            break;
        case "planningOrg":
            ProjectLookup.getProjectsByOrg(fillTable, searchParameter);
            break;
        case "county":
        case "district":
            ProjectLookup.getProjectsByRegion(fillTable, searchParameter);
            break;
        case "doe":
            getProjectsByEffectsIssues(selectedIssue);
            break;
        case "phase":
            ProjectLookup.getProjectsByPhase(fillTable, searchParameter);
            break;
    }
}

function getBackButton()
{
    return $("back");
}
function getForwardButton()
{
    return $("fwd");
}

function createBack()
{
    //alert("create back button: " + backMode);
    // make the back button an "anchor" tag for
    // so that you can activate it by using the
    // tab key.
    var back = document.createElement("a");
    back.href = "#";
    back.id = "back";
    back.title = "back to previous step";

    var backImg = document.createElement("img");
    backImg.src = "images/lt.gif";
    backImg.alt = "back to previous step";
    backImg.border = 0;
    back.appendChild(backImg);

    switch(backMode)
    {
        case STARTOVER:
            back.onclick = search_startOver;
            break;
        case AUTOCOMPLETE:
            back.onclick = search_showBasicSearchAutoComplete;
            break;
        case PROJECT_LIST:
            back.onclick = projectList;
            break;
        case EFFECT_LIST:
            back.onclick = populateEffects;
            break;
        case ISSUE_LIST:
            back.onclick = populateIssues;
            break;
    }
    return back;
}

function createFwd()
{
    /*var fwd = document.createElement("img");
    fwd.id = "fwd";
    fwd.src="images/rt.gif";
    fwd.alt = "go to next step";
    fwd.align = "right";*/

    var fwd = document.createElement("a");
    fwd.href = "#";
    fwd.id = "fwd";
    fwd.title = "go to next step";
    fwd.style.textAlign = "right";

    var fwdImg = document.createElement("img");
    fwdImg.src = "images/rt.gif";
    fwdImg.alt = "go to next step";
    fwdImg.border = 0;
    fwd.appendChild(fwdImg);

    fwd.onclick = search_showBasicSearchAutoComplete;
    return fwd;
}

function createTitle(text)
{
    var title = document.createElement("span");
    title.innerHTML = text;
    title.style.fontWeight = "bold";
    return title;
}

function createSubtitle(text)
{
    var title = document.createElement("div");
    title.innerHTML = text;
    title.style.fontStyle = "italic";
    title.style.borderBottom = "3px dotted #aacbee";
    title.style.paddingBottom = "3";
    return title;
}

function projectSearchOptions()
{
    // clear out old data:
    app.browser().removeChildren(containingDiv);
    searchParameter = null;

    containingDiv.appendChild(createTitle("Select a search option:"));
    if(searchType != null)
        containingDiv.appendChild(createFwd());
    containingDiv.appendChild(document.createElement("BR"));

    // NOTE:  Made the project search buttons "anchor" tags
    // for so that you can activate it by using the tab key.
    // Section 508 Compliance.

    var ul = document.createElement("ul");
    /********************/
    /* Search Option #1 */
    /********************/
    var li1 = document.createElement("li")
    li1.style.whiteSpace = "nowrap";
    var option1 = document.createElement("a");
    option1.title = "Search Projects by Project Number";
    option1.id = "searchOption_1";
    option1.name = "prjNumber";
    option1.onclick = search_showBasicSearchAutoComplete;
    option1.innerHTML = "Project Number";
    option1.href = "#";
    li1.appendChild(option1);
    ul.appendChild(li1);

    /********************/
    /* Search Option #2 */
    /********************/
    var li2 = document.createElement("li")
    li2.style.whiteSpace = "nowrap";
    var option2 = document.createElement("a");
    option2.title = "Search Projects by Project Name";
    option2.id = "searchOption_2";
    option2.name = "prjName";
    option2.onclick = search_showBasicSearchAutoComplete;
    option2.innerHTML = "Project Name";
    option2.href = "#";
    li2.appendChild(option2);
    ul.appendChild(li2);

    /********************/
    /* Search Option #3 */
    /********************/
    var li3 = document.createElement("li")
    li3.style.whiteSpace = "nowrap";
    var option3 = document.createElement("a");
    option3.title = "Search Projects by Planning Organization";
    option3.id = "searchOption_3";
    option3.name = "planningOrg";
    option3.onclick = search_showBasicSearchAutoComplete;
    option3.innerHTML = "Planning Organization";
    option3.href = "#";
    li3.appendChild(option3);
    ul.appendChild(li3);

    /********************/
    /* Search Option #4 */
    /********************/
    var li4 = document.createElement("li")
    li4.style.whiteSpace = "nowrap";
    var option4 = document.createElement("a");
    option4.title = "Search Projects by County";
    option4.id = "searchOption_4";
    option4.name = "county";
    option4.onclick = search_showBasicSearchAutoComplete;
    option4.innerHTML = "County";
    option4.href = "#";
    li4.appendChild(option4);
    ul.appendChild(li4);

    /********************/
    /* Search Option #5 */
    /********************/
    var li5 = document.createElement("li")
    li5.style.whiteSpace = "nowrap";
    var option5 = document.createElement("a");
    option5.title = "Search Projects by District";
    option5.id = "searchOption_4";
    option5.name = "district";
    option5.onclick = search_showBasicSearchAutoComplete;
    option5.innerHTML = "District";
    option5.href = "#";
    li5.appendChild(option5);
    ul.appendChild(li5);

    /********************/
    /* Search Option #6 */
    /********************/
    var li6 = document.createElement("li")
    li6.style.whiteSpace = "nowrap";
    var option6 = document.createElement("a");
    option6.title = "Search Projects by Degree of Effect";
    option6.id = "searchOption_5";
    option6.name = "doe";
    option6.onclick = search_showBasicSearchAutoComplete;
    option6.innerHTML = "Degree of Effect";
    option6.href = "#";
    li6.appendChild(option6);
    ul.appendChild(li6);

    /********************/
    /* Search Option #7 */
    /********************/
    var li7 = document.createElement("li")
    li7.style.whiteSpace = "nowrap";
    var option7 = document.createElement("a");
    option7.title = "Search Projects by Phase (Planning, Programming, or Project Development)";
    option7.id = "searchOption_6";
    option7.name = "phase";
    option7.onclick = search_showBasicSearchAutoComplete;
    option7.innerHTML = "Project Phase";
    option7.href = "#";
    li7.appendChild(option7);
    ul.appendChild(li7);

    containingDiv.appendChild(ul);
    return containingDiv;
}


function search_showBasicSearchAutoComplete(e)
{
    //alert("search_showBasicSearchAutoComplete start");
    var divName;
    var textBoxName;
    var title;
    var functionCall;
    var minChars;
    var srcElement = app.browser().getSourceElement(e);
    if(srcElement.id.indexOf("searchOption") != -1)
        objChecked = srcElement;
    var theValue = objChecked.name;
    searchType = theValue;
    var autocomplete = true;
    backMode = STARTOVER;
    switch(searchType)
    {
        case "prjNumber":
            functionCall = ProjectLookup.getProjectDDById;
            minChars = 2;
            title = "Search by Project Number:";
            break;
        case "prjName":
            functionCall = ProjectLookup.getProjectDDByName;
            minChars = 3;
            title = "Search by Project Name:";
            break;
        case "planningOrg":
            autocomplete = false;
            ProjectLookup.getDistinctOrgNames(showDropdownList);
            break;
        case "county":
            autocomplete = false;
            ProjectLookup.getDistinctCountyNames(showDropdownList);
            break;
         case "district":
             autocomplete = false;
             ProjectLookup.getDistinctDistrictNames(showDropdownList);
            break;
        case "doe":
            autocomplete = false;
            ProjectLookup.getEffects(showEffects);
            break;
        case "phase":
            autocomplete = false;
            var arrPhases = new Array(3);
            arrPhases[0] = "Planning";
            arrPhases[1] = "Programming";
            arrPhases[2] = "Project Development";
            showDropdownList(arrPhases);
            break;
    }
    //alert("end switch");
    if(autocomplete)
    {
        var container = $("autoCompleteContainer");
        if(container == null)
            container = document.createElement("DIV");
        container.id = "autoCompleteContainer";
        //add back button
        container.appendChild(createBack());
        container.appendChild(createTitle(title));
        container.appendChild(document.createElement("BR"));
        var textBox = document.createElement("INPUT");
        textBox.id = "txt_" + theValue;
        textBox.name = "txt_" + theValue;
        if(searchParameter != null)
            textBox.value = searchParameter;
        container.appendChild(textBox);
        //textBox.focus();

        //create a go button:
        container.appendChild(document.createTextNode(" "));
        var go = document.createElement("a");
        go.id = "go";
        go.innerHTML = "go";
        //if(app.browser().isIE())
        go.style.cursor = "hand";

        container.appendChild(go);

        var hiddenDiv = document.createElement("DIV");
        hiddenDiv.id = "hiddenDiv_" + theValue;
        hiddenDiv.className = "auto_complete";
        document.body.appendChild(hiddenDiv);

        //alert("appendChild");
        var parentContainer = $(g_searchSection);
        var psContainer = new ScrollingDiv(g_searchControlName);
        psContainer.addElement(parentContainer, container);

        //ADD AUTOCOMPLETE FUNCTIONALITY:
        var u = new Autocompleter.DWR(textBox.id, hiddenDiv.id, functionCall, {'minChars':minChars});
        //DWRUtil.useLoadingMessage();

        //ONCLICK FUNCTION CALL (AFTER USER SELECTS OPTION)
        //searchParameter = textBox.value;
        //alert(searchParameter);
        //alert(textBox.value);
        u.options.afterUpdateElement = go.onclick = //executeQuery;
        function()
        {
            //alert(textBox.value);
            app.showLoadingMessage();
            searchParameter = textBox.value;
            switch(searchType)
            {
                case "prjNumber":
                    backMode = STARTOVER;
                    ProjectLookup.getProjectMilestoneByParentId(showProjectDetail, textBox.value);
                    //ProjectLookup.getProjectById(fillTable, textBox.value);
                    break;
                case "prjName":
                    backMode = STARTOVER;
                    ProjectLookup.getProjectMilestoneByProjectName(showProjectDetail, textBox.value);
                    //ProjectLookup.getProjectsByName(fillTable, textBox.value);
                    break;
                case "planningOrg":
                    backMode = STARTOVER;
                    ProjectLookup.getProjectsByOrg(fillTable, textBox.value);
                    break;
                case "county":
                case "district":
                    backMode = STARTOVER;
                    ProjectLookup.getProjectsByRegion(fillTable, textBox.value);
                    break;
                 //case "doe":
                 //Not using an autofill textbox for this one.
            }
        }
    }
}


function fillTable(projects) {
   // create a container control, "projectListDiv," and add results
   // to container.  Then add container to the Project Search scrollable div.

    /*********************/
    /* Build custom list */
    /*********************/
    //var controlFocus;
    var projectListDiv = $("projectListDiv");
    if(projectListDiv != null)
    {
        app.browser().removeChildren(projectListDiv);
    }
    else
    {
        projectListDiv = document.createElement("DIV");
        projectListDiv.id = "projectListDiv";
        projectListDiv.style.textAlign = "left";
    }

    var title = "";
    switch(searchType)
    {
        case "prjNumber":
            backMode = AUTOCOMPLETE;
            title = "Your search for project number #" + searchParameter + " returned " + projects.length + " record(s):";
            break;
        case "prjName":
            backMode = AUTOCOMPLETE;
            title = "Your search for project \"" + searchParameter + "\" returned " + projects.length + " record(s):";
            break;
        case "planningOrg":
            backMode = AUTOCOMPLETE;
            //backMode = DROPDOWN;
            title = "Your search for \"" + searchParameter + "\" projects returned " + projects.length + " record(s):";
            break;
        case "county":
            backMode = AUTOCOMPLETE;
            title = "Your search for \"" + searchParameter + "\" projects returned " + projects.length + " record(s):";
            break;
        case "district":
            backMode = AUTOCOMPLETE;
            title = "Your search for \"" + searchParameter + "\" projects returned " + projects.length + " record(s):";
            break;
        case "doe":
            backMode = ISSUE_LIST;
            title = "Your search returned " + projects.length + " record(s) where: ";
            break;
        case "phase":
            backMode = AUTOCOMPLETE;
            title = "Your search for \"" + searchParameter + "\" projects returned " + projects.length + " record(s):";
            break;
    }
    if(projects != null && projects.length > 0)
    {
        var ul = document.createElement("ul")
        for(var i=0; i < projects.length; i++)
        {
            var li = document.createElement("li")
            li.style.whiteSpace = "nowrap";
            var project     = projects[i];
            var name        = project.name;
            var id          = "#" + project.id;
            var link        = document.createElement("A");
            var prjText     = id + " - " + name;
            link.innerHTML  = prjText;
            link.id         = project.id;
            //link.href       ="#";
            //link.onclick    = findDetail;
            link.title      = prjText;
            link.href       = "javascript:findDetail(" + project.id + ")";
            //if(i==0)
            //{
            //    controlFocus = link;
            //}
            li.appendChild(link);
            ul.appendChild(li);
        }
        //1.  add back button
        projectListDiv.appendChild(createBack());

        //2.  add search results text:
        projectListDiv.appendChild(createTitle("Results"));
        if(searchType != "doe")
        {
            projectListDiv.appendChild(createSubtitle(title));
        }
        else
        {
            projectListDiv.appendChild(document.createTextNode(" " + title));
            projectListDiv.appendChild(document.createElement("br"));
            var effectDiv = document.createElement("<DIV>");
            effectDiv.style.backgroundColor = "#EEE";
            effectDiv.style.margin = "5px";
            effectDiv.style.padding = "3px";
            var effectText = document.createElement("span");
            effectText.innerHTML = "&nbsp;<strong><em>Effect: </em></strong>";
            effectDiv.appendChild(effectText);
            effectDiv.appendChild(getDOESpan(selectedDOE));
            effectDiv.appendChild(document.createTextNode(" " + selectedDOE.name));
            effectDiv.appendChild(document.createElement("br"));
            var issueText = document.createElement("span");
            issueText.innerHTML = "&nbsp;<strong><em>Issue: </em></strong>";
            effectDiv.appendChild(issueText);
            effectDiv.appendChild(document.createTextNode(" " + selectedIssue));
            projectListDiv.appendChild(effectDiv);
        }
        //3. add list of projects returned:
        projectListDiv.appendChild(ul);
    }
    else
    {
        //1.  add back button
        var bckBtn = createBack();
        //controlFocus = bckBtn;
        projectListDiv.appendChild(bckBtn);

        //2.  add search results text:
        projectListDiv.appendChild(createTitle("Results"));
        projectListDiv.appendChild(createSubtitle(title));

        var message = document.createTextNode("No projects found.");
        projectListDiv.appendChild(document.createElement("br"));
        projectListDiv.appendChild(message);
    }
    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, projectListDiv);
    app.hideLoadingMessage();
}

function clearSearchResults()
{
    var projectListDiv = $("projectListDiv");
    if(projectListDiv != null)
    {
        app.browser().removeChildren(projectListDiv);
    }
    getBackButton().onclick = showBasic;
}

var project = { name:null, id:-1, orgName: null,
    toLocation: null, fromLocation: null, district: null,
    counties: null, phase: null, projectType: null, contactEmail: null
};

function findDetail(id)
{
    app.showLoadingMessage();
    ProjectLookup.getProjectMilestoneByParentId(showProjectDetail, id);
}

function showProjectDetail(project)
{
    switch(searchType)
    {
        case "prjNumber":
        case "prjName":
        case "planningOrg":
        case "county":
        case "district":
        case "doe":
            backMode = PROJECT_LIST;
            break;
    }
    app.setDefaultProject(project);
    if(currentPage.displayName != g_mapperPage) {
        app.reloadIframe();
    } else {
        app.hideLoadingMessage();
        app.showOnMap("Project", project.id);
    }
    app.browser().removeChildren(containingDiv);
    var container = document.createElement("div");

    //1.  add back button:  if the project search has initialized to this
    //    view (because there is a default project defined in memory),
    //    then set the backMode back to null once the createBack() has been called.
    container.appendChild(createBack());

    //2.  add search results text:
    container.appendChild(createTitle("Project Detail"));

    container.appendChild(createSubtitle("Detailed Information about the selected project:"));

    //4. add project detail:
    container.appendChild(document.createElement("br"));
    var table = document.createElement("table");
    table.className = "psResults";
    table.cellPadding = 1;
    table.cellSpacing = 0;
    tabledth = "100%";
    table.border = 0;

    // Project Name and Id Detail:
    var row1 = table.insertRow(0);
    var cell1_1 = row1.insertCell(0);
    cell1_1.className = "tblHeader";
    cell1_1.innerHTML = "Project Name:";
    var cell1_2 = row1.insertCell(1);
    cell1_2.innerHTML = "#" + project.id + " - " + project.name;

    //Phase Detail:
    var row2 = table.insertRow(1);
    var cell2_1 = row2.insertCell(0);
    cell2_1.className = "tblHeader";
    cell2_1.innerHTML = "Phase:";
    var cell2_2 = row2.insertCell(1);
    cell2_2.innerHTML = project.phase;

    // Planning Organization Detail:
    var row3 = table.insertRow(2);
    var cell3_1 = row3.insertCell(0);
    cell3_1.className = "tblHeader";
    cell3_1.innerHTML = "Planning Organization:";
    var cell3_2 = row3.insertCell(1);
    cell3_2.innerHTML = project.orgName;

    // From Location:
    var row4 = table.insertRow(3);
    var cell4_1 = row4.insertCell(0);
    cell4_1.className = "tblHeader";
    cell4_1.innerHTML = "From Location:";
    var cell4_2 = row4.insertCell(1);
    cell4_2.innerHTML = project.fromLocation;

    // To Location:
    var row5 = table.insertRow(4);
    var cell5_1 = row5.insertCell(0);
    cell5_1.className = "tblHeader";
    cell5_1.innerHTML = "To Location:";
    var cell5_2 = row5.insertCell(1);
    cell5_2.innerHTML = project.toLocation;

    // District:
    var row6 = table.insertRow(5);
    var cell6_1 = row6.insertCell(0);
    cell6_1.className = "tblHeader";
    cell6_1.innerHTML = "District:";
    var cell6_2 = row6.insertCell(1);
    cell6_2.innerHTML = project.district;

    // Counties:
    var row7 = table.insertRow(6);
    var cell7_1 = row7.insertCell(0);
    cell7_1.className = "tblHeader";
    cell7_1.innerHTML = "Counties:";
    var cell7_2 = row7.insertCell(1);
    cell7_2.innerHTML = project.counties;

    // Project Type:
    var row8 = table.insertRow(7);
    var cell8_1 = row8.insertCell(0);
    cell8_1.className = "tblHeader";
    cell8_1.innerHTML = "Project Type:";
    var cell8_2 = row8.insertCell(1);
    cell8_2.innerHTML = project.projectType;

    // SUBMIT COMMENT LINK:
    var row9 = table.insertRow(8);
    var cell9_1 = row9.insertCell(0);
    cell9_1.colSpan = "2";
    cell9_1.className = "tblHeader";
    var contact = project.contactEmail;
    var subjectComment = "Submit a Comment for ETDM Project " + project.id + " - " + project.name;
    cell9_1.innerHTML = '<a href=\"mailto:' + contact + '?subject=' + subjectComment + '\">' + 'Submit Comment</a>';

    // REQUEST A MEETING LINK:
    var row10 = table.insertRow(9);
    var cell10_1 = row10.insertCell(0);
    cell10_1.colSpan = "2";
    cell10_1.className = "tblHeader";
    var subjectMeeting = "Request a Response for ETDM Project " + project.id + " - " + project.name;
    cell10_1.innerHTML = '<a href=\"mailto:' + contact + '?subject=' + subjectMeeting + '\">' + 'Request Response</a>';

    container.appendChild(table);
    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, container);
}

function projectSearch_setActiveProjectMilestone(mId)
{
    app.showLoadingMessage();
    ProjectLookup.getProjectMilestoneByMilestoneEventId(showProjectDetail, mId);
}

function showDropdownList(resultList)
{
    switch(searchType)
    {
        case "planningOrg":
            title = "Select a Planning Organization";
            break;
        case "county":
            title = "Select a County";
            break;
        case "district":
            title = "Select a District";
            break;
        case "phase":
            title = "Select a Phase";
            break;
    }
    backMode = STARTOVER;
    var projectListDiv = $("projectListDiv");
    if(projectListDiv != null)
    {
        app.browser().removeChildren(projectListDiv);
    }
    else
    {
        projectListDiv = document.createElement("DIV");
        projectListDiv.id = "projectListDiv";
        projectListDiv.style.textAlign = "left";
    }
    //add projectListDiv to parent container.
    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, projectListDiv);

    //add back button
    projectListDiv.appendChild(createBack());
    projectListDiv.appendChild(createTitle(title));
    projectListDiv.appendChild(document.createElement("BR"));
    var select = document.createElement("select");
    select.style.width = "170px";
    select.style.fontSize = "0.8em";
    for(var i=0; i < resultList.length; i++)
    {
        var resultName = resultList[i];
        //alert(resultList[i]);
        var option = document.createElement("option");
        option.value = resultName;
        option.innerHTML = resultName;
        if(searchParameter == resultName)
        option.selected = true;
        try
        {
            if(app.browser().isIE())
                select.options.appendChild(option);
            else
                select.add(option, null);
        }
        catch(ex)
        {
            if(i < 1) { alert("Error in 'showOrgs' method of projectSearch.js: " + ex); }
        }
    }
    projectListDiv.appendChild(select);
    //add go button:
    projectListDiv.appendChild(document.createTextNode(" "));
    var go = document.createElement("a");
    go.id = "go";
    go.innerHTML = "go";
    go.style.cursor = "hand";
    projectListDiv.appendChild(go);

    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, projectListDiv);
    select.onchange = go.onclick =
    function()
    {
        if(select.options[select.selectedIndex] != null && select.options[select.selectedIndex] != -1)
        {
            searchParameter = select.options[select.selectedIndex].value;
            app.showLoadingMessage();
            switch(searchType)
            {
                case "planningOrg":
                    ProjectLookup.getProjectsByOrg(fillTable, searchParameter);
                    break;
                case "county":
                    ProjectLookup.getProjectsByRegion(fillTable, searchParameter);
                    break;
                case "district":
                    ProjectLookup.getProjectsByRegion(fillTable, searchParameter);
                    break;
                case "phase":
                    ProjectLookup.getProjectsByPhase(fillTable, searchParameter);
                    break;
            }
        }
    }
}

function showEffects(doeList)
{
    if(effectsLU == null)
        effectsLU = doeList;

    Mode = STARTOVER;
    var projectListDiv = $("projectListDiv");
    if(projectListDiv != null)
    {
        app.browser().removeChildren(projectListDiv);
    }
    else
    {
        projectListDiv = document.createElement("DIV");
        projectListDiv.id = "projectListDiv";
        projectListDiv.style.textAlign = "left";
    }
    //add back button
    projectListDiv.appendChild(createBack());
    projectListDiv.appendChild(createTitle("Select a Degree of Effect"));
    projectListDiv.appendChild(document.createElement("BR"));
    var ul = document.createElement("ul")
    for(var i=0; i < effectsLU.length; i++)
    {
        var li = document.createElement("li")
        li.style.whiteSpace = "nowrap";
        var doe         = doeList[i];
        li.appendChild(getDOESpan(doe));
        var link        = document.createElement("A");
        link.style.paddingLeft = "5px";
        link.innerHTML  = doe.name;
        link.id         = doe.name;
        link.title      = "Click here to find projects that have been assigned a summary degree of effect of: '" + doe.name + "'";
        link.href       = "javascript:getIssues('" + doe.name + "');";
        li.appendChild(link);
        ul.appendChild(li);
    }
    projectListDiv.appendChild(ul);
    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, projectListDiv);
    if(selectedDOE != null)
    {
        $(selectedDOE.name).style.backgroundColor = "#EEEEEE";
    }
}

function getIssues(doeName)
{
    if(doeName != null)
    {
        for(var i=0; i < effectsLU.length; i++)
        {
            var doeTmp = effectsLU[i];
            if(doeName == doeTmp.name)
            {
                selectedDOE = doeTmp;
                break;
            }
        }
    }
    //ProjectLookup.getIssueNames(showIssues);
    ProjectLookup.getIssues(showIssues);
}

function showIssues(issueList)
{
    if(issuesLU == null)
        issuesLU = issueList;
    backMode = EFFECT_LIST;
    //alert(backMode);
    var projectListDiv = $("projectListDiv");
    if(projectListDiv != null)
    {
        app.browser().removeChildren(projectListDiv);
    }
    else
    {
        projectListDiv = document.createElement("DIV");
        projectListDiv.id = "projectListDiv";
        projectListDiv.style.textAlign = "left";
    }
    //add back button
    projectListDiv.appendChild(createBack());
    projectListDiv.appendChild(createTitle("Select an Issue"));
    //projectListDiv.appendChild(document.createElement("BR"));
    var effectDiv = document.createElement("<DIV>");
    //effectDiv.style.border = "dashed 1px #999";
    effectDiv.style.backgroundColor = "#EEE";
    effectDiv.style.margin = "5px";
    effectDiv.style.padding = "3px";
    effectDiv.appendChild(document.createTextNode("Select an issue that has been assigned a degree of effect of: "));
    effectDiv.appendChild(document.createElement("br"));
    effectDiv.appendChild(getDOESpan(selectedDOE));
    var effectName = document.createElement("span");
    effectName.innerHTML = "&nbsp;<strong><em>" + selectedDOE.name + "</em></strong>";
    effectDiv.appendChild(effectName);
    projectListDiv.appendChild(effectDiv);
    //projectListDiv.appendChild(document.createElement("BR"));
    var ul = document.createElement("ul");

    var li0 = document.createElement("li");
    li0.style.whiteSpace = "nowrap";
    var issue         = "All Issues";
    //selectedDOE
    var link0        = document.createElement("A");
    link0.innerHTML  = "All Issues";
    link0.id         = "All Issues";
    link0.title      = "Click here to find projects that have been assigned a summary degree of effect of '" + selectedDOE.name + "' for all issues";
    link0.href       = "javascript:getProjectsByEffectsIssues('All Issues');";
    li0.appendChild(link0);
    ul.appendChild(li0);
    for(var i=0; i < issuesLU.length; i++)
    {
        var li = document.createElement("li")
        li.style.whiteSpace = "nowrap";
        issue         = issueList[i];
        //selectedDOE
        var link        = document.createElement("A");
        link.innerHTML  = issue.name;
        link.id         = issue.name;
        link.title      = "Click here to find projects that have been assigned a summary degree of effect of '" + selectedDOE.name + "' for '" + issue.name + "'";
        link.href       = "javascript:getProjectsByEffectsIssues('" + issue.name + "');";
        li.appendChild(link);
        ul.appendChild(li);
    }
    projectListDiv.appendChild(ul);
    var parentContainer = $(g_searchSection);
    var psContainer = new ScrollingDiv(g_searchControlName);
    psContainer.addElement(parentContainer, projectListDiv);
    if(selectedIssue != null)
    {
        $(selectedIssue).style.backgroundColor = "#EEEEEE";
    }
}

function populateEffects()
{
    //if effects list is already populated, don't re-query:
    if(effectsLU == null)
        ProjectLookup.getEffects(showEffects);
    else
        showEffects(effectsLU);
}
function populateIssues()
{
    //alert("Populate Issues!");
    //ProjectLookup.getIssueNames(showIssues);
    if(issuesLU == null)
        ProjectLookup.getIssues(showIssues);
    else
        showIssues(issuesLU);
}

function getProjectsByEffectsIssues(issueName)
{
    if(issueName != null)
        selectedIssue = issueName;
    searchParameter = "Projects with a Degree of Effect of <strong>" + selectedDOE.name + "</strong>";
    if(issueName != "" && issueName != null)
        searchParameter += " for <strong>" + issueName + "</strong>";
    if(issueName == "All Issues")
        issueName = "";
    ProjectLookup.getProjectsByEffectsIssues(fillTable, selectedDOE.name, issueName);
}

function getDOESpan(doe)
{
    var span = document.createElement("span");
    span.style.width="17px";
    span.innerHTML  = "&nbsp;" + doe.shortName + "&nbsp;";
    span.style.backgroundColor = doe.color;
    span.style.border = "solid #666 1px";
    span.style.textAlign="center";
    span.style.color = "#FFF";
    span.style.fontSize = "8pt";
    return span;
}