//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 1998, Siebel Systems, Inc., All rights reserved.
//
// FILE:       swecommon.js
//  $Revision: 145 $
//      $Date: 11/09/01 4:30p $
//    $Author: Wlai $ of last update
//
// CREATOR:    TDiec
//
// DESCRIPTION
//    
// JavaScript Functions used by the Siebel Web Engine.
//
//////////////////////////////////////////////////////////////////////////////

if (top._swe && top._swe._swejssview != null)
   top._swejssview = top._swe._swejssview;

var SWEIsHighInteract = false;
var SWEPopupResizeNoHide = false;

function SWEGetPopupResizeNoHide ()
{
  if(SWEPopupResizeNoHide != "undefined")
  {
    return SWEPopupResizeNoHide;
  }
  return false;    
}

function SWESetPopupResizeNoHide (bValue)
{
  if(SWEPopupResizeNoHide != "undefined")
  {
    return SWEPopupResizeNoHide = bValue ;
  }
  return;    
}
// 12-EBDFCN
function SWEConfirmNExecute(msg, okurl,cancelurl)
{
   var tf = SWEConfirm(msg);

   if (tf && okurl != null && okurl != '')
   {
      SWEGotoURL(okurl);
   }
   else if (cancelurl != null && cancelurl != '')
      SWEGotoURL(cancelurl);
}
//
//Used to goto a view. 
// 
function SWEGotoView(viewname, busObjZone, url, target)
{
   if (SWEIsHighInteract)
   {
      App().GotoView (viewname, busObjZone, url, target);
   }
   else 
   {
      SWETargetGotoURL (url, target, false);
   }
}

//
//Used to goto a url. Will append a time stamp to enable the server to identify a refresh
// 
function SWETargetGotoURL(url, target, bLeaveApplet)
{
   if (pendingChanges())
   {
      // Prevent data loss warning from kicking in twice, one by focus tracking and one by SWETargetGotoURL.
      // Going to compare SWEApplet against currently selected applet name.
      // If SI focus tracking is turned on, then having pending changes mean the user had clicked on Cancel 
      //    on the first warning.  If he had click Continue, pendingChanges() would return false.
      // If SI focus tracking is not turned on, just go ahead with normal data loss warning.
      // Otherwise if URL request is from currently selected applet, show data loss warning because focus tracking 
      //    wouldn't have displayed the first warning.
      // If URL request is not from currently selected applet, don't show warning because there would have
      //    been a first warning displayed by focus tracking.

      // flag indicating whether to data loss warning, if shown here, would be dup
      var bDupWarning = false; 

      // If focus tracking is turned on, need to check for applet names
      if (typeof(top.SWEApplets) != 'undefined' && typeof(top.SWEApplets[top.CurrentAppletIndex]) != 'undefined')
      {
         // If SWEApplet exists in URL, extract it
         var searchKey = "SWEApplet=";
         var startIdx;
         var endIdx;
         var appletName = null;
         startIdx = url.indexOf(searchKey);
         if (startIdx >= 0)
         {
            endIdx = url.indexOf("&", startIdx);
            if (endIdx >= 0)
               appletName = url.substring(startIdx+searchKey.length, endIdx);
            else
               appletName = url.substring(startIdx+searchKey.length);
         }

         if (typeof(appletName) == "string" && appletName != URLEncode(top.SWEApplets[top.CurrentAppletIndex].Name))
            bDupWarning = true;  // If applet name doesn't match currently selected applet, this would be dup warning if shown.
      }
        
      // Show warning if it wouldn't be redundant 
      if (bDupWarning || (url.indexOf("SkipDataLossWarning") < 0 && StopForSavingData()))
         return;
   }

   var frameObj;
   var now = new Date();

   if( typeof(target) == "string")
   {
      // PR 12-LFSYYX: Port PR 12-IKA10V
      // Fix for PR#12-IKA10V. This allows the coming response
      // to be targeted to a new window.
      if (target == "_blank")
         frameObj = this.open ();
      else if (target != "")
         frameObj = SWEFindFrame(top, target);
      else
         frameObj = null;
   }
   else 
      frameObj = target;

   if(frameObj == null) 
      frameObj = this;

   //Only add the time stamp if the GotoURL is a SWE URL.
   //If this is an external URL, then we don't want to add the time stamp
   if (url.search("start.swe") != -1)
   {  
      url = SWEAppendArgsToURL (url, "SWETS", now.getTime());
      // Fix for 12-G8DVVA. MSN browser sends file download request twice
      // So we set a URL argument indicating that a refresh should not be
      // attempted for such a case. When the server parses this argument, 
      // it will send the file again instead of doing a refresh. We check 
      // frameObj against top to gaurd against misconfiguration
      if (!SWEIsHighInteract && (frameObj != top) && (url.indexOf("SWEMethod=Drilldown") != -1)
          && (navigator.userAgent.indexOf("MSN") > -1))
      {
         url = SWEAppendArgsToURL (url, "SWENR", 1);
      }
      //always append swecount 
      if (typeof(Top().SWECount) == 'undefined')
         Top().SWECount = -1;
      url = SWEAppendArgsToURL (url, "SWEC", Top().SWECount);
   }


   if (SWEIsHighInteract)
   {
      var app = App();
      //var view = app.GetMainView ();
      //if (bLeaveApplet == true && view)
      //{
      //   if (view.SetActiveApplet(null))
      //      app.GotoURL(url, frameObj);
            //else back up original status
      //}
      //else
         app.GotoURL(url, frameObj, bLeaveApplet);
   }
   else 
   {
      if (typeof(top._samePage) != 'undefined' && top._samePage!="")
      {
         //unlikely to have two immediate post changes from the same page
         //otherwise we have to take out the old value and replace with the new one.
         SWEAppendArgsToURL (url, "SWESPa", top._samePage); 
         top._samePage = "";
      }
      
      frameObj.location = url;      
   }
}

function OnPageUnload ()
{
   // cr 12-FU7MEN: Disable select/LOVs during a page refresh in SI   
   // Occurs in IE 5.5 SP2 and up
   var selObjs = document.body.getElementsByTagName("SELECT");
   for(var i=0;i < selObjs.length;i++)
   {
      selObjs[i].disabled = true;
   }
}

function SWEGotoURL(url, bLeaveApplet)
{ 
   SWETargetGotoURL(url, this, bLeaveApplet); 
}

function SWEFindFrame(topWin, frameName)
{
   if (frameName == "_self")
   {
      return this;
   }

   for (var i = 0; i < topWin.frames.length; i ++) 
   {
      var frameObj = topWin.frames[i];

      var theFrame = topWin.frames[frameName];

      if (theFrame != null)
         return theFrame;
            
      frameObj = SWEFindFrame (frameObj, frameName);

      if (frameObj != null)
          return frameObj;
   }

   return null;
}

// PR 12-LFSYYX: Port PR 12-IKA10V
// Fix for PR#12-IKA10V. Add the third argument to handle
// the behavior when cancel is clicked.
function SWEConfirmNCall(msg, jsCall, jsCancelCall)
{
   var tf = SWEConfirm(msg);

   if (tf)
   {
      eval(jsCall);
   }
   // PR 12-LFSYYX: Port PR 12-IKA10V
   else if (jsCancelCall != null)
   {
      eval(jsCancelCall);
   }   
}

var   g_bInitialized = false;

// JAVASCRIPT FUNCTION -- DOES NOTHING (USED FOR THE HREF IN THE CALENDAR and calculator CALL)
function doNothing() {
}

// Deprecated & slow. Kept around for backward compatibility.
// Do not introduce new usage of this function.
function SWEJSSInvokeMethod (
                       appletVar,
                       method, 
                       viewId,
                       view, 
                       applet,                        
                       field,
                       row, 
                       rowIds,
                       reqRowId,
                       inputps,
                       targetView,
                       targetApplet,
                       mode,
                       showPopup,
                       height,
                       width,
                       reqCount,
                       confirmMsg,
                       keepCtx,
                       seqId,
                       resize)
{
   if(confirmMsg != null && confirmMsg != "" )
   {
      var tf = SWEConfirm(confirmMsg);
      if (!tf)
      {
         return;
      }
   }

   var pset = App().NewPropertySet ();
   var bMethod = false;

   if (method != null)
   {
      pset.SetProperty ("SWEMethod", method);
      bMethod = true;
   }

   if (viewId != null)
      pset.SetProperty ("SWEVI", viewId);
   
   if (view != null)
      pset.SetProperty ("SWEView", view);

   if (applet != null)
   {
      pset.SetProperty ("SWEApplet",applet);
      if (bMethod)
         pset.SetProperty ("SWECLK", "1");
   }

   if (seqId != null)
      pset.SetProperty ("SWESeq", seqId);

   if (field != null)
      pset.SetProperty ("SWEField", field);

   if (row != null)
      pset.SetProperty ("SWER", row);

   if (rowIds != null)
      pset.SetProperty ("SWERowIds", rowIds);

   if (reqRowId != null)
      pset.SetProperty ("SWEReqRowId", reqRowId);

   if (inputps != null)
      pset.SetProperty ("SWEIPS", inputps);

   if (targetView != null)
      pset.SetProperty ("SWETargetView", targetView);

   if (targetApplet != null)
      pset.SetProperty ("SWETA", targetApplet);

   if (mode != null)
      pset.SetProperty ("SWEM", mode);

   if (showPopup != null)
      pset.SetProperty ("SWESP", showPopup);

   if (height != null)
      pset.SetProperty ("SWEH", height);

   if (width != null)
      pset.SetProperty ("SWEW", width);

   if (reqCount != null)
      pset.SetProperty ("SWEC", reqCount);

   if (keepCtx != null)
      pset.SetProperty ("SWEKeepContext", keepCtx);

   if (resize != null)
   {
      //method is deprecated so removed the popup code
   }

   return App().GetView("").GetApplet(applet).InvokeMethod(method, pset);
}

//This function is only used for Calendar code, per Anil Mukundan's suggestion
//Please do not use this function for any other purpose.
//Contact Setiono Tandriono or Parthasarathy Ramachandran if you have any questions
//Please keep this function in sync with:
//       SSstring
//       CSSSWEFrame::CreateJSSInvokeMethodCall(CSSMapStringToString& jsArgs,
//                                              LPCTSTR               functionName)
//in framshow.cpp
//
function SWEJSSCalendarInvokeMethod (
                                      appletVar,
                                      method, 
                                      viewId,
                                      view, 
                                      applet, 
                                      field,
                                      row, 
                                      rowIds,
                                      reqRowId,
                                      inputps,
                                      targetView,
                                      targetApplet,
                                      mode,
                                      showPopup,
                                      height,
                                      width,
                                      reqCount,
                                      confirmMsg,
                                      keepCtx,
                                      rowId)
{
   if(confirmMsg != null && confirmMsg != "" )
   {
      var tf = SWEConfirm(confirmMsg);
      if (!tf)
      {
         return;
      }
   }

   var pset = App().NewPropertySet ();

   if (method != null)
      pset.SetProperty ("SWEMethod", method);

   if (viewId != null)
      pset.SetProperty ("SWEVI", viewId);
   else viewId = "";
   
   if (view != null)
      pset.SetProperty ("SWEView", view);

   if (applet != null)
      pset.SetProperty ("SWEApplet",applet);

   if (field != null)
      pset.SetProperty ("SWEField", field);

   if (row != null)
      pset.SetProperty ("SWER", row);

   if (rowIds != null)
      pset.SetProperty ("SWERowIds", rowIds);

   if (rowId != null)
      pset.SetProperty ("SWERowId", rowId);

   if (reqRowId != null)
      pset.SetProperty ("SWEReqRowId", reqRowId);

   if (inputps != null)
      pset.SetProperty ("SWEIPS", inputps);

   if (targetView != null)
      pset.SetProperty ("SWETargetView", targetView);

   if (targetApplet != null)
      pset.SetProperty ("SWETA", targetApplet);

   if (mode != null)
      pset.SetProperty ("SWEM", mode);

   if (showPopup != null)
      pset.SetProperty ("SWESP", showPopup);

   if (height != null)
      pset.SetProperty ("SWEH", height);

   if (width != null)
      pset.SetProperty ("SWEW", width);

   if (reqCount != null)
      pset.SetProperty ("SWEC", reqCount);

   if (keepCtx != null)
      pset.SetProperty ("SWEKeepContext", keepCtx);

   App().InvokeAppletMethod (viewId, applet, method, pset);
}



//
// Please contact Jay Gopalkrishnan before you use / modify this function.
// This is a temporary function that will go away with the view cache changes
//
function SWEJSSInvokeMethod_Temp (
                       appletVar,
                       method, 
                       viewId,
                       view, 
                       applet, 
                       field,
                       row, 
                       rowIds,
                       reqRowId,
                       inputps,
                       targetView,
                       targetApplet,
                       mode,
                       showPopup,
                       height,
                       width,
                       reqCount,
                       confirmMsg,
                       keepCtx)
{
   Top().SetBusy(true);

   if(confirmMsg != null && confirmMsg != "" )
   {
      var tf = SWEConfirm(confirmMsg);
      if (!tf)
      {
         Top().SetBusy(false);
         return;
      }
   }

   var pset = App().NewPropertySet ();

   if (method != null)
      pset.SetProperty ("SWEMethod", method);

   if (viewId != null)
      pset.SetProperty ("SWEVI", viewId);
   
   if (view != null)
      pset.SetProperty ("SWEView", view);

   if (applet != null)
      pset.SetProperty ("SWEApplet",applet);

   if (field != null)
      pset.SetProperty ("SWEField", field);

   if (row != null)
      pset.SetProperty ("SWER", row);

   if (rowIds != null)
      pset.SetProperty ("SWERowIds", rowIds);

   if (reqRowId != null)
      pset.SetProperty ("SWEReqRowId", reqRowId);

   if (inputps != null)
      pset.SetProperty ("SWEIPS", inputps);

   if (targetView != null)
      pset.SetProperty ("SWETargetView", targetView);

   if (targetApplet != null)
      pset.SetProperty ("SWETA", targetApplet);

   if (mode != null)
      pset.SetProperty ("SWEM", mode);

   if (showPopup != null)
      pset.SetProperty ("SWESP", showPopup);

   if (height != null)
      pset.SetProperty ("SWEH", height);

   if (width != null)
      pset.SetProperty ("SWEW", width);

   if (reqCount != null)
      pset.SetProperty ("SWEC", reqCount);

   if (keepCtx != null)
      pset.SetProperty ("SWEKeepContext", keepCtx);

   //CR 12-HXAFMJ removed closepopup
   App().InvokeAppletMethod (viewId, applet, method, pset);
   pset = null;

   Top().SetBusy(false);
}

function SWEJSSBusServiceInvokeMethod (serviceName, methodName, strInPropSet)
{
   var service = App ().GetService (serviceName);
   var inPropSet = App ().NewPropertySet ();
   inPropSet.DecodeFromString (strInPropSet);
   var outPropSet = service.InvokeMethod (methodName, inPropSet);
   var result = outPropSet.EncodeAsString ();
   service = null; 
   inPropSet = null;
   outPropSet = null;
   return (result);   
}

// JAVASCRIPT FUNCTION -- Create Hidden Fields in HTML Forms (J.Huang) 
function c_h (id, inputNames, inputValues) 
{
   var size;
   var text;
   var elem;
	if (inputValues.length != inputNames.length)
	{
      SWEAlert ("error found in writting hidden inputs");
   }
	if (inputValues.length > inputNames.length)
	{
		size = inputNames.length;
	}
	else
	{
		size = inputValues.length;
	}
   
   text = "";
   for (var i = 0; i < size; i++) 
   {
       text += "<input type=\"hidden\" name='" + inputNames[i] + "' value='" + HtmlEncode(inputValues[i]) + "'>";
   }
   elem = document.getElementById(id);
   if (elem)
      elem.innerHTML = text;
}

// SWERefresh(): Called upon closing a popup to refresh the page
// anchor - Used to specify the frame that should be active/anchored to. 
function SWERefresh(targetFrame, url, anchor, targetWindow)
{
   if (url == null || url == "")
   {    
      if (top.opener != null && top.opener.SWEDoRefresh != null)
         top.opener.SWEDoRefresh(anchor);      
      else if (this.SWEDoRefresh != null)
         SWEDoRefresh(anchor);            
   }
   else
   {
      if (targetWindow != "undefined" && targetWindow == "_self")
      {
         SWETargetGotoURL(url, top);
      }
      else if (top.opener != null && top.opener.SWEDoRefresh != null)
         SWETargetGotoURL(url, top.opener);
      else if (targetFrame != null && targetFrame != "")
      {
         var targetFrameObj = eval(targetFrame);
         SWETargetGotoURL(url, targetFrameObj);
      }
    }
}

function SWEJSS_gotoText(id)
{
   var select	= document.all[id + "sel"];
   var text	= document.all[id + "txt"];
   var button	= document.all[id + "btn"];
	
   if (select.style.display != "none")
      text.value = select.options(select.options.selectedIndex).innerText;
   select.style.display = "none";
   text.style.display = "block";
   text.disabled = true;
   button.style.display = "block";
}

// Submit Form when ENTER key pressed on an Input. (For both IE and NS)
// This function is not a generic function to capture 'Enter's. It is specific
// to the password field of the siebel login page. (PageItemName = _SwePassword)
function SWESubmitOnEnter (e)
{
   var keyCode = e ? e.which : window.event.keyCode;
   var formObj = e ? e.target.form : window.event.srcElement.form;

   if (keyCode == 13)
   {
     SWEExecuteLogin(formObj, null, null);
   }
}

var g_sweobj = null;
var g_oInterval = null;
var g_swecmd1 = null;
var g_swecmd2 = null;

function RecurGetJSS ()
{
   eval (g_swecmd2);
   if (g_sweobj != null)
   {
      eval (g_swecmd1);
      clearInterval (g_oInterval);
   }
}

function GetJSSInfo (sweobj, cmd1, cmd2)
{
   g_swecmd1 = cmd1;
   g_swecmd2 = cmd2;  
   if (sweobj == null)
   {
      g_oInterval = window.setInterval ("RecurGetJSS()", 3000);   
   }
   else
   {
      eval (cmd1);
   }
}  


var shutdown = false;
function HandleEvent(event, lparam, rParam) 
{ 
   switch (event)
   {
      // 12-HYGI1Z+F: Port SI busy state cursor from 7.5.x
      case "Disable":
         if (document.all)
         {
            if (lparam)
            {
               if (dvBusy.style.display!="block")
               {
                  dvBusy.style.width = document.body.clientWidth;
                  dvBusy.style.height = document.body.scrollHeight;

                  dvBusy.style.display="block";

                  if (Top().g_menuCursor != null)
                     dvBusy.style.cursor=Top().g_menuCursor;
                  else
                     dvBusy.style.cursor="wait";

                  if (Top().doBusyScroll)
                  {
                     dvScroll.scrollTop = 500;
                     dvScroll.scrollTop = 0;
                  }
               }
            }
            else
            {
               if (dvBusy.style.display!="none")
               {
                  dvBusy.style.display="none";

                  if (Top().g_menuCursor != null)
                     dvBusy.style.cursor=Top().g_menuCursor;
                  else
                     dvBusy.style.cursor="default";

                  if (Top().doBusyScroll)
                  {
                     dvScroll.scrollTop = 500;
                     dvScroll.scrollTop = 0;
                  }
               }
            }
         }
         break;

       case "ShutDown":
         shutdown = true;
         break;

      case "SetScreen":
         //lparam is the screen name
         SWESetScreen(lparam);
         break;
      
      case "UserQuery":
         var elem = document.getElementById("s_pdq");
         if (elem)
         {
            if (elem.options[0].value != "")
            {
               var newOpt = document.createElement("OPTION");
               newOpt.text = "";
               newOpt.value = "";
               elem.options.add(newOpt,0);
            }
            elem.selectedIndex = 0;
         }
         break;

      default:
         break;
   }
}

//This section has to stay in sync with the server side
if (typeof swetop == "undefined") 
{
	var swetop = null;
	// find the topmost window, but make sure it's a valid reference
	var parentWindow;
	var currentWindow;
	if (typeof window.parent != "undefined")
	{
		parentWindow = window.parent;
		currentWindow = window;
		while (currentWindow.parent != currentWindow ) 
		{
			if (typeof parentWindow.swetop != "unknown" && typeof parentWindow.swetop != "undefined") 
			{
				swetop = parentWindow.swetop;
				break;
			}
			if (typeof currentWindow.parent != "undefined")  
			{
				currentWindow = parentWindow;
				parentWindow = parentWindow.parent;
			} 
			else 
				break;
		}
	}
	
   // find the "top" window" in case swetop was not yet found but is defined in the opener
   // 12-FCIWKO Added support to climb back up the hierarchy tree and find swetop.   
   winOpener = window.opener;   

   // CR 12-KKHFH0 and PR 12-KXD5BK: In NS exception is thrown immediately when window.opener.swetop is accessed
   try
   {
      while(winOpener != null)
      {     
         if (typeof winOpener.swetop != "unknown")
         {
            swetop = winOpener.swetop;
            break;
         }

         if (typeof winOpener.opener != "unknown" && typeof winOpener.opener != "undefined")
         {
            winOpener = winOpener.opener;
         }
         else
         {
            winOpener = null;
         }
      }
   }
   catch (e)
   {
      // Do nothing
   }

   if (swetop == null)
      swetop = window;
}

function Top()
{
   return swetop;
}
   

function App() 
{ 
   return Top()._swe._sweapp.S_App; 
}

function SWESetScreen(screenTab)
{
   var objFrame = SWEFindFrame(top, "_swescrnbar");
   if (objFrame == null || objFrame != this)      
      return;
   st_scrn(screenTab.name, -1, screenTab);
}

function SWEExecuteCommand(formObj, action, command, bPopup, height, width, target)
{
   if (! g_bInitialized)
      return;

   if (action != null)
      formObj.action = action;

   if (command != null)
      formObj.SWECmd.value = command;

   if (bPopup == "true" || bPopup == "TRUE")
   {
      if(SWEIsHighInteract)
      { 
         App().OpenPopup("", parseInt(height), parseInt(width),false,false,true);
      }
      else
      {
         SWEShowPopup ("", parseInt(height), parseInt(width), "false");
      }
   }
   if (target != null && target != "")
   {
      formObj.target = target;
   }
   if (SWEIsHighInteract)
   {
      App().SubmitForm(formObj);
   }
   else
   {
      formObj.submit();
   }
}

function SWEPersonalizationDrillDown (viewName, appletName, fieldName, rowId, parentRowIds)
{
   SWEPersonalizationDrillDown_top (viewName, appletName, fieldName, rowId, parentRowIds, this);
}


function SWESubmitForm (csFormObj, csObj, fieldName, rowId, csFrame)
{
   var bRet      = true;
   var height    = 480;
   var width     = 640;
   var objFrame, obj, formObj;

   // adding warning message when waiting for file import
   if (csFormObj.encoding == "multipart/form-data" &&
       document.getElementById("s_swe_filepop_add") != 'undefined' &&
       Top().SWEIsHighInteract && csObj.SWEMethod == "WriteRecord")
   {
      var swefile = document.getElementById("s_SweFileName");

      if (swefile.value != "")
      {
         //  insert warning message
         var msg = App().GetLocalString ("IDS_FILE_IMPORT_PROMPT");
         var oText = document.createElement("B");
         document.body.insertBefore(oText);
         oText.innerText = msg;
         
         App().SetPopupVisible(true);
      }
   }

   if (typeof(csFrame) != 'undefined')
   {
      objFrame = csFrame;
      if (objFrame == null)
      {
         SWEAlert("Fail to submit form due to invalid objFrame!");
         return;
      }
      formObj = objFrame[csFormObj];
      obj = objFrame[csObj];
   }
   else
   {
      obj = csObj;
      formObj = csFormObj;
   }

   if (pendingChanges()&& 
       ((typeof(obj.SWEApplet) != 'undefined' && typeof(top.SWEApplets) != 'undefined' && typeof(top.SWEApplets[top.CurrentAppletIndex]) != 'undefined' && obj.SWEApplet != top.SWEApplets[top.CurrentAppletIndex].Name) || 
       (typeof(obj.SkipDataLossWarning) == 'undefined' && StopForSavingData())))
   {
      return;
   }
   SWESubmitForm_top (obj, formObj, fieldName, rowId);
  
   if(!SWEIsHighInteract)
   {
      if (typeof(obj.SWESPNH) != 'undefined')
         SWESetPopupResizeNoHide(true);

      if (typeof(obj.SWEH) != 'undefined')
         height = obj.SWEH;

      if (typeof(obj.SWEW) != 'undefined')
         width = obj.SWEW;

      if (typeof(obj.SWESPNR) != 'undefined')
      {
         Top().SWEPopupResizeNoAuto = true;
         Top().SWEPopupHeight = height;
         Top().SWEPopupWidth = width;
      }
    
      if (typeof(obj.SWESP)  == 'TRUE' || obj.SWESP  == 'true')
      {
         if (formObj.SWETVI.value ==  Top().SWEHtmlPopupName &&
             formObj.SWETA.value == "" )
             bRet = SWEShowPopup ("", height, width, "false", "false", "scrollbars");
         else
             bRet = SWEShowPopup ("", height, width, "false");
    
     if (typeof (Top().showNSPopup) != "undefined" && Top().showNSPopup == false)
     {
     	 return;
     }
              
         formObj.target = Top().SWEHtmlPopupName;

         if (typeof(formObj.SWESP) != 'undefined')
            formObj.SWESP.value = obj.SWESP;
      
      }
   }
   else
   {
      if (typeof(obj.SWEH) != 'undefined')
      {
         formObj.SWEH.value = obj.SWEH;
      }
      if (typeof(obj.SWEW) != 'undefined')
      {
         formObj.SWEW.value = obj.SWEW;
      }
      if (typeof(obj.SWESPNR) != 'undefined')
      {
         formObj.SWESPNR.value = true;        
      }
      if (typeof(obj.SWESP)  == 'TRUE' || obj.SWESP  == 'true')
      {
          formObj.SWESP.value = obj.SWESP;

          // in case we are opening the popup from non-main view (e.g. Search), need to set 
          // the opener to the view from which popup was opened.  Otherwise refreshing
          // parent will not work properly
          formObj.SWEWN.value = window.name;
      }
      else
      {
        // 12-H2ODXR: Need to reset the value to false to avoid displaying the contents
        // of the browser in a popup when not needed.
        formObj.SWESP.value = false;
        
        if (typeof(formObj.SWEWN) != 'undefined')
        {
            formObj.SWEWN.value = "";
        }
      }
      if (typeof(obj.SWESPNH) != 'undefined' && typeof(formObj.SWESPNH) != 'undefined')
      {
           // 12-HJKXEX: Passed to AxApp to avoid SI popup disappearing and then reappearing
           formObj.SWESPNH.value = true;
      }
   }
   if (typeof(top._samePage) != 'undefined' && top._samePage!="")
   {
       formObj.SWESPa.value = top._samePage;
       top._samePage = "";
   }
   else if (formObj.SWEPOC.value != "")
      top._samePage = "1";

   if (SWEIsHighInteract)
   {
      App().SubmitForm(formObj);
   }
   else
   {
      formObj.submit();
   }
}

function SweClickAddPopup()
{
  if (typeof(s_swe_filepop_add) != 'undefined')
  {
      s_swe_filepop_add.click();
  }
}

//Pointer to functions in the hidden frame
if (typeof (Top()._swescript) != "undefined")
{
	var hiddenFrame                   = Top()._swescript;
	c_d                               = hiddenFrame.c_d;
	EvalFrame                         = hiddenFrame.EvalFrame;
	HtmlEncode                        = hiddenFrame.HtmlEncode;
	pendingChanges                    = hiddenFrame.pendingChanges;
	ResetScreen                       = hiddenFrame.ResetScreen;
	SWEAlert                          = hiddenFrame.SWEAlert;
	SetAppCookie                      = hiddenFrame.SetAppCookie;
	SetScreen                         = hiddenFrame.SetScreen;
	SetDefaultFocus                   = hiddenFrame.SetDefaultFocus;
	StopForSavingData                 = hiddenFrame.StopForSavingData;
	SWEAppendArgsToURL                = hiddenFrame.SWEAppendArgsToURL;
	SWEClosePopup                     = hiddenFrame.SWEClosePopup;
	SWEConfirm                        = hiddenFrame.SWEConfirm;
	SWEFormReset                      = hiddenFrame.SWEFormReset;
	SWEGetAvailScreenHeight           = hiddenFrame.SWEGetAvailScreenHeight;
	SWEGetAvailScreenWidth            = hiddenFrame.SWEGetAvailScreenWidth;
	SWEGetScreenHeight                = hiddenFrame.SWEGetScreenHeight;
	SWEGetScreenWidth                 = hiddenFrame.SWEGetScreenWidth;
	SWEJSSFindAppletFrame             = hiddenFrame.SWEJSSFindAppletFrame;
	SWEJSSGetAppletObj                = hiddenFrame.SWEJSSGetAppletObj;
	SWEJSSGetAppletObjShadow          = hiddenFrame.SWEJSSGetAppletObjShadow;
	SWEPersonalizationDrillDown_top   = hiddenFrame.SWEPersonalizationDrillDown_top;
	SWEPersonalizationGotoScreen      = hiddenFrame.SWEPersonalizationGotoScreen;
	SWEPersonalizationGotoview        = hiddenFrame.SWEPersonalizationGotoview;
	SWEPopupGainFocus                 = hiddenFrame.SWEPopupGainFocus;
	SWEPopupMessage                   = hiddenFrame.SWEPopupMessage;
	SWEPosition                       = hiddenFrame.SWEPosition;
	SWEShowNamedPopup                 = hiddenFrame.SWEShowNamedPopup;
	SWEReloadApp                      = hiddenFrame.SWEReloadApp;
	SWESubmitForm_top                 = hiddenFrame.SWESubmitForm_top;
	SWEUnloadApp                      = hiddenFrame.SWEUnloadApp;
	SweValidateSubmit                 = hiddenFrame.SweValidateSubmit;
	trackChange                       = hiddenFrame.trackChange;
	URLEncode                         = hiddenFrame.URLEncode;
}


function SWEGotoPageRC(PageName,url, target, bLeaveApplet)
{ 
   var pset = top._swescript.CCFMiscUtil_CreatePropSet ();
   pset.SetProperty ("PageItem", PageName);
   App().FireRecorderEvent(App().GetName(), "GoToContainerPageItem", 0, 0, "", pset);
   
   SWETargetGotoURL(url, target, bLeaveApplet); 
}


function SWEIsBrowserBack(pageId)
{
   return ((pageId<Top().SWEServerCount)?true:false);
}


function SWESyncCheck(pageId, errMsg)
{
   if (SWEIsBrowserBack(pageId))
   {
      // client is not in sync with the server
      alert(errMsg);
      if (pageId <= Top().SWECount) // the user is click on back button
         history.back();
      else                          // the user is click on forward button
         history.forward();
   }
}

//12-H63TT7: Hitting back button on browser after logout or session timeout allows user to login back in.
//For logoff and timeout redirect command, we shall use this js function to send out the request
//so that the login request can be removed from the history.
function SWEClearHistoryGotoURL (url, bTimeout)
{
	Top().location.replace(url);
}

// following 2 functions are added for FR12-1BJOS21 to activate ActiveX Controls
function SWEWriteObjectTag (target, objectTag)
{
   target.document.write(objectTag);
}

function SWEWriteInnerHTML (target, objectTag)
{
   target.innerHTML = objectTag;
}



      




