﻿function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// flashload(파일경로, ID, 가로, 세로, BGCOLOR, 변수, 윈도우모드, 대체텍스트)
function flashload(url,id,width,height,bgcolor,fVars,wmode,altText){
	var code ="";
	var flashVars = fVars; 
	var brw = navigator.appName;
	if (fVars == null) {
		flashVars == null;
	}
	code += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" id="'+id+'" align="middle">';
		code += '<param name="allowScriptAccess" value="sameDomain" />';
		code += '<param name="allowFullScreen" value="false" />';
		code += '<param name="movie" value="'+url+'" />';
		code += '<param name="flashVars" value="'+flashVars+'" />';
		code += '<param name="quality" value="best" />';
		code += '<param name="wmode" value="'+wmode+'" />';
		code += '<param name="menu" value="false" />';
		code += '<param name="scale" value="noscale"/>';
		code += '<param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"/>';
		code += '<param name="align" value="middle" />';
		code += '<param name="bgcolor" value="'+bgcolor+'" />';

		code += '<!--[if !IE]>--> ';
		code += '<object type="application/x-shockwave-flash" data="' + url + '" width="' + width + '" height="' + height + '" name="' + id + '">';
		code += '<!--<![endif]--> ';
			code += '<div class="alt_content alt_' + id + '">' + altText + '</div>';
		code += '<!--[if !IE]>--> ';
		code += '</object> ';
		code += '<!--<![endif]--> ';
	code += '</object>';
	if (brw == 'Netscape'|| brw == 'Opera')
	{
		code = '<embed src="'+url+'" flashVars="'+flashVars+'" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'" name="'+ id +'" align="middle" wmode="'+wmode+'" quality="best" menu="false" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><div class="alt_content alt_' + id + '">' + altText + '</div></embed>';
	}
	document.write(code);
	// 플래시가 form 안에 있을경우 자바스크립트 ie접근 에러 해결 코드
	if (brw == 'Microsoft Internet Explorer')
	{
		eval("window." + id + " = document.getElementById('" + id + "');");
	}
}

// flashWrite(파일경로, 가로, 세로, 아이디, 배경색, 변수, 윈도우모드)
function flashWrite(url,w,h,id,bg,vars,win){
	// 플래시 코드 정의
	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='true' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	// 플래시 코드 출력
	document.write(flashStr);
}

// Show-Hide Layer 
function showLayer(tgtEl) {document.getElementById(tgtEl).style.display = "block"; }
function hideLayer(tgtEl) {document.getElementById(tgtEl).style.display = "none"; }
function showhideLayer(tgtEl) {
	var el = document.getElementById(tgtEl);
	el.style.display = (el.style.display == "none" ? "block" : "none");
}

// Select Links
function onchangeUrl(linkstr) {
	var v_url = linkstr;
	if(v_url) {
	window.location = v_url;
	}
}
// add calss
function addClass(element,value) {
  if (!element.className) {
    element.className = value;
  } else {
    newClassName = element.className;
    newClassName+= " ";
    newClassName+= value;
    element.className = newClassName;
  }
}

// imgover
function imgOver() {
  var aImages = document.getElementsByTagName('img');
  for(var i=0; i<aImages.length; i++) {
    if (aImages[i].className == 'imgover') {
      aImages[i].onmouseover = function() {
        var img_src =  this.getAttribute('src');
        img_src = img_src.replace("_off.gif", "_on.gif");
        this.setAttribute('src', img_src);
        }
       aImages[i].onmouseout = function() {
          var img_src =  this.getAttribute('src');
          img_src = img_src.replace("_on.gif", "_off.gif");
          this.setAttribute('src', img_src);
       }
    }
  }
  return false;
}

//list Style Selector
function listStyleSelect(obj) {
  if(!document.getElementById("listStyle")) return false;
  var listElem = document.getElementById("listStyle");
  if(obj.value == "") return false;
  listElem.className = obj.value;
  return true;
}

function imgClick(id) {
  var aImages = document.getElementsByTagName("img");
  for(var i=0; i<aImages.length; i++) {
    if (aImages[i].className.indexOf("imgclick") == -1) continue;
    if (aImages[i].getAttribute("id") != id) {
      var img_src =  aImages[i].getAttribute('src');
      img_src = img_src.replace("_on.gif", "_off.gif");
      aImages[i].setAttribute('src', img_src);
    } else {
      var img_src =  aImages[i].getAttribute('src');
      img_src = img_src.replace("_off.gif", "_on.gif");
      aImages[i].setAttribute('src', img_src);
    }
  }
  return false;
}

function prepareImgClick(elem) {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById(elem)) return false;
  var tabs = document.getElementById(elem);
  var imgs = tabs.getElementsByTagName("img");
  for (var i=0; i<imgs.length; i++ ) {
    var tabId = imgs[i].getAttribute("id");
    if (!tabId) continue;
    imgs[i].destination = tabId;
    imgs[i].onmouseover = function() {
      imgClick(this.destination);
    }
  }
  return false;
}
// label checkbox
function labelClick(labelFor) {
	if(navigator.appVersion.indexOf("MSIE") != -1) {
		var check_name = document.getElementById(labelFor);
		check_name.click();
	}
}
// label focus 필요
function labelFocus(labelFor) {
	if(navigator.appVersion.indexOf("MSIE") != -1) {
		var check_name = document.getElementById(labelFor);
    check_name.focus();
	}
}
// popup
function openwindow(url,target,option) {
	window.open(url,target,option);
}

// alert(msg)
function message(msg) {
	alert(msg);
}


//============== 레이어 팝업 ===========================================
/*
Copyright cloud9
작성자: 개발팀 김승일 과장
: 크로스 브라우징 지향, FF, IE, SAFARI, OPERA 에서 테스팅함
*/

// 투명한 배경색을 설정한다.
function setOpacity(obj,value)
{
	if(typeof(obj)=='string') obj=document.getElementById(obj);
	obj.style.opacity = (value / 100);
	obj.style.MozOpacity = (value / 100);
	obj.style.KhtmlOpacity = (value / 100);
	obj.style.filter = "alpha(opacity=" + value + ")";
}

// document 전체화면 width,height을 구한다.
function getBodySize(){
	var w,h;
	if (self.innerHeight){
		w = self.innerWidth;
		h = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	else if (document.body){
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	return {width:w, height:h};
}

// window 사이즈 구함
function getWindowSize()
{
	var h = 0;
	var w = 0;
	if (window.innerWidth) {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	if (document.body.offsetWidth) {
		w = document.body.offsetWidth;
		h = document.body.offsetHeight;
	}

	return {height:h, width:w};
}

var C9 = {
	Window:function(_opt){
		this.opt = _opt;

		this.el = C9._Frame(this.opt);
		this.bg = null;
		if(this.opt.modal){
			this.bg = C9._CreateBackground(_opt.el);
		}
		return this;
	},
	_CreateBackground:function(_el){
		//모달일 경우 배경
		var div = document.getElementById('c9layer_background_'+_el);
		if(div==null){
			div = document.createElement('div');
			div.id = 'c9layer_background_'+_el;
			div.style.display='none';
			div.style.backgroundColor = '#DDDDDD';
			div.style.position = 'absolute';
			div.style.overflow = 'visible';
			div.style.height = '100%'; //getBodySize().height;
			div.style.width = getBodySize().width;
			div.style.left = '0';
			div.style.top = '0';
			div.style.zIndex = 1000;
			div.style.opacity = '0.5';
			document.body.appendChild(div);
		}
		return div;
	},
	_Frame:function(opt){
		var el = null;
		
		if(!opt.el){
			el = document.createElement('div');
			el.style.display='none';
			document.body.appendChild(el);
		} else {
			el = document.getElementById(opt.el);
		}
		if(el==null) return null;

		if(opt.src) {
			el.innerHTML = opt.src;
		}
        
		opt.width = opt.width || el.style.pixelWidth;
		opt.height = opt.height || el.style.pixelHeight;

		if(opt.width && opt.height){
			el.style.overflow = 'hidden';
			el.style.width = opt.width;
			el.style.height = opt.height;
		}
		if(!opt.transparent){
			el.style.backgroundColor = 'transparent';
		}
		if(opt.center){
			C9._SetWindowCenter(el, opt.width, opt.height);
		} else {
			if(opt.top || opt.left){
				el.style.position = 'absolute';
				if(opt.top){ el.style.top = opt.top; }
				if(opt.left){ el.style.left = opt.left; }
			}
		}
		
		el.style.zIndex = 1001;
		return el;
	},
	_SetWindowCenter:function(obj, w, h){
			var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
			obj.style.position  = 'absolute';
			obj.style.left = (getWindowSize().width/2) - (w/2);
			obj.style.top = scrollTop+(getWindowSize().height/2)-(h/2);
	}
};



C9.Window.prototype.show = function(){
	if(this.el==null) return;
	if(this.bg){ this.bg.style.display='block'; }
	
	this.el.style.display='block';
	
	//this.el.className="layer_show";
	if(this.opt.center){
		var win = this;
		setTimeout(function(){ C9.repositionTimer(win); }, 200);
	}
};

C9.Window.prototype.hide = function(){
	if(this.bg){ this.bg.style.display='none'; }
	if(this.el){ 
		this.el.style.display='none'; 
		//this.el.className="layer_hide";	
	}
}

C9.repositionTimer = function(win){
	var el = win.el;
	var opt = win.opt;
	var bg = win.bg;

	if(bg && bg.style && "none"!=bg.style.display){
		bg.style.height = '100%'; //getBodySize().height;
		bg.style.width = getBodySize().width;
	}

	if(el && el.style && "none"!=el.style.display){
		if(opt.center){
			C9._SetWindowCenter(el, opt.width, opt.height);
			setTimeout(function(){ C9.repositionTimer(win); }, 200);
		}
	}
}

var layerPopup = function() {
	var win;

	return {
		init : function() {
		},
		hide : function() {
			win.hide();
		},
		show : function(id, wsize,hsize) {
			if(!win){
				win = new C9.Window({
					el:id,
					//modal:true,
					center:true,
					width:wsize,
					height:hsize
				});						
			}
		
			win.show();
		}
	};
}();

var layerPopup2 = function() {
	var win;

	return {
		init : function() {
		},
		hide : function() {
			win.hide();
		},
		show : function(id, wsize,hsize) {
			if(!win){
				win = new C9.Window({
					el:id,
					//modal:true,
					center:true,
					width:wsize,
					height:hsize
				});						
			}
		
			win.show();
		}
	};
}();	

