#!/usr/bin/perl

$script00 = $script . 'top.cgi';
$script01 = $script . 'entry.cgi';
$script02 = $script . 'init.cgi';

$script11 = $script . 'mente.cgi';
$script12 = $script . 'member.cgi';
$script13 = $script . 'userreg.cgi';
$script14 = $script . 'setup.cgi';

$home = './';
$datafolder = 'files';

$file = $home . $datafolder;
$mtmpfile = $file . '/mtmp.cgi';
$mmstfile = $file . '/mmst.cgi';
$mresfile = $file . '/mres.cgi';
$msetfile = $file . '/mset.cgi';
$mpayfile = $file . '/mpay.cgi';
$hpayfile = $file . '/hpay.cgi';
$revefile = $file . '/reve.cgi';
$mgodfile = $file . '/mgod.cgi';
$gblkfile = $file . '/gblk.cgi';
$mdelfile = $file . '/mdel.cgi';
$versfile = $file . '/vers.cgi';
$userfile = $file . '/user.cgi';

$entfile = $file . '/ent.cgi';
$ent_f_file = $file . '/ent_from.cgi';
$ent_t_file = $file . '/ent_to.cgi';

$mtitle = '申し込み';

@font = ("ＭＳ ゴシック","ＭＳ 明朝","MS UI Gothic","HGP行書体","HGP創英角ｺﾞｼｯｸUB","HGP創英角ﾎﾟｯﾌﾟ体","HG丸ｺﾞｼｯｸM-PRO");
@color = ("#000000","#000053","#0000a8","#0000ff","#005300","#005353","#0053a8","#0053ff","#00a800","#00a853","#00a8a8","#00a8ff","#00ff00","#00ff53","#00ffa8","#00ffff","#530000","#530053","#5300a8","#5300ff","#535300","#535353","#5353a8","#5353ff","#53a800","#53a853","#53a8a8","#53a8ff","#53ff00","#53ff53","#53ffa8","#53ffff","#a80000","#a80053","#a800a8","#a800ff","#a85300","#a85353","#a853a8","#a853ff","#a8a800","#a8a853","#a8a8a8","#a8a8ff","#a8ff00","#a8ff53","#a8ffa8","#a8ffff","#ff0000","#ff0053","#ff00a8","#ff00ff","#ff5300","#ff5353","#ff53a8","#ff53ff","#ffa800","#ffa853","#ffa8a8","#ffa8ff","#ffff00","#ffff53","#ffffa8","#ffffff");
@formtype = ("----------定型句----------","氏名（姓名）","氏名（姓＋名）","フリガナ（姓名）","フリガナ（姓＋名）","メールアドレス","性別","年月日（年＋月＋日）","郵便番号（□－□）","住所（都道府県＋市区郡番地）","電話番号（□－□－□）","通信欄","--------一般タイプ--------","テキスト（１行）","テキスト（複数行）","ラジオボタン","セレクションボックス","チェックボックス");

@base_pref = ("都道府県","北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県");
@actp = ("お選びください","普通","当座");

$cnt_font = @font;
$cnt_font = $cnt_font - 1;
$cnt_color = @color;
$cnt_color = $cnt_color - 1;
$cnt_formtype = @formtype;
$cnt_formtype = $cnt_formtype - 1;

$formtype[90] = '氏名（姓名）';
$formtype[91] = 'メールアドレス';
$formtype[92] = 'ＩＤ';
$formtype[93] = 'パスワード';
$formtype[94] = '商品名';

$init_e01 = '<><><>2<>2<>2<>0<>20<>20';
$init_e02 = '<><><>2<>2<>2<>0<>20<>20';
$init_e03 = '<><>（全角カタカナ）<>2<>2<>2<>0<>20<>20';
$init_e04 = '<><>（全角カタカナ）<>2<>2<>2<>0<>20<>20';
$init_e05 = '<>（半角英数字）<>2<>2<>2<>0<>52';
$init_e06 = '<><>2<>2<>2<>0<>1<>男性<br>女性';
$init_e07 = '1970<>01<>01<><>2<>2<>2<>0<>1950<br>1951<br>1952<br>1953<br>1954<br>1955<br>1956<br>1957<br>1958<br>1959<br>1960<br>1961<br>1962<br>1963<br>1964<br>1965<br>1966<br>1967<br>1968<br>1969<br>1970<br>1971<br>1972<br>1973<br>1974<br>1975<br>1976<br>1977<br>1978<br>1979<br>1980<br>1981<br>1982<br>1983<br>1984<br>1985<br>1986<br>1987<br>1988<br>1989<br>1990<br>1991<br>1992<br>1993<br>1994<br>1995<br>1996<br>1997<br>1998<br>1999<br>2000<br>2001<br>2002<br>2003<br>2004<br>2005<>01<br>02<br>03<br>04<br>05<br>06<br>07<br>08<br>09<br>10<br>11<br>12<>01<br>02<br>03<br>04<br>05<br>06<br>07<br>08<br>09<br>10<br>11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>21<br>22<br>23<br>24<br>25<br>26<br>27<br>28<br>29<br>30<br>31';
$init_e08 = '<><>（半角数字）<>2<>2<>2<>0<>6<>6';
$init_e09 = '<><><>2<>2<>2<>0<>50<>北海道<br>青森県<br>岩手県<br>宮城県<br>秋田県<br>山形県<br>福島県<br>茨城県<br>栃木県<br>群馬県<br>埼玉県<br>千葉県<br>東京都<br>神奈川県<br>新潟県<br>富山県<br>石川県<br>福井県<br>山梨県<br>長野県<br>岐阜県<br>静岡県<br>愛知県<br>三重県<br>滋賀県<br>京都府<br>大阪府<br>兵庫県<br>奈良県<br>和歌山県<br>鳥取県<br>島根県<br>岡山県<br>広島県<br>山口県<br>徳島県<br>香川県<br>愛媛県<br>高知県<br>福岡県<br>佐賀県<br>長崎県<br>熊本県<br>大分県<br>宮崎県<br>鹿児島県<br>沖縄県<br>海外';
$init_e10 = '<><><>（半角数字）<>2<>2<>2<>0<>6<>6<>6';
$init_e11 = '<>ご意見・ご要望をお書きください。<>3<>2<>2<>0<>52<>5<>0';

$init_e13 = '<><>1<>2<>2<>0<>30<>0';
$init_e14 = '<><>1<>2<>2<>0<>40<>5<>0';
$init_e15 = '<><>1<>2<>2<>0<>2<>自転車<br>電車<br>船<br>飛行機';
$init_e16 = '<><>1<>2<>2<>0<>野球<br>サッカー<br>テニス';
$init_e17 = '<><>1<>2<>2<>0<>1<>2<>読書<br>音楽鑑賞<br>スポーツ';

$init_e1 = '0000<>お名前<>90<>1<><><><>2<>2<>2<>0<>20<>20';
$init_e2 = '0001<>メールアドレス<>91<>1<><>（半角英数字）<>2<>0<>2<>0<>52';
$init_e3 = '0002<>ご希望ＩＤ<>92<>1<><><>2<>0<>2<>0<>20';
$init_e4 = '0003<>ご希望パスワード<>93<>1<><><>2<>0<>2<>0<>20';
$init_e5 = '0004<>ご購入商品<>94<>1<><><>2<>0<>2<>0<>20';

$toppage_p = 'top_p.html';
$toppage_m = 'top_m.html';

$mente = "0";

$version = 'Advance';

$sp = '<!--- main --->';

# ---------------------------------------------------------------------

($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$month = ($mon + 1);
if ($year > 90) { $year = $year + 1900; }
else { $year = $year + 2000; }
if ($month < 10) { $month = "0$month"; }
if ($day < 10)  { $day  = "0$day";  }
if ($sec < 10)	{ $sec	= "0$sec";	}
if ($min < 10)	{ $min	= "0$min";	}
if ($hour < 10)  { $hour  = "0$hour";  }
$date_now = "$year\/$month\/$day";
$dateymd = "$year$month$day";
$datetm = "$year\/$month\/$day $hour:$min:$sec";
$time = time;
$ref = $ENV{'HTTP_REFERER'};

sub mmst_split {
	($mm_mid,$mm_pass,$mm_name,$mm_mail,$mm_bank,$mm_branch,$mm_actp,$mm_acct,$mm_acnm,$mm_accum,$mm_payout,$mm_current,$mm_upid,$mm_amt,$mm_fee,$mm_sts,$mm_effdt,$mm_gid,$mm_other,$mm_dmy) = split(/<>/,$mmst);
}
sub mmst_join {
	$mmst = $mm_mid . "<>" . $mm_pass . "<>" . $mm_name . "<>" . $mm_mail . "<>" . $mm_bank . "<>" . $mm_branch . "<>" . $mm_actp . "<>" . $mm_acct . "<>" . $mm_acnm . "<>" . $mm_accum . "<>" . $mm_payout . "<>" . $mm_current . "<>" . $mm_upid . "<>" . $mm_amt . "<>" . $mm_fee . "<>" . $mm_sts . "<>" . $mm_effdt . "<>" . $mm_gid . "<>" . $mm_other . "<>";
}
sub mtmp_split {
	($mt_mid,$mt_pass,$mt_name,$mt_mail,$mt_bank,$mt_branch,$mt_actp,$mt_acct,$mt_acnm,$mt_accum,$mt_payout,$mt_current,$mt_upid,$mt_amt,$mt_fee,$mt_sts,$mt_effdt,$mt_gid,$mt_other,$mt_dmy) = split(/<>/,$mtmp);
}
sub mtmp_join {
	$mtmp = $mt_mid . "<>" . $mt_pass . "<>" . $mt_name . "<>" . $mt_mail . "<>" . $mt_bank . "<>" . $mt_branch . "<>" . $mt_actp . "<>" . $mt_acct . "<>" . $mt_acnm . "<>" . $mt_accum . "<>" . $mt_payout . "<>" . $mt_current . "<>" . $mt_upid . "<>" . $mt_amt . "<>" . $mt_fee . "<>" . $mt_sts . "<>" . $mt_effdt . "<>" . $mt_gid . "<>" . $mt_other . "<>";
}
sub mres_split {
	($mr_mail0,$mr_sub0,$mr_head0,$mr_foot0,$mr_mail1,$mr_sub1,$mr_head1,$mr_foot1,$mr_mail2,$mr_sub2,$mr_head2,$mr_foot2,$mr_mail3,$mr_sub3,$mr_head3,$mr_foot3,$mr_mail4,$mr_sub4,$mr_head4,$mr_foot4,$mr_mail5,$mr_sub5,$mr_head5,$mr_foot5,$mr_dmy) = split(/<>/,$mres);
}
sub mres_join {
	$mres = $mr_mail0 . "<>" . $mr_sub0 . "<>" . $mr_head0 . "<>" . $mr_foot0 . "<>" . $mr_mail1 . "<>" . $mr_sub1 . "<>" . $mr_head1 . "<>" . $mr_foot1 . "<>" . $mr_mail2 . "<>" . $mr_sub2 . "<>" . $mr_head2 . "<>" . $mr_foot2 . "<>" . $mr_mail3 . "<>" . $mr_sub3 . "<>" . $mr_head3 . "<>" . $mr_foot3 . "<>" . $mr_mail4 . "<>" . $mr_sub4 . "<>" . $mr_head4 . "<>" . $mr_foot4 . "<>" . $mr_mail5 . "<>" . $mr_sub5 . "<>" . $mr_head5 . "<>" . $mr_foot5 . "<>";
}
sub mset_split {
	($ms_max,$ms_delay,$ms_logmax,$ms_per,$ms_msg1,$ms_msg2,$ms_rule,$ms_unit,$ms_dmy) = split(/<>/,$mset);
}
sub mset_join {
	$mset = $ms_max . "<>" . $ms_delay . "<>" . $ms_logmax . "<>" . $ms_per . "<>" . $ms_msg1 . "<>" . $ms_msg2 . "<>" . $ms_rule  . "<>" . $ms_unit . "<>";
}
sub mpay_split {
	($mp_mid,$mp_name,$mp_payout,$mp_effdt,$mp_dmy) = split(/<>/,$mpay);
}
sub mpay_join {
	$mpay = $mp_mid . "<>" . $mp_name . "<>" . $mp_payout . "<>" . $mp_effdt . "<>";
}
sub hpay_split {
	($hp_mid,$hp_name,$hp_payout,$hp_effdt,$hp_dmy) = split(/<>/,$hpay);
}
sub hpay_join {
	$hpay = $hp_mid . "<>" . $hp_name . "<>" . $hp_payout . "<>" . $hp_effdt . "<>";
}
sub reve_split {
	($re_mcnt,$re_debit,$re_payout,$re_credit,$re_dmy) = split(/<>/,$reve);
}
sub reve_join {
	$reve = $re_mcnt . "<>" . $re_debit . "<>" . $re_payout . "<>" . $re_credit . "<>";
}
sub mgod_split {
	($mg_gid,$mg_goods,$mg_amt,$mg_fee,$mg_sts,$mg_per,$mg_mail1,$mg_sub1,$mg_head1,$mg_foot1,$mg_mail2,$mg_sub2,$mg_head2,$mg_foot2,$mg_snd11,$mg_snd12,$mg_snd13,$mg_snd21,$mg_snd22,$mg_snd23,$mg_page,$mg_auto,$mg_mchk,$mg_pagem,$mg_dmy) = split(/<>/,$mgod);
}
sub mgod_join {
	$mgod = $mg_gid . "<>" . $mg_goods . "<>" . $mg_amt . "<>" . $mg_fee . "<>" . $mg_sts . "<>" . $mg_per . "<>" . $mg_mail1 . "<>" . $mg_sub1 . "<>" . $mg_head1 . "<>" . $mg_foot1 . "<>" . $mg_mail2 . "<>" . $mg_sub2 . "<>" . $mg_head2 . "<>" . $mg_foot2 . "<>" . $mg_snd11 . "<>" . $mg_snd12 . "<>" . $mg_snd13 . "<>" . $mg_snd21 . "<>" . $mg_snd22 . "<>" . $mg_snd23 . "<>" . $mg_page . "<>" . $mg_auto . "<>" . $mg_mchk . "<>" . $mg_pagem . "<>";
}
sub user_split {
	($us_name1,$us_name2,$us_mail,$us_ver,$us_effdt,$us_dmy) = split(/<>/,$user);
}
sub user_join {
	$user = $us_name1 . "<>" . $us_name2 . "<>" . $us_mail . "<>" . $us_ver . "<>" . $us_effdt . "<>";
}
sub ent_split {
	$ent =~ s/\n//g;
	($e_seq,$e_item,$e_formtype,$e_must,$e_val,$e_dmy) = split(/<>/,$ent,5);
}
sub ent_join {
	$ent = $e_seq . "<>" . $e_item . "<>" . $e_formtype . "<>" . $e_must . "<>" . $e_val;
}
sub gblk_split {
	($gb_gid,$gb_mail,$gb_dmy) = split(/<>/,$gblk);
}
sub gblk_join {
	$gblk = $gb_gid . "<>" . $gb_mail . "<>";
}
sub gget_split {
	($gg_gid,$gg_mid,$gg_amt,$gg_payout,$gg_effdt,$gg_dmy) = split(/<>/,$gget);
}
sub gget_join {
	$gget = $gg_gid . "<>" . $gg_mid . "<>" . $gg_amt . "<>" . $gg_payout . "<>" . $gg_effdt . "<>";
}

#----------------------------------------------------------------------

sub decode {

	if ($mente) {
		&header("");
		$html  .= qq(<br><br><br><h3>メンテナンス中</h3><h4>しばらくお待ちください</h4>);
		&footer;
		print $html;
		exit;
	}

	if ($ENV{'REQUEST_METHOD'} eq "POST") {
		$tmp = $ENV{'CONTENT_LENGTH'};
		binmode(STDIN);
		while($tmp) {
			$tmp -= sysread(STDIN,$buf,$tmp);
			$query .= $buf;
		}
	}
	elsif ($ENV{'REQUEST_METHOD'} eq 'GET') {
		$query = $ENV{'QUERY_STRING'};
	}

	@_ = split(/&/, $query);
	foreach (@_) {
		($i,$j) = split(/=/,$_);
		$j =~ tr/+/ /;
		$j =~ s/%(..)/pack("C",hex($1))/ge;
		&jcode::convert(*j,'sjis');
		if ($j =~ /\r\n/) { $j =~ s/\r//g; }
		if ($j =~ /\r/) { $j =~ s/\r/\n/g; }
		$j =~ s/<>//g;
		if ($j =~ "<>") { &error("入力エラー","<>は使用できません"); }
		$value{$i} = $j;
		if ($i ne "mode") {
			push(@inname,$i); push(@invalue,$j);
		}
	}

	if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla/) {
		$agent = 1;
		$hr = '<hr>';
		$bar = '━━━━━━━━━━━━━━━━━━━━━━━━━';
	}
	else {
		$ct = '</center>';
		if ($ENV{'HTTP_USER_AGENT'} =~ /DoCoMo/) { $docomo = 1; $styl = ' istyle=4'; $styl2 = ' istyle=3'; $hr = '<hr>'; $accesskey = "accesskey"; }
		elsif ($ENV{'HTTP_USER_AGENT'} =~ /J-PHONE/) { $jphone = 1; $styl = ' mode=numeric'; $styl2 = ' mode=alphabet'; $hr = '<hr>'; $accesskey = "accesskey"; }
		elsif ($ENV{'HTTP_USER_AGENT'} =~ /Vodafone/) { $jphone = 1; $styl = ' mode=numeric'; $styl2 = ' mode=alphabet'; $hr = '<hr>'; $accesskey = "accesskey"; }
		elsif ($ENV{'HTTP_USER_AGENT'} =~ /MOT-/) { $jphone = 1; $styl = ' mode=numeric'; $styl2 = ' mode=alphabet'; $hr = '<hr>'; $accesskey = "accesskey"; }
		elsif ($ENV{'HTTP_USER_AGENT'} =~ /SoftBank/) { $jphone = 1; $styl = ' mode=numeric'; $styl2 = ' mode=alphabet'; $hr = '<hr>'; $accesskey = "accesskey"; }
		elsif ($ENV{'HTTP_USER_AGENT'} =~ /UP\.B/) { $au = 1; $styl = " istyle=4"; $styl2 = ' istyle=3'; $ct = ""; $hr = '<br>━━━━━━━━━━━<br>'; $accesskey = "accesskey"; }
		$agent = 0;
		$bar = '━━━━━━━━━━━';
	}

	if (-e "$mresfile") {
		if (!open(MRES,"$mresfile")) { &error("ファイルが開けませんでした。mresfile","管理者までご連絡ください。"); }
		$mres = <MRES>;
		close(MRES);
		$mres =~ s/\n//g;
		&mres_split;
	}

	if (-e "$msetfile") {
		if (!open(MSET,"$msetfile")) { &error("ファイルが開けませんでした。msetfile","管理者までご連絡ください。"); }
		$mset = <MSET>;
		close(MSET);
		$mset =~ s/\n//g;
		&mset_split;
	}

	if (-e "$versfile") {
		if (!open(VERS,"$versfile")) { &error("ファイルが開けませんでした。versfile","管理者までご連絡ください。"); }
		$vers = <VERS>;
		close(VERS);
		$vers =~ s/\n//g;
		($v,$ftx) = split(/<>/,$vers);
	}

}

# ------------------------------------------------------------------------------

sub idcheck {

	$f = 0;
	if ($value{'mid'} ne "") {
		$mmstfile = $file . '/' . $value{'mid'} . '/mmst.cgi';
		if (-e "$mmstfile") {
			if (!open(MMST,"$mmstfile")) { &error("ファイルが開けませんでした。mmstfile","管理者までご連絡ください。"); }
			$mmst = <MMST>;
			close(MMST);
			$mmst =~ s/\n//g;
			&mmst_split;
			$sv_mmst = $mmst;
			$f = 1;
		}
	}

}

# ------------------------------------------------------------------------------

sub add_user {

	if (!$us_mail) {
		$html  .= qq(
<br>
<br>
<font size=3 color="#cc4000"><u>ユーザー登録をお願いします</u></font>
<br>
<br>
<table border=0 cellpadding=5 cellspacing=1 bgcolor="#000000">
	<tr>
		<td bgcolor="#ffffff">
<font size=3 color="#0000aa">■ユーザー登録をすると・・・</font>
<br>
・製品に関する各種お問い合わせを製造元に行うことができます。<br>
・製品に不具合があった場合にパッチ版をお送りします。<br>
・製品の改善案などをお送りいただき次期バージョンに反映させます。<br>
・最新バージョンの情報などをいち早くお知らせします。<br>
		</td>
	</tr>
</table>
<br>
<form method="post" action="$script13">
<input type=hidden name="hostpass" value="$value{'hostpass'}">
<input type=hidden name="mode" value="user">
<input type=submit value="ユーザー登録する">
</form>
<br>
);
	}

}

#----------------------------------------------------------------------

sub header {

	if ($_[0]) { $tit = $_[0]; }
	else { $tit = ""; }

	if ($agent) { &header_p; }
	else { &header_m; }

}

#----------------------------------------------------------------------

sub footer {

	if ($agent) { &footer_p; }
	else { &footer_m; }

}

#----------------------------------------------------------------------

sub header_p {

	$html  = qq(Content-type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta name="robots" content="index,ALL">
<meta name="description" content="SYSTEM BIZ .NETでは、オリジナルのCGIプログラムを格安で製作いたします。WEBショップ開設、データベース、メール一括送信など貴方のサイトをよりアグレッシブにパワーアップいたします。">
<meta name="Keywords" content="格安CGI製作,格安CGI作成,オリジナルCGI,プログラム製作,リードメール,会員管理,出会いサイト,WEBショップ,メール一括送信,アクセス解析,アフリエイト">
<link rel="stylesheet" type="text/css" media="all" href="./style.css">
<title>$tit</title>
$java
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000FF" vlink="#008080" alink="#888888">
<center>
<br>
<h4>$tit</h4>
);

}

sub footer_p {

	$html .= qq(
<br>
$ft
</center>
</body>
</html>
);

}


#----------------------------------------------------------------------

sub header_m {

	$html  = qq(Content-type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000FF" vlink="#008080" alink="#888888">
<div align=center>$tit</div><br>
);

}

sub footer_m {

	$html .= qq(
$hr
$ft
</center>
</body>
</html>
);

}

#--------------------------------------------------------------------------

sub yen {
	local($_) = $_[0];
	if(!$_) { $_ = 0; }
	1 while s/(.*\d)(\d\d\d)/$1,$2/;
	return $_;
}

sub dateget {
	local($_) = $_[0];
	($dsec,$dmin,$dhour,$dday,$dmon,$dyear,$dwday,$dyday,$disdst) = localtime($_);
	$dmonth = ($dmon + 1);
	if ($dyear > 90) { $dyear = $dyear + 1900; }
	else { $dyear = $dyear + 2000; }
	if ($dmonth < 10) { $dmonth = "0$dmonth"; }
	if ($dday < 10)  { $dday  = "0$dday";  }
	if ($dsec < 10)	{ $dsec	= "0$dsec";	}
	if ($dmin < 10)	{ $dmin	= "0$dmin";	}
	if ($dhour < 10)  { $dhour  = "0$dhour";  }
	$ddate_now = "$dyear\/$dmonth\/$dday";
	$ddateymd = "$dyear$dmonth$dday";
	$ddatetm = "$dyear\/$dmonth\/$dday $dhour:$dmin:$dsec";
}

sub rm_dir {

	local($dir) = $_[0];
	opendir(DIR,$dir);
	while($file1 = readdir(DIR)) {
		if (!unlink("${dir}/${file1}")) {
			if (($file1 ne ".") && ($file1 ne "..")) {
				opendir(DIR2,"${dir}/${file1}/");
				while($file2 = readdir(DIR2)) {
					if (!unlink("${dir}/${file1}/${file2}")) {
						if (($file2 ne ".") && ($file2 ne "..")) {
							opendir(DIR3,"${dir}/${file1}/${file2}/");
							while($file3 = readdir(DIR3)) {
								if (!unlink("${dir}/${file1}/${file2}/${file3}")) {
									if (($file2 ne ".") && ($file2 ne "..")) {
										opendir(DIR4,"${dir}/${file1}/${file2}/${file3}/");
										while($file4 = readdir(DIR4)) {
											unlink("${dir}/${file1}/${file2}/${file3}/${file4}");
										}
										closedir(DIR4);
										rmdir("${dir}/${file1}/${file2}/${file3}");
									}
								}
							}
							closedir(DIR3);
							rmdir("${dir}/${file1}/${file2}");
						}
					}
				}
				closedir(DIR2);
				rmdir("${dir}/${file1}");
			}
		}
	}
	closedir(DIR);
	rmdir("$dir");

}

#--------------------------------------------------------------------------

sub in_cookie {

	$name = ""; $value = "";
	@pairs = split(/\;/,$ENV{'HTTP_COOKIE'});
	foreach $pair (@pairs) {
		local($name, $value) = split(/\=/, $pair,2);
		$name =~ s/ //g;
		$DUMMY{$name} = $value;
	}
	@pairs = split(/\,/,$DUMMY{"MAG"});
	foreach $pair (@pairs) {
		local($name, $value) = split(/\:/, $pair);
		$COOKIE{$name} = $value;
	}

	$c_mid = $COOKIE{'mid'};
	$c_pass = $COOKIE{'pass'};

	if ($value{'mid'}) { $c_mid = $value{'mid'}; }
	if ($value{'pass'}) { $c_pass = $value{'pass'}; }

}

sub ot_cookie { 
	($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg,$ydayg,$isdstg)
						= gmtime(time + 30*24*60*60);

	$yearg += 1900;
	if ($secg  < 10)  { $secg  = "0$secg";  }
	if ($ming  < 10)  { $ming  = "0$ming";  }
	if ($hourg < 10)  { $hourg = "0$hourg"; }
	if ($mdayg < 10)  { $mdayg = "0$mdayg"; }

	$mong = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep',
			'Oct','Nov','Dec') [$mong];
	$youbi = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
			'Friday','Saturday') [$wdayg];
	$date_gmt = "$youbi, $mdayg\-$mong\-$yearg $hourg:$ming:$secg GMT";

	$cook = "mid\:$mm_mid\,pass\:$mm_pass";

print "Set-Cookie: MAG=$cook; expires=$date_gmt\n";

}

sub jis { $msg = $_[0]; &jcode'convert(*msg, 'jis'); }

#----------------------------------------------------------------------

sub error {

	if ($agent) { &error_p; }
	else { &error_m; }

	exit;

}

sub error_p {

	print "Content-type: text/html\n\n";
	print "<html>\n";
	print "<head>\n";
	print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\n";
	print "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n";
	print "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"./style.css\">\n";
	print "<title>$_[0]</title>\n";
	print "</head>\n";
	print "<body>\n";
	print "<div align=\"center\">\n";
	print "<br><br>\n";
	print "<table border=\"1\" cellpadding=\"1\" cellspacing=\"3\" width=\"500\">\n";
	print "  <tr>\n";
	print "    <td bgcolor=\"#0000C0\">\n";
	print "    <table>\n";
	print "      <tr>\n";
	print "	<td><font color=\"#ffffff\"><b>$_[0]</b></font></td>\n";
	print "      </tr>\n";
	print "    </table>\n";
	print "    </td>\n";
	print "  </tr>\n";
	print "  <tr>\n";
	print "    <td>\n";
	print "      <br>\n";
	print "      <blockquote>\n";
	print "      <table>\n";
	print "        <tr>\n";
	print "	  <td>\n";
	print "	  $_[1]\n";
	print "	  </td>\n";
	print "	</tr>\n";
	print "      </table>\n";
	print "      </blockquote>\n";
	print "    </td>\n";
	print "  </tr>\n";
	print "</table>\n";
	print "<p><font color=\"#606060\">ブラウザの戻るボタンで戻ってください</font></p>\n";
	print "</div>\n";
	print "</body>\n";
	print "</html>\n";

}

sub error_m {

	print "Content-type: text/html\n\n";
	print "<html>\n";
	print "<head>\n";
	print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\">\n";
	print "<meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n";
	print "<title></title>\n";
	print "</head>\n";
	print "<body>\n";
	print "<center>\n";
	print "<br><br>\n";
	print "$_[0]<br><br>\n";
	print "$_[1]<br><br>\n";
	print "<font color=\"#606060\">前の画面に戻ってください</font>\n";
	print "</center>\n";
	print "</body>\n";
	print "</html>\n";

}
1;
