function JumpOut(sURL, iWinConfig, iWidth, iHeight){
//  ==============================================================================            
//  Purpose: This method ensures that whenever the user clicks on a link to 
//           another website that we open only one window per site. 
//           For example, if the user clicks on the link to TRN, this method 
//           guarantees we convert the url 'http://www.tax.cch.com/cchessence/..."
//           to a window name of 'wwwtaxcchcom'. The window is always centered
//           on the screen.
//  Author : Mark Orlando      Last Modified: 8/17/2001
//  ==============================================================================
    var sWindowName;
    var sWindowArgs;
    var iPos;
    var sTemp;
    
//  ==============================================================================
//  gpaLooknFeel could look like: q3tads
//  thisURL      could look like: /freecoderegs/InternalRevenueCode/default.asp
//  thisDomain   could look like: 165.181.122.30
//  ==============================================================================

//  Strip away all characters such as 'http://'    
    sWindowName = sURL;
    iPos=sWindowName.indexOf("//");
    if (iPos > -1){              
        sWindowName = sWindowName.substring(iPos+2, sWindowName.length-1);   
    }
//  Strip away all characters to the right of '/'    
    iPos=sWindowName.indexOf("/");
    if (iPos > -1){              
        sWindowName = sWindowName.substring(0, iPos);                
    }
//  ==============================================================================    
//  If there are no more character we know the url is within TADS. 
//  Therefore swap the current document with the requested page.
//  ==============================================================================
    if (sWindowName.length==0){                
        if(typeof(gpaLooknFeel) == "undefined"){
            var newURL=sURL;
        } else {
            var foundAt = sURL.indexOf('?');
            if (foundAt==-1){
                var newURL=sURL+'?gpalooknfeel='+gpaLooknFeel;
            } else {
                var newURL=sURL+'&gpalooknfeel='+gpaLooknFeel;
            }
        }
        document.location=newURL;
        return;
    }        
//  ==============================================================================
//  At this point we know the user wants to go somewhere outside our domain.
//  ==============================================================================  
    iPos=sWindowName.indexOf(".");
    while(iPos>-1){
        sWindowName = sWindowName.substring(0, iPos) + sWindowName.substring(iPos+1, sWindowName.length);  
        iPos=sWindowName.indexOf(".");                      
    }
    sWindowName=sWindowName.toLowerCase();
    
    if (iWidth==null){
        iWidth  = parseInt(screen.width  * .75);
    }
    if (iHeight==null){
        iHeight = parseInt(screen.height  * .75);
    }          
    var iLeft = parseInt((screen.width - iWidth)/2);
    var iTop = parseInt((screen.height - iHeight)/2);
                
    if (iWinConfig==null){
        iWinConfig=0;
    }          
    switch (iWinConfig){
        case 0 : 
            iTop = iTop - 75;  // We have to remove 75 pixels when displaying menubar and toolbar.
            sWindowArgs = 'resizable=yes,menubar=yes,toolbar=yes,scrollbars=yes,status=yes,' +
                          'directories=no,location=yes,width=' + iWidth + ',height=' + iHeight +
                          ',top=' + iTop + ',left=' + iLeft;
            break;
        default: 
            sWindowArgs = 'resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=no,' +
                          'directories=no,location=yes,width=' + iWidth + ',height=' + iHeight +
                          ',top=' + iTop + ',left=' + iLeft;
    }        
    if (window.sWindowName) {
        window.sWindowName.focus();
    } else {
        window.open(sURL, sWindowName, sWindowArgs); 
    }
} 
function GetCookie(name) {
//  =====================================================================================
//  Purpose: This method (taken from JavaScript Primer Plus) is is used to retrieve the
//           value of a cookie.
//  Author:  Mark Orlando 8/3/2001
//  =====================================================================================
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function getCookieVal(offset) {
//  =====================================================================================
//  Purpose: This method (taken from JavaScript Primer Plus) is called by GetCookie.
//  Author: Mark Orlando 8/3/2001
//  =====================================================================================
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value) {
//  =====================================================================================
//  Purpose: This method sets the value of a cookie. Taken from JavaScript Primer Plus.
//           Whenever we update the cookie, we set the expiration to 60 days from now.
//  Author: Mark Orlando 8/3/2001
//  =====================================================================================
  var expirationDate = new Date();
  expirationDate.setTime (expirationDate.getTime() + 60 * (24 * 60 * 60 * 1000));

  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = expirationDate;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}
//--------------------------------------------------------------------
// This will open a new window in a pop-up.

function rPopUpAWindow( WindowTitle, WindowName, TheURL, TheWidth ) {
	rPopUpAWindowWithHeight( WindowTitle, WindowName, TheURL, TheWidth, 450);
}


var gTheWindow=null;


function rPopUpAWindowWithHeight( WindowTitle, WindowName, TheURL, TheWidth, TheHeight ) {

    
    var TheDocument;
    var Width;
	
	if ((gTheWindow!=null)&&(!(gTheWindow.closed))){gTheWindow.close();}
    
    gTheWindow = window.open( "", WindowName, "resizable=yes,menubar=no,toolbar=no,scrollbars=yes,status=no,directories=no,location=no,width=" + TheWidth + ",height=" + TheHeight );
    TheDocument = gTheWindow.document;
    TheDocument.close();
    
    TheDocument.open("text/html", "replace");
    TheDocument.write("<HTML><HEAD><TITLE>Please wait:  Loading " + WindowTitle + "</TITLE></HEAD><BODY BGCOLOR=#FFFFFF><TABLE BORDER=0 WIDTH=100% HEIGHT=100% ><TR><TD VALIGN=CENTER ALIGN=CENTER><FONT FACE=Arial SIZE=2 COLOR=#000080><STRONG>Please wait:  Loading " + WindowTitle + ". . .</STRONG></FONT></TD></TR></TABLE></BODY></HTML>");
    TheDocument.close();
    gTheWindow.focus();
    gTheWindow.location = TheURL;
}
function OpenNonModal(sURL, iWidth, iHeight, sToolBar, sMenuBar, sResizable){
//  Launch a web page in a new non-modal window.
    if (sToolBar == null){
        sToolBar = "no";
    }
    if (sMenuBar == null){
        sMenuBar = "yes";
    }   
    if (sResizable == null){
        sResizable = "yes";
    }      
    var iLeft = parseInt((screen.width - iWidth)/2);
    var iTop  = parseInt((screen.height - iHeight)/2)-60;
    var vRC=window.open(sURL, "_blank","location=no menubar=" + sMenuBar + " resizable=" + sResizable +" scrollbars=" + sResizable + " status=yes toolbar=" + sToolBar + " top=" + iTop + " left=" + iLeft + " width=" + iWidth + " height=" + iHeight)
}

function OpenModal(sURL, iWidth, iHeight, addtlArgs) {
//  ======================================================================================
//  Launch a web page in a modal window. If the user closes the window via the close box 
//  or presses the cancel button, this method will return null. Any developers using this 
//  method must code any Cancel buttons to return a -1 or spaces.    
//  Author: Mark Orlando 7/27/2001
//  ======================================================================================
    var iLeft = parseInt((screen.width - iWidth)/2);
    var iTop = parseInt((screen.height - iHeight)/2);
    if (addtlArgs == null){
        var vArgs = '';
    } else {
        var vArgs = addtlArgs;
    }
    var vRC = window.showModalDialog(sURL, vArgs, 'dialogWidth:'+iWidth+'px; dialogHeight:'+iHeight+'px; dialogLeft:'+iLeft+'px; dialogTop:'+iTop+'px;');
    
    if (vRC == -1 || vRC == null || vRC == "") {
        return null;
    } else {
        return vRC;
    }             
}       
function vPA_LoadArrayOfImages (vImagePaths) {
//  ======================================================================================
//  Purpose: Load an array of image names into actual images
//  Example: 1. Create an array of all the images to be loaded...
//              var gvPA_ImagePaths = new Array ("/wk-graphics/wk-pri-tax-prep-02-b.gif",
//                                               "/wk-graphics/wk-pri-tax-prep-01-b.gif",
//                                               "/wk-graphics/wk-pri-tax-research-01-b.gif",
//                                               "/wk-graphics/wk-pri-tax-research-02-b.gif",
//                                               "/etc");
//           2. Now load it into cache...
//              var gvPA_CachedImages = vPA_LoadArrayOfImages(gvPA_ImagePaths);
//  ======================================================================================
    var  i;
    var  vImages;
    vImages = new Array(vImagePaths.length);
    for ( i=0; i < vImagePaths.length; i++ ) {
        vImages[i] = new Image();
        vImages[i].src = vImagePaths[i];
    }
    return vImages;
}        
//--------------------------------------------------------------------
//  Tests for browser types.

function rfIsNetscape ( ) {

    return navigator.appName == "Netscape";
}

function rfIsMSIE ( ) {

    return navigator.appName == "Microsoft Internet Explorer"
}

function rfIsMSIEv55 ( ) {

    return rfIsMSIE() && navigator.appVersion.indexOf( "5.5" ) >= 0;
}

//
function rfIsNetscape476 ( ) {

    return rfIsNetscape() && navigator.appVersion.indexOf( "4.76" ) >= 0;
}

//
function rfIsNetscapeUnder5 () {
  var xver;
  if  (rfIsNetscape ()){
   xver = navigator.appVersion.charAt(0);
   //alert ("xver=" + xver);
   return xver < 5;
   }
}

//--------------------------------------------------------------------
//  Browser/window functions:

function rWindowHeight ( ) { return rfIsMSIE() ? document.body.clientHeight : window.innerHeight ; }
function rWindowWidth  ( ) { return rfIsMSIE() ? document.body.clientWidth  : window.innerWidth  ; }
function rVScroll      ( ) { return rfIsMSIE() ? document.body.scrollTop    : window.pageYOffset ; }
function rHScroll      ( ) { return rfIsMSIE() ? document.body.scrollLeft   : window.pageXOffset ; }

//====================================================================
//  The following are functions for manipulating a DIV/LAYER:

function rLocateOurGuy ( OurGuysName ) {
    
    if ( rfIsMSIE() ) {
    
        return document.all.tags("DIV")(OurGuysName);
    }
    else if ( rfIsNetscape() ) {
    
        return document.layers[OurGuysName];
    }
}

//------------------------------------------

function rCenterIt ( OurGuysName, OurGuysWidth, OurGuysHeight ) {

    var  OurGuy = rLocateOurGuy( OurGuysName );
    
    if ( OurGuy == null ) return;
    
    if ( rfIsNetscape() ) {
    
        OurGuysWidth  = OurGuy.clip.width;
        OurGuysHeight = OurGuy.clip.height;
    }

    var LastCHeight = rWindowHeight();
    var LastCWidth  = rWindowWidth();
    var LastLScroll = rHScroll();
    var LastTScroll = rVScroll();
    var YDelta       = (LastCHeight - OurGuysHeight)/2;
    var XDelta       = (LastCWidth  - OurGuysWidth) /2;
    if ( YDelta < 0 ) YDelta = 0;
    if ( XDelta < 0 ) XDelta = 0;
    
    if ( rfIsMSIE() ) {
        OurGuy.style.top  = LastTScroll + YDelta;
        OurGuy.style.left = LastLScroll + XDelta;
        OurGuy.style.zIndex = 10;
    }
    else {
        OurGuy.moveToAbsolute( LastLScroll+XDelta, LastTScroll+YDelta );
    }
}

//------------------------------------------

function rKeepAtTop ( OurGuysName ) {

    var  OurGuy = rLocateOurGuy( OurGuysName );
    
    if ( OurGuy == null ) return;

    var LastCHeight = rWindowHeight();
    var LastCWidth  = rWindowWidth();
    var LastLScroll = rHScroll();
    var LastTScroll = rVScroll();
    
    if ( rfIsMSIE() ) {
        OurGuy.style.top  = LastTScroll + 5;
        OurGuy.style.left = LastLScroll + 5;
    }
    else {

        var Offset = (LastCWidth - OurGuy.clip.width) / 2;
        OurGuy.moveToAbsolute( LastLScroll+Offset, LastTScroll+5);
    }
}

//------------------------------------------

function rShowIt ( OurGuysName, fOn ) {

    var  OurGuy = rLocateOurGuy( OurGuysName );
    
    if ( OurGuy != null ) { 
    
        if ( rfIsMSIE() ) {

            OurGuy.style.display = fOn ? "" : "none";
        }
        else {

            OurGuy.visibility = fOn ? "show" : "hide";
        }
    }
}

//====================================================================
//  The following set of functions are used to control the 
//  'please wait' display, in conjunction with please-wait-box.htm.

var gCCOnBox     = 0; 
var gCCDirection = 1;

function rChangeColor ( ) { 
   var i;	
   for ( i=0; i < 12; i++ ) { 
   
       if ( rfIsNetscape() ) {
       
           var TheLayer   = document.layers["T" + i];
           if ( i == gCCOnBox ) { 
               TheLayer.bgColor  = "#000080";
           } 
           else if ( i == gCCOnBox-1 || i == gCCOnBox+1) { 
               TheLayer.bgColor  = "#C0C0FF"; 
           } 
           else {
               TheLayer.bgColor  = "#FFD700";
           }
       }
       else {
       
           var OurGuy     = "T" + i; 
           var el         = document.all[OurGuy]; 
           var TheColor   = "#FFD700"; 
           var TheBGColor = "#FFFFC0";
           if ( i == gCCOnBox ) { 
               TheColor   = "#FFFFFF";	
               TheBGColor = "#000080"; 
           } 
           else if ( i == gCCOnBox-1 || i == gCCOnBox+1) { 
               TheColor   = "#000080";	
               TheBGColor = "#C0C0FF"; 
           } 
           el.style.color           = TheColor; 
           el.style.backgroundColor = TheBGColor;
       }
   } 
   if ( gCCOnBox == 11 ) gCCDirection = -1;
   if ( gCCOnBox == 0  ) gCCDirection = 1;	
   gCCOnBox += gCCDirection; 
   setTimeout('rChangeColor()', 100);
}

//--------------------------------------------------------------------------- 

function rAlignPleaseWaits ( ) {

    if ( !rfIsNetscape() ) return;
    
    var i, TheLayer;
    
    var ScreenWidth  = rWindowWidth();
    var ScreenHeight = rWindowHeight();
    var HScroll      = rHScroll();
    var VScroll      = rVScroll();
    var YDelta       = (ScreenHeight - 200) / 2 + 125 + VScroll;
    var XDelta       = (ScreenWidth - (24*12)) / 2 + HScroll;
    
    if ( YDelta < 0 ) YDelta = 0;
    if ( XDelta < 0 ) XDelta = 0;
    
    for ( i=0; i < 12; i++ ) {
    
        TheLayer = document.layers["T"+i];
        TheLayer.moveToAbsolute( XDelta + i * 24, YDelta );
        TheLayer.visibility = "show";
    }
}
  
//--------------------------------------------------------------------------- 

function rWritePleaseWaitLayers() {

    var  i;
    var  LeftOffset = (window.innerWidth  - 13*20) / 2;
    var  TopOffset  = (window.innerHeight - 40)    / 3;
    var  TheText    = "CCH INTERNET";

    if ( LeftOffset < 0 ) LeftOffset = 0;
    if ( TopOffset  < 0 ) TopOffset  = 0;
    var  LoginOffset = TopOffset;
    TopOffset += 30;

    for ( i=0; i < 12; i++ ) {
        document.write( "<LAYER CLASS=PleaseWaitLayer ID=T" + i 
                      + " TOP=" + TopOffset + " LEFT=" + (LeftOffset + i*20) 
                      + " WIDTH=20 HEIGHT=20 VISIBILITY=hide BGCOLOR=#FFD700> &nbsp;" 
                      + TheText.charAt(i) + "&nbsp; </LAYER>");
    }
    return true;
}

//--------------------------------------------------------------------------- 

function rWritePleaseWaitDivs ( ) {

    var  TheText    = "CCH INTERNET";
    var  i;
    
    document.write("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=4><TR>");
    
    for ( i=0; i < 12; i++ ) {
       document.write( "<TD><FONT FACE=Arial SIZE=3><B><DIV ID=T" + i + "> &nbsp;" + TheText.charAt(i) + "&nbsp;  </DIV></B></FONT></TD>" );
    }
    document.write("</TR></TABLE>" );
}

//--------------------------------------------------------------------

function rWritePleaseWait ( WindowTitle ) {

    if ( !rfIsNetscape() && !rfIsMSIEv55() ) {
        document.open();
        document.write("<HTML><HEAD><TITLE>Please Wait</TITLE></HEAD>");
        document.write("<BODY>");
        document.write("<TABLE BORDER=0 WIDTH=100% HEIGHT=100% ><TR><TD VALIGN=CENTER ALIGN=CENTER><FONT FACE=Arial SIZE=2 COLOR=#000080><STRONG>Please wait: " + WindowTitle + ". . .</STRONG></FONT></TD></TR></TABLE>");
        document.write("</BODY></HTML>");
        document.close();
    }
}

//--------------------------------------------------------------------

function rPleaseWait ( WindowTitle ) {

    if ( rLocateOurGuy("PleaseWait") != null ) {
    
        rShowIt( "BaseForm",   false );
        rCenterIt( "PleaseWait", 400, 200 );
        rShowIt( "PleaseWait", true  );
        rAlignPleaseWaits();
        rChangeColor();
    }
    else {
    
        rWritePleaseWait( WindowTitle );
    }
}
    
//====================================================================

function rDBG_GetSelectedText ( fAsHTML ) {

    if ( navigator.appName == "Microsoft Internet Explorer" ) {
        var TheTmp = document.selection;
        if ( !TheTmp || !TheTmp.createRange || TheTmp.type == "None" ) {
            return null;
        }
        var TheRange = TheTmp.createRange( );
        if ( !TheRange ) {
            return null;
        } 
        return fAsHTML ? TheRange.htmlText : TheRange.text;
    }
    else {
        document.getSelection();
    }
}

function rDBG_ReportBadLink ( ) {

    var TheForm      = document.linkreporter;
    var TheSelection = rDBG_GetSelectedText(false);

    TheForm.lrfl_page_title.value = document.title;
    TheForm.lrfl_page_url.value   = location.href;

    if ( TheSelection != null ) {

        TheForm.lrfl_link_text.value  = TheSelection;
    }
    TheForm.submit();
}

//====================================================================

 function CreateWBIDCookie(CookieName,StringOfValues){
 		SetCookie(CookieName, StringOfValues); 
 }
     
     
 function readWBIDCookie(CookieName,valueSought){
      return parseWBIDCookieForValue(GetCookie(CookieName),valueSought);
 }
     
     
 function  parseWBIDCookieForValue(CookieData,valueSought){
     var values=CookieData.split(";");   
        for(var i=0;i<values.length;i++){
            if (values[i].indexOf(valueSought+"=")>-1){
                var start=values[i].indexOf("=")+1;
                var end=values[i].length
                return values[i].substr(start,end);
            }
         }
    return "" ;
 }

function AlphaNumericOnly(){
//  ===============================================================================================
//  Purpose:  The purpose of this script it to restrict the contents of a textbox to accept only 
//            alphabetic and numeric characters. If the user enters an unacceptable key, then false 
//            is returned and the invalid key does not appear in the textbox.
//  Inputs:   n/a
//  Example:  The way to trigger the execution of this method is to code the <FORM> tag to resemble:
//                <form name="UserOptions" onkeypress="JavaScript:return AlphaNumericOnly();">
//  Author:   Mark Orlando
//  ===============================================================================================
    var soFarSoGood=false;
    var keyPressed = window.event.keyCode;         // Get the ASCII code of the key that was pressed.
    var cntlInQues = window.event.srcElement;      // Determine what type of control has focus.
    if (keyPressed >= 48 && keyPressed <= 57){               // Number from 0 to 9...
        soFarSoGood = true;
    } else {
        if (keyPressed == 46 || keyPressed == 32){           // Period or blank...
            soFarSoGood = true;
        } else {
           if (keyPressed >= 65 && keyPressed <= 90){        // Letter between A and Z...
               soFarSoGood = true;
           } else {
               if (keyPressed >= 97 && keyPressed <= 122){   // Letter between a and z...
                    soFarSoGood = true;
               } else {
                    return false;
               }
           }
        }
    }
} 
function NumericOnly(){
//  ===============================================================================================
//  Purpose:  This script restricts the contents of a textbox to numeric only.
//  Inputs:   n/a
//  Example:  The way to trigger the execution of this method is to code the <FORM> tag to resemble:
//                <form name="UserOptions" onkeypress="JavaScript:return NumericOnly();">
//  Author:   Mark Orlando
//  ===============================================================================================
    var keyPressed = window.event.keyCode;         // Get the ASCII code of the key that was pressed.
    var cntlInQues = window.event.srcElement;      // Determine what type of control has focus.
    if (cntlInQues.type == "text"){                // Only process text box controls.
        if (keyPressed < 48 || keyPressed > 57){   // If key pressed is not numeric, then exit.
            return false;
        }
    }
} 
function LtrimRtrim(ctrlInQues) {
//  =============================================================================     
//  Purpose:  Removes leading and trailing spaces from the passed string. 
//  Inputs:   Reference to the object that triggered the event.
//  Example:  onBlur="JavaScript:LtrimRtrim(this);"
//  Author:   Mark Orlando
//  =============================================================================      
    var strinInQues = ctrlInQues.value;  
    ctrlInQues.value=LtrimRtrimString(strinInQues);
}
function LtrimRtrimString(someString) {
//  =============================================================================     
//  Purpose:  Removes leading and trailing spaces from a string. 
//  Author:   Mark Orlando
//  =============================================================================      
    var strinInQues = someString;  
    var ch = strinInQues.substring(0, 1);
    while (ch == " ") { // Check for spaces at the beginning of the string
        strinInQues = strinInQues.substring(1, strinInQues.length);
        ch = strinInQues.substring(0, 1);
    }
    ch = strinInQues.substring(strinInQues.length-1, strinInQues.length);
    while (ch == " ") { // Check for spaces at the end of the string
        strinInQues = strinInQues.substring(0, strinInQues.length-1);
        ch = strinInQues.substring(strinInQues.length-1, strinInQues.length);
    }
    return strinInQues;
}
