/*  Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    ToolsRel: 8.51.10 */
var gFocusObj = null;
var bRichTextEnabled = 0;
var gRichTextField = null;
var bTimer=null;
var objIframe;     // edit prompt iframe 
var objIframeDoc;  // edit prompt iframe document

if (window.showhide == null)
{
window.showhide = function (obj, bShow)
    {
    if (obj == null)
        return;
    if (bShow)
        {
        obj.style.top = getScrollY();
        var x = getScrollX();
        obj.style.right = (x > 0) ? (0 - x) : x;	
        obj.style.visibility = "visible";
        obj.style.display = "block";
        }
    else
        {
        obj.style.visibility = "hidden";
        obj.style.display = "none";
        }
    }
}

function SetPromptIframeDoc_win0()
{
objIframe = document.getElementById('popupFrame');
if (objIframe)
   objIframeDoc = window.frames[objIframe.name].document;
}

function setSaveText_win0(txt)
{
var saveobj = document.getElementById("SAVED_win0");
if (saveobj)
   {
   document.getElementById("ptStatusText_win0").innerHTML = txt;
   showhide(saveobj, true);
   document.getElementById("saveWait_win0").style.display = "";
   }
}

function processing_win0(opt,waittime)
{
var waitobj = document.getElementById("WAIT_win0");
var saveobj = document.getElementById("SAVED_win0");
var saveWaitObj = document.getElementById("saveWait_win0");
if (opt == 0)
{
    showhide(waitobj, false);
    showhide(saveobj, false);
    return;
}
if (opt == 1)
{
    if (saveobj && (saveobj.style.visibility != "hidden") && (saveobj.style.display != "none")
       && (saveWaitObj.style.display != "none"))
       return;
    showhide(waitobj, true);
    showhide(saveobj, false);
    if(typeof bTimer != "undefined" && bTimer != null)
      clearTimeout(bTimer);
    return;
}
if (opt == 2)
{
    showhide(waitobj, false);
    setSaveText_win0('Saved');
    if (saveWaitObj)
        saveWaitObj.style.display = "none";
    bTimer = setTimeout("processing_win0(0)",waittime);
}
}

function isAltKey(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return false;
if (evt.altKey)
    return true;
if (evt.modifiers)
    return (evt.modifiers & Event.ALT_MASK) != 0;
return false;
}

function isCtrlKey(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return false;
if (evt.ctrlKey)
    return true;
if (evt.modifiers)
    return (evt.modifiers & Event.CONTROL_MASK) != 0;
return false;
}

function isShiftKey(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return false;
if (evt.shiftKey)
    return true;
if (evt.modifiers)
    return (evt.modifiers & Event.SHIFT_MASK) != 0;
return false;
}

function getKeyCode(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return 0;
if (evt.keyCode)
    return evt.keyCode;
if (evt.which)
    return evt.which;
return 0;
}

function cancelBubble(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return;
if (typeof evt.cancelBubble != "undefined")
    evt.cancelBubble = true;
if (typeof evt.stopPropagation != "undefined" && evt.stopPropagation)
    evt.stopPropagation();
}

function isPromptKey(evt)
{
if (isAltKey(evt) && getKeyCode(evt) == "5".charCodeAt(0))
{
    cancelBubble(evt);
    return true;
}
return false;
}

function getEventTarget(evt)
{
if (!evt && window.event)
    evt = window.event;
if (!evt)
    return null;
if (evt.srcElement)
    return evt.srcElement;
if (evt.target)
    return evt.target;
return null;
}

function getModifiers(evt)
{
var res = "";
if (isAltKey(evt))
    res += "A";
if (isCtrlKey(evt))
    res += "C";
if (isShiftKey(evt))
    res += "S";
return res;
}

var nLastKey_win0 = 0;

function doKeyDown_win0(evt)
{
var target = getEventTarget(evt);

if (target && target.form && target.form.name != "win0")
    return findHandler("doKeyDown_" + target.form.name, evt);

nLastKey_win0 = getKeyCode(evt);
if (nLastKey_win0 != "\t".charCodeAt(0)) {

if (ptCommonObj.isGridNav(evt))
	ptGridObj_win0.doArrowNavGrid(evt);

if (ptCommonObj.isTypeAheadEl(evt))
 	ptTAObj_win0.KeyUpDown(evt);

    return true;
}

if (isCtrlKey(evt))
    return tryFocus(oFirstTab_win0);
if (isAltKey(evt) || (isShiftKey(evt) && !ptCommonObj.isGridNav(evt)))
    return true;

if (target == oLastTab_win0)
{
if (oFirstTB_win0)
    {
    if (!bTabOverTB_win0)
        return true;
    }
if (oFirstPg_win0)
    {
    if (!bTabOverPg_win0)
        return tryFocus(oFirstPg_win0);
    }
if (bTabOverNonPS_win0 || oFirstTB_win0 != null || oFirstPg_win0 != null)
    return tryFocus(oFirstTab_win0);
return true;
}
if (target == oLastTB_win0)
{
  if (oFirstPg_win0)
  {
    if (!bTabOverPg_win0)
       return tryFocus(oFirstPg_win0);
  }
  if (bTabOverNonPS_win0 || oFirstPg_win0 != null)
    return tryFocus(oFirstTab_win0);
  return true;
}

if (target == oLastPg_win0)
{
  if (bTabOverNonPS_win0)
    return tryFocus(oFirstTab_win0);
  return true;
}

if (nLastKey_win0 == "\t".charCodeAt(0) && ptCommonObj.isTypeAheadEl(evt))
{
	ptTAObj_win0.KeyUpDown(evt);
	return true;
}

}

function getLastKey_win0()
{
var nTemp = nLastKey_win0;
nLastKey_win0 = 0;
return nTemp;
}

function doKeyUp_win0(evt)
{

var target = getEventTarget(evt);
if (target && target.form && target.form.name != "win0")
    return findHandler("doKeyUp_" + target.form.name, evt);
var key = getKeyCode(evt);
var keyChar = String.fromCharCode(key);
if (isCtrlKey(evt) && key == 220) //debugger console ctl-\
    	{
        ptConsole.active();
        return false;
    	}
if (keyChar == "\r" || key == 27)
	{
    
    if (target != null && target.id.indexOf("$delete") != -1)
       {
	   DeleteCheck2_win0(target.id);
	   return;
	   }

	if (typeof(bPromptPage_win0) != "undefined" && bPromptPage_win0)
		{
		
		if (key == 27)	
			ptCommonObj.updatePrompt(document.win0, "#ICCancel");
		}
	else if (typeof(bModalPage_win0) != "undefined" && bModalPage_win0)
		{
		if (key == 27)
			
		    if (popupModalObj_win0.isModalElement)
		     
		       ptCommonObj.endModalCntrl(document.win0, "#ICOKZG", true);
		    else
		       ptCommonObj.endModalCntrl(document.win0, "#ICCancel");	
		else if (target != null && (target.href		
				|| typeof target.onclick == "function"
				|| target.tagName == "SELECT"   	
				|| target.tagName == "HTML"			
				|| target.tagName == "BODY"			
				|| target.type == "textarea"))		
			;
		else if (popupModalObj_win0.isModalElement)
		    
		  	ptCommonObj.endModalCntrl(document.win0, "#ICOKZG", true);
		else if (baseKey_win0.indexOf("\r") < 0)
			
  			ptCommonObj.endModalCntrl(document.win0, "#ICSave");
		}
	return true;
	}

if (!routeKeyEvent(evt))
    return false;
var bAlt = isAltKey(evt);
var bCtrl = isCtrlKey(evt);
var bNotMine = false;
if (bAlt)
	{
    if (bCtrl || altKey_win0.indexOf(keyChar) < 0)
        if (keyChar == "9" || key == 220 || key == 186)
            return true;
        else
            bNotMine = true;
	}
else if (bCtrl)
	{
    if (key == 88 || key == 120) //debugger console ctl-x
    	{
        ptConsole.deactive();
        return false;
    	}
    keyChar = String.fromCharCode(key | 0x40);
    if (ctrlKey_win0.indexOf(keyChar) < 0)
        bNotMine = true;
	}
else
	{
    if (baseKey_win0.indexOf(keyChar) < 0)
    bNotMine = true;
	}

if (bNotMine) {

	
	if (bAlt || bCtrl) {
			
		
		var navFrame = parent.frames["NAV"];
        if (!navFrame) {
            navFrame = parent.frames["UniversalHeader"];
		}	
		if (navFrame && !isCrossDomain(navFrame) && navFrame.parentKeyHandler) {
            navFrame.parentKeyHandler(window, key, bAlt, bCtrl);
		
		} else if (!isCrossDomain(parent) && parent.ptIframe && parent.ptIframe.parentKeyHandler) {
			parent.ptIframe.parentKeyHandler(window,key,bAlt,bCtrl);
        }
	}
	if (ptCommonObj.isGridNav(evt)) //for grid
    	ptCommonObj.terminateEvent(evt);

    if (ptCommonObj.isTypeAheadEl(evt)) // for type ahead suggest
		ptTAObj_win0.GiveOptions(evt);

	return true;
}


var code = getModifiers(evt) + keyChar;
if (target && target.name)
    document.win0.ICFocus.value = target.name;

if (code == "A8")
    if (!doDeleteKey_win0(target))
        return false;
if (code == "A\xbf")
{
    if (window.FindString_win0
    && document.win0.ICFind
    && findScroll(target))
    {
        if (!FindString_win0(document.win0.ICFind))
            return false;
    }
else
    return false
}

if (code == "A7")
    if (!doInsertKey_win0(target))
        return false;

if (code == "A\xbc" || code == "A\xbe" || code == "A\xde")
    if (!activeLink(target,code))
        return false;

if (code == 'A5')
{
var id_s = target.id.split("$")[0];
var occ_s = target.id.split("$")[1];
var pid = id_s+"$prompt";
if (occ_s && typeof occ_s != "undefined")
pid +="$"+occ_s;
var pobj = document.getElementById(pid);
var operation = "";
if (!pobj || typeof pobj == "undefined" ) {
     pid = id_s+"$spellcheck";
     if (occ_s && typeof occ_s != "undefined")
     pid +="$"+occ_s;
     pobj = document.getElementById(pid);
     if (pobj && typeof pobj != "undefined" ) operation = "$spellcheck";
   }

if (!pobj || typeof pobj == "undefined" ) {
    pid = target.id+"$prompt";
    pobj = document.getElementById(pid);
    if (!pobj || typeof pobj == "undefined" )
        return false;
}
}

if (saveWarningKeys_win0.indexOf(code) >= 0)
{
   var url = "javascript:submitAction_win0(document.win0, \'#KEY" + code;
   if (code == 'A5')
	     url = url  + "\', " + target.id + ")";
   else
        url = url + "\')";
   if (!saveWarning("", null, "", url))
        return false;
}

if (key == 13 && !ptCommonObj.isSearchPage(target.form)) //enter key pressed
{
 if (typeof event != "undefined")
    submitAction_win0(document.win0, event.srcElement.id);
 else // for firefox
    submitAction_win0(document.win0, evt.target.id);
}else
{
if (target && target.form)
    addchg_win0(target);
if (code == 'A5')
 submitAction_win0(document.win0, "#KEY" + code + operation, target.id);
else {
 if (bAlt && (key == 49)) //Alt+1 = Saving
    setSaveText_win0('Saving...', true, false);
 submitAction_win0(document.win0, "#KEY" + code);
 }
}

return false;
}

function activeLink(obj, akey)
{
var scrl = findScroll(obj);
var btnid;
if (!scrl) {
    
    if (akey == "A\xbc")
        btnid = "#ICPrevPage";
    else if (akey == "A\xbe")
        btnid = "#ICNextPage";
    else
        return false;

    var btn = document.getElementById(btnid);
    if (btn)
        return true;
    else
        return false;
    }
if (akey == "A\xbc")
    btnid = "\$hup\$";
else if (akey == "A\xbe")
    btnid = "\$hdown\$";
else if (akey == "A\xde")
    btnid = "\$hviewall\$";
btnid = scrl.id.replace(/\$scroll[im]?\$/,btnid);
var btn = document.getElementById(btnid);
if (btn)
    return true;
return false;
}

function findHandler(handlerName, evt)
{
var obj = window[handlerName];
if (typeof obj == "function")
    return obj(evt);
return true;
}

function keyHandler(keyCode, bIsAlt, bIsCtrl)
{
return keyHandler_win0(keyCode, bIsAlt, bIsCtrl);
}

function keyHandler_win0(keyCode, bIsAlt, bIsCtrl)
{
var keyChar = String.fromCharCode(keyCode);
var code = "";
if (bIsAlt)
{
    code = "A";
    if (bIsCtrl || altKey_win0.indexOf(keyChar) < 0)
        return false;
}
else if (bIsCtrl)
{
    code = "C";
    keyChar = String.fromCharCode(keyCode | 0x40);
    if (ctrlKey_win0.indexOf(keyChar) < 0)
        return false;
}
else
    return false;
code += keyChar;

if (code  == "A8" || code == "A\xbf" || code == "A7")
    return false;

if (target && target.form)
    addchg_win0(target);

submitAction_win0(document.win0, "#KEY" + code);
return true;
}

function doDeleteKey_win0(obj)
{
if (!window.DeleteCheck2_win0)
    return false;
var scroll = findScroll(obj);
if (!scroll)
    return false;
if (scroll.id.search(/^(.*)(\$scroll[im]?\$)(.*)$/,"$fdelete$") < 0)
    buttonid = scroll.id;
else
    buttonid =  RegExp["$1"] + "$fdelete$" +  RegExp["$3"];
if (document.getElementById(buttonid))
    return DeleteCheck2_win0(buttonid);
if (obj.name == null || obj.name.search(/\$(\d*)(\$\$\d*)?$/) < 0)
    return false;
var row = RegExp.$1;
if (buttonid.search(/^(.*)(\$fdelete\$)(.*)$/) < 0)
    return false;
buttonid = RegExp["$1"] + "$delete$" + row + "$$" + RegExp["$3"];

if (document.getElementById(buttonid))
    return DeleteCheck2_win0(buttonid);
return false;
}

function doInsertKey_win0(obj)
{
if (!window.AddMultiple_win0)
    return false;
var scroll = findScroll(obj);
if (!scroll)
    return false;
var bHasInsertBtn = false;
if (scroll.id.search(/^(.*)(\$scroll[im]?\$)(.*)$/,"$fnew$") < 0)
    buttonid = scroll.id;
else
    buttonid =  RegExp["$1"] + "$fnew$" +  RegExp["$3"];
if (document.getElementById(buttonid))
    bHasInsertBtn = true;
if (obj.name == null || obj.name.search(/\$(\d*)(\$\$\d*)?$/) < 0)
    return false;
var row = RegExp.$1;
if (buttonid.search(/^(.*)(\$fnew\$)(.*)$/) < 0)
    return false;
buttonid = RegExp["$1"] + "$new$" + row + "$$" + RegExp["$3"];
if (!bHasInsertBtn)
{
    if(document.getElementById(buttonid))
        bHasInsertBtn = true;
}
if (!bHasInsertBtn)
{
    /* try multiple insert key */
    buttonid = RegExp["$1"] + "$newm$" + row + "$$" + RegExp["$3"];
    if(document.getElementById(buttonid))
        bHasInsertBtn = true;
}
if (bHasInsertBtn)
{
    if (scroll.id.match(/\$scrollm\$/))
        return AddMultiple_win0(document.win0.ICAddCount);
    if (scroll.id.match(/\$scrolli\$/))
        return true;
}
return false;
}

function findScroll(obj)
{
while (obj)
{
    if (typeof obj.id  != "undefined")
        if (obj.id.match(/\$scroll/))
            return obj;
    if (typeof obj.parentNode != "undefined")
        obj = obj.parentNode;
    else    if (typeof obj.offsetParent != "undefined")
        obj = obj.offsetParent;
    else
        return null;
}
}

if (window.doKeyPress_win0 == null)
{
window.doKeyPress_win0 = function (evt)
    {
    var target = getEventTarget(evt);
	if (target && target.form)
     	addchg_win0(target);

    if (target && target.form && target.form.name != "win0")
        return findHandler("doKeyPress_" + target.form.name, evt);

    var key = getKeyCode(evt);
    var keyChar = String.fromCharCode(key);
    if (key==27)	
    	{
        
        if (typeof(MOpopupObj_win0.bIs_shown) != "undefined" && MOpopupObj_win0.bIs_shown)
            return MOpopupObj_win0.StopAccess(evt);   // close mouseover popup
 		if (typeof(bPromptPage_win0) != "undefined" && bPromptPage_win0)
        	return true;
		else if (typeof(bModalPage_win0) != "undefined" && bModalPage_win0)
        	return true;
        else if (ptCommonObj.isTypeAheadEl(evt))		//ICE#1850813000
                return true;
	}

    if (keyChar != "\r" && key != 27)
        return true;

	/*if (keyChar == "\r" && typeof(bModalPage_win0) != "undefined" && bModalPage_win0)	
		{
		ShowOrCloseModalOnEnter(key, target);
		return true;
		}*/

    
    if (!routeKeyEvent(evt))
        return false;

    if (target && key != 27)
        {
        if ((typeof target.onclick == "function" || target.href)
        && target.type != "radio" && target.type != "checkbox")
            return true;
        if (target.type == "textarea")
            return true;
        }
    var code = getModifiers(evt) + keyChar;

    if (target && target.name)
        document.win0.ICFocus.value = target.name;

    var rc = ShowOrCloseModalOnEnter(key, target, "#KEY" + code);
    if (rc == 1)
        return true;
    else if (rc == -1)
        return false;

    
    if ((key == 13) && ptCommonObj.isTypeAheadEl(evt) && ptTAObj_win0.IsGrabHighlighted())
        {
	ptTAObj_win0.HideTheBox();
	return false;
        }
	
    submitAction_win0(document.win0, "#KEY" + code);
    return false;
    }
}

//display modal or close modal if a hyperlink/pushbutton that can display or close a modal
//is specified in ide as activate by enter key
function ShowOrCloseModalOnEnter(theKey, theTarget, theCode)
{
    if (theKey != 13) return 0;  // not ENTER key pressed

    if (typeof(bPromptPage_win0) != "undefined" && bPromptPage_win0)
	return 0;

    if (theTarget.type != "radio" && theTarget.type != "checkbox"
     && typeof document.activeElement.onclick == "function" || 	document.activeElement.href)
	return 0;

    if  (document.activeElement.id.indexOf("popup") != -1)
	return 1;

    var bSAVEBTN=false;  // flag to tell whether there is a PeopleTools OK button for hitting enter key in modal page that has OK & CANCEL buttons
    for (var j = 0; j < 2; j++)
        {
	
	var elements = null;
	if (j == 0)			
	    elements = document.getElementsByTagName('a');
	else
	    elements = document.getElementsByTagName('input');
	
        for (var i = 0; i < elements.length; i++)
            {
            if (elements[i].getAttribute('ActivateByEnter') != null)
               {
               if (elements[i].getAttribute('ActivateByEnter') == 'CLOSE')
                  {
                  ptCommonObj.endModalCntrl(document.win0,elements[i].name);
                  return 1;
                  }
               else
                  {
                  var params = elements[i].getAttribute('ActivateByEnter').split('-');
                  if (params[0] != 0 && params[1] != 0)
                      hAction_win0(document.win0,elements[i].name, params[0], params[1], params[2], true);
                  else
                      hAction_win0(document.win0,elements[i].name, params[0], params[1], params[2], true, true);
                  return 1;
                  }
               }  // end of if (elements[i].getAttribute('ActivateByEnter') != null)
            else if (elements[i].id == "#ICSave")   // save the SAVE button element in case a page has tools default OK button
               bSAVEBTN = true;
            }  // end of for (var i = 0; i < elements.length; i++)
        } // end of for (var j = 0; j < 2; j++)

   if (bSAVEBTN)
      {
      ptCommonObj.endModalCntrl(theTarget.form, theCode);
      return -1;
      }
   else
      return 0;
}

var oFirstTab_win0 = null;
var oLastTab_win0 = null;
var oFirstTB_win0 = null;
var oLastTB_win0 = null;
var oFirstPg_win0 = null;
var oLastPg_win0 = null;

var nFirstTBIndex = 5000;        var nFirstPgIndex = 10000;

function checkTabIndex(obj)
{
if (obj.tabIndex && obj.tabIndex >= 0)
{
    if (obj.tabIndex < nFirstTBIndex)
    {
        if (oLastTab_win0 == null || obj.tabIndex > oLastTab_win0.tabIndex)
            oLastTab_win0 = obj;
        if (oFirstTab_win0 == null || obj.tabIndex < oFirstTab_win0.tabIndex)
            oFirstTab_win0 = obj;
    }
    else if (obj.tabIndex < nFirstPgIndex)
    {
        if (oLastTB_win0 == null || obj.tabIndex > oLastTB_win0.tabIndex)
            oLastTB_win0 = obj;
        if (oFirstTB_win0 == null || obj.tabIndex < oFirstTB_win0.tabIndex)
            oFirstTB_win0 = obj;
    }
    else
    {
        if (oLastPg_win0 == null || obj.tabIndex > oLastPg_win0.tabIndex)
            oLastPg_win0 = obj;
        if (oFirstPg_win0 == null || obj.tabIndex < oFirstPg_win0.tabIndex)
            oFirstPg_win0 = obj;
    }
}
}

function setEventHandlers_win0(sFirst, sLast, bMac)
{
var focus1, focus2;
focus1 = function (evt) {doFocus_win0(this, true, true);};
focus2 = function (evt) {doFocus_win0(this, false, true);};
fchange = function(evt) {addchg_win0(this); };

var i;

if (sFirst!="")
{
    var docanchors = document.anchors;
    var docanclen = docanchors.length;

    for (i = 0; i < docanclen; ++i)
    {
        if (docanchors[i].name == sFirst) break;
    }
    for (++i; i < docanclen; ++i)
    {
        var anc =  docanchors[i];
        if (anc.name == sLast) break;
        checkTabIndex(anc);
        checkAccessKeys(anc);
                if  (typeof anc.onfocus != "function")
            anc.onfocus = focus1;
    }
}
var frm = document.win0;
if (!frm) return;
var frmlen = frm.length;
for (i = 0; i < frmlen; ++i)
{
    var frmi  =  frm[i];
    if (frmi.type=="hidden") continue;
    checkTabIndex(frmi);
    checkAccessKeys(frmi);

 	if (typeof frmi.onblur != "function") {
        frmi.onblur = fchange;
    }

 	if (typeof frmi.onchange != "function") {
        frmi.onchange = fchange;
    }

    if (typeof frmi.onfocus != "function")
    {
    if (typeof frmi.onclick == "function")
        frmi.onfocus = focus1;
    else
        frmi.onfocus = focus2;
    }
}
}
if (window.setKeyEventHandler_win0 == null)
{
    window.setKeyEventHandler_win0 = function ()
    {
    if (typeof(baseKey_win0) != "undefined")
        {
        document.onkeyup = doKeyUp_win0;
        if (baseKey_win0.indexOf("\r") >= 0 || baseKey_win0.indexOf("\x1b") >= 0)
            document.onkeypress = doKeyPress_win0;
        }
    document.onkeydown = doKeyDown_win0;
    }
}
var oTop = null;
var oBottom = null;
if (window.routeKeyEvent == null)
  {
  window.routeKeyEvent = function(evt)
  {
  if (!isAltKey(evt) || isCtrlKey(evt))
  return true;
  var key = getKeyCode(evt);
  var keyChar = String.fromCharCode(key);
  if (keyChar == "9"  && oTop != null)
  {
  oTop.focus();
  return false;
  }
  if (key == 220 && oBottom != null)
  {
  oBottom.focus();
  return false;
  }
    return true;
    }
  }
if (window.checkAccessKeys == null)
{
window.checkAccessKeys = function(obj)
{
  var attr = obj.getAttribute("PSaccesskey");
  if (attr == "9")
    oTop = obj;
  else if (attr == "\\")
    oBottom = obj;
}
}
function setFocus_win0(fldname, indx, oDoc0)
{
gRichTextField = fldname;
if(typeof CKEDITOR != 'undefined')
{
for ( var instanceName in CKEDITOR.instances )
{

if (instanceName == fldname)
{
bRichTextEnabled = 1;
gRichTextField = fldname;

}
}
}
if (bRichTextEnabled == 0)
{
var oDoc = null;
if (!oDoc0 || typeof oDoc0 == "undefined")
	oDoc = document;
else
	oDoc = oDoc0;
var obj = null;
if (oDoc.win0)
{
    obj = oDoc.win0.elements[fldname];
    if (!obj)
        obj = oDoc.win0[fldname];
}
if (!obj)
    obj = oDoc.getElementById(fldname);
if (!obj) return false;
if (indx >= 0 && obj.length && indx < obj.length)
    obj = obj[indx];
if (!oDoc0 || typeof oDoc0 == "undefined")
return !tryFocus(obj);
else
return !tryFocus0(obj);
}
}
function tryFocus(obj)
{
if (!tryFocus0(obj))
    gFocusObj = obj;
return;
}

function setFocusSecPageMessage_win0()
{
var obj;
obj = document.getElementById("#ICOK");
if (obj)
	return tryFocus(obj);
obj = document.getElementById("#ICYes");
if (obj)
	return tryFocus(obj);
obj = document.getElementById("#ICAbort");
if (obj)
	return tryFocus(obj);
obj = document.getElementById("#ICRetry");
if (obj)
	return tryFocus(obj);
}

function tryFocus0(obj)
{
if (obj && typeof obj.focus != "undefined" && !obj.disabled && obj.style.visibility!="hidden")
{
    var b = navigator.userAgent.toLowerCase();
    try {            // check access violation because of trying to focus on invisible field
       obj.focus();
    }
    catch (err) {
       return true;
    }
    if (b.indexOf("msie")!=-1)
       obj.setActive();

    if (window.focusHook)
        focusHook(obj);

var gn = ptCommonObj.isGridEl(null,obj.id);
if (gn != null)
    ptGridObj_win0.doScrollOnFocus(gn, obj);
return false;
}
return true;
}
if (typeof CKEDITOR != 'undefined') CKEDITOR.on( 'instanceReady', function( ev )
{
                 ev.editor.dataProcessor.writer.setRules( 'p',
                      {
                           indent : false,
                           breakBeforeOpen : false,
                           breakAfterOpen : false,
                           breakBeforeClose : false,
                           breakAfterClose : false
                         });

for ( var instanceName in CKEDITOR.instances )
{
if (instanceName == gRichTextField)
{
CKEDITOR.instances[instanceName].focus();
}
}
});


function keyPressHandler(e)
{
    var kCode  = (window.event) ? event.keyCode : e.keyCode;   // MSIE or Firefox?
    return kCode;
}

function UpdateEditorLinkedField()
{
   for ( var instanceName in CKEDITOR.instances )
      {
      if (document.getElementById(instanceName) != null)
         replaceImageSource(instanceName);
      }
}

function preSubmitProcessSpellcheck_win0(form, name) {
    var spellcheckobj = document.getElementById('SPELLCHECKSTRING');
    if (spellcheckobj && spellcheckobj != 'undefined' && RTEspellcheck == true) {
        var spellcheckstring = spellcheckobj.value;
        spellcheckobj.value = ReplaceRTESpellSpaces(spellcheckstring);
    }
}
function preSubmitProcessZoomGrid_win0(form, name) {
    if (name.indexOf('#ICOKZG') == 0) {
        form.ICModalWidget.value = 0;
        form.ICZoomGrid.value = 0;
        var oStateNum = document.getElementById(popupModalObj_win0.stateNumName);
        var oElemNum = document.getElementById(popupModalObj_win0.elemNumName);
        if (typeof oStateNum != 'undefined')
            oStateNum.value = form[popupModalObj_win0.stateNumName].value;
        if (typeof oElemNum != 'undefined')
            oElemNum.value = form[popupModalObj_win0.elemNumName].value;
    }
    else if (window.name == 'popupFrameWidget' && typeof form.ICZoomGrid != 'undefined' && form.ICZoomGrid.value) {
        if (typeof window.parent.popupObj_win0 != 'undefined' && typeof window.popupModalObj_win0 != 'undefined' && typeof window.popupObj_win0 != 'undefined') {
            if (!window.popupObj_win0.isShown && !window.popupModalObj_win0.isShown && !window.popupObj_win0.bPromptPageOpen && !window.popupObj_win0.bPromptMessageOpen && window.parent.popupObj_win0.isShown && window.parent.popupObj_win0.launchedFromModal) {
                if (typeof form.ICModalWidget != 'undefined')
                    form.ICModalWidget.value = 0;
                form.ICZoomGrid.value = 0;
            }
        }
    }
    else if (window.name == 'TargetContent' && typeof form.ICZoomGrid != 'undefined' && form.ICZoomGrid.value) {
        if (typeof window.popupObj_win0 != 'undefined' && typeof window.popupModalObj_win0 != 'undefined') {
            if (!window.popupObj_win0.isShown && !window.popupModalObj_win0.isShown && !window.popupObj_win0.bPromptPageOpen && !window.popupObj_win0.bPromptMessageOpen) {
                if (typeof form.ICModalWidget != 'undefined')
                    form.ICModalWidget.value = 0;
                form.ICZoomGrid.value = 0;
            }
        }
    }
}
function preSubmitProcessCKEDITOR_win0(form, name) {
    if (typeof CKEDITOR != 'undefined') UpdateEditorLinkedField();
}

function preSubmitProcess_win0(form, name) {
    if (!popupObj_win0.updatePromptActn && name.indexOf('#ICQryDownload') == -1) { processing_win0(1, 3000); }
    if ((name.indexOf('$delete') > 0 || name.indexOf('$srt') > 0) && typeof (preID_win0) != 'undefined' && preID_win0 != null) preID_win0 = null; //for grid row highlight
    if (form == null) {
        form = document.forms['win0'];
        form.style.display = 'block';
    }
    preSubmitProcessSpellcheck_win0(form, name);
    preSubmitProcessZoomGrid_win0(form, name);
    preSubmitProcessCKEDITOR_win0(form, name);
}

function aAction0_win0(form, name, params, bAjax, bPrompt)
{
if (loader != null && loader.GetInProcess2()) 
   return;

if (loader != null && loader.GetInProcess())
   {
   if (loader.GetWaitingICAction() == "" && loader.GetInProcessICActionValue() != name && name == "#ICSave") 
       loader.SetWaitingObject(form, name, params, bAjax, bPrompt);
   return;    
   }

if (ptGridObj_win0)
ptGridObj_win0.saveScrollPos();
ptCommonObj.cleanUpModalElement(name);
if (popupObj_win0.isShown && !popupObj_win0.isModalWidget && (!popupObj_win0.bPromptPageOpen || popupObj_win0.bPromptMessageOpen))
popupObj_win0.hidePopup();
form.ICResubmit.value=nResubmit;
form.ICAction.value=name;
form.ICXPos.value=getScrollX();
form.ICYPos.value=getScrollY();
if (typeof bAjax != "undefined" && !bAjax && (typeof params == "undefined" || params == null || params == "") && (typeof popupObj_win0.isModalWidget == "undefined" || !popupObj_win0.isModalWidget))
    form.submit();
else if (typeof params == "undefined" || !params)
loader=new net.ContentLoader(postUrl,form,name,null,null,null,null,null,bAjax, bPrompt);
else
 loader=new net.ContentLoader(postUrl,form,name,null,null,null,params,null,bAjax, bPrompt);
}
function pAction_win0(form, name, efieldname)
{
if(typeof CKEDITOR != 'undefined')UpdateEditorLinkedField();
if (typeof bPSHTMLtemplate != "undefined" && bPSHTMLtemplate == true && window.parent.popupObj_win0 != "undefined" && !window.parent.popupObj_win0.isShown) {
submitAction_win0(form, name);
return;
}
if (typeof(bPromptPage_win0) != "undefined" && bPromptPage_win0) {
aAction_win0(form, name);
if ((typeof form.ICTypeAheadID == 'undefined') ||
    (typeof form.ICTypeAheadID != 'undefined' && form.ICTypeAheadID.value == ''))
    {
    if (getMainPopupObject() != null)
        getMainPopupObject().nChildPrompts++;
    else
        window.parent.popupObj_win0.nChildPrompts++; 
    }
return;
}
if ((loader != null) && (loader.GetInProcess())) return;
form.ICAction.value=name;
form.ICXPos.value=getScrollX();
form.ICYPos.value=getScrollY();
popupObj_win0.showPrompt(name,form,postUrl,efieldname);
}
function mAction_win0(form, name, height, width, title, bModalElement, bSizeOnLoad)
{
if (typeof bModalElement == 'undefined' || bModalElement == null) {
form.ICAction.value=name;
form.ICXPos.value=getScrollX();
form.ICYPos.value=getScrollY();
if (typeof bSizeOnLoad == 'undefined')
var options = [true, true, true, null, height, width, title, true, null];
else
var options = [true, true, true, null, height, width, title, true, null, true];
popupObj_win0.showModalCntrl(form, name, postUrl, options);
}
else {
document.win0.ICModalWidget.value = 1;
document.win0.ICZoomGrid.value = 1;
popupModalObj_win0.modalTitle = title;
popupModalObj_win0.isModalElement = true;
aAction_win0(form, name, null, true, false);
}
}
function hAction_win0(form, name, height, width, title, bShowInModal, bSizeOnLoad)
{
if (bShowInModal != undefined && bShowInModal) {
form.ICAction.value=name;
form.ICXPos.value=getScrollX();
form.ICYPos.value=getScrollY();
if (typeof bSizeOnLoad == 'undefined')
var options = [true, true, true, null, height, width, title, true, null];
else
var options = [true, true, true, null, height, width, title, true, null, true];
popupObj_win0.showModalHyperLink(form, name, postUrl, options);
}
else {
form.ICAction.value=name;
form.ICXPos.value=getScrollX();
form.ICYPos.value=getScrollY();
var options = [true, true, true, null, 0, 0, title, false, null];
popupObj_win0.showModalHyperLink(form, name, null, options);
}
}
