addLoadEvent(function(){
	tinyScrolling.init();
	fontsizeChg.init();
	setSearchBox();
	window.focus();
	
});

addUnLoadEvent(function(){
});


window.onresize = function(){
	adjustmentSiteWidth();
}


/*
	IE bg flicker problem fix
*****************************************************/

	try {
	document.execCommand("BackgroundImageCache",false,true);
	}catch(e){}
	
	
/*
	browserDetect
*****************************************************/

	var browserDetect = {
		isSafari : (navigator.userAgent.indexOf("Safari") != -1)? true : false,
		isFF : (navigator.userAgent.indexOf("Firefox") != -1)? true : false,
		isIE : (navigator.userAgent.indexOf("MSIE") != -1)? true : false,
		isIE4 : (navigator.userAgent.indexOf("MSIE 4") != -1)? true : false,
		isIE5 : (navigator.userAgent.indexOf("MSIE 5") != -1)? true : false,
		isIE6 : (navigator.userAgent.indexOf("MSIE 6") != -1)? true : false,
		isMacIE : (document.all && !window.clipboardData)? true : false,
		isNN4 : (document.layers)? true : false,
		isNN6 : (navigator.userAgent.indexOf("Netscape/6") != -1)? true : false,
		isNN7 : (navigator.userAgent.indexOf("Netscape/7") != -1)? true : false
	}


/* Loding other JS files
*******************************************/
/*load_js = ["scroll.js","styleswitcher.js"];
var thisScript=(function (e){return (e.nodeName.toLowerCase()=='script')? e : arguments.callee(e.lastChild)})(document);
var jspath= thisScript.src.split("/");
jspath.pop();
if(load_js){
	document.open();
	for(var i=0;i<load_js.length;i++) document.write('<script type="text/javascript" src="'+ jspath.join("/")+"/"+load_js[i]+'"><\/script>')
	document.close();
}*/


jsFiles = [
	"scroll.js",
	"styleswitcher.js"
];
if(jsFiles){
var thisScript=(function (e){return (e.nodeName.toLowerCase()=='script')? e : arguments.callee(e.lastChild)})(document);
var jsPath= thisScript.src.replace(/^(.+\/)[^/]*$/,"$1");
	document.open();
	for(var i=0;i<jsFiles.length;i++) document.write('<script type="text/javascript" src="'+ jsPath + jsFiles[i]+'"><\/script>')
	document.close();
}


/*
	onload event control
*****************************************************/

	function addLoadEvent(func) {
		if(document.addEventListener && navigator.userAgent.indexOf('Gecko/') != -1){
			document.addEventListener("DOMContentLoaded", function(){func()}, false);
		}
		else{
			var oldonload = window.onload;
			window.onload = function() {
				func();
				if(typeof oldonload == 'function') oldonload();
			}
		}
	}
	function addUnLoadEvent(func) {
		var oldonunload = window.onunload;
		window.onunload = function() {
			if(typeof window.onunload != 'function') oldonunload();
			func();
		}
	}


/*
	DOM Relation
*******************************************/

function $() {
	for (var i=0, elements=new Array(); i<arguments.length; i++){
		var element=arguments[i];
		element =
		(typeof(element)=="object") ? element :
		document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}
function getElementsByClass(searchClass,node,tag){
	if (node==null) node = document;
	if (tag == null) tag = '*';
	var els = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for(var i=0,x=0,Element= new Array(); i<els.length; i++){
		if (pattern.test(els[i].className)) Element[x++]=els[i];
	}
	return Element;
}
function getSpecificParent(obj,parentObj){//parentObj : class or tagname or id
	var pattern = new RegExp("(^|\\s)"+parentObj+"(\\s|$)");
	do{obj = obj.parentNode;}
	while(!pattern.test(obj.className) && obj.tagName!=parentObj.toUpperCase() && obj.tagName!="BODY" && obj.id!=parentObj)
	return obj;
}

/* Array Enhancing
*****************************************************
	Array.prototype.loadImg
*****************************************************/
Array.prototype.loadImg = function(){
	for(var i=0,preimg = [],len=this.length; i<len ; i++){
		preimg[i]=new Image();
		preimg[i].src = this[i];
	}
	return preimg;
}



/*****************************************************
	emptiness
*****************************************************/
function emptiness(){
}


function getinnerWinSize(){
	W=(!browserDetect.isIE)? window.innerWidth:(document.compatMode=="CSS1Compat")? document.documentElement.clientWidth:document.body.clientWidth;
	H=(!browserDetect.isIE)? window.innerHeight:(document.compatMode=="CSS1Compat")? document.documentElement.clientHeight:document.body.clientHeight;
	return [W, H];
}

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

function getDefStyle(obj){
	style = obj.currentStyle || document.defaultView.getComputedStyle(obj, '');
	return style;
}
function $E(){
	if(window.event) return window.event;
	var caller = arguments.callee.caller;
	while(caller){
		var obj = caller.arguments[0];
		if(obj && obj.constructor == MouseEvent) return obj;
		caller = caller.caller;
	}
	return null;
}


function getScrollTop(){
	return (document.compatMode == 'CSS1Compat')? document.documentElement.scrollTop : document.body.scrollTop;
}
function getScrollLeft(){
	return (document.compatMode == 'CSS1Compat')? document.documentElement.scrollLeft : document.body.scrollLeft;
}

function getPageX(){
	var nowX = (document.compatMode == 'CSS1Compat')? document.documentElement.scrollLeft : document.body.scrollLeft;
	return $E().clientX + nowX;
}
function getPageY(){
	var nowY = (document.compatMode == 'CSS1Compat')? document.documentElement.scrollTop : document.body.scrollTop;
	return $E().clientY + nowY;
}
function getWinInWidth(){
	return (window.innerWidth)? window.innerWidth : (document.compatMode == 'CSS1Compat')? document.documentElement.clientWidth : document.body.clientWidth;
}
function getWinInHeight(){
	return (window.innerHeight)? window.innerHeight : (document.compatMode == 'CSS1Compat')? document.documentElement.clientHeight : document.body.clientHeight;
}
function $XY(obj){
	var X = Y = 0;
	do{
		X += obj.offsetLeft;
		Y += obj.offsetTop;
		obj = obj.offsetParent;
	}while(obj.offsetParent);
	return [X, Y];
}


/*****************************************************
	subWin
*****************************************************/
function subWin() {
	var subWins = getElementsByClass("subWin",$("main"),"a");
	for (var i=0,len=subWins.length; i<len; i++) {
		subWins[i].onclick = function() {
			//window.open(this.href);
			openWin(this.href, this.target, 680, 680, "01010110");
			return false;
		}
	}
}

//window.onload = subWin;


function popSubWin(url,target) {
	openWin(url, target, 780, 600, "11001111");
}


/*
	IE6 Adjustment margin
*****************************************************/
if(browserDetect.isIE6 && $("main").getElementsByTagName("*")){
	if($("main").getElementsByTagName("*")[0].className=="heading-lv2") $("main").getElementsByTagName("*")[0].style.marginTop = "0";
}

if(browserDetect.isIE6 && $("contentsWrapper").getElementsByTagName("*")){
	if(
		$("contentsWrapper").getElementsByTagName("*")[0].className=="heading-lv3" 
		|| $("contentsWrapper").getElementsByTagName("*")[0].className=="headingLv03A01"
	) $("contentsWrapper").getElementsByTagName("*")[0].style.marginTop = "-14px";
}


function adjustmentSiteWidth(){
	if(!browserDetect.isIE6) return;
	var bodySize = document.body.clientWidth;
	document.getElementById("allContentsWrapper").style.width=
	(bodySize < 774)? "774px":
	(bodySize > 1000 )? "1000px":
	"auto";
}
adjustmentSiteWidth();


/*
	IE6,7 Adjustment Button Size
*****************************************************/
if(browserDetect.isIE && document.getElementById("searchBox-btn")){
	var btn = document.getElementById("searchBox-btn");
	btn.style.width = btn.offsetWidth/10+"em";
}



/* Popup Window
*******************************************/
appVer = navigator.appVersion;
uAgent = navigator.userAgent;
//OS
var mac = (navigator.appVersion.indexOf("Mac") != -1)? true : false;
var win = (navigator.appVersion.indexOf("Win") != -1)? true : false;
var nn = (uAgent.indexOf("Netscape") != -1)? true : false;
var nn4 = (document.layers)? true : false;
var nn6 = (uAgent.indexOf("Netscape6") != -1)? true : false;
var opera = (uAgent.indexOf("Opera") != -1)? true : false;
var opera6 = (uAgent.indexOf("Opera/6") != -1)? true : false;
var opera5 = (uAgent.indexOf("Opera/5") != -1)? true : false;
var icab = (uAgent.indexOf("iCab") != -1)? true : false;
var ie = (uAgent.indexOf("MSIE") != -1)? true : false;
var ie5 = (uAgent.indexOf("MSIE 5") != -1)? true : false;
var safari = (uAgent.indexOf("Safari") != -1)? true : false;


var gAgent = navigator.userAgent;
var gAppVer = navigator.appVersion;

var gVersion = null;


if (gAgent.indexOf('MSIE') != -1) {
	gVersion = gAgent.substring((gAgent.indexOf('MSIE') + 5), (gAgent.indexOf('MSIE') + 9));

} else if (gAgent.indexOf('MSIE') == -1) {
	gVersion = gAppVer.substring(0,4);
	if (gAgent.indexOf('Gecko') != -1) {
		if (gAgent.indexOf('Netscape') != -1) {
			gVersion = gAgent.substring((gAgent.indexOf('Netscape') + 9), (gAgent.indexOf('Netscape') + 12));
		}
	}
}

if (gVersion.indexOf(';') != -1) {
	gVersion = gVersion.substring(0, gVersion.indexOf(';'));
}
if (gVersion.indexOf(' ') != -1) {
	gVersion = gVersion.substring(0, gVersion.indexOf(' '));
}

if (!gNewWindow) {
	var gNewWindow = null;
}

function openWin(url, n, w, h, st){
	var width = parseInt(w);
	var height = parseInt(h);
	var toolbar;
	var location;
	var directories;
	var status;
	var menubar;
	var resizable;
	var scrollbars;
	var dependent;

	st.charAt(0) == '1'	?  toolbar = 'yes' 		: toolbar = 'no';
	st.charAt(1) == '1'	?  location = 'yes' 	: location = 'no';
	st.charAt(2) == '1'	?  directories = 'yes' 	: directories = 'no';
	st.charAt(3) == '1'	?  status = 'yes' 		: status = 'no';
	st.charAt(4) == '1'	?  menubar = 'yes' 		: menubar = 'no';
	st.charAt(5) == '1'	?  resizable = 'yes' 	: resizable = 'no';
	st.charAt(6) == '1'	?  scrollbars = 'yes' 	: scrollbars = 'no';
	st.charAt(7) == '1'	?  dependent = 'yes' 	: dependent = 'no';

	if (location == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 0;
			height += 0;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height += 15;

		// NN4(for Win)

		} else if (nn && gVersion >= 4) {
			width += 0;
			height += 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width += 0;
			height += 19;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width += 2;
			height += 6;

		// IE6(for Win)
		} else if (ie && gVersion >= 6) {
			width += 0;
			height -= 19;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height -= 19;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height -= 19;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += -2;
			height += 50;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}

	if (scrollbars == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 15;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width += 16;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 16;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height -= 14;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 16;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 16;
			height += 0;

		// other
		} else {
			width += 15;
			height += 3;
		}
	} else {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 1;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 0;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height += 2;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height += 0;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}


	if (status == 'yes') {
		// NN4 for Mac
		if (mac && nn && gVersion >= 4 && gVersion < 5) {
			width -= 15;
			height -= 15;

		// IE4 for Mac
		}else if(mac && ie && gVersion >= 4 && gVersion < 5){
			width -= 0;
			height += 16;

		}
	}


	if (status == 'no') {
		// NN4
		if (nn && gVersion >= 4 && gVersion < 5) {
			width -= 0;
			height -= 0;

		// NN5 over
		}else if (mac && nn) {
			width += 0;
			height += 80;

		// NN5 over
		}else if (win && nn) {
			width += 0;
			height += 20;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += 0;
			height += 20;

		}
	}


	var win_size = 'width=' + width + ',height=' + height;
	var win_attr = 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',dependent=' + dependent;

	var w = window.open(url, n, win_attr + ',' + win_size);
	w.focus();
	return false;
}





/*
	Open Window for Image
*****************************************************/

var ViewImgs = null;

function openWinImage(url, n, w, h, st,imgpass){
	
	var width = parseInt(w);
	var height = parseInt(h);
	var toolbar;
	var location;
	var directories;
	var status;
	var menubar;
	var resizable;
	var scrollbars;
	var dependent;

	st.charAt(0) == '1'	?  toolbar = 'yes' 		: toolbar = 'no';
	st.charAt(1) == '1'	?  location = 'yes' 	: location = 'no';
	st.charAt(2) == '1'	?  directories = 'yes' 	: directories = 'no';
	st.charAt(3) == '1'	?  status = 'yes' 		: status = 'no';
	st.charAt(4) == '1'	?  menubar = 'yes' 		: menubar = 'no';
	st.charAt(5) == '1'	?  resizable = 'yes' 	: resizable = 'no';
	st.charAt(6) == '1'	?  scrollbars = 'yes' 	: scrollbars = 'no';
	st.charAt(7) == '1'	?  dependent = 'yes' 	: dependent = 'no';

	if (location == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 0;
			height += 0;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height += 15;

		// NN4(for Win)

		} else if (nn && gVersion >= 4) {
			width += 0;
			height += 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width += 0;
			height += 19;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width += 2;
			height += 6;

		// IE6(for Win)
		} else if (ie && gVersion >= 6) {
			width += 0;
			height -= 19;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height -= 19;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height -= 19;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += -2;
			height += 50;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}

	if (scrollbars == 'yes') {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 15;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width += 15;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width += 16;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 16;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height -= 14;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 16;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 16;
			height += 0;

		// other
		} else {
			width += 15;
			height += 3;
		}
	} else {
		// NN5 over
		if (nn && gVersion >= 5) {
			width += 1;
			height += 1;

		// NN4 for Mac
		} else if (mac && nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// NN4(for Win)
		} else if (nn && gVersion >= 4) {
			width -= 0;
			height -= 0;

		// IE5 for Mac
		} else if (mac && ie && gVersion >= 5) {
			width -= 0;
			height -= 0;

		// IE4 for Mac
		} else if (mac && ie && gVersion >= 4) {
			width -= 0;
			height += 2;

		// IE5(for Win)
		} else if (ie && gVersion >= 5) {
			width += 0;
			height += 0;

		// IE4(for Win)
		} else if (ie && gVersion >= 4) {
			width += 0;
			height += 0;

		// other
		} else {
			width += 0;
			height += 0;
		}
	}


	if (status == 'yes') {
		// NN4 for Mac
		if (mac && nn && gVersion >= 4 && gVersion < 5) {
			width -= 15;
			height -= 15;

		// IE4 for Mac
		}else if(mac && ie && gVersion >= 4 && gVersion < 5){
			width -= 0;
			height += 16;

		}
	}


	if (status == 'no') {
		// NN4
		if (nn && gVersion >= 4 && gVersion < 5) {
			width -= 0;
			height -= 0;

		// NN5 over
		}else if (mac && nn) {
			width += 0;
			height += 80;

		// NN5 over
		}else if (win && nn) {
			width += 0;
			height += 20;

		// safari for Mac
		} else if (mac && safari && gVersion >= 0) {
			width += 0;
			height += 20;

		}
	}


	var win_size = 'width=' + width + ',height=' + height;
	var win_attr = 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',resizable=' + resizable + ',scrollbars=' + scrollbars + ',dependent=' + dependent;

	obj = document.createElement('div');
	obj.innerHTML = '<form><input type="hidden" id="Hide" value="'+imgpass+'"></form>';
	document.body.appendChild(obj);
	
	document.getElementById("Hide").value = imgpass;


	var w = window.open(url, n, win_attr + ',' + win_size);

	return false;

}




/*
	common search form events
**************************************/
	var strSerchTex;
	var headerSearchBox =
	{
		inputElem: null,
		guideText: null,
		formElem: null,
		init: function()
		{
			if(!document.getElementById("searchBoxField")) return;
			
			headerSearchBox.inputElem = document.getElementById("searchBoxField");
			headerSearchBox.guideText = getSpecificParent(headerSearchBox.inputElem,"td").abbr;

//alert(document.getElementById("headerSearch-inputWords").abbr);

			headerSearchBox.formElem = document.getElementById("header-thirdHierarchy").getElementsByTagName("form")[0];
			
			if(headerSearchBox.inputElem.value.length>0 && headerSearchBox.inputElem.value.indexOf(headerSearchBox.guideText)==-1){
				headerSearchBox.disableGuide();
			}else{
				headerSearchBox.enableGuide();
				headerSearchBox.inputElem.value = headerSearchBox.guideText;
			}
			
			headerSearchBox.formElem.onsubmit = function(){
				if(!headerSearchBox.checkEnough()){
					return false;
				}
			}
			headerSearchBox.inputElem.onfocus = function(){
				if(headerSearchBox.inputElem.value.indexOf(headerSearchBox.guideText)>-1)
				{
					headerSearchBox.inputElem.value = "";
					headerSearchBox.disableGuide();
				}
			}
			headerSearchBox.inputElem.onblur = function(){
				if(headerSearchBox.inputElem.value.length<1)
				{
					headerSearchBox.enableGuide();
					setTimeout(function(){
						headerSearchBox.inputElem.value = headerSearchBox.guideText;
					},10);
				}
			}
			headerSearchBox.inputElem.onclick = function(){
				if(headerSearchBox.inputElem.value.indexOf(headerSearchBox.guideText)>-1)
				{
					headerSearchBox.inputElem.value = "";
					headerSearchBox.disableGuide();
				}
			}
		},
		checkEnough: function(){
			if(
				headerSearchBox.inputElem.value.length<1 ||
				headerSearchBox.inputElem.value.indexOf(headerSearchBox.guideText) > -1)
			{
				setTimeout(function(){
					headerSearchBox.disableGuide();
					headerSearchBox.inputElem.value = "";
					headerSearchBox.inputElem.select();
				},1);
				return false;
			} else {
				return true;
			}
		},
		disableGuide: function(){
			headerSearchBox.inputElem.style.color = "#333333";
		},
		enableGuide: function(){
			headerSearchBox.inputElem.style.color = "#aaaaaa";
		}
	}
	


function setFontSize(){
	try{
		fontSizeInit();
	}catch(e){
	}
}

function setSearchBox(){
	try{
		headerSearchBox.init();
	}catch(e){
	}
}
