//BrowserTitle
//document.title = "Korail Korea Railroad";

//Popup
function WinOpen(src,win, X, Y, scroll){
l = (screen.width) ?	(screen.width- X) / 2	: 0;
t = (screen.height) ?	(screen.height- Y) / 2 : 0;	
	NewWindow=window.open(src,win,'width='+X+',height='+Y+',top='+t+',left='+l+',scrollbars='+scroll+',toolbar=no,location=no,directories=no,status=no,resizable=no,menubar=no');
}

function WinOpenTL(src, win, w, h, scroll)
{
	var src= src;
	var posi = "width="+ w +",height="+h+",toolbar=no,location=no,status=no,menubar=no,top=10,left=50,scrollbars=" + scroll +",resizable=no" ;
	NewWindow =	window.open(src,win,posi);
}



/*Top Global Menu*/
//1Depth Menu rollOn 
function ImgPreLoad(imgTitle, imageNum) {
		imageNum++;
		rollOn = new Array(imageNum);
		rollOff = new Array(imageNum);
		for (j = 1; j <= imageNum; j++) {
			if (j < 10) {
				tmp = "0";
			} else {
				tmp ="";
			}
			rollOn[j] = new Image();
			rollOn[j].src = imgTitle + tmp + j + "_on.gif";
			rollOff[j] = new Image();
			rollOff[j].src = imgTitle + tmp + j + "_off.gif";
		}
	}
	function imgOn(Num) {
    if (rollOn[Num] != null) {	
				document["T"+Num].src = rollOn[Num].src;
		}
	}
	function imgOff(Num) {
		if (rollOn[Num] != null) {		
			if (Num != Depth1) {
				document["T"+Num].src = rollOff[Num].src;
			}
      else {  
      document["T"+Num].src = rollOn[Num].src;
      }
	}
}
ImgPreLoad('/2007/eng/img/navi/tm',5);

//2Depth Menu rollOn 
function sImgPreLoad(simgTitle, simageNum) {
		simageNum++;
		srollOn = new Array(simageNum);
		srollOff = new Array(simageNum);
		for (h = 1; h <= simageNum; h++) {
			if (h < 10) {
				tmp = "_0";
			} else {
				tmp ="_";
			}
			srollOn[h] = new Image();
			srollOn[h].src = simgTitle + tmp + h + "_on.gif";
			srollOff[h] = new Image();
			srollOff[h].src = simgTitle + tmp + h + "_off.gif";
		}
	}
	function simgOn(gNum) {
    if (srollOn[gNum] != null) {	
				document["G"+gNum].src = srollOn[gNum].src;
		}
	}
	function simgOff(gNum) {
		if (srollOn[gNum] != null) {
			if (gNum != Depth2_tms) {
				document["G"+gNum].src = srollOff[gNum].src;
			}
      else {  
      document["G"+gNum].src = srollOn[gNum].src;
      }
	}
}
sImgPreLoad ('/2007/eng/img/navi/tms',14);

function PreImgLoad(Title, imgNum) {
		imgNum++;
		rollOver = new Array(imgNum);
		rollOut = new Array(imgNum);
		for (i = 1; i <= imgNum; i++) {
			if (i < 10) {
				tmp = "0";
			} else {
				tmp ="";
			}
			rollOver[i] = new Image();
			rollOver[i].src = Title + tmp + i + "_on.gif";
			rollOut[i] = new Image();
			rollOut[i].src = Title + tmp + i + "_off.gif";
		}
	}
	function imgOver(lNum) {
    if (rollOver[lNum] != null) {	
				document["L"+lNum].src = rollOver[lNum].src;
		}
	}
	function imgOut(lNum) {
		if (rollOver[lNum] != null) {
			if (lNum != Depth2) {
				document["L"+lNum].src = rollOut[lNum].src;
			}
      else {  
      document["L"+lNum].src = rollOver[lNum].src;
    		 }
		}
	}	
	//3Depth Menu rollOn 
	function sPreImgLoad(simgTitle, simgNum) {
		simgNum++;
		srollOver = new Array(simgNum);
		srollOut = new Array(simgNum);
		for (k = 1; k <= simgNum; k++) {
			if (k < 10) {
				tmp = "_0";
			} else {
				tmp ="_";
			}
			srollOver[k] = new Image();
			srollOver[k].src = simgTitle + tmp + k + "_on.gif";
			srollOut[k] = new Image();
			srollOut[k].src = simgTitle + tmp + k + "_off.gif";
		}
	}

	function simgOver(sNum) {
		if (srollOver[sNum] != null) {
			document["S"+sNum].src = srollOver[sNum].src;
		}
	}
	function simgOut(sNum) {
		if (srollOver[sNum] != null) {
			if (sNum != Depth3) {
				document["S"+sNum].src = srollOut[sNum].src;
			}
      else {  
      document["S"+sNum].src = srollOver[sNum].src;
    		 }
			}
		}

//°øÅëOnLoad//		

//inageRollOver
function menuOver() {
	this.src = this.src.replace(".gif", "_on.gif");
}
function menuOut() {
	this.src = this.src.replace("_on.gif", ".gif");
}

function imageOver(imgEl) {
	imgEl.src = imgEl.src.replace(".gif", "_on.gif");
}
function imageOut(imgEl) {
	imgEl.src = imgEl.src.replace("_on.gif", ".gif");
}

var tabcurrentSeq2 = -1;
function initTabMenu2(menuEl) {
	for (i=0; i<menuEl.length; i++) {
		if (i != tabcurrentSeq2) {
			menuEl[i].src = menuEl[i].src.replace(".gif", "_on.gif")
		}
	}
}

var tabcurrentSeq = -1;
function initTabMenu(menuEl) {
	for (i=0; i<menuEl.length; i++) {
		if (i != tabcurrentSeq) {
			menuEl[i].onmouseover = menuOver;
			menuEl[i].onmouseout = menuOut;
		} else {
			menuEl[i].src = menuEl[i].src.replace(".gif", "_on.gif")
		}
	}
}

document.getElementsBySelector = function(selector) {
	// Attempt to fail gracefully in lesser browsers
	if (!document.getElementsByTagName) {
		return new Array();
	}
	// Split selector in to tokens
	var tokens = selector.split(' ');
	var currentContext = new Array(document);
	for (var i = 0; i < tokens.length; i++) {
		token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
		if (token.indexOf('#') > -1) {
			// Token is an ID selector
			var bits = token.split('#');
			var tagName = bits[0];
			var id = bits[1];
			var element = document.getElementById(id);
			if (tagName && element.nodeName.toLowerCase() != tagName) {
				// tag with that ID not found, return false
				return new Array();
			}
			// Set currentContext to contain just this element
			currentContext = new Array(element);
			continue; // Skip to next token
		}
		if (token.indexOf('.') > -1) {
			// Token contains a class selector
			var bits = token.split('.');
			var tagName = bits[0];
			var className = bits[1];
			if (!tagName) {
				tagName = '*';
			}
			// Get elements matching tag, filter them for class selector
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			continue; // Skip to next token
		}
		// Code to deal with attribute selectors
		if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
			var tagName = RegExp.$1;
			var attrName = RegExp.$2;
			var attrOperator = RegExp.$3;
			var attrValue = RegExp.$4;
			if (!tagName) {
				tagName = '*';
			}
			// Grab all of the tagName elements within current context
			var found = new Array;
			var foundCount = 0;
			for (var h = 0; h < currentContext.length; h++) {
				var elements;
				if (tagName == '*') {
						elements = getAllChildren(currentContext[h]);
				} else {
						elements = currentContext[h].getElementsByTagName(tagName);
				}
				for (var j = 0; j < elements.length; j++) {
					found[foundCount++] = elements[j];
				}
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			var checkFunction; // This function will be used to filter the elements
			switch (attrOperator) {
				case '=': // Equality
					checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
					break;
				case '~': // Match one of space seperated words 
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
					break;
				case '|': // Match start with value followed by optional hyphen
					checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
					break;
				case '^': // Match starts with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
					break;
				case '$': // Match ends with value - fails with "Warning" in Opera 7
					checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
					break;
				case '*': // Match ends with value
					checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
					break;
				default :
					// Just test for existence of attribute
					checkFunction = function(e) { return e.getAttribute(attrName); };
			}
			currentContext = new Array;
			var currentContextIndex = 0;
			for (var k = 0; k < found.length; k++) {
				if (checkFunction(found[k])) {
					currentContext[currentContextIndex++] = found[k];
				}
			}
			// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
			continue; // Skip to next token
		}
		// If we get here, token is JUST an element (not a class or ID selector)
		tagName = token;
		var found = new Array;
		var foundCount = 0;
		for (var h = 0; h < currentContext.length; h++) {
			var elements = currentContext[h].getElementsByTagName(tagName);
			for (var j = 0; j < elements.length; j++) {
				found[foundCount++] = elements[j];
			}
		}
		currentContext = found;
	}
	return currentContext;
}


// tabbed menu
function initTabMu(menuElId) {
	var tabMenu = document.getElementById(menuElId).getElementsByTagName("a");
	for(i=0; i<tabMenu.length; i++) {
		thismenu = tabMenu.item(i);
		thismenu.menuContainer = document.getElementById(menuElId);
		thismenu.targetEl = document.getElementById(tabMenu.item(i).href.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
		thismenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
		thismenu.onclick = tabMenuClick;
	}

	initmenu = tabMenu.item(0);
	initmenu.targetEl.style.display = "block";
	initmenu.getElementsByTagName("img").item(0).onmouseover();
	initmenu.getElementsByTagName("img").item(0).onmouseover = null;
	initmenu.getElementsByTagName("img").item(0).onmouseout = null;
	initmenu.menuContainer.current = initmenu;
}
function tabMenuClick() {
	currentmenu = this.menuContainer.current;
	if (currentmenu != this) {
		currentmenu.targetEl.style.display = "none";
		currentmenu.getElementsByTagName("img").item(0).onmouseover = menuOver;
		currentmenu.getElementsByTagName("img").item(0).onmouseout = menuOut;
		currentmenu.getElementsByTagName("img").item(0).onmouseout();
	
		this.targetEl.style.display = "block";
		this.getElementsByTagName("img").item(0).onmouseover = null;
		this.getElementsByTagName("img").item(0).onmouseout = null;
		this.menuContainer.current = this;
	}
	return false;
}


//Flash
function IE_HtmlRewrite(objParent) {
	if (window.ActiveXObject && objParent) {
		objParent.innerHTML = objParent.innerHTML;
	}
}

function printHTML(str) {
	var strHTML = str;
	document.write(strHTML);
}

function flash(swf,width,height) {
	var flash_tag = "";
	flash_tag = '<OBJECT id="mainFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
	flash_tag +='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ';
	flash_tag +='WIDTH="'+width+'" HEIGHT="'+height+'" >';
	flash_tag +='<param name="movie" value="'+swf+'">';
	flash_tag +='<param name="wmode" value="transparent">';
	flash_tag +='<param name="quality" value="high">';
	flash_tag +='<PARAM NAME="menu" VALUE="false">';
	flash_tag +='<embed id="mainFlash" name="mainFlash" src="'+swf+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
	flash_tag +='type="application/x-shockwave-flash"  WIDTH="'+width+'" HEIGHT="'+height+'"></embed></object>'

	document.write(flash_tag);
}

function PrintMovie(src,w,h,wmode){
	document.write('<object id="MediaPlayer" name="MediaPlayer" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" width="' + w + '" height="' + h + '">');
	document.write('<param name="URL" value="' + src + '">');

	if(wmode == 0){document.write('<param name="AutoStart" value="0">');}
	if(wmode == 1){document.write('<param name="AutoStart" value="1">');}
	if(wmode != 0 && wmode != 1) { document.write('<param name="AutoStart" value="0">');}

	document.write('<param name="AllowScan" value="true">');
	document.write('<param name="ShowStatusBar">');
	document.write('<param name="ShowTracker">');
	document.write('</object>');
}


//body Title
function MakeTitle(title,copy){
	document.write('<div id="chead">')
	document.write('<h1><img src="'+title+'" alt="'+copy+'"/></h1>')
	document.write('</div>')
}



//POPUP Title
function MakePopTitle(TitleName){
	document.write('<div style="background:url(/fun/img/common/pop_titlebg.gif) repeat-x; height:57px;position:relative">')
	document.write('<div style="float:left; background:url(/fun/img/common/pop_headimg_l.gif); width:57px;height:57px"></div>')
	document.write('<div style="position:absolute;top:20px;left:25px"><img src="'+ TitleName +'" /></div>')
	document.write('<div style="float:right; background:url(/fun/img/common/pop_headimg_r.gif); width:208px;height:57px"></div>')
	document.write('</div>')
}

// active photo
function PhotoChange(str,x){
		if(x){
			str = eval("document.all."+str);
			str.style.display="block";
			str.src="/fun/img/family/"+x;
		}
	}


function JumpMenu(form) {
 var myindex=form.cmbSel.selectedIndex 
	  if (myindex == 0) {
			document.location.href = form.cmbSel.options[myindex].value;
    } 
		else
		{
		 window.open(form.cmbSel.options[myindex].value); 
		}
}

	function goMenu(thisURL,thisTarget) {
		if (thisURL == "" || thisURL == null) return;
		var nowTarget = "_self";
		if (thisTarget != null && thisTarget != "" ) nowTarget = thisTarget;
		window.open(thisURL, nowTarget, "");
	}
	
	
//ÆùÆ®È®´ëÃà¼Ò ÇÔ¼ö ½ÃÀÛ
var customFontSize = 12;
var customLineHeight = 14;
var customInputSize = 17;
function setFontSize(obj){
	try{
		obj.style.fontSize=customFontSize+'px';
		obj.style.lineHeight=customLineHeight+'px';
		if(obj.tagName=='INPUT'){
			obj.style.height=customInputSize+'px';
		}
	}catch(e){}
}
function searchTargetNode(obj){
	setFontSize(obj);
	var ml=obj.childNodes.length;
	if(ml>0){
		for(var i=0;i<ml;i++){
			setFontSize(obj.childNodes[i]);
			if(obj.childNodes[i].tagName=='IFRAME'){
				try{
					searchTargetNode(frames[obj.childNodes[i].name].document.body);
				}catch(e){}
			} else {
				if(obj.childNodes[i].childNodes.length>0){
					searchTargetNode(obj.childNodes[i]);
				}
			}
		}
	}
}
function resetFontSize(targetObjectId){
	if (targetObjectId==null) targetObjectId = "content-area";
	var obj=document.getElementById(targetObjectId);
	searchTargetNode(obj);
}
function increaseFontSize(targetObjectId) {
	if (customFontSize>=16) {
		alert("´õÀÌ»ó Å©°Ô ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
		return;
	}
	customFontSize = customFontSize + 2;
	customLineHeight = customLineHeight + 2;
	customInputSize = customInputSize + 2;
	resetFontSize(targetObjectId);
}
function decreaseFontSize(targetObjectId) {
	if (customFontSize<=12) {
		alert("´õÀÌ»ó ÀÛ°Ô ÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
		return;
	}
	customFontSize = customFontSize - 2;
	customLineHeight = customLineHeight - 2;
	customInputSize = customInputSize - 2;
	resetFontSize(targetObjectId);
}
//ÆùÆ®È®´ëÃà¼Ò ÇÔ¼ö ³¡


function makeTitle(title,alt){
		document.writeln('<div style="position:relative;margin-bottom:20px;">')
		document.writeln('	<h1 style="margin:0;padding:0px;float:left"><img src="'+title+'" style="vertical-align:top;" alt="'+alt+'" /></h1>')
		document.writeln('</div>')
		document.writeln('<br style="clear:both">')
}


// 1depth ·Ñ¿À¹ö½Ã ¶ß´Â ¸Þ´º
function open_sub01() {	sub01.style.visibility="visible";}
function close_sub01() {sub01.style.visibility="hidden";}
function open_sub02() {	sub02.style.visibility="visible";}
function close_sub02() {sub02.style.visibility="hidden";}
function open_sub03() {	sub03.style.visibility="visible";}
function close_sub03() { sub03.style.visibility="hidden";}
function open_sub04() {	sub04.style.visibility="visible";}
function close_sub04() { sub04.style.visibility="hidden";}
function open_sub05() {	sub05.style.visibility="visible";}
function close_sub05() { sub05.style.visibility="hidden";}
function open_sub06() {	sub06.style.visibility="visible";}
function close_sub06() { sub06.style.visibility="hidden";}
function open_sub07() {	sub07.style.visibility="visible";}
function close_sub07() { sub07.style.visibility="hidden";}
function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function popUp(L, e) {
        if(n4) {
        	var barron = document.layers[L]
		barron.left = e.pageX + 30
		barron.top = e.pageY
		barron.visibility = "visible"
        }
        else if(e4) {
        	var barron = document.all[L]
                barron.style.pixelLeft = event.clientX + document.body.scrollLeft - 50
                barron.style.pixelTop = event.clientY + document.body.scrollTop - 110
                barron.style.visibility = "visible"
        }
}
function popDown(L) {
        if(n4) document.layers[L].visibility = "hidden"
        else if(e4) document.all[L].style.visibility = "hidden"
}
n4 = (document.layers) ? 1 : 0
e4 = (document.all) ? 1 : 0
