﻿var defaultValue = null;
function JSrot13(text) { var text = text.replace(/%/, "@"); var rot13text_rotated = ""; /* the function will return this string */; for (i = 1; i < (text.length + 1); i++) { k = text.charCodeAt(i - 1); if (k >= 97 && k <= 109) { k = k + 13; } else if (k >= 110 && k <= 122) { k = k - 13; } else if (k >= 65 && k <= 77) { k = k + 13; } else if (k >= 78 && k <= 90) { k = k - 13; } rot13text_rotated = rot13text_rotated + String.fromCharCode(k); } return rot13text_rotated; } function Securemail(maillink) { var maillink_output; maillink_output = JSrot13(maillink); location.href = 'mailto:' + maillink_output; } function displaymailaddress(linktext) { var linktext_output; linktext_output = JSrot13(linktext); linktext_output = linktext_output.replace(/@/, "<span style='display:none'> *secure E-Mailaddress* <\/span>@"); document.write(linktext_output); }
jQuery.noConflict();

function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};



jQuery(document).ready(function () {

    // counter for insert fields
    /*
    This function provides a text check on limited chars.

    it searches for a container ".additional_fields"

    */
    // default list format each second row for better visibility.
    jQuery("#accordion-categories .listbox:odd, .listbox-person:odd, .listbox-colored:odd, .listbox:odd").css("background", "#f6f6f6");
    jQuery(".additional_fields").each(function () {

        var This = jQuery(this);
        var charCounter = jQuery(".charCounter", this);

        if (charCounter.length != 0) {
            var MaxAllowedChars = charCounter.text();
            TextAreaToCheck = This.next().find("textarea:first");
            var OldValue = "";

            // set init value (used id edit form)
            this.CurrentCharsCount = TextAreaToCheck.val().length;
            charCounter.text(MaxAllowedChars - this.CurrentCharsCount);

            TextAreaToCheck.keyup(function () {
                reference = jQuery(this);
                CurrentCharsCount = jQuery(this).val().length;

                OldValue = reference.val();

                //console.log("max allowed: " + MaxAllowedChars.toString());
                //console.log("current: " + CurrentCharsCount.toString());

                if (CurrentCharsCount > MaxAllowedChars) {
                    reference.val(OldValue.substring(0, MaxAllowedChars));
                    This.addClass("warningstate");
                    return false;
                }
                else {
                    This.removeClass("warningstate");
                }

                charCounter.text(MaxAllowedChars - CurrentCharsCount);

            });
        }

    });


    /*var FieldsToCheck = jQuery(".additional_fields");

    charCounter = jQuery(".charCounter", this);
    TextAreaToCheck = FieldsToCheck.next().find("textarea");

    TextAreaToCheck.keypress(function () {

    console.log(charCounter.html());
    /*el = jQuery(this);
    charCounter = jQuery(".charCounter");
    maxAllowedChars = charCounter.val();
    oldValue = el.val().substring(0, el.val().length);
    chars = el.val().length;
    console.log("max chars: " + maxAllowedChars);

    if (chars >= 300) {
    console.log("über 2 oldvalue: " + oldValue);
    return false;
    }
    });*/




    // logon-box fade in
    jQuery("#plc_lt_zoneLogin_SignInButton_btnSignOutLink").click(function (event) {
        event.preventDefault();

        jQuery(".logon_box").slideToggle();
    });

    // logon-box trim username and password
    jQuery("#plc_lt_zoneLogin_CTIILoginBox_loginElem_btnLogon").click(function () {

        var strPassword = jQuery("#plc_lt_zoneLogin_CTIILoginBox_loginElem_Password").val();
        strPassword = jQuery.trim(strPassword);

        jQuery("#plc_lt_zoneLogin_CTIILoginBox_loginElem_Password").val(strPassword);
    });

    // remove FailureText from Logon-Box
    jQuery("#plc_lt_zoneLogin_CTIILoginBox_loginElem_FailureText").detach();

    // logon-box-left fade in
    jQuery("#plc_lt_SignInButton").click(function (event) {
        event.preventDefault();

        jQuery(".logon_box_left").slideToggle();
    });

    // remove FailureText from Logon-Box
    jQuery("#plc_lt_zoneContent_TemplateHolder_TemplateHolder_lt_ZoneLeft_CTIILoginBoxLeft_loginElem_FailureText").detach();

    jQuery(".podcastlink").hover(function () {
        var el = jQuery(this);
        linkUrl = el.attr("href");

        // playbutton
        playButton = jQuery(".playbutton:first");
        playButton.attr("href", linkUrl);
        playButton.attr("target", "_blank");
        playButton.fadeIn();

    });

    jQuery(".playbutton").mouseleave(function () {

        // playbutton
        playButton = jQuery(".playbutton:first");
        playButton.fadeOut();

    });


    // default values that disappear on focus

    var active_color = '#000'; // Colour of user provided text
    var inactive_color = '#000'; // Colour of default text

    function defaultValuedisappear(id) {
        jQuery(id).css("color", inactive_color);
        var default_values = new Array();
        jQuery(id).focus(function () {
            if (!default_values[this.id]) {
                default_values[this.id] = this.value;
            }
            if (this.value == default_values[this.id]) {
                this.value = '';
                this.style.color = active_color;
            }
            jQuery(this).blur(function () {
                if (this.value == '') {
                    this.style.color = inactive_color;
                    this.value = default_values[this.id];
                }
            });
        });
    };

    defaultValuedisappear("input.LogonField");
    defaultValuedisappear("input.SubscriptionTextbox");

    jQuery("input").enterToTab();
    var TabIndex = 0;

    jQuery(".eventpictures a[rel=gallery]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'type': 'image'
    });

    jQuery(".processpictures a[rel=gallery]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': true,
        'type': 'image'
    });

    jQuery(".tabs").each(function () {
        var Menue = ""
        jQuery(">h2", this).each(function () {
            element = jQuery(this);
            TabIndex++;
            Menue += "<li><a href='#tabs-" + TabIndex + "'>" + element.html() + "</a></li>";
            element.next(".content:first").attr("id", "tabs-" + TabIndex);
            element.remove();

        });
        jQuery(this).prepend("<ul>" + Menue + "</ul>");
    })

    jQuery(".tabs").tabs();

    jQuery("#podcast_tabs").tabs({
        ajaxOptions: {
            type: 'GET',
            error: function (xhr, status, index, anchor) {
                jQuery(anchor.hash).html(
						"Couldn't load this tab. We'll try to fix this as soon as possible. " +
						"If this wouldn't be a demo." + anchor);
            }
        }
    });

    jQuery("button, input:submit, input.button, a.button").button();

    jQuery("#toolsnav a:last").css({ "border": "none", "margin": "0", "padding": "0" });

    jQuery("#accordion-categories").accordion({
        //clearStyle: true,
        autoHeight: false,
        collapsible: true,
        active: false

    });
    jQuery("#accordion-categories-firstopen").accordion({
        autoHeight: false
    });
    jQuery(".formtable tr, .NewsletterSubscription table:first tr").each(function () {
        var e = jQuery(this);

        var label = e.find("td:first label");
        var input = e.find("td input:first, td textarea:first");

        labelHTML = label.html();
        if (labelHTML != null) {
            defaultValue = label.html().substring(0, labelHTML.length - 1);
            label.remove();
            input.DefaultValue(defaultValue);
        }
    });

    jQuery(".EditingFormErrorLabel").each(function () {
        var e = jQuery(this);
        elementsToFormat = e.parent().add(e.parent().prev()).add(e.parent().prev("label"));
        elementsToFormat.css({ "border-bottom": "solid 1px #c00000", "color": "#c00000" });

        e.hide();
        jQuery("html").scrollTop(0);
    });
	
	
	
	jQuery.get('/CMSPages/CTII/AjaxSponsorsScroller.aspx', function(data) {
		jQuery('#sponsorsbox').html(data);
		jQuery('#sponsors').jcarousel({
			scroll: 3,
			auto: 6,
			wrap: 'circular',
			easing: 'swing',
			initCallback: mycarousel_initCallback
		});
	});
	

});

//Formular Enter-Key abfangen
(function (jQuery) {
    jQuery.fn.enterToTab = function () {
        return this.each(function () {
            jQuery(this).bind('keypress', function (event) {
                if (event.keyCode == '13') {
                    event.preventDefault();
                    var list = jQuery(":focusable");
                    list.eq(list.index(this) + 1).focus().select();
                }
            });
        });
    }

    jQuery.extend(jQuery.expr[':'], {
        focusable: function (element) {
            var nodeName = element.nodeName.toLowerCase(),
                tabIndex = jQuery.attr(element, 'tabindex');
            return (/input|select|textarea|button|object/.test(nodeName)
                     ? !element.disabled
                    : 'a' == nodeName || 'area' == nodeName
                    ? element.href || !isNaN(tabIndex)
                    : !isNaN(tabIndex))
            // the element and all of its ancestors must be visible
            // the browser may report that the area is hidden
                    && !jQuery(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
        }
    });




})(jQuery);



jQuery.fn.DefaultValue = function (text) {

    return this.each(function () {
        //Make sure we're dealing with text-based form fields
        if (this.type != 'text' && this.type != 'password' && this.type != 'textarea')
            return;

        //Store field reference
        var fld_current = this;

        //Set value initially if none are specified
        if (this.value == '') {
            this.value = text;
        } else {			//Other value exists - ignore
            return;
        }

        // edited mi
        var thisElement = jQuery(this);
        //Remove values on focus
        thisElement.focus(function () {
            if (this.value == text || this.value == '')
                this.value = '';
        });
        //Place values back on blur
        thisElement.blur(function () {
            if (this.value == text || this.value == '')
                this.value = text;
        });
        //Capture parent form submission
        //Remove field values that are still default
        thisElement.parents("form").each(function () {
            //Bind parent form submit
            jQuery(this).submit(function () {
                if (fld_current.value == text) {
                    fld_current.value = '';

                }
            });
        });
    });
};


