$(function() {
    // MAKING THE IMAGE TABS WORK
    imagify = function() {
        // parent div id
        block_name = '#'+$(this).parents('.pics-block').attr('id')+' ';
        // clicked image id
        container = '*#'+$(this).attr('id')+'c';
        // selecting the clicked image
        $(this).parents('.pics-block-select').find('img').removeClass('selected');
        $(this).addClass('selected');
        // updating the content
        $(block_name+'div.pics-block-left')
            .html($(container).find('.imsel-img').html());
        
        $(block_name+'div.pics-block-text')
            .html($(container).find('.imsel-text').html());


        if($(container).find('.imsel-header').size()>0) {
            $(block_name+'div.pics-block-header')
                .html($(container).find('.imsel-header').html());
        }
    }

    // select the first image on load
    $("img[id^='imsel']").parents(".pics-block").find("img[id^='imsel']:first").each(imagify);
    // click handler
    $("img[id^='imsel']").bind('click',imagify);
    // colorizing the table
    $("#main_table tbody tr:odd").addClass('main_table_odd');
    $("#main_table tbody tr:even").addClass('main_table_even');

    typeof(DD_roundies)=='object' && DD_roundies.addRule('.fg-button', '4px');

    $.imgUnchecked = '/images/checkbox1.gif';
    $.imgChecked = '/images/checkbox2.gif';
    // replace checkboxes, keeping the functionality
    $("input[type='checkbox']").each(function (){
        a = function (cb) {

            var img = document.createElement('img');
            img.src += cb.attr('checked') ? $.imgChecked : $.imgUnchecked;
            img.className = 'checkboxImage';
            img.id = 'cb_'+cb.attr('id');
            img.onclick = function(){  
                cb_switch = function (id) {
                    btn = $('#'+id);
                    img = $('#cb_'+id);
                    btn.attr('checked', !(btn.attr('checked')));
                    btn.attr('checked') ? img.attr('src', $.imgChecked) : img.attr('src', $.imgUnchecked);
                }(cb.attr('id'));
            };
            cb.before(img);
            cb.hide();
        }($(this));
    });
    
    $.fn.datepicker && function() {
        $.datepicker.setDefaults({
           changeMonth: true,
           changeYear: true,
           yearRange: '-03:+03'
        });

        $('.datepicker').datepicker();
        $('.fun-date').datepicker({showOn: 'button', buttonImage: '/images/calendar/date_select.gif', buttonImageOnly: true});
    }();

    $.fn.tabs && function() {
        $("#tabs > ul").removeClass("ui-tabs-hide");
        $tabs = $("#tabs").tabs({ fxAutoHeight: true });
        
				$panels = $('.ui-tabs-panel');
				var maxHeight =
					$.map($panels, function(el) {
						return $(el).height();;
					})
					.sort(function(a, b) {
						return b - a;
					})[0];
				$panels.height(maxHeight);        
    }();
    

});








// disabling selection
window.onload = function () {
    document.body.onselectstart = function () {
        return false;
    }
    
    document.body.ondragstart = function () {
        return false;
    }


var message="";
function clickIE() {if (document.all) {(message);return false}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

function disableselect(e) {
return false
}
function reEnable() {
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar) {
document.onmousedown=disableselect
document.onclick=reEnable
}


// disable right clicks

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

if (isIE||isNN)
{
 document.oncontextmenu=checkV;
}
else
{
 document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP);
 document.onmousedown=checkV;
} 

function checkV(e)
{
    if (isN4)
     {
    if (e.which==2||e.which==3)
        {
        dPUW=alert(PopUpURL);
        return false;
        }
    }
    else
    {
    //dPUW=alert(PopUpURL);
    return false;
    }
}

// for forms in FF
function stopit(e) {
    if( !e ) { e = window.event; } //non-standard (IE)
    if( e.stopPropagation ) { e.stopPropagation(); } //standards
    e.cancelBubble = true; //IE compatible
}

}


function addBookmark(title,url) {
    if (window.sidebar) { 
        window.sidebar.addPanel(title, url,""); 
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
        return true;
    }
}

function roll_over(img_name, img_src)
{
    document.getElementById(img_name).src = img_src;
}


function openCenteredWindow(url, height, width, name, parms) {
   var left = Math.floor((screen.width - width)/2);
   var top = Math.floor((screen.height - height)/2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}


function capitalize(str) {
        newVal = '';
        str = str.split(' ');
        for(var c=0; c < str.length; c++) {
            newVal += str[c].substring(0,1).toUpperCase() +
            str[c].substring(1,str[c].length) + ' ';
        }

        return newVal;
}
