//브라우져 체크
var appname = navigator.appName;
var useragent = navigator.userAgent;
if(appname == "Microsoft Internet Explorer") appname = "IE";
var IE55 = (useragent.indexOf('MSIE 5.5')>0);  //5.5 버전
var IE6 = (useragent.indexOf('MSIE 6')>0);     //6.0 버전
var IE7 = (useragent.indexOf('MSIE 7')>0);     //7.0 버전
var IE8 = (useragent.indexOf('MSIE 8')>0);     //8.0 버전

/*셀렉트 박스 숨기기 IE6.0 전용*/
function selectBoxNone(check){
	if(IE6){
		var obj = document.getElementsByTagName("select");
		for(var i=0;i<obj.length;i++){
			obj[i].style.visibility = check;
		}
	}
}
/*/셀렉트 박스 숨기기 IE6.0 전용*/

function dimLayer(the_id, the_width, the_height) {
	if(the_id=="none"){
		document.getElementById('siteMapSec').style.display = 'none';
		document.getElementById('loginSec').style.display = 'none';
		document.getElementById('dimLayer').style.display = "none";
		selectBoxNone('visible');
	} else {
		var lfrm = document.getElementById(the_id);
		if(the_width=="none"){
			lfrm.style.display = 'none';
			document.getElementById('dimLayer').style.display = "none";
			selectBoxNone('visible');
		} else {
			dimLayerView(null);
			lfrm.style.display = 'block';
			selectBoxNone('hidden');
		}
	}
}

function dimLayerView(dim) {
	var oBody = ( document.compatMode && document.compatMode!="BackCompat" ) ? document.documentElement : document.body  ;
	var cheight= ( oBody.scrollHeight > oBody.clientHeight ? oBody.scrollHeight : oBody.clientHeight  ) + 'px';
	if(!dim){document.getElementById('dimLayer').style.display = "block";
	document.getElementById('dimLayer').style.height = cheight;
	}
}

/*LNB 플래시높이조절*/
function lnbTotalHeight(fheight){
	document.getElementById('lnb').style.height = fheight+"px";
}
/*/LNB 플래시높이조절*/

/*AD VIEW*/
var adViewTxtNow = 0;
var adViewImgNow = 0;
var adViewCountNow = 0;
var adViewPlayNow = 1;
var adViewPlayType;
var adViewPlayer;
function adViewInit(){
	var txtList = $('adViewTxt').getElementsByTagName('li');
	var imgList = $('adViewImg').getElementsByTagName('li');
	for(var i=0;i<txtList.length;i++){
		txtList[i].style.left = $('adViewTxt').offsetWidth*i + adViewTxtNow + 'px';
		imgList[i].style.left = $('adViewImg').offsetWidth*i + adViewImgNow + 'px';
	}
}
function adViewPrev(click){
	adViewPlayNow = (click=='click')? 1 : 0 ;
	adViewPlay('stop');
	adViewCountNow--;
	var count = $('adViewTxt').getElementsByTagName('li').length-1;
	if(adViewCountNow<0){
		adViewCountNow = count;
		adViewTxtNow = $('adViewTxt').offsetWidth * count * -1;
		adViewImgNow = $('adViewImg').offsetWidth * count * -1;
	} else {
		adViewTxtNow = adViewTxtNow + $('adViewTxt').offsetWidth;
		adViewImgNow = adViewImgNow + $('adViewImg').offsetWidth;
	}
	adViewInit();

	if(click=='click') {
		adViewPlay('stop', 'prev');
	} else {
		adViewPlay('start', 'prev');
	}
}
function adViewNext(click){
	adViewPlayNow = (click=='click')? 1 : 0 ;
	adViewPlay('stop');
	adViewCountNow++;
	var count = $('adViewTxt').getElementsByTagName('li').length-1;
	if(adViewCountNow>count){
		adViewTxtNow = 0;
		adViewImgNow = 0;
		adViewCountNow = 0;
	} else {
		adViewTxtNow = adViewTxtNow - $('adViewTxt').offsetWidth;
		adViewImgNow = adViewImgNow - $('adViewImg').offsetWidth;
	}
	adViewInit();

	if(click=='click') {
		adViewPlay('stop', 'next');
	} else {
		adViewPlay('start', 'next');
	}
}

function adViewPlay(play, type){
	adViewInit();
	adViewPlayNow = (play=='stopBtn')? 0 : 1 ;
	if(type=='next'){
		functionType = 'adViewNext()';
		adViewPlayType = type;
	} else {
		functionType = 'adViewPrev()';
		adViewPlayType = type;
	}
	(play=='start' && adViewPlayNow==1)? adViewPlayer = setInterval(functionType,5000) : clearTimeout(adViewPlayer);
}
/*/AD VIEW*/

/*롤링*/
var js_rolling = function(box){
	// 시간단위는 ms로 1000이 1초
	if(box.nodeType==1){
		this.box = box;
	}else{
		this.box = document.getElementById(box);
	}
	this.is_rolling = false;
	this.mouseover_pause = true;
	this.direction = 1; //1:top, 2:right, 3:bottom, 4:left (시계방향) // 1번과 4번만 됨
	this.children =	null;
	this.move_gap = 1;	//움직이는 픽셀단위
	this.time_dealy = 100; //움직이는 타임딜레이
	this.time_dealy_pause = 1000;//하나의 대상이 새로 시작할 때 멈추는 시간, 0 이면 적용 안함
	this.time_timer=null;
	this.time_timer_pause=null;
	this.mouseover=false;
	this.init();
	this.set_direction(this.direction);
}
js_rolling.prototype.init = function(){
	this.box.style.position='relative';
	this.box.style.overflow='hidden';
	var children = this.box.childNodes;
	for(var i=(children.length-1);0<=i;i--){
		if(children[i].nodeType==1){
			children[i].style.position='relative';
		}else{
			this.box.removeChild(children[i]);
		}
	}
	var thisC=this;

	this.box.onmouseover=function(){
		if(!thisC.mouseover_pause){	return;	}
		thisC.mouseover=true;
		if(!thisC.time_timer_pause){
			thisC.pause();
		}
	}
	this.box.onmouseout=function(){
		if(!thisC.mouseover_pause){return;}
		thisC.mouseover=false;
		if(!thisC.time_timer_pause){
			thisC.resume();
		}
	}	
}
js_rolling.prototype.set_direction = function(direction){
	this.direction=direction;
	if(this.direction==2 ||this.direction==4){
		this.box.style.whiteSpace='nowrap';
	}else{
		this.box.style.whiteSpace='normal';
	}
	var children = this.box.childNodes;
	for(var i=(children.length-1);0<=i;i--){
			if(this.direction==1){
				children[i].style.display='block';
			}else if(this.direction==2){
				children[i].style.textlign='right';
				children[i].style.display='inline';
			}else if(this.direction==3){
				children[i].style.display='block';
			}else if(this.direction==4){
				children[i].style.display='inline';
			}
	}
	this.init_element_children();	
}
js_rolling.prototype.init_element_children = function(){
	var children = this.box.childNodes;
	this.children = children;
	for(var i=(children.length-1);0<=i;i--){
			if(this.direction==1){
				children[i].style.top='0px';
			}else if(this.direction==2){
				children[i].style.left='-'+this.box.firstChild.offsetWidth+'px';
			}else if(this.direction==3){
				children[i].style.top='-'+this.box.firstChild.offsetHeight+'px';
			}else if(this.direction==4){
				children[i].style.left='0px';
			}
	}
}
js_rolling.prototype.act_move_up = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.top=(parseInt(child.style.top)-this.move_gap)+'px';
	}
	if((this.children[0].offsetHeight+parseInt(this.children[0].style.top))<=0){
		this.box.appendChild(this.children[0]);
		this.init_element_children();
		this.pause_act();		
	}
}
js_rolling.prototype.move_up = function(){
	if(this.direction!=1&&this.direction!=3){return false;}
	this.box.appendChild(this.children[0]);
	this.init_element_children();
	this.pause_act();	
}
js_rolling.prototype.act_move_down = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.top=(parseInt(child.style.top)+this.move_gap)+'px';
	}
	if(parseInt(this.children[0].style.top)>=0){
		this.box.insertBefore(this.box.lastChild,this.box.firstChild);
		this.init_element_children();
		this.pause_act();	
	}
}
js_rolling.prototype.move_down = function(){
	if(this.direction!=1&&this.direction!=3){return false;}	
	this.box.insertBefore(this.box.lastChild,this.box.firstChild);
	this.init_element_children();
	this.pause_act();
}
js_rolling.prototype.act_move_left = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.left=(parseInt(child.style.left)-this.move_gap)+'px';
	}
	if (this.children.length > 0) {
		if((this.children[0].offsetWidth+parseInt(this.children[0].style.left))<=0){
			this.box.appendChild(this.box.firstChild);
			this.init_element_children();
			this.pause_act();
		}
	}
}
js_rolling.prototype.move_left = function(){
	if(this.direction!=2&&this.direction!=4){return false;}		
	this.box.appendChild(this.box.firstChild);
	this.init_element_children();
	this.pause_act();		
}
js_rolling.prototype.act_move_right = function(){
	for(var i = 0,m=this.children.length;i<m;i++){
		var child = this.children[i];
		child.style.left=(parseInt(child.style.left)+this.move_gap)+'px';
	}
	
	if(parseInt(this.box.lastChild.style.left)>=0){
		this.box.insertBefore(this.box.lastChild,this.box.firstChild);
		this.init_element_children();
		this.pause_act();		
	}
}
js_rolling.prototype.move_right = function(){
	if(this.direction!=2&&this.direction!=4){return false;}			
	this.box.insertBefore(this.box.lastChild,this.box.firstChild);
	this.init_element_children();
	this.pause_act();
}
js_rolling.prototype.start = function(){ //롤링 시작
	var thisC = this;
	this.stop();
	this.is_rolling = true;
	var act = function(){
		if(thisC.is_rolling){
			if(thisC.direction==1){thisC.act_move_up();}
			else if(thisC.direction==2){thisC.act_move_right();}
			else if(thisC.direction==3){thisC.act_move_down();}
			else if(thisC.direction==4){thisC.act_move_left();}
		}
	}
	this.time_timer = setInterval(act,this.time_dealy);
}
js_rolling.prototype.pause_act = function(){ //일시 동작
	if(this.time_dealy_pause){
		var thisC = this;
		var act = function(){thisC.resume();clearTimeout(thisC.time_timer_pause);thisC.time_timer_pause=null;}
		if(this.time_timer_pause){clearTimeout(this.time_timer_pause);}
		this.time_timer_pause = setTimeout(act,this.time_dealy_pause);
		this.is_rolling = false;
	}
}
js_rolling.prototype.pause = function(){ //일시 멈춤
	if(this.time_timer_pause){clearTimeout(this.time_timer_pause);}
	this.is_rolling = false;
}
js_rolling.prototype.resume = function(){ //일시 멈춤 해제
	if(!this.mouseover){
		this.is_rolling = true;
	}
}
js_rolling.prototype.stop = function(){ //롤링을 끝냄
	this.is_rolling = false;
	if(!this.time_timer){
		clearInterval(this.time_timer);
	}
	this.time_timer = null
}
/*/롤링*/

/*select box*/
function dselect(){
	var select = $$('div.dselectbox');
	var selectList = $$('div.selectlist');
	var selectCount = select.length;
	var listWidth;
	try {
		for(var i=0; i<selectCount ; i++){
			listWidth = (IE6 && !IE7) ? parseInt(select[i].style.width) + 'px' : parseInt(select[i].style.width) + 'px';
			selectList[i].style.width = listWidth;
			selectList[i].hide();
		}
	} catch(e) {}
}
function listView(num, evt){
	if (Prototype.Browser.IE) {
		event.cancelBubble = true;
	} else {
		evt.stopPropagation();
	}
	var list = $$('div.selectlist');
	if(list[num-1] == undefined){
		if($('selectlist'+num).style.display =='none'){
			selectHide();
			$('selectlist'+num).show();
		} else {
			$('selectlist'+num).hide();
		}
	} else {
		if(list[num-1].style.display=='none'){
			selectHide();
			list[num-1].show();
		} else {
			list[num-1].hide();
		}
	}
}
function selectHide(){
	$$('div.selectlist').invoke('hide');
}
function selectCheck(txt,valu,idx,link){
	if(valu!='link'){
		$('selectValue'+idx).value = valu;
	} else {
		location.href = link;
	}
	$('selectTxt'+idx).update(txt);
}
function selectClass(obj,over){
	if(over == 'over'){
		obj.className = (obj.className == 'last')?'last on':'on';
	} else {
		obj.className = (obj.className == 'last on')?'last':'';
	}
}
/*/select box*/

/*팝업 오픈*/
function popupOpen(url, name, w, h, s){
	if(w==null){
		window.open(url,name);
	} else {
		window.open(url,name,'width='+w+', height='+h+', scroll='+s);
	}
}
/*/팝업 오픈*/

// 링크 점선 없애기
function bluring(){
	if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
}
document.onfocusin=bluring;

// 이용안내
var tabNum = 0;
function usageView(num){
	if(num == "prev"){
		tabNum--;
		if(tabNum<0) tabNum=5;
	} else if(num == "next") {
		tabNum++;
		if(tabNum>5) tabNum=0;
	} else {
		tabNum=num;
	}
	var obj = $("tabList1").getElementsByTagName("li");
	for(var i=0;i<obj.length;i++){
		var imgEl = obj[i].getElementsByTagName("img").item(0);
		imgEl.src = imgEl.src.replace("on.gif", "off.gif");

		$("tabList1_"+i).style.display = "none";
	}

	var noImg = obj[tabNum].getElementsByTagName("img").item(0);
	noImg.src = noImg.src.replace("off.gif", "on.gif");
	$("tabList1_"+tabNum).style.display = "";
}

//게시판 관련
function goBoardPage(page) {
	$("fmPaging").pg.value = page;
	$("fmPaging").submit();
}
function goBoardList() {
	$("fmPaging").sf.value = "0";
	$("fmPaging").sw.value = "";
	$("fmPaging").pg.value = "1";
	$("fmPaging").submit();
}
function goBoardSearch() {
	if (!$("inputSearchWord").value && $("inputSearchWord").value.length < 2) {
		alert("검색어를 두 자 이상 입력하세요.");
		$("inputSearchWord").focus();
	} else if ($("inputSearchWord").value.indexOf("'")>=0) {
		alert("작은 따옴표(')는 검색할 수 없습니다.");
		$("inputSearchWord").focus();
	} else if ($("inputSearchWord").value.indexOf("\"")>=0) {
		alert("큰 따옴표(\")는 검색할 수 없습니다.");
		$("inputSearchWord").focus();
	} else {
		$("fmPaging").sf.value = $("inputSearchField").value;
		$("fmPaging").sw.value = $("inputSearchWord").value;
		$("fmPaging").pg.value = "1";
		$("fmPaging").submit();
	}
}
function goBoardView(idx, viewPage) {
	$("fmView").idx.value = idx;
	$("fmView").taret = "_self";
	$("fmView").method = "get";
	$("fmView").action = (viewPage)? viewPage : location.pathname.replace(/List.jsp/gim, "Read.jsp");
	$("fmView").submit();
}
function goBoardBackList() {
	$("fmPaging").action = location.pathname.replace(/Read.jsp/gim, "List.jsp");
	$("fmPaging").submit();
}