/**
* Copyright (c) Ahn Jongtae / Nparts Corporation. All Rights Reserved.
* Licensed under the GPL.
* See the GNU General Public License for more details. 
* www.devq.co.kr , www.devq.kr
**/

if ( !titData ) { var titData; }
var clear = ko_path_global+"image/blank.gif";

/*PNG Fix*/
pngfix = function()
{
	var els = document.getElementsByTagName('*');
	var ip = /\.png/i;
	var i = els.length;
	while (i-- > 0)
	{
		var el = els[i];
		var es = el.style;
		if (el.src && el.src.match(ip) && !es.filter)
		{
			es.height = el.height;
			es.width = el.width;
			es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + el.src + "',sizingMethod='crop')";
			el.src = clear;
		}
		else {
			var elb = el.currentStyle.backgroundImage;
			if (elb.match(ip))
			{
				var path = elb.split('"');
				var rep = (el.currentStyle.backgroundRepeat == 'no-repeat') ? 'crop' : 'scale';
				es.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + path[1] + "',sizingMethod='" + rep + "')";
				es.height = el.clientHeight + 'px';
				es.backgroundImage = 'none';
				var elkids = el.getElementsByTagName('*');
				if (elkids)
				{
					var j = elkids.length;
					if (el.currentStyle.position != "absolute") es.position = 'static';
					while (j-- > 0) if (!elkids[j].style.position) elkids[j].style.position = "relative";
				}
			}
		}
	}
}
function ie6PngFix()
{
	if (isIE6()) window.attachEvent('onload',pngfix);
	else return false;
}
/*이벤트*/
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function addEvent( obj, type, fn )
{
	if ( obj.attachEvent )
	{
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent( 'on'+type, obj[type+fn] );
	} else
	obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn )
{
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+type, obj[type+fn] );
		obj[type+fn] = null;
	}
	else {
		obj.removeEventListener( type, fn, false );
	}
}
/*클래스*/
function hasClass(element,value)
{
	if (!element.className) return false;
	var re = new RegExp("(^|\\s)" + value + "(\\s|$)");
	return re.test(element.className);
}
function getElementsByClass(search_class,node,tag)
{
	var class_elements = new Array();
	if (node == null) {
		node = document;
	}
	if (tag == null) {
		tag = "*";
	}
	var els = node.getElementsByTagName(tag);
	for (var i=0, j=0; i<els.length; i++) {
		if (hasClass(els[i],search_class)) {
			class_elements[j] = els[i];
			j++;
		}
	}
	return class_elements;
}
function addClass(element,value)
{
	if (!element.className) {
		element.className = value;
	} else {
		var new_class_name = element.className;
		if (!hasClass(element,value)) {
			element.className += " " + value;
		}
	}
}
function removeClass(element,value)
{
	if (element.className && hasClass(element,value)) {
		var re = new RegExp("(^|\\s)" + value + "(\\s|$)");
		element.className = element.className.replace(re,"");
	}
}
function toggleClass(element,value1,value2)
{
	if (hasClass(element,value1)) {
		if (value2) {
			addClass(element,value2);
		}
		removeClass(element,value1);
	} else {
		if (value2 && hasClass(element,value2)) {
			removeClass(element,value2);
		}
		addClass(element,value1);
	}
}
function getChildrenByTagName(parent,tag_name)
{
	var all_children = parent.childNodes;
	var new_children = new Array();
	for (var i=0, j=0; i<all_children.length; i++) {
		if (all_children[i].tagName && (all_children[i].tagName.toLowerCase() == tag_name.toLowerCase())) {
			new_children[j] = all_children[i];
			j++;
		}
	}
	return new_children;
}
function getChildrenByClassName(parent,class_name)
{
	var all_children = parent.childNodes;
	var new_children = new Array();
	for (var i=0, j=0; i<all_children.length; i++) {
		if (hasClass(all_children[i],class_name)) {
			new_children[j] = all_children[i];
			j++;
		}
	}
	return new_children;
}
/*브라우저*/
function isIE()
{
	var version = navigator.appVersion;
	if (version.indexOf("MSIE") != -1) return true;
	else return false;
}
function isIE6()
{
	var version = navigator.appVersion;
	if (version.indexOf("MSIE 6") != -1) return true;
	else return false;
}
/*스타일*/
function getStyle(el,css_prop)
{
	var strValue;
	if (document.defaultView && document.defaultView.getComputedStyle) {
		strValue = document.defaultView.getComputedStyle(el,null).getPropertyValue(css_prop);
	} else if (el.currentStyle) {
		css_prop = css_prop.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = el.currentStyle[css_prop];
	}
	return strValue;
}
/*엘리먼트*/
function addElement(el,tag)
{
	var original = el;
	while (original.tagName != tag.toUpperCase()) {
		original = original.parentNode;
	}
	var tmp = original.cloneNode(true);
	var input = tmp.getElementsByTagName("input");
	for (var i=0; i<input.length ; i++) {
		input[i].value = "";
	}
	addClass(tmp,"added");
	insertAfter(tmp,original);
	return false;
}
function removeElement(el,tag)
{
	var target = el;
	while (target.tagName != tag.toUpperCase()) {
		target = target.parentNode;
	}
	if (hasClass(target,"added")) {
		target.parentNode.removeChild(target);
	}
	return false;
}
function insertAfter(new_element,target_element)
{
	var parent = target_element.parentNode;
	if (parent.lastChild == target_element) {
		parent.appendChild(new_element);
	} else {
		parent.insertBefore(new_element,target_element.nextSibling);
	}
}
function changeAlt(obj,src,dst) {
	var objAlt = obj.getAttribute('alt');
	if ( objAlt == src ) {
		obj.setAttribute('alt',dst);
	} else if ( objAlt == dst ) {
		obj.setAttribute('alt',src);
	}
}
/*팝업*/
function popup(e)
{
	var winURI = e.getAttribute("href");
	var winname = e.rel.split(" ")[1] ? e.rel.split(" ")[1] : "popup";
	newWindow = window.open(winURI+"&popup=Y",winname,"width=100,height=100,menubar=no,location=no,resizable=no,status=no");
	newWindow.focus();
	return false;
}
function initPopup()
{
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	if (links.length < 1) return false;
	var title;
	for (i = 0; i<links.length; i++) {
		if (links[i].rel.indexOf("popup") != -1) {
			links[i].onclick = function() {
				return popup(this);
			}
			title = links[i].getAttribute("title") ? links[i].getAttribute("title") + "(팝업창을 띄웁니다.)" : "팝업창을 띄웁니다.";
			links[i].setAttribute("title",title);
		}
	}
}
/*이미지*/
function toggleImage(obj)
{
	if(obj.src.indexOf('off.gif') != -1) obj.src = obj.src.replace('off.gif', 'on.gif');
	else if(obj.src.indexOf('on.gif') != -1) obj.src = obj.src.replace('on.gif', 'off.gif');
}
function toggleImageLayer(_id,_img) {
	var el = getId(_id);
	var obj = getId(_img);
	el.style.display = (!el.style || (el.style.display != 'none')) ? 'none' : '';
	if(obj.src.indexOf('off.gif') != -1) obj.src = obj.src.replace('off.gif', 'on.gif');
	else if(obj.src.indexOf('on.gif') != -1) obj.src = obj.src.replace('on.gif', 'off.gif');
}
/*레이어*/
function showLayer(el)
{
	if(!getId(el)) return false;
	el = (typeof el == "string") ? getId(el) : el;
	el.style.display = "block";
}
function hideLayer(el)
{
	if(!getId(el)) return false;
	el = (typeof el == "string") ? getId(el) : el;
	el.style.display = "none";
}
function toggleLayer(_id)
{
	var el = getId(_id);
	el.style.display = (!el.style || (el.style.display != 'none')) ? 'none' : '';
}
function toggleLayerTrue(obj,dp)
{
	obj.style.display = (dp != true) ? 'none' : '';
}
function getClickLayer(e,obj,x,y )
{
	var xy = getEventXY(e);
	clickX = myagent == 'ie' ? xy.x - 55 : xy.x - 55;
	clickY = myagent == 'ie' ? xy.y + 10 : xy.y + 15;
	clickLayer = obj;
	tcx = clickX;
	tcy = clickY;
}
/*탭*/
/*이미지 메인탭*/
function tabChange(el,more)
{
	if (!document.getElementsByTagName || !document.getElementById) return false;
	var prefix = el.getAttribute("href",2).replace("#","").split("-")[0]+"-";
	var tablist = el;
	while (tablist.tagName != "UL") {
		tablist = tablist.parentNode;
	}
	var tabitems = tablist.getElementsByTagName("li");
	var clickedtab = el;
	while (clickedtab.tagName != "LI") {
		clickedtab = clickedtab.parentNode;
	}
	var tabparent = tablist.parentNode;
	var morebutton = getElementsByClass("more",tabparent)[0];
	for (var i=0; i<tabitems.length; i++) {
		var tabcont = getId(prefix+(i+1));
		var tabimg = tabitems[i].getElementsByTagName("img")[0];
		if ((tabitems[i] == clickedtab) && (tabimg.src.indexOf("_off.gif") != -1)) {
			tabimg.src = tabimg.src.replace("_off.gif","_on.gif");
			tabcont.style.display = "block";
			if (more && morebutton) {
				morebutton.setAttribute("href",more);
				morebutton.style.display = "block";
			} else if(!more && morebutton && morebutton.style.display == "block") {
				morebutton.setAttribute("href","#");
				morebutton.style.display = "none";
			}
		} else if (tabitems[i] != clickedtab) {
			if (tabimg.src.indexOf("_on.gif") != -1) {
				tabimg.src = tabimg.src.replace("_on.gif","_off.gif");
			}
			tabcont.style.display = "none";
		}
	}
	return false;
}
/*기본탭*/
/*chgTab - .on 클래스 사용해서 탭 이미지 및 컨탠츠 변경 시*/
function getConts(el,wrapper_class,cont_class)
{
	var wrapper = el;
	while (!hasClass(wrapper,wrapper_class))
	{
		wrapper = wrapper.parentNode;
	}
	var children = wrapper.childNodes;
	var tabconts = new Array();
	for (var i=0, j=0; i<children.length; i++) {
		if (children[i].className && hasClass(children[i],cont_class)) {
			tabconts[j] = children[i];
			j++;
		}
	}
	return tabconts;
}
function chgTab(el)
{
	if (!document.getElementsByTagName) return false;
	var tabconts = getConts(el,"tab-wrap","tab-cont");
	var tablist = el;
	while ((tablist.tagName != "OL") && (tablist.tagName !="UL")) {
		tablist = tablist.parentNode;
	}
	var ontag = getElementsByClass("on",tablist)[0].tagName;
	var clicked = el;
	while (clicked.tagName != ontag) {
		clicked = clicked.parentNode;
	}
	var tabitems = tablist.getElementsByTagName(ontag);
	for (var i=0; i<tabitems.length; i++) {
		if ((tabitems[i] == clicked) && !hasClass(clicked,"on")) {
			addClass(tabitems[i],"on");
			addClass(tabconts[i],"on");
		} else if (tabitems[i] != clicked) {
			removeClass(tabitems[i],"on");
			removeClass(tabconts[i],"on");
		}
	}
	return false;
}
function chgTabImg(el)
{
	if (!document.getElementsByTagName) return false;
	var tabconts = getConts(el,"tab-wrap","tab-cont");
	var tablist = el;
	while ((tablist.tagName != "OL") && (tablist.tagName !="UL")) {
		tablist = tablist.parentNode;
	}
	var ontag = getElementsByClass("on",tablist)[0].tagName;
	var clicked = el;
	while (clicked.tagName != ontag) {
		clicked = clicked.parentNode;
	}
	var tabitems = tablist.getElementsByTagName(ontag);
	var tabimgs = tablist.getElementsByTagName("IMG");
	for (var i=0; i<tabitems.length; i++) {
		if ((tabitems[i] == clicked) && !hasClass(clicked,"on")) {
			tabimgs[i].src = tabimgs[i].src.replace("_off.gif","_on.gif");
			addClass(tabitems[i],"on");
			addClass(tabconts[i],"on");
		} else if (tabitems[i] != clicked) {
			tabimgs[i].src = tabimgs[i].src.replace("_on.gif","_off.gif");
			removeClass(tabitems[i],"on");
			removeClass(tabconts[i],"on");
		}
	}
	return false;
}
// chgCont : 클릭 시 컨탠츠 변경
function chgCont(el)
{
	if (!document.getElementById) return false;
	var t_id = el.getAttribute("href",2).replace("#","");
	var target = getId(t_id);
	var conts = getConts(target,"tab-wrap","tab-cont");
	for (var i=0; i<conts.length; i++) {
		/*var c_id = conts[i].getAttribute("id");
		if (c_id == t_id && !hasClass(conts[i],"on")) {
			addClass(conts[i],"on");
		} else if (c_id != t_id) {
			removeClass(conts[i],"on");
		}*/
		removeClass(conts[i],"on");
	}
	addClass(target,"on");
	return false;
}
/*테이블*/
/*플래쉬*/
function getFlash(swfName,wt,ht,id,trans)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+wt+'" height="'+ht+'" id="'+id+'">');
    document.write('<param name="movie" value="'+swfName+'" />');
    document.write('<param name="quality" value="high" />');
    if (trans != 0) {document.write('<param name="wmode" value="transparent" />');}
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<embed src="'+swfName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" width="'+wt+'" height="'+ht+'" allowScriptAccess="sameDomain" id="'+id+'"></embed>');
	document.write('</object>');
}
function getFlashXML(pSwfUrl,pXmlUrl,wt,ht,trans)
{
    var xmlUrl = escape(pXmlUrl);
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+wt+'" height="'+ht+'" id="" align="middle">');
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<param name="movie" value="'+pSwfUrl+'" />');
    document.write('<param name="quality" value="high" />');
    if (trans != 0) {document.write('<param name="wmode" value="transparent" />');}
    document.write('<param name="FlashVars" value="xml_url='+xmlUrl+'" />');
    document.write('<param name="bgcolor" value="#FFFFFF" />');
    document.write('<embed src="'+pSwfUrl+'" FlashVars="xml_url='+xmlUrl+'" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="'+wt+'" height="'+ht+'" name="" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
    document.write('</object>');
}
function getFlashVars(pSwfUrl,pVarParam,wt,ht,trans)
{
    var varUrl = pVarParam;
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+wt+'" height="'+ht+'" id="" align="middle">');
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<param name="movie" value="'+pSwfUrl+'" />');
    document.write('<param name="quality" value="high" />');
    if (trans != 0) {document.write('<param name="wmode" value="transparent" />');}
    document.write('<param name="FlashVars" value="'+varUrl+'" />');
    document.write('<param name="bgcolor" value="#FFFFFF" />');
	document.write('<embed src="'+pSwfUrl+'" FlashVars="'+varUrl+'" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="'+wt+'" height="'+ht+'" name="" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
    document.write('</object>');
}
/*레이아웃*/
function printArea(el)
{
	if (el)
	{
		if (!document.getElementById) return false;
		var original = document.body.innerHTML;
		var cont = getId(el);
		window.onbeforeprint = function() {
			document.body.innerHTML = cont.innerHTML;
		}
		window.onafterprint = function() {
			document.body.innerHTML = original;
		}
	}
	window.print();
}
/*플래쉬 타이틀*/
function titleWriter(str)
{
	titData = str.replace(/\./g,''); ;
	flashTitle_in();
}
function flashTitle_in()
{    
    document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='200' height='24' id='flashtitle' align='middle'>");
    document.write("<param name='allowScriptAccess' value='always' />");
    //document.write("<param name='movie' value='"+ko_path_plugin+"_global/imagetitle/image/imagetitle.swf' />");
    document.write("<param name='movie' value='"+ko_path_plugin+"_acc/flashtitle/image/imagetitle.swf' />");
    document.write("<param name='quality' value='high' />");
    document.write("<param name='wmode' value='transparent' />");
    document.write("<param name='bgcolor' value='#FFFFFF' />");
    //document.write("<embed src='"+ko_path_plugin+"_global/imagetitle/image/imagetitle.swf' wmode='transparent' quality='high' width='200' height='24' name='flashtitle' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
    document.write("<embed src='"+ko_path_plugin+"_acc/flashtitle/image/imagetitle.swf' wmode='transparent' quality='high' width='200' height='24' name='flashtitle' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
    document.write("</object>");
}
function titleData()
{
   return titData; 	
}
function checkMaxLength()
{
	var textArea = document.getElementsByTagName('textarea');
	for (i=0; i<textArea.length; i++)
	{
		textArea[i].onkeyup = textArea[i].onkeydown = function()
		{
			var max = this.getAttribute('maxlength');
			if(max==null) return;
			var textValue = this.value;
			var totalText = textValue.length;
			if(totalText<=max)
			{
				var curNum = document.getElementsByTagName('span');
				for(j=0; j<curNum.length; j++)
				{
					if (curNum[j].getAttribute('name') == this.name) curNum[j].innerHTML = '(' + totalText + '/' + max + ')';
				}
			} else {
				alert(max + '자리를 넘길 수 없습니다.');
				this.value = this.value.substr(0,max);
			}
		}
	}
}
function getFlashVersion(){
  // ie
  try {
    try {
      // avoid fp6 minor version lookup issues
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
      try { axo.AllowScriptAccess = 'always'; }
      catch(e) { return '6,0,0'; }
    } catch(e) {}
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  // other browsers
  } catch(e) {
    try {
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
      }
    } catch(e) {}
  }
  return '0,0,0';
}
/* 
var version = getFlashVersion().split(',').shift();
if(version < 10){
  alert("Lower than 10");
}else{
  alert("10 or higher");
}
*/

/*로딩*/
addLoadEvent(initPopup);
//addLoadEvent(ie6PngFix);
addLoadEvent(checkMaxLength);
