<!--

// Definition of common JavaScript functions.
// The functions declared in this file are supposed to be used in all,
// or at least the majority of my pages.
// This file (common.js) will be included in all my pages.

// =====================================================================================
// Variable declarations.
// =====================================================================================

// *** Conditional links with cookie counter. ***
var regIdVerify = "verifylinks@schaffter.com"
var regIdVerifyCounter = "verifyLinksCounter@schaffter.com"
var maxCookieCounter = 30

// *** Live mail button. ***
var buttonWidth = 100;
var buttonHeight = 32;
var gifBase = "/gif/btn/";
var mailBtn0;
var mailBtn1;
var mailBtn2;
var mailBtn3;

// =====================================================================================
// Internal functions.
// =====================================================================================

function getVerifyCookieVal(offset)
    {
    var endstr = document.cookie.indexOf(';', offset);
    if(endstr == -1)
        {
        endstr = document.cookie.length;
        }
    return unescape(document.cookie.substring(offset, endstr));
    }

function getVerifyCookie(name)
    {
    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 getVerifyCookieVal(j);
            }
        i = document.cookie.indexOf(' ', i) + 1;
        if(i == 0)
            {
            break;
            }
        }
    return null;
    }

function getVerifyExpiration()
    {
    var expDate = new Date();
    expDate.setTime(expDate.getTime() + (2 * 365 * 24 * 60 * 60 * 1000));
    return expDate;
    }

function setCookie(name, value)
    {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : null;
    document.cookie = name +
                      "=" +
                      escape(value) +
                      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                      ((domain == null) ? "" : ("; domain=" + domain)) +
                      ((secure == true) ? "; secure" : "");
    return;
    }

function forceVerify()
    {
    setCookie(regIdVerify, 1, getVerifyExpiration());
    return;
    }

function releaseVerify()
    {
    setCookie(regIdVerify, 0, getVerifyExpiration());
    return;
    }

function askUserForLink(message, link)
    {
    var cookieValue = getVerifyCookie(regIdVerify);
    var cookieCounter = getVerifyCookie(regIdVerifyCounter);
    if (cookieValue == null)
        {
        cookieValue = 1;    // Verify by default.
        forceVerify();      // Until next time.
        }
    if (cookieCounter == null)
        {
        cookieCounter = 0;
        }
    if (cookieValue == 0)
        {
        // User doesn't want to have verification.
        // Make him remember.
        window.open('/family/memory.html',
                    'Gus',
                    'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=150,height=200');
        location.href = link;
        }
    else
        {
        // Verify.
        if (confirm(message))
            {
            // User wants to leave.
            if (cookieCounter > maxCookieCounter)
                {
                setCookie(regIdVerifyCounter, 0, getVerifyExpiration());
                if (!confirm("You're obviously a frequent flyer here. Do you think that these questions are OK, or would you like me to Cancel this behaviour?"))
                    {
                    releaseVerify();
                    }
                }
            else
                {
                cookieCounter++;
                setCookie(regIdVerifyCounter, cookieCounter, getVerifyExpiration());
                }
            // Leave this site.
            location.href = link;
            }
        }
    return;
    }

function img_act(imgName)
    {
    document[imgName].src = eval(imgName + "1.src");
    }

function img_inact(imgName)
    {
    document[imgName].src = eval(imgName + "0.src");
    }

function img_click(imgName)
    {
    document[imgName].src = eval(imgName + "2.src");
    mailBtn0.src = mailBtn3.src;
    mailBtn1.src = mailBtn2.src;
    }

function overMailButton()
    {
    img_act('mailBtn');
    return true;
    }

function leftMailButton()
    {
    img_inact('mailBtn');
    return true;
    }

function clickMailButton()
    {
    img_click('mailBtn');
    return true;
    }

// ============================================================================
// Public functions.
// ============================================================================

function verifyLink(newLink)
    {
    askUserForLink("You have requested a link to a page that is not part of my Web site. Are you sure that you want to leave my site?",
                   newLink);
    return;
    }

function verifyHugeLink(newLink, downloadSize)
    {
    askUserForLink("The requested link goes to a *huge* page. (About "
                   + downloadSize
                   + " to download.) Are you sure that you want to see this page?",
                   newLink);
    return;
    }

function verifyLanguageLink(newLink, language)
    {
    askUserForLink("You have requested a link to a page that is not part of my Web site."
                   + " Even more, the requested page is written in "
                   + language
                   + "! Are you sure that you want to see this page?",
                   newLink);
    return;
    }

function verifyCountryLink(country)
    {
    askUserForLink("You have requested a link to a page that is not part of my Web site. Are you sure that you want to leave my site?",
                   "http://www.cia.gov/cia/publications/factbook/geos/"+country+".html");
    return;
    }

function showDynamicMailButton()
    {
    if (document.images)    // Images supported by this browser?
        {
        mailBtn0 = new Image();
        mailBtn0.src = gifBase + "mailbtn.gif";
        mailBtn1 = new Image();
        mailBtn1.src = gifBase + "domaibtn.gif";
        mailBtn2 = new Image();
        mailBtn2.src = gifBase + "argh.gif";
        mailBtn3 = new Image();
        mailBtn3.src = gifBase + "bezargh.gif";
        document.write('<a href="/family/mailme.html"');
        document.write(' onMouseover = "overMailButton()"');
        document.write(' onMouseout = "leftMailButton()"');
        document.write(' onClick = "clickMailButton()"');
        document.write('>');
        document.write('<img src="');
        document.write(gifBase);
        document.write('mailbtn.gif" width=');
        document.write(buttonWidth);
        document.write(' height=');
        document.write(buttonHeight);
        document.write(' align="middle" name="mailBtn" naturalsizeflag="3" alt="Mail me!" border=0>');
        document.write('</a>');
/*
        document.write('<BR>')
        document.write('Mailbutton: ')
        document.write(gifBase)
        document.write('mailbtn.gif')
*/
        }
    else
        {
        document.write('<a href="/family/mailme.html"');
        document.write('>');
        document.write('<img src="');
        document.write(gifBase);
        document.write('mailbtn.gif" width=');
        document.write(buttonWidth);
        document.write(' height=');
        document.write(buttonHeight);
        document.write(' align="middle" name="mailBtn" naturalsizeflag="3" alt="Mail me!" border=0>');
        document.write('</a>');
        }
    }

function showPageUpdated() {
	var str=document.lastModified;
	document.write("<CENTER>");
	document.write("This page was last modified on:");
	document.write("<a href='/cpu/tz.html'>");
	document.write(str);
	document.write("</a>.");
	document.write("</CENTER>");
}

function showDynamicFace() {
var now=new Date();
var path='/jpg/faces/';
var file='';
document.write('<CENTER>');
document.write('Author: ');
if(now.getHours()==19) {
   if(now.getMinutes()==10 && now.getSeconds()==5){file='gus001.jpg';}
   if(now.getMinutes()==14 && now.getSeconds()==23){file='gus002.jpg';}
   if(now.getMinutes()==19 && now.getSeconds()==13){file='gus003.jpg';}
   if(now.getMinutes()==34 && now.getSeconds()==57){file='gus004.jpg';}
   if(now.getMinutes()==50 && now.getSeconds()==55){file='gus005.jpg';}
   }
if(now.getHours()==20) {
   if(now.getMinutes()==4  && now.getSeconds()==9){file='gus006.jpg';}
   if(now.getMinutes()==18 && now.getSeconds()==28){file='gus007.jpg';}
   if(now.getMinutes()==29 && now.getSeconds()==19){file='gus008.jpg';}
   if(now.getMinutes()==44 && now.getSeconds()==44){file='gus009.jpg';}
   if(now.getMinutes()==48 && now.getSeconds()==56){file='gus010.jpg';}
   }
if(now.getHours()==21) {
   if(now.getMinutes()==14 && now.getSeconds()==2){file='gus011.jpg';}
   if(now.getMinutes()==18 && now.getSeconds()==23){file='gus012.jpg';}
   if(now.getMinutes()==28 && now.getSeconds()==13){file='gus013.jpg';}
   if(now.getMinutes()==46 && now.getSeconds()==34){file='gus014.jpg';}
   if(now.getMinutes()==59 && now.getSeconds()==46){file='gus015.jpg';}
   }
if(now.getHours()==22) {
   if(now.getMinutes()==1  && now.getSeconds()==8){file='gus016.jpg';}
   if(now.getMinutes()==5  && now.getSeconds()==21){file='gus017.jpg';}
   if(now.getMinutes()==27 && now.getSeconds()==14){file='gus018.jpg';}
   if(now.getMinutes()==37 && now.getSeconds()==32){file='gus019.jpg';}
   if(now.getMinutes()==50 && now.getSeconds()==54){file='gus020.jpg';}
   }
if(now.getHours()==23) {
   if(now.getMinutes()==6  && now.getSeconds()==3){file='gus021.jpg';}
   if(now.getMinutes()==33 && now.getSeconds()==27){file='gus022.jpg';}
   if(now.getMinutes()==40 && now.getSeconds()==13){file='gus023.jpg';}
   }
document.write('<A TARGET="_top" HREF="/family/aboutme.html">');
if(file!='') {
   document.write('<IMG SRC="'+path+file+'">');
   }
else {
   document.write('<IMG SRC="/jpg/gusface.jpg">');
   }
document.write('</A>');
document.write('</CENTER>');
}
//-->


