Navigation  without Java Scripts

/*****************************************************************************

        Copyright (c) Prolog Development Center A/S

Project: GENI CGI-version
FileName: GENI.PRO
Purpose: No description
Written by: Visual Prolog
******************************************************************************/

include "geni.inc"
include "cgitools.pre"

DOMAINS
CONDITIONS = CNO*
HISTORY = RNO*
RNO, CNO, FNO = INTEGER
CATEGORY = STRING

DATABASE - geni
rule(RNO,CATEGORY,CATEGORY,CONDITIONS,STRING)
cond(CNO,STRING,STRING OPTIONS) 
topic(STRING maingoal,STRING purpose)
head(STRING headline, STRING helptopic) 
default_startpage(STRING FILENAME)

DATABASE - tmp
determ kb(STRING)
yes(CNO)
no(CNO)
fact(FNO,CATEGORY,CATEGORY)
whymeet

DATABASE - htmltekst
tekstblok(STRING)

PREDICATES
% Inferences engine
infer()
nondeterm go(HISTORY,CATEGORY,STRING ruleExplanation)
determ check(RNO,HISTORY,CONDITIONS)
determ notest(CNO)
inpq(HISTORY,RNO,CNO,STRING,STRING OPTIONS)

% Answer the WHY Question
gen_why(HISTORY,RNO,STRING,CNO)

% Explanations
sub_cat(CATEGORY,CATEGORY,CATEGORY)
show_conditions(CONDITIONS,string)
show_rule(RNO,string)
report(HISTORY,string)
% evalans(string) 
reverse(CONDITIONS,CONDITIONS)
reverse1(CONDITIONS,CONDITIONS,CONDITIONS)
determ is_htmlfile(STRING)
consult_htm(STRING FileName,STRING HtmlContent)-(i,o)
gethtmlbody(STRING InputHtml,STRING TheBody)

endpage(string)
endpage_Why()

clauses
infer():-
    topic(Maingoal,_),
    go([],MainGoal,""),!.
infer():-
    errorexit.

go( _, Mygoal, Rulexpl ):-
    is_htmlfile(Rulexpl),!,
    consult_htm(Rulexpl,HTMLtext),
    gethtmlbody(HTMLtext,Bodytext),
    not(rule(_,Mygoal,_,_,_)),!,nl,
    write("I think the answer is : ",Mygoal),nl,
    write(Bodytext),nl,
    endpage("").
go( _, Mygoal, Rulexpl ):-
    not(rule(_,Mygoal,_,_,_)),!,nl,
    write("I think the answer is : ",Mygoal),nl,
    write(Rulexpl),nl,
    endpage("").
go( HISTORY, Mygoal,_ ):-
    rule(RNO,Mygoal,NY,COND,Rulexpl),
    check(RNO,HISTORY, COND),
    go([RNO|HISTORY],NY,Rulexpl).
go( _, Mygoal,_ ):-
    rule(_RNO,Mygoal,_NY,_COND,_Rulexpl),!,true,
    write("<H> Sorry, but I have no answer for this problem! </H>\n"),
    endpage("").

check( RNO, HISTORY, [CNO|REST] ):-
    yes(CNO),!,
    check(RNO, HISTORY, REST).
check( _, _, [CNO|_]):-
    no(CNO),
    !,fail.
check( RNO, HISTORY, [CNO|REST]):-
    cond(CNO,NCOND,OPTIONS),
    fronttoken(NCOND,"not",_COND),
    frontchar(_COND,_,COND),
    cond(CNO1,COND,OPTIONS),
    notest(CNO1), !, 
    check(RNO, HISTORY, REST).
check(_,_, [CNO|_] ):-
    cond(CNO,NCOND,OPTIONS),
    fronttoken(NCOND,"not",_COND),
    frontchar(_COND,_,COND),
    cond(CNO1,COND,OPTIONS),
    yes(CNO1),
    !,
    fail.
check( RNO, HISTORY, [CNO|REST] ):-
    cond(CNO,TEXT,OPTIONS),!,
    inpq(HISTORY,RNO,CNO,TEXT,OPTIONS),
    check(RNO, HISTORY, REST).
check( _, _, []).

notest(CNO):-no(CNO),!.
notest(CNO):-not(yes(CNO)),!.

is_htmlfile(FILE):-
    filenameext(File,_Name,Mask),
    Mask = ".htm",!.
is_htmlfile(FILE):-
    filenameext(File,_Name,Mask),
    Mask = ".html",!.

consult_htm(FileName,HTMLTEKST):-
    syspath(ExeStartupPath,_ProgName),
    filenamepath(FullName,ExeStartupPath,FileName),
    trap(file_str(FullName,HTMLTEKST),_,writef("File % is not found! Correct problem!\n",FullName)),!.
consult_htm(_,""):-
    errorexit.


gethtmlbody(TEXT,BODY):-
    upper_lower(TEXT,LOWERTEXT),
    searchstring(LOWERTEXT,"<body",LEN1),
    frontstr(LEN1,LOWERTEXT,_,TXT1),
    searchchar(TXT1,'>',BODY_TAG_LEN),
    STARTPOS = LEN1+BODY_TAG_LEN+1,
    searchstring(LOWERTEXT,"</body>",ENDPOS),