﻿function redirectToAction() {
    if ($('selCountry').value == "0")
        return;
    var url = '/Home/UpdateCities/' + $('selCountry').value;
    new Ajax.Updater('selCities', url,
        {
            method: 'get'
        }
                );
}


function getRoute(route, ddId1, ddId2) {
    var x = document.getElementById("ddId1");
    var y = document.getElementById("ddId2");
    
    for (i = 0; i < x.length; i++) {
        if (x.selectedValue == i) {
            route = route + x.options[i].text + "&";
            i = x.length;
        }
    }

    for (j = 0; j < y.length; j++) {
        if (y.selectedValue == j) {
            route = route + y.options[j].text;
            j = y.length;
        }
    }

    return route;

}

//is called when the value of the parent combo (targetDropDownList) is changed
function bindDropDownList(e, targetDropDownList) {
    var key = this.value;
    var allOptions = targetDropDownList.allOptions;
    var option;
    var newOption;
    targetDropDownList.options.length = 0;

    for (var i = 0; i < allOptions.length; i++) {
        option = allOptions[i];
        //the first option is always shown (i==0)
        if (option.key == key || i == 0) {
            newOption = new Option(option.text, option.value);
            targetDropDownList.options.add(newOption);
        }
    }
} 

//is called when the window loads
//this one is my own implementation, necessary because in case of a postback the combo was always empty
//that problem is solved with this overloaded function
function bindDropDownListOnLoad(targetDropDownList, name) {
    var key = document.getElementById(name).value;
    var allOptions = targetDropDownList.allOptions;
    var option;
    var newOption;
    targetDropDownList.options.length = 0;

    for (var i = 0; i < allOptions.length; i++) {
        option = allOptions[i];
        //the first option is always shown (i==0)
        if (option.key == key || i == 0) {
            newOption = new Option(option.text, option.value);
            newOption.selected = (option.selected == "True");
            targetDropDownList.options.add(newOption);
        }
    }
}
