// Cookieに値を保存する---------------------------
function set_cookie(name,param) {
	// クッキーに書き込む情報
	var c_data = name + "=" + escape(param);
	c_data += "; expires=" + "Thu, 31 Dec 2037 12:00:00 GMT";
	c_data += "; path=/";

	// クッキー書き込み
	document.cookie = c_data ;
}

// Cookieから値を取得する-------------------------
function get_cookie(name) {
	var c_data = document.cookie + ";";
	var c_name = name + "=";

	var id_st = c_data.indexOf(c_name);
	var id_en = -1;

	// クッキー検索
	if (id_st != -1 ) {
		id_en = c_data.indexOf(";", id_st);
		c_data = unescape(c_data.substring(id_st + c_name.length, id_en));
	} else {
		c_data = "";
	}

	// 結果を返す
	return c_data;
}

// ブラウザ判定-----------------------------------
function get_browser() {
	// 初期値
	var cFlg = 'UN';
	var cVer = '';
	var b_type = '';

	// ブラウザの情報取得
	bName = navigator.appName;
	bVer = navigator.appVersion;
	if ( bVer.indexOf("Win") != -1 ) { // for Windows
		
		if ( bName.substring(0,4) == "Micr" ) { // for IE
			b_type = "WINIE";
		} else if ( bName.substring(0,4) == "Nets" ) { // for NN
			cVer = bVer.substring(0,4);
			if ( !(check_one_number(cVer.charAt(3))) ) { cVer = bVer.substring(0,3); }
			cVer = eval(cVer);
			if ( cVer > 5 ) {
				b_type = "WINNN6";
			} else {
				b_type = "WINNN4";
			}
		}
	} else if ( bVer.indexOf("Mac") != -1 ) { // for Macintosh
		if ( bName.substring(0,4) == "Micr" ) { // for IE
			b_type = "MACIE";
		}
	}
	return b_type;
}

// 数字チェック（１文字用）-----------------------
function check_one_number(number) {
	number_0 = "0123456789";
	for ( Z=0 ; Z<10 ; Z++ ) {
		if ( number == number_0.charAt(Z) ) { return true; }
	}
	return false;
}

// FONT CSSのタイプを指定する---------------------
function set_FontType(mode) {
	var FontType = get_cookie("FontType");
	if (mode == 'S') {
		FontType--;
	}else if (mode == 'L') {
		FontType++;
	}

	if(FontType < 1){
		FontType = 1;
	}else if(FontType > 4){
		FontType = 4;
	}

	// Cookie保存
	set_cookie("FontType", FontType);
	// ページリロード
	location.reload();
}

// COLOR CSSのタイプを指定する--------------------
function set_ColorType(mode) {
	var ColorType = get_cookie("ColorType");
	if (ColorType != mode) {

		// Cookie保存
		set_cookie("ColorType", mode);
		// ページリロード
		location.reload();
	}
}


// CSSを設定する----------------------------------
function set_css() {
	var MSG;
	var fontCSS;
	var colorCSS;

	var FontType = get_cookie("FontType");
	if (FontType==1) {
		fontCSS = "font_size1.css";
	} else if (FontType=="2") {
		fontCSS = "font_size2.css";
	} else if (FontType=="3") {
		fontCSS = "font_size3.css";
	} else if (FontType=="4") {
		fontCSS = "font_size4.css";
	} else if (FontType=="5") {
		fontCSS = "font_size5.css";
	} else {   // デフォルト、クッキーなし、読み取り不能時
		fontCSS = "font_size1.css";
	}

	var ColorType = get_cookie("ColorType");
	if (ColorType==1) {
		colorCSS = "font_color1.css";
	} else if (ColorType=="2") {
		colorCSS = "font_color2.css";
	} else if (ColorType=="3") {
		colorCSS = "font_color3.css";
	} else if (ColorType=="4") {
		colorCSS = "font_color4.css";
	} else if (ColorType=="5") {
		colorCSS = "font_color5.css";
	} else if (ColorType=="6") {
		colorCSS = "font_color6.css";
	} else if (ColorType=="7") {
		colorCSS = "font_color7.css";
	} else if (ColorType=="8") {
		colorCSS = "font_color8.css";
	} else {   // デフォルト、クッキーなし、読み取り不能時
		colorCSS = "font_color1.css";
	}

	MSG = '<link href="css/' + fontCSS + '" rel="stylesheet" type="text/css">';
	document.write(MSG);

	MSG = '<link href="css/' + colorCSS + '" rel="stylesheet" type="text/css">';
	document.write(MSG);

}

// CSSを設定--------------------------------------
set_css();

