/*  Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    ToolsRel: 8.51.10 */

var net=new Object();
var promptFieldName = "";  // Save field name associated with lookup prompt
var rteditorlist = ""; //RTE Editor List fields
var bPerf = false; //true to log entries for performance measure

net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;
net.bInProcess=false;           // flag whether there is a request that is being processed currently or not
net.InProcessElTagName="";      // html element tag name that is being processed 
net.InProcessICActionValue="";  // ICAction that is being processed

net.WaitingObjForm=null;        // the form
net.WaitingICAction="";         // ICAction  
net.WaitingArrParams=null;      // parameters
net.WaitingbAjax=false;         // AJAX request or not
net.WaitingbPrompt=false;       // prompt request or not   

net.bScript=false;              // has html area script 
net.arrScript = new Array();    // inline script from html areas
net.arrSrcScript = new Array(); // script file from html areas
net.nScript=-1;                 // inline script array index
net.nSrcScript=-1;              // script file array index
net.nScriptfiles=0;             // number of script files
net.nScriptfileIndex=0;
net.oScript="";                 // html area script file element
net.id="";
net.oSaveObj="";                // "this" object
net._HASTYLE="_HAStyle";
net.ENDSCRIPT="%/script>";
net.ENDSTYLE="%/style>";
net.msgList;
net.OnloadScriptList;
/*--- content loader object for cross-browser requests ---*/
net.ContentLoader=function(url,form,name,method,onload,onerror,params,contentType,bAjax,bPrompt, headerArray,isAsync)
{
if (ptConsole.isEnabled() && bPerf)
	ptConsole.append((new Date()).valueOf() + " request start");

this.url=(typeof url =="undefined" || !url) ? null: url;
if (!this.url)
{
    alert("url is required.");
	return;
}
gFocusObj = null;
this.req=null;
this.form=(typeof form =="undefined" || !form) ? null: form;
this.SetInProcess(true, this.form);
this.doc = document;
if (browserInfoObj.isIE) {
        if (this.form != null && typeof this.form.document != "undefined")
            this.doc = this.form.document;
}
else {
        if (this.form != null && typeof this.form.ownerDocument != "undefined")
            this.doc = this.form.ownerDocument;
}
this.contentType=(typeof contentType =="undefined" || !contentType) ? null: contentType;
this.name=(typeof name =="undefined" || !name) ? null: name;
this.params=(typeof params =="undefined"|| !params) ? "": params;
this.bAjax=(typeof bAjax =="undefined") ? 1: bAjax;
this.bPrompt=(typeof bPrompt =="undefined") ? 0: bPrompt;
if (this.form && typeof this.form.ICTypeAheadID!='undefined'&& this.form.ICTypeAheadID.value!='')
    this.bPrompt=false;
this.onerror=(typeof onerror =="undefined" || !onerror) ? this.defaultError: onerror;
this.bCallBack = (typeof onload =="undefined" || !onload)? 0: 1;
this.onload=(typeof onload =="undefined" || !onload) ? this.processXML: onload;
this.headerArray=(typeof headerArray == "undefined" || !headerArray) ? null: headerArray;
this.isAsync = typeof(isAsync) === "undefined" ? true : isAsync;

if (this.form || method && method.toUpperCase().indexOf("POST") !== -1) {
	if (!this.isResumitAndAllowed(this.form)) {

 		return;
}
	this.method="POST";
} else {
	this.method="GET";
}

if (!this.contentType && this.form && this.method.indexOf("POST")!=-1)
	this.contentType='application/x-www-form-urlencoded';
this.loadXMLDoc();
}

net.ContentLoader.prototype={
isResumitAndAllowed:function(form)
 {
 if (this.bCallBack || !form || !form.ICAction || !form.ICResubmit) return true;
 
 var sResubmit = form.ICResubmit.value;
 var nResubmit = new Number(sResubmit.valueOf());
 if (nResubmit < 1) return true;
 
 var el = document.getElementById(form.ICAction.value); 
    
 if (!el || typeof el == 'undefined' || el.disabled)
    return true;

 switch(el.type)
 {
    case "text":
        form.ICResubmit.value=0;
        return true;
	case "textarea":
        form.ICResubmit.value=0;
		return true;
    case "checkbox":
        form.ICResubmit.value=0;
        return true;
    case "radio":
        form.ICResubmit.value=0;
        return true;
    case "select-one":
        form.ICResubmit.value=0;
        return true;
    case "select-multiple":
        form.ICResubmit.value=0;
		return true;
    default:
       return false;
  }
  return false;
 },
 
 
 
 createXMLHTTPRequest:function()
 {
    if (window.XMLHttpRequest)  // If IE7, Mozilla, Safari, etc: Use native object
        return new XMLHttpRequest();

    try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
        catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
        catch (e) {}
    try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e) {}
    try { return new ActiveXObject("Microsoft.XMLHTTP"); }  // IE
        catch (e) {}
      
    //Microsoft.XMLHTTP points to Msxml2.XMLHTTP.3.0 and is redundant
    throw new Error("This browser does not support XMLHttpRequest.");

 },


 loadXMLDoc:function()
 { 
   if (ptConsole.isEnabled() && bPerf)
	ptConsole.append((new Date()).valueOf() + " processPIAPostParams start");

   this.processPIAPostParams();
    
   if (ptConsole.isEnabled() && bPerf)
	ptConsole.append((new Date()).valueOf() + " processPIAPostParams end and server start");

   if (this.method.indexOf("GET")!=-1 && this.params.length>0)
	this.url +="?"+this.params;
	
   if (ptConsole.isEnabled() && !bPerf)
	ptConsole.append((new Date()).valueOf() + " url:\n" + this.url + "\nparams:"+this.params.length+"\n" + this.params);


  try { this.req=this.createXMLHTTPRequest(); }
      catch(e)
      {
        alert(e);
        this.SetInProcess(false);
        this.SetWaitingObject(null,"",null,false,false);
        this.onerror.call(this);
      }


  if (this.req)
  {
   // try  {
      var loader=this;
      this.req.onreadystatechange=function()
      {
        loader.onReadyState.call(loader);
      }

      if (browserInfoObj.isSafari2x) { this.isAsync = false; }

      this.req.open(this.method,this.url,this.isAsync);

	  if (this.contentType)
      {
        this.req.setRequestHeader('Content-Type', this.contentType);
      }

      
	  if (this.headerArray) {
          for (var i=0; i<this.headerArray.length; i++){
			  if (this.headerArray[i][0] && this.headerArray[i][1])
		         this.req.setRequestHeader(this.headerArray[i][0], this.headerArray[i][1]);
	      } 
	  }

      nLastAction = 1;
      if (!this.bPrompt && typeof nResubmit != 'undefined' && !this.bCallBack 
		&& !popupObj_win0.isModalWidget && !popupObj_win0.hyperLinkAction) 
          nResubmit++;
      this.req.send(this.params);	
/*    }
    catch (err)
    {
    	 this.SetInProcess(false);
         alert(err);
         this.onerror.call(this);
    }*/
  }
 },

 
 GetInProcess2:function()
 {
   return (this.InProcessElTagName=="A" && this.GetInProcess()) ? true : false;
 },

 
 GetInProcess:function()
 {
    return (this.bInProcess) ? true : false;
 },

 
 
 SetInProcess:function(bProcess,oForm)
 {
    this.bInProcess = bProcess;
    if (bProcess && typeof oForm != "undefined" && oForm != null)
       {
       var el = document.getElementById(oForm.ICAction.value);
       if (el != null)
           this.InProcessElTagName = el.tagName;
       else
           this.InProcessElTagName = "";
       this.InProcessICActionValue = oForm.ICAction.value;    // save in-process ICAction value    
       }

    if (!bProcess)
       {
       this.InProcessElTagName="";
       this.InProcessICActionValue="";   
       }

 },

 GetInProcessICActionValue:function()
 {
  return (this.InProcessICActionValue);
 },
 
 GetWaitingObject:function()
 {
  return {v:this.WaitingObjForm,w:this.WaitingICAction,x:this.WaitingArrParams,y:this.WaitingbAjax,z:this.WaitingbPrompt};
 },
  
 SetWaitingObject:function(oForm,strAction,ArrParams,bAjax,bPrompt)
 {
  this.WaitingObjForm = oForm;
  this.WaitingICAction = strAction;
  this.WaitingArrParams = ArrParams;
  this.WaitingbAjax = bAjax;
  this.WaitingbPrompt = bPrompt;
 },
 
 GetWaitingICAction:function()
 {
   return (typeof this.WaitingICAction == "undefined") ? "" : this.WaitingICAction;
 },

 onReadyState:function() {
    var req = this.req;
    if (req.readyState == net.READY_STATE_COMPLETE) {

        // try {
            if (req.status == 200) {
                this.onload.call(this);
            }
        // } catch (e) {alert("PT_AJAX_NET(onReadyState): "+e);}
    }
 },

 defaultError:function()
 {
  alert("error fetching data!"
    +"\n\nreadyState:"+this.req.readyState
    +"\nstatus: "+this.req.status
    +"\nheaders: "+this.req.getAllResponseHeaders());
 },

 processPIAPostParams:function()
 {
      if (!this.form)
	      return;
      var sTmp="";
      
	 if (bCleanHtml) {
            if (ptCommonObj.isPromptReq(this.name) && this.name.indexOf("$prompt") !=-1 ) {
                var aName = this.name.replace("$prompt", "");
                this.doc.chgFldArr_win0.push(aName);
            }
            //process hidden fields
            for (var i = 0; i < this.doc.hiddenFldArr_win0.length; i++) {
                var eId = this.doc.hiddenFldArr_win0[i];
                var eObj =  this.doc.getElementById(eId);
                if (this.method.indexOf("GET") != -1) {
                    if (eId.indexOf("IC") != -1 || eId == this.name.substr(0, this.name.indexOf("$prompt")))
                        sTmp += ptCommonObj.getNV(eObj);
                }
                else {
                    if ((eId == "#ICIncludeHistory" || eId == "#ICCorrectHistory" || eId == "#ICMatchCase") && !eObj.checked)
                        continue;
                    sTmp += ptCommonObj.getNV(eObj);
                }
            }
            //process changed fields
			if (bDefer)
                this.doc.deferFldArr_win0 = new Array();

            while (this.doc.chgFldArr_win0.length > 0) {
                var eId = this.doc.chgFldArr_win0.shift();
                var eObj =  this.doc.getElementById(eId);
 				if (bDefer) {
                    this.doc.deferFldArr_win0.push(eId);
                    if (eObj == null)
                        continue;
                }
                if (this.method.indexOf("GET") != -1) {
                    if (eId.indexOf("IC") != -1 || eId == this.name.substr(0, this.name.indexOf("$prompt")))
                        sTmp += ptCommonObj.getNV(eObj);
                }
                else {
                    if ((eId == "#ICIncludeHistory" || 	eId == "#ICCorrectHistory" || eId == "#ICMatchCase") &&
 		           !eObj.checked) 
                        continue;
                    else {    // exclude unchecked checkbox and radio button
                        if (eObj.tagName == "INPUT" && (eObj.type == "checkbox" || eObj.type == "radio")) {
                            var idArr = eObj.id.split("$");
                            var id = idArr[0];
                            var eObj2 = null;
                            if (eObj.type == "checkbox") {
                                var eid = eObj.id;
                                if (eid.indexOf("$selm") != -1) {
                                    id = eid.replace('$selm', '$selmh');
                                    eObj2 = this.doc.getElementById(id);
                                }
                                else {
                                    eObj2 = this.doc.getElementById(eObj.id + "$chk");
                                    if (!eObj2 && idArr.length > 1) {
                                        for (var i = 1; i < idArr.length - 1; i++)
                                            id += '$' + idArr[i];
                                        id += "$chk$" + idArr[idArr.length - 1];
                                        eObj2 = this.doc.getElementById(id);
                                    }
                                }
                            }
                            if (eObj.type == "radio") {
                                var tscript = 'var radioGrp = this.form.' + eObj.name;
                                eval(tscript);
                                for (var j = 0; j < radioGrp.length; j++) {
                                    if (radioGrp[j].checked)
                                        eObj = radioGrp[j];
                                }
                                
                                eObj2 = this.doc.getElementById(eObj.id + "$rad");
                                if (!eObj2 && idArr.length > 1) {
                                    for (var i = 1; i < idArr.length - 1; i++)
                                        id += '$' + idArr[i];
                                    id += "$rad$" + idArr[idArr.length - 1];
                                    eObj2 = this.doc.getElementById(id);
                                }
                            }                       
                            if (eObj2)
                                sTmp += ptCommonObj.getNV(eObj2);

                            if (!eObj.checked)
                                continue;
                        }
                    }
                    sTmp += ptCommonObj.getNV(eObj);
                }
            } 
 			if (bDefer)
                this.doc.chgFldArr_win0 = this.doc.deferFldArr_win0;
     } else 
	{
	      for (var i=0; i < this.form.elements.length; i++)
	      {	    
	 	      if (this.method.indexOf("GET")!=-1)
		      {
	              if (this.form.elements[i].name.indexOf("IC")!=-1 ||
	                    this.form.elements[i].name==this.name.substr(0,this.name.indexOf("$prompt")))
				   	sTmp +=ptCommonObj.getNV(this.form.elements[i]);
	   	      }
		    else
	          {
			  if ((this.form.elements[i].id == "#ICIncludeHistory" ||
			       this.form.elements[i].id == "#ICCorrectHistory" ||
	 		       this.form.elements[i].id == "#ICMatchCase") &&
	 		       !this.form.elements[i].checked)
			     continue;
		      else {    // exclude unchecked checkbox and radio button
			     if (this.form.elements[i].tagName == "INPUT" &&
			         (this.form.elements[i].type == "checkbox" || this.form.elements[i].type == "radio") ) {
			            if (!this.form.elements[i].checked)
				       continue;
	 		     }
		      }

		      sTmp +=ptCommonObj.getNV(this.form.elements[i]);
	 		  }
	      }
	}
      if (this.params != "") this.params += "&"; 
	  if (this.bAjax) this.params += "ICAJAX=1"; else this.params += "ICAJAX=0";

 	  if (this.bPrompt) this.params += "&ICSPROMPT=1";      
      if (typeof(bSearchDialog_win0)!="undefined" && bSearchDialog_win0)
            this.params += "&ICFRMSEARCH=1"; //search or prompt page

	  // is nav type drop down instead of Left?
	  var bNavTypeDropDown = 0;
      if (!isCrossDomain(parent) && typeof(parent.ptIframe) != "undefined") {
        if (typeof(parent.pthNav) != "undefined") bNavTypeDropDown = 1;	
	  }
	  if (bNavTypeDropDown) this.params += "&ICNAVTYPEDROPDOWN=1"; else this.params += "&ICNAVTYPEDROPDOWN=0";


      if (sTmp != "") this.params += ("&" + sTmp);
      // remove & at the end
      if ((this.params).lastIndexOf("&") == ((this.params).length -1))
         this.params = (this.params).substr(0,(this.params).length -1);
  },



  processXML:function()
  {
    var val =  getPSLoginCookieValue();   
    if (val == -1)
    {
        if (isSignout())
           self.location=timeOutURL;   
        else
           window.parent.document.body.innerHTML=this.req.responseText;
        return;
    }
	if (ptConsole.isEnabled() && bPerf)
            ptConsole.append((new Date()).valueOf() + " server return");

    var ct =  this.req.getResponseHeader("content-type");
    if (ct.indexOf("xml") == -1)
    {
         
	 if (typeof(popupObj_win0) != "undefined" && popupObj_win0.hyperLinkAction) 
	 {
	     if ((this.req.responseText.indexOf("ShowInModal=1") != -1) || popupObj_win0.isModalWidget) //open in a modal window
	     {
	 	if (typeof window.parent.popupObj_win0 != "undefined" && window.parent.popupObj_win0 
			&& window.parent.popupObj_win0.isShown)		//modal window is open already
		{
	  	    window.parent.popupObj_win0.launchedFromModal=true;
    		    this.form.ICResubmit.value="1";
	       	    this.form.submit();
		}
		else
		{
		    this.SetInProcess(false);
		    this.SetWaitingObject(null,"",null,false,false);
		    popupObj_win0.hyperLinkAction = false;
		    //open new modal window and resubmit html page
		    popupObj_win0.bmodaliFrame = true;      
		    popupObj_win0.showModalCntrl(this.form, this.name, postUrl, null);
		    processing_win0(0);
		}
		this.SetInProcess(false);
                           this.SetWaitingObject(null,"",null,false,false);
	            
		if (popupObj_win0.hyperLinkAction) {	
			return;
		}
	     }
	     else if (window.parent.document.win0 != "undefined" && window.parent.document.win0)  
	     {	
		window.parent.document.getElementById("ICModalWidget").value = 0; 
		window.parent.popupObj_win0.hyperLinkAction = false;
		window.parent.popupObj_win0.isModalWidget = false;
		window.parent.document.win0.ICResubmit.value="1";
		window.parent.document.win0.submit();
		return; 
	     }
	     else if (this.form)		
	     {
		document.getElementById("ICModalWidget").value = 0; 
		popupObj_win0.hyperLinkAction = false;
		popupObj_win0.isModalWidget = false;
		this.form.ICResubmit.value="1";
	       	this.form.submit();
		return; 
	     }
	 }

	 if (typeof(popupObj_win0) != "undefined" && popupObj_win0.isModalWidget)
	 {  
   	    // check to see if the returned html is the page where the modal was launched
	    // -1 indicates that the html returned is not the page where the modal was launched
	    // need this check to determine whether or not to close a modal window when a message is thrown

	    
	    
	    
	    try {
	        var szPageName = "Page=" + this.form.ICModalOrginatingPage.value;
	        var nPageNameIndex = this.req.responseText.indexOf(szPageName);
	    }
	    catch (form_exc) {
			popupObj_win0.hidePopup(); 
			popupObj_win0.isModalWidget = false;
			document.win0.ICResubmit.value="1";
			document.win0.submit();
 	    } 
        
            
            if (browserInfoObj.isIE && this.form) {
               try  {
                var orgValue = this.form.ICModalOrgContent.value;
            } catch (e) {
                this.SetInProcess(false);
                this.SetWaitingObject(null,"",null,false,false);
                return;
            }
        }     // end of if (typeof(popupObj_win0) != "undefined" && popupObj_win0.isModalWidget)
        
	// begin: perform the various ways of closing or not closing a non-prompt modal window
        if (this.form && this.req.responseText.indexOf("popupObj_win0.showMsg()") != -1 && nPageNameIndex == -1 )
	{
            
            
            if (!popupObj_win0.modalResendClose)
	    { 
                
	        popupObj_win0.modalResendClose = true;
	        this.form.ICModalWidget.value = "1";
	        this.SetInProcess(false);
            this.SetWaitingObject(null,"",null,false,false);
	        popupObj_win0.endModalCntrl(this.form, this.name);
	        return;
            } 
            else
            { 
            
	        popupObj_win0.modalResendClose = false;
	        this.form.ICResubmit.value="1";
	        this.form.submit();
            }
        }
        else if (this.form && this.form.ICModalOrgContent.value != this.form.ICModalNewContent.value && popupObj_win0.launchedFromModal)
	{
            
            
            
            this.form.ICResubmit.value="1";
            this.form.submit();
        }
        else if (document.win0)
        {
        
	    popupObj_win0.isModalWidget = false;
	    document.win0.ICResubmit.value="1";
	    this.SetInProcess(false);
        this.SetWaitingObject(null,"",null,false,false);
	    document.win0.submit();
	    popupObj_win0.hidePopup();
	}
     } // end: perform the various ways of closing or not closing a non-prompt modal window
     else if (this.form)
     {
  	this.form.ICResubmit.value="1";
        this.form.submit();
     }
     this.SetInProcess(false);
     this.SetWaitingObject(null,"",null,false,false);
     return;
    }  // end of if (ct.indexOf("xml") == -1)

    
    
    if (this.form.ICModalLongClosed != null &&
	    typeof this.form.ICModalLongClosed != 'undefined' && 
	    this.form.ICModalLongClosed.value.length > 0) {
	    this.form.ICModalLongClosed.value = "";
	    }

	var xmlDoc = null;
	var bErr = 0;
	if (window.ActiveXObject)
	{
	    if (this.req.responseXML.parseError.errorCode == 0)   // xml parser error because of unprintable character in xml
	        xmlDoc = this.req.responseXML;
	    else {                                                // xml parser error found, following will fix it.  
	         xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	         xmlDoc.async="false";
	         xmlDoc.loadXML(this.req.responseText);
	    }

	}
	else
	{
           var parser=new DOMParser();
           xmlDoc=parser.parseFromString(this.req.responseText,"text/xml");
           if (xmlDoc.documentElement.nodeName=="parsererror") {
               bErr = 1;
               var sText = this.req.responseText;
               sText = sText.replace(/\u001E/g, "&#30;");   // replace record separator with character reference
               xmlDoc=parser.parseFromString(sText,"text/xml");
               if (xmlDoc.documentElement.nodeName=="parsererror") {
                  alert("xml is invalid");
                  return;
               }
               
           }

     }  
	
	
    var TAFieldValue;
	var bTARequest = false;
 	if (this.form && typeof this.form.ICTypeAheadID!='undefined'&& this.form.ICTypeAheadID.value!='') {
		bTARequest = true;
	}
    if (bTARequest) 
    {
         var TAField = document.getElementById(this.form.ICTypeAheadID.value);
         if (TAField)	
         	TAFieldValue = TAField.value;
    }
     var oDoc = document;
	 var promptList = xmlDoc.getElementsByTagName("PFIELD");  
     var scriptList = xmlDoc.getElementsByTagName("GENSCRIPT");
	 var sysvar = xmlDoc.getElementsByTagName("SYSVAR");
     net.msgList = xmlDoc.getElementsByTagName("GENMSG");
     var fieldList = xmlDoc.getElementsByTagName("FIELD");
     rteditorlist = xmlDoc.getElementsByTagName("RTEDITORSCRIPT");
	 
	 var modalfield = xmlDoc.getElementsByTagName("MFIELD");

     if (ptConsole.isEnabled() && !bPerf)        
		ptConsole.append((new Date()).valueOf() + " response:\n" + this.req.responseText);

	 if (scriptList)  // check redirect URL.  if it is redirect script, run it.
     {
          for (var i=0; i < scriptList.length; i++)
            {
               var sTmp = (scriptList[i].firstChild.data).toLowerCase(); 
               if (sTmp.indexOf("document.location=") == 0 || sTmp.indexOf("document.location =") == 0) {
                    eval(scriptList[i].firstChild.data);
                    return;
               }
            }
      }

	 if (sysvar && sysvar.length>0)  // sysvar run it first
     {
         for (var i=0; i < sysvar.length; i++) 
			eval(sysvar[i].firstChild.data);
	 }

     if (fieldList)
     {
         if (ptConsole.isEnabled() && bPerf)
                ptConsole.append((new Date()).valueOf() + " partial page refresh start");

		 var sData = "";
         net.nScript=-1;
         net.nSrcScript=-1;
         net.bScript=false;
         for (var flIdx=fieldList.length-1; flIdx > -1; flIdx--)
 	     {
         attrs=fieldList[flIdx].attributes;
   	     id=attrs.getNamedItem("id").value;
 		 if (id=='divpopupFrame' && oDoc.getElementById('popupFrame'))
   	            continue;
		 oid = id.substr(3+this.form.name.length,id.length);
	     if (popupModalObj_win0 && !popupModalObj_win0.isModalElement && modalfield.length==0)
				popupModalObj_win0.clearModalContent(false);

   	     var obj = oDoc.getElementById(id);
         if (obj)
         {
		 	
		 	if (typeof(bPromptPage_win0) != 'undefined' && bPromptPage_win0 &&
				(obj.id == "win0divSEARCHABOVE" || obj.id == "win0divSEARCHADV" || obj.id == "win0divSEARCHBELOW"))
				obj.style.width = "450px";
			
			if (rteditorlist)
			{
			var RTArea = obj.getElementsByTagName('textarea');
			var countrtarea;
			var ResponseDataObject= document.createElement('div');
			ResponseDataObject.setAttribute('id','TempResponse');
                        ResponseDataObject.innerHTML = (this.restoreXMLData(fieldList[flIdx].firstChild.data)).replace(/&#30;/g, "\u001E"); // restore xml data and record separator before update
			var RTAreanew = ResponseDataObject.getElementsByTagName('textarea');
			for(var ii = 0; ii < RTArea.length; ii++)
                {
				   countrtarea = 0;
                   for(var jj=0; jj < RTAreanew.length; jj++)
				   {
                   if (RTArea[ii].id == RTAreanew[jj].id)
                   countrtarea = countrtarea + 1;
                   }
                   if (countrtarea == 0 )
                   {                       
					for ( var instanceName in CKEDITOR.instances)
            		{  
              			if (instanceName == RTArea[ii].id)
                 		eval(CKEDITOR.instances[instanceName].destroy());
             		} 
                   }
                }
			 }

			if (bCleanHtml) {
				
				if (browserInfoObj.isIE) {
					var div = oDoc.createElement("div");
					div.innerHTML = (this.restoreXMLData(fieldList[flIdx].firstChild.data)).replace(/&#30;/g, "\u001E");
					
					var nObjLen = obj.children.length;
					for (var idx=0; idx < nObjLen; idx++) {
						obj.removeChild(obj.children[0]);  
				    }
				
					var ndDivLen = div.children.length;
					for (var idx=0; idx < ndDivLen; idx++) {
						obj.appendChild(div.children[0]);  
					}
				}
				else {
					obj.innerHTML = (this.restoreXMLData(fieldList[flIdx].firstChild.data)).replace(/&#30;/g, "\u001E"); // restore xml data and record separator before update
				}
			}
			else {
	   			if (ptConsole.isEnabled() && bPerf)
	                 ptConsole.append((new Date()).valueOf() + "call processScript start");
        
				sData = this.processScript(id,fieldList[flIdx].firstChild.data);
			    if (sData && sData.length>0)
	                obj.innerHTML = (this.restoreXMLData(sData)).replace(/&#30;/g, "\u001E");    // restore xml data and record separator before update
	            else
	                obj.innerHTML = (this.restoreXMLData(fieldList[flIdx].firstChild.data)).replace(/&#30;/g, "\u001E"); // restore xml data and record separator before update
    
	 			if (ptConsole.isEnabled() && bPerf)
					ptConsole.append((new Date()).valueOf() + "call processScript end");
			}
            
            if ((browserInfoObj.isIE) && (obj.firstChild != null) && (obj.firstChild.tagName != null) && 
                (((obj.firstChild.tagName).toUpperCase().indexOf("TABLE") >= 0)))          
            {
                if (!('ltr' == 'rtl' && oid == "PSPAGECONTAINER"))
                {
                    obj.style.width = 0;			//rel#790232
                    obj.style.width = obj.firstChild.offsetWidth;
                }
            }
         }
         }
		
		if (ptConsole.isEnabled() && bPerf)
            ptConsole.append((new Date()).valueOf() + " partial page refresh end");
      }
	
	
     if (bTARequest)
     {
          var TAField = oDoc.getElementById(this.form.ICTypeAheadID.value);
          if (TAField != null && TAFieldValue != '' && TAField.value != TAFieldValue) 
              TAField.value = TAFieldValue;
     }

      if (net.msgList)
      {
            for (var i=0; i < net.msgList.length; i++)
            {
             var msg = net.msgList[i].firstChild.data;
	     if (!popupObj_win0.Initialized)
		popupObj_win0.init();
             popupObj_win0.addMsg(msg);
            }
      }

	  if (this.bPrompt && promptList && promptList.length>0)
      {  
     	 oDoc = document.getElementById("popupFrame").contentWindow.document;
	     for (var i=promptList.length-1; i > -1; i--) 
 	     {
         attrs=promptList[i].attributes;
   	     id=attrs.getNamedItem("id").value;
   	     if (id=='divpopupFrame' && oDoc.getElementById('popupFrame'))
   	         continue;
   	     var obj = oDoc.getElementById(id);
         if (obj)
         {  
		 	
		 	if (obj.id == "win0divSEARCHABOVE" || obj.id == "win0divSEARCHADV" || obj.id == "win0divSEARCHBELOW")
				obj.style.width = "450px";

            obj.innerHTML = promptList[i].firstChild.data; 
            if (id!='divpopupFrame')
                obj.style.display = "block";
         }    
         } 
     	 popupObj_win0.launchPrompt(this.name, this.form, "", "");
	  }

	  
 	  if  (modalfield && modalfield.length>0 && popupModalObj_win0.isModalElement &&
		   !bTARequest)  
	  {
	  if (!popupModalObj_win0.isModalWidget)  
	      {
		  
	  	  var szParts = this.name.split("$");
		  id = "win0" + "div" + szParts[0] + "$" + szParts[szParts.length - 1];

		  
		 	var nIdx = -1;
			for (var idx = 0; idx < modalfield.length; idx++) {
				if (modalfield[idx].attributes.getNamedItem("id").value == id)
				nIdx = idx;
				}
			if (nIdx == -1) {
			    nIdx = 0;
			    id = modalfield[0].attributes.getNamedItem("id").value;
				}

		  
		  
		  
		  
		  
		  for (var i=0; i < modalfield.length; i++)
		  	  {
 		      attrs=modalfield[i].attributes;
	          var elementID=attrs.getNamedItem("id").value;
			  popupModalObj_win0.gridOccurences[i] = document.getElementById(elementID);		
			  }

		  
		  var options = [true, true, true, null, 0, 0, popupModalObj_win0.modalTitle, modalfield[nIdx], id];		
		  popupModalObj_win0.showModalElement(this.form, null, null, options);

		  
		  
		  for (var i=0; i < modalfield.length; i++)
			{
		    if (popupModalObj_win0.gridOccurences[i] != null && 
		        typeof popupModalObj_win0.gridOccurences[i] != 'undefined' &&
		        popupModalObj_win0.gridOccurences[i].id != popupModalObj_win0.modalContentID)
				{
				var element = popupModalObj_win0.gridOccurences[i];  
				var elementParent = element.parentNode;
				elementParent.removeChild(element);
				elementParent.innerHTML = modalfield[i].firstChild.data;
				popupModalObj_win0.gridOccurences[i] = elementParent.firstChild;
				}
			}

		  }
	  else // user action on the modal grid
		  {
		  
		  var nIdx = 0;
		  for (var idx = 0; idx < modalfield.length; idx++)	
			{
			if (modalfield[idx].attributes.getNamedItem("id").value == popupModalObj_win0.modalContentID)
				nIdx = idx;
			}

		  
		  var modalCurrentElement = document.getElementById(popupModalObj_win0.gridScrollableAreaID); 
		  if (modalCurrentElement) {
	 		  var currentHeight = modalCurrentElement.offsetHeight;
			  var currentWidth = modalCurrentElement.offsetWidth;
			  var nCurrentCols = modalCurrentElement.childNodes[0].childNodes[0].childNodes[0].childNodes.length;	
			  }	

		  
  		  var modalElement = document.createElement("div");
		  modalElement.innerHTML =  modalfield[nIdx].firstChild.data;
		  var oldChild = popupModalObj_win0.popupContent.firstChild;	
		  popupModalObj_win0.popupContent.replaceChild(modalElement, oldChild);
 	          popupModalObj_win0.popShadow.style.height = (popupModalObj_win0.popInner.offsetHeight + 7) + 'px';
		  popupModalObj_win0.popShadow.style.width = (popupModalObj_win0.popInner.offsetWidth + 2) + 'px';
		  popupModalObj_win0.sizeShadowImageContainers(popupModalObj_win0.popInner.offsetHeight, popupModalObj_win0.popInner.offsetWidth, true);

			
			
			
			for (var i=0; i < modalfield.length; i++)
				{
			    if (popupModalObj_win0.gridOccurences[i] != null && 
			        typeof popupModalObj_win0.gridOccurences[i] != 'undefined' &&
			        popupModalObj_win0.gridOccurences[i].id != popupModalObj_win0.modalContentID)
					{
					var element = popupModalObj_win0.gridOccurences[i];		
					var elementParent = element.parentNode;
					elementParent.removeChild(element);
					elementParent.innerHTML = modalfield[i].firstChild.data;
					popupModalObj_win0.gridOccurences[i] = elementParent.firstChild;
					}
				}
                  
                  popupModalObj_win0.sizeGridZoomElement(popupContentContainerModal);   
			}  // end of else
			
			// set focus
			var popupContentContainerModal = document.getElementById('popupContentContainerModal');
		    var tagElements = popupContentContainerModal.getElementsByTagName('*');          
		    popupModalObj_win0.setFocus(tagElements);			
	  }

	  if (ptConsole.isEnabled() && bPerf)
            ptConsole.append((new Date()).valueOf() + " scripts start");


      if (scriptList)
          net.OnloadScriptList = scriptList;
      else 
          net.OnloadScriptList="";

      if (net.bScript) { //script from html area
          net.nScriptfileIndex=0;
          net.nScriptfiles = net.arrSrcScript.length;
          if (net.nScriptfiles == 0) {
              this.finalCall();
			  if (ptConsole.isEnabled() && bPerf)
				ptConsole.append((new Date()).valueOf() + " scripts & request end");
              return;
          }    
          net.id = id;
          this.getScriptfile();
      }
      else {
          this.finalCall();
          if (ptConsole.isEnabled() && bPerf)
	      ptConsole.append((new Date()).valueOf() + " scripts & request end");
          return;
      }             

if (ptConsole.isEnabled() && bPerf)
	ptConsole.append((new Date()).valueOf() + " scripts & request end");
     
},

restoreXMLData:function(sRespdata)  
{
   var sTmpdata = sRespdata;
   if (sTmpdata.indexOf("&lt;![CDATA*") != -1 && sTmpdata.indexOf("*]>") != -1)
   {
        sTmpdata=(sTmpdata.replace(/&lt;!\[CDATA\*/g,"&lt;![CDATA["));
        sTmpdata=(sTmpdata.replace(/\*\]\>/g,"]]>"));
   }
   return sTmpdata;
},


loadedAllScriptfiles:function()  // check for all script files loaded in browser
{
   if (net.nScriptfiles>0 && net.nScriptfileIndex >= net.nScriptfiles) // all html area script files loaded
   {
      this.finalCall();
      return 1;
   }
   else if (net.nScriptfiles>0)
      return 0;
   else
      return 1; 
},

getScriptfile:function()     // load script file(s) in browser
{
   if (this.loadedAllScriptfiles()) return;       // all javascript files loaded
   
   var i = net.nScriptfileIndex;
   net.id=net.id+"_"+i+"src";
   if (net.nScriptfiles>0 && i<net.nScriptfiles) 
   {
       var newId = net.id+"_HAScript";
       var oldScript = document.getElementById(newId);
       var oHead=document.getElementsByTagName("head")[0];
       if (oldScript) 
	    oHead.removeChild(oldScript);
       net.oScript = document.createElement("script");  // create html area script file element	    
       net.oScript.setAttribute("id",newId);
       net.oScript.setAttribute("type","text/javascript");
       net.nScriptfileIndex++;
       if (net.arrSrcScript[i]) {
          net.oScript.setAttribute("src",net.arrSrcScript[i]);
          net.oSaveObj =this; 
          net.oSaveHead = oHead;
          this.loadScriptfile();
       }   
       else {
          this.loadedAllScriptfiles();
      }
   }
},

loadScriptfile: function()
{  // catch file-load error, onload event for non-IE browser, onreadystatechange event for IE browser 
   net.oScript.onerror=net.oScript.onload=net.oScript.onreadystatechange = this.GotAsyncData;
   net.oSaveHead.appendChild(net.oScript);
},

GotAsyncData:function() 
{
    //alert("in GotAsyncData: net.oScript.readyState="+net.oScript.readyState);  // debug

    
    //if (! browserInfoObj.isIE || (browserInfoObj.isIE && ( net.oScript.readyState == "loaded" || net.oScript.readyState == "complete"))) 
    {
      // get next javascript file
      net.oSaveObj.getScriptfile();
    }    
    return;
},

finalCall:function()
{
   net.arrSrcScript= new Array();
   net.nScriptfiles=0;
   net.nScriptfileIndex=0;
   if (net.bScript) { // run java script from html area
        var n= net.arrScript.length;
		for (var xx=0; xx < n; xx++)
		{
		   if (net.arrScript[xx]) 
               this.addScript(id+"_"+xx,net.arrScript[xx]);  // run script
        }
		net.arrScript = new Array();
		net.bScript = false;
   }

   if (net.OnloadScriptList && net.OnloadScriptList.length>0 ) {    // run page java script and page onload event java script
        for (var i=0; i < net.OnloadScriptList.length; i++) 
        {
               eval(net.OnloadScriptList[i].firstChild.data);       // run script
        }
   }
   
   net.OnloadScriptList="";   // clear var

   if (net.msgList && net.msgList.length>0) 
   {
       this.SetInProcess(false);
       this.SetWaitingObject(null,"",null,false,false);
       popupObj_win0.showMsg();
   }

   // for modal non-prompt	
   popupObj_win0.deferPrompt();
   this.SetInProcess(false);

   if (ptGridObj_win0)
       ptGridObj_win0.restoreScrollPos();

   // Save field name assoicated with the lookup prompt 
   if (this.bPrompt) 
  	   promptFieldName = this.name;  

   // See if we need to refresh RC since the field may be changed from prompt
   if ( ptRC.isEnabled() && (!this.bPrompt) && (promptFieldName.length  > 0) ) {
	   window.top.ptrc.refreshRCOnChangeIfNeeded(promptFieldName);
	   promptFieldName = "";
   }	
	
   // Need to add change event as page is re-constructed!!!
   if (ptRC.isEnabled() && !this.bPrompt) 
	   window.top.ptrc.onAddChangeEvent();

   
   ptCommonObj.generateABNSearchResults();

   if (this.GetWaitingICAction() != "")
   {
      var objWaiting = this.GetWaitingObject();
      this.SetWaitingObject(null,"",null,false,false);
      aAction0_win0(objWaiting.v, objWaiting.w, objWaiting.x, objWaiting.y, objWaiting.z);
   }

},

addScript:function(id,dscript)   // add inline js to html header section
{
if (!id || !dscript) return;
var sId=id+"_HAScript";
var obScript = document.getElementById(sId);
var obHead=document.getElementsByTagName("head")[0];
if (obScript) {
 obHead.removeChild(obScript);
}
obScript = document.createElement("script");
obScript.setAttribute("type","text/javascript")
obScript.setAttribute("id",sId);
obScript.text = dscript;
obHead.appendChild(obScript);
},

addStyle:function(id,dstyle,src)  // add style to html header section
{
if (!dstyle || dstyle.length==0) return;

var oStyle = document.getElementById(id+net._HASTYLE);
var oHead=document.getElementsByTagName("head")[0];
if (oStyle) {         // remove stylesheet
 oHead.removeChild(oStyle);
}

// for external css file
if (src) {
  oStyle=document.createElement("link")
  oStyle.setAttribute("id",id+net._HASTYLE);
  oStyle.setAttribute("rel", "stylesheet")
  oStyle.setAttribute("type", "text/css")
  oStyle.setAttribute("href", src)
}  
else {
  oStyle = document.createElement('style');
  oStyle.setAttribute("id",id+net._HASTYLE);
  oStyle.type = 'text/css';
  if (browserInfoObj.isIE)  // IE browser
      oStyle.styleSheet.cssText=dstyle;
  else         // non-IE browser
      oStyle.innerHTML=dstyle;
}
oHead.appendChild(oStyle);
},

processScript:function(id,data)
{
var sData = new String(data);
var myExp2= new RegExp("</script","gi");
sData = sData.replace(/<script/gi,"%script");
sData = sData.replace(myExp2,"%/script");
myExp2= new RegExp("</style","gi");
sData = sData.replace(/<style/gi,"%style");
sData = sData.replace(myExp2,"%/style");

if (sData.indexOf("%script")==-1 && sData.indexOf("%style")==-1) return null;

var nLen = (net.ENDSCRIPT).length;  // length of %/style>

var pos=sData.indexOf("%script");

if (pos != -1) net.bScript=true;

var pos2;
var sJS=".js";
while(pos>-1){
    pos2=sData.indexOf(net.ENDSCRIPT,pos);  
    var sTmp = sData.substring(pos,pos2);
    pos3 = sTmp.indexOf(">");
    var sTmp0 = sTmp.substring(0,pos3)
    if (sTmp0.length>0 && sTmp0.indexOf("src")!=-1)
    {
      var src = sTmp0.substring(sTmp0.indexOf("src")+5,sTmp0.length-1);
      var iEnd = (src.toLowerCase()).indexOf(sJS);
      if (iEnd > -1) {
          net.nSrcScript++;
          src = src.substring(0,iEnd+sJS.length);
          net.arrSrcScript[net.nSrcScript]=src;
      }
      else {
           net.nScript++;
           net.arrScript[net.nScript]=src;
      }
    }
    else
    {
	 sTmp = sTmp.substring(pos3+1,sTmp.length);
	 if (sTmp.length>0)
	 {
	    ++net.nScript;
	    var pos1=sTmp.indexOf("%script") 
	    if(pos1>-1){
	       sTmp = sTmp.replace("%script","<script");
	       sTmp = sTmp.replace("%/script","</script");
	    }
	    pos1=sTmp.indexOf("%style")
	    if(pos1>-1){
	    sTmp = sTmp.replace("%style","<style");
	    sTmp = sTmp.replace("%/style","</style");
	    }
	    net.arrScript[net.nScript]=sTmp;
	 }

    }
   
     if(rteditorlist)
     {
        for (var i=0; i < rteditorlist.length; i++)
         {
   			var rteeditor = rteditorlist[i].attributes;
            var rteeditorid=rteeditor.getNamedItem("id").value;
            if(sTmp.indexOf(rteeditorid)!=-1)
              {
            	for ( var instanceName in CKEDITOR.instances )
             		{  
              			if (instanceName == rteeditorid)
                 		eval(CKEDITOR.instances[rteeditorid].destroy());
             		}  
              }
         }
     }
    sData = sData.substring(0,pos)+sData.substring(pos2+nLen,sData.length);
    pos=sData.indexOf("%script");
 }

var nStyle=-1;
nLen = (net.ENDSTYLE).length;    // length of %/style>
pos=sData.indexOf("%style");
while(pos>-1){
    pos2=sData.indexOf(net.ENDSTYLE,pos);
    var sTmp = sData.substring(pos,pos2);
    pos3 = sTmp.indexOf(">");
    var sTmp0 = sTmp.substring(0,pos3)
    if (sTmp0.length>0 && sTmp0.indexOf("src")!=-1)
    {
      var src = sTmp0.substring(sTmp0.indexOf("src")+5,sTmp0.length-1);
      ++nStyle;
	  this.addStyle(id+"_"+nStyle,sTmp,src);
    }
    else
    {
      sTmp = sTmp.substring(pos3+1,sTmp.length);
      if (sTmp.length>0)
		{
		    ++nStyle;
		    this.addStyle(id+"_"+nStyle,sTmp,null);
		}
    }
    sData = sData.substring(0,pos)+sData.substring(pos2+nLen,sData.length);
    pos=sData.indexOf("%style");
 }
 sData = sData.replace("%/style","</style"); // recover the wrong replacement of end-style tag
 return sData;
}
}

/*--- not used currently ---*/
net.cmdQueues=new Array();
net.CommandQueue=function(id,url,onUpdate,freq)
{
  this.id=id;
  net.cmdQueues[id]=this;
  this.url=url;
  this.queued=new Array();
  this.sent=new Array();
  this.onUpdate=onUpdate;
  if (freq)
  {
    this.repeat(freq);
  }
  this.lastUpdateTime=0;
}

net.CommandQueue.STATUS_QUEUED=-1;
net.CommandQueue.STATE_UNINITIALIZED=net.READY_STATE_UNINITIALIZED;
net.CommandQueue.STATE_LOADING=net.READY_STATE_LOADING;
net.CommandQueue.STATE_LOADED=net.READY_STATE_LOADED;
net.CommandQueue.STATE_INTERACTIVE=net.READY_STATE_INTERACTIVE;
net.CommandQueue.STATE_COMPLETE=net.READY_STATE_COMPLETE;
net.CommandQueue.STATE_PROCESSED=5;

net.CommandQueue.PRIORITY_NORMAL=0;
net.CommandQueue.PRIORITY_IMMEDIATE=1;


net.CommandQueue.prototype={
 addCommand:function(command)
 {
  if (this.isCommand(command))
  {
    this.queue.append(command,true);
    if (command.priority==net.CommandQueue.PRIORITY_IMMEDIATE)
    {
      this.fireRequest();
    }
  }
 },

 fireRequest:function()
 {
  if (!this.onUpdate && this.queued.length==0)
  {
    return;
  }
  var data="lastUpdate="+this.lastUpdateTime+"&data=";
  for(var i=0;i<this.queued.length;i++)
  {
    var cmd=this.queued[i];
    if (this.isCommand(cmd))
    {
      data+=cmd.toRequestString();
      this.sent[cmd.id]=cmd;
    }
  }
  this.queued=new Array();
  this.loader=new net.ContentLoader(
    this.url,
    net.CommandQueue.onload,
    net.CommandQueue.onerror,
    "POST",data
  );
 },

 isCommand:function(obj)
 {
  return (
    obj.implementsProp("id")
    && obj.implementsProp("priority")
    && obj.implementsFunc("toRequestString")
    && obj.implementsFunc("parseResponse")
  );
 },

 repeat:function(freq){
  this.unrepeat();
  if (freq>0)
  {
    this.freq=freq;
    var cmd="net.cmdQueues["+this.id+"].fireRequest()";
    this.repeater=setInterval(cmd,freq*1000);
  }
 },

 unrepeat:function()
 {
  if (this.repeater)
  {
    clearInterval(this.repeater);
  }
  this.repeater=null;
 }
}

net.CommandQueue.onload=function()
{
  var xmlDoc=this.req.responseXML;
  var elDocRoot=xmlDoc.getElementsByTagName("responses")[0];
  var lastUpdate=elDocRoot.attributes.getNamedItem("updateTime");
  if (parseInt(lastUpdate)>this.lastUpdateTime)
  {
    this.lastUpdateTime=lastUpdate;
  }
  if (elDocRoot)
  {
    for(i=0;i<elDocRoot.childNodes.length;i++)
    {
      elChild=elDocRoot.childNodes[i];
      if (elChild.nodeName=="command")
      {
        var attrs=elChild.attributes;
        var id=attrs.getNamedItem("id").value;
        var command=net.commandQueue.sent[id];
        if (command)
        {
          command.parseResponse(elChild);
        }
      }
      else if (elChild.nodeName=="update")
      {
        if (this.implementsFunc("onUpdate"))
        {
          this.onUpdate.call(this,elChild);
        }
      }
    } //for
  } //if
}


net.CommandQueue.onerror=function()
{
  alert("problem sending the data to the server");
}
