
function AssoloSelect(id,myConfigs) 
{
	this.Configs = {
		items : ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
        mainDivClass : "assoloSelectMainDiv",
        itemsDivClass : "assoloSelectItem",
        itemsDivClassOver : "assoloSelectItem_over",
        maxHeight : false,
        maxWidth : false,
        afterSelectEvent: false
    };
	this.theInput = null;
    this.DivSelect = null;
	
	if (myConfigs) {
		if (isdefined(myConfigs.items))  this.Configs.items  = myConfigs.items;
		if (isdefined(myConfigs.mainDivClass))  this.Configs.mainDivClass  = myConfigs.mainDivClass;
		if (isdefined(myConfigs.itemsDivClass))  this.Configs.itemsDivClass  = myConfigs.itemsDivClass;
		if (isdefined(myConfigs.itemsDivClassOver))  this.Configs.itemsDivClassOver  = myConfigs.itemsDivClassOver;
		if (isdefined(myConfigs.maxHeight))  this.Configs.maxHeight = myConfigs.maxHeight;
		if (isdefined(myConfigs.maxWidth))  this.Configs.maxWidth = myConfigs.maxWidth;
		if (isdefined(myConfigs.afterSelectEvent))  this.Configs.afterSelectEvent = myConfigs.afterSelectEvent;
	}

	this.theInput = document.getElementById(id);
	if (this.theInput) {
        this.DivSelect = document.createElement("div");
        this.DivSelect.id = id + "_assoloselect";
        this.DivSelect.style.position = "absolute";
        this.DivSelect.className = this.Configs.mainDivClass;
        if (this.Configs.maxHeight && this.Configs.maxWidth) {
            this.DivSelect.style.height = this.Configs.maxHeight+"px";
            this.DivSelect.style.width = this.Configs.maxWidth+"px";
            this.DivSelect.style.overflow = "auto";
        }

        var oSelf = this;
        var el;
        for(var i in this.Configs.items) {
            el = document.createElement("div");
            el.innerHTML = this.Configs.items[i];
            el.className = this.Configs.itemsDivClass;
            el.onmouseover = function () { this.className = oSelf.Configs.itemsDivClassOver }
            el.onmouseout = function () { this.className = oSelf.Configs.itemsDivClass }
            el.onclick = function () { oSelf.SelectMe(this); }
            
            
            this.DivSelect.appendChild(el);
        }
        
        this.DivSelect.style.display = "none";
        this.theInput.parentNode.insertBefore(this.DivSelect, this.theInput.nextSibling); 
	
        function ShowMySelect() {
            oSelf.ShowSelect();
        }
        function HideMySelect() {
            oSelf.HideSelect();
        }
        
        try {
            this.theInput.addEventListener('focus', ShowMySelect, true);
        } catch(err) {
            this.theInput.attachEvent('onfocus', ShowMySelect );
        }
        
        try {
            this.theInput.addEventListener('blur', HideMySelect, true);
        } catch(err) {
            this.theInput.attachEvent('onblur', HideMySelect );
        }
        
	} else {
		alert("Errore interno: elemento "+id+" non trovato!");
	}
}

AssoloSelect.prototype.ShowSelect = function()
{
    var pos = GetXYWH(this.theInput);
    
    this.DivSelect.style.left = (pos[0])+"px";
    this.DivSelect.style.top = (pos[1]+pos[3])+"px";
    this.DivSelect.style.display = "inline";
}

AssoloSelect.prototype.HideSelect = function()
{
    var oSelf = this;
    setTimeout(function() { oSelf.DivSelect.style.display = "none"; }, 500);

    return true;
}

AssoloSelect.prototype.SelectMe = function(el)
{
    this.theInput.value = el.innerHTML;
    if (this.Configs.afterSelectEvent) {
        this.Configs.afterSelectEvent(this,el);
    }
}

