//=======================================================================================
//---------------------------------------------------------------------------------------
//	モジュール名	：func.js
//	概要			：JavaScript共通関数ライブラリ
//	バージョン		：$Id: func.js,v 1.3 2006/05/19 08:41:35 mori Exp $
//	最終更新日		：2005.09.01
//	最終更新者		：早稲田システム開発株式会社（システム部：西　義尚）
//	備考			：$Revision: 1.3 $
//---------------------------------------------------------------------------------------
//=======================================================================================

//var load_cnt = 0;

//if(load_cnt == 0){
//	window.location.replace(window.location);
//	load_cnt++;
//}
//history.go(window.location);

//if (location.replace == null)
//	location.replace = location.assign;

history.forward();

var nYPos;
var nTimer;


//---------------------------------------------------------------------------------------
//	関数名	：get_cl
//	概要	：ブラウザの種類を取得する
//	引数	：なし
//	戻り値	：
//	備考	：
//---------------------------------------------------------------------------------------

function get_cl(){
	var cl = "";

	if(navigator.userAgent.indexOf("Win") >= 0){
		if(navigator.userAgent.indexOf("MSIE") >= 0){
			//Win IE
			cl = "winie";
		}else if(navigator.userAgent.indexOf("Netscape") >= 0){
			//Win NN
			cl = "winnn";
		}else if(navigator.userAgent.indexOf("Firefox") >= 0){
			//Win Firefox
			cl = "winfx";
		}else{
			//Win Other
			cl = "winzz";
		}
	}else if(navigator.userAgent.indexOf("Mac") >= 0){
		if(navigator.userAgent.indexOf("MSIE") >= 0){
			//Mac IE
			cl = "macie";
		}else if(navigator.userAgent.indexOf("Netscape") >= 0){
			//Mac NN
			cl = "macnn";
		}else if(navigator.userAgent.indexOf("Safari") >= 0){
			//Mac Safari
			cl = "macsf";
		}else{
			//Mac Other
			cl = "maczz";
		}
	}else{
		cl = "winie";
	}

	return cl;

}



//---------------------------------------------------------------------------------------
//	関数名	：set_toolbar_pos
//	概要	：ツールバーの移動
//			  現在は使用してない（らしい）
//	引数	：なし
//	戻り値	：なし
//	備考	：ツールバーの背景がある場合
//---------------------------------------------------------------------------------------
function set_toolbar_pos()
{
	try{

		var cl = get_cl();

		//NNの場合
		if (cl == "winnn" || cl == "macnn")
		{
			//画面の位置を取得
			nYPos = window.pageYOffset;
			//NN4
			if(document.layers)
			{
				//レイヤーの幅と高さをマウス座標にセット
				document.header_layer.left = 0;
				document.header_layer.top = nYPos;
			}
			//NN6
			else
			{
				document.getElementById("header_layer").style.left = 0;
				document.getElementById("header_layer").style.top = nYPos;
			}

		}else if(cl == "winie"){
			//画面の位置を取得
			nYPos = document.body.scrollTop;
			//レイヤーの幅と高さを座標にセット
			header_layer_back.style.left = 0;
			header_layer_back.style.top = nYPos;
			header_layer.style.left = 0;
			header_layer.style.top = nYPos;

		}else{
			//画面の位置を取得
			nYPos = document.body.scrollTop;
			//レイヤーの幅と高さを座標にセット
			header_layer.style.left = 0;
			header_layer.style.top = nYPos;

		}
		nTimer=setTimeout("set_toolbar_pos()",100);
	}catch(e){
	}

}

function ReplaceString(targetStr, searchStr, replaceStr){
	var regPattern = new RegExp(searchStr, "g");
	var resultSrt = targetStr.replace(regPattern, replaceStr);
	return resultSrt;
}


//---------------------------------------------------------------------------------------
//	関数名	：checkIsZenkaku
//	概要	：全角チェック
//	引数	：value
//	戻り値	：true（全角）、false（全角以外）
//	備考	：
//---------------------------------------------------------------------------------------
function checkIsZenkaku(value) {
	for (var i = 0; i < value.length; ++i) {
var c = value.charCodeAt(i);
//	半角カタカナは不許可
if (c < 256 ) {
//if (c < 256 || (c >= 0xff61 && c <= 0xff9f)) {
	return false;
}
	}
	return true;
}

//---------------------------------------------------------------------------------------
//	関数名	：getByteCount
//	概要	：文字列のバイト数を取得する
//	引数	：value
//	戻り値	：バイト数
//	備考	：全角を3バイト、半角を1バイトとしてカウント(UTF-8)
//---------------------------------------------------------------------------------------
function getByteCount(value) {
	var count = 0;
	for ( var i = 0; i < value.length; ++i ) {
var sub = value.substring(i, i + 1);
//全角の場合3バイト追加。
if( checkIsZenkaku(sub) ){
	count += 3;
} else {
	count += 1;
}
	}
	return count;
}


//---------------------------------------------------------------------------------------
//	関数名	：IsSpecialChar
//	概要	：特殊文字が含まれるかどうかチェックする
//	引数	：s
//	戻り値	：true（含まれる）、false（含まれない）
//	備考	：
//---------------------------------------------------------------------------------------
function IsSpecialChar(s){
	//戻り値：true(含まれている)、false（含まれていない）
	if(s.match(/[!"#$%&'\(\)=\\|,:;^\[\]\{\}`*?+><]/)){
		return true;
	}
	else{
		return false;
	}
}


//---------------------------------------------------------------------------------------
//	関数名	：plus_int_check
//	概要	：整数値として正しいかチェックする
//	引数	：$num
//	戻り値	：true（整数）、false（整数以外）
//	備考	：
//---------------------------------------------------------------------------------------
function plus_int_check(num)
{
	data = num.match(/[^0-9]/g);
	if (data){
		return false;
	}else{
		return true;
	}
}

//---------------------------------------------------------------------------------------
//	関数名	：close_me
//	概要	：自分のウィンドウを閉じる
//	引数	：なし
//	戻り値	：なし
//	備考	：
//---------------------------------------------------------------------------------------
function close_me()
{
	// Macintosh
	if (navigator.userAgent.indexOf('Mac') >= 0) {
		var r = setTimeout("window.close();", 500);
	}
	// Windows
	else if (navigator.userAgent.indexOf('Win') >= 0) {
		window.close();
	}
	// Other
	else {
		var r = setTimeout("window.close();", 500);
	}
}

//---------------------------------------------------------------------------------------
//	関数名	：show_wait
//	概要	：しばらくお待ちくださいのレイヤーを表示する
//	引数	：なし
//	戻り値	：なし
//	備考	：
//---------------------------------------------------------------------------------------
function show_wait()
{
	var cl_nm = get_cl();
	if(cl_nm == "macie"){
		return;
	}

/*
	var x = 100;
	var y = 100;
	var layName = "layer_wait";

	if(cl_nm == "winnn" || cl_nm == "macnn"){
		document.layers[layName].moveTo(x,y);
	}else{
		document.getElementById(layName).style.left=x;
		document.getElementById(layName).style.top=y;
	}
*/

	nTimer=setTimeout("show_wait_dialog()",1000);
}


//---------------------------------------------------------------------------------------
//	関数名	：show_wait_dialog
//	概要	：しばらくお待ちくださいのレイヤーを表示する
//	引数	：なし
//	戻り値	：なし
//	備考	：
//---------------------------------------------------------------------------------------
function show_wait_dialog()
{
	//NNの場合
	if(document.layers)
	{
		document.layer_wait.visibility="Show";
	}
	//IEの場合
	else
	{
		layer_wait.style.visibility="visible";
		//layer_wait.style.zIndex=999;

	}
}


//---------------------------------------------------------------------------------------
//	関数名	：set_window_center
//	概要	：ウィンドウを画面中央に移動させる
//	引数	：w, h
//	戻り値	：なし
//	備考	：
//---------------------------------------------------------------------------------------
function set_window_center(w, h)
{
/*
	if((document.all) && (navigator.userAgent.indexOf("Win") >= 0)){
		//Win IE4以降
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}else if((document.all) && (navigator.userAgent.indexOf("Mac") >= 0)){
		//Mac IE4以降
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}else if(document.layers){
		//N4
		w = window.outerWidth;
		h = window.outerHeight;
	}else if(document.getElementById){
		//N6以降
		w = window.outerWidth;
		h = window.outerHeight;
	}else{
		w = window.outerWidth;
		h = window.outerHeight;
	}
*/
	try{
		var x = (screen.width  - w) / 2;
		var y = (screen.height - h) / 2;
		moveTo(x,y);
	}catch(e){
	}
}


//---------------------------------------------------------------------------------------
//	関数名	：get_ext
//	概要	：ファイルの拡張子を取得する
//	引数	：file_nm
//	戻り値	：拡張子
//	備考	：
//---------------------------------------------------------------------------------------
function get_ext(file_nm){
	var fileTypes = new Array();
	fileTypes = file_nm.split(".");
	var fileType = fileTypes[fileTypes.length - 1].toLowerCase();
	if(fileType != ""){
		return fileType;
	}
	else{
		return "";
	}
}


//---------------------------------------------------------------------------------------
//	関数名	：set_div_size
//	概要	：ツールバー、ドキュメント<DIV>のheightをセット
//	引数	：h(ツールバー領域の高さ pixcel)
//			：p1（ツールバー領域の高さ % - Mac IE、Safari用）
//			：p2（ドキュメント領域の高さ % - Mac IE、Safari用）
//	戻り値	：なし
//	備考	：
//---------------------------------------------------------------------------------------
function set_div_size(h, p1, p2){

	try{
		//var p1 = Math.round(h / window.innerHeight * 100);
		var cl = get_cl();
		var new_h = 0;

		if(cl=="macie" || cl=="macsf" || cl=="maczz"){
			document.getElementById("toolbar_area").style.height = p1 + "%";
			document.getElementById("doc_area").style.height = p2 + "%";
			show_doc_area();
			return;
		}

		if(cl=="winnn" || cl=="macnn"){
			new_h = window.innerHeight - h;
		}else{
			new_h = document.body.clientHeight - h;
		}
		document.getElementById("toolbar_area").style.height = h;
		document.getElementById("doc_area").style.height = new_h;

		//document.getElementById("doc_area").style.visibility="visible";

	}catch(e){
	}

}

//---------------------------------------------------------------------------------------
//	関数名	：RTrim
//	概要	：入力文字の左空白カット・全角対応
//	引数	：strTemp（値）
//	戻り値	：カット後の値
//	備考	：
//---------------------------------------------------------------------------------------
function RTrim(strTemp)
{
	var nLoop = 0;
	var strReturn = strTemp;
	while (nLoop < strTemp.length)
	{
		if ((strReturn.substring(strReturn.length - 1, strReturn.length) == " ") || (strReturn.substring(strReturn.length - 1, strReturn.length) == "　"))
		{
			strReturn = strTemp.substring(0, strTemp.length - (nLoop + 1));
		}
		else
		{
			break;
		}
		nLoop++;
	}
	return strReturn;
}
//---------------------------------------------------------------------------------------
//	関数名	：LTrim
//	概要	：入力文字の右空白カット・全角対応
//	引数	：strTemp（値）
//	戻り値	：カット後の値
//	備考	：
//---------------------------------------------------------------------------------------
function LTrim(strTemp)
{
	var nLoop = 0;
	var strReturn = strTemp;
	while (nLoop < strTemp.length)
	{
		if ((strReturn.substring(0, 1) == " ") || (strReturn.substring(0, 1) == "　"))
		{
			strReturn = strTemp.substring(nLoop + 1, strTemp.length);
		}
		else
		{
			break;
		}
		nLoop++;
	}
	return strReturn;
}

