
function countryArrayEntry(id, name, url) {
    this.id = id;
    this.name = name;
    this.url = url;
}

function buildCountryArray(id, type) {
    var i = 0;
    var prefix = "";

    if (type != null && type == "list") {
        prefix = "- ";
    }

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

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

function getCountryName(id) {
    var name = "";
    for (var i=0;i<countryArray.length;i++) {
        if (countryArray[i] != null && countryArray[i].id == id) {
            name = countryArray[i].name;
        }
    }
    return name;
}

function getCountryLink(id) {
    var link = "";
    for (var i=0;i<countryArray.length;i++) {
        if (countryArray[i] != null && countryArray[i].id == id) {
            link = countryArray[i].url;
        }
    }
    return link;
}

function buildCountryList() {
    var c = 0;
    var buffer = "";
    for (var i=0;i<countryArray.length;i++) {
        if (countryArray[i] != null) {
            c++;
            buffer += "<a class=\"list\" href=\"javascript:buildRegionList('" + countryArray[i].id + "')\">" + countryArray[i].name.substring(0,26) + "</a>\n";
        }
    }
    if (c == 0) {
        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.";
    }
    document.getElementById('nav_country_list').innerHTML = buffer;
}

function buildCountryGrid() {
    var c = 0; 
    var d = 0;
    var cols = 8;
    var buffer = "";
    buffer += "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr>";
    for (var i=0;i<countryArray.length;i++) {
        if (countryArray[i] != null) {
            c++;
            d++;
            buffer += "<td class='grid' nowrap><a href=\"countries.jsp?countryid=" + countryArray[i].id + "\">" + countryArray[i].name.substring(0,26) + "</a></td>";
            if (d == cols) {
                if (c < countryArray.length) {
                    buffer += "</tr><tr><td colspan='" + cols+(cols-1) + "' height='4' nowrap='nowrap'></td></tr><tr>\n";
                } else {
                    buffer += "</tr><tr>\n";
                }
                d = 0;
            } else {
                buffer += "<td width='4px' nowrap></td>";
            }
        }
    }

    if (d == 0 || d > (cols-3)) {
        // add missing td tags
        for (var j=d;j<cols;j++) {
            buffer += "<td></td>";
        }
        // new row
        buffer += "</tr><tr><td colspan='" + cols + "' height='28'><a href='" + url + "search/search1.jsp'>Click here for a full list of our resorts...</a></td>";
    } else {
        var colspan = cols-d;
        buffer += "<td colspan='" + colspan + "'><a href='" + url + "search/search1.jsp'>Click here for a full list of our resorts...</a></td>";
    }


//    var colspan = (cols*2)-(d*2)-1;
//    if (d < cols && d <= 3) {
//        buffer += "<td colspan='" + colspan + "'><a href='" + url + "search/search1.jsp'>Click here for a full list of our resorts...</a></td>";
//    } else {
//        for (var j=d;j<cols;j++) {
//            buffer += "<td></td>";
//        }
//        buffer += "</tr><tr><td colspan='" + cols + "' height='28'><a href='" + url + "search/search1.jsp'>Click here for a full list of our resorts...</a></td>";
//    }

    if (c == 0) {
        buffer = "<td>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.</td>";
    }

    buffer += "</tr></table>";
    document.getElementById('nav_country_list').innerHTML = buffer;
}

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}
