﻿(function ($) {

    $.fn.detailstable = function (options) {
        var opts;

        opts = $.extend({}, $.fn.detailstable.defaults, options);

        return this.each(function () {
            var l_Odd = true;

            //alert('trying tbl');
            //$('td:first', $('tr:even', this)).hide();
            //$(this).children('tr').each(function(){
            //$('tr', this).each(function(){
            //$(this).find('tr').each(function(){
            //alert('hi');
            //.children('tbody,thead,tfoot')
            //                     .children('tr')
            //$('tr', this).filter(function(){
            //alert($(this).closest('table').tagName);
            //  return true;
            //}).each(function(){

            $(this).children('tbody,thead,tfoot').children('tr').each(function () {
                var l_Child;
                l_Child = $(this).children()[0];

                $(this).prepend('<' + l_Child.tagName + ' style="width:20px;"></' + l_Child.tagName + '>');
            });
            //$('tr:odd', this).each(function(){
            $(this).children('tbody,thead,tfoot').children('tr:odd').each(function () {
                var l_DetailRow = $(this).next();
                var l_ToggleButton = $('<img src="' + ((opts.hideDetail) ? opts.expandImgSrc : opts.collapseImgSrc) + '" />');


                var l_DetailNotEmpty = false;

                l_DetailRow.children().each(function () {
                    if (l_DetailNotEmpty) return;
                    l_DetailNotEmpty = ($(this).children().size() > 0);
                });

                /*

                if ($('td', l_DetailRow).is(':empty')) {  //l_DetailRow.hasClass('empty')){
                //alert('here');
                //l_DetailRow.hide();
                l_DetailRow.remove();
                } else {
                */
                //l_DetailRow.hide();
                //} else {

                if (!l_DetailNotEmpty || opts.hideDetail) l_DetailRow.hide()

                //$(l_DetailRow.children()[1]).addClass('detail');
                if (l_DetailNotEmpty) $(l_DetailRow.children()[1]).wrapInner('<div class="detail"></div>');

                if (l_Odd) {
                    $(this).addClass('odd');
                    l_DetailRow.addClass('odd');
                } else {
                    $(this).addClass('even');
                    l_DetailRow.addClass('even');
                }
                l_Odd = !l_Odd;

                if (!l_DetailNotEmpty) l_DetailRow.remove();

                if (l_DetailNotEmpty) {
                    $('td:first', this).prepend(l_ToggleButton);
                    l_ToggleButton.click(function () {
                        if (l_DetailRow.is(':hidden')) {
                            l_DetailRow.show();
                            //l_ToggleButton.text('[-]');
                            l_ToggleButton.attr('src', opts.collapseImgSrc);
                        } else {
                            l_DetailRow.hide();
                            //l_ToggleButton.text('[+]');
                            l_ToggleButton.attr('src', opts.expandImgSrc);
                        }
                        //l_DetailRow.toggle();
                    });
                }

            });
        });
    };

    $.fn.detailstable.defaults = {
        expandImgSrc: '/DesktopModules/ELP.Profile/images/DNN-plus.gif',
        collapseImgSrc: '/DesktopModules/ELP.Profile/images/DNN-minus.gif',
        hideDetail: true
    };

    //$.fn.detailstable.Show = function(l_DetailRow){
    //};
    /*
		
    //alert('hi');

    return this.each(function(){
    // process tables here
    alert('hiya');

    //$('table.details TR').prepend('<td style="width:20px;"></td>');
    $('table.details TR:odd').each(function(){

    // get the next row    
    $(this).next().hide(); //  initially hidden

    // add a expand collapse column
    $(this).prepend('<td style="width:20px;"></td>');
	   
    // first row is table header (0)
    // odd rows are content header rows (1, 3, etc..)
    // even rows are detail rows (2, 4, etc..)   
    });
    });

    */

})(jQuery);


(function($){

    $(function(){

        $('a.button').wrapInner('<span />');

        $('.grid-col input, .grid-col textarea, .grid-col select').each(function(){
            var $this = $(this);
            var $wrap = $this.wrap('<div class="elp-input" />').parent();
            //$this.wrap('<div class="elp-input" />');

            $this.focusin(function(){
                $wrap.addClass('elp-input-active');
                $wrap.removeClass('elp-input');
                //alert('here');
            });

            $this.focusout(function(){
                //alert('there');
                $wrap.addClass('elp-input');
                $wrap.removeClass('elp-input-active');
            });

        });

		
		$('ul.treeview').treeview({ collapsed:true });	    
	    
		if ($.fn.charttable){
			$('table.chart-ly, table.chart-xsy').charttable();
		}			

		if ($.fn.detailstable){
			$('table.details').detailstable();
			//$('table.details').detailstable( {hideDetail:false} );
		}			
	
	    $('table.list').each(function(){
			$('TR:odd', this).addClass('odd'); //.removeClass('Normal').removeClass('DNN_Reports_Grid_AlternatingRow').removeClass('DNN_Reports_Grid_Row').addClass('odd');
			$('TR:even', this).addClass('even'); 
 	    });
		//	$('table.list TR:even').addClass('even');
	
	    //alert(Date.parse('25 Oct 2005'));
	    
        
  
		if ($.fn.multiselect){
			$('.multiselect').multiselect({
				selectedList:5/*,
				position: {
				my: 'left bottom',
				at: 'left top'
				}*/
			});
		}
		

        $('span.izmlms-passed-completed').text('Completed'); // workaround to remove result %

		if ($.fn.flash){
			//var l_Url = 'http://localhost:55555/DesktopModules/ELP.Profile/UserBrowserInfo.ashx?flash='+$.flash.version.string;
			//l_Url=l_Url+'&callback=?'
			jQuery.get('/DesktopModules/ELP.Profile/UserBrowserInfo.ashx?flash='+$.flash.version.string);
			//alert('/DesktopModules/ELP.Profile/UserBrowserInfo.ashx?flash='+$.flash.version.string);
			//jQuery.get('/DesktopModules/ELP.Profile/UserBrowserInfo.ashx?flash='+$.flash.version.string, null, function(data){ alert('browser info: '+data); } );
			//alert('called it');
/*			
$.ajax({
    type: 'GET',
    url: l_Url,
	dataType: 'json',
    data: {},
    success: function(response) { alert('success4: ' + l_Url); },
    error: function(xhr, type, exception) { alert("Error4: " + type); }
})
*/
			
			
		}
		
		
    });

})(jQuery);


