//javascript [selectable view]
function openvoices() {
	var nowPageId = findBodyId();
	if(nowPageId != "employment"){
		//alert("Not emp. page id is " + nowPageId);
		location.href = "employment.shtml#open";
	} else {
		//alert("yes, page id is " + nowPageId);
		openvoice();
		show('voice_sales','voice0');
	}
}
function findBodyId(){
	var oBody = document.getElementsByTagName("body");
	var nowPageId = oBody[0].id;
	return nowPageId;
}
function openvoice() {
	//alert("now openvoice");
	var element = document.getElementById("voices");
	element.style.display = 'block';
}
function closevoice() {
	//alert("closevoice");
	var element = document.getElementById("voices");
	element.style.display = 'none';
}
function subMenuChange(obj){
	//alert("subMenuChange " + obj);
	var submenu = document.getElementById("submenu");
	var links = submenu.getElementsByTagName("a");
	for (i=0; i<links.length; i++) {
		//links[i].setAttribute("class", "nothere"); 
		var eles = links[i];
		eles.getAttribute("className");
		eles.style.cssText = "";
	}
	setAtt(obj);
	var nowPageId = findBodyId();
	if(nowPageId == "employment"){
		if(obj.indexOf("voice") > -1) {
			setAtt("openvoice");
		} else {
			closevoice();
		}
	}
}
function setAtt(obj) {
	var element = document.getElementById(obj);
	if(element){
		element.getAttribute("className");
		element.style.cssText = "background-color: #ededed; color: #000;";
	}
}

function show(id,obj) {
	//alert("表示するdivは"+id+"	選択表示にするのは"+obj);
	var divGazo = document.getElementById("main");
	var divs = divGazo.getElementsByTagName("div");
	if (! document.getElementById(id)){
		blockDiv = divs[0];
	} else {
		blockDiv = document.getElementById(id);
	}
	for (i=0; i<divs.length; i++) {
		divs[i].style.display = 'none';
	}
	blockDiv.style.display = 'block';
	subMenuChange(obj);
	//backToTop();
	backToTop2();
}

function backToTop2() {
  var x1 = x2 = x3 = 0;
  var y1 = y2 = y3 = 0;
  if (document.documentElement) {
      x1 = document.documentElement.scrollLeft || 0;
      y1 = document.documentElement.scrollTop || 0;
  }
  if (document.body) {
      x2 = document.body.scrollLeft || 0;
      y2 = document.body.scrollTop || 0;
  }
  x3 = window.scrollX || 0;
  y3 = window.scrollY || 0;
  var x = Math.max(x1, Math.max(x2, x3));
  var y = Math.max(y1, Math.max(y2, y3));
  window.scrollTo(Math.floor(x / 10), Math.floor(y / 100));
  if (x > 1 || y > 1) {
      window.setTimeout("backToTop2()", 200);
  } else {
  	window.scrollTo(0, 0);
  }
  /*window.scrollTo(Math.floor(x / 10), Math.floor(y / 2));
  window.scrollTo(Math.floor(x / 5), Math.floor(y / 2));
  window.scrollTo(x, y);
  if (x > 0 || y > 0) {
      window.setTimeout("backToTop2()", 100);
  }
  */
}

function showDef(id) {
	//alert("showDef");
	var divGazo = document.getElementById("main");
	var divs = divGazo.getElementsByTagName("div");
	for (i=0; i<divs.length; i++) {
		divs[i].style.display = 'none';
	}
	divs[0].style.display = 'block';
	//bodyタグのidから現在のページを特定
	var nowPageId = findBodyId();
	//alert(nowPageId);
	if (nowPageId.indexOf("maleb") > -1){
		//subMenuChange("sub0");
		//alert(nowPageId+" のページtest中");
	} else {
		subMenuChange("sub0");
		//alert("test中");
	}
}

function dropshow(linkid,jump,subMenuId) {
	//bodyタグのidから現在のページを特定
	var nowPageId = findBodyId();
	//var oBody = document.getElementsByTagName("body");
	//var nowPageId = oBody[0].id;
	var wantToGo = jump;
	//alert("want to go  " + wantToGo);
	//linkidを使ってジャンプ先が現在のページ内かどうか判定
	var samePage = linkid.indexOf(nowPageId);
	//alert("samePage  " + samePage);
	var here = "sub" + subMenuId;
	if (subMenuId == "openvoice"){here = "voice_sales";}
	//現在のページ内であればsamePage>-1。show(jump2,imhere)
	if (samePage > -1){
		//show(jump2,here);
		var wantStr = jump.indexOf("#") + 1;
		var wantToShow = jump.substring(wantStr);
		//alert("wantToShow  " + wantToShow);
		show(wantToShow,here);
	} else {
	//他のページであればsamePageは-1。location.href = jump1+ jump2
		location.href = wantToGo;
	}
}
function hideHr(divGazo) {
	hrs = divGazo.getElementsByTagName("hr");
	for ( i = 0 ; i < hrs.length ; ++i){
		hrs[i].style.border = '1';
		hrs[i].style.height = '0';
		hrs[i].style.display = 'none';
	}
	hrender();
}
function hrender() {
	hrsb = document.getElementById("contents_end");
	//alert(hrsb.id);
	hrsb.style.display = 'block';
	hrsb.style.border = '0';
	hrsb.style.height = '0';
	hrsb.style.visibility = 'hidden';
}
function chk() {
	//alert("chk");
	divGazo = document.getElementById("main");
	hideHr(divGazo);
	divs = divGazo.getElementsByTagName("div");
	//alert("main 要素には " + divs.length + " 個の <div> 要素があり、1つ目のidは"+divs[0].id+"です");
	srch = location.hash;
	if(srch !=""){
		if (srch == "#header") {
			backToTop2();
		}else if (srch == "#open") {
			srch = "voice_sales";
			var sub = "voice0";
			//alert("subは" + sub);
			show(srch,sub);
			//return;
		}else if (srch.indexOf("#male_") > -1) {
			srch = srch.substring(1);
			switch (srch) {
			case "male_t":
				//alert("male_t");
				show("male_t","sub0");
				break;
			case "male_m":
				//alert("male_m");
				show("male_m","sub1");
				break;
			case "male_q":
				//alert("male_q");
				show("male_q","sub2");
				break;
			default:
				//alert("male_top");
				show("male_top","male");
				break;
			}
		}else{
			//alert("location.hash is " + srch);
			srch = srch.substring(1);
			//show(srch);
			var DivIdnum = 0;
			for (i = 0 ; i<divs.length;++i){
				if (divs[i].id == srch){
					DivIdnum = i;
					break;
				}
			}
			var sub = "sub" + DivIdnum;
			//alert("subは" + sub);
			show(srch,sub);
		}
	} else {
		showDef();
	}
}
function resetcheck(){
	if(window.confirm('入力内容をリセットしてもよろしいですか？')){ // 確認ダイアログを表示
		return true; // 「OK」時はリセットを実行
	}
	else{ // 「キャンセル」時の処理
		window.alert('キャンセルされました'); // 警告ダイアログを表示
		return false; // リセットを中止
	}
}
