var dwOrigRate = 6;
var fRefreshOK = 1;
var fAdultMode = false;
var fSnoopMode = false;

function IsThis( szWhat )
{
    return( 0 < location.pathname.indexOf( szWhat ) );
}

function SaveSettings()
{
    if( IsThis( "pic" ) )
    {
        if( dwOrigRate != document.hatens3.dwRefreshRate.value )
        {
            document.cookie = "RefreshRate="+Number(document.hatens3.dwRefreshRate.value)+":Snoop="+Number(fSnoopMode)+":Adult="+Number(fAdultMode)+"; expires=Thu, 06-Dec-2033 00:00:01 GMT";
        }
    }
    else if( IsThis( "journal" ) )
    {
        if( ( fSnoopMode != document.frm.fSnoop.checked ) || ( fAdultMode != document.frm.fAdult.checked ) )
        {
            document.cookie = "RefreshRate="+dwOrigRate+":Snoop="+Number(document.frm.fSnoop.checked)+":Adult="+Number(document.frm.fAdult.checked)+"; expires=Thu, 06-Dec-2033 00:00:01 GMT";
        }
    }
}

function StopIt()
{
    fRefreshOK = 0;
}

function SaveAndRefresh()
{
    SaveSettings();
    document.location.reload();
}

function GetCookieStr( szSeekStr )
{
    szCookieStr = document.cookie.substring( document.cookie.indexOf( szSeekStr ) + szSeekStr.length );
    dwIndex = szCookieStr.indexOf( ":" );
    if( 0 < dwIndex)
    {
       szCookieStr = szCookieStr.substring( 0, dwIndex );
    }

    dwIndex = szCookieStr.indexOf( ";" );
    if( 0 < dwIndex)
    {
       szCookieStr = szCookieStr.substring( 0, dwIndex );
    }

    return( szCookieStr );
}  

function GetRefreshRate()
{
    if( document.cookie )
    { 
        return( Number( GetCookieStr( "RefreshRate=" ) ) );
    }
    else
    {
        return( 7 );
    }
}   

function RefreshNow()
{
    SaveSettings();

// Can't do this because JScript forces use of cache <ack!>
//    document.zpic.src = "http://www.nwlink.com/~zachd/webcam32.jpg";

    if( 1 == fRefreshOK )
    {
        document.location.reload();
    }
}

function MakeNewWindow( szPage )
{
    SaveSettings();
    if( "pic2.html" == szPage )
    {
        window.open( szPage,"camA","height=265,width=360,resizable=yes,scrollbars=yes,toolbar=no,status=no" );
    }
    else
    {
        window.open( szPage,"camB","height=265,width=360,resizable=yes,scrollbars=yes,toolbar=no,status=no" );
    }
}

function WrapSection( szType, szPoint )
{
    if( "Snoop" == szType )
    {
        if( "Begin" == szPoint )
        {
            if( !fSnoopMode )
            {
                document.write( "<b>&lt;snoop&gt;Hiding personal section.  If you want to see this, click the \"Snoop\" checkbox and reload the page.</b><font color=ccffdd>");
            }
            else
            {
                document.write( "<b>&lt;snoop&gt;</b>");
            }
        }
        else if( "End" == szPoint )
        {
            if( !fSnoopMode )
            {
                document.write( "</font><b>&lt;/snoop&gt;</b>");
            }
            else
            {
                document.write( "<b>&lt;/snoop&gt;</b>");
            }
        }
    }
    else if( "Adult" == szType )
    {
        if( "Begin" == szPoint )
        {
            if( !fAdultMode )
            {
                document.write( "<b>Hiding adult section.  If you want to see this, click the \"Adult\" checkbox and reload the page.</b><font color=ccffdd>");
            }
            else
            {
                document.write( "<b>&lt;adult&gt;</b>");
            }
        }
        else if( "End" == szPoint )
        {
            if( !fAdultMode )
            {
                document.writeln( "</font>");
            }
            else
            {
                document.write( "<b>&lt;/adult&gt;</b>");
            }
        }
    }
}

if( IsThis( "journal" ) )
{
    fSnoopMode = ( "1" == GetCookieStr( "Snoop=" ) );
    fAdultMode = ( "1" == GetCookieStr( "Adult=" ) );
    document.write( "<input type=checkbox name=fSnoop " + ( fSnoopMode ? "checked" : "" ) +">I want to be a snoop.<br>" );
    document.write( "<input type=checkbox name=fAdult " + ( fAdultMode ? "checked" : "" ) +">I want to view adult entries.<br>" );
}
else
{
    fSnoopMode = ( "1" == GetCookieStr( "Snoop=" ) );
    fAdultMode = ( "1" == GetCookieStr( "Adult=" ) );
}

if( !IsThis( "instapic" ) )
{
    dwOrigRate = GetRefreshRate();
}


function Swear( szPhrase )
{
    if( !fAdultMode )
    {
         var dwLength = szPhrase.length - 1;
         var dwCurrentIndex = 0;
         document.write( szPhrase.substr( 0, 1 ) );
         while( dwCurrentIndex < dwLength )
         {
             document.write( "*" );
             dwCurrentIndex++;
         }
    }
    else
    {
         document.write( szPhrase );
    }
}


function ZDate( szDate )
{
    document.write( "<a name=\"" + szDate + "\"><b><font size=+1>" + szDate + "</font>.</b></a>" );
}

function ZEntry( szDate )
{
    document.write( "<a href=\"#" + szDate + "\">" + szDate + "</a>" );
}


