#!/usr/bin/perl

unless ($ARGV[0] eq "bh") {
	print <<eND;
Content-type: text/html

eND
}

chdir("/home12c/sub007/sc13648-GPVH/") || print "Couldn't change directory $!<BR>\n";
$mainloc = "at";
$mainfile = "at";

########### second screen (deactivated)
$cookieid = "atid";
$cookie = $ENV{"HTTP_COOKIE"};

$cookie =~ m/$cookieid\=([^;]+)/;
$id = $1;

exit unless $id;

$time = time;

$subfolder = substr($id,0,3);

open(DATA,"ids/$subfolder/$id/main.txt");
while ($_ = <DATA>) {
	$info{$1} = $2 if m/^([^=]+)\=(.+)/;
}
close(DATA);
$igname = $info{"igname"};

#($event = $ARGV[0]) || ($event = param("event"));

open(DATA,"ids/$subfolder/$id/ob.txt") || open(DATA,"ids/$subfolder/$id/ob.txt");
while ($_ = <DATA>) {
	$obinfo{$1} = $2 if m/^([^=]+)\=(.*)/;
}

$hl = $obinfo{"hl"};
push @togo, qq~<p>This is currently being worked on. There will be more.~;

if ($hl >= 1) {
	push @togo, qq~<p><a href=/cgi-bin/creatorh.pl?fl=ob.txt;start=hypintro1><p>Introductory Trance</a>. You started with this.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp7.txt;start=c1>Leave trance. Usually not needed.</a>~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp8.txt;start=g1>Intro</a> Gives a meaning to counting from 10 to 1.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp7.txt;start=g1>General Relaxation</a>~;
}
else {
	push @togo, qq~<p><a href=/cgi-bin/creatorh.pl?fl=ob.txt;start=firstvisit><p>Introduction</a>~;
}

if ($hl >= 2) {
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp6.txt;start=a1>Intro, starter</a> Encourages more hypnosis.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp7.txt;start=a1>Improving Induction.</a> This is good for starting.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp7.txt;start=b1>Be the person you want to be</a> Another starter.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp7.txt;start=d1>Enjoy training</a> Another good starter.~;
	#??push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp9.txt;start=c1>Your happiness</a> furthers your happiness at being in my home.~;

}
if ($hl >= 3) {
	#push @togo, qq~<br><a href=/t/hyp2/d1.htm>An example of effects without hypnosis</a> (but vicious)~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp8.txt;start=j1>Making things right</a> Finding happiness. Includes following rules and accepting punishments. Negative reinforcement~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp8.txt;start=h1>Night Visit</a> Suggests having a hypnoimagery while you are about to sleep or sleeping. Probably you should be experienced with my hypnoimageries before doing this one.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp6.txt;start=c1>Energy/Willpower</a> Better energy, willpower, and happiness when you are obedient.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp8.txt;start=k1>Training</a> Suggests that your unconscious will help you with training (outside of training) for the next few days.~;
	push @togo, qq~<br><a href=/cgi-bin/creatorh.pl?fl=hyp8.txt;start=m1>Obedience</a> Suggests that your unconscious will help train you to be obedient for the next few days. Somewhat vicious.~;
}

if ($hl >= 100) {
	#push @togo, qq~<br><a href=/t/hyp2/a1.htm>Harmony. Some negative reinforcement.</a>~;
	#push @togo, qq~<br><a href=/t/hyp2/b1.htm>Harmony & improving induction. Very light negative reinforcement.</a>~;

	#push @togo, qq~<br><a href=/t/hyp2/e1.htm>Memories of outside the Harem</a> If memories outside the harem are causing you pain, this helps you not have those memories only when you are in the harem.~;
	push @togo, qq~<br><a href=/t/hyp2/f1.htm>Sleep</a> Pleasant sleep if you have been obedient. But only if you have been obedient. So this is a "vicious" hypnosis, trapping you into obedience.~;
	push @togo, qq~<br><a href=/t/hyp2/g1.htm>Concentration</a> Same as above -- good concentration if you have been obedient.~;
	push @togo, qq~<br><a href=/t/hyp2/h1.htm>Happiness</a> Same as the two above.~;
	#push @togo, qq~<br><a href=/t/hyp6/b1.htm>Just Jack</a> Negative imagery for other men.~;
	#push @togo, qq~<br><a href=/t/hyp2/i1.htm>Pride</a> Your pride should not depend on Jack selecting you. Makes sense only if you are elgible to be selected by Jack.~;


	if ($girlinfo{"traininglevel"} >= 15) {
		push @togo, qq~<br><a href=/t/hyp6/m1.htm>Bondage</a> Suggestions about bondage training. For if you have been in that training for at least a few days.~;
	}

	push @togo, qq~<br><a href=/t/hyp8/b1.htm>Fantasy</a> Being with Jack. Suggests a dream.~;
	push @togo, qq~<br><a href=/t/hyp8/d1.htm>Suggests writing a fantasy</a>~;
}

if ($hl >= 1) {
	push @togo, qq~<p><a href=/cgi-bin/printpage.pl?target=IGNAME;nextfile=t/atwork/choice.htm>Add Inductions </a>~;
}

if (open(DATA,">ids/$subfolder/$id/hyppos.txt") || open(DATA,">ids/$subfolder/$id/hypneg.txt") ) {
	push @togo, qq~<p><a href=/cgi-bin/rare/selfhyp.pl>Phrases</a>~;
}	

push @togo, qq~<p><a href=/cgi-bin/rare/edithyp.pl?event=list>Testing -- Do not use </a>~;
push @togo, qq~<p><a href=/cgi-bin/rare/selfhyp.pl?event=list>Continue Testing -- Do not use </a>~;


printonblankerpage(@togo);
exit;

################

sub printonblankerpage {
	@toprint = @_;
	chdir("/home12c/sub007/sc13648-GPVH/$mainloc");
	open(DATA,"cgi-bin/shells/atshell.htm") || open(DATA,"cgi-bin/atshell.htm")  || print "There was a problem reading body: $!";
	@lines = <DATA>;
	close(DATA);
	$contentmarker = "<!--content-->";

	foreach (@lines) {
		if (m/$contentmarker/o) {
			print @toprint;
		}
		else {
			print;
		}
	}
	exit;
}

sub printpage {
	my ($fl, $in) = @_;
	chdir("/home12c/sub007/sc13648-GPVH/$mainloc");
	exec "cgi-bin/main.pl" if $fl eq "page" || $fl eq "ownpage";
	open(DATA,"$fl") || open(DATA,"$fl") || print "There was a problem reading $fl";
	@lines = <DATA>;
	close(DATA);
	foreach (@lines) {
		s/INSERT/$in/go;
		print;
	}
	exit;
}

sub savechangestochr {
	open(DATA,">$mainfile/$subfolder/$id/ob.txt") || open(DATA,">$mainfile/$subfolder/$id/chr.txt")  || print "Problem writing to chr for some reason: $!";
	@keys = keys(%info);
	foreach (@keys) {
		$i = $info{$_};
		print DATA "$_=$i\n";
	}
	close(DATA);
	return;
}