

//-----------------------------------------
//  キー(key) と 値(value) でクッキーを書き込む
//-----------------------------------------
function setCookie(key, value) {
     var tmp = key + '=' + escape(value) + '; ';
     tmp += 'expires=Tue, 31-Dec-2030 23:59:59; ';
     document.cookie = tmp;
}

function setCookie2(key, value, path) {
	
     var tmp = key + '=' + escape(value) + '; ';
     tmp += 'expires=Tue, 31-Dec-2030 23:59:59; ';
     tmp += 'path=' + path +'; ';
     document.cookie = tmp;
}

//----------------------------
//  ループ回数の最大値を返す
//----------------------------
function loot_init( digitsChange  ){
	var keta = 0; 
	if(digitsChange == 'ON'){  
		keta = 6 + document.calc.ketasu.selectedIndex * 4; 
	} 
	else{ 
		keta = 10;
	} 		
	var loop_limit = 0; 
	if(keta == 6){ loop_limit = 501;} 
	else if(keta == 10){loop_limit = 401;} 
	else if(keta == 14){loop_limit = 301;} 
	else if(keta == 18){loop_limit = 201;} 
	else if(keta <= 30){loop_limit = 101;} 
	else if(keta <= 42){loop_limit = 51;} 
	else if(keta <= 50){loop_limit = 21;} 
	return loop_limit;
}


//-----------------------------------------------------
//  実行画面下側のＴＡＢのエリアを表示する。
//------------------------------------------------------
var SM_JA_TAB = new Array('tabANK'   , 'tabFAQ');
var SM_EN_TAB = new Array('tabANK_EN', 'tabFAQ_EN');

var _tabpc ;
var _tablang;

function getTabMessage(){
	if(_tablang == ""){
		return  "<font color='#3366cc' >上のタブをクリックすると各情報BOXを開きます。</font>";
	}
	else if(_tablang == ""){
		return  "";
	}
	return "";
}


function getRadioValue(radio){
	for (i = 0; i < radio.length; i++) {
		if (radio[i].checked) {
			return radio[i].value;
		}
	}
	return "";
}


//--------------------------------
//  時分秒・度分秒の文法チェック
//--------------------------------
function checkHms(str, type){
	if(type == "hms"){ //時:分:秒
		if( ! (str.match(/^-?[0-9]+\.?\d*:[0-9]+\.?\d*:[0-9]+\.?\d*$/)) &&
		    ! (str.match(/^-?[0-9]+\.?\d*:[0-9]+\.?\d*$/))        &&
		    ! (str.match(/^-?[0-9]+\.?\d*$/))  ){
			return(  "時分秒「" + str  +"」の指定が誤っています。\n(指定例) \n12:59:59 -->12時59分59秒\n12:59 -->12時59分\n12 -->12時" );
		}
	}
	else{  //度°分'秒
		if( ! (str.match(/^-?[0-9]+\.?\d*°[0-9]+\.?\d*'[0-9]+\.?\d*"$/)) &&
		    ! (str.match(/^-?[0-9]+\.?\d*°[0-9]+\.?\d*'[0-9]+\.?\d*$/))  &&
		    ! (str.match(/^-?[0-9]+\.?\d*'[0-9]+\.?\d*'[0-9]+\.?\d*$/))   &&
		    ! (str.match(/^-?[0-9]+\.?\d*°[0-9]+\.?\d*'$/))  &&
		    ! (str.match(/^-?[0-9]+\.?\d*°[0-9]+\.?\d*$/))  &&		    
		    ! (str.match(/^-?[0-9]+\.?\d*'[0-9]+\.?\d*$/))   &&
		    ! (str.match(/^-?[0-9]+\.?\d*'[0-9]+\.?\d*'$/))   &&		    
		    ! (str.match(/^-?[0-9]+\.?\d*°$/))        &&
		    ! (str.match(/^-?[0-9]+\.?\d*$/))  ){

			return(  "度分秒「" + str  +"」の指定が誤っています。\n(指定例) \n10'11'12 -->10度11分12秒\n10°11'12 -->10度11分12秒\n10°11'12\" -->10度11分12秒\n10°11\" -->10度11分\n10'11 -->10度11分\n10'11' -->10度11分\n10' -->10度\n10 -->10度\n10°-->10度" );
		}
	}
	return "";
}

function checkHexDec(sw, str){
	if(sw == 2){
		if (str.match(/[^01]/)) {
			if(lang == "en"){
				alert("Input data (" + str + ") is wrong.");
			}
			else{
				alert("２進の入力値「" + str + "」に誤りがあります。");
			}
			return false;
		}
	}
	else if(sw == 8){
		if (str.match(/[^0-7]/)) {
			if(lang == "en"){
				alert("Input data (" + str + ") is wrong.");
			}
			else{
				alert("８進の入力値「" + str + "」に誤りがあります。");
			}
			return false;
		}
	}
	else if(sw == 10){
		if (str.match(/[^0-9]/)) {
			if(lang == "en"){
				alert("Input data (" + str + ") is wrong.");
			}
			else{
				alert("１０進の入力値「" + str + "」に誤りがあります。");
			}
			return false;
		}
	}
	else if(sw == 16){
		if (str.match(/[^0-9A-Fa-f]/)) {
			if(lang == "en"){
				alert("Input data (" + str + ") is wrong.");
			}
			else{
				alert("１６進の入力値「" + str + "」に誤りがあります。");
			}
			return false;
		}
	}	
	return true;
}

function tabSelect(pc, isIphone, lang) {
	_tabpc = pc;
	_tablang = lang;
	width=0;	
	tabmesper='95%';

	if(lang == ""){
		message = "アンケートにご協力ください。";
	}
	else{
		message = "Please fill in questionnaire." 
	}

	var anketo = "<table border=0 cellpadding=0 cellspacing=1  bgcolor=#7597dd><tr><td bgcolor='#E1F0F0' nowrap align=left valign=top>&nbsp;<input type=checkbox class='checkbox' id='anksel' onclick=anketosel('" + _tabpc + "','"+ _tablang + "');>&nbsp;<span class=anketo >" + message + "</span>&nbsp;</td></tr></table>";
	var html = "";

	if(pc == 0 && lang == ""){
		_isIphone = isIphone;
		width=290;
		tabmesper='80%';
		html = "<table border=0 width=290 cellpadding=0 cellspacing=0>";
		html += "<tr><td height=50 align=center>"  +  anketo   + "</td></tr>";	
		// スマートフォン 日本語
		html += "<tr><td height=33 width=290><img src='/keisan/image/here.gif' border=0>&nbsp;<font color=#3366cc style='font-size:100%;'><b>情報ＢＯＸ一覧</b></td></tr>";
		html += "<tr>";
		html += "	<td nowrap>";
		html += "	<li id='" + SM_JA_TAB[0] + "'><a href='#' onclick='return seltab(0);'><b id='" + SM_JA_TAB[0] + "str'>アンケート</b></a></li>";
		html += "	<li id='" + SM_JA_TAB[1] + "'><a href='#' onclick='return seltab(1);'><b id='" + SM_JA_TAB[1] + "str'>よくある質問</b></a></li>";
		html += "	</td>";
		html += "</tr>";
	}
	else if(pc == 0 && lang == "en"){
		_isIphone = isIphone;
		width=290;
		tabmesper='80%';
		html = "<table border=0 width=290 cellpadding=0 cellspacing=0>";
		html += "<tr><td colspan=2 height=50 align=center>"  +  anketo   + "</td></tr>";
		// スマートフォン 英語
		html += "<tr><td height=33 width=290><img src='/keisan/image/here.gif' border=0>&nbsp;<font color=#3366cc style='font-size:100%;'><b>Infomation Box</b></td></tr>";
		html += "<tr>";
		html += "	<td nowrap>";
		html += "	<li id='" + SM_EN_TAB[0] + "'><a href='#' onclick='return seltab(0);'><b id='" + SM_EN_TAB[0] + "str'>Questionnaire</b></a></li>";
		html += "	<li id='" + SM_EN_TAB[1] + "'><a href='#' onclick='return seltab(1);'><b id='" + SM_EN_TAB[1] + "str'>FAQ</b></a></li>";
		html += "	</td>";
		html += "</tr>";
	}
	html += "<tr height=2>";
	html += "  <td bgcolor=#0066cc colspan=2></td>";
	html += "</tr>";
	html += "<tr>";
	html += "  <td  valign=top class='undertab' colspan=2><span id='undertab'></span></td>";
	html += "</tr>";
	html += "<tr>";
	html += "  <td id='tabinfo' colspan=2 height=22 valign=bottom align=center style='font-size:" + tabmesper+ ";'>" + getTabMessage() + "</td>";
	html += "</tr>";
	html += "<tr>";
	html += "  <td width=100% align=left id='voice' style='padding-top:10px;'></td>";
	html += "</tr>";
	html += "</table>";
	document.getElementById('tabArea').innerHTML = html;
	// ここから下はアンケートリストがあったら表示する
	readAnketo(0);
}

function readAnketo(offset) {
	// ここから下はアンケートリストがあったら表示する
	var postData = 'command=list'+  '&libnum=' + sysUserCode + '&lang=' + lang +  '&is_pc=' + _tabpc +  '&offset=' + offset + '&rand=' +  Math.floor(Math.random() * 10);

	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					if(document.getElementById('voice') != null){
						document.getElementById('voice').innerHTML = req.responseText ;
					}
				}
			return;
	    }
	}

//alert( postData  );	
	
	req.open('POST', '/dc/anketo/submit.php', true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
	req.send(postData);	
}

function readAnketo2(offset) {
	readAnketo(offset);
	window.scrollBy( 0, 0 );
	return false;
}

var _isIphone;
//-------------------------------
//  ＴＡＢのエリアの初期化処理
//-------------------------------
function tabinit(no){
	var thisTab = "";

	if(_tabpc == 0 && _tablang == ""){
		thisTab = SM_JA_TAB;
	}
	
	else if(_tabpc == 0 && _tablang =="en"){
		thisTab = SM_EN_TAB;
	}
	
	for(var i = 0 ; i < thisTab.length ; i++){
		if(thisTab[i] == 'tabBBS' || thisTab[i] == 'tabANK' || thisTab[i] == 'tabANK_EN'){
			document.getElementById(thisTab[i]).style.cssText = "background-color:#ffe8e7;";
		}
		else{
			document.getElementById(thisTab[i]).style.cssText = "background-color:#ebebeb;";
		}
		document.getElementById(thisTab[i] + 'str').style.cssText = "color:#16387c;";
	}

	if(no != null){
		document.getElementById(thisTab[no]).style.cssText = "background-color:#0066cc;";
		document.getElementById(thisTab[no] + 'str').style.cssText = "color:white;";
	}
}
//---------------------------------------------------
// アンケートのチェックボックスが押されたときの処理
//---------------------------------------------------
function anketosel(pc, lang){
	if(document.getElementById('anksel') != null){ document.getElementById('anksel').checked = true;  }
	seltab(0 );

}
//-------------------------------------
// TABのクローズが押されたときの処理
//-------------------------------------
function tabClose() {

	document.getElementById('voice').style.cssText = "padding-top:40px;";
	document.getElementById('tabinfo').innerHTML = getTabMessage();
	
	document.getElementById("undertab").innerHTML = "";
	tabinit(null);
	if(document.getElementById('anksel') != null){ document.getElementById('anksel').checked = false;  }

	window.scrollBy( 0, 0 );
	return false;

}

//----------------------------------------
//  実行画面下側のＴＡＢのエリアの選択処理
//----------------------------------------
function seltab(no){

	document.getElementById('voice').style.cssText = "padding-top:0px;";
	document.getElementById('tabinfo').innerHTML = "";

	tabinit(no);
	var closeleft = "<table><tr><td align=right nowrap><a href='#' onclick='return tabClose();'><img src='/keisan/image/batu.gif' border=0></a>&nbsp;</td></tr><tr><td valign=top>";
	var closeright = "</td></tr></table>";

	if(_tabpc == 0 && _tablang == ""){
		//  スマートフォン  の日本語
		if(no == 0){ // アンケート
			document.getElementById('undertab').innerHTML = closeleft + "<iframe src='/keisan/anketotab.php?libname=" +  urlEncode(libtitle) + "&libnum=" + sysUserCode + "' frameborder=0   height=700 width=290 class='tabwaku'></iframe>"  + closeright;
		}		
		else if(no == 1){// よくある質問
			document.getElementById('undertab').innerHTML = closeleft + "<iframe src='/keisan/faq.php?exec=2' frameborder=0 height=2700 width=290 class='tabwaku'></iframe>"  + closeright;
		}	
//		else if(no == 2){// うんちく
//			document.getElementById('undertab').innerHTML = closeleft + "<iframe src='/keisan/unchiku/index.php?header=no' frameborder=0 height=1000 width=290 class='tabwaku'></iframe>"  + closeright;
//		}	

	}
	else if(_tabpc == 0 && _tablang == "en"){
		//  スマートフォン  の英語
		if(no == 0){ // アンケート
			document.getElementById('undertab').innerHTML = closeleft + "<iframe src='/keisan/anketotab.php?libname=" +  urlEncode(libtitle) + "&libnum=" + sysUserCode + "' frameborder=0   height=810 width=290 class='tabwaku'></iframe>"  + closeright;
		}		
		else if(no == 1){// よくある質問
			document.getElementById('undertab').innerHTML = closeleft + "<iframe src='/keisan/faq.php?exec=2' frameborder=0 height=2250 width=290 class='tabwaku'></iframe>"  + closeright;
		}	
	}
//	setTimeout("scroll(0," + (mouseYPos - mouseYSPos) + ")", 0);
	window.scrollBy( 0, 0 );
	return false;
}


//---------------------------
//  自作ライブラリ削除
//---------------------------
function deletelib(target, libname ,lang ){

//	libname = allReplace(libname, "'", "&#39;");
	libname = allReplace(libname, "'", "＆＃３９；");

	//  &amp; --> ' に戻す
	target = target.replace('&apos;', "'");
	var nwin = window.open('','_blank', 'width=500,height=300,toolbar=no,menubar=no,location=no,toolbar=no');
	nwin.document.open();
	nwin.document.write('<html>');
	nwin.document.write('<head>');
	nwin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
	nwin.document.write('<meta http-equiv="Content-Style-Type" content="text/css">');
	nwin.document.write('<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>');	
	nwin.document.write('</head>');
	nwin.document.write('<body bgcolor=#ffffff>');
	nwin.document.write('<br><br><br><br><br>');
	nwin.document.write('<CENTER>');
	nwin.document.write('「<FONT color=red>' + target + '</FONT> 」を削除しますか？</P>');
	nwin.document.write('<INPUT type=submit name=deleteyn value=はい onclick="window.opener.repaintMenu(\'' + libname + '\',\'' + lang   + '\');window.close()">　　　');
	nwin.document.write('<INPUT type=button onclick="window.close()" value=いいえ>');
	nwin.document.write('<INPUT type=hidden name=path value="' +  libname  + '">');
	nwin.document.write('</CENTER>');
	nwin.document.write('</body>');
	nwin.document.write('</html>');	
	nwin.document.close();
}

//------------------------------------------------
//  FREE計算のタイトルセルをＩＮＰＵＴ文に変更する
//------------------------------------------------
function tdToInput(id ){
	var obj = document.getElementById(id);
	function toInput(){
		var inpid = 'inp' + id;	
		if(document.getElementById(inpid) == null){

			var str = obj.innerHTML;
			str = allReplace(str,  "'", "&#39;");
			if(obj.innerHTML == '&nbsp;'){
				str="";
			}
//			obj.innerHTML = "<input maxlength=30 id='" + inpid  + "' type='text' value='" +   str  +"' onblur=\"inputToTd('" + id + "')\" style='width:95%;'>";
			obj.innerHTML = "<input maxlength=40 size=40 id='" + inpid  + "' type='text' value='" +   str  +"' onblur=\"inputToTd('" + id + "')\" style='width:95%;'>";
		
			document.getElementById(inpid).focus();
		}
	}
	obj.onclick  = function(){toInput();}
}


//-------------------------------------------
//  FREE計算のＩＮＰＵＴ文をセルに変更する
//-------------------------------------------
function inputToTd(id){
	if(document.getElementById('inp' +id).value == ''){
		document.getElementById(id).innerHTML = "&nbsp;";
	}
	else{
		var v = document.getElementById('inp' +id).value;
		v = allReplace(v, "'", "&#39;");
		document.getElementById(id).innerHTML = v;
	}
}

var freeTitle =  new Array();
function addFreeTitle(key, value){
	freeTitle[key]=value;
	
}

//------------------------------------
//  答えのタイトルからＰＯＳＴ用の
//  タイトルＩＮＰＵＴ文を作成する
//------------------------------------	
function createPostTitleInput(){
	var ans = "";
	//シングル＆マルチ  mul1, mul2, mul3,....
	if(document.getElementById('mul1') != null){ 
		for(var i = 1; i <= 20; i++){
			var id = 'mul'+ i;
			var v = document.getElementById(id);
			var value="";
			if(v != null){value= v.innerHTML;}
			else{		  value = freeTitle[id];}
			if(value == undefined){
				value = "ans" + i;
			}
			value = allReplace(value,  "'", "&#39;");
			ans += "<input type='hidden' id='" + id + "' name='" + id + "' value='" + value  + "'>";
		}
	}
	//テーブル  tbl0, tbl1, tbl2, tbl3,....
	else if(document.getElementById('tbl0') != null){ 
		for(var i = 0; i < 20; i++){
			var id = 'tbl'+ i;
			var v = document.getElementById(id);
			var value="";
			if(v != null){value= v.innerHTML;}
			else{		  value = freeTitle[id];}

			if(value == undefined){
				value = "tbl" + i;
			}			
			value = allReplace(value,  "'", "&#39;");
			ans += "<input type='hidden' id='" + id + "' name='" + id + "' value='" + value + "'>";
		}
	}
	else{
		for(var i = 1; i <= 20; i++){
			var id = 'mul'+ i;
			if (id in freeTitle) {
				var value = allReplace(freeTitle[id],  "'", "&#39;");
				ans += "<input type='hidden' id='" + id + "' name='" + id + "' value='" + value + "'>";
			}
		}
		for(var i = 0; i < 20; i++){
			var id = 'tbl'+ i;
			if (id in freeTitle) {
				var value = allReplace(freeTitle[id],  "'", "&#39;");
				ans += "<input type='hidden' id='" + id + "' name='" + id + "' value='" + value + "'>";
			}
		}
	}
//alert(ans);
	return ans;
}

function getInputDtValue(id){
	var v = document.getElementById(id);
	var inpv = document.getElementById('inp' + id);
	if(inpv != null){
		return "<input type='hidden' id='" + id  + "' name='" + id + "' value='" + inpv.value  + "'>";
	}
	else if(v != null){
		return "<input type='hidden' id='" + id + "' name='" + id + "' value='" + v.innerHTML  + "'>";
	}
	return '';
}

//------------------------------------
//  パラメータを保存する時
//  ＩＤのテーブルを作成する
//------------------------------------
function makeTitleParamSR(){
	var initlen = paramSR.length;

	//シングル＆マルチ  mul1, mul2, mul3,....
	for(var i = 1; i <= 20; i++){
		if(getInputDtValue('mul'+ i) != ''){
			paramSR.push('mul'+ i + "::TTL"  );	
		}
	}
	if(paramSR.length > initlen){
		return;
	}
	//テーブル  tbl0, tbl1, tbl2, tbl3,....
	for(var i = 0; i < 20; i++){
		if(getInputDtValue('tbl'+ i) != ''){
			paramSR.push('tbl'+ i + "::TTL"  );	
		}
	}
	return;
}


//---------------------------
//  Dailogを表示する
//---------------------------
function opendialog(target){
	var nwin = window.open('','freefunc', 'width=300,height=600,toolbar=no,menubar=no,location=no,toolbar=no');
	nwin.document.open();
	nwin.document.write('<html>');
	nwin.document.write('<head>');
	nwin.document.write('<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">');
	nwin.document.write('<meta http-equiv="Content-Style-Type" content="text/css">');
	nwin.document.write('<link rel="stylesheet" href="/keisan/css/Keisan.css" type="text/css">');
	nwin.document.write('<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"/>');	
	nwin.document.write('</head>');
	nwin.document.write('<CENTER>');
	nwin.document.write( target);
	nwin.document.write('</CENTER>');
	nwin.document.write('</body>');
	nwin.document.write('</html>');	
	nwin.document.write('<script language=\"JavaScript\">');
	nwin.document.write('function insertText(s){ window.opener.insertText(s);}');
	nwin.document.write('function toukeiUpper(){ window.opener.toukeiUpper();}');
	nwin.document.write('function toukeiLower(){ window.opener.toukeiLower();}');
	nwin.document.write('function tokusyuFunc1(){ window.opener.tokusyuFunc1();}');
	nwin.document.write('function tokusyuFunc2(){ window.opener.tokusyuFunc2();}');
	nwin.document.write('function tokusyuFunc3(){ window.opener.tokusyuFunc3();}');	
	nwin.document.write('function syotouFunc(){ window.opener.syotouFunc();}');
	nwin.document.write('</script>');
	nwin.document.write('<br><center><input type=button value="閉じる" onclick="window.close()"></center>');	
	nwin.document.close();
	return nwin;
}


//----------------------------
//  変数の保存・呼び出し
//  親を閉じたら子も閉じる
//----------------------------
function unLoadWindow()
{
	 // 子画面を閉じる
//	 if( paramwin != null ) {
//	      paramwin.close();
//	      paramwin = null;
//	 }
} 

function toEuc(moji){
	var moji_length = moji.length;
	var moji_x = "";
	for(var i=0;i<moji_length;i++){
		moji_x = moji_x + "&" + "#" + moji.charCodeAt(i) + ";";
	}
	return moji_x;
}

function repaintMenu(libname, lang){
	var charset = "";
	if(lang == "en"){
		charset = "utf-8";
	}

	libname = allReplace(libname, "＆＃３９；", "'");
	libname=urlEncode(libname);// UTF-8にエンコードしている。
	var jump = "/has10/Menu.cgi?path=" + libname + '&deleteyn=yes&lang=' + lang + "&charset=" + charset;
	location.href = jump;
}


function getSelctedRadioNum(formradio){
	for (i = 0; i < formradio.length; i++) {
		if (formradio[i].checked) {
			return i;
		}
	}
	return 0;
}


function setValueToCell(tablename, value, variID, isOnLoad){
	if(value == null || value == "undefined"){
		value="";
	}
	
	var id = 'var_'.concat(variID);   // INPUTのID
	var id_unit = id.concat('_unit');
	var id__explain = id.concat('_explain');


	// 「表示しない」にチェックがある場合は、表示名だけを表示するようにする。値はinputにセットする 
	var parentID = id.concat('_inp');
	var disp_on_off = "";
	if(document.getElementById(parentID) != null){
		disp_on_off = document.getElementById(parentID).getAttribute('disp_on_off');
	}

	// <math> 対応
	if(value.indexOf('<math>') != -1){ 
		value =value.replace("<math>", '<img src="/cgi-bin/mimetex.cgi?');
    	value =value.replace("</math>", '">');
	}

	// 表示名|値|単位|説明  or 値 or [hidden]|値  or 表示名|値   など
	var dvuc = value.split('|');
	var disp = "";
	var val = "";
	var unit = "";
	var explain = "";

	if(dvuc.length == 1){
		val = value;
	}
	else if(dvuc.length == 2){	
		disp = dvuc[0];
		val = dvuc[1];
	}
	else if(dvuc.length == 3){	
		disp = dvuc[0];
		val = dvuc[1];
		unit = dvuc[2];
	}	
	else if(dvuc.length == 4){	
		disp = dvuc[0];
		val = dvuc[1];
		unit = dvuc[2];
		explain = dvuc[3];
	}

//alert(  value + "==" + disp   + ":"+  val   + ":"  + unit  + ":"  + explain  + ":"  +  dvuc.length ) ; 

	// 特殊扱い
	if(disp_on_off == "OFF"){
		if(disp == "[hidden]"){
			document.getElementById(id.concat('_disp')).innerHTML = "";
		}
		else{
			if(disp.indexOf(".gif") != -1 || disp.indexOf(".jpg") != -1){
				// dispに画像表示
				var tablename = tablename.substring(0, tablename.length-4);
				tablename=EscapeEUCJP(tablename);
				disp=EscapeEUCJP(disp);
				document.getElementById(id.concat('_disp')).innerHTML = "<img src='/keisan/table/" + tablename +'/' + disp + "' border=0>";
			}
			else{
				document.getElementById(id.concat('_disp')).innerHTML = disp;
			}
		}
	}
	else{
		if(dvuc.length > 1){
			var before = document.getElementById(id).getAttribute('type');
			var after = "";
			
			if(disp == "[hidden]"){
				document.getElementById(id.concat('_disp')).innerHTML = "";
				document.getElementById(id.concat('_unit')).innerHTML = ""; 
				document.getElementById(id.concat('_explain')).innerHTML = "";
				toHiddenInput(id);
				after = 'hidden';
			}
			else{
				toTextInput(id);
				after = 'text';
				if(disp.indexOf(".gif") != -1 || disp.indexOf(".jpg") != -1){
					// dispに画像表示
					var tablename = tablename.substring(0, tablename.length-4);
					tablename=EscapeEUCJP(tablename);
					disp=EscapeEUCJP(disp);
					document.getElementById(id.concat('_disp')).innerHTML = "<img src='/keisan/table/" + tablename +'/' + disp + "' border=0>";
				}
				else{
					if(disp != ""){
						document.getElementById(id.concat('_disp')).innerHTML = disp;
					}
				}
				if(unit != ""){
					document.getElementById(id.concat('_unit')).innerHTML = unit;
				}
				if(explain != ""){
					document.getElementById(id.concat('_explain')).innerHTML = explain;
				}
			}
		
		}
	}

	if(isOnLoad == 1 && document.getElementById(id).value != ''){

	}
	else{
		if(disp_on_off == "OFF" || dvuc.length <= 1){ 
			document.getElementById(id).value = val;
		}
		else{
//	alert("333  前のTYPE="+  before  + "後のTYPE=" + after );			
			// valの値がＮＵＬＬでhidden -> text の時だけ値をセットする
			if(val != ""  || (val == ""  && before == "hidden" && after == 'text') ){
				document.getElementById(id).value = val;
			}
		}
	}
}

//----------------------------------------------
//  ・新規にTYPE=hiddenのINPUTを作成する。
//  ・INPUTのTYPEをTextからHidden にする。
//  ・INPUTのTYPEをHiddenからHidden にする。
//  IEは　type をhiidenに下だけではダメなので
//  この命令を呼ぶ必要がある
//----------------------------------------------
function toHiddenInput(inpID){
	var parentID = inpID.concat('_inp');
	var el = document.getElementById(inpID);
	var size  = el.getAttribute('size');

//	var value = el.getAttribute('value');
	var value = el.value;

//	alert("111  前のTYPE="+   el.getAttribute('type')  + "前のvalue=" + value    + " -->hidden "  + inpID );	
	document.getElementById(parentID).innerHTML = "<input size='" + size +"' autocomplete=off type='hidden' name='" + inpID +"' id='" + inpID + "' value='" + value + "' class='text'>";

}

//----------------------------------------------
// ・新規にhiddenのINPUTを作成する。
// ・INPUTのTYPEをTextからTextにする。
// ・INPUTのTYPEをHiddenからText にする。
// IEは　type をhiidenに下だけではダメなので
// この命令を呼ぶ必要がある
//----------------------------------------------
function toTextInput(inpID){

	var parentID = inpID.concat('_inp');
	var el = document.getElementById(inpID);
	var size  = el.getAttribute('size');

	// 例外 レングスが０か-1の場合はＨＩＤＤＥＮにしない
	if(size == null || size == '' || size== 0){   // null はサイズをセットしない時
		return;
	}
//	var value = el.getAttribute('value');
	var value = el.value;

//	alert("22  前のTYPE="+  el.getAttribute('type') + "前のvalue=" + value  + "-->text "  + inpID  );	
	document.getElementById(parentID).innerHTML = "<input size='" + size +"' autocomplete=off type='text' name='" + inpID +"' id='" + inpID + "' value='" + value + "' class='text'>";

}

var  eventCount = 0;
//----------------------------
//  外部テーブル( 一次元 )
//----------------------------
function getOutTable(tablenam, selectedIndex, isOnLoad, itemnames, lang) {
	var tablenam2 = tablenam;
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();

	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					var text = req.responseText;
					valueAr = text.split(',');	
					if(valueAr == ''){
//						alert('指定された文字列は外部テーブルに存在しません');
					}
					else{
						itemAr = itemnames.split(',');
						for( i = 0; i < itemAr.length; i++){
							//if(itemAr[i] == '' || itemAr[i] == null){
							//	continue;
							//}
							setValueToCell(tablenam2, valueAr[i+2], itemAr[i], isOnLoad);
						}
						nextFocus();
					}
				}
				eventCount--;
				return;
	    }
	};
	eventCount++;
	tablenam=urlEncode(tablenam);// UTF-8にエンコードしている。
	req.open('GET', 'TableFile.cgi?&type=0&table=' + tablenam + '&selectedIndex=' + selectedIndex + '&lang=' + lang + '&rand=' + Math.floor(Math.random() * 10) , true);
	req.send(null);
}

//-------------------------------------------------
//  外部テーブル( 2次元で1次元しか使わない場合)
//--------------------------------------------------
function getOutTable2_1only(tablenam, firstSecondRet, selectedIndex, isOnLoad, lang){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();

//	document.getElementById('executebtn').disabled = true;
	var tablenam3 = tablenam;
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					var text = req.responseText;
					valueAr = text.split(',');	
					if(valueAr != ''){
						itemAr = firstSecondRet.split(',');
						for( i = 3; i < itemAr.length; i++){
							var item = itemAr[i].split('|')[1];
							setValueToCell(tablenam3, valueAr[i-3], item, isOnLoad);
						}
						nextFocus();
					}
				}
				eventCount--;
//				document.getElementById('executebtn').disabled = false;
				
				return;
	    }
	};
	eventCount++
	tablenam=urlEncode(tablenam);// UTF-8にエンコードしている。
	var firstSecondRet2=urlEncode(firstSecondRet);// UTF-8にエンコードしている。
	req.open('GET', 'TableFile.cgi?&type=3&table=' + tablenam + '&firstSecondRet=' + firstSecondRet2 + '&selectedIndex=' + selectedIndex + '&lang=' + lang + '&rand=' + Math.floor(Math.random() * 10) , true);
	req.send(null);
}

function setDispValue(tablenam, text, firstSecondRet){ 

	var valueAr = text.split(',');	
	if(valueAr != ''){
		var itemAr = firstSecondRet.split(',');
		for( i = 3; i < itemAr.length; i++){
			var item = itemAr[i].split('|')[1];
			//if(item == '' || item == null){
			//	continue;
			//}			

			setValueToCell(tablenam, valueAr[i-3], item, 1);
		}
	}
}


var outtableEventNum2 = new Array();
//-----------------------------------------
//   2段階の1番目の項目が選択されたら
//   2番目のリストを表示しなおす
//-----------------------------------------
function getOutTable2_1(tablenam, firstValue , firstSecondRet, firstItem, secondItem, secondArea, inpType, lang){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();

//	document.getElementById('executebtn').disabled = true;
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					var text = req.responseText;
					document.getElementById(secondArea).innerHTML = text;
				}
//				document.getElementById('executebtn').disabled = false;				
				if(outtableEventNum2[secondItem]){
					if(inpType == 'radio' || inpType == 'listradio'){
						window.document.getElementsByName(secondItem)[outtableEventNum2[secondItem]].checked = true;	
					}
					else{
						document.getElementById(secondItem).selectedIndex = outtableEventNum2[secondItem];
					}
					/////delete  outtable21End[secondItem];  // 第一変数のonchange イベントが終わった。変数の保存・呼び出で使用
					return;
				}
				// second  Event
				eventCount--;
				getOutTable2_2(0, tablenam, firstSecondRet,  firstItem, secondItem, inpType, lang);
				return;
	    }
	};
	eventCount++;
	var tablenam2=urlEncode(tablenam);// UTF-8にエンコードしている。
	var firstSecondRet2=urlEncode(firstSecondRet);// UTF-8にエンコードしている。
	var firstValue2=urlEncode(firstValue);// UTF-8にエンコードしている。
	var firstItem2=urlEncode(firstItem);// UTF-8にエンコードしている。	
	var secondItem2=urlEncode(secondItem);// UTF-8にエンコードしている。
	req.open('GET', 'TableFile.cgi?type=1&table=' + tablenam2 + '&firstSecondRet=' + firstSecondRet2 + '&firstValue=' + firstValue2 + '&firstItem=' + firstItem2 + '&secondItem=' + secondItem2 +  '&inpType=' + inpType+ '&lang=' + lang +'&rand=' + Math.floor(Math.random() * 10) , true);
	req.send(null);
}

//-----------------------------------------
//   2番目の項目が選択されたら
//   他の項目にセットする
//-----------------------------------------
function getOutTable2_2(onLoad, tablenam, firstSecondRet, firstItem, secondItem, inpType,lang){
	var fsv = firstSecondRet.split(',');

	var tablenam2 = tablenam;
	if(fsv.length > 3){
		var fsv2 = new Array(0);
		for (var j = 0; j < fsv.length; j++){
			if(fsv[j].indexOf('|') != -1){
				fsv2.push(fsv[j]);
			}
		}
		var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
			try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
			catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
		})();

//		document.getElementById('executebtn').disabled = true;

		req.onreadystatechange = function() {
			switch (req.readyState) {
				case 1: // Open
				case 2: // Sent
				case 3: // Receiving
					break;
				case 4: // Loaded
					if(req.status == 200){
						var ans = req.responseText.split(',');
						if(ans == ''){ return;}
						for (var j = 0; j < fsv2.length; j++){
							var items = fsv2[j].split('|');
							var item = items[1];
							if( ans[j] == 'undefined'){
								ans[j]='';	
							}
							if(document.getElementById('var_'.concat(item)) != null){
								// input に値 |  画像、文字列などを表示
								setValueToCell(tablenam2, ans[j], item, onLoad);
							}
						}
					}

					eventCount--;
//					document.getElementById('executebtn').disabled = false;					
					return;
		    }
		}

		var firstname="";
		var secondname=""; 
		if(inpType == 'list' || inpType == 'listradio'){
			firstname  = document.getElementById(firstItem).options[document.getElementById(firstItem).selectedIndex].text;
		}
		else{
			var id = firstItem + "_" + getSelctedRadioNum(document.getElementsByName(firstItem));
			firstname  = document.getElementById(id).innerHTML;
		}

		if(inpType == 'radio' || inpType == 'listradio'){
			var id = secondItem + "_" + getSelctedRadioNum(document.getElementsByName(secondItem));
			secondname  = document.getElementById(id).innerHTML;
		}
		else{
			 secondname = document.getElementById(secondItem).options[document.getElementById(secondItem).selectedIndex].text;
		}

		tablenam=urlEncode(tablenam);// UTF-8にエンコードしている。		
		var firstSecondRet2=urlEncode(firstSecondRet);// UTF-8にエンコードしている。	
		var firstname2 = urlEncode(firstname);// UTF-8にエンコードしている。
		var secondname2 = urlEncode(secondname);// UTF-8にエンコードしている。
		eventCount++;
		req.open('GET', 'TableFile.cgi?type=2&table=' + tablenam + '&firstSecondRet=' + firstSecondRet2 + '&first=' + firstname2 +  '&second=' + secondname2 + '&lang=' + lang + '&rand=' + Math.floor(Math.random() * 10) , true);
		req.send(null);
	}
}

//----------------------------------------------------------
//  端末がアンドロイドで画面横幅が４４０ピクセル未満の場合は
//  画像やグラフ、ＭＩＭＥＴＥＸのサイズを 画面横幅/４４０
//  に縮小する。
//----------------------------------------------------------
function resizeImage(imageID,isAndraid){

//alert(document.body.clientWidth );

	var width = document.body.clientWidth-15;
	var ta = document.getElementById(imageID);
//alert( "width=" + width + ":ta.width=" + ta.width + ":" + isAndraid  + ":"  + imageID);
	if(ta != null && isAndraid == 1 &&  ta.width > width){
	   var myh = parseInt(width / ta.width * ta.height);
	   var myw = parseInt(width);
	   var mycss="width:"+myw+"px;height:"+myh+"px;";
	   ta.style.cssText=mycss;
	}
}


function setIDHtml(id, value) {
	if(document.getElementById(id) != null){
		document.getElementById(id).innerHTML = value;
	}
}

function setIDValue(id, value) {
	if(document.getElementById(id) != null){
		document.getElementById(id).value = value;
	}
}

function setIdStyle(id, value) {
	if(document.getElementById(id) != null){
		document.getElementById(id).style.cssText = value;
	}
}


//----------------------------
//  レートを取得する
//----------------------------
function getRate(id , from, to, startchar, endchar, rand, isValue){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
		catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
	})();
	
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					xt = req.responseXML.documentElement.firstChild.nodeValue;
					if(isValue == 1){
						xt = Math.round(xt*100)/100; 
						if(document.getElementById(id) != null && document.getElementById(id).value == ''){ 
							document.getElementById(id).value = startchar + xt + endchar;
						}
					}
					else{
						if(document.getElementById(id) != null) {  
							document.getElementById(id).innerHTML = startchar + xt + endchar;
						}
					}
				}
		    return;
		};
	}	
	req.open('GET', 'Kawase.cgi?&from=' + from +  '&to=' + to + '&rand=' + rand , true);
	req.send(null); 
}

var parentnum = 0;
function getGoogleMapNum() { 
  return parentnum; 
} 

function googleMap(num) { 
  parentnum = num;
 
  var childWindow  = window.open('/keisan/googleMap.php', 'Map', 'scrollbars=yes'); 
  childWindow.focus();

} 

function googleMapKyori(num) { 
  parentnum = num; 
  
  var childWindow  = window.open('/keisan/googleMapKyori.php', 'Map', 'scrollbars=yes'); 
  childWindow.focus(); 
}

function getNowNicname(){
	return nownicname;
}


//-----------------------------
// ログインリンク情報を作成
//-----------------------------
var loginflag=0;
var nownicname="";
function loginChg(){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
		catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
	})();
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					var loginuser = req.responseText.split("\n");
					if(lang == null || lang == ''){
						if(document.getElementById("youkoso") != null){
							if(loginuser[0] != ""){
								document.getElementById("youkoso").innerHTML = "ようこそ" +  loginuser[0] +  "さん";
							}
							else{
								document.getElementById("youkoso").innerHTML = "ゲストさん";
							}
						}
						nownicname = loginuser[0];
						saveloadMemberSet();

						if(document.getElementById("loginout") != null){
							document.getElementById("loginout").innerHTML = loginuser[1];
							if( loginuser[1].match(/ログアウト/)) {
								loginflag=1;
							}
						}
					}
					else{
						if(document.getElementById("youkoso") != null){
							if(loginuser[0] != ""){
								document.getElementById("youkoso").innerHTML = "Welcome," +  loginuser[0] ;
							}
							else{
								document.getElementById("youkoso").innerHTML = "Welcome,Guest";
							}
						}
						nownicname = loginuser[0];
						saveloadMemberSet();
						if(document.getElementById("loginout") != null){
							document.getElementById("loginout").innerHTML = loginuser[1];
							if( loginuser[1].match(/Logout/)) {
								loginflag=1;
							}
						}
					}

					// ユーザ情報
					if(document.getElementById("userinfo") != null){
						document.getElementById("userinfo").innerHTML = loginuser[2];
					}
					
					// スマートフォン / ＰＣ切り替え
					if(document.getElementById("selpcsmt") != null){
						if(lang == ''){
							document.getElementById("selpcsmt").innerHTML = '&nbsp;' + loginuser[3];
						}
						else{
							document.getElementById("selpcsmt").innerHTML = '&nbsp;' + loginuser[3];
						}
					}	
				}
				return;
	    }
	};
	// ログインリンク情報を作成
	req.open('GET', '/dc/loginsession.php', true);
	req.send(null);
}

//-----------------------------
// ログインを行う(autologin時に)
//------------------------------
function memberlogin(id, path){

	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject("Msxml2.XMLHTTP");    }
		catch(e) { return new ActiveXObject("Microsoft.XMLHTTP"); }
	})();
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
//alert( id  + ":" + req.responseText  );
					if(req.responseText == "autologin"){
						if(id == 'lib'){
							location.href =  "/dc/memberlogin.php?id=lib&path=" + urlEncode(path);// UTF-8にエンコードしている。
						}
						else if(id == 'edit'){
							location.href =  "/dc/memberlogin.php?id=edit&path=" + urlEncode(path);// UTF-8にエンコードしている。
						}						
						else if(id == 'free'){
							location.href =  "/dc/memberlogin.php?id=free";
						}
					}
					return;
				}
	    }
	};
	req.open('GET', '/dc/ismemberlogin.php', true);
	req.send(null);
}


function saveloadMemberSet(){

	if(document.getElementById("saveloadmember") != null){
		if(nownicname != ""){
			if(lang == null || lang == ''){
				document.getElementById("saveloadmember").innerHTML = nownicname +  "<font color=#3366cc  style='font-size:80%;'>さん</font>";
			}
			else{
				document.getElementById("saveloadmember").innerHTML = "<font color=#3366cc  style='font-size:90%;'>Welcome,</font>&nbsp;" + nownicname;
			}
			document.getElementById("nicname").style.cssText = 'font-size:100%;color:#3366cc;';
		}
	}

}


function saveloadMemberFreeSet(){
	if(document.getElementById("saveloadmember") != null){
		if(nownicname != ""){
			if(lang == null || lang == ''){
				document.getElementById("saveloadmember").innerHTML = "ようこそ&nbsp;" + nownicname +  "さん";
			}
			else{
				document.getElementById("saveloadmember").innerHTML = "Welcome,&nbsp;" + nownicname;
			}
			document.getElementById("nicname").style.cssText = 'font-size:100%;color:#3366cc;';
		}
	}
}


//---------------------------------------
//  入力値の保存・呼出
//---------------------------------------
function savaLoad(lang){

}

//---------------------------------------
//  PC or スマートフォン選択
//---------------------------------------
function dispselect(is_pc){
	setCookie2('is_pc', is_pc, '/');
}

//---------------------------------------
//  FLASHのIEアクティブ化対応
//---------------------------------------
function flashDisp(width, height, id) {
	if (AC_FL_RunContent == 0) {
		alert('このページでは \"AC_RunActiveContent.js\" が必要です。');
	} else {
		AC_FL_RunContent(
		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
		'width', width,
		'height', height,
		'src', id,
		'quality', 'high',
		'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', id,
		'bgcolor', '#ffffff',
		'name', id,
		'menu', 'true',
		'allowFullScreen', 'false',
		'allowScriptAccess','sameDomain',
		'movie', id,
		'salign', ''
		); //end AC code
	}
}

//-----------------------------------------
//  keyで指定されたクッキーを読み込む
//-----------------------------------------
function getCookie(key) {
    tmp = ' ' + document.cookie + ';';
    var xx1 = xx2 = 0;
    var len = tmp.length;
    while (xx1 < len) {
        xx2 = tmp.indexOf(';', xx1);
        var tmp2 = tmp.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf('=');
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return('');
}

//------------------------------------------------------------------------------------

//----------------------------------------
//  スマートフォン用 履歴ソースを取得   
//----------------------------------------
function getHistrySmt(){

	var nomemmes = "記録されていません。";
	if(lang == 'en'){
		nomemmes = "Not registered.";
	}
	var str = "";
	
	var dailyuse = getDailyUseLib();
	if(dailyuse.length == 0){
		str +=  nomemmes +"<br>";
	}
	else{
		str +="<ul class='menu2'>\n";
		for(var i = 0 ; i < dailyuse.length; i++) {
			var s = dailyuse[i].split('=');
			var pos = s[1].indexOf(":");
			if( pos != -1){
				s[1] = s[1].substring(0,pos);
			}
			s[0] = allReplace(s[0],  "'", "&#39;");	
		
			str += "<li><span ><a href='#' onclick='addMenuMyPageSmt(\"" + s[0]  + "\",\"" + s[1] + "\")'><img src='/keisan/image/pcMyAdd2.gif' border=0 width=15></a></span>&nbsp;<a href='/has10/SpecExec.cgi?id="+ s[1] + "'>" + s[0] + "</a>" +"</li>\n";
		
		
		}
		str +="</ul>\n";
	}
	return str;
}
//---------------------------------------
// スマートフォンお気に入りに追加
//---------------------------------------
function addMenuMyPageSmt(name, address){
	_addMyPage(name, address);
	if(document.getElementById('favorite') != null){
		document.getElementById('favorite').innerHTML = getFavoriteSmt() ;
	}
}

//---------------------------------------
// スマートフォン用　お気に入りから削除
//--------------------------------------
function delMyPageSmt(name){
	_delMyPage(name);
	if(document.getElementById('favorite') != null){
		document.getElementById('favorite').innerHTML = getFavoriteSmt();
	}
}

var pcMypagePos = null;

//---------------------------------------
//  お気に入りに追加
//---------------------------------------
function _addMyPage(name, address){

	if(name != "" && address != ""){
		var favorites = _getMyPage();
		var olddelete = 0;
		if(favorites.length >= 10){
			olddelete=1;	
		}
		var addCount = 1;
		var str =  name + "=" + address;;
		if(favorites.length > 0){
			for(var i = 0 ; i < favorites.length; i++) {
				var s = favorites[i].split('=');
				if(s[0] != name){
					if(str != ""){
						str += ";"
					}
					str += s[0] + "=" + s[1];
					addCount++;
					if(addCount == 10){
						break;
					}
				}
			}
		} 
		setCookie2('favorites', str, '/');
	}
     // メニュー
	if(document.getElementById('_topmy') != null ){
		var toptab = getCookie('toptab');
		if(toptab == 'my'){		
			myPageClick();
		}
	}
	//  実行
	if(document.getElementById('myfavorite') != null){ 
		_myPageClick('myfavorite');
	}

	
	if(lang == 'en'){
		alert( "'" +  name + "' was added to favorite." );
	}
	else{
		alert("【 " + name + " 】を お気に入りに追加しました。" );
	}
}

//------------------------
// 実行のお気に入りから削除
//------------------------
function delExecMyPage(name){
	_delMyPage(name);
	getExecMyPage();
}

//--------------------------------
//  お気に入り から削除
//--------------------------------
function _delMyPage(name){

	if(name != ""){
	
		var delmes = name + "をお気に入りから削除しますか？";
		if(lang == 'en'){
			delmes = "Do you want to delete '" + name + "' from Favorite?";
		}
		
		if (window.confirm( delmes )) {
			var str = "";
			var favorites = _getMyPage();
			if(favorites.length > 0){
				for(var i = 0 ; i < favorites.length; i++) {
					var s = favorites[i].split('=');
					if(s[0] != name){
						if(str != ""){
							str += ";";
						}
						str += s[0] + "=" + s[1];
					}
				}
			}
			setCookie2('favorites', str, '/');
		}
	}
}



//----------------------------------------------
// メニューの実行のTABのお気に入りと履歴を表示する
//---------------------------------------------
function getTopMyPageHistory(){

	var toptab = getCookie('toptab');
	//  実行
	if(document.getElementById('myfavorite') != null){ 
		document.getElementById('myhist').innerHTML = _getUseTop10(); 
		_myPageClick('myfavorite');
	}
	//  メニュー
	else{
		if(toptab == "" || toptab == 'hist'){
			histClick();
		}
		else{
			myPageClick();
		}
	}
}


//----------------------------------
// 履歴をクリック
//----------------------------------
function histClick(){
	
	if(lang == ""){
		document.getElementById('_topmy').innerHTML   = "<font color=#3f66b3>お気に入り</font>";
		document.getElementById('_tophist').innerHTML = "<font color=#000000><b>履歴</b></font>";
	}
	else{
		document.getElementById('_topmy').innerHTML   = "<font color=#18397b>Favorite</font>";
		document.getElementById('_tophist').innerHTML = "<font color=#18397b><b>History</b></font>";
	}

	
	setIdStyle('topmy0',  "border:0px;");
	setIdStyle('topmy',   "border:1px solid #bfbfc1;");
	setIdStyle('tophist0', "border-top:1px solid #bfbfc1;border-left:1px solid #bfbfc1;border-right:1px solid #bfbfc1;");
	setIdStyle('tophist',  "border-left:1px solid #bfbfc1; border-right:1px solid #bfbfc1;");
	setIdStyle('dumtab',  "border-top:1px solid #ffffff;border-right:1px solid #ffffff;border-bottom:1px solid #bfbfc1;border-left:0px");
	setCookie2('toptab', 'hist', "/");
	
	document.getElementById('topmyhist').innerHTML = _getUseTop10();
}


//----------------------------------
// お気に入りをクリック
//----------------------------------
function myPageClick(){
	if(lang == ""){
		document.getElementById('_topmy').innerHTML   = "<font color=#000000><b>お気に入り</b></font>";
		document.getElementById('_tophist').innerHTML = "<font color=#3f66b3>履歴</font>";
	}
	else{
		document.getElementById('_topmy').innerHTML   = "<font color=#18397b><b>Favorite</b></font>";
		document.getElementById('_tophist').innerHTML = "<font color=#18397b>History</font>";
	}
	
	setIdStyle('topmy0', "border-top:1px solid #bfbfc1;border-left:1px solid #bfbfc1;border-right:1px solid #bfbfc1;");
	setIdStyle('topmy',  "border-left:1px solid #bfbfc1; border-right:1px solid #bfbfc1;");
	setIdStyle('tophist0',  "border:0px;");
	setIdStyle('tophist',   "border:1px solid #bfbfc1;");
	setCookie2('toptab', 'my', "/");
	_myPageClick('topmyhist');
}

function _myPageClick(id){
	var delmes="お気に入りから削除";
	var nomemmes = "記録されていません。";
	if(lang == 'en'){
		delmes="Delete from Favorite";
		nomemmes = "Not registered.";
	}
	
	var str = "";
	var favorites = _getMyPage();
	if(favorites.length == 0){
		str += "<span style='font-size:13px;line-height:19px;'> " + nomemmes + "</span><br>";
	}
	else{
		str += "<table cellpadding=0 cellspacing=0 border=0 style='font-size:13px;line-height:19px;'>";
		for(var i = 0 ; i < favorites.length; i++) {
			var s = favorites[i].split('=');
			s[0] = allReplace(s[0],  "'", "&#39;");	
			str += "<tr><td valign=top width=16 align=center><a href='#' onclick='delTop(\"" + s[0]  + "\")'  alt='" + delmes + "' + title='" + delmes +"' style='padding:1px;'><img src='/keisan/image/pcMyDel2.gif' border=0 ></a></td><td><a href='/has10/SpecExec.cgi?id="+ s[1] + "'>" + s[0] + "</a></td></tr>\n";
		}
		str += "</table>";
	}
	document.getElementById(id).innerHTML =  str;
}


//------------------------
// TOPメニューお気に入り
//------------------------
function delTop(name){
	_delMyPage(name);
	getTopMyPageHistory();
}


//------------------------
// 実行のお気に入り表示
//------------------------
function getExecMyPage(){
	var delmes="お気に入りから削除";
	var nomemmes = "記録されていません。";
	if(lang == 'en'){
		delmes="Delete from Favorite";
		nomemmes = "Not registered.";
	}

	var str = "";
	var favorites = _getMyPage();
	if(favorites.length == 0){
		str =  nomemmes + "<br>";
	}
	else{
		str = "<table cellpadding=0 cellspacing=0 border=0>";
		for(var i = 0 ; i < favorites.length; i++) {
			var s = favorites[i].split('=');

			s[0] = allReplace(s[0],  "'", "&#39;");	
			
			str += "<tr><td valign=top><a href='#' onclick='delExecMyPage(\"" + s[0]  + "\")'  alt='" + delmes + "' title='" + delmes +  "' style='padding-top:3px;'><img src='/keisan/image/pcMyDel2.gif' border=0 ></a></td><td><a href='/has10/SpecExec.cgi?id="+ s[1] + "'>" + s[0] + "</a></td></tr>";
		}
		str += "</table>\n"; 
	}
	
	if(document.getElementById('exeMyPage') != null){
		document.getElementById('exeMyPage').innerHTML = str;
	}
}


//--------------------------------------------
//  お気に入りをクッキーから読み込む
//--------------------------------------------
function _getMyPage(){
	var favorites = new Array();
	var cookie = getCookie('favorites');
	if(cookie == ''){
		return favorites;
	}
	var ck = cookie.split(';');
	for(var j=0; j < ck.length; j++){
		favorites.push(ck[j]);
	}
	return favorites;
}

//------------------------------------------
//  スマートフォン用メニュー Mお気に入り取得   
//-------------------------------------------
function getFavoriteSmt(){

	var nomemmes = "記録されていません。";
	if(lang == 'en'){
		nomemmes = "Not registered.";
	}	

	//-----------------------
	//  お気に入り
	//-----------------------
	var favorites = _getMyPage();
	var str="";	
	if(favorites.length == 0){
		str += nomemmes +"<br><br>";
	}
	else{
		str +="<ul class='menu2'>\n";
		for(var i = 0 ; i < favorites.length; i++) {
			var s = favorites[i].split('=');

			s[0] = allReplace(s[0],  "'", "&#39;");	
			
			str += "<li><span><a href='#' onclick='delMyPageSmt(\"" + s[0]  + "\")'><img src='/keisan/image/pcMyDel2.gif' border=0 width=15></a></span>&nbsp;<a href='/has10/SpecExec.cgi?id="+ s[1] + "'>" + s[0] + "</a></li>";

		
		}
		str +="</ul><br><br>\n";
	}	
	return str;
}

//-----------------------------------------
// よく使うライブラリをクッキーに書き込む
//   実行時にだけaddressが入っている
//-----------------------------------------
function setDailyUseLib(name, address, lang){

	if(name != "" && address != ""){
		var str = name + "=" + address;
		var dailyuse = getDailyUseLib();

		if(dailyuse.length > 0){
			var j = 1;
			for(var i = 0 ; i < dailyuse.length; i++) {
				var s = dailyuse[i].split('=');
				if(s[0] != name){
					str += ";" + s[0] + "=" + s[1];
					j++;
					if(j == 10){break;}
				}
			}
		}
		setCookie2('dailyuse', str, '/');
	}
}

//--------------------------------------------
//  よく使うライブラリをクッキーから読み込む
//--------------------------------------------
function getDailyUseLib(){
	var dailyuse = new Array();
	var cookie = getCookie('dailyuse');

	if(cookie == ''){
		return dailyuse;
	}
	var ck = cookie.split(';');
	for(var j=0; j < ck.length; j++){
		dailyuse.push(ck[j]);
	}
	return dailyuse;
}

//--------------------------------------------
//  最近使ったライブラリ
//--------------------------------------------
function _getUseTop10(){
	var addmes="お気に入りに追加";
	var nomemmes = "記録されていません。";
	if(lang == 'en'){
		addmes="Add to favorite";
		nomemmes = "Not registered.";
	}
	var str="";
	var dailyuse = getDailyUseLib();
	if(dailyuse.length == 0){
		return "<span style='font-size:13px;line-height:19px;'> " + nomemmes + '<span><br>';
	}
	str = "<table cellpadding=0 cellspacing=0 style='font-size:13px;'>";
	for(var i = 0 ; i < dailyuse.length; i++) {
		var s = dailyuse[i].split('=');
		var pos = s[1].indexOf(":");
		if( pos != -1){
			s[1] = s[1].substring(0,pos);
		}
		s[0] = allReplace(s[0],  "'", "&#39;");		
		str += "<tr><td align=center valign=top width=16><a href='#' onclick='_addMyPage(\""+ s[0] + "\",\"" +  s[1] +"\");'  alt='" + addmes +"' title='" + addmes + "'><img src='/keisan/image/pcMyAdd2.gif' border=0 ></a></td>";
		str += "<td valign=top style='line-height:10px;padding-bottom:9px;'><a href='/has10/SpecExec.cgi?id="+ s[1] + "' >" + s[0] + "<a></td></tr>\n";
	}
	str += "</table>";
	return str;
}

function getUseTop10ByID(){
	document.getElementById('usetop10').innerHTML = _getUseTop10();
}

function getUseTop10(){
	return document.write(_getUseTop10());
}


//--------------------------------------------
//  プロフィールをクッキーから読み込む
//--------------------------------------------
function getProfileCookie(){
	var profile = new Array();
	var cookie = getCookie('profile');

	if(cookie != ''){
		var ck = cookie.split(';');
		for(var j=0; j < ck.length; j++){
			profile.push(ck[j]);
		}
	}
	return profile;
}

//--------------------------------------------
//  プロフィールをクッキーから読み込む
//--------------------------------------------
function getProfileCookie2(cname){
	var profile = new Array();
	var cookie = getCookie('profile');
	if(cookie != ''){
		var ck = cookie.split(';');
		for(var j=0; j < ck.length; j++){
			var s = ck[j].split('=');
			if(s[0] == cname){
				return s[1];
			}	
		}
	}
	return null;
}

function getProfileStr(ptype, val, variname){
	//  "自分の誕生年",  "自分の誕生月一覧(1-12)",  "自分の誕生月一覧(Jan-Dec)", "自分の誕生日一覧(1-31)", "相手の誕生年",  "相手の誕生月一覧(1-12)",  "相手の誕生月一覧(Jan-Dec)", "相手の誕生日一覧(1-31)", "性別", "体重", "身長" ,"年齢","ウェスト","ヒップ"
	var value="";
	if(ptype != val){
		value=val;
	}
	var name="";
	if(ptype == "自分の誕生月一覧(1-12)"){
		name="self_month_1_12";
	}
	else if(ptype == "自分の誕生月一覧(Jan-Dec)"){
		name="self_month_jan_Dec";
	}
	else if(ptype == "自分の誕生日一覧(1-31)"){
		name="self_month_1_31";
	}
	else if(ptype == "自分の誕生年"){
		name="self_y";
	}
	else if(ptype == "相手の誕生月一覧(1-12)"){
		name="other_month_1_12";
	}
	else if(ptype == "相手の誕生月一覧(Jan-Dec)"){
		name="other_month_jan_Dec";
	}
	else if(ptype == "相手の誕生日一覧(1-31)"){
		name="other_month_1_31";
	}
	else if(ptype == "相手の誕生年"){
		name="other_y";
	}
	else if(ptype == "性別"){
		name="sex";
	}
	else if(ptype == "体重"){
		name="weight";
	}
	else if(ptype == "身長"){
		name="height";
	}
	else if(ptype == "年齢"){
		name="age";
	}
	else if(ptype == "ウエスト"){
		name="waist";
	}
	else if(ptype == "ヒップ"){
		name="hipp";
	}
	
	var cookie = getProfileCookie();

	
	if(value == ""){
		for(var i = 0 ; i < cookie.length; i++) {
			var s = cookie[i].split('=');
			if(s[0] == name){
				value = s[1];
				break;
			}
		}
	}

	if(ptype == "性別"){
		if(value != null && value !=""){
			document.getElementsByName(variname)[value].checked = true;
		}
	}
	else if(ptype == "自分の誕生年"  ||  ptype == "相手の誕生年"  ||  ptype == "体重"  || ptype == "身長" || ptype == "年齢" || ptype == "ウエスト" || ptype == "ヒップ" ){
		document.getElementById(variname).value = value;
	}	
	else{
		if(value != null && value !=""){
			document.getElementById(variname).selectedIndex = value - 1 ;
		}
	}
	setProfileCookie(name, value);
	return;
}

//-----------------------------------------
// プロフィールをクッキーに書き込む
//
//	self_month_1_12=1-12
//	self_month_jan_Dec=1-12
//	self_month_1_31=1-31
//	self_y=xxxx
//	other_month_1_12=1-12
//	other_month_jan_Dec=1-12
//	other_month_1_31=1-31
//	other_y=xxxx
//  sex=0-男,  1-女
//  weight= xxx kg 
//  height= xxx cm
//-----------------------------------------
function setProfileCookie(name, value){
	if(name != "" && value != "" ){
		var str = name + "=" + value;
		var profile = getProfileCookie();

		if(profile.length > 0){
			for(var i = 0 ; i < profile.length; i++) {
				var s = profile[i].split('=');
				if(s[0] != name){
					str += ";" + s[0] + "=" + s[1];
				}
			}
		}		
		setCookie2('profile', str, '/');
	}
}

function urlEncode(instr){
	var outstr = encodeURI(instr);
	outstr = outstr.replace('%EF%BD%9E','%e3%80%9C');  // # 〜 
	outstr = outstr.replace('%E2%88%A5','%e2%80%96');  // ‖
	outstr = outstr.replace('%EF%BC%8D','%e2%88%92');  // −
	outstr = outstr.replace('%EF%BF%A0','%c2%a2');	 // ¢
	outstr = outstr.replace('%EF%BF%A1','%c2%a3');     // £
	outstr = outstr.replace('%EF%BF%A2','/%c2%ac');    // ¬
	return outstr;
}


//---------------------------------------------
// TOP メニュー 生活・教育・・専門のレイアウト 
//---------------------------------------------
function doLayout(life, math, special, self){

	var cookie = getCookie('menulayout');
	if(cookie == ''){
		if(document.getElementById('pos4') == null){
			cookie = "life,math,special";
		}
		else{
			cookie = "life,math,special,self";
		}
	}
	var layout = cookie.split(',');
	for(var i = 0; i < layout.length; i++){
		var pos='pos1';
		if(i == 1){pos='pos2';}
		else if(i == 2){pos='pos3';}
		else if(i == 3){pos='pos4';}
		if(layout[i] == 'life'){
			document.getElementById(pos).innerHTML = life;
		}
		else if(layout[i] == 'math'){
			document.getElementById(pos).innerHTML = math;
		}
		else if(layout[i] == 'special'){
			document.getElementById(pos).innerHTML = special;
		}
		else if(layout[i] == 'self'){
			document.getElementById(pos).innerHTML = self;
		}
		
		if(i == 0) { 
			setElementAttribute(layout[i] + "_up" , 'alt', '最後尾に移動');  
			setElementAttribute(layout[i] + "_up" , 'title', '最後尾に移動');
		}
		else if(i == (layout.length-1)) { 
			setElementAttribute(layout[i] + "_down" , 'alt', '最上位に移動');  
			setElementAttribute(layout[i] + "_down" , 'title', '最上位に移動');
		}		
	}
}

//---------------------------------------------
// TOP メニュー 生活・教育・・専門の上下移動 
//---------------------------------------------
function updown(updawnkey){
	var lifepos=0;
	var mathpos=1;
	var specialpos=2;
	var selfpos=3;

	var cookie = getCookie('menulayout');
	if(cookie == ''){
		if(document.getElementById('pos4') == null){
			cookie = "life,math,special";
		}
		else{
			cookie = "life,math,special,self";
		}
	}	
	var layout = cookie.split(',');	
	for(var i = 0; i < layout.length ; i++){
		if(layout[i] == 'life'){
			lifepos=i;
		}
		else if(layout[i] == 'math'){
			mathpos=i;
		}
		else if(layout[i] == 'special'){
			specialpos=i;
		}		
		else if(layout[i] == 'self'){
			selfpos=i;
		}
	}
	if(updawnkey == 'life_up'){
		layout = sawps( layout, lifepos, lifepos-1 );
	}
	else if(updawnkey == 'life_down'){
		layout = sawps( layout, lifepos, lifepos+1 );
	}
	else if(updawnkey == 'math_up'){
		layout = sawps( layout, mathpos, mathpos-1 );
	}	
	else if(updawnkey == 'math_down'){
		layout = sawps( layout, mathpos, mathpos+1 );
	}
	else if(updawnkey == 'special_up'){
		layout = sawps( layout, specialpos, specialpos-1 );
	}
	else if(updawnkey == 'special_down'){
		layout = sawps( layout, specialpos, specialpos+1 );
	}
	else if(updawnkey == 'self_up'){
		layout = sawps( layout, selfpos, selfpos-1 );
	}
	else if(updawnkey == 'self_down'){
		layout = sawps( layout, selfpos, selfpos+1 );
	}

	for(var i = 0; i < layout.length ; i++){

		setElementAttribute(layout[i] + "_up" , 'alt', '上に移動');  
		setElementAttribute(layout[i] + "_up" , 'title', '上に移動');
		setElementAttribute(layout[i] + "_down" , 'alt', '下に移動');  
		setElementAttribute(layout[i] + "_down" , 'title', '下に移動');
		
		if(i == 0) { 
			setElementAttribute(layout[i] + "_up" , 'alt', '最後尾に移動');  
			setElementAttribute(layout[i] + "_up" , 'title', '最後尾に移動');
		}
		else if(i == (cookie.length-1)) { 
			setElementAttribute(layout[i] + "_down" , 'alt', '最上位に移動');  
			setElementAttribute(layout[i] + "_down" , 'title', '最上位に移動');
		}
	}
	if(document.getElementById('pos4') == null){
		setCookie('menulayout', layout[0] + ',' + layout[1] + ',' + layout[2]);
	}
	else{
		setCookie('menulayout', layout[0] + ',' + layout[1] + ',' + layout[2] + ',' + layout[3]);
	}
}


function setElementAttribute(id, attribute, value) { 
    var element = document.getElementById(id); 
    element.setAttribute(attribute, value); 
} 


//------------------------------------------
//  ＴＯＰメニューを上下キーで移動させる
//   from --> to へ移動
//-------------------------------------------
function  sawps(layout, from, to){
	if(to == -1){
		to=layout.length-1;
	}
	else{
		if(to == layout.length){to=0;}
	}
	
	var save1 = layout[from];
	layout[from] = layout[to];
	layout[to] = save1;
	
	var fromPos = "pos" + (++from);
	var toPos= "pos" + (++to);

	var str = document.getElementById(fromPos).innerHTML; 
	document.getElementById(fromPos).innerHTML = document.getElementById(toPos).innerHTML; 
	document.getElementById(toPos).innerHTML = str; 
	
	return layout;
}


//----------------------------
//  年月日を取得する 
//  (例）  19991231
//----------------------------
function getYYYYMMDD(){
	var dd = new Date();
	var yyyy = dd.getYear();
	var mm = dd.getMonth() + 1;
	dd = dd.getDate();
	if (yyyy < 2000) { yyyy += 1900; }
	if (mm < 10) { mm = '0' + mm; }
	if (dd < 10) { dd = '0' + dd; }
	return ('' + yyyy + mm + dd);
}

//----------------------------
//  年を取得する 
//  (例）  1999
//----------------------------
function getYYYY(){
	var yyyy = new Date().getYear();
	if (yyyy < 2000) { yyyy += 1900; }
	return (yyyy);
}		

//----------------------------
//  月を取得する 
//  (例）  12
//----------------------------
function getMM(){
	var mm = new Date().getMonth() + 1;
	if (mm < 10) { mm = '0' + mm; }			
	return (mm);
}

//----------------------------
//  日を取得する 
//  (例）  31
//----------------------------
function getDD(){
	var dd = new Date().getDate();
	if (dd < 10) { dd = '0' + dd; }		
	return (dd);
}

//----------------------------
//  時分秒を取得する 
//  (例）  115959
//----------------------------
function getHHMMSS(){
	var dd = new Date();
	var hh = dd.getHours();
//	var mm = dd.getMinutes() + 1;
	var mm = dd.getMinutes();
	var ss = dd.getSeconds();
	if (hh < 10) { hh = '0' + hh; }
	if (mm < 10) { mm = '0' + mm; }
	if (ss < 10) { ss = '0' + ss; }
	return ('' + hh + mm + ss);
}

//----------------------------
//  時を取得する 
//  (例）  11
//----------------------------
function getHH(){
	var dd = new Date();
	var hh = dd.getHours();
	if (hh < 10) { hh = '0' + hh; }
	return hh;
}

//----------------------------
//  分を取得する 
//  (例）1分の場合は  --> 01 と返す
//----------------------------
function getMMinit(){
	var dd = new Date();
//	var mm = dd.getMinutes() + 1;
	var mm = dd.getMinutes();
	if (mm < 10) { mm = '0' + mm; }
	return mm;
}

//----------------------------
//  秒を取得する 
//  (例）1秒の場合は  --> 01 と返す
//----------------------------
function getSS(){
	var dd = new Date();
	var ss = dd.getSeconds();
	if (ss < 10) { ss = '0' + ss; }
	return ss;
}

function getYMD(id){
	if(id == 'YYYYMMDD'){
		return getYYYYMMDD();
	}
	else if(id == 'YYYY'){
		return getYYYY();
	}
	else if(id == 'MM'){
		return getMM();
	}
	else if(id == 'DD'){
		return getDD();
	}
}
function getHMS(id){		
	if(id == 'HHMMSS'){
		return getHHMMSS();
	}
	else if(id == 'HH'){
		return getHH();
	}
	else if(id == 'MM'){
		return getMMinit();
	}			
	else if(id == 'SS'){
		return getSS();
	}	
}

//-------------------------------------
//  min 〜max 内のランダムな値を返す
//-------------------------------------
function getRandomFromTo(min, max){		
//		return min + Math.floor( Math.random() * (max+1) ); 
	return  new Number(min) + Math.floor( Math.random() * (max-min+1)); 
}

function getRandom(range){
	var reg = new RegExp(',');
	if( reg.test(range) ){		// 位ごとに範囲を指定
		var kurai = range.split(',');
		var i;
		var ans = 0;
		
		for (i = 0; i < kurai.length; i++) {
			var kuraiRenge = kurai[i];
			var minMax = kuraiRenge.split('|');	
			var c = getRandomFromTo(minMax[0], minMax[1]);
			ans += c * Math.pow(10,i) ;
		}
		return ans;
	}
	else{ 			  // 全体の範囲を指定
		var minMax = range.split('|');	
		return getRandomFromTo(minMax[0], minMax[1]);
	}
}

//-----------------------------------------
//  ポップアップメニュー
//-----------------------------------------
var tid;
var cgi = 'has10';


//function MM_swapImgRestore() { //v3.0
//  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
//}

//function MM_swapImage() { //v3.0
//   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
//   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
//}

//function MM_preloadImages() { //v3.0
//  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
//    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
//    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
//}

//function MM_findObj(n, d) { //v4.01
//  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
//    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
//  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
//  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
//  if(!x && d.getElementById) x=d.getElementById(n); return x;
//}


//-----------------------------------------
//   グラフ描画
//------------------------------------------
function dispgraph(){
	document.calc.action = '/keisan/graph/php/graphForm.php'; 
	document.calc.target = '_blank'; 
	document.calc.method = 'post'; 
	document.calc.submit(); 
}

//-------------------
// 計算画面中のグラフ描画
//------------------
function callDispGraph(
    lang, 
	xLabel, 
	data, 
	exp, 
	title_onoff,
	gtitle,
	yname,
	xname,
	width,
	height,
	background,
	xstep,
	xcol,
	label_angle,
	scale_max,
	scale_min,
	zero_memory,
	infinity,
	up_ignore,
	down_ignore,
	nonOutpuTable,
	line_width,
	circle_size,
	spline,
	stack,
	transparent,
	stack2,
	transparent2,
	d23,
	bargap,
	regend_pos,
	rwidth,
	legend_y_offset,
	each,
	uniqID,
	isAndroid,
	isIphone){


	filename = Math.floor(Math.random() * 123456789012) + '.png'; 
    //  同一画面のグラフ
	// POSTパラメータ   
	postData =  'filenam=' + filename;
	postData += '&lang=' + lang;
	postData += '&xLabel=' + encode(xLabel);
	postData += '&data=' + data ;
	postData += '&exp=' + exp;
	postData += '&width=' + width;
	postData += '&height=' + height;
	postData += '&titleonoff=' + title_onoff;
	postData += '&gtitle=' + gtitle;
	postData += '&yname=' + yname;
	postData += '&xname=' + xname;
	postData += '&xstep=' + xstep;

	postData += '&xcol=' + xcol;
	postData += '&label_angle=' + label_angle;
	
	postData += '&scale_max=' + scale_max;
	postData += '&scale_min=' + scale_min;
	postData += '&zero_memory=' + zero_memory;
	postData += '&line_width=' + line_width;
	postData += '&circle_size=' + circle_size;

	if(transparent == 'ON'){
		postData += '&transparent=0';
	}
	else{
		postData += '&transparent=1';
	}

	postData += '&stack=' + stack;
	if(transparent2 == 'ON'){
		postData += '&transparent2=0';
	}
	else{
		postData += '&transparent2=1';
	}

	postData += '&stack2=' + stack2;	
	postData += '&infinity=' + infinity;
	postData += '&up_ignore=' + up_ignore;
	postData += '&down_ignore=' + down_ignore;	

	postData += '&non_output_table=' + nonOutpuTable;
	
	postData += '&background=' + background;
	if(regend_pos == 'right'){
		postData += '&regend_pos=1';
	}
	else{
		postData += '&regend_pos=0';
	}

	postData += '&d23=' + d23;
	postData += '&rwidth=' + rwidth;
	postData += '&rheight=' + rwidth;

	postData += '&legend_y_offset=' + legend_y_offset;
	postData += '&bargap=' + bargap;
	postData += '&spline=' + spline;
	postData += '&each_graph=' + each;	


	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {   
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }   
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }   
	})();   
	req.onreadystatechange = function() {   
	switch (req.readyState) {   
		case 1: // Open   
		case 2: // Sent   
		case 3: // Receiving   
			break;   
		case 4: // Loaded   
			if(req.status == 200){
				var cwidth = document.body.clientWidth -5;
				if(width > cwidth && isAndroid == 1){
				   height = parseInt(cwidth / width * height);
				   width = parseInt(cwidth);
				}
				if(isIphone == 1){
//alert(isIphone + ":" + document.innerWidth);
				   height = parseInt(height*0.78);
				   width = parseInt(width*0.78);
				}
				document.getElementById('myGraph').innerHTML = "<img width=" + width + " height=" +  height  + " src='/keisan/lib/virtual/tmp/"+ filename + "' border=0><br><br>";   
			
			}
		return;
	    }   
	};  
//alert(postData + ":" + postData);

	req.open('POST', '/keisan/graph/php/graph.php', true);   
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
	req.send(postData);
	
}

//-------------------------------------
//   計算ボタンが押された時に呼ばれる
//--------------------------------------
function execGo(){
	var postData ="";
	for(var i = 0; i < document.calc.length; i++){
		if(document.calc.elements[i] != null ){

			if(postData != ""){
				postData += "&";
			}	
			var nam = document.calc.elements[i].name;
			var val = document.calc.elements[i].value;
			if(nam != null && val !=null && nam.match(/^var_/)) {
				nam = urlEncode(nam);
			}			
			postData  += nam  + "=" + val;
		}

	}

	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {   
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }   
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }   
	})();   
	req.onreadystatechange = function() {   
	switch (req.readyState) {   
		case 1: // Open   
		case 2: // Sent   
		case 3: // Receiving   
			break;   
		case 4: // Loaded   
			if(req.status == 200){
//alert(req.responseText );
				document.getElementById('inout').innerHTML = req.responseText;  
				postrender(document.getElementById('inout'));
				getUseTop10ByID();
			}
		return;
	    }   
	};
	req.open('POST', '/has10/SpecExec.cgi', true);   
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
	req.send(postData);	
}

//---------------------------------------------------
//innerHTMLに挿入してそこにあるscriptもついでに実行
//---------------------------------------------------
function postrender(target)
{
    var i, f, script, temp = document.write;
    var scripts = target.getElementsByTagName('script');
    for(i=0,f=scripts.length;i<f;i++)
    {
        script = scripts[i];
        eval(script.text)
    };

    document.write = temp;

};

function encode(text){
	html = allReplace(text, '&', '%26');	 
	return  encodeURI(allReplace(html, '+', '%2B'));	 
}
function allReplace(text, s, t) {
 while (true) { 
     var text2 = text;
	 text = text2.replace(s, t);
 	if (text == text2) {
  		break;  
 	}
	}
	return text;
}

//-------------------------------リニューアル---------------------------------------------------------------------------
//--------------------------------------
// リニューアル ロード時呼び出し
//  お気に入りの「この計算を登録」はＯＦＦ
//--------------------------------------
function favoriteHistoryLoad(){
	var toptab = getCookie('toptab');
	if(toptab == "" || toptab == 'hist'){
		_getHistoryTab();
	}
	else{
		_getFavoriteTab(0);
	}
}

function setTopTab(str){
	setCookie2('topCateTab', str, '/');
	
}



//--------------------------------------
// リニューアル PHPロード時呼び出し
//--------------------------------------
function pageLoad(lang){
// alert("lang =" + lang + "   is_pc=" + is_pc);
	menuTopLoad(lang, is_pc);
	favoriteHistoryLoad();
}


//--------------------------------------
// リニューアル FREE計算ロード時呼び出し
//--------------------------------------
function freeLoad(){
//	favoriteHistoryLoad();

	libtitle = "フリー計算";
	selectGmenu();
	$('#questionnaire .tabs .tab-title li').siblings().removeClass('selected');
	$('#questionnaire .tabs .tab-title li').eq(0).addClass('selected');
	$('#questionnaire .tabs .tab-contents').hide().eq(0).show();	
	readAnketo(0);

	menuTopLoad(lang, is_pc);
	
}


//--------------------------------------
// リニューアル 実行ロード時呼び出し
//--------------------------------------
function menuLoad(kaisou){
	favoriteHistoryLoad();
	libtitle = kaisou;
	selectGmenu();
	menuTopLoad(lang, is_pc);

}

function menuBBS(){
	favoriteHistoryLoad();
	libtitle = "BBS";
	selectGmenu();
	menuTopLoad(lang, is_pc);

}

//---------------------------------------------
// リニューアル メニューＴＯＰロード時呼び出し
//---------------------------------------------
function menuTopLoad(la, pc){
	var domain = location.hostname;	
	if(la == ""){
		var topCateTab = getCookie('topCateTab');
		if(topCateTab == null){
			topCateTab = 0;
		}
		else{
			topCateTab--;
		}
		favoriteHistoryLoad();
		if(domain ==      '128.1.110.155' ){   enserver = "http://128.1.110.168/"; }
		else if(domain == '128.1.110.163'){    enserver = "http://128.1.110.165/"; }
		else if(domain == 'keisan.casio.jp' ){ enserver = "http://keisan.casio.com/"; }
		else if(domain == 'keisan02.casio.jp'){enserver = "http://keisan02com.casio.jp/"; }
		if(document.getElementById('sellang') != null){ document.getElementById('sellang').innerHTML =  "<a href='" + enserver + "has10/Menu.cgi?pc=" + pc + "'>English</a>";}

	}
	else{
		if(domain ==      '128.1.110.168' ){    enserver = "http://128.1.110.155/"; }
		else if(domain == '128.1.110.165'){     enserver = "http://128.1.110.163/"; }
		else if(domain == 'keisan.casio.com' ){ enserver = "http://keisan.casio.jp/"; }
		else if(domain == 'keisan02com.casio.jp'){enserver = "http://keisan02.casio.jp/"; }
		if(document.getElementById('sellang') != null){ document.getElementById('sellang').innerHTML =  "<a href='" + enserver + "has10/Menu.cgi?pc=" + pc +"'>Japanese</a>"; }
	}

	//私が作った計算
	if(nownicname != ""){
		if(document.getElementById('myself') != null){ document.getElementById('myself').innerHTML = "私の自作式(" +  nownicname + "さん)";}
	}


	readColumnOneLine(); //計算コラム最新1行を読み込む
	
}



//--------------------------------------
// リニューアル 実行ロード時呼び出し
//--------------------------------------
function execLoad(){
	var toptab = getCookie('toptab');
	if(toptab == "" || toptab == 'hist'){
		_getHistoryTab();
		$('#favorite .tabs .tab-title li').siblings().removeClass('selected');
		$('#favorite .tabs .tab-title li').eq(1).addClass('selected');
		$('#favorite .tabs .tab-contents').hide().eq(1).show();
	}
	else{
		_getFavoriteTab(1);
	}
	readAnketo(0);
	selectGmenu();
	menuTopLoad(lang, is_pc);

	readColumnOneLine(); //計算コラム最新1行を読み込む

}

function setPcLang(pc, isIphone, lang) {
	_tabpc = pc;
	_isIphone = isIphone;
	_tablang = lang;
}



//--------------------------------
//  計算コラム最新1行を読み込む
//--------------------------------
function readColumnOneLine(){
	if(document.getElementById('keisancolumn') !=null){

		var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
			try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
			catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
		})();
		req.onreadystatechange = function() {
			switch (req.readyState) {
				case 1: // Open
				case 2: // Sent
				case 3: // Receiving
					break;
				case 4: // Loaded
					if(req.status == 200){
						document.getElementById('keisancolumn').innerHTML = req.responseText;
						return;
					}
		    }
		};
		req.open('GET', '/keisan/unchiku/contents.php?pno=new', true);
		req.send(null);		
		

	}
}

//--------------------------------------
// リニューアル お気に入りセット
//--------------------------------------
function getFavoriteTab(isRegist){
	setCookie2('toptab', 'my', "/");
	_getFavoriteTab(isRegist);
}

function _getFavoriteTab(isRegist){
	if(document.getElementById('favorite-tab') == null) return;
	var favorite = _getMyPage();
	var str = "";
	for(var i = 0 ; i < favorite.length; i++) {
		var s = favorite[i].split('=');
		var pos = s[1].indexOf(":");
		if( pos != -1){
			s[1] = s[1].substring(0,pos);
		}
		var name = allReplace(s[0],  "'", "&#39;");	
		str += "<dl>\n";
		str += "<dd><a href='#' onclick='delFavoriteTab(" + isRegist + ", \"" + name  + "\")'><img src='/keisan/common/img/ico_minus.gif' alt='お気に入りから削除'  class='favorite_hist_icon' /></a> </dd>\n";
		str += "<dt><a href='/has10/SpecExec.cgi?id="+ s[1] + "''>"+ name + "</a></dt>\n";
		str += "</dl>\n";

	}
	str += "<p class='none'>記録されていません</p>\n";

	if(isRegist == 1 && (typeof libname != "undefined") ){
		str += "<div class='add'><a href='' onclick='_addMyPage(\""+ libname + "\",\"" +  sysUserCode +"\");_getFavoriteTab(" + isRegist+ ");return false;'><img src='/keisan/common/img/btn_add.gif' alt='+この計算を登録する' class='hov' /></a></div>\n";
	}else{
		str += "<div class='add'><img src='/keisan/common/img/btn_add_none.gif' alt='+この計算を登録する' /></div>\n";
	}
	document.getElementById('favorite-tab').innerHTML = str;
}


//--------------------------------------
//  リニューアル　お気に入り から削除
//--------------------------------------
function delFavoriteTab(isRegist, name){
	if(name != ""){
		var delmes = "「" + name + "」をお気に入りから削除しますか？";
		if(lang == 'en'){
			delmes = "Do you want to delete '" + name + "' from Favorite?";
		}
		if (window.confirm( delmes )) {
			var str = "";
			var favorites = _getMyPage();
			if(favorites.length > 0){
				for(var i = 0 ; i < favorites.length; i++) {
					var s = favorites[i].split('=');
					if(s[0] != name){
						if(str != ""){
							str += ";";
						}
						str += s[0] + "=" + s[1];
					}
				}
			}
			setCookie2('favorites', str, '/');
		}
	}
	getFavoriteTab(isRegist);	
}

//--------------------------------------
// リニューアル 履歴にセット
//--------------------------------------
function getHistoryTab(){
	setCookie2('toptab', 'hist', "/");
	_getHistoryTab();
}

function _getHistoryTab(){
	if(document.getElementById('history') == null) return;
	var dailyuse = getDailyUseLib();
	var str = "";
	for(var i = 0 ; i < dailyuse.length; i++) {
		var s = dailyuse[i].split('=');
		var pos = s[1].indexOf(":");
		if( pos != -1){
			s[1] = s[1].substring(0,pos);
		}
		var name = allReplace(s[0],  "'", "&#39;");	
		var onClick = " onclick='_addMyPage(\""+ name + "\",\"" +  s[1] +"\");'";
		str += "<dl>\n";
		str += "<dd><a href='#' onclick='addHistoryTab(\""+ name + "\",\"" +  s[1] +"\");'><img src='/keisan/common/img/ico_plus.gif' alt='お気に入りに追加'  class='favorite_hist_icon'  /></a> </dd>\n";
		str += "<dt><a href='/has10/SpecExec.cgi?id="+ s[1] + "''>"+ name + "</a></dt>\n";
		str += "</dl>\n";

	}
	str += "<p class='none'>記録されていません</p>\n";
	document.getElementById('history').innerHTML = str;
}


//---------------------------------------
//  リニューアル お気に入りに追加
//---------------------------------------
function addHistoryTab(name, address){

	if(name != "" && address != ""){
		var favorites = _getMyPage();
		var olddelete = 0;
		if(favorites.length >= 10){
			olddelete=1;	
		}
		var addCount = 1;
		var str =  name + "=" + address;;
		if(favorites.length > 0){
			for(var i = 0 ; i < favorites.length; i++) {
				var s = favorites[i].split('=');
				if(s[0] != name){
					if(str != ""){
						str += ";"
					}
					str += s[0] + "=" + s[1];
					addCount++;
					if(addCount == 10){
						break;
					}
				}
			}
		} 
		setCookie2('favorites', str, '/');
	}
     // メニュー
	if(document.getElementById('_topmy') != null ){
		var toptab = getCookie('toptab');
		if(toptab == 'my'){		
			myPageClick();
		}
	}
	//  実行
	if(document.getElementById('myfavorite') != null){ 
		_myPageClick('myfavorite');
	}
	if(lang == 'en'){
		alert( "'" +  name + "' was added to favorite." );
	}
	else{
		alert("【 " + name + " 】を お気に入りに追加しました。" );
	}
}


//--------------------------------------
// リニューアル グローバルメニュー選択
//--------------------------------------
function selectGmenu(){

	if(is_pc == 0 || libtitle == ""){
		return;
	}

	// Groval menu 選択
	if(libtitle.match(re = new RegExp("^04000000.数学公式集")) ||
	   libtitle.match(re = new RegExp("^05000000.物理公式集")) ||
	   libtitle.match(re = new RegExp("^06000000.計算応用集")) ||
	   libtitle.match(re = new RegExp("^05000000.Mathematics")) ||
	   libtitle.match(re = new RegExp("^06000000.Science"))   ) {
		document.getElementById('nav-global01img').src = "/keisan/common/img/nav_g01_on.gif";
	}
	else if(libtitle.match(re = new RegExp("^07000000.統計関数")) ||
	   libtitle.match(re = new RegExp("^08000000.特殊関数"))      ||
	   libtitle.match(re = new RegExp("^08500000.数値解析"))      ||
	   libtitle.match(re = new RegExp("^07000000.Probability Function"))      ||
	   libtitle.match(re = new RegExp("^08000000.Special Function"))      ||
	   libtitle.match(re = new RegExp("^08500000.Numerical analysis")) ) {
		document.getElementById('nav-global02img').src = "/keisan/common/img/nav_g02_on.gif";
	}
	else if(libtitle.match(re = new RegExp("^09000000.")) ||
			libtitle.match(re = new RegExp("^09100000.")) ||
			libtitle.match(re = new RegExp("^09300000.")) ||
			libtitle.match(re = new RegExp("^09500000.")) ||
			libtitle.match(re = new RegExp("^09700000.")) ||
			libtitle.match(re = new RegExp("^09900000.")) ) {
		document.getElementById('nav-global03img').src = "/keisan/common/img/nav_g03_on.gif";
	}
	else if(libtitle.match(re = new RegExp("フリー計算"))  ) {
		document.getElementById('nav-global04img').src = "/keisan/common/img/nav_g04_on.gif";
	}
	else if(libtitle.match(re = new RegExp("BBS"))  ) {
		document.getElementById('nav-global05img').src = "/keisan/common/img/nav_g05_on.gif";
	}
	else{
		document.getElementById('nav-global00img').src = "/keisan/common/img/nav_g00_on.gif";
	}

}

function frqask(){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
				document.getElementById('faq').innerHTML = req.responseText;
				return;
				}
	    }
	};
	req.open('GET', '/keisan/faq.php?&exec=1' , true);
	req.send(null);
}

function linkset(){
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();
	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
				document.getElementById('linkset').innerHTML = req.responseText;
				return;
				}
	    }
	};
	req.open('GET', '/keisan/link.php?&exec=1&title=' + libname , true);
	req.send(null);
}


function changebug(){
	document.getElementById('chgbug').style.cssText = 'display:inline;';
	document.getElementById('chgank').style.cssText = 'display:none;';
	document.bug.content_flag[1].checked = true;
	
}

function changeanketo(){
	document.getElementById('chgbug').style.cssText = 'display:none;';
	document.getElementById('chgank').style.cssText = 'display:inline;';
	document.bug.content_flag[0].checked = true;
}

function ankset(){ 
	document.getElementById('libnum').value =  sysUserCode ;
	if(document.getElementById('libname') != null){
		document.getElementById('libname').value =  libname ;
	}
}

function submitank(){

	ankset();
	
	var postData ="command=" + document.bug.command.value;
	postData +="&charset=UTF-8";
	postData +="&libnum="  + urlEncode(document.bug.libnum.value);
	postData +="&libname=" + urlEncode(document.bug.libname.value);
	postData +="&lang="    + document.bug.lang.value;
	postData +="&man="     + urlEncode(getRadioValue(document.bug.man));
	postData +="&age="     + urlEncode(getRadioValue(document.bug.age));
	postData +="&work="    + urlEncode(getRadioValue(document.bug.work));
	postData +="&useful="  + urlEncode(getRadioValue(document.bug.useful));
	postData +="&content_flag=" + getRadioValue(document.bug.content_flag);
	postData +="&purpose="      + urlEncode(document.bug.purpose.value);
	postData +="&bodytext="     + urlEncode(document.bug.bodytext.value);

	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();   
	req.onreadystatechange = function() {   
	switch (req.readyState) {   
		case 1: // Open   
		case 2: // Sent   
		case 3: // Receiving   
			break;   
		case 4: // Loaded   
			if(req.status == 200){
				document.getElementById('anks').style.cssText = 'display:none;';
				if(lang == ''){
					document.getElementById('thanskank').style.cssText = 'display:inline;';
				}
				else if(lang == 'en'){
					document.getElementById('thanskanken').style.cssText = 'display:inline;';
				}
			}
			return;
	    }   
	};

	req.open('POST', '/dc/anketo/submit.php', true);   
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');  
	req.send(postData);
	
}

function dispank(){
	document.getElementById('thanskank').style.cssText = 'display:none;';
	document.getElementById('thanskanken').style.cssText = 'display:none;';
	document.getElementById('anks').style.cssText = 'display:inline;';
}


function bbsset(){ 
	var req = window.XMLHttpRequest ? new XMLHttpRequest() : (function() {
		try      { return new ActiveXObject('Msxml2.XMLHTTP');    }
		catch(e) { return new ActiveXObject('Microsoft.XMLHTTP'); }
	})();

	req.onreadystatechange = function() {
		switch (req.readyState) {
			case 1: // Open
			case 2: // Sent
			case 3: // Receiving
				break;
			case 4: // Loaded
				if(req.status == 200){
					document.getElementById('bbs').innerHTML = req.responseText;
					return;
				}
	    }
	};
	req.open('GET', '/dc/user_forum/index.php?charset=UTF-8&header=no&title=' + urlEncode(libtitle) , true);
	req.send(null);
}


function ankButtonPush(){ 
	ankset();
	$('#questionnaire .tabs .tab-title li').siblings().removeClass('selected');
	$('#questionnaire .tabs .tab-title li').eq(1).addClass('selected');
	$('#questionnaire .tabs .tab-contents').hide().eq(1).show();
	return false;
}


function myLibSort(data){ 
	var sortcol = 0;  // 階層順
	if(document.getElementById("libsort").selectedIndex == 1){ // ライブラリ名順
		sortcol = 2;
	}
	else if(document.getElementById("libsort").selectedIndex == 2){ // 日付順
		sortcol = 4;
	}
	else if(document.getElementById("libsort").selectedIndex == 3){ // 実行回数順
		sortcol = 5;
	}
	var table1 = document.getElementById("myliblist");
	
	for (var i = table1.rows.length -1; i >= 2 ;i--) {  
	    table1.deleteRow(i);  
	}
	var order = 1;
	if(document.getElementById("libsortorder").checked == false){
		order = -1;
	}


	// カテゴリ選択
	var catename = document.getElementById("category").options[document.getElementById("category").selectedIndex].text;
	catename = catename.replace(/　/g, ""); 
	catename = catename.replace(/【/g, ""); 
	catename = catename.replace(/】/g, ""); 	


	var searchdata = new Array();
	if(catename !='全て'){
		for(var row = 0; row < data.length; row++){
			
			if(data[row][1].indexOf(catename ) != -1){
				searchdata.push(data[row]);
			}
		
		}
	}
	else{
		searchdata = data;
	}

	if(document.getElementById("mylibwarning") != null ){
		if( searchdata.length  == 0  ){    
			document.getElementById("mylibwarning").innerHTML = "このカテゴリには、私の自作式は登録されていません。";
			return;
		}
		else{
			document.getElementById("mylibwarning").innerHTML = "";
		}
	}

	var sortdata = sort2(searchdata,sortcol,order);

	
		
	//"6",
	//"練習/練習用",
	//"練習",
	//"<span class='link-mode-koji'><a href='/has10/SpecExec.cgi?path=09900000%2e%8e%84%82%cc%8e%a9%8d%ec%8e%ae%81i%97%fb%8fK%81j%2f05000000%2e%97%fb%8fK%97p%2f10000106%2e%97%fb%8fK%2fdefault%2exml'>練習</a></span>",
	//"2011/12/27",
	//"0",
	//"<a href='/dc/registauth.php?path=09900000%2e%8e%84%82%cc%8e%a9%8d%ec%8e%ae%81i%97%fb%8fK%81j%2f05000000%2e%97%fb%8fK%97p%2f10000106%2e%97%fb%8fK%2fdefault%2exml'><img src='/keisan/common/img/ico_editor.png' alt='' /></a>",
	//"<a style='cursor:pointer;'  onclick='deletelib(\"練習\", \"09900000.私の自作式（練習）/05000000.練習用/10000106.練習\", \"\")'><img src='/keisan/common/img/ico_delete.png' border=0></a>",
	//"説明"	
	
	
	for(var row = 0; row < sortdata.length; row++){
		var rows = table1.insertRow(-1);
		var colnum = 0;
//		for(var col = 1; col < 8; col++){
//			var cell = rows.insertCell(colnum);
//			if(colnum == 0 || colnum == 2 | colnum == 3){
//				cell.setAttribute('noWrap', true);
//			}
//			colnum++;
//			var datacol = col; 
//			if(col >= 2){ datacol++;}
//			cell.innerHTML = sortdata[row][datacol];
//		}

		rows.insertCell(0).innerHTML = sortdata[row][1];
		rows.insertCell(1).innerHTML = sortdata[row][3];
		rows.insertCell(2).innerHTML = sortdata[row][6];
		rows.insertCell(3).innerHTML = sortdata[row][7];
		rows.insertCell(4).innerHTML = sortdata[row][8];
		rows.insertCell(5).innerHTML = sortdata[row][5];
		rows.insertCell(6).innerHTML = sortdata[row][4];
	}
}

//---------------------------
//  二次元配列のソート
//  order:1=昇順、-1=降順
//---------------------------
function sort2(data,sortcol,order){
    data.sort(function(a,b){
    	if(sortcol == 0 || sortcol == 5) {   // 実行回数	
			return((a[sortcol] - b[sortcol])*order);
			//return(a[sortcol] - b[sortcol]);
    	}
    	else{
    		if(order == 1){
    			if( new String(a[sortcol]) > new String(b[sortcol]) ){
					return 1;
    			}
    			else{
					return -1;
    			}
    		}
    		else{
				if( new String(a[sortcol]) < new String(b[sortcol]) ){
					return 1;
				}
				else{
					return -1;
				}
    		}
    	}
    
    });
    return(data);
}

function newlibedit(){
	// カテゴリ選択
	var catename = document.getElementById("category").options[document.getElementById("category").selectedIndex].text;
	if(catename.indexOf("　")  == -1 ){
		alert("新規登録は、カテゴリから【・・・】のあるカテゴリは選択できません。");
		return false;
	}
	var url = "/has10/CaluRegist.cgi?pc=1&path="+  document.getElementById("category").options[document.getElementById("category").selectedIndex].value;
	window.location.assign(url) 
	return false;
}

function serLibcategory(data, path){

	for(var i = 0; i < document.getElementById("category").length; i++){
		if(document.getElementById("category").options[i].value == path){
			document.getElementById("category").selectedIndex = i;
			myLibSort(data);
		}
	}

}




