﻿function SearchMapKeywords(keywordid) {
    var keyword = document.getElementById(keywordid).value;
    if (keyword.length > 0) {
        GSIX.Webservice.gsixweb.searchOrganisationPerName(keyword, function(result) {
            if (result.tables[0].rows != null) {
                var count = 0;
                var resultsdiv = document.createElement('div');
                resultsdiv.id = 'resultsdiv';
                var resultstable = document.createElement('table');
                resultstable.className = 'searchresultstable';
                resultsdiv.className = 'searchmapsdiv';
                var newRow = resultstable.insertRow(-1);
                var oCell = newRow.insertCell(0);
                oCell.innerHTML = "<div class='head1alt'>Search Results:</div><div class='subhead1'>Click on any of the results to see more information about the organisation.</div>";
                while (count < result.tables[0].rows.length) {
                    newRow = resultstable.insertRow(-1);
                    oCell = newRow.insertCell(0);
                    var t1 = result.tables[0].rows[count]["value"];
                    oCell.innerHTML = "<a href='javascript:loadsearchresults(" + result.tables[0].rows[count]["orgid"] + " , \"" + t1 + "\")'>" + result.tables[0].rows[count]["value"] + "</a>";
                    count = count + 1;
                }
                resultsdiv.appendChild(resultstable);
                var containerdiv = document.createElement('div');
                containerdiv.appendChild(resultsdiv);
                dialog.showcustom(containerdiv.innerHTML);
            }
            else {
                alert('No results found for your search');
            }

        }
        , onFailed);
    }
}

function onFailed() {
    alert('Error');
}

function filtermapContinentSurvey(toid , fromid) {
    //var countriesarray = new Array();
    var value = document.getElementById(fromid).options[document.getElementById(fromid).selectedIndex].text    
    var i = 0;
    GSIX.Webservice.gsixweb.getCountriesFromContinent(value, function(result) {
        if (result.tables[0].rows != null) {
            var count = 0;
            clearDropDownList(document.getElementById(toid));
            //addDropDownListItem(document.getElementById("dropdownbycountry"), "All", "All");
            while (count < result.tables[0].rows.length) {
                addDropDownListItem(document.getElementById(toid), result.tables[0].rows[count]["name"], result.tables[0].rows[count]["name"]);
                count = count + 1;
            }
        }
    }
        , onFailed);
}

function clearDropDownList(dropDownList) {
    //get the total item from the dropDownList
    var intTotalItems = dropDownList.options.length;
    //loop through the number of items
    for (var intCounter = intTotalItems; intCounter >= 0; intCounter--) {
        //remove the intCounter( currently index) item from the dropDownList
        dropDownList.remove(intCounter);
    }
}

function addDropDownListItem(dropDownList, value, Text) {
    //Create new item option to be added in the dropDownList
    var newOption = document.createElement("option");
    //assign Text value to the text property of the option object 
    newOption.text = Text;
    //assign value to the value property of the option object 
    newOption.value = value;
    //add new option in the dropDownList
    dropDownList.options.add(newOption);
}
