// 왼쪽, 오른쪽 공백문자 제거
function trim(strSource) {
	re = /^\s+|\s+$/g;
	return strSource.replace(re, '');
}

// 왼쪽 공백문자 제거
function ltrim(strSource) {
	re = /^\s+/g;
	return strSource.replace(re, '');
}

// 오른쪽 공백문자 제거
function rtrim(strSource) {
	re = /\s+$/g;
	return strSource.replace(re, '');
}

// 빈 문자열 검사
function isEmptyString (strSource) {
	return trim (strSource).length < 1;
}

// 개체의 표시 of/off
function toggleView (objId) {
	try {
		var obj = document.getElementById (objId);
		
		if (obj.style.display == "none")
			obj.style.display = "block";
		else
			obj.style.display = "none";
	} catch (e) {
	}
}

function getByteLength(input,maxLng,areaNm) 
{
    var byteLength = 0;
    var tmpInput = "";

    for (var inx = 0; inx < input.length; inx++) 
    {
        var oneChar = escape(input.charAt(inx));
        if ( oneChar.length == 1 ) 
        {
            byteLength ++;
        } else if (oneChar.indexOf("%u") != -1) 
        {
            byteLength += 2;
        } else if (oneChar.indexOf("%") != -1)
        {
            byteLength += oneChar.length/3;
        }
        if(byteLength > (maxLng-1)){
        	alert(maxLng+"byte 이상 사용할수 없습니다.");
        	byteLength-= 2;
        	if(areaNm == 1){
        		document.frm.writeCmmnt.value=tmpInput;
        		return byteLength;
        		
        	}else{
        		document.frm.updateCmmnt.value=tmpInput;
        		return byteLength;
        	
        	}
        	input.length = byteLength;
        } else {
        	tmpInput += input.charAt(inx);
        }
    }
    return byteLength;
}


// 파일 추가
function addFile (tableId, maxFileCnt, fileCnt, fileId) {

	var table = document.getElementById (tableId);
	if (table == null)
		return false;
		
		
	var rows = table.rows;

	var fileCount = getFileCount (rows, maxFileCnt, fileCnt, fileId);
	
	if (fileCount >= maxFileCnt) {
		alert ("첨부파일은 최대 "+ maxFileCnt + "개까지 허용합니다.");
		return;
	}

	
	var firstCell = rows[0].cells[0];
	
	var row = table.insertRow (rows.length);
	var cell = row.insertCell (0);

	cell.className = firstCell.className;
	cell.innerHTML = firstCell.innerHTML;
}


// 파일 개수 검사
function getFileCount (rows, maxFileCnt, fileCnt, fileId) {
	var curCnt = 0;
	if (fileId && fileCnt) {
		for (var i = 0; i < fileCnt; i++) {
			if (!document.getElementById (fileId + "_" + i).checked)
				curCnt++; 		
		}
	}
	
	if (rows) {
		if (maxFileCnt > 1) 
			curCnt = curCnt + rows.length;
	}
			
	return curCnt;
}


// 기존파일 삭제 대상 해제할 경우, 파일 개수 검사 후 처리.
function uncheckFile (tableId, maxFileCnt, fileCnt, fileId, cntl) {
	if (cntl.checked)
		return;
		
	var table = document.getElementById (tableId);
	if (table == null)
		return false;
		
		
	var rows = table.rows;

	var fileCount = getFileCount (rows, maxFileCnt, fileCnt, fileId);
	
	if (fileCount > maxFileCnt) {
		alert ("첨부파일은 최대 "+ maxFileCnt + "개까지 허용합니다.\n" +
			"추가한 파일을 삭제하거나 기존 파일을 삭제하도록 체크한 후 처리할 수 있습니다."
		);
		cntl.checked = true;
	}
}

// 파일 삭제
function delFile (tableId, cntl) {
	var table = document.getElementById (tableId);
	if (table == null)
		return false;
		
	var rows = table.rows;
	if (rows == null)
		return false;
		
	if (rows.length == 1) {
		addFile (tableId);
		table.deleteRow (0);
		return;
	}
	
	var row = cntl.parentNode.parentNode;
	for (var i = 0; i < rows.length; i++) {
		if (rows[i] == row) {
			table.deleteRow (i);
			break;
		}
	}
}

// 정수만 입력한다.
function onlyInteger () {
	var keyCode = event.keyCode;
	
	if ((keyCode > 47 && keyCode < 58) || (keyCode > 95 && keyCode < 106) || isPermittedKeyCode (keyCode)) {
		event.returnValue = true;
	} else {
		event.returnValue = false;
	}
}

// 키입력시 항상 허용되어야 할 키들 : backspace, tab, enter, 화살표  등
function isPermittedKeyCode (keyCode) {
	var permittedKeyCode = [8, 9, 13, 46, 36, 35];
	var result = false;
	
	for (var i = 0; i < permittedKeyCode.length; i++) {
		if (keyCode == permittedKeyCode[i]) {
			result = true;
			break;
		}
	}

	return result;
}

function cyberOpen(){
	window.open("/cyberPR/main.action","cyberPR","width=750,height=530");
}

function popup(url){
	window.open(url);
}


function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
	
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// 2009.03.11 메인메뉴 뷰를 위해 추가 - 박영환
function changeImage (control, source) {
	control.src = source;
}
// 2009.03.11 메인메뉴 뷰를 위해 추가 - 박영환
function showMenu (menuNo, subMenuNo, subMenuCount) {
	if (!subMenuNo) { // 대메뉴 처리
		var menuCount = 6;

		for (var i = 1; i <= menuCount; i++) {
			document.getElementById ("submenu_" + i).style.visibility = "hidden";
			document.getElementById ("menu_" + i).src = "/images/mainmenu/menu_" + i + ".gif";
		}

		document.getElementById ("submenu_" + menuNo).style.visibility = "visible";
		document.getElementById ("menu_" + menuNo).src = "/images/mainmenu/menu_" + menuNo + "_up.gif";
	} else {	// 서브메뉴 처리
		for (var i = 1; i <= subMenuCount; i++) {
			document.getElementById ("submenu_" + menuNo + "_" + i).src = "/images/mainmenu/submenu_" + menuNo + "_" + i + ".gif";
		}
		document.getElementById ("submenu_" + menuNo + "_" + subMenuNo).src = "/images/mainmenu/submenu_" + menuNo + "_" + subMenuNo + "_up.gif";
	}
}


//화면 Zoom
	var zoomRate = 20;			//확대/축소시 증감률
	//var maxRate = 300;			//최대확대률
	var maxRate = 160;			//최대확대률
	var minRate = 100;			//최소축소률

	function zoomInOut(contentid, how) {

		if(getCookie("zoomVal") != null && getCookie("zoomVal") != ""){
			//document.all[contentid].style.zoom = getCookie("zoomVal");
			document.body.style.zoom = getCookie("zoomVal");
			currZoom=getCookie("zoomVal");
		}
		else{
			//document.all[contentid].style.zoom = '100%'; 
			document.body.style.zoom = '100%'; 
			currZoom = '100%';
		}
		
		if (((how == "in") && (parseInt(currZoom) >= maxRate)) || ((how == "out") && (parseInt(currZoom) <= minRate)) ) {
			return; 
		}
		if (how == "in") {
			//document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)+zoomRate+'%'
			document.body.style.zoom = parseInt(document.body.style.zoom)+zoomRate+'%'  //<=요기만 수정하면 됨
		}
		else {
			//document.all[contentid].style.zoom = parseInt(document.all[contentid].style.zoom)-zoomRate+'%'
			document.body.style.zoom = parseInt(document.body.style.zoom)-zoomRate+'%' //<= 요기만 수정하면 됨
		}
		//SetCookie("zoomVal",document.all[contentid].style.zoom);
		//SetCookie("zoomVal",document.body.style.zoom);
		SetCookie("zoomVal",document.body.style.zoom, 1);
	}



	function SetCookie( name, value, expiredays ){
		var todayDate = new Date();
		todayDate.setDate( todayDate.getDate() + expiredays );
		document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" ;
	}
	
	function GoZoom(contentid){
		if(getCookie("zoomVal") != null && getCookie("zoomVal") != ""){
			//document.all[contentid].style.zoom = getCookie("zoomVal");
			document.body.style.zoom = getCookie("zoomVal");
			currZoom=getCookie("zoomVal");
		}
		else{
			//document.all[contentid].style.zoom = '100%'; 
			document.body.style.zoom = '100%'; 
			currZoom = '100%';
		}
	}
	
	function initZoomDisplay(){
		var currZoom = "100%" ;
		if(getCookie("zoomVal") != null && getCookie("zoomVal") != ""){
			currZoom=getCookie("zoomVal");
		}
		document.body.style.zoom = currZoom ;
	}


 
	var defsize = 12;
	function zoom_it(n) {
		defsize += n;
		var divs_body = document.getElementsByTagName("body");
		var divs_table = document.getElementsByTagName("table");
		var divs_td = document.getElementsByTagName("td");
		var divs_div = document.getElementsByTagName("div");
		var divs_a = document.getElementsByTagName("a");
		var divs_tr = document.getElementsByTagName("tr");
		var divs_span = document.getElementsByTagName("span");
		var i=0;
		for(i=0,len=divs_body.length ; i<len ; i++) { 
			divs_body[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_table.length ; i<len ; i++) { 
			divs_table[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_td.length ; i<len ; i++) { 
			divs_td[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_div.length ; i<len ; i++) { 
			divs_div[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_a.length ; i<len ; i++) { 
			divs_a[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_tr.length ; i<len ; i++) { 
			divs_tr[i].style.fontSize = defsize + "px";
		}
		for(i=0,len=divs_span.length ; i<len ; i++) { 
			divs_span[i].style.fontSize = defsize + "px";
		}
	} 
 
	function zoom_de() {
		defsize=12;
		var divs_body = document.getElementsByTagName("body");
		var divs_table = document.getElementsByTagName("table");
		var divs_td = document.getElementsByTagName("td");
		var divs_div = document.getElementsByTagName("div");
		var divs_a = document.getElementsByTagName("a");
		var divs_tr = document.getElementsByTagName("tr");
		var divs_span = document.getElementsByTagName("span");
		var i=0;
		for(i=0,len=divs_body.length ; i<len ; i++) { 
			divs_body[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_table.length ; i<len ; i++) { 
			divs_table[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_td.length ; i<len ; i++) { 
			divs_td[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_div.length ; i<len ; i++) { 
			divs_div[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_a.length ; i<len ; i++) { 
			divs_a[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_tr.length ; i<len ; i++) { 
			divs_tr[i].style.fontSize = "12px";
		}
		for(i=0,len=divs_span.length ; i<len ; i++) { 
			divs_span[i].style.fontSize = "12px";
		}
	} 

//------------------------------------------------------------------
//		화면 확대 축소
//------------------------------------------------------------------

	var nowZoom = 100; // 현재비율
	var maxZoom = 140; // 최대비율
	var minZoom = 80; // 최소비율(현재와 같아야 함)


    //화면 키운다.
	function zoomIn() {
		if (nowZoom < maxZoom) {
			nowZoom += 5; // 10%씩 커진다.
		} else {
			return;
		}

		document.body.style.zoom = nowZoom + "%";
	}
	
	//화면 줄인다.
	function zoomOut() {
		if (nowZoom > minZoom) {
			nowZoom -= 5; // 10%씩 작아진다.
		} else {
			return;
		}

		document.body.style.zoom = nowZoom + "%";
	}
	//화면 기본.
	function zoomOr() {
		nowZoom = 100; // 기본크기로
		document.body.style.zoom = nowZoom + "%";
	}
//화면 Zoom

// 하단 관련사이트 링크
	function openorgan(popNm,frm) {
		var organ = document.getElementById(frm);
		if (organ.options[organ.selectedIndex].value =="" ) {
//			alert ("관련단체명을 선택해주세요");
			return;
		}
		window.open(organ.options[organ.selectedIndex].value,popNm);
	}
	
//투명한 PNG 이미지 처리 방법 setPng24 	
function setPng24(obj) {
  obj.width=obj.height=1;
  obj.className=obj.className.replace(/\bpng24\b/i,''); 
  obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+obj.src+"',sizingMethod='image');"
  obj.src='/images/blank_png.gif'; 
  return '';
}
