﻿function changeImg( id , imgName){
	document.getElementById(id).src=imgName;
}

function getXmlHttpRequest() {

	var xmlhttp;

        try{
                  xmlhttp = new XMLHttpRequest();
        } catch(e)  {
                  try {
                             xmlhttp = new ActiveXObject("Msxm12.XMLHTTP");
                  } catch(e) {
                             try {
                                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                             } catch (e) {
                                         xmlhttp = false;
                             }
                  }
         }
	return xmlhttp;
}

function loadTop() {
	
	function drawTop(){
		if( xmlhttp.readyState == 4 ){
			if(xmlhttp.status == 200 ){
				target.innerHTML = xmlhttp.responseText;
			} else {
				target.innerHTML = 'fail to get data';
			}
		} else {
			target.innerHTML = 'now loading';
		}
	}

	var target = document.getElementById('commonTop');
	var xmlhttp = getXmlHttpRequest();
	
	xmlhttp.open("GET",'../common/top.html',true);
	xmlhttp.onreadystatechange = drawTop;
	document.getElementById('commonTop').innerHTML =  'データ取得中';
	xmlhttp.send(null);
}

function writeTop(){

       var header = '<div id="mainFrame"> <div id="leftMargin">&nbsp;</div> <div id="contents">'

	header = header + '<div id="topImage"><img src="../../image/common/common_top_txt01.jpg" alt="" usemap="#topMap" /></div> <div id="linkBar"> <div class="eachLink"> <a href= "../../html/top/top.html"> <img id="eachLinkImg1" src="../../image/common/common_top_link_menu01.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg1\',\'../../image/common/common_top_link_menu01s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg1\',\'../../image/common/common_top_link_menu01.jpg\');" /> </a> </div> <div class="eachLink"> <a href= "../../html/intro/intro.html?who=1"> <img id="eachLinkImg2" src="../../image/common/common_top_link_menu02.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg2\',\'../../image/common/common_top_link_menu02s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg2\',\'../../image/common/common_top_link_menu02.jpg\');" /> </a> </div> <div class="eachLink"> <a href= "../intro/intro.html?who=2"> <img id="eachLinkImg3" src="../../image/common/common_top_link_menu03.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg3\',\'../../image/common/common_top_link_menu03s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg3\',\'../../image/common/common_top_link_menu03.jpg\');" /> </a> </div> <div class="eachLink"> <a href="../../html/interview/underconstruction.html"> <img id="eachLinkImg4" src="../../image/common/common_top_link_menu04.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg4\',\'../../image/common/common_top_link_menu04s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg4\',\'../../image/common/common_top_link_menu04.jpg\');" /> </a> </div> <div class="eachLink"> <a href ="../../html/question/question.html"> <img id="eachLinkImg5" src="../../image/common/common_top_link_menu05.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg5\',\'../../image/common/common_top_link_menu05s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg5\',\'../../image/common/common_top_link_menu05.jpg\');" /> </a> </div> <div class="eachLink"> <a href="../../../data.html"> <img id="eachLinkImg6" src="../../image/common/common_top_link_menu06.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg6\',\'../../image/common/common_top_link_menu06s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg6\',\'../../image/common/common_top_link_menu06.jpg\');" /> </a> </div> <div class="eachLink"> <a href ="../../../recruit_new.html"> <img id="eachLinkImg7" src="../../image/common/common_top_link_menu07.jpg" alt="" onmouseover="javascript:changeImg(\'eachLinkImg7\',\'../../image/common/common_top_link_menu07s.jpg\');" onmouseout="javascript:changeImg(\'eachLinkImg7\',\'../../image/common/common_top_link_menu07.jpg\');" /> </a></div><div class="clearFooter"></div></div><div class="marginTen">&nbsp;</div>';

	header = header + '<map id="" name="topMap"><area shape="rect" coords="5,66,155,95" href="../../../../index.html" alt="" /></map>';

	header = header + '<div id="mainWrap">';

	document.writeln(header);

}

function drawIntro(who){
	var name = who.split('_');
	
	var each1string = '<a href ="../../html/intro/intro.html?who=' + name[0] + '_01">';
	each1string = each1string + '<img src="../../image/intro/intro' + name[0] + '_link_pic01.jpg" /></a>';
	document.getElementById('each1').innerHTML = each1string;
	
	var each2string = '<a href ="../../html/intro/intro.html?who=' + name[0] + '_02">';
	each2string = each2string + '<img src="../../image/intro/intro' + name[0] + '_link_pic02.jpg" /></a>';
	document.getElementById('each2').innerHTML = each2string;

	var each3string = '<a href ="../../html/intro/intro.html?who=' + name[0] + '_03">';
	each3string = each3string + '<img src="../../image/intro/intro' + name[0] + '_link_pic03.jpg" /></a>';
	document.getElementById('each3').innerHTML = each3string;

	var photo = '<img src="../../image/intro/main' + who + '.jpg"/>'
	document.getElementById('photo').innerHTML = photo;
	var intro = '<img src="../../image/intro/intro' + name[0] + '_main_jikosyo_txt' + name[1] + '.gif"/>';
	document.getElementById('intro').innerHTML = intro;

	for( var i = 1; i <= 6; i++ ){
		document.getElementById('theme' + i).innerHTML = '<img src="../../image/intro/intro' + name[0] + '_main_q' + i + '.jpg" alt="img' + i + '" />';
	}
	if( name[0] == '1'){
		document.getElementById('theme7box').innerHTML = '<div class="theme" id="theme7"></div> <div class="marginK"></div> <div class="writing"> </div> <div class="marginK"></div>';
		document.getElementById('theme' + i).innerHTML = '<img src="../../image/intro/intro' + name[0] + '_main_q7.jpg"/>';
	} else {
		document.getElementById('theme7box').style.height='0px';
	}

/*
	if( name[0] == '2' ){
		var box = document.getElementById('lastLink');
		box.style.textAlign='right';
		box.style.paddingTop = '2px';
		box.innerHTML = '<a href="../../../newface2009/index.html">私たちが作成した、2009年度新卒採用ページはこちらです。</a>';
	}
*/
	
	var xmlhttp = getXmlHttpRequest();

	var file = ( name[0] == 1 ) ? 'writings1.xml' : 'writings2.xml';
	xmlhttp.open("GET",'../../xml/' + file ,true);
	xmlhttp.onreadystatechange = getWritings;
	xmlhttp.send(null);

	function getWritings(){
		if( xmlhttp.readyState == 4 ){
			if(xmlhttp.status == 200 ){
				var contents = xmlhttp.responseXML.getElementsByTagName('contents');
				var p = contents[0].getElementsByTagName('p' + who );
				eval( 'var arr = (' + p[0].firstChild.nodeValue + ')' );

				var divs =document.getElementById('rightMain').getElementsByTagName('div');
				var count = 0;
				var isIE = (navigator.appName == 'Microsoft Internet Explorer');

				var person_img = new Object();
				person_img['f2_01'] = 'src="../../image/intro/f2_01.jpg" width="120px" height="158px" align="right" alt="image"' ;
				person_img['s2_01'] = 'src="../../image/intro/s2_01.jpg" width="200px" height="127px" align="left" alt="image"';
				person_img['f2_02'] = 'src="../../image/intro/f2_02.jpg" width="190px" height="134px" align="right" alt="image"';
				person_img['s2_02'] = 'src="../../image/intro/s2_02.jpg" width="130px" height="167px" align="right" alt="image"';
				person_img['f2_03'] = 'src="../../image/intro/f2_03.jpg" width="180px" height="143px" align="right" alt="image"';
				person_img['s2_03'] = 'src="../../image/intro/s2_03.jpg" width="128px" height="167px" align="right" alt="image"';
				person_img['f1_01'] = 'src="../../image/intro/f1_01.jpg" width="150px" height="124px" align="right" alt="image"' ;
				person_img['s1_01'] = 'src="../../image/intro/s1_01.jpg" width="120px" height="136px" align="right" alt="image"';
				person_img['f1_02'] = 'src="../../image/intro/f1_02.jpg" width="128px" height="150px" align="left" alt="image"';
				person_img['s1_02'] = 'src="../../image/intro/s1_02.jpg" width="160px" height="147px" align="right" alt="image"';
				person_img['f1_03'] = 'src="../../image/intro/f1_03.jpg" width="195px" height="145px" align="right" alt="image"';
				person_img['s1_03'] = 'src="../../image/intro/s1_03.jpg" width="190px" height="126px" align="right" alt="image"';

				for ( var i = 0; i < divs.length; i++ ){
					var att = (isIE) ? divs[i].getAttribute('className') : divs[i].getAttribute('class');
					if( att == 'writing' ){
						if( name[0] == '2' && count == 4 ){
							//schedule table
							var schedule = arr[count];
							var table = '<table id="schedule">';
							for( var j = 0; j < schedule.length; j++ ){
								var row = schedule[j].split('|');
								table = table + '<tr><td class="cell1">' + row[0] + '</td><td class="cell2">' + row[1] + '</td></tr>';
							}
							table = table + '</tr></table>';
							divs[i].innerHTML = table;
						} else if ( name[0] == '2' &&  count == 0 ){
							var img = '<img id="imageA"' + person_img['f' + who] +  '/>' + arr[count]  + '<div class="clearFooter"></div>';
							divs[i].innerHTML = img;
						} else if ( name[0] == '2' &&  count == 3 ){
							var img = '<img id="imageB"' + person_img['s' + who] + '/>' + arr[count]  + '<div class="clearFooter"></div>';
							divs[i].innerHTML = img;
						} else if ( name[0] == '1' &&  count == 1 ){
							var img = '<img id="imageA"' + person_img['f' + who] +  '/>' + arr[count]  + '<div class="clearFooter"></div>';
							divs[i].innerHTML = img;
						} else if ( name[0] == '1' &&  count == 4 ){
							var img = '<img id="imageB"' + person_img['s' + who] + '/>' + arr[count]  + '<div class="clearFooter"></div>';
							divs[i].innerHTML = img;
						} else {
							divs[i].innerHTML = arr[count];
						}
						count++;
					}
				}
			}
		}
	}	
}


