if (typeof(jQuery!='undefined')) {
  $(document).ready(function() {
    //var bgcolor='#728556';
    //alert('jq');
    //$("li.menuMega").hoverIntent(megaConfig);
    $("ul#menu").superfish({delay: 500, autoArrows: true, animation: {opacity:'show', height:'show'}});
    $(window).resize(doMenuPosition);
    doMenuPosition(); // set initial menu position
    //loadImageList();
    //alert($("#divSidebar").html());
    if (($("#divSidebar").html()=='<!--{PAGE_SIDEBAR}-->')) {
      //alert('sidebar clear');
      $("#divSidebar").html('');
      $("#tdRightSidebar").width(0);
    }
    if (typeof showLogin != 'undefined' && showLogin)
      showLoginDialog();
    if (typeof bgcolor != 'undefined') {
      $('body').css('backgroundColor', bgcolor);
    }
  })
  
  function addMega() {
    //$(this).addClass('hovering');    
  }
  function removeMega() {
    //$(this).removeClass('hovering');
  }
  function doMenuPosition() {
    var newLeft=$(window).width()/2- ($("ul#menu").width()/2);
    newLeft=Math.round(newLeft);
    $("#menuWrapper").css('left', newLeft+'px')
  }
  //var megaConfig= { interval: 500, sensitivity:4, over:addMega, timeout: 500, out: removeMega };
}

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';
    }
  }
}
function setformfocus()
{
  //if (document.forms.length>0) document.forms[0].elements[0].focus();
  var username=document.getElementById('username');
  if (username)
  {
    username.focus();
  }
}

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

function getIFrameDocument(aID) 
{
  var doc = null; 

  // if contentDocument exists, W3C compliant (Mozilla)
  if (document.getElementById(aID).contentDocument)
  {
    doc = document.getElementById(aID).contentDocument;
  }
  else
  {
    // IE
    doc = document.frames[aID].document;
  }
  return doc;
} 

function showLoginDialog() {
  if (typeof jQuery !='undefined') {
    $("#loginDialog").dialog({modal:true,autoOpen:false});
    $("#loginDialog").dialog('open');
  }
  else
    location='index.php?login=1';
}

