﻿// Script changes text on collapsed sections
textArray = new Array();
function changeText(obj, newText) {
    if (newText == obj.innerHTML) {
        obj.innerHTML = textArray[obj.id];
    } else {
        textArray[obj.id] = obj.innerHTML;
        obj.innerHTML = newText;
    }
}

// Script sets alternating colours on GridView rows
$(document).ready(function() {
    $('table.Grid tbody tr:odd').addClass('Row');
    $('table.Grid tbody tr:even').addClass('AlternatingRow');
    $('table.Grid tbody tr').bind('mouseover', function() { $(this).addClass('HighlightRow'); });
    $('table.Grid tbody tr').bind('mouseout', function() { $(this).removeClass('HighlightRow'); });
});

// Script to Set DatePicker (EventSearch & EditUsersDelagetes & Logon & TrainingRecord & Assignment & NotesAndSlides)
$(function() {
    $("#StartDate").datepicker(
                { dateFormat: 'dd/mm/yy' });
});

$(function() {
    $("#EndDate").click(function() {
        /* Set end date textbox to match value and then set datepicker if, this value
        is null */
        if ($(this).val() == "") {
            $(this).val($("#StartDate").val());
            $(this).datepicker("setDate", $("#StartDate").datepicker("getDate"));
            $(this).datepicker("refresh");
        } else {
            /* OR set the end date if the start date exceeds the current end date */
            var sDateParts = $("#StartDate").val().split("/");
            var eDateParts = $(this).val().split("/");

            var sDate = new Date(sDateParts[2], sDateParts[1] - 1, sDateParts[0]);
            var eDate = new Date(eDateParts[2], eDateParts[1] - 1, eDateParts[0]);

            if (+sDate > +eDate) {
                $(this).val($("#StartDate").val());
                $(this).datepicker("setDate", $("#StartDate").datepicker("getDate"));
                $(this).datepicker("refresh");
            }            
        }
    });
});

$(function() {
    $("#EndDate").datepicker(
                 { dateFormat: 'dd/mm/yy' });
});

$(function() {
    $("#FromDate").datepicker(
                 { dateFormat: 'dd/mm/yy' });
});  

$(function() {
    $("button, input:submit, a", ".togglePanel").button();
    $("a", ".togglePanel").click(function() { return false; });
});

$(function() {
    $("#accordion").accordion({
        animated: 'bounceslide',
        collapsible: true,
        icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' }
    });
});
