
// Copyright (c) 2000-2005, Mobular Technologies&#174;, Inc.  All Rights Reserved.
// Mobular and Mobular Technologies are Registered Trademarks of Mobular Technologies, Inc.
// All rights reserved.  Unauthorized reproduction prohibited.
// http://www.mobular.com/
//
// Mobular Engine Serial Number-38_4_4
        /*
         * catchPreview.js
         *
         * This catches content thrown by the Preview Pane of Outlook and other areas
         * where Javascript is disabled.
         */
         
         // Initialize eKit/eDocument
       
        eengine.loadRCOffers();

        eengine.show2pg = eengine.g_show2pgDefault;
        eengine.searchType = "AND";
        eengine.loadDropdownMenus();
        eengine.g_saCurrentQueryString = "";             

        eengine.loadImageMaps();
        eengine.setContactModuleLinks();        
        eengine.setFooterLinks();
                
        //alert (eengine.g_saCurrentQueryString);             
        
        if (g_prtDocs.length > 1)
        {
          g_solution_type = "kit";
        }
        else
        {
          g_solution_type = "e-document";
        }
        
        var g_toc_title = "Table of contents";      
        var g_blankPagetxt = "<br><br><br><br><span class=\"blank_page\">This page<br>intentionally left  blank</span>";        
        var g_animaoff = "<!-- pa_status_start -->Page animation off<!-- pa_status_end -->";
        var g_animaon = "<!-- pa_status_start -->Page animation on<!-- pa_status_end -->";        
        var g_cover = "Cover";        
        var g_spacecover = " cover";        
        var g_searchfor = "Search for ";        
        var g_previoustxt = "Previous";        
        var g_nexttxt = "Next";        
        var g_downloadthetxt = "Download the ";        
        var g_linknotdefinetxt = " link is not defined at the bottom of the index.html file.";        
        var g_helptxt = "Help";        
        var g_printtxt = "Print";
        var g_singpgtxt = "Single page view";
        var g_twopgtxt = "Two page view";
        var g_ecathometxt = "E-catalog home";        
        
        // Warning message for doClickThrough2 from inside the static exe
        var g_exeWarningMessage = 'Accessing content external to the e-document requires that you be online.\n\nNote: You will only be shown this message once.';
        var g_exeWarningMessageShown = false;

        // Warning/error messages
        var g_Messages = new Array( 
          "You have reached the beginning of the e-document." ,
          "You have reached the end of the e-document.",
          "You have reached the beginning of the kit.", 
          "You have reached the end of the kit.", 
          "Your page number is out of range for the current document.  There are only [[total_pages_in_doc]] pages in the [[doc_name]].",
          "Your page range is invalid.  You should have a single page number or an upper and lower bound separated by a dash (e.g. 3-5).\n\nYou entered '[[page_range]]'.  Please reenter your page range and try again.",
          "Please enter a valid page range.",
          "Your page number/range is outside of the range for the current document.  There are only [[total_pages_in_doc]] pages in the [[doc_name]] document.\n\nYou entered '[[page_range]]'.  Please reenter your page range and try again.",
          "There is a ten (10) page limit for low resolution print jobs.  Please reduce your print range and try again.",
          "The calling location for a call to doStandardClickThrough must be either 'ContactModule' or 'Footer'.  Please fix the showglobalrc.html and/or footer.html accordingly.  Exiting."
        );        
        
        
        // Clean out anything that has been know to appear in the e-document database that
        // is incorrect.  
        
        // Database cleaner array
	var g_db_fixes = new Array(
	  "i 5|i5",
	  "i series|iseries",
	  "x series|xseries",
	  "&#222;|fi",
	  "&#151; |",
	  "&#170;|&trade;",
	  "&#208;|-",
	  "&#223;|fl",
	  "&#151;|-"
        );
        
        // Database cleaner code
        for(var i=0;i<database.length;i++)
        {
  	  for (var j=0;j<g_db_fixes.length;j++) 
  	  {
            var fix_tokens = g_db_fixes[j].split('|');
            database[i] = database[i].replace(eval('/' + fix_tokens[0] + '/g'), fix_tokens[1]);
          }
        }



 
        // gather location, if 'location' bar is not there a blank
        // string is returned
        var t = new String(""+this.parent.location);

        
        // turn tracking off (value = 1).. IBM request
        eengine.track = 1;
        
        // provide custom/generic url for tracking if desired.
        eengine.track_url_gen = "";

        // warn user if needed.
        eengine.wrnUsr(); 
  
        // check for '?'.   If present, process name / value pairs.
        if (t.indexOf("?") != -1) {

             // For some unknown reason, some the SMB group starts their query string with
             // an ampersand, which should only be a separator.  If you see this situation,
             // fix it and remove this leading ampersand.
             t = t.replace("?&", "?");

             // strip off html file name
             t = t.substring(t.indexOf("?")+1);
             t = unescape(t);
 
             // clear out any Image#.x or Image#.y that can confuse split functions.
             var iChk = /(Image[0123456789]+)\.([xy]+)=/gi;
             t=t.replace( iChk, "$1_$2=" );

             var iChkS = /(search[0123456789]+)\.([xy]+)=/gi;
             t=t.replace( iChkS, "$1_$2=" );

             var iChkG = /(go[0123456789]+)\.([xy]+)=/gi;
             t=t.replace( iChkG, "$1_$2=" );
 
             // stores the value taken from the name value pair
             var paren1 = "";
             var dCT = 0;

             // this is the only special regular expression..
             // this is the catch-all that runs most href engine commands.
             var objRegExpBtn   = /[\?]*where=(.+)[&]*/;

             var _prm = t.split('&');

             // remove any stray '?' items that would prevent parsing
             for ( var i=0; i < _prm.length; i++ ) {
                 if ( _prm[i].indexOf("?") > 0 ) {
                   _prm[i] = _prm[i].substring( _prm[i].indexOf("?")+1 );
                 }
             }

             var frmObj = new Array();
             for ( var i=0; i<document.forms.length; i++ ) {
                if ( document.forms[i].name )
                  frmObj[frmObj.length] = "document."+document.forms[i].name;

             }
            
             // check for a staticframe if necessary
             // This should work for a framed and non framed build
             if ( parent ) {
               if ( parent.staticFrame ) {
                 if ( parent.staticFrame.document ) {
                   for ( var i=0; i<parent.staticFrame.document.forms.length; i++ ) {
                      if ( parent.staticFrame.document.forms[i].name )
                        frmObj[frmObj.length] = "parent.staticFrame.document."+parent.staticFrame.document.forms[i].name;
      
                   }    
                 }
               }
             }

             // process the url string from the user action...
             for ( var j=0; j < frmObj.length; j++ ) {
                for ( var i=0; i < _prm.length; i++ ) {

                     var elem = _prm[i].split('=');
                     var _obj = frmObj[j] + "." + elem[0];

                     if ( eval(_obj) ) {
                        // pull action sequence from form tag
                        var act = pullAction( frmObj[j] );

                        switch ( eval(_obj + ".type" ) ) {
                          case "select-one":
                             // process combo box like prodGroup, brandGroup
                             if ( act != "" ) {
                               cbxFillValue( eval(_obj), elem[1]);
                               if ( paren1 == "" ) paren1 = act;
                             }

                             // this is the default choice for a drop down
                             if ( paren1 == "" ) paren1 = "eengine.writePage(document.prodForm.prodGroup.options[document.prodForm.prodGroup.selectedIndex].value)";

                             break;
                          case "text":
                             // process text box... like query, pagenumber and so on
                                                
                             // compensate if the user has entered a single tick mark
                             t=0;
      		       if ( elem[1].indexOf("'") != -1 ) dCT = 1;

                             paren1 = processQuery(elem[1], _obj, act);

                             break;
                        }

                     }

                }
             } 
 
             // final check.. look for standard where= commands
             if (objRegExpBtn.test(t)) {
                 paren1 = RegExp.$1; 
                 if ( paren1.toLowerCase().indexOf("doclickthrough") != -1 ) dCT = 1;
             }

             // clear out any pesky encoded characters.
             if ( dCT == 0 ) {
               paren1 = unescape(paren1);
               var stopspot = paren1.indexOf("?");
               if(stopspot != -1){paren1 = paren1.substring(0,stopspot);}
             }
             
             // hand the query string to the global parameter that SurfAid will use if present.
             eengine.g_saCurrentQueryString = t;             

	     // if blank.. must be the start.. assume this and push b level             
             if ( paren1 == '' ) {           
             //   eengine.writePage2(1);
             // DKR/2005-04-08...For IBM this needs to call showShow2 not writePage2(1)
                eengine.showShow2();
             }

             // Special checks to enable a few functions for IBM.
             if ( (paren1.toLowerCase().indexOf("writepage2") != -1) ||
                  (paren1.toLowerCase().indexOf("writeseries") != -1) ||
                  (paren1.toLowerCase().indexOf("godetail") != -1) ||
                  (paren1.toLowerCase().indexOf("goproductlist") != -1) ||
                  (paren1.toLowerCase().indexOf("showfeaturedoffers") != -1) ||
                  (paren1.toLowerCase().indexOf("gotodocumentbynumber") != -1) ||
                  (paren1.toLowerCase().indexOf("alertsurfaid") != -1)                  
                ) {
                eval(paren1);
             }

             // go ahead and run paren1.. no matter what is in it
             // since by this time it contains a reference to something in the
             // engine
             // IBM requested we disable this.  Since they're not using S2F, Chris says no problem.
             //eval(paren1);
        } 
          else {   
          eengine.showShow2();
        }

        function pullAction(f_obj) {

           var r_val = "";

           var act = eval(f_obj + ".action");
           if ( act != "" ) {
              var act_ar = act.split('=');
              if ( act_ar.length > 1 ) r_val = act_ar[1];
           }

           return r_val;
        }

        // processes any search requests
        function processQuery(_p, obj, act) {

           // replace any spaces
           if ( _p != "" ) {
              var regrep = /\+/ig
              _p = _p.replace( regrep, ' ' );
           }

           // push value back into text box
           eval(obj + ".value = _p");

           // compensate if the user has entered a single tick mark
           if ( _p.indexOf("'") != -1 ) {
             _p = "eengine.search(\""+_p+"\", '*')";
           } else {
             _p = "eengine.search('"+_p+"', '*')";
           }

           if ( act )
             if ( act != "" )
               _p = act;
               
           return _p;
        }

        // this was added to accomodate the capture of the drop down
        // box values when exploding out of an Outlook preview window.
        function cbxFillValue(cbx, val) {
          if ( val != "" ) {
            // remove '+' if present
            var regrep = /\+/ig

       	 // replace and spaces
       	 val = val.replace( regrep, ' ' );

       	 // reverse any encoding
       	 val = unescape(val);

               for (var ii=0; ii < cbx.length; ii++) {
       	   var cbxVal = cbx.options[ii].value;
       	   if ( cbxVal.toUpperCase() == val.toUpperCase() ) {
       	     cbx.selectedIndex = ii;
       	     break;
                 }
               }
          }
        }

        // *************************************
        //Clear keyword if it is the default
        function resetForm() {
           parent.searchFrame.document.searchForm.reset();
        }
        
        
        eengine.addSurfAid('DocumentOpen', null, null);
        
        var total_load = 1;

