/// <reference path="../jquery-1.4.2.min.js" />
/// <reference path="../Cufon/cufon-yui.js" />

/* MENU FUNCTIONS */

var $j = jQuery.noConflict();

$j(document).ready(function () {

    adjustFooterHeight();

    $j(".infoBox").each(function (index, obj) {

        var infoBubble;

        $j(obj).hover(function () {

            var offset;

            if (($j(obj).offset().left + 255 > $j(window).width()) || ($j(obj).attr("contact") == "true")) {
                infoBubble = $j("#infoBubbleLeft");
                offset = $j(obj).offset().left - infoBubble.width();
            }
            else {
                infoBubble = $j("#infoBubbleRight");
                offset = $j(obj).offset().left + $j(obj).width() + 5;
            }

            if ($j(obj).attr("info").length) {
                infoBubble.find(".textCell").html($j(obj).attr("info"));
            }
            else {
                infoBubble.find(".textCell").html($j("#" + $j(obj).attr("textCarrierID")).html());
            }

            infoBubble.css({
                "top": $j(obj).offset().top + ($j(obj).height() / 2),
                "left": offset
            });

            infoBubble.show();

            infoBubble.find(".dritteReiheRechts").height(0);
            infoBubble.find(".dritteReiheLinks").height(0);

            infoBubble.find(".dritteReiheLinks").height(infoBubble.find(".textCell").height() - 46);
            infoBubble.find(".dritteReiheRechts").height(infoBubble.find(".textCell").height() - 46);
        }, function () {
            infoBubble.hide();
            infoBubble.find(".dritteReiheRechts").height(0);
            infoBubble.find(".dritteReiheLinks").height(0);
        });
    });

    $j("div.prodSelCat div").click(function () {

        if (!$j("body").hasClass("nofooterSitemap")) {
            $j("div.prodSelCat div").each(function () {
                $j(this).removeClass("selected");
            });
            $j(this).addClass("selected");

            Cufon.refresh();
        }

    });

    $j(document).ready(function () {

        $j("span.hoverWrapper > a").each(function () {
            $j(this).next().css('height', $j(this).next().outerHeight());
            $j(this).next().hide();
            var leftPosition = ($j(this).position().left - 3) + "px";
            $j("div#" + "submenu-" + $j(this).attr("id")).css("left", leftPosition);
        });

    });

    var closeTimeout = false;
    var closeMenuTimeout;

    $j("span.hoverWrapper").hover(
        function () {
            if ($j("a", $j(this)).next("div.hoverMenu").length) {
                if ($j("div.hoverMenu:visible").length) {
                    window.clearTimeout(closeMenuTimeout);
                    closeTimeout = false;
                    closeMenu($j("div.hoverMenu:visible").not($j("div.hoverMenu:visible", $j(this))));
                }
                //                        window.clearTimeout(closeTimeout);

                //            $j("span.hoverWrapper").bind("mouseleave", function () {
                //                alert('');
                //            });

                if (!closeTimeout) {
                    //closeMenu($j("div.hoverMenu").not($j(this)));

                    var hoverMenu = $j("div.hoverMenu", $j(this));

                    hoverMenu
                .stop(true, true)
                .animate({
                    height: "show"
                },
                    {
                        duration: 500,
                        easing: "easeOutExpo",
                        queue: false
                    }
                );
                }
            }
        },
        function () {
            if ($j("a", $j(this)).next("div.hoverMenu").length) {
                if (!closeTimeout) {

                    closeTimeout = true;

                    var hoverMenu = $j("div.hoverMenu", $j(this));
                    closeMenuTimeout = window.setTimeout(function () {
                        closeMenu(hoverMenu);
                    }, 1000);
                }
            }
        });

    var closeMenu = function (hoverMenu) {

        hoverMenu
            .stop(true, true)
            .animate({
                height: "hide"
            },
                {
                    duration: 500,
                    easing: "easeOutExpo",
                    queue: false,
                    complete: function () {
                        closeTimeout = false;
                    }
                }
            );
    }

    $j("img#modalCloseButton").click(function () {

        $j("div#modalDialog").fadeOut("fast");

    });

    $j("div#slItemBox > div").mouseenter(function () {

        var headline = $j(this).attr('headline');
        var tooltip = $j(this).attr('tooltip');

        if ($j("body").hasClass("nofooterSitemap")) {
            var offset = $j(this).offset().left - ($j("div#tooltip").width() / 2);
        }
        else {
            var offset = $j(this).position().left + $j(".PlusSlider").position().left;
        }



        if (tooltip.length > 0) {

            //$j("div#tooltipContent").children().remove();                       
            $j("div#tooltip").css("opacity", "0");
            $j("div#tooltipContent").html(tooltip);

            var title = $j("<div class='botonWhite' />").html(headline);
            $j("div#tooltipContent").prepend(title);

            Cufon.refresh('.botonWhite');

            $j("div#tooltip").css({
                "left": ($j(this).width() / 2) + offset,
                "top": $j("#svcSliderCtr").position().top - $j("div#tooltip").height() + 80
            });

            $j("div#tooltip").fadeIn();

            $j("div#tooltip").stop().animate({
                top: "-=20px",
                opacity: 1
            }, 250);


        }

    }).mouseleave(function () {

        $j("div#tooltip").css("opacity", "1")
            .stop()
            .animate({
                top: "-=30px",
                opacity: 0
            }, 250,
            function () {
                $j("div#tooltip").hide();
            });

    });

    $j("div.GlossaryContainer .trenner:last").remove()

});

var showFootnote = function (number, text) {

    $j("div#footnote").children().remove();

    var element = $j("<div />");
    element.text(number + ") " + text);

    $j("div#footnote").append(element);

    $j("div#modalDialog").css("height", $j(document).height());
    $j("div#modalDialog").fadeIn("fast");
}

var handleContentHeight = function () {
    var sidebarSliderheight = $j(".sidebarSlider").outerHeight();
    var mainContentContainer = $j("#mainContent");
    var contentContainer = $j(".contentWide700");
    var rightBoxContainer = $j("#rightInfoBox");
    var rightBoxContainerHeight = rightBoxContainer.outerHeight();
    var callbackBoxContainer = $j("#rightCallbackBox");
    var callbackBoxContainerHeight = callbackBoxContainer.outerHeight();
    var hollydaycontainerHeight = $j("#hollyday").outerHeight();
    var buffer = 0;

    if (callbackBoxContainerHeight > 0) {
        buffer = 130;
    }
    if (hollydaycontainerHeight > 0 && callbackBoxContainerHeight == null) {
        buffer += 75;
    }

    if (mainContentContainer.length > 0 && rightBoxContainerHeight + callbackBoxContainerHeight + hollydaycontainerHeight > mainContentContainer.outerHeight()) {
        mainContentContainer.css("min-height", rightBoxContainer.outerHeight() + callbackBoxContainer.outerHeight() + hollydaycontainerHeight + buffer);
    }

    if (contentContainer.length > 0 && rightBoxContainerHeight + callbackBoxContainerHeight + hollydaycontainerHeight > contentContainer.outerHeight()) {
        var newContentMinHeight = rightBoxContainerHeight + callbackBoxContainerHeight;
        if (newContentMinHeight < 600 && $j(".ShoppingCart").length)
            newContentMinHeight = 600;
        if (sidebarSliderheight > 0) {
            newContentMinHeight -= sidebarSliderheight / 2;
        }
        contentContainer.css("min-height", newContentMinHeight + buffer);
    }
    callbackBoxContainer.css("margin-top", rightBoxContainerHeight / 3 + 10);
}
$j(document).ready(function () {
    handleContentHeight();
});

var handlePressItems = function () {
    $j(".pageWrap").each(function () {

        //window.console.log('new');
        var wrap = $j(this);
        var x = 0;
        var z = 0;


        var pressItemList = $j(".pressItem", wrap);
        pressItemList.each(function (index, value) {

            if (index == 0) {
                var wrapItems = $j("<div class='pageItem' />");
                wrapItems.appendTo($j(".pressSlider", wrap));
            }

            var divWrap = $j(".pageItem", wrap).get(z);

            if (x <= 3) {
                $j(this).appendTo(divWrap);

                x++;

                if ((x >= 4) && (pressItemList.length - 1 > index)) {
                    x = 0;
                    z++;
                    var wrapItems = $j("<div class='pageItem' />");
                    wrapItems.appendTo($j(".pressSlider", wrap));
                }
            }
        });
    });
}

var handleVWCoupons = function () {
    $j(".vwItem6").each(function () {

        //window.console.log('new');
        var wrap = $j(this);
        var x = 0;
        var z = 0;


        var pressItemList = $j(".vwSliderItem", wrap);
        pressItemList.each(function (index, value) {

            if (index == 0) {
                var wrapItems = $j("<div class='pageItem' />");
                wrapItems.appendTo($j(".vwSlider", wrap));
            }

            var divWrap = $j(".pageItem", wrap).get(z);

            if (x <= 5) {
                $j(this).appendTo(divWrap);

                x++;

                if ((x >= 6) && (pressItemList.length - 1 > index)) {
                    x = 0;
                    z++;
                    var wrapItems = $j("<div class='pageItem' />");
                    wrapItems.appendTo($j(".vwSlider", wrap));
                }
            }
        });
    });
}

var handleFAQ = function (activeFAQ) {

    $j(activeFAQ).click();

}


/* Service Area */
$j(document).ready(function () {

    var firstlevel = null;
    var secondlevel = null;
    var question = null;
    var faq = null;

    /* Show Subcategories  */
    $j(".list_faq .firstlevel > a.botonBold").click(function () {
        var current = $j(this);

        if (firstlevel != null) {
            if ($j(firstlevel).text() != $j(current).text()) {
                firstlevel.parent().children(".secondlevel").slideToggle();

                firstlevel.toggleClass("arrowBlue");
                firstlevel.toggleClass("arrowBlackBottom");

                if (secondlevel != null) {
                    secondlevel.parent().children(".questions").slideToggle();

                    secondlevel.toggleClass("arrowBlue");
                    secondlevel.toggleClass("arrowBlackBottom");

                    secondlevel = null;
                }
            }
        }


        if (current.parent().children(".secondlevel").length > 0) {
            current.parent().children(".secondlevel").slideToggle();
            if (current.parent().children(".secondlevel").children().text = '') {
                current.parent().children(".secondlevel").children().children(".questions").slideToggle();
            }
        }

        current.toggleClass("arrowBlue");
        current.toggleClass("arrowBlackBottom");
        Cufon.refresh();

        if (current.hasClass("arrowBlackBottom")) {
            firstlevel = current;
        }
        else {
            firstlevel = null;

            if (secondlevel != null) {
                secondlevel.parent().children(".questions").slideToggle();

                secondlevel.toggleClass("arrowBlue");
                secondlevel.toggleClass("arrowBlackBottom");

                secondlevel = null;
            }
        }


    });
    /* Show Questions */
    $j(".secondlevel li > a.boton").click(function () {
        var current = $j(this);

        if (secondlevel != null) {
            if ($j(secondlevel).text() != $j(current).text()) {
                secondlevel.parent().children(".questions").slideToggle();

                secondlevel.toggleClass("arrowBlue");
                secondlevel.toggleClass("arrowBlackBottom");

                if (question != null) {
                    question.parent().children(".answers").slideToggle();

                    question.toggleClass("arrowBlue");
                    question.toggleClass("arrowBlackBottom");
                    question.toggleClass("open");

                    question = null;
                }
            }
        }


        current.parent().children(".questions").slideToggle();

        current.toggleClass("arrowBlue");
        current.toggleClass("arrowBlackBottom");
        Cufon.refresh();

        if (current.hasClass("arrowBlackBottom")) {
            secondlevel = current;
        }
        else {
            secondlevel = null;

            if (question != null) {
                question.parent().children(".answers").slideToggle();

                question.toggleClass("arrowBlue");
                question.toggleClass("arrowBlackBottom");
                question.toggleClass("open");

                question = null;
            }
        }
    });
    /* Show Answers */
    $j(".questions li > a").click(function () {
        var current = $j(this);

        if (question != null) {
            if ($j(question).text() != $j(current).text()) {
                question.parent().children(".answers").slideToggle();

                question.toggleClass("arrowBlue");
                question.toggleClass("arrowBlackBottom");
                question.toggleClass("open");
            }

        }
        current.parent().children(".answers").slideToggle();

        current.toggleClass("arrowBlue");
        current.toggleClass("arrowBlackBottom");
        current.toggleClass("open");
        Cufon.refresh();

        if (current.hasClass("arrowBlackBottom")) {
            question = current;
        }
        else {
            question = null;
        }

    });

    /* Show Answers in Service Top Items */
    $j(".faqTitel a").click(function () {
        var current = $j(this);

        if (faq != null) {
            if ($j(faq).text() != $j(current).text()) {
                faq.parent(".faqTitel").next(".faqText").slideToggle();

                faq.toggleClass("arrowBlue");
                faq.toggleClass("arrowBlackBottom");
            }
        }
        current.parent(".faqTitel").next(".faqText").slideToggle();


        current.toggleClass("arrowBlue");
        current.toggleClass("arrowBlackBottom");
        Cufon.refresh();

        if (current.hasClass("arrowBlackBottom")) {
            faq = current;
        }
        else {
            faq = null;
        }
    });

    /* Checkboxen Shop CustomerDataSteps */
    var checkboxes = $j(".CheckBoxInput", ".checkbox");
    var cb_checked = "/Images/Website/checkbox/checkbox_aktiv_gruen.png";
    var cb_unchecked = "/Images/Website/checkbox/checkbox.png";

    $j(".checkbox .CheckBoxInput").each(function () {
        var currCbInput = $j(this);
        var isChecked = ((currCbInput.attr("checked") == "checked") || (currCbInput.attr("checked") == true));

        if (isChecked)
            $j(".CheckBoxImage", currCbInput.parents(".checkbox")).attr("src", cb_checked);
    });
    $j(".checkbox .CheckBoxImage").click(HandleCheckboxClick);
    $j(".checkbox .ClickableText a").click(function (e) {
        window.open($j(this).attr("href"));
        e.preventDefault();
        e.stopPropagation();
    });
    $j(".checkbox .ClickableText").click(HandleCheckboxClick);

    function HandleCheckboxClick() {
        // Prevent from executing disabled steps.
        // [MB]
        if (CustomerStepIsDisabled($j(this)))
            return;

        var current = $j(this);

        if (current.attr('aria-disabled') == 'true')
            return;

        var currentParent = current.parents(".checkbox");
        var currentInput = $j(".CheckBoxInput", currentParent);
        // Hack, because ASP.NET generates spans around the checkboxes.
        if (currentInput.attr("id") != "#CbWs_TComContractExist_false" && currentInput.attr("id") != "#CbWs_TComContractExist_true") {

            if (currentInput.length > 0) {
                if (currentInput[0].tagName.toLowerCase() != "input") {
                    currentInput = $j("input", currentInput);
                }
            }

            var currentImage = $j(".CheckBoxImage", currentParent);
            // Negotiate to allow null values.
            // [MB]
            var switchToChecked = !currentInput.hasClass("CbChecked");

            if (switchToChecked) {
                currentInput.removeClass("CbUnchecked");
                currentInput.addClass("CbChecked");
                currentInput.attr("checked", "checked");
                currentImage.attr("src", cb_checked);
            }
            else {
                currentInput.removeClass("CbChecked");
                currentInput.addClass("CbUnchecked");
                currentInput.removeAttr("checked");
                currentImage.attr("src", cb_unchecked);
            }
        }
        //currentInput.trigger('click');

    }


    /* RadioButtons Shop CustomerDataSteps */
    $j(".radio .RbImage").click(HandleRadioButtonClick);
    $j(".radio .RbClickableText").click(HandleRadioButtonClick);

    function HandleRadioButtonClick() {

        if (CustomerStepIsDisabled($j(this)))
            return;

        var rb_checked = "/Images/Website/radiobutton/radiobutton_aktiv_gruen.png";
        var rb_unchecked = "/Images/Website/radiobutton/radiobutton.png";
        var cb_checked = "/Images/Website/checkbox/checkbox_aktiv_gruen.png";
        var cb_unchecked = "/Images/Website/checkbox/checkbox.png";
        var current = $j(this);

        if (current.attr('aria-disabled') == 'true')
            return;


        var currentRadioButton = current.parents(".radio");
        var currentGroup = current.parents(".RadioButtonGroup");

        var currentInput = $j(".RbInput", currentRadioButton);
        var currentImage = $j(".RbImage", currentRadioButton);
        var groupInputs = $j(".RbInput", currentGroup);
        var groupImages = $j(".RbImage", currentGroup);

        if (currentInput.hasClass("RbCheckbox")) {
            if (currentInput.attr("checked") == "checked" || currentInput.attr("checked") == true) {
                currentImage.attr("src", cb_unchecked);
                currentInput.removeAttr("checked");
                currentInput.removeClass("RbChecked");
                currentInput.addClass("RbUnchecked");
            }
            else {
                groupImages.attr("src", cb_unchecked);
                groupInputs.removeAttr("checked");
                if (groupInputs.hasClass("RbChecked")) {
                    groupInputs.removeClass("RbChecked");
                    groupInputs.addClass("RbUnchecked");
                }
                currentImage.attr("src", cb_checked);
                currentInput.attr("checked", "checked");
                currentInput.removeClass("RbUnchecked");
                currentInput.addClass("RbChecked");
            }
        }
        else {

            groupImages.attr("src", rb_unchecked);
            groupInputs.removeAttr("checked");
            if (groupInputs.hasClass("RbChecked")) {
                groupInputs.removeClass("RbChecked");
                groupInputs.addClass("RbUnchecked");
            }
            currentImage.attr("src", rb_checked);
            currentInput.attr("checked", "checked");
            currentInput.removeClass("RbUnchecked");
            currentInput.addClass("RbChecked");
        }
    }


});

function CustomerStepIsDisabled(elementInStep) {
    return elementInStep.parents(".customerStep").hasClass("txt_silver");
}

//[FK] bookmarking function
function bookmarkTele2() {
    var title = '';
    if (document.title != '') {
        title = document.title;
    }
    else {
        title = 'Tele2 Deutschland'
    }

    //browsers

    if (window.sidebar) {
        window.sidebar.addPanel(title, window.location, "");
    }
    else if (window.external) {
        window.external.AddFavorite(window.location, title);
    }
    else if (window.opera && window.print) {
        window.external.AddFavorite(window.location, title);

    }
    else {
        alert('Bitte drücken Sie STRG + D, um ' + title + ' Ihren Favoriten hinzuzufügen.');
    }
}

function omniture() {
    if (window.pageName != null && window.pageName != "") {
        s_objectID = pageName + "." + $j(this).attr("sObjId");

    }
    else {
        s_objectID = $j(this).attr("sObjId");
    }

    //console.log("storing " + s_objectID);

    //Enable for testing [BH]
    //alert(s_objectID);
}

// Set Omniture Clicks (s_ObjectID) [SC]
$j(document).ready(function () {
    $j("*[sObjId], *[sobjid]").unbind("click");
    $j("*[sObjId], *[sobjid]").click(omniture);
});


function adjustFooterHeight() {
    var h_footer = $j('#footer').outerHeight(true);
    $j('#siteCtr').css('padding-bottom', h_footer + 20);
}

function slowConnection() {

    var viewport_h = $j(document).height();
    var modal_h = $j('#SpeedCheckBox').height();

    // include for speedcheck ... if (document.cookie.indexOf("speedcheck") < 0) {
    //
    if (document.cookie.indexOf("speedcheck") < 0) {

        var oldName = s.pageName;
        s.pageName = "Ws.SpeedCheck";
        var s_code = s.t(); if (s_code) document.write(s_code);
        s.pageName = oldName;

        $j('#SpeedCheckOverlay').css('display', 'block');
        popUnder("/Extras/PopUps/Schneckentempo.aspx?popup=1");
        setSCCookie();
    }
}

function setSCCookie() {
    var datum = new Date();
    var oneDay = datum.getTime() + (24 * 60 * 60 * 1000);
    var halfDay = datum.getTime() + (12 * 60 * 60 * 1000);
    datum.setTime(halfDay);
    document.cookie = "speedcheck=checked; expires=" + datum.toGMTString();
}

function deleteSCCookie() {
    document.cookie = 'speedcheck=checked; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function popUnder(url) {
    newwindow = window.open(url, "TELE2", 'width=650,height=650,left=0,top=0');
    if (newwindow != null) {
        newwindow.blur();
        window.focus();
    }
    else {
        $j('#SpeedCheckOverlay .closeThis').click(function () {
            newWin = window.open(url, "TELE2", 'width=650,height=650,left=0,top=0');
        }, function () {
            newWin.blur();
            window.focus();
        });
    }

}

/* SPEED CHECK */

var SpeedTest = function () {
    /*
    From:  http://techallica.com/kilo-bytes-per-second-vs-kilo-bits-per-second-kbps-vs-kbps/
    256 kbps            31.3 KBps
    384 kbps            46.9 KBps
    512 kbps            62.5 KBps
    768 kbps            93.8 KBps
    1 mbps ~ 1000kbps   122.1 KBps
    */
};
SpeedTest.prototype = { imgUrl: "/Images/Website/SpeedCheck/52kb.png", size: 53955, run: function (options) {
    if (options && options.onStart)
        options.onStart();

    var imgUrl = this.imgUrl + "?r=" + Math.random();
    this.startTime = (new Date()).getTime();

    var testImage = new Image();
    var me = this;
    testImage.onload = function () {
        me.endTime = (new Date()).getTime();
        me.runTime = me.endTime - me.startTime;

        if (options && options.onEnd)
            options.onEnd(me.getResults());
    };
    testImage.src = imgUrl;
}

  , getResults: function () {
      if (!this.runTime)
          return null;

      return {
          runTime: this.runTime,
          Kbps: (this.size * 8 / 1024 / (this.runTime / 1000)),
          KBps: (this.size / 1024 / (this.runTime / 1000))
      };
  }
}

function getUserBandwidth() {

    //speedcheck cookie set?
    if (0 < document.cookie.indexOf('speedcheck')) {
        return;
    }

    if ($j('body').attr('id') == 'PopUp') {
        return;
    }

    var st = new SpeedTest();
    st.run({
        onStart: function () {
            // FUNCTION BEFORE START
        },
        onEnd: function (speed) {
            if (speed.Kbps < 187.5) { slowConnection(); }
        }

    });

}

/* Coveragecheck Abort */
function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function InitAbortPopup() {
    $j('.CovCheckAbbruch').prependTo('#wrapper');
    $j('.CovCheckAbbruch, .close').click(function () {
        $j('.CovCheckAbbruch').hide();
    });
    $j(".CovCheckAbbruch .modalContent").click(function (event) {
        event.stopPropagation();
    });

    $j("div.checkboxes input").filter(":checkbox,:radio").checkbox();

    if (readCookie("TELE2_COVCHECK") == "true" && window.location.href.toLowerCase().indexOf("/internet/tele2-komplett.aspx") >= 0 ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.toLowerCase().indexOf("/internet/tele2-surf.aspx") >= 0 ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 15) == "http://tele2.de" ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 16) == "http://localhost" ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 28) == "http://demo-preview.tele2.de" ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 23) == "http://staging.tele2.de" ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 27) == "http://www.staging.tele2.de" ||
                readCookie("TELE2_COVCHECK") == "true" && window.location.href.substring(0, 19) == "http://www.tele2.de") {
        eraseCookie("TELE2_COVCHECK");
        $j('.CovCheckAbbruch').show();
    }
    else {
        eraseCookie("TELE2_COVCHECK");
    }
}

function ValidateAbortForm() {
    var anythingChecked = false;
    var additionalInfo = false;
    $j(".radiobuttons input").each(function () {
        if ($j(this).attr('checked'))
            anythingChecked = true;
    })
    if ($j('.radiobuttons span[box="other"] input').attr('checked') && $j('.CovCheckAbbruch .textarea355 textarea').val() != '' || !$j('.radiobuttons span[box="other"] input').attr('checked'))
        additionalInfo = true;
    if (anythingChecked && additionalInfo)
        return true;
    else {
        if (!anythingChecked)
            $j('.errorMsg.noOptionSelected').show();
        else
            $j('.errorMsg.noOptionSelected').hide();
        if (!additionalInfo) {
            $j('.errorMsg.noMessageEntered').show();
            $j('div.textarea355').css('background-image', 'url("/Images/Website/forms/text355_err.png")');
        }
        else {
            $j('.errorMsg.noMessageEntered').hide();
            $j('div.textarea355').css('background-image', 'url("/Images/Website/forms/text355.png")');
        }
        return false;
    }
}

function UpdateTargetFromSource(sourceId, targetId, disableTarget) {
    if (sourceId && targetId) {
        var source = $j("#" + sourceId);
        var target = $j("#" + targetId);

        if ((source.length > 0) && (target.length > 0)) {
            target.val(source.val());

            if (source.attr("type") == "radio") {
                if ((source.attr("checked") == true) || (source.attr("checked") == "checked")) {
                    target.attr("checked", "checked");
                }
                else {
                    target.removeAttr("checked");
                }
            }

            if (disableTarget) {
                target.css('color', '#999999')
                      .attr('disabled', 'disabled')
                      .attr('readonly', 'true');
            }
        }
    }
}

$j(window).load(function () {
    getUserBandwidth();
});

