function getSelectedTours()
{
    var DropSelectArea = DropArea.options[DropArea.selectedIndex].value;
    var DropSelectTown = DropTown.options[DropTown.selectedIndex].value;
    var DropSelectCat = 0;
    if (DropCat.selectedIndex < 0)
        DropCat.selectedIndex = 0;

    DropSelectCat = DropCat.options[DropCat.selectedIndex].value;
    var DropSelectSubCat = DropSubCat.options[DropSubCat.selectedIndex].value;
    //var TownClientValue = DropTownClient.options[DropTownClient.selectedIndex].value;
     
    SelectedArray = new Array();
    TjonustuArrayTemp =  new Array();
 
 /*
    if (TownClientValue == 1)
        TjonustuArrayTemp =TjonustuArray;
    else if (TownClientValue == 2)
        TjonustuArrayTemp = TownArray;
        */
    
	if (DropSelectTown == 0 && DropSelectArea == 0)
            SelectedArray = TjonustuArrayTemp; 
     
   if (DropSelectTown != 0) 
   {
        // find with selected towns
        var counter=0;
        for (var i = 0; i < TjonustuArrayTemp.length; i++) {
            if (TjonustuArrayTemp[i][5] == DropSelectTown)
            {
            SelectedArray[counter] = TjonustuArrayTemp[i];
            counter++;
            }
        }
   }
   else if (DropSelectArea != 0)
   {
        // find with selected areas
         var counter=0;
        for (var i = 0; i < TjonustuArrayTemp.length; i++) {
            if (TjonustuArrayTemp[i][4] == DropSelectArea)
            {
            SelectedArray[counter] = TjonustuArrayTemp[i];
            counter++;
            }
        }
    }
   
    //alert('TjonustuArrayNew'+SelectedArray.length+' - '+TjonustuArray.length);

        TjonustuArrayTemp = SelectedArray;
        if (DropSelectSubCat != 0 || DropSelectCat != 0)
            SelectedArray = new Array(); 
   
        if (DropSelectSubCat != 0) 
        {
                // find with selected subcat
                var counter=0;
                for (var i = 0; i < TjonustuArrayTemp.length; i++) {
                    if (TjonustuArrayTemp[i][3] == DropSelectSubCat)
                    {
                    SelectedArray[counter] = TjonustuArrayTemp[i];
                    counter++;
                    }
              }
        }
        else if (DropSelectCat != 0)
        {
            // find with selected cat
            var counter=0;
            for (var i = 0; i < TjonustuArrayTemp.length; i++) {
                if (TjonustuArrayTemp[i][1] == DropSelectCat)
                {
                SelectedArray[counter] = TjonustuArrayTemp[i];
                counter++;
                }
            }
        }
 
 
 /*

    if (SearchWordBox.value != "") {
        var counter = 0;
        TjonustuArrayTemp = SelectedArray;
        SelectedArray = new Array(); 
        for (var i = 0; i < TjonustuArrayTemp.length; i++) {
            if (TjonustuArrayTemp[i][0].toLowerCase().indexOf(SearchWordBox.value) != -1) {
                SelectedArray[counter] = TjonustuArrayTemp[i];
                counter++;
            }
        }
    }
 */
   return SelectedArray;
}


 
var bigmap = document.getElementById("Leit_map_canvas");
var smallmap = document.getElementById("Leit_Map_Small");
var ButtonMap = document.getElementById("ShowMap");
var DropArea = document.getElementById("ctl00_SearchControl1_SelectArea");
var DropTown = document.getElementById("ctl00_SearchControl1_Town");
var DropCat = document.getElementById("ctl00_SearchControl1_Category");
var DropSubCat = document.getElementById("ctl00_SearchControl1_SubCategory");
var DropTownClient = document.getElementById("ctl00_SearchControl1_TownClient");
var DropTownClient2 = document.getElementById("ctl00_SearchControl1_TownClient2");
var SearchWordBox = document.getElementById("ctl00_SearchControl1_SearchWords");
var SelectedArray = new Array();

function ResetSearch() {

    if (DropCat.selectedIndex >= 0)
        DropCat.selectedIndex = 0;
    if (DropSubCat.selectedIndex >= 0)
        DropSubCat.selectedIndex = 0;
    if (DropArea.selectedIndex >= 0)
        DropArea.selectedIndex = 0;
    if (DropTown.selectedIndex >= 0)
        DropTown.selectedIndex = 0;

    LandshlutarChange();
}
function ShowHideMapFunc() 
{
        var bigmap = document.getElementById("Leit_map_canvas");
        var smallmap = document.getElementById("Leit_Map_Small");
        var ButtonMap = document.getElementById("ShowMap");
 
        if (bigmap.className == "mapLeitHidden") {
            ButtonMap.value = "Hide Map";
            bigmap.className = "mapLeitShow";
            //smallmap.className = "mapsmall";
    
            document.getElementById("ctl00_SearchControl1_ShowMapHidden").value = "1";
        }
        else {
            ButtonMap.value = "Show map";
            bigmap.className = "mapLeitHidden";
            //smallmap.className = "mapsmallHidden";
            document.getElementById("ctl00_SearchControl1_ShowMapHidden").value = "0";
        }
}
 
function LoadCats() {
/*
    var optn = DropCat;
    optn = document.getElementById("ctl00_SearchControl1_Category");
        var SelVal = optn.options[optn.selectedIndex].value;
        var counter = 0;

        optn.options[0] = new Option('All Categories', '0');
        for (i = 0; i < CatArray.length; i++) {
            optn.options[counter] = new Option(CatArray[i][0], CatArray[i][1]);
                counter++;
            }
 
            if (optionValueIndexOf(optn, SelVal) == -1)
                optn.value = "0";
            else
                optn.value = SelVal;
                */
}
 

 
function SearchWordChange() {
    getSelectedTours();

}
 
function SearchForChange()
{
    var NewSearch = document.getElementById("NewSearch");
    var ActivityDiv = document.getElementById("ActivityDiv");
    var TownClient = document.getElementById("ctl00_SearchControl1_TownClient");
    
    /*
    var TownClientValue = TownClient.options[TownClient.selectedIndex].value;
    if (TownClientValue == 1)
    {
        ActivityDiv.className = "DivShow";
        NewSearch.className = "DivHidden";
    }
    if (TownClientValue == 2)
    {
        ActivityDiv.className = "DivHidden";
        NewSearch.className = "DivHidden";
    }
    if (TownClientValue == 3)
    {
        ActivityDiv.className = "DivHidden";
        NewSearch.className = "DivShow";
    }
    */
    getSelectedTours();
}
 
function AreaChange(theArea) {
    
    var counter = 1;
    var DropSelectArea = document.getElementById("ctl00_SearchControl1_SelectArea");
    var DropSelectArea2 = document.getElementById("ctl00_SearchControl1_SelectArea2");

    DropSelectArea.value = theArea;
    DropSelectArea2.value = theArea;

    //var TheSelVal = DropSelectArea.options[DropSelectArea.selectedIndex].value;
    var TheSelVal= theArea;

    var optn = document.getElementById("ctl00_SearchControl1_Town");
    var optn2 = document.getElementById("ctl00_SearchControl1_Town2");
    var TownSelVal = optn.options[optn.selectedIndex].value;
    for (var i = (optn.options.length - 1); i >= 0; i--) {
        optn.options[i] = null;
        optn2.options[i] = null;
     }

    optn.options[0] = new Option('All Cities', '0');
    optn2.options[0] = new Option('All Cities', '0');
   
    for (i = 0; i < TownArray.length; i++) 
    {
        if (TownArray[i][1] == TheSelVal || TheSelVal == 0) 
        {
            optn.options[counter] = new Option(TownArray[i][0], TownArray[i][2]);
            optn2.options[counter] = new Option(TownArray[i][0], TownArray[i][2]);     
        counter++;
        }
    }

    if (optionValueIndexOf(optn, TownSelVal) == -1) {
        optn.value = "0";
        optn2.value = "0";
    }
    else {
        optn.value = TownSelVal;
        optn2.value = TownSelVal;
    }
 
    getSelectedTours();
    LandshlutarChange();
    LoadCats();
}
 
function TownChange() {
    getSelectedTours();

}
 
function CatagoryChange() {
    //getSelectedTours();

    var counter = 1;
    var TheSelVal = 0;
    if (DropCat.selectedIndex >= 0)
        TheSelVal = DropCat.options[DropCat.selectedIndex].value;
    
    var optn = document.getElementById("ctl00_SearchControl1_SubCategory");
    var SubCatSelVal = optn.options[optn.selectedIndex].value;
    for (var i = (optn.options.length - 1); i >= 0; i--)
    { optn.options[i] = null; }


    optn.options[0] = new Option('All Subcategories', '0');
    for (i = 0; i < SubCatArray.length; i++) {
        if (SubCatArray[i][1] == TheSelVal) {
        
            var Birta = false;
         //   for (var b = 0; b < SelectedArray.length; b++) {
           //         if (SelectedArray[b][3] == SubCatArray[i][2])
            //        {
                    Birta = true;
            //        }
           //   }
 
           //if (Birta == true)
           // {
                optn.options[counter] = new Option(SubCatArray[i][0], SubCatArray[i][2]);
                counter++;
           // }
        }
    }
 
    if (optionValueIndexOf(optn, SubCatSelVal) == -1)
        optn.value ="0";
    else
        optn.value = SubCatSelVal;
   
}
 
function SubCatagoryChange()
{
    getSelectedTours();

}
 
function optionValueIndexOf(options,value) 
{
    for (var i=0;i<options.length;i++) 
    {
        if (options[i].value == value) 
        {
        return i;
        }
    }
    return -1;
}

SearchForChange(); 
AreaChange(document.getElementById("ctl00_SearchControl1_SelectArea").options[document.getElementById("ctl00_SearchControl1_SelectArea").selectedIndex].value);
CatagoryChange();

    function LandshlutarChange() {
        var DropSelectArea = document.getElementById("ctl00_SearchControl1_SelectArea");
        var DropValue = DropSelectArea.options[DropSelectArea.selectedIndex].value;
        var Flashval = 0;
        if (DropValue == 1)   		// reykjavik
            Flashval = 3;
        else if (DropValue == 2) 	// reykjanes
            Flashval = 4;
        else if (DropValue == 3) 	// vesturland
            Flashval = 2;
        else if (DropValue == 4) 	// vestfirdir
            Flashval = 1;
        else if (DropValue == 5) 	// Nordurland
            Flashval = 7;
        else if (DropValue == 6) 	// austurland
            Flashval = 6;
        else if (DropValue == 7) 	// sudurland
            Flashval = 5;
 
        document.landakort.GotoFrame(Flashval);

    }







