/* ------------------------------------------------------------
 * Name      : common.js
 * Created   : 2009/11 cnscamp by psj
 * Updated  :
 ------------------------------------------------------------ */
 
 /*----------------------------------------------------------------------------------------
* 	isAccess(e)
*	example : 
*	if (isAccess(event)) {
*	}
*	return : true | false
*	date : 2007.5.1

*	descript : 
	마우스클릭이나 키보드로 선택된 상태인지 판단

	탭키로 해당 영역에 포커스가 간후 다시 탭으로 넘어갈 경우 onkeypress 이벤트가 발생하여 원하는 이벤트 처리가 안된다.
	마우스나 엔터키가 눌러진 경우 keycode = 1)만 이벤트가 발생하게 처리한다.
	Netscape/Firefox/Opera 의 경우 e.which 1로 체크, Safari 의 경우 window.event 0 으로 체크
	IE의 경우 event.button 이나 keycode 13(엔터키)로 체크
----------------------------------------------------------------------------------------*/
function isAccess(e) {
	
	var keynum;
	var ismouseClick = 1;
	
	if (window.event) {		//IE & Safari
		keynum = e.keyCode;
		
		//Safari의 경우 마우스클릭은 keynum 0 이 넘어옴
		if (event.button == 0 || keynum == 0){
			ismouseClick = 0;
		}		
		
	} else if ( e.which ){		// Netscape/Firefox/Opera
		keynum = e.which;
		
		if (keynum == 1) {
			ismouseClick = 0;
		}		
		
	}
	
	//마우스 클릭이거나 엔터키를 누른경우 true값 반환
	if ( ismouseClick == 0 || keynum == 13 ) {
		return true;
	} else {
		return false;
	}
}


/*	글자확대축소 */	
var currentFontSize = 1;

function zoomUtil(state, e){
	var idx;
	var arrFontSize = new Array();

	arrFontSize[0] = "65%";
	arrFontSize[1] = "75%";
	arrFontSize[2] = "85%";
	arrFontSize[3] = "100%";
	arrFontSize[4] = "110%";
	arrFontSize[5] = "120%";
	arrFontSize[6] = "130%";
	
	if (isAccess(e)) {
		if (state == "plus") {		
						
			if (currentFontSize < 6 ) {
				idx = currentFontSize + 1;
				currentFontSize = idx;
			}else{
				idx = 6;
				currentFontSize = idx;
			}			
		
		} else if (state == "default") {
			idx = 1;
			currentFontSize = idx;
		
		} else if (state == "minus") {			
			
			if ( currentFontSize >= 1) {
				idx = currentFontSize - 1;
				currentFontSize = idx;
			}else{
				idx = 0;
				currentFontSize = idx;
			}
			
		}		
	}
	
	document.body.style.fontSize = arrFontSize[idx];
	
	return false;	
}
 

/* 화면확대 스크립트(IE에서만 동작) */ 
var zoomRate = 10;
var curRate = 100;
var minRate = 100;
var maxRate = 200;
function initZoom()
{
 document.body.style.position="relative";
 document.body.style.zoom = '100%';
 curRate = 100;
}

initZoom();


function zoomInOut(value){
 var ue = navigator.userAgent.toLowerCase();
 if(ue.indexOf('firefox')!=-1){ alert("익스플로러에서만 동작합니다."+"\n파이어폭스 브라우저 메뉴 [보기]-[크기조정]을 이용하세요."); }
 else if(ue.indexOf('opera')!=-1){ alert("익스플로러에서만 동작합니다."+"\n오페라 브라우저 메뉴 [보기]-[Zoom]을 이용하세요."); }
 else if(ue.indexOf('chrome')!=-1){ alert("익스플로러에서만 동작합니다."+"\n구글 크롬 브라우저 메뉴 [글꼴 크기]를 이용하세요."); }
 else if(ue.indexOf('safari')!=-1){ /* alert("익스플로러에서만 동작합니다."+"\n사파리 브라우저 메뉴 [보기]-[텍스트 크게]/[텍스트 작게]를 이용하세요."); */ }
 else if(ue.indexOf('msie')!=-1){  }
 else { alert("익스플로러에서만 동작합니다.\n"+ue+"\n브라우저 메뉴의 확대축소 기능을 이용하세요."); }
 if(((value=="plus")&&(curRate >= maxRate))||((value == "minus") && (curRate <= minRate))){return;} 
  if(value=="plus"){curRate = parseInt(curRate) + parseInt(zoomRate);}
  else if (value=="minus"){curRate = parseInt(curRate) - parseInt(zoomRate);}
  else{curRate = 100}
  document.body.style.zoom = curRate + '%';
}

 

/*******************************************************************************************
 ' 기   능 : 팝업가운데띄우기
 ' 사용법 : onclick="open_window('파일명','pop', 910, 370, 'no', 'no', 'no', 'no')"
 ' 작성일 : 2009.04.13
*******************************************************************************************/

function open_window(url,  name,  width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = (toolbar == 'yes') ? 'yes' : 'no';
  menubar_str = menubar  == 'yes' ? 'yes' : 'no';
  statusbar_str = statusbar  == 'yes' ? 'yes' : 'no';
  scrollbar_str = scrollbar  == 'yes' ? 'yes' : 'no';
  resizable_str = resizable == 'yes'  ? 'yes' : 'no';
     // 팝업 가운데로 띄우기

   var left = Math.ceil( (window.screen.width  - width) / 2 );
   var top = Math.ceil( (window.screen.height - height) / 2 );

  
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

/*******************************************************************************************
 ' 기   능 : onAir 팝업
*******************************************************************************************/

function onair(){
	open_window('/onAir/onAir.jsp',  'onair',  400, 400, 'no', 'no', 'no', 'no', 'no');
}


function errorImageLoad(obj, errImg) {
		obj.src = errImg;
}

