/*
CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only thing you need to change in this file is the following
variables: checkboxHeight, radioHeight and selectWidth.

Replace the first two numbers with the height of the checkbox and
radio button. The actual height of both the checkbox and radio
images should be 4 times the height of these two variables. The
selectWidth value should be the width of your select list image.

You may need to adjust your images a bit if there is a slight
vertical movement during the different stages of the button
activation.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "25";
var radioHeight = "25";

/* No need to change anything after this */
document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.styled_wide { display: none; } select.styled_wide { position: relative; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
    init: function() {
        var inputs = document.getElementsByTagName("input");
        var span = Array();
        var textnode;
        var option;
        var active;
        inputs = document.getElementsByTagName("select");                                                   // get all select element
        for (a = 0; a < inputs.length; a++) {
            if (inputs[a].className == "styled" || inputs[a].className == "styled_wide") {                  // for each select whole classname inidcates it should be altered
                option = inputs[a].getElementsByTagName("option");                                          // get the current option
                active = option[0].childNodes[0].nodeValue;                                                 // get the active node
                span[a] = document.createElement("span");                                                   // create the span element                
                for (b = 0; b < option.length; b++) {                                                       // go trhough every option
                    if (option[b].selected == true) {                                                       // check which one is selected
                        span[a].innerHTML = option[b].childNodes[0].nodeValue;                              // add the selected option's text                        
                    }
                }                
                span[a].className = inputs[a].className;                                                    // keep the class name
                span[a].id = "select" + inputs[a].id;                                                       // generate a custom ID                
                inputs[a].parentNode.insertBefore(span[a], inputs[a]);                                      // insert it before the actual select
                inputs[a].onchange = Custom.choose;
                inputs[a].onkeyup = Custom.choose;
                inputs[a].onblur = Custom.unchoose;
            }
        }
    },

    choose: function() {        
        option = this.getElementsByTagName("option");
        for (d = 0; d < option.length; d++) {
            if (option[d].selected == true) {
                document.getElementById("select" + this.id).innerHTML = "<strong>" + option[d].childNodes[0].nodeValue + "</strong>";
            }
        }
    },
    unchoose: function() {        
        option = this.getElementsByTagName("option");
        for (d = 0; d < option.length; d++) {
            if (option[d].selected == true) {
                document.getElementById("select" + this.id).innerHTML = option[d].childNodes[0].nodeValue;
            }
        }
    },
    
}
//window.onload = Custom.init;