
function regionArrayEntry(id, name, countryid) {
    this.id = id;
    this.name = name;
    this.countryid = countryid;
}

function buildRegionArray(id) {
    for (var i=0;i<regionArray.length-1;i++) {
        document.write("<option value='" + regionArray[i].id + "'");
        if (id != null && regionArray[i].id == id) {
            document.write(" selected");
        }
        document.write(">" + regionArray[i].name + "</option>");
    }
}

function buildParentRegionArray(id) {
    for (var i=0;i<parent.regionArray.length-1;i++) {
        document.write("<option value='" + parent.regionArray[i].id + "'");
        if (id != null && parent.regionArray[i].id == id) {
            document.write(" selected");
        }
        document.write(">" + parent.regionArray[i].name + "</option>");
    }
}

function populateRegions(id, type) {
    var k = 0;
    var prefix = "";

    if (type == "form") {
        var selector = document.getElementById('regionid');
        selector.options.length = 0;
        var option = new Option("Please select a Region", "0");
        selector.options[k++] = option;
    }
    if (type == "search") {
        var selector = document.getElementById('search_regionid');
        selector.options.length = 0;
        var option = new Option("All Regions", "0");
        selector.options[k++] = option;
    }
    if (type == "list") {
        var selector = document.getElementById('nav_regionid');
        selector.options.length = 0;
        var option = new Option("Please select a Region...", "0");
        selector.options[k++] = option;
        option.className = "header";
        prefix = "- ";
        document.getElementById('nav_country').className = "disabled";
        document.getElementById('nav_region').className = "active";
        document.getElementById('nav_resort').className = "disabled";
    }
    for (var i=0;i<regionArray.length-1;i++) {
        if (regionArray[i].countryid == id) {
            var option = new Option(prefix + regionArray[i].name, regionArray[i].id);
            selector.options[k++] = option;
        }
    }
}

function populateParentRegions(id, page, regionid) {
    if (document.getElementById('Fregionid')) {
        var selector = document.getElementById('Fregionid');
    } else {
        var selector = document.getElementById('regionid');
    }
    selector.options.length = 0;
    k = 0;
    if (page != null && page == "search") {
        var option = new Option("All Regions", "0");
        selector.options[k++] = option;
    }
    if (page != null && page == "form") {
        var option = new Option("Please select a Region", "0");
        selector.options[k++] = option;
    }
    for (var i=0;i<parent.regionArray.length-1;i++) {
        if (parent.regionArray[i].countryid == id) {
            var option = new Option(parent.regionArray[i].name, parent.regionArray[i].id);
            selector.options[k++] = option;
            if (parent.regionArray[i].id == regionid) {
                option.selected = true;
            }
        }
    }
}

function buildRegionList(id) {
    var cLink = getCountryLink(id);
    var cName = getCountryName(id);
    var g = 0;
    var buffer = "";
    //if (id != null) {
        for (var j=0;j<regionArray.length;j++) {
            if (regionArray[j] != null && (id == null || id == regionArray[j].countryid)) {
                g++;
                buffer += "<a class=\"list\" href=\"javascript:buildResortList('" + regionArray[j].id + "')\">" + regionArray[j].name.substring(0,26) + "</a>\n";
            }
        }
        if (g == 0) {
            if (cLink.length > 0) {
                buffer = "<a href='" + cLink + "'>Please click here to view our<br>resorts and properties in<br>" + cName + "</a>";
            } else {
                buffer = "We are currently working on<br>this section of the website." + 
                         "<br><br>Please call us on 01608<br>738286 or complete our<br><a href='contact.jsp'>Contact Request</a> form for<br>more information.";
            }
        }
    //} else {
    //    buffer = "Please select a country to<br>populate this list.";
    //}
    document.getElementById('nav_region_list').innerHTML = buffer;
    buildResortList();
}