// jquery functions:
if (typeof jQuery !='undefined') 
{
  $(document).ready(function() {
    $(window).resize(adjustLayout);
    adjustLayout();
    //doPageCorner();
    if (typeof showLogin != 'undefined' && showLogin)
      showLoginDialog();
    //alert($('test').hasClass('noBullet'));
    $("#leftMenu li").hover(function() {
        if (!$(this).hasClass('noBullet')) {
          $(this).css('background-image', 'URL("images/btnRed_150.gif")');
          $(this).find("a").css('color', 'white');
        }
      }, 
      function() {
        if (!$(this).hasClass('noBullet')) {
          $(this).css('background-image', 'URL("images/btnOrange_150.gif")');
          $(this).find("a").css('color', '#800000');
        }
      }
    );
    $("#leftMenu li").click(doMenuClick);
  });
  
  function doMenuClick(obj) {
    if (!$(this).hasClass('noBullet'))
      window.document.location=$(this).find("a").attr('href');
  }
  function doPageCorner() {
    $("#test").corner();
    $("#page_header").corner("top");
    $("#divFooter").corner("bottom");
    //$("#page_wrapper").css("color", 'blue');
  }
  function showLoginDialog() {
    if (typeof jQuery !='undefined') {
      $("#loginDialog").dialog({modal:true,autoOpen:false});
      $("#loginDialog").dialog('open');
    }
    else
      location='index.php?login=1';
  }
  function showMsg(str) {
    var tmpstr=$("#debug").html();
    $("#debug").html(tmpstr+"<br />"+str);
  }
  
  function adjustLayout() {
    // get natural heights:
    var cHeight=$("#main_content").height();
    //showMsg("raw center col height:"+cHeight);
    var lHeight=$("#leftbar_content").height();
    //showMsg("raw left col height:"+lHeight);
    var rHeight=$("#rightbar").height();
    //alert(rHeight);
    // find max height:
    //lHeight=400;
    sideMax=Math.max(Math.max(lHeight, rHeight));
    //alert('side:'+sideMax);
    var maxHeight=Math.max(cHeight, sideMax);
    maxHeight=maxHeight+100;  // for some reason, eliminating this cuts off in all browsers.
    //showMsg('Max Height: '+maxHeight);
    //maxHeight=maxHeight+150;
    // assign new max to all columns:
    $("#page_maincontent").height(maxHeight+'px');
    $("#page_leftbar").height(maxHeight+'px');
    $("#page_rightbar").height(maxHeight+'px');
    // show the foother
    
    //alert(maxHeight);
    $("#page_footer").show();
    //alert($("#page_maincontent").height());
    //alert($("#page_leftbar").height());
  }
}// end of jquery functions


//old global functions (for backwards compatibility)
function doGlobalLoad(sender)
{
  //alert('load');
  sender.setformfocus();
  if (window.doLocalLoad)
    doLocalLoad();
  if (window.opener && !window.opener.closed)
  {
    if (document.getElementById("closebtn"))
      document.getElementById("closebtn").style.display='block';
    if (document.getElementById("returnbtn"))
      document.getElementById("returnbtn").style.display='none';
  }
  else
  {
    if (document.getElementById("returnbtn"))
      document.getElementById("returnbtn").style.display='block';
    if (document.getElementById("closebtn"))
      document.getElementById("closebtn").style.display='none';
  }
  // load random images:
  //loadImageList();
  adjustLayout(); // had to add this here, in addition in jquery.ready() because it didn't work all the time up there.
}
function setformfocus()
{
  //if (document.forms.length>0) document.forms[0].elements[0].focus();
  var username=document.getElementById('username');
  if (username)
  {
    try {
      username.focus();
    }
    catch (e) {
      //alert(e.message); 
    }
  }
}

function popWindow(url)
{
  var win=window.open('', '', 'HEIGHT=400, WIDTH=400, resizable, status, scrollbars');
  win.moveTo(100,100);
  win.location=url;
}


function confirm_delete(str)
{
  if (str)
  {
    str=' '+str;
  }
  var result=confirm('Are you Sure you want to delete'+str+'?');
  return result;
}

