/**
 * Select.
 * 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 select object.
var select = null;


/**
 * Initializes this program.
 */
function initSelect() {
    select = new Select();
}


/**
 * The constructor.
 */
function Select() {
}


/**
 * Handles onclick events for the select box.
 */
Select.prototype.click = function(menuId) {
    // Open or close the select menu.
    var state = document.getElementById(menuId).style.visibility;
    if (state == 'hidden') {
        document.getElementById(menuId).style.visibility = 'visible';
    } else {
        document.getElementById(menuId).style.visibility = 'hidden';
    }
}


/**
 * Handles mouseout events.
 */
Select.prototype.mouseout = function(option) {
    option.style.backgroundColor = '#eceeed';
    option.style.border = '1px solid #eceeed';
}


/**
 * Handles mouseover events.
 */
Select.prototype.mouseover = function(option) {
    option.style.backgroundColor = '#b2b4bf';
    option.style.border = '1px solid #000000';
}


/**
 * Handles onclick events for select options.
 */
Select.prototype.option = function(boxId, menuId, inputId, option, value) {
    // Close the select menu.
    document.getElementById(menuId).style.visibility = 'hidden';
    
    // Set the input value.
    document.getElementById(inputId).value = value;

    // Set the select box label.
    var old = document.getElementById(boxId).firstChild;
    var txt = document.createTextNode(option.firstChild.nodeValue);
    document.getElementById(boxId).replaceChild(txt, old);
}


// Run this function upon the onload event.
addOnLoad(initSelect);
