/// <reference path="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.1-vsdoc.js" />

$(document).ready(function() {
    $('.intext').toggleVal();
    $('table.alternate tbody tr:odd').addClass('odd');
    $('table.alternate tbody tr:even').addClass('even');
    $('table tbody tr.void').css('background-color', 'white');
    $('.check a').not('.disabled .check a').click(function(e) { // tgl checkbox
        e.preventDefault();
        var t = $(this);
        t.toggleClass('active');
        t.closest('tr').find('[id*=HiddenField_SelectedSID]').val(t.hasClass('active') ? t.attr('data-sid') : '');

    });

    //  popup modal dropdown
    $('.dropdown dt a').click(function(e) {
        e.preventDefault();
        var t = $(this);
        var turnon = !t.hasClass('active');
        $('.dropdown dd ul').removeClass('active');
        $('.dropdown dt a').removeClass('active');
        if (turnon) {
            t.addClass('active');
            var dropID = t.closest('dl').attr('id');
            $('#' + dropID + ' dd ul').toggleClass('active');
        }
    });

    //  select an element
    $('.dropdown dd ul li a').click(function(e) {
        e.preventDefault();
        var t = $(this);
        if (t.parent().hasClass('full'))
            return;
        t.closest('tr').find('[id*=HiddenField_SelectedID]').val(t.attr('data-sid'));
        var dropID = t.closest('dl').attr('id');
        var text = t.html();
        $('#' + dropID + ' dt a span').html(text);

        //  CAMA added 2011.05.18
        var href = t.closest('li').find('input[id*=HiddenField_Href]').val();
        t.closest('tr').find('.submit').attr('href', href);
        ///

        $('#' + dropID + ' dd ul').removeClass('active');
        $('.dropdown dt a').removeClass('active');
        $('.colorTip').hide()
    });

    //  ReClick selected sequences
    $('[id*=HiddenField_SelectedID]').each(function() {
        var t = $(this);
        t.closest('tr').find('[data-sid=' + t.val() + ']').click();
    });

    //  exit all modals
    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (!$clicked.parents().hasClass('dropdown')) {
            $('.dropdown dd ul').removeClass('active');
            $('.dropdown dt a').removeClass('active');
        }
    });
});

$(function() {
    $('.collapserow').each(function() {
        var t = $(this);
        if (t.prev().is('.collapserow'))
            t.find('td').css('padding-top', '0');
        if (t.next().is('.collapserow'))
            t.find('td').css('padding-bottom', '0');
    });

    $('[data-fn="datepicker"]').datepicker();

    $('[data-visibility-boundto]').each(function() {
        var t = $(this);
        $('#' + t.data('visibility-boundto')).bind('click', function() {
            if ($(this).attr('checked'))
                t.show();
            else
                t.hide();
        });
        if ($('#' + t.data('visibility-boundto')).attr('checked'))
            t.show();
        else
            t.hide();
    });
});


function getStyle(oElm, strCssRules) {
    var strValue = new Array();
    var strCssRuleArray = strCssRules.split(/,\s*/)

    for (i = 0; i < strCssRuleArray.length; i++) {
        var strCssRule = strCssRuleArray[i];

        if (document.defaultView && document.defaultView.getComputedStyle) {
            strValue.push(document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule));
        }
        else if (oElm.currentStyle) {
            strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
                return p1.toUpperCase();
            });
            strValue.push(oElm.currentStyle[strCssRule]);
        }
    }
    return strValue.join(', ');
}

$(document).ready(function() {
    if (document.URL.toString().match(/localhost/)) {
        $('*').each(function() {
            $(this).bind('mouseenter', function() {
                var trace = $('#trace');
                if (trace.length < 1) {
                    $('body').append('<div id="trace" style="position: fixed; left: 0; top: 0; font-size: 10px;"></div>');
                    trace = $('#trace');
                }
                var newTrace = getStyle(this, 'font-size, font-family, font-weight');
                if (trace.text() != newTrace) {
                    trace.text();
                } 
            });
        });
    }
});

