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

function buildCountryArray(id) {
    for (var 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(">" + countryArray[i].name + "</option>");
    }
}

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

function buildCountryRow() {
    for (var i=0;i<=countryArray.length;i++) {
        try {
            document.write("<a href='country.jsp?id=" +  countryArray[i].linkid + "' title='" + countryArray[i].name + "'><img src='uploads/Country" +  countryArray[i].id + "/" + countryArray[i].filename + "' border='0'><br>" + countryArray[i].name + "</a>");
        } catch(ex) {}
    }
}

function buildCountryCol() {
    for (var i=0;i<=countryArray.length;i++) {
        try {
            document.write("<a href='country.jsp?id=" +  countryArray[i].linkid + "' title='" + countryArray[i].name + "'><img src='uploads/Country" +  countryArray[i].id + "/" + countryArray[i].filename + "' border='0'><br>" + countryArray[i].name + "</a>");
        } catch(ex) {}
    }
}

function CountryValidator() {
    var error = "Some of the details you have entered are incorrect. Please review the following information:\n";

    var name = document.getElementById('name').value;
    if (name == null || name.length < 1) {
        error += "\nName is required";
    }

    if (error != "Some of the details you have entered are incorrect. Please review the following information:\n") { 
        alert(error);
        return false;
    }
    return true;
}

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