
// Copyright (c) 2000-2007, 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-69_28_393
        /*
         * catchPreview.js
         *
         * This catches content thrown by the Preview Pane of Outlook and other areas
         * where Javascript is disabled.
         */

        // gather location, if 'location' bar is not there a blank
        // string is returned
        var t = new String(""+this.parent.location);

        // check for '?'.   If present, process name / value pairs.
        if (t.indexOf("?") != -1) {
             // 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;

             }

             // 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);}
             }

             // go ahead and run paren1.. no matter what is in it
             // since by this time it contains a reference to something in the
             // engine
			eengineConfig.subscribe( paren1,"eengine.postProcess.engineidle");
        }

        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();
        }
      
    