$(document).ready(function () {
    $(".defaultText").focus(function (srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).removeClass("defaultTextActive");
            $(this).val("");
        }
    });

    $(".defaultText").blur(function () {
        if ($(this).val() == "") {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });

    $(".defaultText").blur();

    styleWidgets();
    styleBullets();
    $("ul.modules h4").hide();



//    $('#mainsearchformSubmit').live('click',function () {
//        alert('sadsad');
//    });

});

function styleBullets() {

    $('body.ld .learningmodule_widget h4').remove();
    $('body.ld ol>li').attr('class', 'decimal');

    $('body.ld .usercontent ul').attr('class', 'bulletul');
    $('body.ld .quicklinks_widget ul').attr('class', 'bulletul');
    $('body.ld .learningmodule_widget .innerContent>.fc ul').attr('class', 'bulletul');
    $('body.ld .learningmodule_widget .innerContent>.fc ul>li').attr('class', 'bullet');
    $('body.ld .learningmodule_widget ul.modules>li ul').attr('class', 'bulletul');
    $('body.ld .learningmodule_widget ul.modules>li ul>li').attr('class', 'bullet');
    $('body.ld .owMoreinfo ul').attr('class', 'bulletul');
    $('body.ld .owMoreinfo ul>li').attr('class', 'bullet');

    $('body.ld .owitem ul.cbtnav>li').attr('class', 'bullet');
    $('body.ld .owitem ul.cbtnav').attr('class', 'bulletul');

    $('body.ld .owitem .LatestResources ul').addClass("bulletul");
    $('body.ld .owitem .LatestResources ul>li').addClass("bullet");

    $('body.ld .owitem .LatestBlogPostsList ul').addClass("bulletul");
    $('body.ld .owitem .LatestBlogPostsList ul>li').addClass("bullet");

    $('body.ld .owitem ul.topicLinkList').addClass("bulletul");
    $('body.ld .owitem ul.topicLinkList>li').addClass("bullet");

    $('body.ld .owitem .ActivityList ul').addClass("bulletul");
    $('body.ld .owitem .ActivityList ul>li').addClass("bullet");

    $('body.ld .qit_widget .tabContent>ul').attr('class', 'bulletul');
    $('body.ld .qit_widget .tabContent>ul>li').attr('class', 'bullet');

    $('body.ld .newsfeeds_widget ul').attr('class', 'bulletul');
    $('body.ld .richTextContent ul').attr('class', 'bulletul');

    $('body.ld .usercontent ul>li').attr('class', 'bullet');
    $('body.ld .quicklinks_widget ul>li').attr('class', 'bullet');

    $('body.ld .newsfeeds_widget ul>li').attr('class', 'bullet');
    $('body.ld .richTextContent ul>li').attr('class', 'bullet');
    $('body.ld .introTxt ul>li').addClass("bullet");

    $('body.ld .richTextContent img').addClass('contentimage');
    $('body.ld .learningmodule_widget ul.modules>li>img').addClass('contentimage');
    $('body.ld .learningmodule_widget ul.modules>li a.externalImage').addClass('contentimage');
    $('body.ld .accordionLinks .innerContent .AccordionLinksText img').addClass('contentimage');
    $('body.ld .learningmodule_widget img').addClass('contentimage');

    //$(".newsfeeds_widget img[src=='']").hide();

    $('body.ld .accordionLinks .innerContent ul>li').addClass('bullet');
    $('body.ld ul.faqQuestions .wrapper>ul>li').addClass('bullet');

    $('body.ld ul.linksGroupList>li').removeClass('bullet');
    $('body.ld ul.faqQuestions>li, body.ld ul.faqList>li').addClass('nobullet');


}


function onSearchFormSubmit() {
    var textfield = $('body.ld #ld_mainsearchform').find('.textfield').attr('value');
    var url = '/Base/FastQueryManager/ReformatQuery/' + textfield + '.aspx';
    $.ajax({
        url: url,
        success: function (data) {
            var qval;
            var form = $('#ld_mainsearchform');
            var action = form.attr('action');
            var textfield = $(form).find('.textfield').val();
            $(data).find("value").each(function () {
                qval = $(this).text();
            });
            window.location = action + '?q=' + qval + '&pm=fql&ms=true&t=' + textfield;
            return true;
        }
    });
    return false;
}


function onMainSearchFormSubmit() {
    var textfield = $('#mainsearchform').find('.textfield').attr('value');
    var url = '/Base/FastQueryManager/ReformatQuery/' + textfield + '.aspx';
    $.ajax({
        url: url,
        success: function (data) {
            var qval;
            var form = $('#mainsearchform');
            var action = form.attr('action');
            var textfield = $(form).find('.textfield').val();
            $(data).find("value").each(function () {
                qval = $(this).text();
            });
            window.location = action + '?q=' + qval + '&pm=fql&ms=true&t=' + escape(textfield);
            return true;
        }
    });
    return false;
}

function onSearchFormSubmit() {
    var textfield = $('#ld_mainsearchform').find('.textfield').attr('value');
    var url = '/Base/FastQueryManager/ReformatQuery/' + textfield + '.aspx';
    $.ajax({
        url: url,
        success: function (data) {
            var qval;
            var form = $('#ld_mainsearchform');
            var action = form.attr('action');
            var textfield = $(form).find('.textfield').val();
            $(data).find("value").each(function () {
                qval = $(this).text();
            });
            window.location = action + '?q=' + qval + '&pm=fql&ms=true&t=' + escape(textfield);
            return true;
        }
    });
    return false;
}

function qexist(form) {
    if ($(form).find('#q').length > 0) {
        return true;
    }
    else {
        return false;
    }
}

function sleep(ms) {
    var dt = new Date();
    dt.setTime(dt.getTime() + ms);
    while (new Date().getTime() < dt.getTime());
}


function styleWidgets() {
    $("body.ld  .Widgets li").each(function () {
        var html = $(this).html();
        html = '<div class="secondary-content"><div class="secondary-content-inner">' + html + '</div></div>'
        $(this).html(html);
    });
}

function clearDefaultText() {
    $(".defaultText").each(function () {
        if ($(this).val() == $(this)[0].title) {
            $(".defaultText").val("");
        }
    });
}
