//fontSize Defalut
var fontSize = 12;
//fontColorIndex Defalut(0은 글자색)
var fontColorIndex = 0;
//fontColorIndex Defalut(0은 바탕색)
var bgColorIndex = 0;

//글자색 배열
fontColor = new Array();
fontColor[0] = "";
fontColor[1] = "";
fontColor[2] = "#ffff00";
fontColor[3] = "#ffffff";
fontColor[4] = "#6666ff";
fontColor[5] = "#ff6666";
fontColor[6] = "#ff66ff";
fontColor[7] = "#66ff66";

//배경색 배열
bgColor = new Array();
bgColor[0] = "";
bgColor[1] = "";
bgColor[2] = "#000000";
bgColor[3] = "#6666ff";
bgColor[4] = "#ff6666";
bgColor[5] = "#ff66ff";
bgColor[6] = "#66ff66";

var zoomRate = 20;
var maxRate = 200;
var minRate = 100;


function tts_setCookie( key, value, term ){
	var expire = new Date();
	expire.setDate( expire.getDate() + term );
	document.cookie = key + "=" + escape( value ) + "; domain=test.gbgs.go.kr; path=/; expires=" + expire.toGMTString() + ";";
}

/*----------------------------------------------------------------------------*/
/* NAME : f_playinput()                                                       */
/* DESC : 서브페이지에서 사용자가 입력한 텍스트를 음성으로 합성하여 재생한다. */
/*----------------------------------------------------------------------------*/
function f_playinput(inText){
    if(readCookie("voiceStart")== "start"){
		 sRes = sBot.IsAvailable();
		if( sRes == 1 )
		{
			sBot.OnSendText(inText);
			//parent.frames[1].OnSendText(inText);
		}
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_playinput_d()													  */
/* DESC : 서브페이지에서 사용자가 입력한 텍스트를 음절단위로 합성하여 재생한다*/
/*----------------------------------------------------------------------------*/
function f_playinput_d(inText){

	if(readCookie("voiceStart")== "start"){
		 sRes = sBot.IsAvailable();
		if( sRes == 1 )
		{
			sBot.OnSendText( inText );
		}
	}

}

function f_playInput_d(inText){

	if(readCookie("voiceStart")== "start"){
		 sRes = sBot.IsAvailable();
		if( sRes == 1 )
		{
			sBot.OnSendText( inText );
		}
	}

}

/*----------------------------------------------------------------------------*/
/* NAME : f_selectVoice2()													  */
/* DESC : 콤보박스에 onChange됐을 때 음성									  */

/*----------------------------------------------------------------------------*/
function f_selectVoice2(obj) {
	var opts = obj.options;
	var strText  = "";

	if (readCookie("voiceStart")== "start"){
		for (var i=0; i<opts.length; i++) {
			if ( opts[i].selected ) strText = opts[i].text;
		}
		f_playinput(strText);
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_selectVoice()													  */
/* DESC : 셀렉트 박스에 onFocus됐을 때 음성									  */

/*----------------------------------------------------------------------------*/
function f_selectVoice(str, obj) {
	var opts = obj.options;
	var strText  = "";

	if (readCookie("voiceStart")== "start"){
		for (var i=0; i<opts.length; i++) {
			if ( opts[i].selected ) strText = (String)(str+ ". 상하 화살표키로 선택. " + opts[i].text);
		}
		f_playinput(strText);
	}
}


/*----------------------------------------------------------------------------*/
/* NAME : f_setVoice()                                                        */
/* DESC : 화면이 처음 Load되었을 때 실행되는 함수(음성관련)                   */

/*----------------------------------------------------------------------------*/
function f_setVoice()
{
/*
	var strXTag;
	strXTag = "<OBJECT ID=\"CoreWebGen\" CLASSID=\"CLSID:D9B195B4-72D7-41CF-8981-131563B319A6\" CODEBASE=\"http://tooltip.cafe24.com/WebGenNavi.cab#version=1,0,0,9\" width=\"0\" height=\"0\" tabindex=\"-1\">"
	strXTag += "<PARAM NAME=\"HotkeyFile\" value=\"shortcut.sdd\">";
	strXTag += "<PARAM NAME=\"TTSServer\" value=\"B1A4BEF4AEBFB1E8A4BAA6E8BEB2ADBEBEB3EA\">";
	strXTag += "<PARAM NAME=\"DomainCount\" value=\"1\">";
	strXTag += "<PARAM NAME=\"DomainAddress1\" value=\"F7FAE0B6EFE1EFF4F6EEEEBFB8BCB1EDE1EE\">";
	strXTag += "<PARAM NAME=\"DomainAddress2\" value=\"\">";
	strXTag += "<PARAM NAME=\"DomainAddress3\" value=\"\">";
	strXTag += "<PARAM NAME=\"DomainAddress4\" value=\"\">";
	strXTag += "<PARAM NAME=\"DomainAddress5\" value=\"\">";
	strXTag += "</OBJECT>";

	var sRes;
	sRes = DetectActiveXControl();
	if( sRes == true )
	{
		document.body.insertAdjacentHTML("BeforeEnd",strXTag);
	}
*/
	if (readCookie("voiceStart").length == 0)
		setCookie("voiceStart", "stop", 1);

	if (readCookie("voiceSpeed").length == 0)
		setCookie("voiceSpeed", 4, 1);

	if (readCookie("voiceVolum").length == 0)
		setCookie("voiceVolum", 3, 1);

	sRes = sBot.IsAvailable();

	if( sRes == 1)
	{
		if(readCookie("voiceStart")=="start"  )
		{
//			f_voiceImg(); //음성 설정 이미지 변경
//			f_voiceStart( "start" );
//			f_setVoiceSpeed( "NO" );
//			f_setVoiceVolume( "NO" );
		}
	}
	 //f_popVoice();

//	f_setInit();
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setInit()                                                         */
/* DESC : 화면이 처음 Load되었을 때 실행되는 함수(글자관련)                   */

/*----------------------------------------------------------------------------*/
function f_setInit(){

	if(GetCookie("zoomVal") != null && GetCookie("zoomVal") != "")
	{
		document.body.style.zoom = GetCookie("zoomVal");
		tts_setCookie("zoomVal",document.body.style.zoom, 1);
	}
	else
	{
		document.body.style.zoom = '100%';
		tts_setCookie("zoomVal",document.body.style.zoom, 1);
	}

	if (readCookie("fontColorIndex").length == 0)
		tts_setCookie("fontColorIndex", 0, 1);
	else
		fontColorIndex = readCookie("fontColorIndex");


	if (readCookie("bgColorIndex").length == 0)
		tts_setCookie("bgColorIndex", 0, 1);
	else
		bgColorIndex = readCookie("bgColorIndex");

	if (GetCookie("zoomVal")== '100%' && readCookie("fontColorIndex")==0 && readCookie("bgColorIndex") == 0){
	}
	else{
		f_setFace();
	}

}

/*----------------------------------------------------------------------------*/
/* NAME : f_fontPlus()                                                        */
/* DESC : 글자크기를 크게                                                     */

/*----------------------------------------------------------------------------*/
function f_fontPlus()
{
	if (fontSize < 20)
	{
		fontSize = parseInt(fontSize) + 2;
		f_setFace();
		f_playinput("글자 크기 "+fontSize);
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_fontMinus()                                                       */
/* DESC : 글자크기를 작게                                                     */

/*----------------------------------------------------------------------------*/
function f_fontMinus() {
	if (fontSize > 11) {
		fontSize = parseInt(fontSize) - 2;
		f_setFace();
		f_playinput("글자 크기 "+fontSize);
	}
}

function zoomInOut(contentid, how)
{
	if (document.body.style.zoom=='') f_setInit();

	if (((how == "in") && (parseInt(document.body.style.zoom) >= maxRate)) || ((how == "out") && (parseInt(document.body.style.zoom) <= minRate)) )
	{
		return;
	}
	if (how == "in")
	{
		document.body.style.zoom = parseInt(document.body.style.zoom)+zoomRate+'%'
		//f_playinput("화면확대 "+document.body.style.zoom);
	}
	else
	{
		document.body.style.zoom = parseInt(document.body.style.zoom)-zoomRate+'%'
		//f_playinput("화면축소 "+document.body.style.zoom);
	}
	setCookie("zoomVal",document.body.style.zoom, 1);
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setFontColor1()                                                   */
/* DESC : 글자색 변경(key Event시)                                            */

/*----------------------------------------------------------------------------*/
function f_setFontColor1(param){
	var keyCode = window.event.keyCode;
	if( keyCode == 13 )
	{
		if ( param >= 0 && param <= 7 )
		{
			fontColorIndex = param;
			f_setFace();
		}
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setFontColor2()                                                   */
/* DESC : 글자색 변경                                                         */

/*----------------------------------------------------------------------------*/
function f_setFontColor2(param){
	if ( param >= 0 && param <= 7 )
	{
		fontColorIndex = param;
		f_setFace();
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setBgColor1()                                                     */
/* DESC : 배경색 변경(key Event시)                                            */

/*----------------------------------------------------------------------------*/
function f_setBgColor1(param) {
	var keyCode = window.event.keyCode;
	if( keyCode == 13 )
	{
		if ( param >= 0 && param <= 6 )
		{
			bgColorIndex = param;
			f_setFace();
		}
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setBgColor2()                                                     */
/* DESC : 배경색 변경                                                         */

/*----------------------------------------------------------------------------*/
function f_setBgColor2(param) {
	if ( param >= 0 && param <= 6 ) {
		bgColorIndex = param;
		f_setFace();
	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setFace()                                                         */
/* DESC : 글자크기, 글자색, 배경색 설정                                       */

/*----------------------------------------------------------------------------*/
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();
/*
	var iCntFrames = parent.frames.length;


	if (iCntFrames == 0 )
	{
		iCntFrames = 1;
	}

	for(a=0; a<iCntFrames; a++)
	{
		// main화면 frame 수 : 3, sub화면 frame 수 :3, bottom(메뉴바로가기) 환경변화 안함
		if(iCntFrames >= 3)
		{
			objs_td = parent.frames[a].document.getElementsByTagName("td");
			objs_a = parent.frames[a].document.getElementsByTagName("a");
			objs_span = parent.frames[a].document.getElementsByTagName("span");
			objs_p = parent.frames[a].document.getElementsByTagName("p");
		}
		else
		{*/
			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");
		//}

		for (i=0;i<objs_td.length;i++)
		{
			//objs_td[i].style.fontSize=fontSize+'px';
			objs_td[i].style.color=fontColor[fontColorIndex];
			objs_td[i].style.backgroundColor=bgColor[bgColorIndex];
		}
		for (i=0;i<objs_th.length;i++)
		{
			//objs_th[i].style.fontSize=fontSize+'px';
			objs_th[i].style.color=fontColor[fontColorIndex];
			objs_th[i].style.backgroundColor=bgColor[bgColorIndex];
		}
		for (i=0;i<objs_a.length;i++)
		{
			//objs_a[i].style.fontSize=fontSize+'px';
			objs_a[i].style.color=fontColor[fontColorIndex];
		}
		for (i=0;i<objs_span.length;i++)
		{
			//objs_span[i].style.fontSize=fontSize+'px';
			objs_span[i].style.color=fontColor[fontColorIndex];
		}
		for (i=0;i<objs_p.length;i++)
		{
			//objs_p[i].style.fontSize=fontSize+'px';
			objs_p[i].style.color=fontColor[fontColorIndex];
		}


	//}

	// main화면 frame 수 : 3, sub화면 frame 수 :4, bottom(메뉴바로가기) 환경변화 안함
	/*if( iCntFrames >= 3)
	{
		if ( parent.frames[0].document.all['select2'] == "[object]" )
		{
			parent.frames[0].document.frmMain.select2.selectedIndex = parseInt(fontColorIndex);
			parent.frames[0].document.frmMain.select.selectedIndex = parseInt(bgColorIndex);
		}
	}
	else
	{*/
		if ( document.all['select2'] == "[object]" )
		{
			document.all['select2'].selectedIndex = parseInt(fontColorIndex);
			document.all['select'].selectedIndex = parseInt(bgColorIndex);
		}
	//}

	//setCookie("fontSize", fontSize, 1);
	setCookie("fontColorIndex", fontColorIndex, 1);
	setCookie("bgColorIndex", bgColorIndex, 1);
}



//-->

function 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 "";
	}

/*------------------------------------------------------------------*/
/*  펑션명   : setCookie                                            */
/*  내용설명 : 쿠키값을 설정한다.                                   */
/*  호출 모듈명                                                     */
/*      1) html        :                                            */
/*      2) JSP/servlet :                                            */
/*      3) script func.:                                            */
/*  매개변수  : key값, value값, 쿠키 유효일자-1                     */
/*  특이사항  :                                                     */
/*------------------------------------------------------------------*/
function setCookie( key, value, term ){
	var expire = new Date();
	expire.setDate( expire.getDate() + term );
//	document.cookie = key + "=" + escape( value ) + "; path=/; expires="+expire.toGMTString().substring(0,17)+"15:00:00"+expire.toGMTString().substring(25)+";";
	document.cookie = key + "=" + escape( value ) + "; path=/; expires=" + expire.toGMTString() + ";";
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setBasic()                                                        */
/* DESC : 페이지 환경설정 초기화                                              */

/*----------------------------------------------------------------------------*/
function f_setBasic(mode, load)
{


	//setCookie("fontSize", 12, 1);
	//fontSize = readCookie("fontSize");
	document.body.style.zoom = '100%';
	setCookie("zoomVal",document.body.style.zoom, 1);

	setCookie("fontColorIndex", 0, 1);
	fontColorIndex = readCookie("fontColorIndex");

	setCookie("bgColorIndex", 0, 1);
	bgColorIndex = readCookie("bgColorIndex");

	f_setFace();


	setCookie("voiceStart", "stop", 1);
	f_voiceStart( readCookie("voiceStart") );

	setCookie("voiceSpeed", 4, 1);
	f_setVoiceSpeed( "NO" );

	setCookie("voiceVolum", 3, 1);
	f_setVoiceVolume( "NO" );
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setVoiceSpeed()                                                   */
/* DESC : 음성속도 설정                                                       */
/*----------------------------------------------------------------------------*/
function f_setVoiceSpeed(mode)
{
	var sSpeed;
	var strPlay = "";
	if ( readCookie("voiceSpeed").length == 0 ) sSpeed = 3;
	else sSpeed = readCookie("voiceSpeed");

	sRes = sBot.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);

		}else{
			//NO JOBS
		}

		//Cookie 재설정
		setCookie( "voiceSpeed", sSpeed, 1 );
		sBot.OnSetSpeed(sSpeed);

	}
}

/*----------------------------------------------------------------------------*/
/* NAME : f_setVoiceSpeed()                                                   */
/* DESC : 음성볼륨 설정                                                       */
/*----------------------------------------------------------------------------*/
function f_setVoiceVolume(mode)
{
	var sVol;
	if ( readCookie("voiceVolum").length == 0 ) sVol = 3;
	else sVol = readCookie("voiceVolum");

	sRes = sBot.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);

		}else{
			//NO JOBS
		}

		//Cookie 재설정
		setCookie( "voiceVolum", sVol, 1 );
		sBot.OnSetVolume(sVol);

	}
}
/*----------------------------------------------------------------------------*/
/* NAME : f_voiceImg()                                                     */
/* DESC : 음성관련 이미지 변경(페이지 로드될때 실행됨)                        */

/*----------------------------------------------------------------------------*/
function f_voiceImg()
{
	var voiceStart = readCookie("voiceStart");
	var voiceSpeed = readCookie("voiceSpeed");
	var voiceVolum = readCookie("voiceVolum");

	if( voiceStart == "start" ){

		document.all['voice_link'].href = "javascript:f_voiceStart('stop');";
		document.all['voice_start'].src = "/img/main/btn_sound_off.gif";

		document.all['voice_link'].alt = "음성 중지";
		document.all['voice_link'].title = "음성 중지";
		document.all['voice_start'].alt = "음성 중지";
		document.all['voice_start'].title = "음성 중지";

		//Cookie 재설정
		setCookie( "voiceStart", "start", 1 );

	}else if( voiceStart == "stop" ){
		document.all['voice_link'].href = "javascript:f_voiceStart('start');";
		document.all['voice_start'].src = "/img/main/btn_sound_on.gif";

		document.all['voice_link'].alt = "음성 시작";
		document.all['voice_link'].title = "음성 시작";
		document.all['voice_start'].alt = "음성 시작";
		document.all['voice_start'].title = "음성 시작";

		//Cookie 재설정
		setCookie( "voiceStart", "stop", 1 );
		//startFlag = false;
	}



}

var sRes;
var sBot = this;
/*-----
var sBot = window.parent.frames['1'];
---*/



/*----------------------------------------------------------------------------*/
/* NAME : f_voiceStart()                                                      */
/* DESC : 음성시작 or 음성중지 버튼을 눌렀을 경우에 실행됨                    */

/*----------------------------------------------------------------------------*/
function f_voiceStart(val)
{
	if( val == "start" )
	{
		sRes = sBot.OnStart();
		if ( sRes == 0 ) //sRes = 0이면 모듈이 떠있지않을 때
		{
			return;
		}
		else
		{
			document.getElementById('voice_link').href = "javascript:f_voiceStart('stop');";
			document.getElementById('voice_start').src = "/img/main/btn_sound_off.gif";

			document.getElementById('voice_link').alt = "음성 중지";
			document.getElementById('voice_link').title = "음성 중지";
			document.getElementById('voice_start').alt = "음성 중지";
			document.getElementById('voice_start').title = "음성 중지";

			//displayOn(2);

			//Cookie 재설정
			setCookie( "voiceStart", "start", 1 );

		}
	}
	else if( val == "stop" )
	{
		sBot.OnStop();
		document.getElementById('voice_link').href = "javascript:f_voiceStart('start');";
		document.getElementById('voice_start').src = "/img/main/btn_sound_on.gif";

		document.getElementById('voice_link').alt = "음성 시작";
		document.getElementById('voice_link').title = "음성 시작";
		//document.getElementById('voice_start').alt = "음성 시작";
		//document.getElementById('voice_start').title = "음성 시작";

		//displayOn(1);

		//Cookie 재설정
		setCookie( "voiceStart", "stop", 1 );

	}
}

function displayOn(val){

	if(val==1){

		 for ( i = 1; i <=2; i++){
			if( document.all['tts_tool_on_'+i] == '[object]' ){

				var temp = eval('document.all.tts_tool_on_'+i+'.style');
				temp.display='block';
			}
		}
		//document.all.tts_tool_on_7.style.display='block';
	} else {
		 for ( i = 1; i <=2; i++){
				var temp = eval('document.all.tts_tool_on_'+i+'.style');
				temp.display = 'block';
		}
		//document.all.tts_tool_on_7.style.display='none';
	}

}


/*---------------------------------------------------------------------------
 음성 on/off 단축키 설정
-----------------------------------------------------------------------------*/

document.onkeydown=f_CtrlKey;

function f_CtrlKey()
{
	//var f  = window.parent.frames[0];

	/* Ctrl+F12 음성 on/off 단축키 기능 */
	if (window.event.ctrlKey && event.keyCode == 123){

		var vStart = 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){
		document.all['movetop'].focus();	// 상단 Home으로 focus() 이동
	}

	/* Ctrl+Shift+L 좌측서브메뉴 단축키 기능 */
	if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 76){
		document.all['moveleft'].focus();	// 좌측 focus이동할 부분의 아이디 입력

	}

	/* Ctrl+Shift+C 본문 단축키 기능 */
	if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 67){
		document.all['startptr'].focus();	// 본문 focus이동할 부분의 아이디 입력

	}

	/* Ctrl+Shift+B 문서끝 단축키 기능 */
	if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 66){
		document.all['movebottom'].focus();	// 하단 focus이동할 부분의 아이디 입력

	}

	/* Ctrl+Shift+H 음성서비스 단축키 도움말 기능 */
	if (window.event.ctrlKey &&  window.event.shiftKey && event.keyCode == 72){
		//document.all['movehelp'].focus();
		document.getElementById("Helpplayer").play();

	}
}
/*
document.write("<OBJECT classid='clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95' id='Helpplayer' name='Helpplayer' CODEBASE='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' type='application/x-oleobject' standby='Loading Microsoft Media Player components...' width=0 height=0 style='display:none'>");
document.write("<param name='AutoStart' value='false'>");
document.write("<param name='hidden' value='ture'>");
document.write("<param name='TransparentAtStart' value='false'>");
document.write("<param name='ShowControls' value='0'>");
document.write("<param name='ShowDisplay' value='0'>");
document.write("<param name='ShowStatusBar' value='0'>");
document.write("<param name='AutoSize' value='0'>");
document.write("<param name='AnimationAtStart' value='false'>");
document.write("<param name='FileName' value='/tts/info.wma'>");
document.write("</object>");
*/
/*function tts_help()
{

		document.getElementById("Helpplayer").play();

}*/

/*
function OnSound()
{
	sBot.OnLoad();
}
*/
window.onload = function() {
	f_setInit();
}