var encoding = 'utf8';
document.write("<div id=\"journal\" style=\"width:380px; height:550px;\">");
document.write("<p>■ カテゴリーから探す</p>");
document.write("<div style=\"padding-left:50px;\"><select id=\"categories\" onchange=\"categoryChange(this.options[this.selectedIndex].value)\" style=\"width:300px; height:24px; font-size:12pt; border:1px solid CornflowerBlue; background-color:Azure; font-family:Tahoma,Sans;\"><option value=\"0\">全カテゴリー</option>");
document.write("<option value=\"1\">アレルギー性疾患</option>");
document.write("<option value=\"4\">麻酔学</option>");
document.write("<option value=\"8\">心臓・心血管系</option>");
document.write("<option value=\"9\">細胞生物学</option>");
document.write("<option value=\"10\">臨床神経学</option>");
document.write("<option value=\"11\">重篤疾患医学</option>");
document.write("<option value=\"12\">歯科・口腔外科学</option>");
document.write("<option value=\"13\">皮膚医学</option>");
document.write("<option value=\"14\">救急医学</option>");
document.write("<option value=\"15\">分泌・代謝系</option>");
document.write("<option value=\"16\">消化器・腎臓系医学</option>");
document.write("<option value=\"17\">遺伝子学</option>");
document.write("<option value=\"18\">老年病医学</option>");
document.write("<option value=\"20\">血液学</option>");
document.write("<option value=\"21\">免疫学</option>");
document.write("<option value=\"22\">感染症</option>");
document.write("<option value=\"27\">一般・内科</option>");
document.write("<option value=\"30\">微生物学</option>");
document.write("<option value=\"31\">産婦人科</option>");
document.write("<option value=\"32\">癌</option>");
document.write("<option value=\"33\">眼科</option>");
document.write("<option value=\"34\">整形外科学</option>");
document.write("<option value=\"35\">耳鼻咽喉科</option>");
document.write("<option value=\"37\">病理学</option>");
document.write("<option value=\"38\">小児科</option>");
document.write("<option value=\"39\">末梢血管疾患</option>");
document.write("<option value=\"41\">生理学</option>");
document.write("<option value=\"42\">精神医学</option>");
document.write("<option value=\"46\">放射線医学・核医学</option>");
document.write("<option value=\"47\">再生生物学</option>");
document.write("<option value=\"48\">呼吸器系</option>");
document.write("<option value=\"49\">リウマチ学</option>");
document.write("<option value=\"50\">外科学</option>");
document.write("<option value=\"51\">移植医学</option>");
document.write("<option value=\"53\">泌尿器・腎臓学</option>");
document.write("<option value=\"54\">ウイルス学</option>");
document.write("</select></div>");
document.write("<p>■ 雑誌名から探す</p>");
document.write("<div style=\"text-align:right;\">（半角英数のみ/アンド検索はスペース又はカンマ区切り）</div>");
document.write("<div style=\"padding-left:50px;\"><input id=\"journalkey\" style=\"width:200px; height:21px; background-color:Azure; border:1px solid CornflowerBlue;\" type=\"text\">&nbsp;<button onclick=\"return searchJournal()\" style=\"cursor:pointer; width:80px; height:24px; border:1px solid CornflowerBlue; background-color:Azure; font-size:10pt;\">検 索</button></div>");
document.write("<p>■ 雑誌リスト（引用が多い順に20件を表示）</p>");
document.write("<div style=\"text-align:right;\">（<span style=\"color:blue;\">青色</span>で強調している雑誌は投稿規定もご覧になれます）</div>");
document.write("<div style=\"padding-left:50px;\"><select id=\"journals\" style=\"cursor:pointer; width:300px; height:300px; font-size:10pt; border:1px solid CornflowerBlue; font-family:Tahoma,Sans;\" size=\"10\" onchange=\"selectJournal(this.options[this.selectedIndex].firstChild.nodeValue, this.options[this.selectedIndex].value)\">");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"4897\">NEW ENGLAND JOURNAL OF MEDICINE</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"1176\">CELL</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"4333\">LANCET</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"1321\">CIRCULATION</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"3684\">JOURNAL OF IMMUNOLOGY</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"1145\">CANCER RESEARCH</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"974\">BLOOD</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"4272\">JAMA-JOURNAL OF THE AMERICAN MEDICAL ASSOCIATION</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"4244\">JOURNAL OF VIROLOGY</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"3390\">JOURNAL OF CLINICAL ONCOLOGY</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"1917\">EMBO JOURNAL</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"4670\">MOLECULAR AND CELLULAR BIOLOGY</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"3334\">JOURNAL OF CELL BIOLOGY</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"3556\">JOURNAL OF EXPERIMENTAL MEDICINE</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"563\">APPLIED AND ENVIRONMENTAL MICROBIOLOGY</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"4859\">NEUROLOGY</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"1068\">BRITISH MEDICAL JOURNAL</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"3273\">JOURNAL OF BACTERIOLOGY</option>");
document.write("<option style=\"background-color:Honeydew; color:black;\" value=\"3379\">JOURNAL OF CLINICAL ENDOCRINOLOGY &amp; METABOLISM</option>");
document.write("<option style=\"background-color:LemonChiffon; color:black;\" value=\"4762\">NATURE GENETICS</option>");
document.write("</select></div>");
document.write("</div>");

var httpObj;

var defaultValues = new Array();
defaultValues['_coverletter'] = "カバーレター";
defaultValues['_title'] = "タイトルページ > Title";
defaultValues['_runninghead'] = "論文 > タイトルページ > Running head";
defaultValues['_keyword'] = "論文 > タイトルページ > Key word";
defaultValues['_titlenote'] = "論文 > タイトルページ > その他・特記事項";
defaultValues['_abwordcount'] = "論文 > アブストラクト > word数";
defaultValues['_abchapter'] = "論文 > アブストラクト > 章立て";
defaultValues['_abnote'] = "論文 > アブストラクト > その他・特記事項";
defaultValues['_bodywordcount'] = "論文 > 本文 > word数";
defaultValues['_bodychapter'] = "論文 > 本文 > 章立て";
defaultValues['_bodynote'] = "論文 > 本文 > その他・特記事項";
defaultValues['_thanks'] = "論文 > 謝辞";
defaultValues['_cited'] = "論文 > 参考文献";
defaultValues['_figurelegends'] = "論文 > 図の説明（Figure legends）";
defaultValues['_tablecount'] = "表 > 数";
defaultValues['_tablenote'] = "表 > その他・特記事項";
defaultValues['_figurecount'] = "図 > 数";
defaultValues['_figurenote'] = "図 > その他・特記事項";
defaultValues['_note'] = "特記事項";
defaultValues['_date'] = "情報提供日";

function createXMLHttpRequest() {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        return new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e2) {
        return null;
      }
    }
  } else {
    return null;
  }
}

function getResult() {
	if(httpObj.readyState == 4 && httpObj.status == 200) {
		var results = httpObj.responseXML.getElementsByTagName("journals");
 
		if(results[0].attributes[0].value == "1") {
			var journals = httpObj.responseXML.getElementsByTagName("journal");
			for(var i = 0; i < journals.length; ++i) {
				var op = document.createElement("option");
				var bgcolor = "LemonChiffon";
				if(i%2 == 0) bgcolor = "Honeydew";
				op.style.backgroundColor = bgcolor;
				op.value = journals[i].attributes[0].value;
				op.style.color = journals[i].attributes[1].value;
				op.appendChild(document.createTextNode(journals[i].firstChild.nodeValue));
				document.getElementById('journals').appendChild(op);
			}
		}else {
			var op = document.createElement("option");
			op.value = 0;
			op.appendChild(document.createTextNode("該当なし"));
			document.getElementById('journals').appendChild(op);
		}
	}
}

function categoryChange(categoryID) {
	while(document.getElementById('journals').childNodes.length > 0) {
		document.getElementById('journals').removeChild(document.getElementById('journals').lastChild);
	}
	var bodyParam = new Array();
	bodyParam["CID"] = categoryID;
	bodyParam["ENCODING"] = encoding;

	var bodyArray = new Array();
	for(var key in bodyParam) {
		bodyArray.push(key + "=" + encodeURIComponent(bodyParam[key]));
	}
	var body = bodyArray.join("&");

	httpObj = null;
	httpObj = createXMLHttpRequest();
	if(httpObj) {
		httpObj.onreadystatechange = getResult;
		httpObj.open("POST","journal/search.php",true);
		httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		httpObj.send(body);

		document.getElementById('journalkey').value = "";
	}else {
		alert("ブラウザが対応していません");
	}
}

function searchJournal() {
	if(document.getElementById('journalkey').value == "") {
		alert("検索キーが入力されていません");
		document.getElementById("journalkey").focus();
		return false;
	}else {
		var keyword = document.getElementById("journalkey").value;
		keyword = keyword.replace("　",",");
		keyword = keyword.replace(/\s/g,",");

		cObj = new RegExp("^,|,$");
		while(keyword.match(cObj)) {
			keyword = keyword.replace(cObj,"");
		}
		if(keyword == "") {
			alert("検索キーが入力されていません");
			document.getElementById("journalkey").focus();
			return false;
		}
		eObj = new RegExp("[^0-9a-zA-Z,]");
		if(keyword.match(eObj)) {
			alert("検索に使用できるのは半角英数文字のみです");
			document.getElementById("journalkey").focus();
			return false;
		}

		while(document.getElementById('journals').childNodes.length > 0) {
			document.getElementById('journals').removeChild(document.getElementById('journals').lastChild);
		}
		var bodyParam = new Array();
		bodyParam["SEARCH"] = keyword;
		bodyParam["ENCODING"] = encoding;

		var bodyArray = new Array();
		for(var key in bodyParam) {
			bodyArray.push(key + "=" + encodeURIComponent(bodyParam[key]));
		}
		var body = bodyArray.join("&");		

		httpObj = null;
		httpObj = createXMLHttpRequest();
		if(httpObj) {
			httpObj.onreadystatechange = getResult;
			httpObj.open("POST","journal/search.php",true);
			httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			httpObj.send(body);
		}else {
			alert("ブラウザが対応していません");
		}
		document.getElementById('categories').value= 0;
		return true;
	}
}

function selectJournal(selectedJournal,selectedJournalID) {
	document.getElementById('selectedJournal').value = selectedJournal;

	document.getElementById('searchResults').style.position = "relative";
	document.getElementById('searchLabel').style.position = "relative";
	document.getElementById('searchResults').style.top = "0px";
	document.getElementById('searchResults').style.left = "0px";
	document.getElementById('searchLabel').style.left = "0px";
	document.getElementById('reg_form').style.display = "none";

	searchControl.execute(selectedJournal);
	loadData(selectedJournalID);
}

function showRegulationInfo(){
	if(document.getElementById('searchResults').style.left == "0px") {
		document.getElementById('searchResults').style.position = "absolute";
		document.getElementById('searchLabel').style.position = "absolute";
		document.getElementById('searchResults').style.top = "35px";
		moveLeft(450);
	}
}

function moveLeft(moveWidth){
	moveWidth -= 70;
	left = parseInt(document.getElementById('searchResults').style.left.replace("px",""));
	left += 70;
	document.getElementById('searchResults').style.left = left.toString()+"px";
	document.getElementById('searchLabel').style.left = left.toString()+"px";
	if(moveWidth > 70) {
		setTimeout("moveLeft("+moveWidth+")",50);
		document.getElementById('reg_form').style.display = "block";
	}
}

function getData() {
	if(httpObj.readyState == 4 && httpObj.status == 200) {

		while(document.getElementById('reg_form').childNodes.length > 0) {
			document.getElementById('reg_form').removeChild(document.getElementById('reg_form').lastChild);
		}

		var results = httpObj.responseXML.getElementsByTagName("journal");
 
		if(results[0].attributes[0].value == "new") {
			document.getElementById('regbutton').style.display = "none";
		}else if(results[0].attributes[0].value == "hidden") {
			document.getElementById('regbutton').style.display = "none";
		}else if(results[0].attributes[0].value == "exist") {
			document.getElementById('regbutton').style.display = "block";

			var elements = httpObj.responseXML.getElementsByTagName("element");
			for(var i = 0; i < elements.length; ++i) {
				//document.getElementById(elements[i].attributes[0].value).value = elements[i].firstChild.nodeValue;
				var subsection = document.createElement("div");
				subsection.className = "subsection";

				var h3 = document.createElement("h3");
				h3.appendChild(document.createTextNode(defaultValues[elements[i].attributes[0].value]));

				subsection.appendChild(h3);
				document.getElementById('reg_form').appendChild(subsection);

				var p = document.createElement("p");

				var blocks = elements[i].firstChild.nodeValue.split("\n");
				for(var j = 0; j < blocks.length; ++j) {
					var div =  document.createElement("div");
					div.appendChild(document.createTextNode(blocks[j]));
					p.appendChild(div);
				}
				document.getElementById('reg_form').appendChild(p);
			}
		}else {
			alert("データの読み込みに失敗しました");
		}
	}
}

function loadData(journalID){
	var bodyParam = new Array();
	bodyParam["journal_id"] = journalID;

	var bodyArray = new Array();
	for(var key in bodyParam) {
		bodyArray.push(key + "=" + encodeURIComponent(bodyParam[key]));
	}
	var body = bodyArray.join("&");

	httpObj = null;
	httpObj = createXMLHttpRequest();
	if(httpObj) {
		httpObj.onreadystatechange = getData;
		httpObj.open("POST","journal/get_regulation.php",true);
		httpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		httpObj.send(body);
	}else {
		alert("ブラウザが対応していません");
	}
}

document.getElementById('categories').value= 0;
document.getElementById('journals').selectedIndex= 0;
loadData(4897);