
// Function to load images.
function imageLoader(imgs) {

    if (imgs.constructor == Array) {
        for (var i = 0; i < imgs.length; i++) {
            imgToLoad = new Image();
            imgToLoad.src = imgs[i];
        }
    } else {
        imgToLoad = new Image();
        imgToLoad.src = imgs;
    }

}

// Function to add a function to the onload stack.
function addLoader(func) {

    // Get old onload function(s), if they exist.
    var oldOnLoad = window.onload;

    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldOnLoad) {
                oldOnLoad();
            }
            func();
        }
    }

}

/**
 *
 * JaxEvent Component
 *
 */

// Function to add an event listener to the window or document.
function addEvent(evt, func) {

    // Check the event type and the DOM obj accordingly.
    if ((evt == 'scroll') || (evt == 'resize')) {
        obj = window;
    } else {
        obj = document;
    }

    // Detect browser and add the correct event listener.
    brw = new JaxBrowser();

    if (brw.browser == 'MSIE') {
        obj.attachEvent('on' + evt, func);
    } else {
        obj.addEventListener(evt, func, true);
    }

}


/**
 *
 * JaxFlash Component
 *
 */

// Prototype for the JaxFlash object and its methods and properties.
function JaxFlash() {

    // Method to dynamically write out the flash code to work around any browser display issues, i.e., the IE "white box" issue.
    this.flashMovie = function(url, nm, wid, hgt, bgcolor, wmode, ver) {

        if (bgcolor == null) {
            bgcolor = '#ffffff';
        }
        if (wmode == null) {
            wmode = 'window';
        }
        if (ver == null) {
            ver = 9;
        }

        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + ver + ',0,0,0" width="' + wid + '" height="' + hgt + '" id="' + nm + '" align="middle">');
        document.write('    <param name="allowScriptAccess" value="sameDomain" />');
        document.write('    <param name="movie" value="' + url + '" />');
        document.write('    <param name="quality" value="high" />');
        document.write('    <param name="bgcolor" value="' + bgcolor + '" />');
        document.write('    <param name="wmode" value="' + wmode + '" />');
        document.write('    <embed src="' + url + '" quality="high" bgcolor="' + bgcolor + '" wmode="' + wmode + '" width="' + wid + '" height="' + hgt + '" name="' + nm + '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://get.adobe.com/flashplayer/" />');
        document.write('    </embed>');
        document.write('</object>');

    }

    // Method to load a variable into a SWF.
    this.loadFlashVar = function(nm, tar, val) {

	    if (eval('window.' + nm)) {
	        windowName = eval("window.document['" + nm + "']");
	        windowName.SetVariable(tar, val);
	    } else if (eval('document.' + nm)) {
	        docName = eval('document.' + nm);
	        docName.SetVariable(tar, val);
	    }

    }

}


/**
 *
 * JaxForm Component
 *
 */

// Prototype for the JaxForm object and its methods and properties.
function JaxForm(formId, conds) {

    // Define form properties.
    this.id = formId;
    this.fo = document.getElementById(this.id);
    this.conditions = conds;
    this.validators = new Array();

    if (this.conditions != null) {
        // Loop through the validators array that was passed.
        for (var i = 0; i < this.conditions.length; i++) {
            foElem = eval('this.fo.' + this.conditions[i][0]);
            foElem.setAttribute('jax', this.conditions[i][1]);
        }
    }

    // Method to validate the form.
    this.validate = function() {

        // Clear the validators array.
        this.validators = new Array();

        // Parse through the different types of form elements.
        this.parseFormElements('input');
        this.parseFormElements('select');
        this.parseFormElements('textarea');

        // Loop through the current global validators array.
        for (var i = 0; i < this.validators.length; i++) {

            // Check form element and return error message
            error = this.formElementIsValid(this.validators[i]);

            // If there is an error, display error message, focus the incorrect field and return false.
            if (error != null) {

                alert(error);

                if (this.validators[i][0] == 'radio') {
                    fo = eval('this.fo.' + this.validators[i][1] + '[0]');
                } else if (this.validators[i][0] == 'checkbox') {
                    fo = eval('this.fo.' + this.validators[i][1].substring(0, this.validators[i][1].indexOf('[')));
                } else {
                    fo = eval('this.fo.' + this.validators[i][1]);
                }

                fo.focus();
                if (this.validators[i][0].indexOf('select') == -1) {
                    fo.select();
                }
                return false;

            }

        }

        // If there is no error message, return true.
        return true;

    }

    // Method to parse through the form elements for jax-based validator attributes and conditions.
    this.parseFormElements = function(tag) {

        // Get the form elements.
        var objs = document.getElementsByTagName(tag);

        // Loop through the form elements, parsing the jax-based validators and setting the global validator array.
        for (var i = 0; i < objs.length; i++) {

            var obj = objs[i];

            if (obj.getAttribute('jax')) {

                // Check if the validator has multiple conditions.
                if (obj.getAttribute('jax').indexOf('&') != -1) {
                    objConds = obj.getAttribute('jax').split('&');
                } else {
                    objConds = new Array(obj.getAttribute('jax'));
                }

                customMsg = null;
                for (var k = 0; k < this.conditions.length; k++) {
                    if (this.conditions[k].indexOf(obj.name) != -1) {
                        customMsg = (this.conditions[k][2] != undefined) ? this.conditions[k][2] : null;
                    }
                }

                for (var j = 0; j < objConds.length; j++) {
                    // Check if the validator has a condition value or not.
                    if (objConds[j].indexOf('|') != -1) {
                        cond = objConds[j].substring(0, objConds[j].indexOf('|'));
                        condVal = objConds[j].substring(objConds[j].indexOf('|') + 1);
                    } else {
                        cond = objConds[j];
                        condVal = null;
                    }

                    // Add the validator to the validators array.
                    this.validators.push(Array(obj.type, obj.name, obj.value, cond, condVal, customMsg));
                }

            }

        }

    }

    // Method to validate the form element.
    this.formElementIsValid = function(elem) {

        var msg = null;

        switch (elem[3]) {

            // Alphanumeric pattern.
            case 'AlphaNum':
                if (!elem[2].match(/^\w+$/)) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not alphanumeric.';
                }
                break;

            // Alpha-only pattern.
            case 'Alpha':
                if (!elem[2].match(/^[a-zA-Z]+$/)) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field must contain only characters of the alphabet.';
                }
                break;

            // Between two values.
            case 'Between':
                var numAry = elem[4].split('|');
                if ((parseInt(elem[2]) <= parseInt(numAry[0])) || (parseInt(elem[2]) >= parseInt(numAry[1]))) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not between ' + numAry[0] + ' and ' + numAry[1];
                }
                break;

            // E-mail pattern.
            case 'Email':
                if (!elem[2].match(/[a-zA-Z0-9\.\-\_+%]+@[a-zA-Z0-9\-\_\.]+\.[a-zA-Z]{2,4}/)) {
                    msg = (elem[5] != null) ? elem[5] : 'The address in the ' + elem[1].replace(/_/g, ' ') + ' field is not a valid email.';
                }
                break;

            // Equal to value.
            case 'Equal':
                if (elem[2] != elem[4]) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field does not equal ' + elem[4];
                }
                break;

            // Greater than value.
            case 'GreaterThan':
                if (parseInt(elem[2]) <= parseInt(elem[4])) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not greater than ' + elem[4];
                }
                break;

            // String length greater than value.
            case 'Length':
                if (parseInt(elem[2].length) != parseInt(elem[4])) {
                    msg = (elem[5] != null) ? elem[5] : 'The length of the ' + elem[1].replace(/_/g, ' ') + ' field does not equal ' + elem[4];
                }
                break;

            // String length between two values.
            case 'LengthBet':
                var numAry = elem[4].split('|');
                if ((parseInt(elem[2].length) <= parseInt(numAry[0])) || (parseInt(elem[2].length) >= parseInt(numAry[1]))) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not between ' + numAry[0] + ' and ' + numAry[1];
                }
                break;

            // String length greater than value.
            case 'LengthGT':
                if (parseInt(elem[2].length) <= parseInt(elem[4])) {
                    msg = (elem[5] != null) ? elem[5] : 'The length of the ' + elem[1].replace(/_/g, ' ') + ' field is not greater than ' + elem[4];
                }
                break;

            // String length less than value.
            case 'LengthLT':
                if (parseInt(elem[2].length) >= parseInt(elem[4])) {
                    msg = (elem[5] != null) ? elem[5] : 'The length of the ' + elem[1].replace(/_/g, ' ') + ' field is not less than ' + elem[4];
                }
                break;

            // Less than value.
            case 'LessThan':
                if (parseInt(elem[2]) >= parseInt(elem[4])) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not less than ' + elem[4];
                }
                break;

            // Value not empty.
            case 'NotEmpty':
                if ((elem[0] == 'radio') || (elem[0] == 'checkbox')) {
                    var elems = document.getElementsByTagName('input');
                    var counter = 0;

                    for (i = 0; i < elems.length; i++) {
                        if (elems[i].type == elem[0]) {
                            if (elems[i].checked) {
                                counter++;
                            }
                        }
                    }
                    if (counter == 0) {
                        if (elem[1].indexOf('[') != -1) {
                            elemName = elem[1].substring(0, elem[1].indexOf('['));
                        } else {
                            elemName = elem[1];
                        }
                        msg = (elem[5] != null) ? elem[5] : 'The ' + elemName.replace(/_/g, ' ') + ' field must be checked.';
                    }
                } else if (elem[2].length < 1) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is empty.';
                }
                break;

            // Not equal to value.
            case 'NotEqual':
                if (elem[2] == elem[4]) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field cannot equal ' + elem[4];
                }
                break;

            // Numeric value.
            case 'Num':
                if (isNaN(elem[2])) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not a number.';
                }
                break;

            // Value matches regular expression.
            case 'RegEx':
                var regex = eval(elem[4]);
                if (!elem[2].match(regex)) {
                    msg = (elem[5] != null) ? elem[5] : 'The ' + elem[1].replace(/_/g, ' ') + ' field is not in the correct format.';
                }
                break;

            default:
                msg = null;

        }

        return msg;

    }

    // Method to check the length of the input of a form field and jump to the next one.
    this.checkLength = function(obj) {

        if (obj.value.length == obj.maxLength) {
            var next = obj.tabIndex;
            if (next < this.fo.length) {
                this.fo.elements[next].focus();
            }
        }

    }

    // Method to convert a string from a form field input into a friendly URL, passing it to another form field.
    this.convertURL = function(subj, targ, sep) {

        sub = eval('this.fo.' + subj);
        tar = eval('this.fo.' + targ);
        tar.value = sub.value.slug(sep);

    }

    // Method to quickly perform a checkbox validation to make sure at least one checkbox is checked.
    this.checkValidate = function(elem, conf) {

        chk = document.getElementsByTagName('input');
        counter = 0;

        for (i = 0; i < chk.length; i++) {
            if (chk[i].type == 'checkbox') {
                if (chk[i].checked) {
                    counter++;
                }
            }
        }

        if ((elem != null) && (counter == 0)) {
            alert('Please select at least one ' + elem + '.');
            return false;
        } else if (conf != null) {
            var answer = confirm('This action cannot be undone. Are you sure?');
            if (answer) {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }

    }

    // Method to check all checkboxes specified.
    this.checkAll = function(elem, exclude) {

        if (exclude != null) {
            if (exclude.constructor != Array) {
                exclude = new Array(exclude);
            }
        } else {
            exclude = new Array();
        }

        chk = document.getElementsByTagName('input');
        counter = 0;

        if (elem == null) {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].type == 'checkbox') && (exclude.indexOf(chk[i].value) == -1)) {
                    if (!chk[i].checked) {
                        chk[i].checked = true;
                    }
                }
            }
        } else {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].name.indexOf(elem) != -1) && (exclude.indexOf(chk[i].value) == -1)) {
                    if (!chk[i].checked) {
                        chk[i].checked = true;
                    }
                }
            }
        }

    }

    // Method to uncheck all checkboxes specified.
    this.uncheckAll = function(elem, exclude) {

        if (exclude != null) {
            if (exclude.constructor != Array) {
                exclude = new Array(exclude);
            }
        } else {
            exclude = new Array();
        }

        chk = document.getElementsByTagName('input');
        counter = 0;

        if (elem == null) {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].type == 'checkbox') && (exclude.indexOf(chk[i].value) == -1)) {
                    if (chk[i].checked) {
                        chk[i].checked = false;
                    }
                }
            }

        } else {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].name.indexOf(elem) != -1) && (exclude.indexOf(chk[i].value) == -1)) {
                    if (chk[i].checked) {
                        chk[i].checked = false;
                    }
                }
            }
        }

    }

    // Method to inverse the checkboxes specified.
    this.checkInverse = function(elem, exclude) {

        if (exclude != null) {
            if (exclude.constructor != Array) {
                exclude = new Array(exclude);
            }
        } else {
            exclude = new Array();
        }

        chk = document.getElementsByTagName('input');
        counter = 0;

        if (elem == null) {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].type == 'checkbox') && (exclude.indexOf(chk[i].value) == -1)) {
                    if (chk[i].checked) {
                        chk[i].checked = false;
                    } else if (!chk[i].checked) {
                        chk[i].checked = true;
                    }
                }
            }

        } else {
            for (i = 0; i < chk.length; i++) {
                if ((chk[i].name.indexOf(elem) != -1) && (exclude.indexOf(chk[i].value) == -1)) {
                    if (chk[i].checked) {
                        chk[i].checked = false;
                    } else if (!chk[i].checked) {
                        chk[i].checked = true;
                    }
                }
            }
        }

    }

}

// Prototype for the JaxElementInput object and its methods and properties.
function JaxElementInput(inputType, appendTo, attribs) {

    // Set the parent element and create the child element.
    this.parentElem = document.getElementById(appendTo);
    this.elem = document.createElement('input');
    this.elem.setAttribute('type', inputType);

    // Set any element attributes.
    if (attribs != undefined) {
        for (var i = 0; i < attribs.length; i++) {
            this.elem.setAttribute(attribs[i][0], attribs[i][1]);
        }
    }

    // Append the child element to the parent element.
    this.parentElem.appendChild(this.elem);

    // Method to remove the child element.
    this.remove = function() {
        this.parentElem.removeChild(this.elem);
    }

}

// Prototype for the JaxElementSelect object and its methods and properties.
function JaxElementSelect(appendTo, vals, attribs, sel) {

    // Set the parent element and define the properties.
    this.parentElem = document.getElementById(appendTo);
    this.elem = document.createElement('select');
    this.values = new Array();
    this.valueSelected = (sel != undefined) ? sel : null;

    // Set any element attributes.
    if (attribs != undefined) {
        for (var i = 0; i < attribs.length; i++) {
            this.elem.setAttribute(attribs[i][0], attribs[i][1]);
        }
    }

    // If value passed was a YEAR flag, calculate the year range and set the values
    if (vals.indexOf('YEAR') != -1) {
        var years = new Array();
        var yearAry = vals.split('_');

        if ((yearAry[1] != undefined) && (yearAry[2] != undefined)) {
            if (yearAry[1] < yearAry[2]) {
                for (var i = yearAry[1]; i <= yearAry[2]; i++) {
                    years.push(i);
                }
            } else {
                for (var i = yearAry[1]; i >= yearAry[2]; i--) {
                    years.push(i);
                }
            }
        } else if (yearAry[1] != undefined) {
            var d = new Date();
            var year = d.getFullYear()
            if (year < yearAry[1]) {
                for (var i = year; i <= yearAry[1]; i++) {
                    years.push(i);
                }
            } else {
                for (var i = year; i >= yearAry[1]; i--) {
                    years.push(i);
                }
            }
        } else {
            var d = new Date();
            var year = d.getFullYear();
            for (var i = year; i <= (year + 10); i++) {
                years.push(i);
            }
        }
        vl = years;

    // Else, set the values based of a pre-defined flag, or the an array of values passed.
    } else {

        switch (vals) {
            // Months, numeric short values.
            case 'MONTHS_SHORT':
                vl = new Array(Array('--', '--'), Array('01', '01'), Array('02', '02'), Array('03', '03'), Array('04', '04'), Array('05', '05'), Array('06', '06'), Array('07', '07'), Array('08', '08'), Array('09', '09'), Array('10', '10'), Array('11', '11'), Array('12', '12'));
                break;
            // Months, long name values.
            case 'MONTHS_LONG':
                vl = new Array(Array('--', '------'), Array('01', 'January'), Array('02', 'February'), Array('03', 'March'), Array('04', 'April'), Array('05', 'May'), Array('06', 'June'), Array('07', 'July'), Array('08', 'August'), Array('09', 'September'), Array('10', 'October'), Array('11', 'November'), Array('12', 'December'));
                break;
            // Days of Month, numeric short values.
            case 'DAYS_OF_MONTH':
                vl = new Array(Array('--', '--'), Array('01', '01'), Array('02', '02'), Array('03', '03'), Array('04', '04'), Array('05', '05'), Array('06', '06'), Array('07', '07'), Array('08', '08'), Array('09', '09'), Array('10', '10'), Array('11', '11'), Array('12', '12'), Array('13', '13'), Array('14', '14'), Array('15', '15'), Array('16', '16'), Array('17', '17'), Array('18', '18'), Array('19', '19'), Array('20', '20'), Array('21', '21'), Array('22', '22'), Array('23', '23'), Array('24', '24'), Array('25', '25'), Array('26', '26'), Array('27', '27'), Array('28', '28'), Array('29', '29'), Array('30', '30'), Array('31', '31'));
                break;
            // Days of Week, long name values.
            case 'DAYS_OF_WEEK':
                vl = new Array(Array('--', '------'), Array('Sunday', 'Sunday'), Array('Monday', 'Monday'), Array('Tuesday', 'Tuesday'), Array('Wednesday', 'Wednesday'), Array('Thursday', 'Thursday'), Array('Friday', 'Friday'), Array('Saturday', 'Saturday'));
                break;
            // Hours, 12-hour values.
            case 'HOURS':
                vl = new Array(Array('--', '--'), Array('01', '01'), Array('02', '02'), Array('03', '03'), Array('04', '04'), Array('05', '05'), Array('06', '06'), Array('07', '07'), Array('08', '08'), Array('09', '09'), Array('10', '10'), Array('11', '11'), Array('12', '12'));
                break;
            // Military Hours, 24-hour values.
            case 'MILITARY_HOURS':
                vl = new Array(Array('--', '--'), Array('00', '00'), Array('01', '01'), Array('02', '02'), Array('03', '03'), Array('04', '04'), Array('05', '05'), Array('06', '06'), Array('07', '07'), Array('08', '08'), Array('09', '09'), Array('10', '10'), Array('11', '11'), Array('12', '12'), Array('13', '13'), Array('14', '14'), Array('15', '15'), Array('16', '16'), Array('17', '17'), Array('18', '18'), Array('19', '19'), Array('20', '20'), Array('21', '21'), Array('22', '22'), Array('23', '23'));
                break;
            // Minutes, incremental by 1 minute.
            case 'MINUTES':
                vl = new Array(Array('--', '--'), Array('00', '00'), Array('01', '01'), Array('02', '02'), Array('03', '03'), Array('04', '04'), Array('05', '05'), Array('06', '06'), Array('07', '07'), Array('08', '08'), Array('09', '09'), Array('10', '10'), Array('11', '11'), Array('12', '12'), Array('13', '13'), Array('14', '14'), Array('15', '15'), Array('16', '16'), Array('17', '17'), Array('18', '18'), Array('19', '19'), Array('20', '20'), Array('21', '21'), Array('22', '22'), Array('23', '23'), Array('24', '24'), Array('25', '25'), Array('26', '26'), Array('27', '27'), Array('28', '28'), Array('29', '29'), Array('30', '30'), Array('31', '31'), Array('32', '32'), Array('33', '33'), Array('34', '34'), Array('35', '35'), Array('36', '36'), Array('37', '37'), Array('38', '38'), Array('39', '39'), Array('40', '40'), Array('41', '41'), Array('42', '42'), Array('43', '43'), Array('44', '44'), Array('45', '45'), Array('46', '46'), Array('47', '47'), Array('48', '48'), Array('49', '49'), Array('50', '50'), Array('51', '51'), Array('52', '52'), Array('53', '53'), Array('54', '54'), Array('55', '55'), Array('56', '56'), Array('57', '57'), Array('58', '58'), Array('59', '59'));
                break;
            // Minutes, incremental by 5 minutes.
            case 'MINUTES_BY_5':
                vl = new Array(Array('--', '--'), Array('00', '00'), Array('05', '05'), Array('10', '10'), Array('15', '15'), Array('20', '20'), Array('25', '25'), Array('30', '30'), Array('35', '35'), Array('40', '40'), Array('45', '45'), Array('50', '50'), Array('55', '55'));
                break;
            // Minutes, incremental by 15 minutes.
            case 'MINUTES_BY_15':
                vl = new Array(Array('--', '--'), Array('00', '00'), Array('15', '15'), Array('30', '30'), Array('45', '45'));
                break;
            // US States, short name values.
            case 'US_STATES_SHORT':
                vl = new Array(Array('--', '--'), Array('AK', 'AK'), Array('AL', 'AL'), Array('AR', 'AR'), Array('AZ', 'AZ'), Array('CA', 'CA'), Array('CO', 'CO'), Array('CT', 'CT'), Array('DC', 'DC'), Array('DE', 'DE'), Array('FL', 'FL'), Array('GA', 'GA'), Array('HI', 'HI'), Array('IA', 'IA'), Array('ID', 'ID'), Array('IL', 'IL'), Array('IN', 'IN'), Array('KS', 'KS'), Array('KY', 'KY'), Array('LA', 'LA'), Array('MA', 'MA'), Array('MD', 'MD'), Array('ME', 'ME'), Array('MI', 'MI'), Array('MN', 'MN'), Array('MO', 'MO'), Array('MS', 'MS'), Array('MT', 'MT'), Array('NC', 'NC'), Array('ND', 'ND'), Array('NE', 'NE'), Array('NH', 'NH'), Array('NJ', 'NJ'), Array('NM', 'NM'), Array('NV', 'NV'), Array('NY', 'NY'), Array('OH', 'OH'), Array('OK', 'OK'), Array('OR', 'OR'), Array('PA', 'PA'), Array('RI', 'RI'), Array('SC', 'SC'), Array('SD', 'SD'), Array('TN', 'TN'), Array('TX', 'TX'), Array('UT', 'UT'), Array('VA', 'VA'), Array('VT', 'VT'), Array('WA', 'WA'), Array('WI', 'WI'), Array('WV', 'WV'), Array('WY', 'WY'));
                break;
            // US States, long name values.
            case 'US_STATES_LONG':
                vl = new Array(Array('--', '------'), Array('AL', 'Alabama'), Array('AK', 'Alaska'), Array('AZ', 'Arizona'), Array('AR', 'Arkansas'), Array('CA', 'California'), Array('CO', 'Colorado'), Array('CT', 'Connecticut'), Array('DC', 'District of Columbia'), Array('DE', 'Delaware'), Array('FL', 'Florida'), Array('GA', 'Georgia'), Array('HI', 'Hawaii'), Array('ID', 'Idaho'), Array('IL', 'Illinois'), Array('IN', 'Indiana'), Array('IA', 'Iowa'), Array('KS', 'Kansas'), Array('KY', 'Kentucky'), Array('LA', 'Louisiana'), Array('ME', 'Maine'), Array('MD', 'Maryland'), Array('MA', 'Massachusetts'), Array('MI', 'Michigan'), Array('MN', 'Minnesota'), Array('MS', 'Mississippi'), Array('MO', 'Missouri'), Array('MT', 'Montana'), Array('NE', 'Nebraska'), Array('NV', 'Nevada'), Array('NH', 'New Hampshire'), Array('NJ', 'New Jersey'), Array('NM', 'New Mexico'), Array('NY', 'New York'), Array('NC', 'North Carolina'), Array('ND', 'North Dakota'), Array('OH', 'Ohio'), Array('OK', 'Oklahoma'), Array('OR', 'Oregon'), Array('PA', 'Pennsylvania'), Array('RI', 'Rhode Island'), Array('SC', 'South Carolina'), Array('SD', 'South Dakota'), Array('TN', 'Tennessee'), Array('TX', 'Texas'), Array('UT', 'Utah'), Array('VT', 'Vermont'), Array('VA', 'Virginia'), Array('WA', 'Washington'), Array('WV', 'West Virginia'), Array('WI', 'Wisconsin'), Array('WY', 'Wyoming'));
                break;
            // US States & Territories, short name values.
            case 'US_TERR_SHORT':
                vl = new Array(Array('--', '--'), Array('AS', 'AS'), Array('FM', 'FM'), Array('GU', 'GU'), Array('MH', 'MH'), Array('MP', 'MP'), Array('PW', 'PW'), Array('PR', 'PR'), Array('VI', 'VI'), Array('AE', 'AE'), Array('AA', 'AA'), Array('AP', 'AP'));
                break;
            // US States & Territories, long name values.
            case 'US_TERR_LONG':
                vl = new Array(Array('--', '------'), Array('AS', 'American Samoa'), Array('FM', 'Federated States of Micronesia'), Array('GU', 'Guam'), Array('MH', 'Marshall Islands'), Array('MP', 'Northern Mariana Islands'), Array('PW', 'Palau'), Array('PR', 'Puerto Rico'), Array('VI', 'Virgin Islands'), Array('AE', 'Armed Forces'), Array('AA', 'Armed Forces Americas'), Array('AP', 'Armed Forces Pacific'));
                break;
            // Canadian Provinces, short name values.
            case 'CA_PROVINCES_SHORT':
                vl = new Array(Array('--', '--'), Array('AB', 'AB'), Array('BC', 'BC'), Array('MB', 'MB'), Array('NB', 'NB'), Array('NL', 'NL'), Array('NT', 'NT'), Array('NS', 'NS'), Array('NU', 'NU'), Array('ON', 'ON'), Array('PE', 'PE'), Array('QC', 'QC'), Array('SK', 'SK'), Array('YT', 'YT'));
                break;
            // Canadian Provinces, long name values.
            case 'CA_PROVINCES_LONG':
                vl = new Array(Array('--', '------'), Array('AB', 'Alberta'), Array('BC', 'British Columbia'), Array('MB', 'Manitoba'), Array('NB', 'New Brunswick'), Array('NL', 'Newfoundland and Labrador'), Array('NT', 'Northwest Territories'), Array('NS', 'Nova Scotia'), Array('NU', 'Nunavut'), Array('ON', 'Ontario'), Array('PE', 'Prince Edward Island'), Array('QC', 'Quebec'), Array('SK', 'Saskatchewan'), Array('YT', 'Yukon'));
                break;
            // Mexican States, short name values.
            case 'MEX_STATES_SHORT':
                vl = new Array(Array('--', '--'), Array('AG', 'AG'), Array('BC', 'BC'), Array('BS', 'BS'), Array('CM', 'CM'), Array('CS', 'CS'), Array('CH', 'CH'), Array('CO', 'CO'), Array('CL', 'CL'), Array('DF', 'DF'), Array('DG', 'DG'), Array('GT', 'GT'), Array('GR', 'GR'), Array('HG', 'HG'), Array('JA', 'JA'), Array('ME', 'ME'), Array('MI', 'MI'), Array('MO', 'MO'), Array('NA', 'NA'), Array('NL', 'NL'), Array('OA', 'OA'), Array('PB', 'PB'), Array('QE', 'QE'), Array('QR', 'QR'), Array('SL', 'SL'), Array('SI', 'SI'), Array('SO', 'SO'), Array('TB', 'TB'), Array('TM', 'TM'), Array('TL', 'TL'), Array('VE', 'VE'), Array('YU', 'YU'), Array('ZA', 'ZA'));
                break;
            // Mexican States, long name values.
            case 'MEX_STATES_LONG':
                vl = new Array(Array('--', '------'), Array('AG', 'Aguascalientes'), Array('BC', 'Baja California'), Array('BS', 'Baja California Sur'), Array('CM', 'Campeche'), Array('CS', 'Chiapas'), Array('CH', 'Chihuahua'), Array('CO', 'Coahuila'), Array('CL', 'Colima'), Array('DF', 'Federal District'), Array('DG', 'Durango'), Array('GT', 'Guanajuato'), Array('GR', 'Guerrero'), Array('HG', 'Hidalgo'), Array('JA', 'Jalisco'), Array('ME', 'Mexico State'), Array('MI', 'Michoac&#225;n'), Array('MO', 'Morelos'), Array('NA', 'Nayarit'), Array('NL', 'Nuevo Le&#243;n'), Array('OA', 'Oaxaca'), Array('PB', 'Puebla'), Array('QE', 'Quer&#233;taro'), Array('QR', 'Quintana Roo'), Array('SL', 'San Luis Potos&#237;'), Array('SI', 'Sinaloa'), Array('SO', 'Sonora'), Array('TB', 'Tabasco'), Array('TM', 'Tamaulipas'), Array('TL', 'Tlaxcala'), Array('VE', 'Veracruz'), Array('YU', 'Yucat&#225;n'), Array('ZA', 'Zacatecas'));
                break;
            // UK Counties, long name values.
            case 'UK_COUNTIES':
                vl = new Array(Array('--', '------'), Array('Aberdeenshire', 'Aberdeenshire'), Array('Alderney', 'Alderney'), Array('Angus/Forfarshire', 'Angus/Forfarshire'), Array('Argyllshire', 'Argyllshire'), Array('Avon', 'Avon'), Array('Ayrshire', 'Ayrshire'), Array('Banffshire', 'Banffshire'), Array('Bedfordshire', 'Bedfordshire'), Array('Berkshire', 'Berkshire'), Array('Berwickshire', 'Berwickshire'), Array('Buckinghamshire', 'Buckinghamshire'), Array('Buteshire', 'Buteshire'), Array('Caithness', 'Caithness'), Array('Cambridgeshire', 'Cambridgeshire'), Array('Cheshire', 'Cheshire'), Array('Clackmannanshire', 'Clackmannanshire'), Array('Clwyd', 'Clwyd'), Array('Cornwall', 'Cornwall'), Array('County Antrim', 'County Antrim'), Array('County Armagh', 'County Armagh'), Array('County Down', 'County Down'), Array('County Fermanagh', 'County Fermanagh'), Array('County Londonderry', 'County Londonderry'), Array('County Tyrone', 'County Tyrone'), Array('Cumbria', 'Cumbria'), Array('Derbyshire', 'Derbyshire'), Array('Devon', 'Devon'), Array('Dorset', 'Dorset'), Array('Dumbartonshire', 'Dumbartonshire'), Array('Dumfriesshire', 'Dumfriesshire'), Array('Durham', 'Durham'), Array('Dyfed', 'Dyfed'), Array('East Lothian', 'East Lothian'), Array('East Sussex', 'East Sussex'), Array('East Yorkshire', 'East Yorkshire'), Array('Essex', 'Essex'), Array('Fair Isle', 'Fair Isle'), Array('Fife', 'Fife'), Array('Gloucestershire', 'Gloucestershire'), Array('Greater London', 'Greater London'), Array('Greater Manchester', 'Greater Manchester'), Array('Guernsey', 'Guernsey'), Array('Gwent', 'Gwent'), Array('Gwynedd', 'Gwynedd'), Array('Hampshire', 'Hampshire'), Array('Herefordshire', 'Herefordshire'), Array('Herm', 'Herm'), Array('Hertfordshire', 'Hertfordshire'), Array('Huntingdonshire', 'Huntingdonshire'), Array('Inner Hebrides', 'Inner Hebrides'), Array('Inverness-shire', 'Inverness-shire'), Array('Isle of Man', 'Isle of Man'), Array('Isle of Wight', 'Isle of Wight'), Array('Isles of Scilly', 'Isles of Scilly'), Array('Jersey', 'Jersey'), Array('Kent', 'Kent'), Array('Kincardineshire', 'Kincardineshire'), Array('Kinross-shire', 'Kinross-shire'), Array('Kirkcudbrightshire', 'Kirkcudbrightshire'), Array('Lanarkshire', 'Lanarkshire'), Array('Lancashire', 'Lancashire'), Array('Leicestershire', 'Leicestershire'), Array('Lincolnshire', 'Lincolnshire'), Array('Merseyside', 'Merseyside'), Array('Mid Glamorgan', 'Mid Glamorgan'), Array('Middlesex', 'Middlesex'), Array('Midlothian/Edinburghshire', 'Midlothian/Edinburghshire'), Array('Morayshire', 'Morayshire'), Array('Nairnshire', 'Nairnshire'), Array('Norfolk', 'Norfolk'), Array('North Yorkshire', 'North Yorkshire'), Array('Northamptonshire', 'Northamptonshire'), Array('Northumberland', 'Northumberland'), Array('Nottinghamshire', 'Nottinghamshire'), Array('Orkney', 'Orkney'), Array('Outer Hebrides', 'Outer Hebrides'), Array('Oxfordshire', 'Oxfordshire'), Array('Peeblesshire', 'Peeblesshire'), Array('Perthshire', 'Perthshire'), Array('Powys', 'Powys'), Array('Renfrewshire', 'Renfrewshire'), Array('Ross-shire', 'Ross-shire'), Array('Roxburghshire', 'Roxburghshire'), Array('Rutland', 'Rutland'), Array('Sark', 'Sark'), Array('Selkirkshire', 'Selkirkshire'), Array('Shetland', 'Shetland'), Array('Shropshire', 'Shropshire'), Array('Somerset', 'Somerset'), Array('South Glamorgan', 'South Glamorgan'), Array('South Yorkshire', 'South Yorkshire'), Array('Staffordshire', 'Staffordshire'), Array('Stirlingshire', 'Stirlingshire'), Array('Suffolk', 'Suffolk'), Array('Surrey', 'Surrey'), Array('Sutherland', 'Sutherland'), Array('Tyne and Wear', 'Tyne and Wear'), Array('Warwickshire', 'Warwickshire'), Array('West Glamorgan', 'West Glamorgan'), Array('West Lothian/Linlithgowshire', 'West Lothian/Linlithgowshire'), Array('West Midlands', 'West Midlands'), Array('West Sussex', 'West Sussex'), Array('West Yorkshire', 'West Yorkshire'), Array('Wigtownshire', 'Wigtownshire'), Array('Wiltshire', 'Wiltshire'), Array('Worcestershire', 'Worcestershire'));
                break;
            // Ireland Counties, long name values.
            case 'IRELAND_COUNTIES':
                vl = new Array(Array('--', '------'), Array('Carlow', 'Carlow'), Array('Cavan', 'Cavan'), Array('Clare', 'Clare'), Array('Cork', 'Cork'), Array('Donegal', 'Donegal'), Array('Dublin', 'Dublin'), Array('Galway', 'Galway'), Array('Kerry', 'Kerry'), Array('Kildare', 'Kildare'), Array('Kilkenny', 'Kilkenny'), Array('Laois', 'Laois'), Array('Leitrim', 'Leitrim'), Array('Limerick', 'Limerick'), Array('Longford', 'Longford'), Array('Louth', 'Louth'), Array('Mayo', 'Mayo'), Array('Meath', 'Meath'), Array('Monaghan', 'Monaghan'), Array('Offaly', 'Offaly'), Array('Roscommon', 'Roscommon'), Array('Sligo', 'Sligo'), Array('Tipperary', 'Tipperary'), Array('Waterford', 'Waterford'), Array('Westmeath', 'Westmeath'), Array('Wexford', 'Wexford'), Array('Wicklow', 'Wicklow'));
                break;
            // Countries, long name values.
            case 'COUNTRIES':
                vl = new Array(Array('--', '------'), Array('AF', 'Afghanistan'), Array('AL', 'Albania'), Array('DZ', 'Algeria'), Array('AS', 'American Samoa'), Array('AD', 'Andorra'), Array('AO', 'Angola'), Array('AI', 'Anguilla'), Array('AQ', 'Antarctica'), Array('AG', 'Antigua and Barbuda'), Array('AR', 'Argentina'), Array('AM', 'Armenia'), Array('AW', 'Aruba'), Array('AU', 'Australia'), Array('AT', 'Austria'), Array('AZ', 'Azerbaijan'), Array('BS', 'Bahamas'), Array('BH', 'Bahrain'), Array('BD', 'Bangladesh'), Array('BB', 'Barbados'), Array('BY', 'Belarus'), Array('BE', 'Belgium'), Array('BZ', 'Belize'), Array('BJ', 'Benin'), Array('BM', 'Bermuda'), Array('BT', 'Bhutan'), Array('BO', 'Bolivia'), Array('BA', 'Bosnia and Herzegowina'), Array('BW', 'Botswana'), Array('BV', 'Bouvet Island'), Array('BR', 'Brazil'), Array('IO', 'British Indian Ocean Territory'), Array('BN', 'Brunei Darussalam'), Array('BG', 'Bulgaria'), Array('BF', 'Burkina Faso'), Array('BI', 'Burundi'), Array('KH', 'Cambodia'), Array('CM', 'Cameroon'), Array('CA', 'Canada'), Array('CV', 'Cape Verde'), Array('KY', 'Cayman Islands'), Array('CF', 'Central African Republic'), Array('TD', 'Chad'), Array('CL', 'Chile'), Array('CN', 'China'), Array('CX', 'Christmas Island'), Array('CC', 'Cocos (Keeling) Islands'), Array('CO', 'Colombia'), Array('KM', 'Comoros'), Array('CG', 'Congo'), Array('CD', 'Congo), Array(the Democratic Republic of the'), Array('CK', 'Cook Islands'), Array('CR', 'Costa Rica'), Array('CI', 'Cote d&#39;Ivoire'), Array('HR', 'Croatia (Hrvatska)'), Array('CU', 'Cuba'), Array('CY', 'Cyprus'), Array('CZ', 'Czech Republic'), Array('DK', 'Denmark'), Array('DJ', 'Djibouti'), Array('DM', 'Dominica'), Array('DO', 'Dominican Republic'), Array('TP', 'East Timor'), Array('EC', 'Ecuador'), Array('EG', 'Egypt'), Array('SV', 'El Salvador'), Array('GQ', 'Equatorial Guinea'), Array('ER', 'Eritrea'), Array('EE', 'Estonia'), Array('ET', 'Ethiopia'), Array('FK', 'Falkland Islands (Malvinas)'), Array('FO', 'Faroe Islands'), Array('FJ', 'Fiji'), Array('FI', 'Finland'), Array('FR', 'France'), Array('FX', 'France), Array(Metropolitan'), Array('GF', 'French Guiana'), Array('PF', 'French Polynesia'), Array('TF', 'French Southern Territories'), Array('GA', 'Gabon'), Array('GM', 'Gambia'), Array('GE', 'Georgia'), Array('DE', 'Germany'), Array('GH', 'Ghana'), Array('GI', 'Gibraltar'), Array('GB', 'Great Britain'), Array('GR', 'Greece'), Array('GL', 'Greenland'), Array('GD', 'Grenada'), Array('GP', 'Guadeloupe'), Array('GU', 'Guam'), Array('GT', 'Guatemala'), Array('GN', 'Guinea'), Array('GW', 'Guinea-Bissau'), Array('GY', 'Guyana'), Array('HT', 'Haiti'), Array('HM', 'Heard and Mc Donald Islands'), Array('VA', 'Holy See (Vatican City State)'), Array('HN', 'Honduras'), Array('HK', 'Hong Kong'), Array('HU', 'Hungary'), Array('IS', 'Iceland'), Array('IN', 'India'), Array('ID', 'Indonesia'), Array('IR', 'Iran (Islamic Republic of)'), Array('IQ', 'Iraq'), Array('IE', 'Ireland'), Array('IL', 'Israel'), Array('IT', 'Italy'), Array('JM', 'Jamaica'), Array('JP', 'Japan'), Array('JO', 'Jordan'), Array('KZ', 'Kazakhstan'), Array('KE', 'Kenya'), Array('KI', 'Kiribati'), Array('KP', 'Korea), Array(Democratic People&#39;s Republic of'), Array('KR', 'Korea), Array(Republic of'), Array('KW', 'Kuwait'), Array('KG', 'Kyrgyzstan'), Array('LA', 'Lao People&#39;s Democratic Republic'), Array('LV', 'Latvia'), Array('LB', 'Lebanon'), Array('LS', 'Lesotho'), Array('LR', 'Liberia'), Array('LY', 'Libyan Arab Jamahiriya'),
                               Array('LI', 'Liechtenstein'), Array('LT', 'Lithuania'), Array('LU', 'Luxembourg'), Array('MO', 'Macau'), Array('MK', 'Macedonia), Array(The Former Yugoslav Republic of'), Array('MG', 'Madagascar'), Array('MW', 'Malawi'), Array('MY', 'Malaysia'), Array('MV', 'Maldives'), Array('ML', 'Mali'), Array('MT', 'Malta'), Array('MH', 'Marshall Islands'), Array('MQ', 'Martinique'), Array('MR', 'Mauritania'), Array('MU', 'Mauritius'), Array('YT', 'Mayotte'), Array('MX', 'Mexico'), Array('FM', 'Micronesia), Array(Federated States of'), Array('MD', 'Moldova), Array(Republic of'), Array('MC', 'Monaco'), Array('MN', 'Mongolia'), Array('MS', 'Montserrat'), Array('MA', 'Morocco'), Array('MZ', 'Mozambique'), Array('MM', 'Myanmar'), Array('NA', 'Namibia'), Array('NR', 'Nauru'), Array('NP', 'Nepal'), Array('NL', 'Netherlands'), Array('AN', 'Netherlands Antilles'), Array('NC', 'New Caledonia'), Array('NZ', 'New Zealand'), Array('NI', 'Nicaragua'), Array('NE', 'Niger'), Array('NG', 'Nigeria'), Array('NU', 'Niue'), Array('NF', 'Norfolk Island'), Array('MP', 'Northern Mariana Islands'), Array('NO', 'Norway'), Array('OM', 'Oman'), Array('PK', 'Pakistan'), Array('PW', 'Palau'), Array('PA', 'Panama'), Array('PG', 'Papua New Guinea'), Array('PY', 'Paraguay'), Array('PE', 'Peru'), Array('PH', 'Philippines'), Array('PN', 'Pitcairn'), Array('PL', 'Poland'), Array('PT', 'Portugal'), Array('PR', 'Puerto Rico'), Array('QA', 'Qatar'), Array('RE', 'Reunion'), Array('RO', 'Romania'), Array('RU', 'Russian Federation'), Array('RW', 'Rwanda'), Array('KN', 'Saint Kitts and Nevis'), Array('LC', 'Saint LUCIA'), Array('VC', 'Saint Vincent and the Grenadines'), Array('WS', 'Samoa'), Array('SM', 'San Marino'), Array('ST', 'Sao Tome and Principe'), Array('SA', 'Saudi Arabia'), Array('SN', 'Senegal'), Array('SC', 'Seychelles'), Array('SL', 'Sierra Leone'), Array('SG', 'Singapore'), Array('SK', 'Slovakia (Slovak Republic)'), Array('SI', 'Slovenia'), Array('SB', 'Solomon Islands'), Array('SO', 'Somalia'), Array('ZA', 'South Africa'), Array('GS', 'South Georgia and the South Sandwich Islands'), Array('ES', 'Spain'), Array('LK', 'Sri Lanka'), Array('SH', 'St. Helena'), Array('PM', 'St. Pierre and Miquelon'), Array('SD', 'Sudan'), Array('SR', 'Suriname'), Array('SJ', 'Svalbard and Jan Mayen Islands'), Array('SZ', 'Swaziland'), Array('SE', 'Sweden'), Array('CH', 'Switzerland'), Array('SY', 'Syrian Arab Republic'), Array('TW', 'Taiwan), Array(Province of China'), Array('TJ', 'Tajikistan'), Array('TZ', 'Tanzania), Array(United Republic of'), Array('TH', 'Thailand'), Array('TG', 'Togo'), Array('TK', 'Tokelau'), Array('TO', 'Tonga'), Array('TT', 'Trinidad and Tobago'), Array('TN', 'Tunisia'), Array('TR', 'Turkey'), Array('TM', 'Turkmenistan'), Array('TC', 'Turks and Caicos Islands'), Array('TV', 'Tuvalu'), Array('UG', 'Uganda'), Array('UA', 'Ukraine'), Array('AE', 'United Arab Emirates'), Array('UK', 'United Kingdom'), Array('US', 'United States'), Array('UM', 'United States Minor Outlying Islands'), Array('UY', 'Uruguay'), Array('UZ', 'Uzbekistan'), Array('VU', 'Vanuatu'), Array('VE', 'Venezuela'), Array('VN', 'Viet Nam'), Array('VG', 'Virgin Islands (British)'), Array('VI', 'Virgin Islands (U.S.)'), Array('WF', 'Wallis and Futuna Islands'), Array('EH', 'Western Sahara'), Array('YE', 'Yemen'), Array('YU', 'Yugoslavia'), Array('ZM', 'Zambia'), Array('ZW', 'Zimbabwe'));
                break;
            default:
                vl = vals;
        }
    }

    if (vl.constructor == Array) {
        for (var i = 0; i < vl.length; i++) {
            this.values.push(vl[i]);
        }
    } else {
        this.values.push(vl);
    }

    // Create the option elements.
    for (var i = 0; i < this.values.length; i++) {
        newOpt = document.createElement('option');
        if (this.values[i].constructor == Array) {
            newOpt.setAttribute('value', this.values[i][0]);
            newOpt.selected = (this.valueSelected == this.values[i][1]) ? true : false;
            newOpt.innerHTML = this.values[i][1];
        } else {
            newOpt.setAttribute('value', this.values[i]);
            newOpt.selected = (this.valueSelected == this.values[i]) ? true : false;
            newOpt.innerHTML = this.values[i];
        }
        this.elem.appendChild(newOpt);
    }

    // Append the new child select element to the parent element.
    this.parentElem.appendChild(this.elem);

    // Method to remove the child element.
    this.remove = function() {
        this.parentElem.removeChild(this.elem);
    }

}

