
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 mailto(url){
        var myUrl = escape(url);
        parent.location.href="mailto:Your%20Contact%20Address?subject=Link-Tip&body=This%20page%20can%20be%20of%20interest%20to%20you.%20To%20view%20the%20page,%20click here:%0d%0a%0d%0a" + myUrl+ "%0d%0a%0d%0a%0d%0aIf the link doesn't work, try copying and pasting it into your browser's address bar.";
}

function openWindow(url,width,height,scroll,name,anchor)
{ 
	if(name==undefined){
		name='';
	}else{
		name = name.replace(/\s/g,"");
	}
	//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;
}



//FAQ Print

function openFaqPrintWindow(p){
    var printFaq = $("#printFaq").val();
    window.open(p+printFaq,'Printview',"toolbar=no,width=745,height=500,status=yes,scrollbars=yes,resizable=no,menubar=no,dependent=no");
}

function bookmark(){
   
      if (!document.all){
    	  if($("#bookmark").length > 0){
    		  $("#bookmark").css({display: "none"});
          }
          
          if($("#gwtbookmark").length > 0){
        	  $("#gwtbookmark").css({display: "none"});
          }
          
          return;
      }
}

/*
 * jQuery i18n plugin
 * @requires jQuery v1.1 or later
 *
 * Examples at: http://recurser.com/articles/2008/02/21/jquery-i18n-translation-plugin/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Based on 'javascript i18n that almost doesn't suck' by markos
 * http://markos.gaivo.net/blog/?p=100
 *
 * Revision: $Id$
 * Version: 1.0.0  Feb-10-2008
 */
 (function($) {
/**
 * i18n provides a mechanism for translating strings using a jscript dictionary.
 *
 */
	var i18n_dict = {};

/*
 * i18n property list
 */
$.i18n = {
	
/**
 * setDictionary()
 * Initialise the dictionary and translate nodes
 *
 * @param property_list i18n_dict : The dictionary to use for translation
 */
	setDictionary: function(i18n_dict_param) {
		i18n_dict = i18n_dict_param;
	},
	
/**
 * _()
 * The actual translation function. Looks the given string up in the 
 * dictionary and returns the translation if one exists. If a translation 
 * is not found, returns the original word
 *
 * @param string str : The string to translate 
 * @param property_list params : params for using printf() on the string
 * @return string : Translated word
 *
 */
	_: function (str, params) {
		var transl = str;
		if (i18n_dict && i18n_dict[str]) {
			transl = i18n_dict[str];
		}
		return this.printf(transl, params);
	},
	
/**
 * toEntity()
 * Change non-ASCII characters to entity representation 
 *
 * @param string str : The string to transform
 * @return string result : Original string with non-ASCII content converted to entities
 *
 */
	toEntity: function (str) {
		var result = '';
		for (var i=0;i<str.length; i++) {
			if (str.charCodeAt(i) > 128)
				result += "&#"+str.charCodeAt(i)+";";
			else
				result += str.charAt(i);
		}
		return result;
	},
	
/**
 * stripStr()
 *
 * @param string str : The string to strip
 * @return string result : Stripped string
 *
 */
 	stripStr: function(str) {
		return str.replace(/^\s*/, "").replace(/\s*$/, "");
	},
	
/**
 * stripStrML()
 *
 * @param string str : The multi-line string to strip
 * @return string result : Stripped string
 *
 */
	stripStrML: function(str) {
		// Split because m flag doesn't exist before JS1.5 and we need to
		// strip newlines anyway
		var parts = str.split('\n');
		for (var i=0; i<parts.length; i++)
			parts[i] = stripStr(parts[i]);
	
		// Don't join with empty strings, because it "concats" words
		// And strip again
		return stripStr(parts.join(" "));
	},

/*
 * printf()
 * C-printf like function, which substitutes %s with parameters
 * given in list. %%s is used to escape %s.
 *
 * Doesn't work in IE5.0 (splice)
 *
 * @param string S : string to perform printf on.
 * @param string L : Array of arguments for printf()
 */
	printf: function(S, L) {
		if (!L) return S;

		var nS = "";
		var tS = S.split("%s");

		for(var i=0; i<L.length; i++) {
			if (tS[i].lastIndexOf('%') == tS[i].length-1 && i != L.length-1)
				tS[i] += "s"+tS.splice(i+1,1)[0];
			nS += tS[i] + L[i];
		}
		return nS + tS[tS.length-1];
	}

};

})(jQuery);

(function($) {


// 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);
};



// replace the buttons by link elements for eye-candy
$.fn.replaceButtons = function() {
	var msie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
	return this.each(function() {
		$(this).find("input[type='submit'], input[type='reset'], input[type='button'], ").each(function() {
			var t = $(this)
			t.hide().after($('<a href="#" class="gui-btn"><span><span>' + t.val() + '</span></span></a>').click(function() { t.trigger("click"); if(msie6) { $(this).blur(); }; return false; }));
		});
	});
};

$.fn.initTabs = function() {
	var tabs = $(".tabs", this);
	var contents = $(".tabContents", this);

	var tabLinks = $("a", tabs).click(function() {
		$("a", tabs).removeClass("active");
		
		var href = $(this).addClass("active").attr("href");
		
		$(".innerTabContents > div", contents).hide();
		$(href).show();
		
		return false;
	});
	
	tabLinks.filter(".active").click();
	
	return this;
};


// initialize faq lists
$.fn.faqList = function(options) {
	
	var settings = $.extend({
		questionTags: "dt", // any jQuery selector possible, you can also use span.question, div.title, etc.
		answerTags: "dd",
		animationSpeed: 400
	}, options);


	this.each(function(i, v) {
		var l = $(this);
		var answers = l.find(settings.answerTags).hide();
		
		l.find(settings.questionTags).each(function(i, v) {
			$(this).wrapInner("<a href='#'></a>").find("> a").click(function() {
			    $("#printFaq").val($(this).parent(":first").next().attr("id"));
				l.find(settings.answerTags + ":visible").slideUp(settings.animationSpeed);
				l.find(settings.questionTags + " > a.open").removeClass("open").addClass("closed");
				if (!answers.eq(i).is(":visible")) {
					$(this).removeClass("closed").addClass("open");
					answers.eq(i).slideDown(settings.animationSpeed);
				}
				return false;
			}).addClass("closed");
		});
		
        $("dd[class^=activeItem]").show();
        $("dd[class^=activeItem]").prev("dt:first").children(".closed").addClass("open").removeClass("closed");
	});
};

/**
 * openModalWindow()
 *
 * Display message in a lightbox-like modal overlay
 *
 */
$.JMMShowMessage = function(message, title) {
	
	// creating overlay for transparent background		
	var modal = $('<div class="modal-blackout" />').appendTo(document.body).css("opacity", 0);
	if ($.browser.msie && $.browser.version < 7) {
		$('<iframe frameborder="0" />').appendTo(modal);
	}
	
	
	// important: popup must use visibility: hidden; instead of display: none;
	// to make the size calculatable before showing popup
	var popup = $('<div class="modalPopup"><div class="popup-title" /><div class="popup-content" />'
			+ '<div class="popup-controls"><a href="#" class="gui-btn close-this-popup"><span><span>' + $.i18n._("js.closeWindow") + '</span></span></a></div></div>')
		.appendTo(document.body)
		.css("visibility", "hidden");
	
	// closes popup with a smooth animation and removes
	// popup elements from the document
	var closeThisPopup = function() {
		modal.fadeOut(250, function() { $(this).remove(); });
		popup.fadeOut(250, function() { $(this).remove(); });
	};
	
	$("a.close-this-popup", popup).click(closeThisPopup);
	
	$(".popup-title", popup).html(title != undefined ? title : "");
	$(".popup-content", popup).html(message);
	
	// fade in modal
	modal.fadeTo(500, 0.4, function() { popup.css("visibility", "visible"); });
};

})(jQuery);

jQuery(function($) {

	// set dictionary for i18n
	// dictionary variable has to be declared before loading this file in global namespace
	if (typeof dictionary != "undefined") {
		$.i18n.setDictionary(dictionary);
	}

	// 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 = $("#leftColSearchLabel").text();
	$("#leftColSearch").val(defaultValue).focus(function() { if ($(this).val() == defaultValue) $(this).val(""); })
		.blur(function() { if ($(this).val() == "") $(this).val(defaultValue); });
	
	// faq lists
	$("#faq").initTabs().find(".tabContents > div").faqList();	
	
	/*$("#finder table tbody tr.entry").each(function() {
		var t = $(this).addClass("closed");
		var d = t.next().hide();
		var dd = d.find("td > div").hide();
		t.find(".title a, .category a").click(function() {
			if (d.is(":visible")) {
				dd.slideUp(250, function() { d.hide(); });
				t.removeClass("open").addClass("closed");
			} else {
				d.show();
				dd.slideDown();
				t.removeClass("closed").addClass("open");
			}
			
			return false;
		});
	});*/
	
	// beautify buttons
	$("#main").replaceButtons();
	
	// language selector
	$("#selectLanguage").change(function() {
		window.location.href = $(this).val();
	});
	
});

$(document).ready(function() {
	
	if($('#mailTo').length > 0 ){
		$('#mailTo').click(function(e){
			e.stopPropagation();
			return JWMM.mailto();
		});
	};
	
	$('textarea').each(function(){
		var $this = $(this);
		if ($this.val().match(/^\s/) != null) {
			$this.val("");
		}
	}); 
	
});

