<?php
error_reporting(E_ERROR | E_PARSE);
ini_set('display_errors', 0);

include("./init.php");
include("./file_func.php");
include("./loger_class.php");

	if( $_COOKIE["ckAdmin"] == "woodwood"){
		$fAdmin = TRUE;
	}else{
		$fAdmin = FALSE;
	}
	
	if( $fAdmin){
//		header("Location: ./index.php");
//		echo "alert( document.URL);";
		
		echo "var str = document.URL;\n";
		echo "if( str.match(/[\/]$/i)){\n";
		echo "	location.replace(\"./index.php\");\n";
		echo "}";
		
//		if( document.URL = "
//		echo "location.replace(\"./index.php\");";
//		exit;
	}
	
	$ckTempName = $_COOKIE["ckName"];
	$sOut = "name = \"".$ckTempName."\";";
	$sOut = mb_convert_encoding( $sOut, "SJIS", "EUC-JP");
	
	echo $sOut;
	
	$sOut = "function TitleBar(){";
//echo "alert( document.URL);";
//exit;
		//	タイトルバー
		$aTemp = aReadFile( RECORD_POSITION . "title.txt", 0);
		/*
		$cLog = new Loger( $aTemp);
		if( $cLog->sMsg != ""){
			$aTitle = explode( "!!BR!!", $cLog->sMsg);
			$iNum=0;
			for( $i=0; $i<count($aTitle); $i++){
				if( $aTitle[ $i] != ""){
					$aTitleTemp[ $iNum] = $aTitle[ $i];
					$iNum++;
				}
			}
			
			$iImage = rand( 1, count( $aTitleTemp)) - 1;
			$sImage = $aTitleTemp[ $iImage];
			$sImage = preg_replace( "/\[\[image:@([0-9a-zA-Z_-]+\.[a-zA-Z]+)\]\]/", "./image/\\1", $sImage);
			
		}else{
			//	Nullだったよ。
	//		$sImage = "./image/suteki.jpg";
		}
		*/
		if( $aTemp[5] != "")
		{
			$aTitle = explode( "!!BR!!", $aTemp[5]);
			$iNum=0;
			for( $i=0; $i<count($aTitle); $i++){
				if( trim($aTitle[ $i]) != ""){
					$aTitleTemp[ $iNum] = trim($aTitle[ $i]);
					$iNum++;
				}
			}
			
			$iImage = rand( 1, count( $aTitleTemp)) - 1;
			$sImage = $aTitleTemp[ $iImage];
			$sImage = preg_replace( "/\[\[image:@([0-9a-zA-Z_-]+\.[a-zA-Z]+)\]\]/", "./image/\\1", $sImage);
			
		}
		else
		{
			$sImage = "./image/suteki.jpg";
		}
		
//		$sOut .= "document.getElementById(\"top\").style.backgroundImage=\"url( ./image/sutekicraft01.jpg)\";";
		//	background: url(./titlebar_002.jpg) no-repeat;
		$sOut .= "if( !document.getElementById(\"top\").style.backgroundImage){";
		$sOut .= "document.getElementById(\"top\").style.backgroundImage=\"url(". $sImage .")\";";
		$sOut .= "}";
		//	echo $sOut;
		//	alert( $sOut);
	$sOut .= "}";
	
	echo $sOut;

error_reporting(E_ALL);
ini_set('display_errors', 1);
?>