var count;
var selectLength;

var Custom = {
	init: function() {
        var span = Array(), textnode, option, active;
    	var inputs = $$('select.styleId');
        for(var a = 0; a < inputs.length; a++) {
            var option = inputs[a].getElementsByTagName("option");
            var active = option[0].childNodes[0].nodeValue;
            var textnode = document.createTextNode(active);
            var countryWidget = $('country');
            var stateWidget = $('state');
            span[a] = $("select_"+inputs[a].name);
            selectLength = span[a].clientWidth;
            if (selectLength > 135){
                count = 35;
            } else {
                count = 18;
            }
            for(var b = 0; b < option.length; b++) {
                if(option[b].selected == true) {
                    var text = option[b].childNodes[0].nodeValue;
                    text = text.substr(0, count);
                    textnode = document.createTextNode(text);
                }
            }
            if (span[a].innerHTML == ""){
                span[a].appendChild(textnode);
            }
            if(countryWidget && (countryWidget.options[countryWidget.selectedIndex].value == "" || countryWidget.options[countryWidget.selectedIndex].value != "1")){
                $('select_state').addClassName('disabled');
                stateWidget.disabled = true;
            }
  		}
    },

    choose: function(link) {
        try{
            var option = link.getElementsByTagName("option");
            for(var d = 0; d < option.length; d++) {
                if(option[d].selected == true) {
                    var optionText = option[d].childNodes[0].nodeValue;
                    optionText = optionText.substr(0, count);
                    $("select_"+link.name).childNodes[0].nodeValue = optionText;
                }
            }
        } catch(e){

        }

    }
};