function selectInput(param1, param2, param3, param4){
        $("#"+param1).html(param3);
        $("#"+param2).val(param4);
}

if (!JWMM) {
/**
 * @namespace global Juwi specific variables and functions
 *  
 */
    var JWMM = {
    mail: function (sTo, sSubject, sBody, sUrl) {
     		var swap = function (chr) {
    			switch(chr) {
    				case "´":
    				return "'";
    				return "%3F";
    				case "?":
    				return "%3F";
    				case "&":
    				return "%27";
    				case "=":
    				return "%3E";
    			}
    			return chr;
    		};
    		var encode = function (str) {
    			return (str).replace(/\?/g, function(match){return swap(match);});
    		};
    		var amp = "&";
    		var sUrl = sUrl || window.location.href;
    		var params = "subject=" + encode(sSubject) + amp + "body=" + encode(sBody) + encode(sUrl) + "\n\n";
    		
    		window.location = encodeURI("mailto:" + sTo + "?" + params);
    		return false;
    	},
    	mailto: function () {
    		return JWMM.mail(JWMM.mailTo, JWMM.mailSubject, JWMM.mailBody);
    	}
    };
}

function openWindow(url,width,height,scroll,name,anchor)
{
	//default scrollbars=no;
	if(scroll=='')
	{
		scroll = 'no';
	}	
	if(anchor!=null)
	{
		url = url+""+anchor;
	}
	
	popWindow = window.open(url,name,"toolbar=no,width="+width+",height="+height+",status=yes,scrollbars="+scroll+",resizable=no,menubar=no,dependent=no");
	popWindow.blur;
}

// does the user still have MSIE 6?
// TODO: do not user jQuery for that,
// because these properties are deprecated
var msie6 = $.browser.msie && $.browser.version < 7;
var msie7 = $.browser.msie && $.browser.version == 7;
var msie = $.browser.msie;
 
(function($) {

/**
 * replaceButtons()
 * replaces the button elements in result by <a> elements that are better stylable
 * and adds behaviors to them so they will be usable like 
 *
 */
$.fn.replaceButtons = function() {
	return this.each(function() {
		$(this).find("input[type='submit'], input[type='reset'], input[type='button'], button").each(function() {
			// find all buttons inside the matched elements		
			var t = $(this)
			if (t.attr("type") && t.attr("type").toLowerCase() == "reset") {
				t.attr("form").onreset = function () {
					$(".gui-select")._active = -1;
					/*
						TODO reset dropdowns
					*/
				}
			}
			// only replace visible buttons
			if (t.is(":visible") && !t.hasClass("dont-replace")) {
				// hide button and insert <a> tag after that is better stylable and add click behavior
				t.hide().after($('<a href="#" class="gui-btn ' + t.attr("class") +'"><span><span>' + t.val() + '</span></span></a>')
					.click(function() {
						if(t.attr("type").toLowerCase() == "submit") {
							t.parents("form").submit();
						} else {
							t.trigger("click");
						}
						if(msie6) {
							$(this).blur();
						}
						return false;
					}));
				}
		});
	});
};


// opens an url in a popup
$.createPopupWindow = function(options) {

	var settings = $.extend({
		url: null,
		width: 720,
		height: 487,
		center: true,
		
		scrollbars: true,
		resizable: false,
		toolbar: false,
		location: false,
		menubar: false,
		
		id: 'popup'
	}, options);
	
	var yn = function(val) { return (val == true ? "yes" : "no"); }; // shorthand function for converting a boolean value to yes and no
	
	// creating messy option string
	var optionString = "menubar=" + yn(settings.menubar) + ",location=" + yn(settings.location)
		+ ",toolbar=" + yn(settings.toolbar) + ",resizable=" + yn(settings.resizable)
		+ ",scrollbars=" + yn(settings.scrollbars)
		+ ",width=" + settings.width + ",height=" + settings.height;
	
	if (settings.center) {
		// if option is set, move window to center of screen
		var winLeft = (screen.width - settings.width)/2;
		var winTop = (screen.height - settings.height)/2;
		
		optionString += ",left=" + winLeft + ",top=" + winTop;
	}
	
	var w = window.open(settings.url, settings.id, optionString);
};

/**
 * openWithDisclaimer()
 *
 * Opens disclaimer in a lightbox-like modal overlay
 *
 */
openWithDisclaimer = function(urlToOpen,extUrl) {
	var extUrl = encodeURIComponent(extUrl);	
	
	// creating overlay for transparent background		
	var modal = $('<div class="modal-blackout" />').appendTo(document.body).css("opacity", 0);
	
	// ceating loader div, displaying laoding animation
	var loader = $('<div class="modal-loader" />').appendTo(document.body);
	
	// fade in modal
	modal.fadeTo(500, 0.4);
	
	// create popup and iframe elements
	// important: popup must use visibility: hidden; instead of display: none;
	// to make the size calculatable before showing popup
	var disclaimer = $('<div class="popup"><iframe frameborder="0" /></div>')
		.appendTo(document.body)
		.css("visibility", "hidden");
	var iframe = $("iframe", disclaimer);
	
	// closes popup with a smooth animation and removes
	// popup elements from the document
	var closeThisPopup = function() {
		modal.fadeOut(250, function() { $(this).remove(); });
		disclaimer.fadeOut(250, function() { $(this).remove(); });
		loader.remove();
	};
	
	// attach loading handler to iframe
	iframe.load(function() {
		
		// get iframe content for attaching link handlers
		var iframeContent = iframe.contents();
		
		// adjust iframe height to content length
		iframe.height($("body", iframeContent).outerHeight());
		
		// center on screen
		disclaimer.css("margin-top", disclaimer.outerHeight() / -2);
		
		// hide loader	
		loader.hide();
		
		// init OK and cancel buttons
		// cancel button must return false to avoid scrolling of
		// parent browser window to top
		$("#disclaimerCancel", iframeContent).click(function() {
			closeThisPopup();
			return false;
		});
		
		// disclaimer OK must not return false because otherwise
		// link would not be opened
		$("#disclaimerOk", iframeContent).click(function() {
			closeThisPopup();
		});
		
		// finally after all is set up, fade in the popup
		disclaimer.css("opacity", 0).css("visibility", "visible").fadeTo(250, 1);

	}).attr("src", urlToOpen + "&url=" + extUrl); // finally set src attribute of iframe to start loading process
	
	//return false; // don't follow disclaimer link
};	

})(jQuery);



jQuery(function($) {
	
	// init search field
	// when user focussed that field and it has it's default value, specified by a <label> element's text content
	// the field will be emptied. If user blurs field and it is empty, default value will be restored
	var defaultValue = $("#searchTermLabel").text();
	$("#searchTerm").val(defaultValue).focus(function() { if ($(this).val() == defaultValue) $(this).val(""); })
		.blur(function() { if ($(this).val() == "") $(this).val(defaultValue); });
		
	// initialize top navigation's smooth hover effect with "Get to know RebiSmart" and "I have a RebiSmart"
	$(".quicklinks li a.highlight").each(function() {
		$(this).removeClass("highlight").append($('<span class="hover" />').html($(this).text())).each(function() {
			var s = $(this).find("span.hover").css("opacity", 0)
			s.hover(function () { s.stop().fadeTo(500, 1); }, function () {	s.stop().fadeTo(500, 0); });			
		});	
	} );
	
	// init form elements on login page
	$("#loginForm label").hide().each(function() {
		var t = $(this);
		var defaultValue = t.html();
		
		var f = $("#" + t.attr("for"));
		
		
		// if field is a password
		if (f.attr("type") == "password") {
			
			var pwReplacement = null;
			
			// insert dummy field after password fiel, because we cant't change the type of a text field into password at runtime
			pwReplacement = f.after('<input type="text" class="' + f.attr("class") + '" />').next().val(defaultValue);
			pwReplacement.focus(function() {
				// when focussing dummy field hide it and focus real password field 
					$(this).hide();
					f.show().focus();
			});
			
			f.blur(function() {
				if ($(this).val() == "") {
					// when blurring password field, hide it and show dummy, if value is ampty
					$(this).hide();
					pwReplacement.show().val(defaultValue);
				} else {
					pwReplacement.hide();
				}
			}).blur();
		} else {
			// handling normal fields
			f.focus(function() {
				if ($(this).val() == defaultValue) {
					$(this).val("");
				}
			}).blur(function() {
				if ($(this).val() == "") {
					$(this).val(defaultValue);
				}
			}).blur();
		}
	});	
	
	// hide login button if JS is enabled
	$("#loginForm input[type=submit]").hide();
	$("#loginSubmit").click(function() {
		$("#loginForm form").submit();
		return false;
	});

	// init print link
	$("#printLink, #glossaryLink").click(function() { $.createPopupWindow({url: $(this).attr("href") }); return false; });
	
	if (msie6) {
//		$("#searchSubmit").hover(
//			function() { $(this).attr("id", "searchButton-msie6-hover"); },
//			function() { $(this).attr("id", "searchButton"); });
//		
		$(".bodySearch input.submit").hover(
			function() { $(this).addClass("submit-msie6-hover"); },
			function() { $(this).removeClass("submit-msie6-hover"); });
	}
	
	// replace buttons by better stylable <a> tags
	var b = $("body");
	if (b.attr("id") != "print") {
		$("#contentWrapper").replaceButtons();
	}
});
