//------------------------------------------------------------------------------
function FSI_PanelGotoPage(nav, pageNumber)
{
  var form = $(nav).parents("form:first");
  form.find("[name=pg_gotopage]").val(pageNumber);
  var target = $(nav).parents(".fsi-panel-list-container:first");
  var loading = $(nav).parents(".jqmDialog:first").find(".rcm-ajax-loading");

  form.ajaxSubmit({
    target:target
    ,beforeSubmit:function(){loading.css("visibility", "visible");}
    ,success:function(){loading.css("visibility", "hidden");}
  });

}
//------------------------------------------------------------------------------
function FSI_PanelColumnSort(nav, field, order)
{
  var form = $(nav).parents("form:first");
  var p = $(nav).parents(".jqmDialog:first");
  p.find("[name=pg_gotopage]").val(1);
  p.find("[name=pg_sort_field]").val(field);
  p.find("[name=pg_sort_order]").val(order);

  var target = $(nav).parents(".fsi-panel-list-container:first");
  var loading = p.find(".rcm-ajax-loading");

  form.ajaxSubmit({
    target:target
    ,beforeSubmit:function(){loading.css("visibility", "visible");}
    ,success:function(){loading.css("visibility", "hidden");}
  });

}
//------------------------------------------------------------------------------
function FSI_GotoPage(pageNumber)
{
  document.pg_form_paging.pg_gotopage.value = pageNumber;

  try {
    if (document.pg_form_paging.pg_ajax.value == 1)
    {
      RCM_AjaxPostToDiv("divPaging", "pg_form_paging", "page_loading");
      return;
    }
  }catch(e){}
  try {
    var xy = RCMT_GetScrollXY();
    document.pg_form_paging.pg_scrollx.value = xy[0];
    document.pg_form_paging.pg_scrolly.value = xy[1];

  }catch(e){}

  document.pg_form_paging.submit();
  return;
}
//------------------------------------------------------------------------------
function FSI_ColumnSort(field, order)
{
  document.pg_form_paging.pg_gotopage.value = 1;
  document.pg_form_paging.pg_sort_field.value = field;
  document.pg_form_paging.pg_sort_order.value = order;

  try {
    if (document.pg_form_paging.pg_ajax.value == 1)
    {
      RCM_AjaxPostToDiv("divPaging", "pg_form_paging", "page_loading");
      return;
    }
  }catch(e){}
  try {
    var xy = RCMT_GetScrollXY();
    document.pg_form_paging.pg_scrollx.value = xy[0];
    document.pg_form_paging.pg_scrolly.value = xy[1];

  }catch(e){}

  document.pg_form_paging.submit();
  return;
}
//------------------------------------------------------------------------------
function FSI_Focus()
{
  var focus = function () {
    var id = RCMT_GetElementsByAttribute(document.body, "input", "pg_focus_here")[0];
    try { id.focus() } catch(e) {};
    try { id.select() } catch(e) {};
  }
  RCMT_AddListener(window, 'load', focus);
}
//------------------------------------------------------------------------------
function FSI_Submit(event, formName)
{
  var valBefore;
  $(document).find("form[name="+formName+"] input[name=pg_event]").each(function(){
    valBefore = $(this).val();
    $(this).val(event);
  });
  document.forms[formName].submit();
  $(document).find("form[name="+formName+"] input[name=pg_event]").each(function(){
    $(this).val(valBefore);
  });  
}
//------------------------------------------------------------------------------
function FSI_SubmitToExternal(form_id, url)
{
  var queryString = $('#'+form_id).formSerialize();
  FSI_PopupExternalLink(url + queryString);
  RCM_AjaxPanelHide('#'+form_id);
  return false;
}
//------------------------------------------------------------------------------
function FSI_Menu()
{
    // Animation object
    var oAnim;

    // Utility function used to setup animation for submenus
    function setupMenuAnimation(p_oMenu) {
        if(!p_oMenu.animationSetup) {
            var aItems = p_oMenu.getItemGroups();
            if(aItems && aItems[0]) {
                var i = aItems[0].length - 1;
                var oSubmenu;
                do {
                    oSubmenu = p_oMenu.getItem(i).cfg.getProperty("submenu");
                    if(oSubmenu) {
                        oSubmenu.beforeShowEvent.subscribe(onMenuBeforeShow, oSubmenu, true);
                        oSubmenu.showEvent.subscribe(onMenuShow, oSubmenu, true);
                     }
                 }
                while(i--);
             }
             p_oMenu.animationSetup = true;
         }
     }

    // "beforeshow" event handler for each submenu of the menu bar
    function onMenuBeforeShow(p_sType, p_sArgs, p_oMenu) {
        if(oAnim && oAnim.isAnimated()) {
            oAnim.stop();
            oAnim = null;
        }
        YAHOO.util.Dom.setStyle(this.element, "overflow", "hidden");
        YAHOO.util.Dom.setStyle(this.body, "marginTop", ("-" + this.body.offsetHeight + "px"));
    }

    // "show" event handler for each submenu of the menu bar
    function onMenuShow(p_sType, p_sArgs, p_oMenu) {
        oAnim = new YAHOO.util.Anim(
            this.body,
            { marginTop: { to: 0 } },
            .2,
            YAHOO.util.Easing.easeOut
        );
        oAnim.animate();

        var me = this;
        function onTween() {
            me.cfg.refireEvent("iframe");
        }
        function onAnimationComplete() {
            YAHOO.util.Dom.setStyle(me.body, "marginTop", ("0px"));
            YAHOO.util.Dom.setStyle(me.element, "overflow", "visible");
            setupMenuAnimation(me);
        }
        /*
             Refire the event handler for the "iframe"
             configuration property with each tween so that the
             size and position of the iframe shim remain in sync
             with the menu.
        */
        if(this.cfg.getProperty("iframe") == true) {
            oAnim.onTween.subscribe(onTween);
        }
        oAnim.onComplete.subscribe(onAnimationComplete);
    }

    // "render" event handler for the menu bar
    function onMenuRender(p_sType, p_sArgs, p_oMenu) {
        //setupMenuAnimation(p_oMenu);
    }

    // Instantiate and render the menu bar
    var oMenuBar = new YAHOO.widget.MenuBar("site_menubar", { autosubmenudisplay:true, hidedelay:750, lazyload:false });

    // Subscribe to the "render" event
    //oMenuBar.renderEvent.subscribe(onMenuRender, oMenuBar, true);
    oMenuBar.render();
}
//------------------------------------------------------------------------------
function FSI_PopupSiteMessage(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var placement = (',left=0,top=0,height='+height);

  var siteMessage = window.open(url, 'FSI_PopupSiteMessage' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes,width=600' + placement );
  try{ siteMessage.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupReport(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var left = screen.availWidth-2 - 670;
  var placement = (',left='+left+',top=0,height='+height);

  var siteMessage = window.open(url, 'FSI_PopupReport' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes,width=670' + placement );
  try{ siteMessage.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupMessage(url)
{
  var w = 600;
  var h = 400;

  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();
  if (window.screenX) {
    var pos_x = window.screenX + 125;
    var pos_y = window.screenY + 233;
  } else if (screen) {
    var bottom = screen.availHeight;
    var right = screen.availWidth;
    var pos_x = parseInt((right- w)/2) ;
    var pos_y = parseInt((bottom - h)/2);
  }
  var placement = (',left=' + pos_x + ',top=' + pos_y + ", height=" + h, ", width=" + w);

  var siteMessage = window.open(url, 'FSI_PopupMessage' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes' + placement );
  try{ siteMessage.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupDocument(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var placement = (',left=0,top=0,height='+height);

  var siteDocument = window.open(url, 'FSI_PopupDocument' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes,width=700' + placement );
  try{ siteDocument.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupDocumentViewer(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var width  = (screen.availWidth-2)*(3/4);
  var placement = (',left=0,top=0,height='+height);

  var siteMessage = window.open(url, 'FSI_PopupReport' , 'scrollbars=no,menubar=yes,toolbar=no,resizable=yes,status=yes,width='+ width + placement );
  try{ siteMessage.focus(); }catch(e){}
}
//------------------------------------------------------------------------------
function FSI_PopupExternalLink(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var width = screen.availWidth-2;
  var placement = (',left=0,top=0,height='+height + ',width='+width);

  var siteDocument = window.open(url, 'FSI_PopupExternalLink' , 'location=yes,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes,status=yes' + placement );
  try{ siteDocument.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupFullScreen(url)
{
  var parmSeparator = (url.indexOf("?") == -1)? "?":"&";

  url = url + parmSeparator + "u=" + RCMT_GenUuid();

  var height = screen.availHeight-2;
  var width = screen.availWidth-2;
  var placement = (',left=0,top=0,height='+height + ',width='+width);

  var siteDocument = window.open(url, 'FSI_PopupFullScreen' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes' + placement );
  try{ siteDocument.focus(); }catch(e){}

}
//------------------------------------------------------------------------------
function FSI_PopupForm(url)
{
  var w = 0, h = 0, left = 0, top  = 0;

  if (screen.availWidth <= 1024)
  {
    w = screen.availWidth*6/6;
    h = screen.availHeight*6/6;
  }else if(screen.availWidth <= 1280){
    w = screen.availWidth*5/6;
    h = screen.availHeight*5/6;
  }else{
    w = screen.availWidth*4/5;
    h = screen.availHeight*4/5;
  }

  left = (screen.availWidth - w)/2 ;
  top = (screen.availHeight - h)/2 - 50;
  var placement = (',left=' + left + ',top=' + top + ", height=" + h + ", width=" + w);

  var popupForm = window.open(url, 'FSI_PopupForm' , 'scrollbars=yes,menubar=yes,toolbar=no,resizable=yes,status=yes' + placement );
  try{ popupForm.focus(); }catch(e){}

}
//------------------------------------------------------------------------------