/**
 * Executed when document is finished loading elements into DOM
 */
$(document).ready(function() {

	var header_h = $("#header").height();

	$("#content").height($(window).height() - header_h);
	$(".content").height($(window).height() - $(".content").position().top);

	/**
	 * Display confirmation dialog whenever link
	 * with className "confirm" is slicked
	 */
	$(".confirm").click(function(){
		return confirm("Do you really want to continue?");
	});

  $('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top - header_h - 30;
        $('.content').animate({scrollTop: targetOffset}, 1000);
       return false;
      }
    }
  });

	$("#header #UserEmail").val("MAILADDRESSE").css("color", "#666");
	$("#header #UserPassword").val("        ").css("color", "#666");

	$("#header #UserEmail").focus(function(){
		if ($("#header #UserEmail").val() == "MAILADDRESSE") {
			$("#header #UserEmail").val("").css("color", "#000");
		}
	});
	$("#header #UserEmail").blur(function(){
		if ($("#header #UserEmail").val() == "") {
			$("#header #UserEmail").val("MAILADDRESSE").css("color", "#666");
		}
	});

	$("#header #UserPassword").focus(function(){
		if ($("#header #UserPassword").val() == "        ") {
			$("#header #UserPassword").val("").css("color", "#000")
		}
	});
	$("#header #UserPassword").blur(function(){
		if ($("#header #UserPassword").val() == "") {
			$("#header #UserPassword").val("        ").css("color", "#666")
		}
	});

	$('.pop').fancybox({
		//padding: 15
	});

});

/**
 * Print email link (protection from spambots)
 * If javascript is disabled, nothing is visible
 *
 * @param string p1 Part 1 - this is username
 * @param string p2 Part 2 - this is domain and TLD
 * @param string name (optional) Display value
 */
function writemail(p1, p2, name) {
	if (typeof(name) == "undefined") {
		name = p1+"@"+p2;
	}

	document.write("<a href='mailto:"+p1+"@"+p2+"'>"+name+"</a>");
}

/**
 *
 */
function readMore(id) {
	$("#text-"+id).slideToggle();
}

/**
 * Redirect user to specified page
 *
 * @param string url Address to redirect to
 */
function redirect(url) {
	document.location = url;
}


function applicationSubject(el) {
	if (el.value == "Training and further training" || el.value == "Aus-, und weiterbildung") {
		$("#documents").appendTo($(el).find("~ label").eq(0)).show();
	} else {
		$("#documents").hide();
	}
}