/*******************************************************************
**         Start OPL1.JS                                         **
**         Design and Development: Terry Thurber 2009             **
*******************************************************************/

/*******************************************************************
**            Global Variables Accessed by function calls         **
**   20071210: Set Variables _HTTP and the Method - would like to **
**             make global variables once sychronisity timing     **
**             is resolved.                                       **
**             Need to evaluate setInterval to resolve modeless   **
**             execution of JavaScript functions                  **
*******************************************************************/
var _isBrowserActiveX = !(typeof window.ActiveXObject=="undefined");
var rootURL             = new String("");
/*******************************************************************
**                     Page Pre Loaders                           **
*******************************************************************/

/******************************************************************/

/*******************************************************************
**   function Init : Called By HTML onload() method               **
**   2007.11.06 :getGTTP(menuhtml) for divMenu                    **
**   2007.12.09 :Added try catch to getHTTP. Added function       **
**               "constructor" to oHTTP.onreadystatechange which  **
**               allows parameters to be passed to function being **
**               pointed to:                                      **
**               oHTTP.onreadystatechange =                       **
**               function() {processReqChange(oHTTP,theMethod);}; **
**   Note: DOMParser only reports node values and does not report **
**   HTML or XML TAGS                                             **
**      1st arg is the name of the input file                     **
**      2ed arg is the function that execute the "theMethod" from **
**          inside an eval() funtion at processReqChange          **
**      3rd argument sets the mime type:                          **
**          true for XML compliant documents                      **
**          false non XML documents.                              **
**   2007.12.09: Need to resolve timming issues before multiple   **
**               functions can be pointed to in Init              **
*******************************************************************/

function runPageOpener(aURL,oWin)
{
var theURL=aURL+oWin.theID;
eval('window.open(theURL)');
}

function runHedgePopup(oWin)
{
var winRef = oWin.open('popOPL1MFASK.HTM','popMFASK',
'width=350,height=250,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,scrollbars=1');
winRef.focus();
}

function runAlert(oWin){alert("The window.id is: "+oWin.theID);}

function getContentForHome()
{
getHTTP("R6MarketingHome.XML","setContent(oHTTP.responseText);",false);
}

function getContentForProjects()
{
getHTTP("R6MarketingProjects.XML","setContent(oHTTP.responseText);",false);
}

function getContentForOthers()
{
getHTTP("R6MarketingOthers.XML","setContent(oHTTP.responseText);",false);
}
function getContentForSamples()
{
getHTTP("R6MarketingSamples.XML","setContent(oHTTP.responseText);",false);
}

/*******************************************************************
**   function setMainMenu : Called By function Init               **
**   2007.11.06 - getGTTP(menuhtml) for divMenu                   **
**   Note: Cross Browser Test at botom includes the text for      **
**   both DOMParser (mozilla) and ActiveX (IE) XML streams. As    **
**   noted, DOMParser will not report XML tags or HTML tags, and  **
**   therefore will not parse to an "innerHTML" assignment.       **
**                                                                **
**   2007.12.95 A file with tags loaded as string through getHTTP **
**   in function Init is assigned to divMenu on the caller's      **
**   onload function                                              **
*******************************************************************/
function setContent(theResponse)
{
window.document.getElementById('Content').innerHTML=theResponse;
}

function setNotices(theResponse)
{
window.document.getElementById('Notices').innerHTML=theResponse;
}

function setMainMenu(theResponse)
{
window.document.getElementById('mainMenu').innerHTML=theResponse;
/******************************************************************
**    Cross Browser Test - DOMParser() vs Microsoft.XMLDOM       **
*******************************************************************
** var text="<note><to>Tove</to><from>Jani</from><heading>       **
** Reminder</heading><body>Don't forget me this weekend!</body>  **
** </note>"                                                      **
*******************************************************************
var oXML = getXMLDOC(theResponse);
alert("Text of first child element (Tove): ");
alert(oXML.childNodes[0].childNodes[0].nodeValue);
alert("Text of second child element (Jani): ");
alert(oXML.childNodes[1].childNodes[0].nodeValue);
alert("Text of third child element (Reminder): ");
alert(oXML.childNodes[2].childNodes[0].nodeValue);
********************************************************************
**       End DOM Parser MSXML Cross Browser Test                  **
*******************************************************************/
}
/*******************************************************************
**   function getXMLDOC :   Called anyone needing an XML Document **
**   2007.12.08: Initiall the XML object was set globally (like   **
**               the _HTTP), but the IE AciveX MSXML would not    **
**               render a useabl XML doc unless the user class    **
**               is intantiated just before the string (quasi) is **
**               parsed to the XML Document. Tried to figure it   **
**               out but gave up                                  **
**   2007.12.09: xmlhttpRequest object has a mime over ride to    **
**               accomodate XML files and HTTP.responseXML:       **
**               oHTTP.overrideMimeType('text/xml');              **
**               Use "isXML" as false for non complianant XMLs    **
**               to avoid Javaconsole errors                      **
*******************************************************************/
function getXMLDOC(theResponse)
{
if (_isBrowserActiveX)
   {
   var theDOC                   = new ActiveXObject("Microsoft.XMLDOM");
       theDOC.async             = "false";
       theDOC.resolveExternals  = "false";
       theDOC.loadXML(theResponse);
   }
else
   {
   var theDOC                   = new DOMParser();
       theDOC = theDOC.parseFromString(theResponse,"text/xml");
   }
theDOC = theDOC.documentElement;
return theDOC;
}
/*******************************************************************
**   function processReqChange: Called [only] by function getHTTP **
**   2007.12.08: Moved back to a Javascript eval() function to    **
**               process the caller's goto method. For example,   **
**               "theMethod" (global var) for the Init function   **
**               is:                                              **
**               theMethod="setMainMenu(_HTTP.responseText);"     **
**   2007.12.09  Need to add status=200 check                     **
*******************************************************************/
function processReqChange(oHTTP,theMethod)
{
if (oHTTP.readyState == 4)
   {
   eval(theMethod);
   }
return null;
}
/*****************************************************************************
**   function postHTTP: Called by any function needing an HTTP              **
**                     "GET".                                               **
**   2009.02.02: Results are parsed to string through getXMLDOC             **
**               and then sent to function designated in global             **
**               var "theMethod".                                           **
**                                                                          **
** var lcXML="<?xml version=\"1.0\"?><row><aid>"+cWinName+"</aid></row>"    **
** var lcURL="http://www.r6solutions.com/OPL1_SIM2.HTM"                     **
** var lcMethod="window.open(\"http://www.r6solutions.com/OPL1_SIM2.HTM\")" **
** postHTTP(lcURL,lcXML,lcMethod,false);                                    **
*****************************************************************************/
function postHTTP(theURL,theXML,theMethod,isXML)
{
alert("top of postHTTP");
var oHTTP;
if (window.XMLHttpRequest)
   {
   alert("firefox");
   oHTTP = new XMLHttpRequest();
   if (oHTTP.overrideMimeType)
      {
      if (isXML)
         {
         oHTTP.overrideMimeType('text/xml');
         }
      else 
         {
         oHTTP.overrideMimeType('text/plain');
         }
      }
   } 
else /*IE*/
   {
   try 
   {
   alert("IE");
   oHTTP = new ActiveXObject("Msxml2.XMLHTTP");
   } 
   catch (e)
   {
      try 
      {
      oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {}
   }
   }

if (!oHTTP)
   {
   alert('Timed Out : Cannot create an HTTP instance');
   return false;
   }
else 
   {
   oHTTP.onreadystatechange = 
        function() {processReqChange(oHTTP,theMethod);};
   oHTTP.open("POST", theURL, false);
   oHTTP.setRequestHeader("Content-Type", "text/xml");
   oHTTP.setRequestHeader("Connection", "close");

   oHTTP.send(theXML);
   /* oHTTP.abort */
   }
return null;
}
/*******************************************************************
**   function setHTTP: Sets a Global the Cross Browser Compliant  **
**                     HTTP object. Runs 1 time at top of this    **
**                     script.                                    **
**   2007.12.05: Implemented Cross Browser(mozilla)               **
**               XMLHTTPRequest                                   **
**   2007.12.06: Implemented IE MSXML2.HTTP                       **
**   2007.12.07: Implemented Generic IE Microsoft.XMLHTTP         **
**   2007.12.09: Turned off untilsynchronios vehaviors are        **
**               resolved.                                        **
**   Note: This feature will retrieve XML and HTML "GET" strings  **
**         But nnot to forget that DOMParser (mozilla) will not   **
**         reports HTML or XML tags.                              **
*******************************************************************/
function setHTTP()
{
if (_isBrowserActiveX)
   {
   var theHTTP = new ActiveXObject("Microsoft.XMLHTTP");
   }
else
   {
   var theHTTP = new XMLHttpRequest();
   }
return theHTTP;
}

/*******************************************************************
**          End R6Marketing.JS  2007.12.08                        **
**                              2007.12.09                        **
**                              2007.12.21                        **
*******************************************************************/

