function smooth2Dialog(){
	// convert all the old smoothbox link to new smoothDialog system
	$$("a.smoothbox").each(function(item){
		href = item.get("href");
		params = href.parseQueryString();
		item.set("href",'#'+href);
		item.store("link",href);

		if(href.indexOf("TB_iframe")) {
			item.addEvent("click",function(){
				new MooDialog.Iframe(this.retrieve("link"),{
					title: item.get("title")||'Novonordisk',
					size: {
						width: params.width,
						height: params.height
					},
					onHide:function(){
						if(TB_RedirectUrl != "") window.location.href = TB_RedirectUrl;
					}
				});
			});
		}
	});	
}

/* FUNCTION TB_SHOW REPLACES THE SMOOTHBOX TB_SHOW ******************/
function TB_show(title,url){
	params = url.parseQueryString();
	new MooDialog.Iframe(url,{
		title: title,
		size: {
			width: params.width,
			height: params.height
		},
		onOpen:function(){
			this.wrapper.addClass("loading");
			this.wrapper.getElement("iframe").addEvent("load",function(){
				this.removeClass("loading");				  
			}.bind(this.wrapper));
		},
		onHide:function(){
			if(TB_RedirectUrl != "") window.location.href = TB_RedirectUrl;
		}
	});
}

function checkMessages(tbTitle,w,h){
	messageElement = $("messages");
	Rex = /[a-zA-Z0-9]/;
	if(messageElement &&  (messageElement.getChildren().length > 0 || messageElement.get("html").test(Rex) != "" ) ) {
		messageElement.MooDialog({
					onOpen:function(){
						$$("select").each(function(item){
							item.setStyle("visibility","hidden");
						});

					},					
					onHide:function(){
						$$("select").each(function(item){
							item.setStyle("visibility","visible");
						});
						if(TB_RedirectUrl != "") window.location.href = TB_RedirectUrl;
					},drag:true,title:tbTitle||'System message',size:{width:w||100,height:h||150}});
	}
}

function enableSBDrag(){
	if( (sb = $("TB_window")) && (handle = $("TB_title")) ) {
		new Drag.Move(sb,{'handle':handle});
		handle.addClass("draggable");
	}
}

function addHand(selector){
    $$(selector).each(function(item){
        if(!item.getElement('th')) item.addClass("hand");
        // IE6 BUGGY FIX
        if(Browser.Engine.trident && Browser.Engine.version == 4) {
            item.addEvent("mouseover",function(){
                item.addClass("hover");
            });
            item.addEvent("mouseout",function(){
                item.removeClass("hover");
            });
        }
    });
}
