﻿/**************** TOP OF MASTER PAGE ********************/
// Tom's code
function initsub() {
    if (typeof initTooltips == 'function') {
        initTooltips();
        $('.selectspecial').sSelect({ ddMaxHeight: '160px' });
    }
    try {
        initpage();
    }
    catch (err) {
    }
}

$(function () {
    ////// Twitter / facebook widget /////
    $('#social-background').hover(
            function () { $('#social-background .mid').slideDown(); },
            function () { $('#social-background .mid').slideUp(); }
        );
    $('#social-background .mid a').html('');
    //$('#social-background .mid').slideDown();

    ////// View more / less script /////
    $('.content-wrapper.see-more-mode div').each(function () {
        var trimmedText = GetFirstWords($(this).html(), 35);
        if (trimmedText != false) {
            $(this).html(
                '<div class="short">' + trimmedText + '...</div>' +
                '<div class="long">' + $(this).html() + '</div>' +
                '<div class="view-more a">more...</div>'
            );
        }
    });
    $('.content-wrapper.see-more-mode .view-more').click(function () {
        if ($(this).html() == 'more...') {
            $(this).html('less...').siblings('.short').hide().siblings('.long').show();
        } else {
            $(this).html('more...').siblings('.short').show().siblings('.long').hide();
        }
    });
    var hashAnchor = self.document.location.hash.substring(1);
    if (hashAnchor.length >0 && $('#' + hashAnchor).length > 0) {
        $('#' + hashAnchor).next('div').children('.a').click();
    }
});

function GetFirstWords(text,IdealNumberOfWords) {
    var str = '';
    var words = [];
    words = text.split(' ');

    var lastIndex = IdealNumberOfWords;
    if(words.length <= IdealNumberOfWords){
        return false;
    }

    for (var i = 0; i < lastIndex;i++) {
        str += words[i] + ' ';
    }
    return str.trim();
}

/**************** BOTTOM OF MASTER PAGE *****************/
// Breadcrumb
function EndOfDoc() {
    var secondCrumb = $('#divMenu a.hover')[0];
    var thirdCrumb = $('#Body_smSubMenu_divSubMenu .mid.current')[0];

    var strDef = "<a href='default.aspx'>home</a>";
    var str = strDef;
    if (secondCrumb !== undefined) {
        str += " > <a href='" + $(secondCrumb).attr('href') + "'>" + $(secondCrumb).attr('href').replace('-', ' ').replace('.aspx', '') + "</a>";
        if (thirdCrumb !== undefined) {
            str += " > <a href='#divBody'>" + $(thirdCrumb).html() + "</a>";
            //str += " > <span style='color:white;font-weight:bold;'>" + $(thirdCrumb).html() + "</span>";
        }
    }

    if (str == strDef && $('h1').length > 0) {
        str += " > <a href='#divBody'>" + $('h1').html() + "</a>";
    }

    $('#breadcrumb').html(str.toLowerCase());
}


$(function () {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(UpdatePanelRefreshed);
    UpdatePanelRefreshed(undefined, undefined);
});

function UpdatePanelRefreshed(sender, args) {
    setTimeout("$('.fadeout').fadeOut();", 5000);
    $('.datepicker').datepicker({ dateFormat: 'dd/mm/yy' });
}

var text = '';
function ShowSuggestionHtml(subject, notes) {
    text = $('#modalPopupContentArea').html();   //remember current contents.
    $('.divSuggestionText').html(subject);  //set up new text
    $('#hdnNotes').val(notes);              //store 'notes' in hidden field

    $('#modalPopupContentArea').fadeOut(function () {
        $('#modalPopupContentArea').html($('#divSuggestionHtml').html()).fadeIn();
    });
    
}
function RestoreText() {
    $('#modalPopupContentArea').fadeOut(function () {
        $('#modalPopupContentArea').html(text).fadeIn();
    });
}
function SendNewSuggestion() {
    //alert($('#hdnNotes').val() + ' ... ' + $('#txtNewSuggestion').val());
    SendSuggestion($('.divSuggestionText').html(), $('#hdnNotes'), $('#txtNewSuggestion').val());
    RestoreText();
}

function SendSuggestion(suggestionFor, notes, actualSuggestion) {
    $.ajax({
        type: "POST",
        url: "/WebService.asmx/SubmitSuggestion",
        contentType: "application/json; charset=utf-8",
        data: "{'suggestionFor':'" + suggestionFor + "','notes':'" + notes + "','actualSuggestion':'" + actualSuggestion + "'}",
        dataType: "json",
        success: SuggestionSent,
        error: SuggestionFailedToSend
    });
}
function SuggestionSent(responseData) {
    debugger;
}
function SuggestionFailedToSend(responseData) {
    debugger;
}
