ErmJS.Controls = {
    ColorButton: new Class({
        initialize: function(text,color,clickEvent) {
       
            if (typeof(text) == "object") {
                this.element = text.getParent();
                this.button = text;
                this.disabled = false;
                
                if(this.element.getElement("button").get("disabled") == true) {
                    this.setDisabled(true);

                }
                 
            } else {
                this.element = new Element("div");
                if (color == "orange") {
                    this.element.addClass("inlineblock newermbutton orangebutton");
                } else {
                    this.element.addClass("inlineblock newermbutton graybutton");
                }
                var button = new Element("button",{
                    html: text
                });
                if (clickEvent != null) button.addEvent("click",clickEvent);
                this.element.adopt(button);
            }
            this.originalClass = this.element.hasClass("orangebutton") ? "orangebutton" : "graybutton";
            
        },
		toElement: function() {
			return this.element;
		},
		setDisabled: function(TorF) {
		    if (TorF == false) {
		        //this.element.removeClass("graybutton");
		        this.element.removeClass("disabledbutton");
		        //this.element.addClass(this.originalClass);
		        this.element.setStyle("opacity",1);
		        if ($(document.body).hasClass("ie")) {
		            this.button.setStyle("opacity",1);
		        }
		    } else {
				//console.log(this.originalClass);
				//this.element.removeClass(this.originalClass);
                //this.element.addClass("graybutton");
		        
		        this.element.addClass("disabledbutton");
		        this.element.setStyle("opacity",0.25);
		        if ($(document.body).hasClass("ie")) {
		            this.button.setStyle("opacity",0.25);
		        }
		    }
		    this.disabled = TorF;
		    this.button.set("disabled",TorF);
		}
		
    }),
	ColorButtonLinkHTML: function(text,color,href,target) {
		var ret = "<div class='inlineblock newermbutton";
		if (color == "orange") {
			ret += " orangebutton";
		} else {
			ret += " graybutton";
		}
		ret += "'><a class='inlineblock' href='" + href + "'";
		if (target != null) {
			ret += " target='" + target + "'";
		}
		ret +=">" + text + "</a></div>";
		return ret;
	},
    alert: function(text, title, widthInt, closeFunction) {
        
        if ($(document.body).hasClass("ie")) {
            $$('iframe').setStyle("visibility","hidden");
        }
       
        this.alertWindow = new StickyWin.Modal({showNow: false});
        var content = new Element("div",{
			styles: {margin: "0px 30px"}
		});
        if ($defined(widthInt)) {
            this.alertWindow.setContent(StickyWin.ui(title,content, {
                width: widthInt
            }));
        
        } else {
            this.alertWindow.setContent(StickyWin.ui(title,content, {
                width: 500
            }));
        }
		var footer = new Element("div",
		{
			styles: {"text-align": "center"}
		});
		var closeAction = function(alertWindow) {
			alertWindow.hide();
			if (closeFunction != null) closeFunction.run();
			if ($(document.body).hasClass("ie")) {
                $$('iframe').setStyle("visibility","visible");
            }
		}.pass([this.alertWindow, closeFunction])
		
		content.set("html", "<p>" + text + "</p>")
		
        footer.adopt($(new ErmJS.Controls.ColorButton(captable[604],"orange",closeAction)));
		content.adopt(footer);
        this.alertWindow.show();
        this.alertWindow.pin();
    },
    confirm: function(args) {
        if (!$defined(args.okText)) {
            args.okText = captable[604];
        }
        if (!$defined(args.cancelText)) {
            args.cancelText = captable[341];
        }
        if (!$defined(args.title)) {
            args.title = "";
        }
        
    
        if ($(document.body).hasClass("ie")) {
            $$('iframe').setStyle("visibility","hidden");
        }
        var options = {
            showNow: false,
            closeOnClickOut: false,
            modalOptions: {
                hideOnClick:false
            }
        };
        
        this.alertWindow = new StickyWin.Modal(options);
        var content = new Element("div",{
			styles: {margin: "0px 30px"}
		});
        if ($defined(args.width)) {
            this.alertWindow.setContent(StickyWin.ui(args.title,content, {
                width: args.width,
                closeButton: false
            }));
        
        } else {
            this.alertWindow.setContent(StickyWin.ui(args.title,content, {
                width: 450,
                closeButton: false
            }));
        }
		var footer = new Element("div",
		{
			styles: {"text-align": "center"}
		});
		var closeAction = function() {
			this.hide();
			if ($(document.body).hasClass("ie")) {
                $$('iframe').setStyle("visibility","visible");
            }
		}.bind(this.alertWindow)
		if (args.text) {
		    content.set("html", "<p>" + args.text + "</p>");
		}
        else if (args.contentHolder) {
            //console.log(args.contentHolder.getChildren());
            content.adopt(args.contentHolder.getChildren());
        }
		 
		
		
		if (args.overrideOkDefault == true) var okButton = $(new ErmJS.Controls.ColorButton(args.okText,"orange",null));
		else var okButton = $(new ErmJS.Controls.ColorButton(args.okText,"orange",closeAction));;
		
		okButton.setStyle("margin-right","5px");
		
		if (args.overrideCancelDefault == true) var cancelButton = $(new ErmJS.Controls.ColorButton(args.cancelText,"gray",null));
		else var cancelButton = $(new ErmJS.Controls.ColorButton(args.cancelText,"gray",closeAction));
		
		
		if ($defined(args.okFunction)) {
		    okButton.addEvent("click",args.okFunction);
		}
		if ($defined(args.cancelFunction)) {
		    cancelButton.addEvent("click",args.cancelFunction);
		}
        footer.adopt([okButton,cancelButton]);
		content.adopt(footer);
        this.alertWindow.show();
        this.alertWindow.pin();
        return this.alertWindow;
    }
}
