// Initialize for remote JS loading

    var store_xmlhttp=false;
    var store_destObjRef;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
     try {
      store_xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
      try {
       store_xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
       store_xmlhttp = false;
      }
     }
    @end @*/
    if (!store_xmlhttp && typeof XMLHttpRequest!='undefined') {
    	try {
    		store_xmlhttp = new XMLHttpRequest();
    	} catch (e) {
    		store_xmlhttp=false;
    	}
    }
    if (!store_xmlhttp && window.createRequest) {
    	try {
    		store_xmlhttp = window.createRequest();
    	} catch (e) {
    		store_xmlhttp=false;
    	}
    }

    function store_dynRemoteJSCallbackExecute() {
     if (store_xmlhttp.readyState==4)
     {
      // alert("response");
      // alert(store_xmlhttp.responseText);

      // create a new function with the returned javascript function body
      var returnFunction=new Function(store_xmlhttp.responseText);

      // then execute the newly created function
      returnFunction();
     }
    }

    function store_dynRemoteJSCallbackExecuteGlobal() {
     if (store_xmlhttp.readyState==4)
     {
      // alert("response");
      // alert(store_xmlhttp.responseText);

      // then execute the returned content globally, expects to be wrapped in a <script> tag
      store_evalScriptsGlobal(store_xmlhttp.responseText);
     }
    }

    function store_evalScriptsGlobal(htmlContent)
    {
         // find all script elements in the HTML and eval them globally
          var scriptText = htmlContent;
          var VstartIdx;
          var VendIdx;

          // convert all script tags to lowercase
          scriptText = scriptText.replace(/script/gi,"script");


          VstartIdx = scriptText.indexOf("<script");
          while (VstartIdx != -1)
          {
            VstartIdx = scriptText.indexOf(">", VstartIdx) + 1; // seek to end of tag and one char after
            VendIdx = scriptText.indexOf("</script", VstartIdx) - 1; // search for close tag and one char before

            // there is only a string to extract if ending char location is at or after start location
            if (VendIdx >= VstartIdx)
            {
              var strData = scriptText.substring(VstartIdx, VendIdx);
              if (strData.length > 0)
              {
                // need to eval in a global context
                // otherwise variables defined will exist only within this function

                // IE =exectScript, FF/chrome/etc =wind.eval
                if (window.execScript)
                  { window.execScript(strData); }
                else
                  { window.eval(strData); }
              }
            }

            VstartIdx = scriptText.indexOf("<script", VendIdx); // search for next opening tag
          }

          /*
                  This was nicer (FF/chrome), but IE wouldn't find the script elements
                  var Idx;
                  var objScripts = store_destObjRef.getElementsByTagName("script")

                  for (Idx = 0; Idx < objScripts.length; Idx++)
                  {
                    // need to eval in a global context
                    // otherwise variables defined will exist only within this function
                    alert(objScripts[Idx].innerHTML);

                    // IE =exectScript, FF/chrome/etc =wind.eval
                   if (window.execScript)
                     { window.execScript(objScripts[Idx].innerHTML); }
                   else
                     { window.eval(objScripts[Idx].innerHTML); }
                  }
          */
    }


    function store_dynRemoteJSCallbackReplaceContent()
    {
      if (store_xmlhttp.readyState==4)
      {
        // alert("response");
        // alert(store_xmlhttp.responseText);

        // load in the html content
        store_destObjRef.innerHTML = store_xmlhttp.responseText;

        evalScriptsGlobal(store_xmlhttp.responseText);
      }
    }


    function store_dynRemoteJSStartReplaceContent(sourceURL, in_destObjRef)
    {
      if (store_xmlhttp)
      {
        d=document;
        store_destObjRef = in_destObjRef;
        store_xmlhttp.open("GET", sourceURL,true);
        store_xmlhttp.onreadystatechange=store_dynRemoteJSCallbackReplaceContent;
        store_xmlhttp.send(null);
      }
    }

    function store_dynRemoteJSStartEvalGlobal(sourceURL)
    {
      if (store_xmlhttp)
      {
        d=document;
        store_xmlhttp.open("GET", sourceURL,true);
        store_xmlhttp.onreadystatechange=store_dynRemoteJSCallbackExecuteGlobal;
        store_xmlhttp.send(null);
      }
    }

    function store_dynRemoteJSStart(sourceURL)
    {
      if (store_xmlhttp)
      {
        d=document;
        store_xmlhttp.open("GET", sourceURL,true);
        store_xmlhttp.onreadystatechange=store_dynRemoteJSCallbackExecute;
        store_xmlhttp.send(null);
      }
    }



