$(function() {
    $("#globalsearch").keypress(function(event) {
        if (event.keyCode == 13) {
            SearchFromGlobal();
            return false;
        }
    });
    $("#globalsearchbutton").click(function(event) {
        SearchFromGlobal();
        return false;
    });
    $(".removeDefaultInputValue").removeDefaultInputValue();
    $(".niceSelectOptions").niceGoToSelect();
    
    $("input.newssearch").keypress(function(event) {
        if (event.keyCode == 13) {
            searchNews();
            return false;
        }
    });    
    
});

function SearchFromGlobal() {
    var url = "/Soeg.aspx?";
    url += addToQs("q", $("#globalsearch").val());
    url = url.substr(0, url.length-1);
    window.location = url;
}

function addToQs(name, val) {
    if (val != "") {
        return name + "=" + encodeURIComponent(val) + "&";
    }
    return "";
}

(function($) {
    // plugin definition
    $.fn.niceGoToSelect = function() {
        return this.each(function() {
            var $this = $(this);
            if ($.browser.msie && $.browser.version.substr(0, 1) < 8) {
                $this.hover(
                    function() {
                        
                        $this.find(".niceSelectHiddenOptions").css("width", 280);
                        var height1 = $(".niceSelectHiddenOptions").height();
                        $this.find(".niceSelectHiddenOptions").css("margin-top", -24-height1).show();
                    },
				    function() {
				        
				        $this.find(".niceSelectHiddenOptions").hide();
				    }
				    );
            } else
                $this.hover(

				function() {				   
				    var height1 = $(".niceSelectHiddenOptions").height();
				    $this.find(".niceSelectHiddenOptions").css("margin-top", -24 - height1).show();
				},
				function() {
				    $this.find(".niceSelectHiddenOptions").hide();
				}
			);
        });
    }
})(jQuery);

$.fn.removeDefaultInputValue = function() {
	$(this).each(function(i){
		var obj = $(this);
		if (obj.val() != "") {
			obj.css('color', '#999999');
			if (obj.attr('title') == "") {
				obj.attr('title', obj.val());
			}
			$(this).bind("focus", function(event) {
					if (obj.val() == obj.attr('title')) {
							obj.val('');
							obj.css('color', '#000000');
					}
			}),
			$(this).bind("blur", function(event) {
					if (obj.val() == '' && obj.attr('stopInsertDefaultValue') != "true") {
							obj.val(obj.attr('title'));
							obj.css('color', '#999999');
					}
			});
			$(this).parents('form').bind("submit", function(event) {
					obj.attr('stopInsertDefaultValue', "true");
					if (obj.val() == obj.attr('title')) {
							obj.val('');
					}
			});
		}			
	});
  return this;
};