/**
 * Distributor Locator.
 * Version: 1.0
 *
 * The use of this script is strictly forbidden without prior written
 * consent. You must obtain permission before copying, modifying, 
 * redistributing, deriving or selling any part of this program.
 *
 * Copyright (c) 2008 HYPERZOID
 * All Rights Reserved
 */

// The distributor locator object.
var distributor = null;


/**
 * Initializes this program.
 */
function initDistributor() {
    distributor = new Distributor();
}


/**
 * The constructor.
 */
function Distributor() {
    // The data container element.
    this.data = document.getElementById('content');
}


/**
 * Displays all distributors at a certain country.
 * @param country The location of the distributors.
 */
Distributor.prototype.selectCountry = function(country) {
    if (country == -1) {
        return;
    }

    // Hide distributors for all locations.
    this.hide();
    
    // Show select box for Canadian cities.
    if (country == 'canada') {
        document.getElementById('cities').style.visibility = 'visible';
        this.selectCity('default');
        return;
    } else {
        document.getElementById('cities').style.visibility = 'hidden';
    }
    
    // Show distributors for selected location.
    document.getElementById(country).style.visibility = 'visible';
    document.getElementById(country).style.display    = 'inline';
}


/**
 * Displays all distributors in a certain city.
 * @param city The location of the distributors.
 */
Distributor.prototype.selectCity = function(city) {
    if (city == -1) {
        return;
    }

    // Hide distributors for all locations.
    this.hide();
    
    // Show distributors for selected location.
    document.getElementById(city).style.visibility = 'visible';
    document.getElementById(city).style.display    = 'inline';
}


/**
 * Hides distributors in all locations.
 */
Distributor.prototype.hide = function() {
    var locations = this.data.getElementsByTagName('div');
    for (var i = 0; i < locations.length; i++) {
        locations[i].style.visibility = 'hidden';
        locations[i].style.display    = 'none';
    }
}


// Initialize this program upon the onload event.
addOnLoad(initDistributor);