// by babystar - selectbox.htc에서 쓰이는 createPopup함수는 XSS설정 전에 호출되어야 하므로
//               selectbox.htc의 createPopup이후에 동작하도록 하였음 (2009.09)
//document.domain = "kbs.co.kr";

function vodPlay(filename,title)
{
	var title = escape(title);
    window.open("/gz2010/player/vod/play.html?filename="+filename+"&title="+title,"vodplayer","toolbar=no, status=no,resizable=no,scrollbars=yes,width=880,height=500,left=0,top=0");
	
}

function VODPlayer(query,type,title) { 
	document.domain = "kbs.co.kr";
	try{
		URLString = document.location.href;
		tURLString = URLString.split("/"); 

		ctURLString = tURLString[2].split(".");
		cString= ctURLString[1]+"."+ctURLString[2]+"."+ctURLString[3];
	}catch(e){
		cString = "";
	}

	if(cString != "kbs.co.kr"){
	}else{
		var title = escape(title);
		gurl = 'http://ag2010.kbs.co.kr/player/vod/checkAsx_ag.php?'+query+'&type='+type+'&title='+title;
		vodplayer = window.open(gurl, 'vodplayerHigh1', 'width=350 , height=400 , resizable=no , status=0 , scrollbars=0 , menubar=no, toolbar=no, statusbar=no, fullscreen=no, channelmode=no,location=no,directories=no,alwaysRadised=0,top=10,left=390');
	}
}

/* 폰트 사이즈 조절 **********************************************************************/
function setCookie(name,value,expires) {
	var today = new Date();
	today.setDate( today.getDate() + parseInt( expires ) );
	document.cookie = name + "=" + escape( value ) + "; path=/" + ((expires == null)? "" : (" ; expires=" + expires.toGMTString()));
}

function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i< clen) {
		var j = i + alen;
		if(document.cookie.substring(i,j)==arg) {
			var end = document.cookie.indexOf(";",j);
			if(end == -1)
			end = document.cookie.length;
			return unescape(document.cookie.substring(j,end));
		}
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return null;
}

function getFontCookie() {
	var cookie = getCookie("news_font_size");
	if ( cookie == null ) return 14;
	if ( cookie.length ) return cookie;
	else return 14;
}

function scaleFont(val) {
	var content, lineHeight;
	content = document.getElementById("newsContents");
	if (val > 0) {
		if (fontSize <= 20) { //가장 큰 폰트사이트
			fontSize = fontSize + val;
			lineHeight = fontSize+Math.round(1.5*fontSize);
			content.style.fontSize = fontSize + "px";
		}
	} else {
		if (fontSize > 9) { //가장 작은 폰트사이트
			fontSize = fontSize + val;
			lineHeight = fontSize+Math.round(1.1*fontSize);
			content.style.fontSize = fontSize + "px";
		}
	}
	setCookie("news_font_size", fontSize, mydate);
}

// 뉴스 기사의 폰트를 기본 14으로 처리한다.
var mydate = new Date;
mydate.setDate(mydate.getDate()+1000);
setCookie("news_font_size", 14, mydate);
var fontSize = parseInt(getFontCookie());
function showhide1(what) {
	showhide01.style.display='none';
	showhide02.style.display='none';
	showhide03.style.display='none';
	if (what.style.display=='none') {
		what.style.display='';
	}
}

/* 레이어 SHOW/HIDE **********************************************************************/
function showdiv(targetEl, uniqid) {
	if(document.getElementById(targetEl)) document.getElementById(targetEl).style.display="block";
}
function hidediv(targetEl) {
	if(document.getElementById(targetEl)) document.getElementById(targetEl).style.display="none";
}

/* allou check start ****************************************************************************************/
// 서브릿 초기화 실행
function initServlet(oIframe) {
	oIframe.location.href = "/servlet/InitServlet";
}

// ############### 문자열 내의 모든 공백 문자 존재 여부 확인 ###########
function IsIncludeSpace(data){
	var lszTrim = data;
	var j = 0;
	 
	for(var i = 0; i < data.length; i++)
	{
		if(data.substring(i, i+1) == ' ')
			return true;
	}
	
	return false;
} 

// 빈 문자열인지 검사 (빈칸만 포함하는 문자열도 빈 문자열로 간주)
function IsEmpty(data) {
	var length = 0;
	var trimdata = TrimAll(data);

	if(trimdata.length == 0) return true;
	else return false;
} 

// 빈 문자열인지 검사하여 빈 문자열일 경우 메세지(failMessage) 출력
function checkEmpty(data, msg) {
	if(IsEmpty(data)) {
		alert(msg);
		return false;
	} else return true;
}

// RADIO 버튼이 선택되었는지 검사하여 선택되지 않았으면... 메시지(failMessage) 출력
function checkRadio(obj, msg) {
	try {
		var check = false;
		
		if (obj.length) {
			for (i=0; i<obj.length; i++) {
				if (obj[i].checked)
					check = true;
			}
		} else {
			if (obj.checked)
				check = true;
		}
		
		if (check)
			return true;
		else
			alert (msg);
	} catch (e) {
		alert(msg);
	}
	return check;
}

// ############### 문자열이 알파벳과 숫자로만 이루어져 있는지 확인 ######
function IsAlphaNum(str){
	var Alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var Number = '1234567890';
	var kiki = Alpha+Number;
	var i;
	for (i=0; i<str.length; i++){
		if(kiki.indexOf(str.substring(i,i+1))<0) {
			return false;
		}	
	}//for
	return true;
}

function IsMail(str){
var StrEmail = str;
	var ArrMatch = StrEmail.match(/^(\".*\"|[A-Za-z0-9_-]([A-Za-z0-9_-]|[\+\.])*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9][A-Za-z0-9_-]*)+)$/);
	if (ArrMatch == null) {
		return false;
	}
	var ArrIP = ArrMatch[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (ArrIP != null){
		for (var i = 1; i <= 4; i++) {
			if (ArrIP[i] > 255) {
				return false;
			}
		}
	}
	return true;
}

// ######################## 날짜인지 검사  ########################
function IsDate(str, format){
	var szFormat = format;
	if(mtrim(str).length < szFormat.length)
		return false;

	var cCurr = '';
	var arrDelim = new Array();
	var	arrDateFormat = new Array();
	var nPartIndex = -1;
	var nDelimPartIndex = -1;
	var cLastChar = '';

	for(nIndex = 0; nIndex < szFormat.length; nIndex++)	{
		cCurr = szFormat.charAt(nIndex);
		// 이전 문자와 같은 문자가 아닌 경우
		if(cCurr != cLastChar) {
			// 날짜 구분자인 경우
			if(cCurr != 'Y' && cCurr != 'M' && cCurr != 'D') {
				nDelimPartIndex++;
				arrDelim[nPartIndex] = new Object();
				arrDelim[nDelimPartIndex].nStartIndex = nIndex;
				arrDelim[nDelimPartIndex].cDelimChar = szFormat.charAt(nIndex);
			// 날짜 형식 문자인 경우
			} else {
				nPartIndex++;
				arrDateFormat[nPartIndex] = new Object();
				arrDateFormat[nPartIndex].nStartIndex = nIndex;
				arrDateFormat[nPartIndex].nCount = 1;
			}
			
			cLastChar = szFormat.charAt(nIndex);
		}
		// 이전 문자와 같은 문자인 경우
		else {
			arrDateFormat[nPartIndex].nCount++;
		}
	}

	// 날짜 검사
	for(nIndex = 0; nIndex < arrDateFormat.length; nIndex++) {
		if(IsNumber(
				str.substring(
					arrDateFormat[nIndex].nStartIndex
					, arrDateFormat[nIndex].nStartIndex + arrDateFormat[nIndex].nCount)) == false) {
			return false;
		}
	}
	// 구분자 검사
	for(nIndex = 0; nIndex < arrDelim.length; nIndex++)	{
		if(str.charAt(arrDelim[nIndex].nStartIndex) != arrDelim[nIndex].cDelimChar) {
			return false;
		}
	}

	return true;
}

/*--------------------------------------------------
 * 날짜형식 Check함수 호출
 * @param objValue : 날짜
 * @param gbn : 구분자 형식 EX)2001-02-03
//--------------------------------------------------*/
function IsDate2(obj,gbn) {
    var sDate = obj.value;
    var sPatt;
    var sYear = "", sMonth = "", sDay = "";
    var iYear = 0, iMonth = 0, iDay = 0;

    sPatt = /\//g; sDate = sDate.replace(sPatt,"");
    sPatt = /-/g;  sDate = sDate.replace(sPatt,"");
    sPatt = /\./g; sDate = sDate.replace(sPatt,"");

    if(sDate == "") {
        obj.value="";
        return false;
    }
    if(sDate.length != 8) {
        alert('올바른 날짜 형식이 아닙니다.');
        obj.value="";
        obj.focus();
        return false;
    } else {
        sYear = sDate.substring(0,4);
        sMonth = sDate.substring(4,6);
        sDay = sDate.substring(6,8);
    }

    if(isNaN(sYear) || isNaN(sMonth) || isNaN(sDay)) {
        obj.value="";
        obj.focus();
        return false;
    }

    iYear = parseInt(sYear,'10');
    iMonth = parseInt(sMonth,'10');
    iDay = parseInt(sDay,'10');

    if (iYear < 1) iYear = 0;
    if (iMonth < 1 || iMonth > 12)  iMonth = 0;
    if (iDay < 1) iDay = 0;

    if ( iMonth == 1 || iMonth == 3 || iMonth == 5 || iMonth == 7 || iMonth == 8 || iMonth == 10 || iMonth == 12) {
        if (iDay > 31) iDay = 0;
    } else if (iMonth == 4 || iMonth == 6 ||  iMonth == 9 || iMonth == 11) {
        if (iDay > 30) iDay = 0;
    } else if (iMonth == 2 ) {
        if (iYear % 4 != 0 || (iYear % 100 == 0 && iYear % 400 != 0)) {
            if (iDay > 28) iDay = 0;
        } else if(iDay > 29) {
            iDay = 0;
        }
    }
    if(iYear == 0 || iMonth == 0 || iDay == 0) {
        alert('올바른 날짜 형식이 아닙니다.');
        obj.value = "";
        obj.focus();
        return false;
    } else {
        obj.value = sYear + gbn + sMonth + gbn + sDay;
    }
    
    return true;
}

/*--------------------------------------------------
 * 시간형식 Check함수 호출
 * @param objValue : 시간
 * @param gbn : 구분자 형식 EX)15:12:23
//--------------------------------------------------*/
function IsTime(obj,gbn) {
    var sTime = obj.value;
    var sPatt;
    var sHour = "", sMin = "", sSec = "";
    var iHour = 0, iMin = 0, iSec = 0;

    sPatt = /\//g; sTime = sTime.replace(sPatt,"");
    sPatt = /-/g;  sTime = sTime.replace(sPatt,"");
    sPatt = /\./g; sTime = sTime.replace(sPatt,"");

    if(sTime == "") {
        obj.value="";
        return false;
    }
    if(sTime.length != 6) {
        alert('올바른 시간 형식이 아닙니다.');
        obj.value="";
        obj.focus();
        return false;
    } else {
        sHour = sTime.substring(0,2);
        sMin = sTime.substring(2,4);
        sSec = sTime.substring(4,6);
    }

    if(isNaN(sHour) || isNaN(sMin) || isNaN(sSec)) {
        obj.value="";
        obj.focus();
        return false;
    }

    if( !(sTime.match( /^[0-2]?[0-3]?[0-5]?[0-9]?[0-5]?[0-9]?$/ )) ) {
        alert('올바른 시간 형식이 아닙니다.');
        obj.value = "";
        obj.focus();
        return false;
    } else {
        obj.value = sHour + gbn + sMin + gbn + sSec;
    }
    
    return true;
}

// ######################## 시간인지 검사  ########################
function IsHour(hour, msg) {
	if (hour == "" || (hour > -1 && hour <= 24))
		return true;
	else {
		alert (msg);
		return false;
	}
}

// ######################## 분인지 검사  ########################
function IsMinute(minute, msg) {
	if (minute == "" || (minute > -1 && minute <= 59))
		return true;
	else {
		alert (msg);
		return false;
	}
}

//######################## 숫자인지 검사  ########################
//ime-mode:disabled
function keyPressOnlyNumber(){
    if((event.keyCode<48)||(event.keyCode>57)){
      event.returnValue=false;
    }
}

// ######################## 숫자인지 검사  ########################
function IsNumber(str){
	var Number = '1234567890';
	var kiki = Number;
	var i;
	for (i=0; i<str.length; i++){
		if(kiki.indexOf(str.substring(i,i+1))<0) {
			return false;
		}
	}//for
	return true;
}

// #################### 숫자('.' 포함)인지 검사  ####################
function IsNumber2(data){
	var Number = '1234567890';
	var etc = '.';
	var kiki = Number+etc;
	var i;
	for (i=0; i<data.length; i++){
		if(kiki.indexOf(data.substring(i, i+1))<0) {
			return false;
		}
	}//for
	return true;
}

// ################## 숫자(','/ '.' 포함)인지 검사  ##################
function IsNumber3(data){
	var Number = '1234567890';
	var etc = ',.';
	var kiki = Number+etc;
	var i;
	for (i=0; i<data.length; i++){
		if(kiki.indexOf(data.substring(i,i+1))<0) {
			return false; 
		}
	}//for
	return true;
}

// ############### 문자열이 '-'와 숫자로만 이루어져 있는지 확인 ######
function IsNumberExt(str){
	var Alpha = '-';
	var Number = '1234567890';
	var kiki = Alpha+Number;
	var i;
	for (i=0; i<str.length; i++){
		if(kiki.indexOf(str.substring(i,i+1))<0) {
			return false; 
		}
	}//for
	return true;
}

// ############### 핸드폰 번호 체크 ######
 function chkPhone(v){
	var hp_str = v.substring(0,3);
	if(hp_str!="010" && hp_str!="011" && hp_str!="016" && hp_str!="017" && hp_str!="018" && hp_str!="019"){
		return false;
	}
	return chkPatten(v,"regPhone");
}

function checkByte(obj,len,inputName){
	var ThisString = obj.value;
	var ByteLength = 0;
	for(var i=0;i < ThisString.length; i++){
		if(ThisString.charCodeAt(i) > 255) {
			ByteLength += 2;
		}
		else{
			ByteLength++;
		}
	}
	if(ByteLength>len){
		alert(inputName + ' '+ len + 'Byte를 넘습니다. 현재' + ByteLength + 'Byte 입니다.');
		obj.focus();
		return false;
	}
	return true;
}
function diplayByte(obj,len,dispName){
	var ThisString = obj.value;
	var ByteLength = 0;
	for(var i=0;i < ThisString.length; i++){
		if(ThisString.charCodeAt(i) > 255) {
			ByteLength += 2;
		} 
		else{
			ByteLength++;
		}
	}
	
	var div = document.getElementById(dispName) ;
	
	if ( ByteLength > len ) {
		div.innerHTML = "[ <font color='red'>" + ByteLength + "</font> / " + len + " bytes ]" ;
	} else {
		div.innerHTML = "[ " + ByteLength + " / " + len + " bytes ]" ;
	}
}

function checkDefaultInput(obj,len,inputName,emptyMsg){
	//업체명 Null체크
	if(IsEmpty(obj.value)){
		alert(emptyMsg);
		obj.focus();
		return false;
	}
	//업체명 바이트 체크 
	if(!checkByte(obj,len,inputName)){
		obj.focus();
		return false;
	}
	return true;
}

 // ############### 전화번호 형식 체크 ######
function chkPatten(val,patten) {
    var regPhone =/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;                     // 형식 : 033-1234-5678
    var regMail =/^[_a-zA-Z0-9-]+@[._a-zA-Z0-9-]+\.[a-zA-Z]+$/;

    patten = eval(patten);
    if(!patten.test(val)){
        return false;
    }
    return true;
}

// ######################## 체크박스 모두 선택  ########################
function checkAll(id, checks, isCheck){
	var fobj = document.getElementsByName(checks);
	if(fobj == null) return;

  	if(fobj.length){
  		for(var i=0; i < fobj.length; i++){
  			if(fobj[i].disabled==false){
  				fobj[i].checked = isCheck;
  			}
  		}
  	}else{
  		if(fobj.disabled==false){
  			fobj.checked = isCheck;
  		}
  	}
  	
  	if(isCheck){
  		document.getElementById(id).innerHTML="<a href=\"javascript:checkAll('"+id+"','"+checks+"',false)\">취소</a>";
  	}else{
  		document.getElementById(id).innerHTML="<a href=\"javascript:checkAll('"+id+"','"+checks+"',true)\">선택</a>";
  	}
}

// ######################## 체크박스 모두 선택(사용자용)  ########################
function checkUserAll(id, checks, isCheck,rootPath){
	var fobj = document.getElementsByName(checks);
	
  	if(fobj.length){
  		for(var i=0; i < fobj.length; i++){
  			if(fobj[i].disabled==false){
  				fobj[i].checked = isCheck;
  			}
  		}
  	}else{
  		if(fobj.disabled==false){
  			fobj.checked = isCheck;
  		}
  	}
  	
  	if(isCheck){
  		document.getElementById(id).innerHTML="<a href=\"javascript:checkUserAll('"+id+"','"+checks+"',false,'"+rootPath+"')\"><img src=\""+rootPath+"/images/bbs/t_c_che.gif\" width=\"9\" height=\"9\"></a>";
  	}else{
  		document.getElementById(id).innerHTML="<a href=\"javascript:checkUserAll('"+id+"','"+checks+"',true,'"+rootPath+"')\",><img src=\""+rootPath+"/images/bbs/t_c_che.gif\" width=\"9\" height=\"9\"></a>";
  	}
}

function checkBoxAll(obj, checks){
	var fobj = document.getElementsByName(checks);
	
	isCheck = obj.checked;
	
  	if(fobj.length){
  		for(var i=0; i < fobj.length; i++){
  			if(fobj[i].disabled==false){
  				fobj[i].checked = isCheck;
  			}
  		}
  	}else{
  		if(fobj.disabled==false){
  			fobj.checked = isCheck;
  		}
  	}
}

// 체크된 값을 가져온다.(디폴트 구분자 : ',')
function getCheckedValue(checks, divstring) {
	var fobj = document.getElementsByName(checks);
	var index = 0;
	var result = "";
	
	if(divstring == null) divstring = "','";
	
	if(fobj.length){
  		for(index = 0; index < fobj.length; index++){
  			if(fobj[index].disabled == false && fobj[index].checked == true) {
  				if(result == "") result += fobj[index].value;
  				else result += divstring + fobj[index].value;
  			}
  		}
  	} else {
  		if(fobj.disabled==false && fobj.checked == true) {
  			result = fobj.value;
  		}
  	}
  	
  	if(result != "")
	  	result = "'" + result + "'";
	
  	return result;
}

// 체크된 값을 가져온다.(디폴트 구분자 : ',')
function getCheckedNumValue(checks, divstring) {
	var fobj = document.getElementsByName(checks);
	var index = 0;
	var result = "";
	
	if(divstring == null) divstring = ",";
	
	if(fobj.length){
  		for(index = 0; index < fobj.length; index++){
  			if(fobj[index].disabled == false && fobj[index].checked == true) {
  				if(result == "") result += fobj[index].value;
  				else result += divstring + fobj[index].value;
  			}
  		}
  	} else {
  		if(fobj.disabled==false && fobj.checked == true) {
  			result = fobj.value;
  		}
  	}
  	return result;
}

// 체크안된 값을 가져온다.(디폴트 구분자 : ',')
function getUnCheckedValue(checks, divstring) {
	var fobj = document.getElementsByName(checks);
	var index = 0;
	var result = "";
	
	if(divstring == null) divstring = "','";
	
	if(fobj.length){
  		for(index = 0; index < fobj.length; index++){
  			if(fobj[index].disabled == false && fobj[index].checked == false) {
  				if(result == "") result += fobj[index].value;
  				else result += divstring + fobj[index].value;
  			}
  		}
  	} else {
  		if(fobj.disabled==false && fobj.checked == false) {
  			result = fobj.value;
  		}
  	}
  	
  	if(result != "")
	  	result = "'" + result + "'";
	  	
  	return result;
}

// ######################## 브라우져 체크(네스케이프, 익스플로러)  ########################
function check_browser() {
    var ret;
    ret = navigator.appName;
    if (ret == "Netscape")
        return "NE";
    else if (ret == "Microsoft Internet Explorer")
        return "IE";
    else
        return -1;
}

// ######################## 정수체크  ########################
function is_valid_float(object) {

    if (object.getAttribute("required") != null && !object.value)
        return false;

    if (object.value.length != 0) {
        if (object.getAttribute("float") != null) {
            var regExpFloat = /^(([\+-])?(\d+)(\.\d+)?)$/;
            if(!regExpFloat.test(object.value)) return false;
        }
    }
    return true;
}

// ######################## Upper Case  ########################
function is_upper(value) {
    var i;
    for(i = 0 ; i < _upperValue.length ; i++)
        if(value == _upperValue.charAt(i))
            return true;
    return false;
}

// ######################## 대문자 변환  ########################
function to_upper(obj) {
    var strNew;
    var str = obj.value;
    for(i = 0 ; i < str.length ; i++) {
        if(str.charAt(i) >= 'a' && str.charAt(i) <= 'z')
            strNew = strNew + str.charAt(i).toUpperCase() ;
        else
            strNew = strNew + str.charAt(i);
    }
    obj.value = strNew;
}

// ######################## Lower Case  ########################
function is_lower(value) {
    var i;
    for(i = 0 ; i < _lowerValue.length ; i++)
        if(value == _lowerValue.charAt(i))
            return true;
    return false;
}

// ######################## is Int  ########################
function is_int(value) {
    var j;
    for(j = 0 ; j < _intValue.length ; j++)
        if(value == _intValue.charAt(j))
            return true;
    
    return false;
}

// ######################## 좌측공백제거  ########################
function ltrim(para) {
    while(para.substring(0,1) == ' ')
        para = para.substring(1, para.length);
    return para;
}

// ######################## 중간공백제거  ########################
function mtrim(para) {
    for(var i = 0 ; i < para.length ;)
        if(para.substring(i,i+1) == ' ')
            para = para.substring(0,i) + para.substring(i+1,para.length);
        else
            i++;
    return para;
}

// ######################## 오른쪽공백제거  ########################
function rtrim(para) {
    while(para.substring(para.length-1,para.length) == ' ')
        para = para.substring(0,para.length-1);
    return para;
}

// ############### 문자열 내의 모든 공백 문자 제거 ##################
function TrimAll(data) { 
	var lszTrim = data; 
	var j = 0; 
	 
	for(var i = 0; i < data.length; i++)
	{
		if(data.substring(i, i+1) == ' ')
		{
			if(i > 0)
				lszTrim = data.substring(0, i);
			else
				lszTrim = "";

			lszTrim = lszTrim + data.substring(i+1);
			data = lszTrim;
			i--;
		}
	} 
	 
	return lszTrim;
} 

// ############### 오늘(YYYY-MM-DD)날짜 리턴  ##################
function to_day() {
    var now     = new Date();
    var yr      = now.getYear();
    var mName   = now.getMonth() + 1;
    var dName   = now.getDate();

    if(yr < 100)
        year = ("19" + yr).toString();
    else
        year = yr.toString();

    if(mName < 10)
        month = ("0" + mName).toString();
    else
        month = mName.toString();

    if(dName < 10)
        day = ("0" + dName).toString();
    else
        day = dName.toString();

    return year + "-" + month + "-" + day;
}

function to_day2() {
	var now     = new Date();
	var yr      = now.getYear();
	var mName   = now.getMonth() + 1;
	var dName   = now.getDate();
	var hName = now.getHours();

	if(yr < 100)
		year = ("19" + yr).toString();
	else
		year = yr.toString();
	
	if(mName < 10)
		month = ("0" + mName).toString();
	else
		month = mName.toString();
	
	if(dName < 10)
		day = ("0" + dName).toString();
	else
		day = dName.toString();
	
	return year + month + day + hName;
}

// ############### 문자열 인코딩  ##################
function str_encoding(str) {
    var ret     = '';
    var c       = '';
    var temp    = '';

    if(check_browser() != 'IE') return str;

    for(i = 0 ; i < str.length ; i++) {
        temp = str.charCodeAt(i);
        if(temp > 122 || temp == 32)
            c = escape(str.charAt(i));
        else
            c = str.charAt(i);
        ret = ret + c;
    }
    return ret;
}


// ########### 날짜 형식 검사(yyyy-mm-dd) ###############
function checkDateFormat(obj, objName) {
	var str = String(obj.value);
	var year;
	var month;
	var day;
	var dash_1;
	var dash_2;
	var msg;
	
	if(str.length < 1 || str.length.length > 10) {
		msg = "입력하신 " + objName + "의 길이가 형식에 맞지 않습니다.";
		alert(msg);
		return false;
	} else {
		year = str.substring(0, 4);
		dash_1 = str.substring(4, 5);
		month = str.substring(5, 7);
		dash_2 = str.substring(7, 8);
		day = str.substring(8, 10);
		
		if(!(IsNumber(year) && IsNumber(month) && IsNumber(day))) {
			msg = objName + "는 숫자로 입력되어야 합니다.";
			alert(msg);
			return false;
		}
		if(dash_1 != "-" || dash_2 != "-") {
			msg = objName + "의 년월일 구분은 -로 입력되어야 합니다.";
			alert(msg);
			return false;
		}
	}
	
	return true;
}

// ############### 날짜 문자열에 '-' 추가  ##################
function addStringToDate(strDate, sep) {
    var str = '';
    var t_date = removeDashFromDate(strDate);

    if (t_date.length < 1 || t_date.length < 8) {
        return "";
    }
    else {
        str = t_date.substring(0, 4) + sep + t_date.substring(4, 6) + sep + t_date.substring(6, 8);
    }
    
    return str;
}

// ############### 날짜 문자열에 '-' 추가  ##################
function addDashToObjDate(obj) {
	
	var sep = '-';
	var str = '';
	var t_date = removeDashFromDate(obj.value);
	
	if (t_date.length < 1 || t_date.length < 8) {
		return "";
	}
	else {
		str = t_date.substring(0, 4) + sep + t_date.substring(4, 6) + sep + t_date.substring(6, 8);
		obj.value = str;
	}
	
	return obj.value;
}

// ############### 날짜 문자열에 '-' 추가  ##################
function addDashToDate(strDate) {
	
	var sep = '-';
	var str = '';
	var t_date = removeDashFromDate(strDate);
	
	if (t_date.length < 1 || t_date.length < 8) {
		return "";
	}
	else {
		str = t_date.substring(0, 4) + sep + t_date.substring(4, 6) + sep + t_date.substring(6, 8);
	}
	
	return str;
}

// ############### 날짜 문자열에서 '-' 제거  ##################
function removeDashFromDate(strDate) {
    if(strDate.length < 1) {
        return "";
    } else {
        var st = "";
        var sp = "-";
        for(var i = 0 ; i < strDate.length ; i++)
            if(sp.indexOf(strDate.substring(i,i+1)) == -1) st += strDate.substring(i,i+1);
        
        return st;
    }
}

// ############### 슬러쉬 / 제거  ##################
function del_slash(obj) {
    var str = String(obj.value);
    if(str.length < 1) {
        return "";
    } else {
        var st = "";
        var sp = "/";
        for(var i = 0 ; i < str.length ; i++)
            if(sp.indexOf(str.substring(i,i+1)) == -1)
                st += str.substring(i,i+1);
        return st;
    }
}

// ############### 하이픈 (-) 제거  ##################
function del_hyphen(obj) {
    var str = String(obj.value);
    if(str.length < 1) {
        return "";
    } else {
        var st = "";
        var sp = "-";
        for(var i = 0 ; i < str.length ; i++)
            if(sp.indexOf(str.substring(i,i+1)) == -1)
                st += str.substring(i,i+1);
        return st;
    }
}

function del_hyphen_value(value) {
    var str = value;
    if(str.length < 1) {
        return "";
    } else {
        var st = "";
        var sp = "-";
        for(var i = 0 ; i < str.length ; i++)
            if(sp.indexOf(str.substring(i,i+1)) == -1)
                st += str.substring(i,i+1);
        return st;
    }
}

// ############### 이메일 형식 체크  ##################
function is_email(obj) {
    var s =  String(obj.value);

    if ( s == "" || s == null) { alert("이메일을 입력하십시요.");
        return false;
    } else {
        var i = 1;
        var sLength = s.length;

        while ((i < sLength) && (s.charAt(i) != "@")) i++;

        if ((i >= sLength) || (s.charAt(i) != "@")) {
            alert("이메일이 형식에 맞지 않습니다.");
            return false;
        } else i += 2;

        while ((i < sLength) && (s.charAt(i) != ".")) i++;

        if ((i >= sLength - 1) || (s.charAt(i) != ".")) {
            alert("이메일이 형식에 맞지 않습니다.");
            return false;
        } else return true;
    }
}

// ############### 오브젝트 갯수 체크  ##################
function getLength(obj) {
    for(f = 0 ; f < document.forms.length ; f++) {
	    var mForm = document.forms[f];
	    var iElements = mForm.elements.length;
	    var cnt = 0;
	    
	    for(i = 0 ; i < iElements ; i++) {
	      if(mForm.elements[i].name == obj) {
	        cnt = cnt + 1;
	      }
		}
	}
	return cnt;
}

// ############### 오브젝트명을 받아와서 체크박스일 경우 체크된 갯수 리턴  ##################
function getChecked(obj) {
    for(f = 0 ; f < document.forms.length ; f++) {
	    var mForm = document.forms[f];
	    var iElements = mForm.elements.length;
	    var cnt = 0;
	    
	    for(i = 0 ; i < iElements ; i++) {
	      if(mForm.elements[i].name == obj) {
	        if(mForm.elements[i].checked) {
	          cnt = cnt + 1;
	        }
	      }
		}
	}
	return cnt;
}

function findFormElement(form, name) {
	var arrObj = new Array();
	var obj = null;
	var nCount = 0;

	for(var i = 0; i < form.elements.length; i++) {
	    if(form.elements[i].name == name)
	    	nCount++;
	}
	
	if(nCount <= 1) {
		for(var i = 0; i < form.elements.length; i++) {
		    if(form.elements[i].name == name) {
		    	obj = form.elements[i];
		    	break;
		    }
		}

		return obj;
	}
	else {
		nCount = 0;
		for(var i = 0; i < form.elements.length; i++) {
		    if(form.elements[i].name == name) {
		    	arrObj[nCount] = form.elements[i];
		    	nCount++;
		    }
		}

		return arrObj;
	}
}

// 윈도우 팝업
function openWindow(surl, type, name) {
	var pop_size    = type.split("*");
	var popupwidth  = pop_size[0];
	var popupheight = pop_size[1];
	
	if(isNaN(parseInt(popupwidth))) {
		Top  = (window.screen.availHeight - 600) / 2;
		Left = (window.screen.availWidth  - 800) / 2;
	} else {
		Top  = (window.screen.availHeight - popupheight) / 2;
		Left = (window.screen.availWidth  - popupwidth)  / 2;
	}
	
	if(Top  < 0) Top  = 0;
	if(Left < 0) Left = 0;
	
	var delim = (surl.indexOf("?") == -1) ? "?" : "&";
	
	Feature = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	
	if(name == "") name = "popupWindow";
	
	PopUpWindow = window.open(surl, name, Feature);
	PopUpWindow.focus();
}

// 윈도우 팝업
function openWindowScroll(surl, type, name) {
	var pop_size    = type.split("*");
	var popupwidth  = pop_size[0];
	var popupheight = pop_size[1];
	
	if(isNaN(parseInt(popupwidth))) {
		Top  = (window.screen.availHeight - 600) / 2;
		Left = (window.screen.availWidth  - 800) / 2;
	} else {
		Top  = (window.screen.availHeight - popupheight) / 2;
		Left = (window.screen.availWidth  - popupwidth)  / 2;
	}
	
	if(Top  < 0) Top  = 0;
	if(Left < 0) Left = 0;
	
	var delim = (surl.indexOf("?") == -1) ? "?" : "&";
	
	Feature = "toolbar=0,menubar=0,scrollbars=yes,resizable=no,left=" + Left + ",top=" + Top + ",width=" + popupwidth + ",height=" + popupheight;
	
	if(name == "") name = "popupWindow";
	
	PopUpWindow = window.open(surl, name, Feature);
	PopUpWindow.focus();
}

// round 함수 ( val = 값, precision= 소숫점 자릿수)
function round(val,precision) {
	val = val * Math.pow(10,precision);
	val = Math.round(val); 
	return val/Math.pow(10,precision);
}

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str

    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (0xf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }

    return s0;

}

function decodeURL(str){

    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str

    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
					for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
						sss = str.charAt(++i);
						if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
							ss += sss;      // if hex, add the hex character
						} else {--i; break;}    // not a hex char., exit the loop
					}
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
	            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }

    return s0;

}

// 입력받은 값(숫자)이 0일 경우, 포커싱
function zeroSelect(obj) {
    if (obj.value == 0) {
        obj.select();
    }
}

// 입력받은 키보드값이 숫자인지 판단
function isDigit(e) {
    if (e.ctrlKey == true) {
        return true;
    }

    var sKeyCode = e.keyCode;
    if (sKeyCode == 8 || sKeyCode == 9 || sKeyCode == 37 || sKeyCode == 39 || sKeyCode == 46 || 
        (sKeyCode >= 48 && sKeyCode <= 57) || (sKeyCode >= 96 && sKeyCode <= 105)
        ||sKeyCode == 110 ||sKeyCode == 190) {
        window.event.returnValue = true;
    } else {
        window.event.returnValue = false;
    }
}

// 숫자만 입력 받음.
function inputNumber() {
    var inputs = document.getElementsByTagName("INPUT");
    
    for(i=0; i<inputs.length; i++) {
        if (inputs[i].className == "numberbox") {
            inputs[i].onfocus = function(){zeroSelect(this);};
            inputs[i].onkeydown = function(){isDigit(event);};
        }
    } 
}

var preobj;
//
function mouseOver(dobj) {
	if(preobj != dobj)
		dobj.style.backgroundColor = "#EEEEEE";
}
//
function mouseOut(dobj) {
	if(preobj != dobj)
		dobj.style.backgroundColor = "";
}

// 라운드 테이블 만들기
function roundTable(objID) {
	var obj = document.getElementById(objID);
	var Parent, objTmp, Table, TBody, TR, TD;
	var bdcolor, bgcolor, Space;
	var trIDX, tdIDX, MAX;
	var styleWidth, styleHeight;
	
	// get parent node
	Parent = obj.parentNode;
	objTmp = document.createElement('SPAN');
	Parent.insertBefore(objTmp, obj);
	Parent.removeChild(obj);
	
	// get attribute
	bdcolor = obj.getAttribute('rborder');
	bgcolor = obj.getAttribute('rbgcolor');
	radius = parseInt(obj.getAttribute('radius'));
	if (radius == null || radius < 1) radius = 1;
	else if (radius > 6) radius = 6;
	
	MAX = radius * 2 + 1;

	Table = document.createElement('TABLE');
	TBody = document.createElement('TBODY');

	Table.cellSpacing = 0;
	Table.cellPadding = 0;
	
	for (trIDX=0; trIDX < MAX; trIDX++) {
		TR = document.createElement('TR');
		Space = Math.abs(trIDX - parseInt(radius));
		for (tdIDX=0; tdIDX < MAX; tdIDX++) {
			TD = document.createElement('TD');
			
			styleWidth = '1px'; styleHeight = '1px';
			if (tdIDX == 0 || tdIDX == MAX - 1) styleHeight = null;
			else if (trIDX == 0 || trIDX == MAX - 1) styleWidth = null;
			else if (radius > 2) {
				if (Math.abs(tdIDX - radius) == 1) styleWidth = '2px';
				if (Math.abs(trIDX - radius) == 1) styleHeight = '2px';
			}
			
			if (styleWidth != null) TD.style.width = styleWidth;
			if (styleHeight != null) TD.style.height = styleHeight;
			
			if (Space == tdIDX || Space == MAX - tdIDX - 1) TD.style.backgroundColor = bdcolor;
			else if (tdIDX > Space && Space < MAX - tdIDX - 1)  TD.style.backgroundColor = bgcolor;
			
			if (Space == 0 && tdIDX == radius) TD.appendChild(obj);
			TR.appendChild(TD);
		}
		TBody.appendChild(TR);
	}
	
	Table.appendChild(TBody);
	
	// insert table and remove original table
	Parent.insertBefore(Table, objTmp);
}

function convertToUTF8(s) {
	var c, d = "";
	
	for (var i = 0; i < s.length; i++) {
		c = s.charCodeAt(i);
		if (c <= 0x7f) {
			d += s.charAt(i);
		} else if (c >= 0x80 && c <= 0x7ff) {
			d += String.fromCharCode(((c >> 6) & 0x1f) | 0xc0);
			d += String.fromCharCode((c & 0x3f) | 0x80);
		} else {
			d += String.fromCharCode((c >> 12) | 0xe0);
			d += String.fromCharCode(((c >> 6) & 0x3f) | 0x80);
			d += String.fromCharCode((c & 0x3f) | 0x80);
		}
	}
	
	return d;
}

function convertFromUTF8(s) {
	var c, d = "", flag = 0, tmp;
	for (var i = 0; i < s.length; i++) {
		c = s.charCodeAt(i);
		if (flag == 0) {
			if ((c & 0xe0) == 0xe0) {
				flag = 2;
				tmp = (c & 0x0f) << 12;
			} else if ((c & 0xc0) == 0xc0) {
				flag = 1;
				tmp = (c & 0x1f) << 6;
			} else if ((c & 0x80) == 0) {
				d += s.charAt(i);
			} else {
				flag = 0;
			}
		} else if (flag == 1) {
			flag = 0;
			d += String.fromCharCode(tmp | (c & 0x3f));
		} else if (flag == 2) {
			flag = 3;
			tmp |= (c & 0x3f) << 6;
		} else if (flag == 3) {
			flag = 0;
			d += String.fromCharCode(tmp | (c & 0x3f));
		} else {
			flag = 0;
		}
	}
	
	return d;
}

// HTML 특수 문자들을 치환한다.
// 	'(작은따옴표) -> &#039;
// 	" (큰따옴표) 	-> &quot;
//	& (앰퍼센트)	-> &amp;
//	< (보다작은)	-> &lt;
//	> (보다 큰)	-> &gt;
function HtmlSpecialChars(str)
{
	var ret_str = str;
	
//	search = new Array(/'/g, /"/g, /&/g, /</g, />/g);
//	replace = new Array("&#039;", "&quot;", "&amp;", "&lt;", "&gt;");
	search = new Array(/&/g, /</g, />/g);
	replace = new Array("&amp;", "&lt;", "&gt;");

	cnt = search.length;
	
	for(i = 0; i < cnt; i++) {
		ret_str = ret_str.replace(search[i], replace[i]);
	}
	
	return ret_str;
}

function display_obj(obj_name)
{
	obj_array = obj_name.split("|");
	l1 = obj_array.length;
	
	for (i=0;i<l1;i++)
	{
		if (obj_array[i] != "")
		{
			dis_obj = eval("document.all." + obj_array[i]);
			if(dis_obj != null)
			{
				if (dis_obj.length != null)
				{
					 l2 = dis_obj.length;
					 for(j=0;j<l2;j++)
					 {
						dis_obj.item(j).style.display = "block";
					 }
				}
				else
				{
					dis_obj.style.display = "block";
				}
			}
		}
	}
}

function hidden_obj(obj_name)
{
	obj_array = obj_name.split("|");
	l1 = obj_array.length;
	
	for (i=0;i<l1;i++)
	{
		if (obj_array[i] != "")
		{
			hidd_obj = eval("document.all." + obj_array[i]);
			if(hidd_obj != null)
			{
				if (hidd_obj.length != null)
				{
					 l2 = hidd_obj.length;
					 for(j=0;j<l2;j++)
					 {
						hidd_obj.item(j).style.display = "none";
					 }
				}
				else
				{
					hidd_obj.style.display = "none";
				}
			}
		}
	}
}

function clear_tr_children(obj_name)
{

	clear_obj = eval("document.all." + obj_name);
	
	if (clear_obj != null)
	{
		l1 = clear_obj.cells.length
		
		for (i=0;i<l1;i++)
		{
			obj = clear_obj.cells.item(i)
			l2 = obj.children.length
			
			for(j=0;j<l2;j++)
			{
				tname = obj.children(j).tagName
				
				if (tname == "INPUT")
				{
					if (obj.children(j).type == "text" || obj.children(j).type == "password" || obj.children(j).type == "hidden")
					{
						obj.children(j).value = "";
					}
					else if(obj.children(j).type == "radio" || obj.children(j).type == "checkbox")
					{
						obj.children(j).checked = false ;
					}
				}
				else if(tname == "SELECT")
				{
					obj.children(j).selectedIndex = 0;
				}
				else if(tname == "TEXTAREA")
				{
					obj.children(j).value = "";
				}
			}
		}
	}
}

//이미지 미리보기
function goImageView(mask_filename){
	if(mask_filename == ''){
		alert('이미지가 없습니다.');
		return;
	}else{
		this.openWindow("/actions/CommonAction?cmd=imgPreView&mask_filename="+mask_filename, "toolbar=0,menubar=0,width=100,height=100", "opendata");
	}
}

//이미지 미리보기
function goImageView_bbs(attach_idx){
	if(attach_idx == ''){
		alert('이미지가 없습니다.');
		return;
	}else{
		this.openWindow("/actions/CommonAction?cmd=imagePreview_bbs&attach_idx="+attach_idx, "toolbar=0,menubar=0,width=100,height=100", "opendata");
	}
}

// cp업체 공통 팝업
function goCpPopup(pUrl,formName,codeField,nameField){
	var url = pUrl+"?cmd=listPopup";
	url +="&formName="+formName;
	url +="&codeField="+codeField;
	url +="&nameField="+nameField;
	openWindow(url, "800*600", "postpop");
}	

/************************************************** 
 * 텍스트를 길이에 맞게 줄임 (...)으로 표시하여 나타낸다)
**************************************************/
function decreaseString(szContent, bIsLink, width, bIsDisplayAlt, bAddSpaceOnBegin) {
	var szResult = "";
	
	if(typeof(bIsLink) == "undefined")
		bIsLink = false;
	if(typeof(width) == "undefined")
		width = "100%";
	if(typeof(bIsDisplayAlt) == "undefined")
		bIsDisplayAlt = true;
	if(typeof(bAddSpaceOnBegin) == "undefined")
		bAddSpaceOnBegin = true;

	szContent = szContent.replaceAll("'", "\\'");
	szContent = szContent.replaceAll("\"", "\\\"");

	if(bAddSpaceOnBegin)
		szResult = "&nbsp;";
	szResult = szResult + "<span style='position:absolute;width:" + width + ";overflow:hidden;text-overflow:ellipsis;";
	if(bIsLink)
		szResult += "cursor:hand;";
	szResult += "'";
	if(bIsDisplayAlt)
		szResult += " title='" + szContent + "'";
	szResult += "><nobr>" + szContent + "</nobr></span>";

	return szResult;
}

function AddComboOption(combo, optionText, optionValue)
{
	var oOption = document.createElement("option") ;

	oOption.text 	= optionText ;
	oOption.value   = optionValue ;
	
	combo.options.add(oOption);

	return oOption ;
}

/************************************************************
 * MoveFocus(obj , limit , tgObjName)
 *
 * obj : 해당 object 
 * limit : 글자 제한 Length 
 * tgObjName : target Object Name
 *
 * 해당 Object의 limit 만큼 글을 쓰면 대상오브젝트로 포커스 이동
 ************************************************************/
function MoveFocus(obj , limit , tgObjName) {
	var objValue = obj.value ; 
	if ( objValue.length == limit ) {
		document.getElementById(tgObjName).focus() ;
	}
}

/*
function alert(msg) {
	window.showModalDialog("/jsp/test.jsp", "", "dialogWidth: 300px; dialogHeight:200px");
}
*/

///// ZonnInOut //////////////////////////////////////////////////////////////////////////////
var nowZoom = 100; // 현재비율
var maxZoom = 120; // 최대비율
var minZoom = 70; // 최소비율(현재와 같아야 함)

// +, - 키를 입력하면 화면 확대, 축소를 한다.
document.onkeypress = getKey;

function getKey(keyStroke) {
	isNetscape = (document.layers);
	eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
	which = String.fromCharCode(eventChooser).toLowerCase();
	which2 = eventChooser;

	var el = event.srcElement;

	if ((el.tagName != "INPUT") && (el.tagName != "TEXTAREA")) {
		if (which == "+") {
			zoomIn();
		} else if (which == "-") {
			zoomOut();
		}
	}
}

//화면 키운다.
function zoomIn() {
	if (nowZoom < maxZoom) {
		nowZoom += 10; // 5%씩 커진다.
	} else {
		return;
	}

	//document.body.style.zoom = nowZoom + "%";
	document.getElementById("contents_layer").style.zoom = nowZoom + "%";
}

//화면 줄인다.
function zoomOut() {
	if (nowZoom > minZoom) {
		nowZoom -= 10; // 5%씩 작아진다.
	} else {
		return;
	}

	//document.body.style.zoom = nowZoom + "%";
	document.getElementById("contents_layer").style.zoom = nowZoom + "%";
}

//원래대로
function default_size(){
	nowZoom = 100;
	document.body.style.zoom ="100%";
}

function boardZoom(val) {
	var content, lineHeight;
	content = document.getElementById("contents_layer");
	if (val > 0) {
		if (fontSize <= 20) { //가장 큰 폰트사이트
			fontSize = fontSize + val;
			lineHeight = fontSize+Math.round(1.5*fontSize);
			content.style.fontSize = fontSize + "px";
		}
	} else {
		if (fontSize > 9) { //가장 작은 폰트사이트
			fontSize = fontSize + val;
			lineHeight = fontSize+Math.round(1.1*fontSize);
			content.style.fontSize = fontSize + "px";
		}
	}	
}

//20081223 추가
/* 화면 확대 축소 시작 IE 전용 */
 var nowZoom = 100; // 현재비율
 var maxZoom = 120; // 최대비율(500으로하면 5배 커진다)
 var minZoom = 70; // 최소비율

//화면 키운다.
function zoomInRe() {
  if (nowZoom < maxZoom) {
   nowZoom += 10; //25%씩 커진다.
  } else {
   return;
  }

  page.style.zoom = nowZoom + "%";
}

//화면 줄인다.
function zoomOutRe() {
  if (nowZoom > minZoom) {
   nowZoom -= 10; //25%씩 작아진다.
  } else {
   return;
  }

  page.style.zoom = nowZoom + "%";
}

///// Login Return_url //////////////////////////////////////////////////////////////////////////////

/* return_url 변환 */
function getLoginReturnUrl(return_url) {
	return_url = return_url.replaceAll("&", "[NP~]");
	
	for(var nIndex=0; nIndex < return_url.length; nIndex++) {
		if(return_url.indexOf("?") > -1) {
			return_url = return_url.replace("?", "[NQ~]");
		}
	}
	
	return_url = escape(return_url);
	
	return return_url;
}

// 동영상 플레이어 popup object

var _popup = null;


// 동영상 플레이어창 생성 여부

function fnIsOpenVodPlayer() {
	if (!_popup) {
		return false;

	} else {
		try {
			if (_popup.document) {
				return true;
			} else {
				return false;
			}

		} catch (e) {
			// 창이 팝업되었다 닫힌 경우

			_popup = null;
			return false;
		}
	}

}

// 동영상 플레이어 팝업
function fnOpenVodPlayer(vod_info, param) {
    var stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=880,height=535,left=300,top=200";    
    var arrType = new Array();
	var type    = new Array();
    if ( vod_info != null && vod_info != ""){  
		arrType = vod_info.split("||");
		for ( var k = 0 ; k < arrType.length  ; k++ ){
			 if ( arrType[k].split("|") != "") {
				 type = arrType[k].split("|"); 
			 }
		}
    }

	// 플레이어창이 이미 팝업되어있으면, 해당 창에 동영상을 재생시킨다.
	if (!fnIsOpenVodPlayer()) {
		if ( type[0] == "D" || type[0] == "F"){
			stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=960,height=460,left=300,top=200"; 
			_popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?type=2&cmd=showMP4&vod_info=" + escape(vod_info) + param, "", stat);
		} else {
			_popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=show&vod_info=" + escape(vod_info) + param, "", stat);
		}

	} else {
		if ( type[0] == "D" || type[0] == "F"){ 
            _popup.document.location.replace(DEFAULT_CONTEXT + "/actions/VodPlayerAction?type=2&cmd=showMP4&vod_info=" + escape(vod_info) + param);
		} else {
			_popup.document.location.replace(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=show&vod_info=" + escape(vod_info) + param);
		}

	}

	
}


function fnOpenVodPlayer2(broad_date, broad_code, vod_idx) {
	 stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=960,height=460,left=300,top=200"; 
	 //if (!fnIsOpenVodPlayer()) {
	//		_popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=showMP4&broad_code=" +broad_code + "&broad_date=" + broad_date + "&vod_idx=" + vod_idx + "&type=1", "", stat);

	//} else {
			document.location.replace(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=showMP4&broad_code=" +broad_code + "&broad_date=" + broad_date + "&vod_idx=" + vod_idx + "&type=1");
	//}
}


// 오디오 플레이어 팝업
function fnOpenAodPlayer(aod_url) {
	var stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=521,height=176";
	var popup = window.open(DEFAULT_CONTEXT + "/jsp/common/vodplayer/AodPlayer.jsp?aod_url=" + encodeURIComponent(aod_url), "", stat);
}

// On-Air 동영상 플레이어 팝업
// @param channel 재생채널
// @param auth_yn 인증여부(로그인필요여부)
// @param restrict_ip_yn 해외IP차단여부
// @param reply_use_yn 댓글사용여부
function fnOpenLivePlayer(channel, auth_yn, restrict_ip_yn, reply_use_yn) {
	/* 20100125 by allou, SSO
	// 인증여부가 활성화되어있을경우 로그인체크
	if (auth_yn && auth_yn == 'Y') {
		if (!getCookie("userid") || getCookie("userid") == "") {
			alert("로그인 후 사용하실 수 있습니다.");
			return;
		}
	}
	*/

	var stat = null;
	
	// 댓글사용여부가 활성화되어있을경우 창 사이즈 변경
	if (reply_use_yn == 'Y') {
		stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=880,height=535";
	} else {
		stat = "toolbar=0,menubar=0,scrollbars=auto,resizable=no,width=520,height=535";
	}
	
	/* cdn 테스트 용   
    var popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=liveCdn&channel=" + channel + "&auth_yn=" + auth_yn + "&restrict_ip_yn=" + restrict_ip_yn + "&reply_use_yn=" + reply_use_yn, "", stat);
    */
	/* 엘지 네오텍 테스트용 
	//alert("/actions/VodPlayerAction?cmd=GSTest&channel=" + channel + "&auth_yn=" + auth_yn + "&restrict_ip_yn=" + restrict_ip_yn + "&reply_use_yn=" + reply_use_yn);

	var popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=GSTest&channel=" + channel + "&auth_yn=" + auth_yn + "&restrict_ip_yn=" + restrict_ip_yn + "&reply_use_yn=" + reply_use_yn, "", stat);
     */     

	var popup = window.open(DEFAULT_CONTEXT + "/actions/VodPlayerAction?cmd=live&channel=" + channel + "&auth_yn=" + auth_yn + "&restrict_ip_yn=" + restrict_ip_yn + "&reply_use_yn=" + reply_use_yn, "", stat);
    
}


/****************************************************
tbl      : 병합할 대상 table object
startRow : 병합 시작 row, title 한 줄일 경우 1
cNum     : 병합 실시할 컬럼번호, 0부터 시작
length   : 병합할 row의 길이, 보통 1
add      : 비교할 기준에 추가할 컬럼번호
          A | 1
          B | 1
         을 서로 구분하고 싶다면, add에 0번째
         컬럼을 추가
*****************************************************/
function mergeCell(tbl, startRow, cNum, length, add) {
	var isAdd = false;
	if(tbl == null) return;
	if(startRow == null || startRow.length == 0) startRow = 1;
	if(cNum == null || cNum.length == 0) return ;
	if(add  == null || add.length == 0) {
	    isAdd = false;
	}else {
	    isAdd = true;
	    add   = parseInt(add);
	}
	cNum   = parseInt(cNum);
	length = parseInt(length);
	
	rows   = tbl.rows;
	rowNum = rows.length;
	
	tempVal  = '';
	cnt      = 0;
	startRow = parseInt(startRow);
	
	for( i = startRow; i < rowNum; i++ ) { 
	    curVal = rows[i].cells[cNum].innerHTML;
	    if(isAdd) curVal += rows[i].cells[add].innerHTML;
	    if( curVal == tempVal ) {
	        if(cnt == 0) {
	            cnt++;
	            startRow = i - 1;
	        }
	        cnt++;
	    }else if(cnt > 0) {
	        merge(tbl, startRow, cnt, cNum, length);
	        startRow = endRow = 0;
	        cnt = 0;
	    }else {
	    }
	    tempVal = curVal;
	}

	if(cnt > 0) {
	    merge(tbl, startRow, cnt, cNum, length);
	}
}

/*******************************************
mergeCell에서 사용하는 함수
********************************************/
function merge(tbl, startRow, cnt, cellNum, length) {
	rows = tbl.rows;
	row  = rows[startRow];
	
	for( i = startRow + 1; i < startRow + cnt; i++ ) {
	    for( j = 0; j < length; j++) {
	        rows[i].deleteCell(cellNum);
	    }
	}
	for( j = 0; j < length; j++) {
	    row.cells[cellNum + j].rowSpan = cnt;
	}
}

/*******************************************
show - hide layer
********************************************/
function hideLayer(targetId){
	var toggleTarget = document.getElementById(targetId)
	toggleTarget.style.display = "none";
}
function showLayer(targetId){
	var toggleTarget = document.getElementById(targetId)
	toggleTarget.style.display = "block";
}

/*******************************************/
/**  iframe resize                        **/
/*******************************************/
function resizeIFrame(currentfr) {
	var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
    var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0;

	if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) {
		currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight + 27;
	} else if (currentfr.Document && currentfr.Document.body.scrollHeight) {
		currentfr.height = currentfr.Document.body.scrollHeight + 27;
	}
}

/********************************************/
/** 노출관리 이미지  사이즈 변경           **/
/********************************************/
function imgFit(obj, maxWidth, maxHeight) {
    var w = obj.width;
    var h = obj.height;
    
    if(w > maxWidth || h > maxHeight) {
        if(w > h) {
            nw = maxWidth;
            nh = Math.round((h*nw)/w);
        } else {
            nh = maxHeight;
            nw = Math.round((nh*w)/h);
        }
    } else {  /*if small*/
    	nw = maxWidth;
    	nh = maxHeight;
    }
    
    obj.width = nw;
    obj.height = nh;
    //alert(nw+"/"+nh);
}

// 회원가입
function goJoinInsert() {
	if(confirm("회원가입 페이지로 이동하시겠습니까?")) {
		window.top.document.location.href = "http://sso.kbs.co.kr/SSO/KBSWeb/member/Select.aspx";
	} else {
		return;
	}
}

// 회원수정
function goJoinUpdate() {
	if(confirm("회원수정 페이지로 이동하시겠습니까?")) {
		window.top.document.location.href = "http://sso.kbs.co.kr/SSO/KBSWeb/member/ConfirmUpdate.aspx";
	} else {
		return;
	}
}

// 로그온/로그아웃 메뉴 HTML(공통)
function goJoinMenuHtml(logonoff) {
	var str = "";
	if(logonoff) {
		str += "<a href=\"javascript:goLogout();\">로그아웃</a> | <a href=\"javascript:goJoinUpdate();\">정보수정</a>";
	} else {
		str += "<a href=\"javascript:goLogin();\">로그인</a> | <a href=\"javascript:goJoinInsert();\">회원가입</a>";
	}
	return str;
}

// 레터설정
function goLetterConfig() {
	var go_url = "http://newsletter.kbs.co.kr/modify.html";
	//var surl = "http://www.kbs.co.kr/asx/login/SSOLogon.php?from_url=" + go_url;
	
	var type = "615*480";
	var name = "letterPopup";
	openWindow(go_url, type, name);
}

//kbs뉴스홈 시사프로그램 버튼 
var RollerMainSisaProgram = new function () {
	var children;
	var ddChildren;
	var show_element_count = 5;
	var iTotalCount  = 0;
	var iIndex = 0;
	
	this.init = function(){
		this.children  = document.getElementById("sisa_program_area").childNodes;
		this.ddChildren =  new Array(); 
		this.show_element_count = 5;

		for( var i = 0; i < this.children.length;i++){
			if( "DD" == this.children[i].nodeName){
				this.ddChildren.push(this.children[i]);
			}
		}
		
		this.iTotalCount = this.ddChildren.length;
		
		this.iIndex = Math.floor(Math.random() * (this.ddChildren.length- 4))  ;
		this.show();
	}
	
	this.show = function (){
		for( var i = 0; i < this.ddChildren.length ; i++){
			if( i >= this.iIndex  && i < this.iIndex + this.show_element_count){
				this.ddChildren[i].style.display="block";
			} else {
				this.ddChildren[i].style.display="none";
			}
		}
	}
	
	this.move = function (move_type) {
		if( this.iTotalCount < this.show_element_count) return;
		if( move_type == 'prev'){
			if( (this.iIndex =  this.iIndex - 1) < 0) {
				this.iIndex = 0;
				this.remove(move_type);
			}
		} else {
			if( (this.iIndex =  this.iIndex + 1) > this.iTotalCount - this.show_element_count ) {
				this.iIndex = this.iTotalCount - this.show_element_count ;
				this.remove(move_type);
			}
		}
		this.show();
	}
	
	this.remove = function(move_type){
		var obj = document.getElementById("sisa_program_area");
		if( move_type =='prev'){
			obj.insertBefore( obj.removeChild(this.ddChildren[this.iTotalCount -1]) ,this.ddChildren[0]);
		} else if(move_type =='next' ){
			obj.appendChild( obj.removeChild(this.ddChildren[0])  );
		}
		
		while(this.ddChildren.pop()){}
			
		this.children  = document.getElementById("sisa_program_area").childNodes;
		for( var i = 0; i < this.children.length;i++){
			if( "DD" == this.children[i].nodeName){
				this.ddChildren.push(this.children[i]);
			}
		}
	}
}

document.write("<" + "script type=\"text/javascript\" language=\"JavaScript\" src=\"http://news.kbs.co.kr/javascript/common_divided.js\"></" + "script>");

