The Doc Dialer: The Code
The Doc Dialer
The Code
<HTML>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
// by Yehuda Shiran. v1.0
// Copyright (c) 2000 Yehuda Shiran. All Rights Reserved.
// See https://www.docjavascript.com for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
function bName() {
if (navigator.appName == "Microsoft Internet Explorer")
return 1;
if (navigator.appName == "Netscape")
return 2;
return 0;
}
function bVer() {
// return version number (e.g., 4.03)
msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
return(parseFloat(navigator.appVersion.substr(msieIndex,3)));
}
var nameCode = bName();
var versionCode = bVer();
var agt = navigator.userAgent.toLowerCase();
var mac = (agt.indexOf("mac")!=-1);
// -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function numPressed(digit) {
if (digit == 0) {
currentTrie = tree;
outputStringToDisplay(welcomeStr);
}
else if (typeof(currentTrie) == "number") return;
else if (digit >= 2 && digit <= 9 && currentTrie[digit]) {
currentTrie = currentTrie[digit];
updateBoard(currentTrie);
printDisplay();
}
clearDisplayIndex();
}
function updateBoard(trieNode) {
if (typeof(trieNode) == "number") {
addEmployeeToDisplay(trieNode);
}
else {
for (i=2; i<=9; i++) {
memberNode = trieNode[i];
if (memberNode) {
if (typeof(memberNode) == "number") {
addEmployeeToDisplay(memberNode);
}
else {
updateBoard(memberNode);
}
}
}
}
}
function addEmployeeToDisplay(empNum) {
printList[empNum] = true;
}
function clearDisplayIndex() {
for (i=0; i<=EMPMAX; i++) {
printList[i] = false;
}
}
function printDisplay() {
var str = "";
for (i=0; i<=EMPMAX; i++) {
if (printList[i] == true) {
var fileName = extractFileName(empList[i]).toLowerCase();
str += '<A HREF=' + '"' + fileName + '.html"' + '>' + empList[i] + '</A>' + ' ' +
'<A HREF="calling.html" >' + empPhone[i] + '</A>' + '<BR>';
}
}
outputStringToDisplay(str);
}
function outputStringToDisplay(str) {
if (nameCode == 1) {
document.all.foundSoFar.innerHTML = str;
}
else {
document.foundSoFar.document.write(str);
}
}
function extractFileName(empName) {
if (nameCode == 1 && versionCode >= 5.5) {
var regExp = /(\w+)\s*(\w+)/g;
return empName.replace(regExp, matchingFunction);
}
else {
blankPos = empName.indexOf(" ");
firstName = empName.substr(0, blankPos);
lastName = empName.substr(blankPos + 1, empName.length - blankPos);
return firstName + lastName;
}
}
function matchingFunction(matchedString, subMatch1, subMatch2, matchPos, source) {
return (subMatch1 + subMatch2)
}
// -->
</SCRIPT>
<FORM NAME="phonePlate">
<TABLE BORDER=2WIDTH=150 HEIGHT=60CELLPADDING=1 CELLSPACING=5>
<TR>
<TD><INPUT NAME="button1" TYPE="BUTTON" VALUE=" 1 "
onclick="numPressed(1)"></TD>
<TD><INPUT NAME="button2" TYPE="BUTTON" VALUE=" 2 ABC "
onclick="numPressed(2)"></TD>
<TD><INPUT NAME="button3" TYPE="BUTTON" VALUE=" 3 DEF "
onclick="numPressed(3)"></TD>
<TD ROWSPAN="4" VALIGN="top" NOWRAP><SPAN ID="foundSoFar"></SPAN></TD>
</TR>
<TR>
<TD><INPUT NAME="button4" TYPE="BUTTON" VALUE=" 4 GHI "
onclick="numPressed(4)"></TD>
<TD><INPUT NAME="button1" TYPE="BUTTON" VALUE=" 5 JKL "
onclick="numPressed(5)"></TD>
<TD><INPUT NAME="button1" TYPE="BUTTON" VALUE=" 6 MNO"
onclick="numPressed(6)"></TD>
</TR>
<TR>
<TD><INPUT NAME="button7" TYPE="BUTTON" VALUE=" 7 PRS"
onclick="numPressed(7)"></TD>
<TD><INPUT NAME="button8" TYPE="BUTTON" VALUE=" 8 TUV "
onclick="numPressed(8)"></TD>
<TD><INPUT NAME="button9" TYPE="BUTTON" VALUE=" 9 WXY"
onclick="numPressed(9)"></TD>
</TR>
<TR>
<TD><INPUT NAME="button*" TYPE="BUTTON" VALUE=" * "
onclick="numPressed(10)"></TD>
<TD><INPUT NAME="button0" TYPE="BUTTON" VALUE=" 0 "
onclick="numPressed(0)"></TD>
<TD><INPUT NAME="button#" TYPE="BUTTON" VALUE=" # "
onclick="numPressed(11)"></TD>
</TR>
</TABLE>
</FORM>
</HEAD>
<BODY>
<SCRIPT>
<!--
var EMPMAX = 100;
var empList = new Array(EMPMAX);
empList[1] = "Ronald Reagan"; //76 //73
empList[2] = "Jimmy Carter"; //54 //22
empList[3] = "Richard Nixon"; //74 //6
empList[4] = "Bill Clinton"; //24 //25
empList[5] = "Gerald Ford"; //437 //3
empList[6] = "George Bush"; //436 //28
empList[7] = "Lyndon Johnson"; //59 //56467
empList[8] = "John Kennedy"; //56465 ///53
var empPhone = new Array(EMPMAX);
empPhone[1] = 5808;
empPhone[2] = 5919;
empPhone[3] = 5303;
empPhone[4] = 5606;
empPhone[5] = 5707;
empPhone[6] = 5313;
empPhone[7] = 5838;
empPhone[8] = 5006;
var tree = new Array(10);
var tmpArray = new Array(10);
tree[2] = tmpArray;
tree[2][2] = 2; // Carter, Jimmy
tree[2][4] = 4; // Bill Clinton
tree[2][5] = 4; // Clinton, Bill
tree[2][8] = 6; // Bush, George
tree[3] = 5; // Ford, Gerarld
var tmpArray = new Array(10);
tree[4] = tmpArray;
var tmpArray = new Array(10);
tree[4][3] = tmpArray;
tree[4][3][7] = 5; // Gerald Ford
tree[4][3][6] = 6; // George Bush
var tmpArray = new Array(10);
tree[5] = tmpArray;
tree[5][4] = 2; // Jimmy Carter
tree[5][9] = 7; // Lyndon Johnson
tree[5][3] = 8; // Kennedy, John
var tmpArray = new Array(10);
tree[5][6] = tmpArray;
var tmpArray = new Array(10);
tree[5][6][4] = tmpArray;
var tmpArray = new Array(10);
tree[5][6][4][6] = tmpArray;
tree[5][6][4][6][5] = 8; // John Kennedy
tree[5][6][4][6][7] = 7; // Johnson, Lyndon
tree[6] = 3; // Nixon, Richard
var tmpArray = new Array(10);
tree[7] = tmpArray;
tree[7][3] = 1; // Reagan, Ronald
tree[7][4] = 3; // Richard Nixon
tree[7][6] = 1; // Ronald Reagan
var currentTrie = tree;
var printList = new Array(EMPMAX);
clearDisplayIndex();
var welcomeStr = "Welcome to DOCJS Trie Phone. <BR>Please key in a president name:";
outputStringToDisplay(welcomeStr);
// -->
</SCRIPT>
</BODY>
</HTML>
Produced by Yehuda Shiran and Tomer Shiran
Created: February 14, 2000
Revised: February 14, 2000
URL: https://www.webreference.com/js/column57/10.html