//============================================================================
// Site
//============================================================================
$(document).ready( function() {
});

//============================================================================

(function($) {
    $.fn.emptySelect = function()
    {
        return this.each(function(){
            if (this.tagName=='SELECT') this.options.length = 0;
        });
    }
    $.fn.loadSelect = function(optionsDataArray)
    {
        return this.emptySelect().each(function(){
        if (this.tagName=='SELECT') {
            var selectElement = this;
            $.each(optionsDataArray,function(index,optionData){
                var option = new Option(optionData.hdr,
                                    optionData.id);
                if ($.browser.msie) {
                  selectElement.add(option);
                }
                else {
                    selectElement.add(option,null);
                }
            });
            }
        });
    }
})(jQuery);


function ct_send(ct)
{
    document.getElementById('ct').value = ct
    //alert(document.getElementById('ct').value)
    document.form_main.submit()
}
function ow (url, w, h)
{
    var centerWidth = (window.screen.width - w) / 2;
    var centerHeight = (window.screen.height - h) / 2;
    newWindow = window.open(url,"","width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=no,status=no,location=no");
    newWindow.moveTo(centerWidth, centerHeight);
    newWindow.blur();
    newWindow.focus();
}

function sleep(milliSeconds)
{
    var startTime = new Date().getTime(); // get the current time
    while (new Date().getTime() < startTime + milliSeconds); // hog cpu
    
}

$(document).ready( function() {
    //isIE6 = /msie|MSIE 6/.test(navigator.userAgent)
    //if(!isIE6)
    //    $(document).pngFix();

    
    // Import GET Vars
    document.$_GET = [];
    var urlHalves = String(document.location).split('?');
    if(urlHalves[1]){
       var urlVars = urlHalves[1].split('&');
       for(var i=0; i<=(urlVars.length); i++){
          if(urlVars[i]){
             var urlVarPair = urlVars[i].split('=');
             document.$_GET[urlVarPair[0]] = urlVarPair[1];
          }
       }
    }
    
    /*
        $('.content_113Z h2').click(function() {
            $(this).nextUntil('h2').toggle('slow');
            return false;
        }).nextUntil('h2').hide();
    
        $('.content_113ZZ h2:nth-child(2)').click(function() {
            $(this).nextUntil('h2').toggle('slow');
            return false;
        }).nextUntil('h2').hide();
    */
    
    //alert(document.$_GET['n'])
    
    if(document.$_GET['n'])
    {
        n = parseInt(document.$_GET['n']) - 1
        //alert(n)
        $('.content_113 h2:not(:eq(' + n.toString() + '))').nextUntil('h2').hide()
    }
    $('.content_113 h2').click(function() {
        $(this).nextUntil('h2').toggle('slow');
        return false;
    })    
    //$('.content_113 h2:eq(1)').nextUntil('h2').show()



});

$(document).ready(function() {
    $('.tab_view tbody tr:odd').addClass('trbodyodd');
    $('.tab_view tbody tr:even').addClass('trbody');

    $('.view_rows_table tbody tr').hover(function() {
            $(this).addClass('sel');                
        }, function() {                
              $(this).removeClass('sel');                
        })

    set_disable()

    $('.view_rows_table tr')
        .filter(':has(:checkbox:checked)')
        .addClass('trselected')
        .end()
        .click(function(event) {
            $(this).toggleClass('trselected');
            if (event.target.type !== 'checkbox') {
                $(':checkbox', this).attr('checked', function() {
                    return !this.checked;
                });
            }
            set_disable()
        })

    $('.AdmModel_CategoriesTreeLeft_Cdf tr')
        .click(function(event) {
            $(':checkbox', this).attr('checked', function() {
                if($(this).attr('checked') == true)
                    $('#ZZ_sel_ids_chbx_' + $(this).attr('rel')).attr('checked', true)
            });
        })
})



function El_AdmModel_CategoriesTreeLeft_SelCatId_check(elCheckbox, parent_id)
{
    //if(elCheckbox.attr("checked") == true)
        //$('#ZZ_sel_ids_chbx_' + parent_id).attr("checked", true);
}

function set_disable()
{
    check_cnt = $("#form_main :input:checked").size()
    if(check_cnt == 1)
        $('.check_one').removeAttr("disabled").css("color","#000")
    else
        $('.check_one').attr("disabled","true").css("color","#bbb")

    if(check_cnt > 0)
        $('.check_gt0').removeAttr("disabled").css("color","#000")
    else
        $('.check_gt0').attr("disabled","true").css("color","#bbb")
}

function selectAll(elem)
{
    f = elem.form;
    check_cnt = 0
    for(i=0; f.elements[i]; i++) {
        if(f.elements[i].type == 'checkbox') {
            f.elements[i].checked = elem.checked;
            
            if(f.elements[i].checked) {
                check_cnt++
            } else {
                //check_cnt = 0
            }
        }
    }
    set_disable()
}

