/*
 * TTS Script
 * (C)Copyright 2004-2008 CoreInterface,. Inc.
 *
 * 음성서비스 스크립트 본체
 */

/******************************************************************************
 * 환경설정
 *****************************************************************************/

/* 음성 중지버튼 눌렀을때 (ON->OFF) */
var ttsenv_onstop_href = "javascript:f_voiceStart('start')";
var ttsenv_onstop_src ="/image/common/voiceOff.gif";
var ttsenv_onstop_alt = '음성 시작';
var ttsenv_onstop_title = '음성 시작';
/* 음성 시작버튼 눌렀을때 (OFF->ON) ON 이미지 추가해주세요!! */
var ttsenv_onstart_href = "javascript:f_voiceStart('stop')";
var ttsenv_onstart_src ="/image/common/voiceOn.gif";
var ttsenv_onstart_alt = '음성 중지';
var ttsenv_onstart_title = '음성 중지';

/* IE 사용시 화면 확대축소 비율 */
var ttsenv_zoomRate = 20;   /* 화면 확대축소 비율 변동폭 (% 단위) */
var ttsenv_zoommaxRate = 200;   /* 화면 확대축소시 원크기대 최대 확대비율 (% 단위) */
var ttsenv_zoomminRate = 100;   /* 화면 확대축소시 원크기대 최대 축소비율 (% 단위) */
var ttsenv_zoomDefault = 100;	/* 기본 화면 크기 */

/* NS 사용시 글자 확대축소 비율 */
var ttsenv_fontRate = 2;    /* 2pt 단위 */
var ttsenv_fontmaxRate = 19;
var ttsenv_fontminRate = 9; /* 최소 9pt */
var ttsenv_fontDefault = '';	/* 디폴트 => ''이 들어있으면 스타일시트 값을 따른다 */

/* 글자색 배열 */
var ttsenv_fontcolor = new Array();
ttsenv_fontcolor[0] = "";
ttsenv_fontcolor[1] = "#000000";
ttsenv_fontcolor[2] = "#ffff00";
ttsenv_fontcolor[3] = "#ffffff";
ttsenv_fontcolor[4] = "#6666ff";
ttsenv_fontcolor[5] = "#ff6666";
ttsenv_fontcolor[6] = "#ff66ff";
ttsenv_fontcolor[7] = "#66ff66";

/* 배경색 배열 */
var ttsenv_bgcolor = new Array();
ttsenv_bgcolor[0] = "";
ttsenv_bgcolor[1] = "#ffffff";
ttsenv_bgcolor[2] = "#000000";
ttsenv_bgcolor[3] = "#6666ff";
ttsenv_bgcolor[4] = "#ff6666";
ttsenv_bgcolor[5] = "#ff66ff";
ttsenv_bgcolor[6] = "#66ff66";

/* 기본 음성속도 (1~5) */
var ttsenv_defaultspeed = 3;
/* 기본 음성볼륨 (1~5) */
var ttsenv_defaultvolume = 3;

/* 프레임방식 사용시 대기횟수와 1회 대기당 시간(ms 단위) */
var ttsenv_wait_count=100;
var ttsenv_wait_time=100;

var ttsenv_callsetzoom=false;   /* activeX의 SetZoom()을 호출할지 여부. 1,0,0,30 이후부터 지원되므로 이전사용자는 disable */
var ttsenv_useframe=true;   /* 프레임 사용시 true. activex.js로 직접삽입시는 false */

/******************************************************************************
 * TTS Script Code
 *****************************************************************************/
var tts_webgenStyleSheet=null;

var tts_curRate;
var tts_fontcolorindex;
var tts_bgcolorindex;
var tts_curfontsize;

/* inText로 입력받은 문자열 재생 (플래시 사용시 필요함) */
function f_playinput(inText)
{
    if(tts_readCookie("voiceStart")== "start") {
	sRes = IsAvailable();
	if( sRes == 1 ) {
	    if(ttsenv_useframe==true)
		sBot.OnSendText(inText);
	    else
		OnSendText(inText);
	}
    }
}

/* f_playinput()과 동일 */
function f_playinput_d(inText)
{
    if(tts_readCookie("voiceStart")== "start") {
	sRes = IsAvailable();
	if( sRes == 1 ) {
	    if(ttsenv_useframe==true)
		sBot.OnSendText(inText);
	    else
		OnSendText(inText);
	}
    }
}

/* <body> onload 이벤트에 걸어주어야 함. 쿠키를 읽어서 음성을 예전 페이지의 상태대로 설정함 */
function f_setVoice()
{
    if(document.addEventListener) {
        document.addEventListener("keydown",f_ctrlkey_ff,false/*,0,true*/);
    } else {
        document.attachEvent("onkeydown",f_ctrlkey_ie);
    }
    if(tts_readCookie("voiceStart").length == 0)
	tts_setCookie("voiceStart", "stop", 1);
    if(tts_readCookie("voiceSpeed").length == 0)
	tts_setCookie("voiceSpeed", 3, 1);
    if(tts_readCookie("voiceVolum").length == 0)
	tts_setCookie("voiceVolum", 3, 1);
    if(tts_readCookie("voiceStart") == "start") {   /* 음성 ON 시 */
	f_voiceStart("start");
	f_setVoiceSpeed("NO");
	f_setVoiceVolume("NO");
    } else {	/* 음성 OFF시 - 프레임모드일경우만 처리할 필요 있음 */
	if(ttsenv_useframe==true) {
	    if(sBot.SwitchCheck() == true)
		sBot.SwitchMode('0');
	}
    }
}

/* <body> onload 이벤트에 걸어주어야 함. 쿠키를 읽어서 화면 확대축소비율을 예전 페이지의 상태대로 설정함 */
function f_setInit()
{
    if((GetCookie("zoomVal") != null) && (GetCookie("zoomVal") != "")) {
	tts_curRate = GetCookie("zoomVal");
	if(!((tts_curRate >ttsenv_zoomminRate)&(tts_curRate<ttsenv_zoommaxRate)))
	    tts_curRate = ttsenv_zoomDefault;
	tts_setCookie("zoomVal",tts_curRate, 1);
	f_zoominout('zoom','');
    } else {
	tts_curRate = ttsenv_zoomDefault;
	tts_setCookie("zoomVal",tts_curRate, 1);
	f_zoominout('zoom','');
    }
    if((GetCookie("fontSize")!=null)&&(GetCookie("fontSize")!="")) {
	tts_curfontsize=GetCookie("fontSize");
	if((tts_curfontsize>ttsenv_fontmaxRate)||(tts_curfontsize<ttsenv_fontminRate))
	    tts_curfontsize=ttsenv_fontDefault;
	tts_setCookie("fontSize",tts_curfontsize,1);
    } else {
	tts_curfontsize=ttsenv_fontDefault;
	tts_setCookie("fontSize",tts_curfontsize,1);
    }
    if(tts_readCookie("fontColorIndex").length == 0) {
	tts_setCookie("fontColorIndex", 0, 1);
    } else
	tts_fontcolorindex= tts_readCookie("fontColorIndex");
    if(tts_readCookie("bgColorIndex").length == 0)
	tts_setCookie("bgColorIndex", 0, 1);
    else
	tts_bgcolorindex = tts_readCookie("bgColorIndex");
    f_setFace();
}

/* 글자색설정 */
function f_setFontColor1(param)
{
    var keyCode = window.event.keyCode;
    if( keyCode == 13 ) {
	if ( (param >= 0) && (param <= 7) ) {
	    tts_fontcolorindex = param;
	    f_setFace();
	}
    }
}

/* 글자색설정 - 설정 콤보박스에 onchange 이벤트로 걸어둠 */
function f_setFontColor2(param)
{
    if ( (param >= 0) && (param <= 7) ) {
	tts_fontcolorindex = param;
	f_setFace();
    }
}

/* 바탕색설정 */
function f_setBgColor1(param)
{
    var keyCode = window.event.keyCode;
    if( keyCode == 13 ) {
	if ( param >= 0 && param <= 6 ) {
	    tts_bgcolorindex = param;
	    f_setFace();
	}
    }
}

/* 바탕색설정 - 설정 콤보박스에 onchange 이벤트로 걸어둠 */
function f_setBgColor2(param)
{
    if ( param >= 0 && param <= 6 ) {
	tts_bgcolorindex = param;
	f_setFace();
    }
}

/* 글자크기 / 글자색 / 배경색 설정 */
function f_setFace()
{
/*
    var objs_td		= new Array();
    var objs_th		= new Array();
    var	objs_a		= new Array();
    var	objs_span	= new Array();
    var objs_p		= new Array();

    objs_td   = document.getElementsByTagName("td");
    objs_th   = document.getElementsByTagName("th");
    objs_a    = document.getElementsByTagName("a");
    objs_span = document.getElementsByTagName("span");
    objs_p    = document.getElementsByTagName("P");
    objs_div  = document.getElementsByTagName("DIV");
    objs_body = document.getElementsByTagName("BODY");
    for (i=0;i<objs_td.length;i++) {
	objs_td[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	objs_td[i].style.backgroundColor=ttsenv_bgcolor[tts_bgcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_td[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_td[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_th.length;i++) {
	objs_th[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	objs_th[i].style.backgroundColor=ttsenv_bgcolor[tts_bgcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_th[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_th[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_div.length;i++) {
	objs_div[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	objs_div[i].style.backgroundColor=ttsenv_bgcolor[tts_bgcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_div[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_div[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_body.length;i++) {
	objs_body[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	objs_body[i].style.backgroundColor=ttsenv_bgcolor[tts_bgcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_body[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_body[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_a.length;i++) {
	objs_a[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_a[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_a[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_span.length;i++) {
	objs_span[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_span[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_span[i].style.fontSize='';
	}
    }
    for (i=0;i<objs_p.length;i++) {
	objs_p[i].style.color=ttsenv_fontcolor[tts_fontcolorindex];
	if((tts_checkbrowser())==1) {
	    if(tts_curfontsize!='')
		objs_p[i].style.fontSize=tts_curfontsize+'px';
	    else
		objs_p[i].style.fontSize='';
	}
    }
    if ( document.all['select2'] == "[object]" ) {
	document.all['select2'].selectedIndex = parseInt(tts_fontcolorindex);
	document.all['select'].selectedIndex = parseInt(tts_bgcolorindex);
    }
    tts_setCookie("fontColorIndex", tts_fontcolorindex , 1);
    tts_setCookie("bgColorIndex", tts_bgcolorindex , 1);
    if((tts_checkbrowser())==1)
	tts_setCookie("fontSize", tts_curfontsize, 1);
*/
    var font_index=parseInt(tts_fontcolorindex);
    var bg_index=parseInt(tts_bgcolorindex);
    if(isNaN(font_index)==true) {
        font_index=0;
    }
    if(isNaN(bg_index)==true) {
        bg_index=0;
    }
    f_setface_run(document.body);
    if(document.getElementById('select2')!=null) {
        document.getElementById('select2').selectedIndex = font_index;
    }
    if(document.getElementById('select')!=null) {
        document.getElementById('select').selectedIndex = bg_index;
    }
    tts_setCookie("fontColorIndex", font_index, 1);
    tts_setCookie("bgColorIndex", bg_index, 1);
    if(tts_checkbrowser()==1) {
        tts_setCookie("fontSize", tts_curfontsize, 1);
    }
}

function f_setface_run(obj) {
    if(obj==null) {
        return;
    }
    if(obj.childNodes!=null) {
        if(obj.childNodes.length>0) {
            var i;
            var s=false;
            if(obj.style!=null) {
                obj.style.backgroundColor=ttsenv_bgcolor[tts_bgcolorindex];
                obj.style.color=ttsenv_fontcolor[tts_fontcolorindex];
            }
            for(i=0;i<obj.childNodes.length;i++) {
                if(obj.childNodes[i].nodeName=="#text") {
                    if(s==false) {
                        if(obj.style!=null) {
                            if(tts_checkbrowser()!=1) {
                                if(tts_curfontsize==null) {
                                    obj.style.fontSize='';
                                } else if(tts_curfontsize=='') {
                                    obj.style.fontSize='';
                                } else {
                                    obj.style.fontSize=tts_curfontsize+'pt';
                                }
                            }
                        }
                        s=true;
                    }
                } else {
                    f_setface_run(obj.childNodes[i]);
                }
            }
        }
    }
}

/* 화면 확대/축소 - 외부호출 */
function f_scalescreen(contentid,how)
{
    if((tts_checkbrowser())==1)
	f_zoominout(contentid,how); /* IE일 경우 */
    else {  /* IE가 아닐 경우 (폰트 확대/축소) */
        if(how=='in') { /* 확대 */
            if(tts_curfontsize==null) {
                tts_curfontsize=ttsenv_fontminRate;
            } else if(tts_curfontsize=='') {
                tts_curfontsize=ttsenv_fontminRate;
            } else {
                tts_curfontsize=tts_curfontsize-(-ttsenv_fontRate);
                if(tts_curfontsize>ttsenv_fontmaxRate) {
                    tts_curfontsize=ttsenv_fontmaxRate;
                }
            }
        } else if(how=='out') { /* 축소 */
            if(tts_curfontsize!=null) {
                if(tts_curfontsize!='') {
                    tts_curfontsize=tts_curfontsize-ttsenv_fontRate;
                    if(tts_curfontsize<ttsenv_fontminRate) {
                        tts_curfontsize='';
                    }
                }
            }
        } else {
            if(tts_curfontsize!=null) {
                if(tts_curfontsize!='') {
                    if(tts_curfontsize<ttsenv_fontminRate) {
                        tts_curfontsize='';
                    } else if(tts_curfontsize>ttsenv_fontmaxRate) {
                        tts_curfontsize=ttsenv_fontmaxRate;
                    }
                }
            }
        }
        tts_setCookie("fontSize", tts_curfontsize, 1);
        f_setFace();
/*
	if(how=='in') {
	    tts_curfontsize=tts_curfontsize+ttsenv_fontRate;
	    if(tts_curfontsize>ttsenv_fontmaxRate)
		tts_curfontsize=ttsenv_fontmaxRate;
	} else if(how=='out') {
	    tts_curfontsize=tts_curfontsize-ttsenv_fontRate;
	    if(tts_curfontsize>ttsenv_fontminRate)
		ttscurfontsize=ttsenv_fontminRate;
	}
	tts_setCookie("fontSize", tts_curfontsize, 1);
	f_setFace();
*/
    }
}

var webgen_userAgent = navigator.userAgent.toLowerCase();

var webgen_browser =
{
	version: (webgen_userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
	safari: /webkit/.test( webgen_userAgent ),
	opera: /opera/.test( webgen_userAgent ),
	msie: /msie/.test( webgen_userAgent ) && !/opera/.test( webgen_userAgent ),
	mozilla: /mozilla/.test( webgen_userAgent ) && !/(compatible|webkit)/.test( webgen_userAgent ),
        chrome: /chrome/.test (webgen_userAgent )
};


/* 화면 확대/축소 */
function f_zoominout(contentid, how)
{
    function zoomHTML(zoomValue) {
        if (webgen_browser.msie) {
            if(webgen_browser.version == "8.0") {
                zoomHTML_IE8(zoomValue);
            } else {
                zoomHTML_IE7(zoomValue);
            }
        }
    }
    function zoomHTML_IE8(zoomValue) {
        document.body.style.zoom  = zoomValue + "%";
        applyOverflow(document.body, false);
        if (tts_webgenStyleSheet == null) {
            tts_webgenStyleSheet = document.createStyleSheet('webgen.css');
        }
        if(parseInt(zoomValue) > 100) {
            if (tts_webgenStyleSheet != null) {
                if (tts_webgenStyleSheet.rules.length > 0 ) {
                    tts_webgenStyleSheet.removeRule(0);
                }
                tts_webgenStyleSheet.addRule("html","overflow: scroll;");
            }
        } else {
            if (tts_webgenStyleSheet != null) {
                if (tts_webgenStyleSheet.rules.length > 0 ) {
                    tts_webgenStyleSheet.removeRule(0);
                }
            }
        }
    }
    function applyOverflow(rootNode, parentApply) {
        var nodeItem;
        var isApply = parentApply;
        for(var i=0; i<rootNode.childNodes.length; i++) {
            nodeItem = rootNode.childNodes[i];
            if(nodeItem.nodeType == "1") {
                if (!parentApply) {
                    nodeItem.style.overflow = "hidden";
                    isApply = true;
                }
                applyOverflow(rootNode.childNodes.item(i),isApply);
            }
        }
    }
    function zoomHTML_IE7(zoomValue) {
        applyZoom(document.body, false, zoomValue);
    }

    function applyZoom(rootNode, parentZoom, zoomValue) {
        var nodeItem;
        var isZoom = parentZoom;
        for(var i=0; i<rootNode.childNodes.length; i++) {
            nodeItem = rootNode.childNodes[i];
            if(nodeItem.nodeType == "1") {
                if (!parentZoom) {
                    nodeItem.style.zoom = zoomValue+ "%";
                    isZoom = true;
                }
                applyZoom(rootNode.childNodes.item(i),isZoom, zoomValue);
            }
        }
    }

	var sRes;

    if(((how=="in")&&(tts_curRate >= ttsenv_zoommaxRate))||((how == "out") && (tts_curRate <= ttsenv_zoomminRate)))
	return;
    if (how=="in") {
	tts_curRate=(-(-(tts_curRate)))+(-(-(ttsenv_zoomRate)));
	if(tts_curRate>ttsenv_zoommaxRate)
	    tts_curRate=ttsenv_zoommaxRate;
		zoomHTML(tts_curRate);
	//document.body.style.zoom = tts_curRate + '%';
    } else if (how =="out") {
	tts_curRate = (-(-(tts_curRate))) - (-(-(ttsenv_zoomRate)));
	if(tts_curRate<ttsenv_zoomminRate)
	    tts_curRate=ttsenv_zoomminRate;
	zoomHTML(tts_curRate);
	//document.body.style.zoom = tts_curRate + '%';
    } else
	zoomHTML(tts_curRate);
	//document.body.style.zoom = tts_curRate + '%';	/* 예전페이지 설정 복구시 f_setInit()에서 직접 호출됨 */
    tts_setCookie("zoomVal",tts_curRate, 1);
    if(ttsenv_callsetzoom==true) {
	sRes=IsAvailable();
	if(sRes==1) {
	    if(ttsenv_useframe==true)
		sBot.OnSetZoom(tts_curRate);
	    else
		OnSetZoom(tts_curRate);
	}
    }
}

/* 쿠키 읽기 */
function tts_readCookie( str )
{
    var key = str + "=" ;
    var key_len = key.length ;
    var cookie_len = document.cookie.length;
    var i = 0;

    while (i < cookie_len ) {
	var j = i + key_len;
	if ( document.cookie.substring( i, j ) == key ) {
	    var cookie_end = document.cookie.indexOf(";",j);
	    if (cookie_end == -1)
		cookie_end = document.cookie.length;
	    return document.cookie.substring(j,cookie_end );
	}
	i++
    }
    return ""
}

function GetCookie( name )
{
    var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length ) {
	var y = (x+nameOfCookie.length);
	if ( document.cookie.substring( x, y ) == nameOfCookie ) {
	    if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
		endOfCookie = document.cookie.length;
	    return unescape( document.cookie.substring( y, endOfCookie ) );
	}
	x = document.cookie.indexOf( " ", x ) + 1;
	if ( x == 0 )  break;
    }
    return "";
}

/*------------------------------------------------------------------*/
/*  펑션명   : tts_setCookie                                        */
/*  내용설명 : 쿠키값을 설정한다.                                   */
/*  호출 모듈명                                                     */
/*      1) html        :                                            */
/*      2) JSP/servlet :                                            */
/*      3) script func.:                                            */
/*  매개변수  : key값, value값, 쿠키 유효일자-1                     */
/*  특이사항  :                                                     */
/*------------------------------------------------------------------*/
function tts_setCookie(key, value, term){
    var expire = new Date();
    expire.setDate( expire.getDate() + term );
    document.cookie = key + "=" + escape( value ) + "; path=/; expires=" + expire.toGMTString() + ";";
}

/* IE여부 체크 (IE여야만 zoominout이 작동한다) */
function tts_checkbrowser()
{
    return 0;
    if(window.navigator.userAgent.indexOf("MSIE")>0)
	return 1;
    return 0;
}

/* 환경설정 초기화 */
function f_setBasic(mode, load)
{
    tts_setCookie("fontColorIndex", 0, 1);
    tts_fontcolorindex = tts_readCookie("fontColorIndex");
    tts_setCookie("bgColorIndex", 0, 1);
    tts_bgcolorindex = tts_readCookie("bgColorIndex");
    if(tts_checkbrowser()==1) {
        tts_setCookie("zoomVal",ttsenv_zoomDefault, 1);
        tts_curRate = ttsenv_zoomDefault;
        f_scalescreen('zoom','');
    } else {
        tts_setCookie("fontSize",ttsenv_fontDefault,1);
        tts_curfontsize = tts_readCookie("fontSize");
    }
    f_setFace();
    tts_setCookie("voiceStart", "stop", 1);
    f_voiceStart( tts_readCookie("voiceStart") );
    tts_setCookie("voiceSpeed", ttsenv_defaultspeed, 1);
    f_setVoiceSpeed( "NO" );
    tts_setCookie("voiceVolum", ttsenv_defaultvolume, 1);
    f_setVoiceVolume( "NO" );
}

/* 속도 설정. mode='up' -> 속도빠르게, mode='down' -> 속도느리게 */
function f_setVoiceSpeed(mode)
{
    var sSpeed;
    var strPlay = "";

    if ( tts_readCookie("voiceSpeed").length == 0 )
	sSpeed = ttsenv_defaultspeed;
    else
	sSpeed = tts_readCookie("voiceSpeed");
    /* 1~5 사이 한계값을 넘어가지 않도록 조치 */
    if(sSpeed<1)
	sSpeed=1;
    else if(sSpeed>5)
	sSpeed=5;
    sRes = IsAvailable();
    if (sRes != 0) {
	if( mode == "up" ) {
	    if( sSpeed < 5 ) sSpeed = parseInt(sSpeed) + 1;
	    f_playinput("음성 속도"+ sSpeed);
	} else if( mode == "down" ){
	    if( sSpeed > 1 ) sSpeed = parseInt(sSpeed) - 1;
	    f_playinput("음성 속도 "+ sSpeed);
	}
	tts_setCookie( "voiceSpeed", sSpeed, 1 );
	if(ttsenv_useframe==true)
	    sBot.OnSetSpeed(sSpeed);
	else
	    OnSetSpeed(sSpeed);
    }
}

/* 볼륨 설정, mode='up' -> 볼륨크게, mode='down' -> 볼륨작게 */
function f_setVoiceVolume(mode)
{
    var sVol;

    if ( tts_readCookie("voiceVolum").length == 0 )
	sVol = ttsenv_defaultvolume;
    else
	sVol = tts_readCookie("voiceVolum");
    /* 1~5 사이 범위 넘어가지 않도록 조치함 */
    if(sVol<1)
	sVol=1;
    else if(sVol>5)
	sVol=5;
    sRes = IsAvailable();
    if ( sRes != 0 ) {
	if( mode == "up" ) {
	    if( sVol < 5 )
		sVol = parseFloat(sVol) + 1;
	    f_playinput("음성 볼륨 "+ sVol);
	} else if( mode == "down" ) {
	    if( sVol > 1 )
		sVol = parseFloat(sVol) - 1;
	    f_playinput("음성 볼륨 "+ sVol);
	}
	//Cookie 재설정
	tts_setCookie( "voiceVolum", sVol, 1 );
	if(ttsenv_useframe==true)
	    sBot.OnSetVolume(sVol);
	else
	    OnSetVolume(sVol);
    }
}

/* f_voiceStart() 부속 프레임 제어함수 / 2006/10/18 추가됨 */
var sRes;
var ss = this;
var f_voiceOn_delLEN;
var f_voiceOn_delCNT;

function IsAvailable()
{
    if(ttsenv_useframe==false)	/* 프레임 미사용시는 의미없으므로 무조건 true 리턴처리 */
	return true;
    //if(ss) {
	//if(sBot.IsAvailable())
	//    return true;
	//else
	 //   return false;
   // }
    return false;
}

function f_voiceOn_delST() {
    f_voiceOn_delLEN = ttsenv_wait_time;	/* 1회 대기시간 100ms */
    f_voiceOn_delCNT = ttsenv_wait_count;	/* 대기횟수, 100회 */
}

function f_voiceOn_delCN()
{
    if(f_voiceOn_delCNT!=0) {
	if(IsAvailable()) {
	    if(sBot.OnStart()) {  /* 정상수행시 리턴 */
		if(ttsenv_callsetzoom==true)
		    sBot.OnSetZoom(tts_curRate);
		return;
	    } else
		setTimeout('f_voiceOn_delCN()',f_voiceOn_delLEN);
	} else
	    setTimeout('f_voiceOn_delCN()',f_voiceOn_delLEN);
    } else {
	alert('음성 ON 실패');
	f_voiceStart('stop');
    }
    f_voiceOn_delCNT = (-(-(f_voiceOn_delCNT))) - 1;
}

function f_voiceStart(val)
{
    if(ttsenv_useframe==true)
	f_voiceStart_frame(val);
    else
	f_voiceStart_noframe(val);
}

/* 음성켜기 / 음성끄기, val = "stop" : 음성끄기, val = "start : 음성켜기 */
function f_voiceStart_frame(val)
{
    if(ss) {
	if(val == "start") {
            if(!(f_detectcontrol())) {
                /* IE일 경우에만 연다 */
                tts_setCookie("voiceStart", "start", 1);    /* 쿠키 사전셋팅 (리프레시후 자동ON시키기 위함) */
                if(navigator.appName == "Microsoft Internet Explorer") {
                    var iframe = document.createElement("iframe");
                    iframe.id="install_module";
                    iframe.name="install_module";
                    iframe.style.width ="0";
                    iframe.style.height="0";
                    iframe.style.borderWidth="0";
                    iframe.style.margin="0";
                    iframe.style.padding="0";
                    iframe.title="음성모듈설치";
                    document.body.appendChild(iframe);
                    //window.open('/tts/installmodule.html','','width=500px,height=250px,toolbar=no,menubar=no,location=no,scrollbars=no,directories=no');
                    iframe.src='/tts/installmodule.html';
                }
                return;     /* 리프레시 된 후 onload 과정에서 음성이 다시 Enable 된다. */
            }
	    if(sBot.SwitchCheck() == false) {
		sBot.SwitchMode('1');
		f_voiceOn_delST();
		f_voiceOn_delCN();
	    } else {
		sRes = sBot.OnStart();
		if(sRes == 0) //sRes = 0이면 모듈이 떠있지않을 때
		    return;
		if(ttsenv_callsetzoom==true)
		    sBot.OnSetZoom(tts_curRate);
	    }
	    /* 음성버튼은 일단 ON 한다. 실패시는 자동으로 OFF한다. */
/*
	    document.all['voice_link'].href = ttsenv_onstart_href;
	    document.all['voice_start'].src = ttsenv_onstart_src;
	    document.all['voice_start'].alt = ttsenv_onstart_alt;
	    document.all['voice_start'].title = ttsenv_onstart_title;
*/
		document.all.voice_on.style.display = 'none';
		document.all.voice_off.style.display = 'block';

	    //displayOn(2);
	    tts_setCookie("voiceStart", "start", 1);
	} else if(val == "stop") {
	    //if(sBot && sBot.SwitchCheck() == true)
		//if (sBot)
		//{
		//sBot.SwitchMode('0');
		//}
/*
	    document.all['voice_link'].href = ttsenv_onstop_href;
	    document.all['voice_start'].src = ttsenv_onstop_src;
	    document.all['voice_start'].alt = ttsenv_onstop_alt;
	    document.all['voice_start'].title = ttsenv_onstop_title;

		document.all.voice_on.style.display = 'block';
		document.all.voice_off.style.display = 'none';

	    //displayOn(1);
	    tts_setCookie("voiceStart", "stop", 1);
	    sBot.OnStop();
*/
	}
    }
}

function f_voiceStart_noframe(val) {
    if(val == "start") {
	if(DetectActiveXControl())    /* DetectActiveXControl()은 activex.js 내에 있다 */
	    sRes = OnStart();
	else {
	    /* IE일 경우에만 연다 */
	    if(navigator.appName == "Microsoft Internet Explorer")
		window.open('installmodule.html','','width=408px,height=184px,toolbar=no,menubar=no,location=no,scrollbars=no,directories=no');
	    return;
	}
	if(sRes == 0) //sRes = 0이면 모듈이 떠있지않을 때
	    return;
	/* 음성버튼은 일단 ON 한다. 실패시는 자동으로 OFF한다. */
/*	document.all['voice_link'].href = tts_onstart_href;
	document.all['voice_start'].src = tts_onstart_src;
	document.all['voice_start'].alt = tts_onstart_alt;
	document.all['voice_start'].title = tts_onstart_title;
*/
	document.all.voice_on.style.display = 'none';
	document.all.voice_off.style.display = 'block';

	displayOn(2);
	tts_setCookie("voiceStart", "start", 1);
    } else if(val == "stop") {
	OnStop();
/*	document.all['voice_link'].href = tts_onstop_href;
	document.all['voice_start'].src = tts_onstop_src;
	document.all['voice_start'].alt = tts_onstop_alt;
	document.all['voice_start'].title = tts_onstop_title;
*/
	document.all.voice_on.style.display = 'block';
	document.all.voice_off.style.display = 'none';

	displayOn(1);
	tts_setCookie("voiceStart", "stop", 1);
    }
}

/* 음성 ON/OFF시 일부 버튼을 가리는 등의 조작을 함. 툴바의 형태에 따라서 사용자가 수정해주어야만 함
 * var = 1 -> 음성 ON->OFF, var = 2 -> 음성 OFF->ON */
function displayOn(val){
    if(val==1) {
		for(i=1; i <=2; i++) {	/* 음성 OFF시 */
		    if(eval('document.all.tts_tool_on_' + i) == '[object HTMLTableCellElement]') {
				var temp = eval('document.all.tts_tool_on_' + i);
				temp.style.display = 'none';
		    }
		}
    } else {
		for(i=1; i<=2; i++) {	/* 음성 ON시 */
		    var temp = eval('document.all.tts_tool_on_' + i);
		    temp.style.display = '';
		}
    }
}

/* ActiveX 컨트롤 활성화 처리 */
function f_detectcontrol()
{
    /* 브라우저를 확인한다. IE에서만 돌아가므로 IE 아닐경우는 모두 false 되돌린다. */
    if(navigator.appName != "Microsoft Internet Explorer") {
	return false;
    }
    try
    {
        var xObj = new ActiveXObject("HCIGENNAVI.HCIGenNaviCtrl.1");
        if(xObj)
        {
            Installed = true;
        }
        else
        {
            Installed = false;
        }
    }
    catch(ex)
    {
        Installed = false;
    }

    if(Installed == true)
    {
        return true;
    }
    else
    {
        return false;
    }
}


/******************************************************************************
 * Deprecated Function
 *****************************************************************************/

/* <select>가 onchange 이벤트 일으킬때의 음성. CoreWebGen.cab일경우에만 사용하며 WebGenNavi.cab, HCIGenNavi.cab일 경우는
 * 자동으로 붙이므로 사용하지 않음 */
function f_selectVoice2(obj)
{
    var opts = obj.options;
    var strText  = "";

    if (tts_readCookie("voiceStart")== "start") {
	for (var i=0; i<opts.length; i++)
	    if ( opts[i].selected ) strText = opts[i].text;
	f_playinput(strText);
    }
}

/* <select>가 onfocus 이벤트 일으킬때의 음성. CoreWebGen.cab일경우에만 사용하며 WebGenNavi.cab, HCIGenNavi.cab일 경우는
 * 자동으로 붙이므로 사용하지 않음 */
function f_selectVoice(str, obj) {
    var opts = obj.options;
    var strText  = "";

    if (tts_readCookie("voiceStart")== "start"){
	for (var i=0; i<opts.length; i++)
	    if ( opts[i].selected ) strText = (String)(str+ ". 상하 화살표키로 선택. " + opts[i].text);
	f_playinput(strText);
    }
}

function f_ctrlkey_ie()
{
    //if(ttsenv_opt_useshortcut==true) {
        /* Ctrl+F12 음성 on/off 단축키 기능 */
        if (window.event.ctrlKey && (event.keyCode == 123)){
            var vStart = tts_readCookie("voiceStart");
            if (vStart == "start") {
                f_voiceStart( "stop");
            } else {
                f_voiceStart( "start");
            }
        }
        /* Ctrl+Shift+T 상단메뉴 단축키 기능 */
        if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 84){
            if(document.getElementById('tmenuptr')!=null) {
                document.getElementById('tmenuptr').focus();	// 상단 Home으로 focus() 이동
            }
        }
        /* Ctrl+Shift+L 좌측서브메뉴 단축키 기능 */
        if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 76){
            if(document.getElementById('lmenuptr')!=null) {
                document.getElementById('lmenuptr').focus();	// 좌측 focus이동할 부분의 아이디 입력
            }
        }
        /* Ctrl+Shift+C 본문 단축키 기능 */
        if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 67){
            if(document.getElementById('startptr')!=null) {
                document.getElementById('startptr').focus();	// 본문 focus이동할 부분의 아이디 입력
            }
        }
        /* Ctrl+Shift+B 문서끝 단축키 기능 */
        if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 66){
            if(document.getElementById('bottomptr')!=null) {
                document.getElementById('bottomptr').focus();	// 하단 focus이동할 부분의 아이디 입력
            }
        }
        if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 72){
            if(document.getElementById('movehelp')!=null) {
                document.getElementById('movehelp').focus();
            }
            if(document.getElementById('Helpplayer')!=null) {
                document.getElementById("Helpplayer").play();
            }
        }
    //}
}

function f_ctrlkey_ff(e)
{
    //if(ttsenv_opt_useshortcut==true) {
        /* Ctrl+F12 음성 on/off 단축키 기능 */
        if (e.ctrlKey && (e.keyCode == 123)){
            var vStart = tts_readCookie("voiceStart");
            if (vStart == "start") {
                f_voiceStart( "stop");
            } else {
                f_voiceStart( "start");
            }
        }
        /* Ctrl+Shift+T 상단메뉴 단축키 기능 */
        if (e.ctrlKey &&  e.shiftKey && e.keyCode == 84){
            if(document.getElementById('tmenuptr')!=null) {
                document.getElementById('tmenuptr').focus();	// 상단 Home으로 focus() 이동
            }
        }
        /* Ctrl+Shift+L 좌측서브메뉴 단축키 기능 */
        if (e.ctrlKey &&  e.shiftKey && e.keyCode == 76){
            if(document.getElementById('lmenuptr')!=null) {
                document.getElementById('lmenuptr').focus();	// 좌측 focus이동할 부분의 아이디 입력
            }
        }
        /* Ctrl+Shift+C 본문 단축키 기능 */
        if (e.ctrlKey &&  e.shiftKey && e.keyCode == 67){
            if(document.getElementById('startptr')!=null) {
                document.getElementById('startptr').focus();	// 본문 focus이동할 부분의 아이디 입력
            }
        }
        /* Ctrl+Shift+B 문서끝 단축키 기능 */
        if (e.ctrlKey &&  e.shiftKey && e.keyCode == 66){
            if(document.getElementById('bottomptr')!=null) {
                document.getElementById('bottomptr').focus();	// 하단 focus이동할 부분의 아이디 입력
            }
        }
        if (e.ctrlKey &&  e.shiftKey && e.keyCode == 72){
            if(document.getElementById('movehelp')!=null) {
                document.getElementById('movehelp').focus();
            }
            if(document.getElementById('Helpplayer')!=null) {
                document.getElementById("Helpplayer").play();
            }
        }
    //}
}

