var zoomRate = 25;			// 확대/축소시 증감률
var maxRate = 200;			//최대확대률
var minRate = 100;			//최소축소률

/*
var fontSize = fSize;			//fontSize Default
var setfontsize = 12;		//setfontsize Default
var SetFont = strSetFont;	//SetFont Default "font";
*/
var fontColorIndex = 0;		//fontColorIndex Defalut(0은 글자색)
var bgColorIndex = 0;		//fontColorIndex Defalut(0은 바탕색)
var ScreenSize = 100;		//ScreenSize Default
var VoiceSpeed = 3;			//VoiceSpeed Default
var VoiceVolum = 3;			//VoiceVolum Default


var beforeBgColor;
var beforeTag;
var beforeTableTag;

//var afontSize = new Array();

var aVoice = new Array();
aVoice[1] = 1;
aVoice[2] = 2;
aVoice[3] = 3;
aVoice[4] = 4;
aVoice[5] = 5;

var aScreen = new Array();
aScreen[1] = 100;
aScreen[2] = 125;
aScreen[3] = 150;
aScreen[4] = 175;
aScreen[5] = 200;

var 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";

var bgColor = new Array();
bgColor[0] = "";
bgColor[1] = "";
bgColor[2] = "#000000";
bgColor[3] = "#6666ff";
bgColor[4] = "#ff6666";
bgColor[5] = "#ff66ff";
bgColor[6] = "#66ff66";


/*****************************************************************/
//쿠키값 읽기
/*****************************************************************/
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 space_setCookie( key, value, term ){
	var expire = new Date();  
	expire.setDate( expire.getDate() + term );
	document.cookie = key + "=" + escape( value ) + "; path=/; expires=" + expire.toGMTString() + ";";
}


//setTimeout( "bodyactive();", 5000);

/*****************************************************************/
//
/*****************************************************************/
function bodyactive(){
	if (window.ActiveXObject) { // IE	
		var sRes = "";	
		sRes = IsInstalled();
		if( sRes == true ){
			document.body.insertAdjacentHTML("BeforeEnd",objectTag);
		}else{
		}
	}
}

/*****************************************************************/
/*PageInit()*/
/*****************************************************************/
//페이지 로딩시 실행
function f_PageInit(){	
	

		if( readCookie("VoiceStart").length == 0){
			space_setCookie("VoiceStart", VoiceStart , 1);
		}else VoiceStart = readCookie("VoiceStart");
	
		if( readCookie("VoiceVolum").length == 0 ){
			space_setCookie("VoiceVolum", VoiceVolum, 1);
		}else VoiceVolum = readCookie("VoiceVolum");
	
		if( readCookie("VoiceSpeed").length == 0 ){
			space_setCookie("VoiceSpeed", VoiceSpeed, 1);
		}else VoiceSpeed = readCookie("VoiceSpeed");
	
		var res = NetlightObjectType(NetLightCOM);
		if( res == true ){
		f_VoiceStart( readCookie("VoiceStart") )};
	
		if( typeof(DynamicNetLightCOM) != 'undefined' ){
		
	
			VoiceVolum = parseFloat(readCookie("VoiceVolum"));
			NetLightCOM.VoiceVolume=VoiceVolum;
			f_ImgChg(VoiceVolum, "volum");
	
			VoiceSpeed = parseFloat(readCookie("VoiceSpeed"));
			NetLightCOM.VoiceSpeed=VoiceSpeed;
			f_ImgChg(VoiceSpeed, "speed");
		}
		else{
			f_ImgChg("", "COM");
		}
	
		fontColorIndex = readCookie("fontColorIndex");
		bgColorIndex = readCookie("bgColorIndex");
		f_FontInit();

}


/*****************************************************************/
/*Init()*/
/*****************************************************************/
function f_FontInit(){
		
		/*
		if (readCookie("setfontsize").length == 0 ){
			space_setCookie("setfontsize", setfontsize, 1);
		}else setfontsize = readCookie("setfontsize");	//폰트사이즈
		
		if( readCookie("fontSize").length == 0 ){
			space_setCookie("fontSize", fontSize, 1);
		}else fontSize = readCookie("fontSize");		//폰트사이즈
		
		
		if (readCookie("SetFont").length == 0 ){
			space_setCookie("SetFont", SetFont, 1);
		}else SetFont = readCookie("SetFont");			//폰트or스크린
		*/

		if( readCookie("fontColorIndex").length == 0 ){
			space_setCookie("fontColorIndex", 0, 1);
		}else fontColorIndex = readCookie("fontColorIndex");	
			
		if ( readCookie("bgColorIndex").length == 0 ){
			space_setCookie("bgColorIndex", 0, 1);
		}else bgColorIndex = readCookie("bgColorIndex");
	
		if ( readCookie("zoomVal").length == 0 ){
			space_setCookie("zoomVal", "100%", 7);
		}else currZoom = readCookie("zoomVal")+"%";		//화면크기

		zoomInOut("");
		
		//setFontSize(setfontsize);
		f_setFace();
		
	
		
}

/*****************************************************************/
/*폰트사이즈 배열저장*/
/*****************************************************************/
function setFontSize(val){
	afontSize[1] = val;
	for( var i=2; i<6; i++ ){
		val = parseInt(val) + 3;
		afontSize[i] = val;
	}
}


/*****************************************************************/
/*설치*/
/*****************************************************************/
function f_objectInsert(mode){
	var sRes = "";
	sRes = IsInstalled();
	if( sRes == true ){
		document.body.insertAdjacentHTML("BeforeEnd", objectTag);
	}else{
		var com = confirm("음성서비스를 받으시려면 프로그램을 설치하셔야 합니다.\n\n설치하시겠습니까?");

		if( com == true ){
			top.location.href="/NetLight2/ActiveX.jsp?conf_Lang=kor";
		}
	}
}


/*****************************************************************/
/*음성 설정*/
/*****************************************************************/
function f_VoiceStart(str){
	//-setTimeout("", 2000);
	if( typeof(DynamicNetLightCOM) != 'undefined' ){
		if( str == "start" ){
			f_ImgChg('', "VoiceStart");
			if( FrameLength == 2 ){
			
				if( typeof(eval(FrameMainName +"document.all['VoiceLink']")) == 'object' ){
					eval(FrameMainName +"document.all['VoiceLink']").href = "JavaScript:NetReader('VoiceStop');";
					eval(FrameMainName +"document.all['VoiceLink']").title="음성 켜기 버튼";
					
				}
			}else{
				if( typeof(document.all['VoiceLink']) == 'object' ){
					document.all['VoiceLink'].href="JavaScript:NetReader('VoiceStop');";
					document.all['VoiceLink'].title="음성 켜기 버튼";

				}
			}

			DynamicNetLightCOM.VoiceActive=true;
		}
		else if( str == "stop"){
			f_ImgChg('', "VoiceStop");
			if( FrameLength == 2 ){
				if( typeof(eval(FrameMainName +"document.all['VoiceLink']")) == 'object' ){
					eval(FrameMainName +"document.all['VoiceLink']").href="JavaScript:NetReader('VoiceStart');";
					eval(FrameMainName +"document.all['VoiceLink']").title="음성 끄기 버튼";
				}
			}else{
				if( typeof(document.all['VoiceLink']) == 'object' ){
					document.all['VoiceLink'].href="JavaScript:NetReader('VoiceStart');";
					document.all['VoiceLink'].title="음성 끄기 버튼";
				}
			}
		
			
			DynamicNetLightCOM.VoiceActive=false;
		}
		space_setCookie("VoiceStart", str, 1);
	}else{
		//alert("NetLight 음성모듈이 존재하지 않습니다");
		f_objectInsert("voice");
	}	
}
// 테스트

/*****************************************************************/
/*네비게이션 설정*/
/*****************************************************************/
/*
function f_NaviStart(str){
	//-setTimeout("", 2000);
	if( typeof(DynamicNetLightCOM) != 'undefined' ){
		if( str == "start" ){
			f_ImgChg('', "NaviStart");
			if( FrameLength == 2 ){
			
				if( typeof(eval(FrameMainName +"document.all['NaviLink']")) == 'object' ){
					eval(FrameMainName +"document.all['NaviLink']").href = "JavaScript:NetReader('NaviStop');";
					eval(FrameMainName +"document.all['NaviLink']").title="네비게이션 켜기 버튼";
					
				}
			}else{
				if( typeof(document.all['NaviLink']) == 'object' ){
					document.all['NaviLink'].href="JavaScript:NetReader('NaviStop');";
					document.all['NaviLink'].title="네비게이션 켜기 버튼";

				}
			}
			
			DynamicNetLightCOM.NavigationActive=true;
			f_VoiceStart("start");
		}
		else if( str == "stop"){
			f_ImgChg('', "NaviStop");
			if( FrameLength == 2 ){
				if( typeof(eval(FrameMainName +"document.all['NaviLink']")) == 'object' ){
					eval(FrameMainName +"document.all['NaviLink']").href="JavaScript:NetReader('NaviStart');";
					eval(FrameMainName +"document.all['NaviLink']").title="네비게이션 끄기 버튼";
				}
			}else{
				if( typeof(document.all['NaviLink']) == 'object' ){
					document.all['NaviLink'].href="JavaScript:NetReader('NaviStart');";
					document.all['NaviLink'].title="네비게이션 끄기 버튼";
				}
			}
		
			
			DynamicNetLightCOM.NavigationActive=false;
			
		}
		space_setCookie("NaviStart", str, 1);
	}else{
		//alert("NetLight 음성모듈이 존재하지 않습니다");
		f_objectInsert("voice");
	}	
}
*/

//음성모듈 볼륨설정
function f_VoiceVolume(mode)
{
	var sVol;
	sVol = readCookie("VoiceVolum");
	for( var i=0; i<aVoice.length; i++){
		if(sVol == aVoice[i]){
			sVol = i;
			break;
		}
	}

	if( mode == "up" ){
		if( sVol < 5 ){
			sVol = parseInt(sVol) + 1;
		}

	}else if( mode == "down" ){
		if( sVol > 1 ){
			sVol = parseInt(sVol) - 1;
		}
	}else{
		//NO JOBS
	}


	if( typeof(DynamicNetLightCOM) != 'undefined' ){
		//Cookie 재설정
		space_setCookie( "VoiceVolum", aVoice[sVol], 1 );
		//NetLight Voice Setting
		NetLightCOM.VoiceVolume = readCookie("VoiceVolum");
	}else{//alert("NetLight 음성모듈이 존재하지 않습니다");
	}
}

//음성모듈 스피드 설정
function f_VoiceSpeed(mode)
{
	var sSpeed;
	sSpeed = readCookie("VoiceSpeed");
	for( var i=0; i<aVoice.length; i++){
		if(sSpeed == aVoice[i]){
			sSpeed = i;
			break;
		}
	}

	if( mode == "up" ){
		if( sSpeed < 5 ){
			sSpeed = parseInt(sSpeed) + 1;
		}

	}else if( mode == "down" ){
		if( sSpeed > 1 ){
			sSpeed = parseInt(sSpeed) - 1;
		}
	}else{
		//NO JOBS
	}	

	
	if( typeof(DynamicNetLightCOM) != 'undefined' ){
		//Cookie 재설정
		space_setCookie( "VoiceSpeed", aVoice[sSpeed], 1 );
		//NetLight Speed Setting
		NetLightCOM.VoiceSpeed = readCookie("VoiceSpeed");		
	}else{//alert("NetLight 음성모듈이 존재하지 않습니다");
	}
}

/*********************************************************/
//글자 크게
/*********************************************************/
/*
function f_fontPlus(){
	if (fontSize < 20){
		fontSize = parseInt(fontSize) + 3;
		//f_ImgChg(fontSize, "font");
		f_setFace();
	}
}
*/
/*********************************************************/
//글자 작게
/*********************************************************/
/*
function f_fontMinus() {
	if (fontSize > 13) {
		fontSize = parseInt(fontSize) - 3;
		f_setFace();
	}
}
*/
/*********************************************************/
//폰트컬러
/*********************************************************/
function f_setFontColor(val){
	if ( val >= 0 && val <= 7 ) 
	{
		fontColorIndex = val;
		f_setFace();
	}
}

/*********************************************************/
//바탕색
/*********************************************************/
function f_setBgColor(val){
	if ( val >= 0 && val <= 6 ) 
	{
		bgColorIndex = val;
		f_setFace();
	}
}
/*********************************************************/
//화면확대
/*********************************************************/
function zoomInOut(how){
	var sValue;
	//-setTimeout("", 1000);

	if(readCookie("zoomVal") != null && readCookie("zoomVal") != "" && readCookie("zoomVal") != "NaN"){
			if( FrameLength == 2 ){
				eval(FrameMainName +"document.body").style.zoom = readCookie("zoomVal")+"%";	

			}else{
				
				document.body.style.zoom = readCookie("zoomVal")+"%";
			}
			currZoom=readCookie("zoomVal");
	}else{
			if( FrameLength == 2 ){
				eval(FrameMainName +"document.body").style.zoom = "100%"; 
			}else{
				document.body.style.zoom = "100%"; 
			}
			currZoom = "100%";
	}

	if ( ((how == "in") && (parseInt(currZoom) >= maxRate)) || ((how == "out") && (parseInt(currZoom) <= minRate)) ) {
		return; 
	}
	if (how == "in") {
		if( FrameLength == 2 )
			eval(FrameMainName +"document.body").style.zoom = parseInt(eval(FrameMainName +"document.body").style.zoom)+zoomRate+"%";
		else
			document.body.style.zoom = parseInt(document.body.style.zoom)+zoomRate+"%";


	}else if( how == "out" ){
		if( FrameLength == 2 )
			eval(FrameMainName +"document.body").style.zoom = parseInt(eval(FrameMainName +"document.body").style.zoom)-zoomRate+"%";
		else
			document.body.style.zoom = parseInt(document.body.style.zoom)-zoomRate+"%";
	}
	if( FrameLength == 2 ){
		sValue = parseInt(eval(FrameMainName +"document.body").style.zoom);		
	}else{
		sValue = parseInt(document.body.style.zoom);
	}
		
	space_setCookie("zoomVal", sValue, 365);



	
}

/*********************************************************/
//레벨 이미지 변경
/*********************************************************/
function f_ImgChg(val, flag){
	//Start
	if(flag == "VoiceStart"){
		if( FrameLength == 2 ){
			if( typeof(eval(FrameMainName +"document.all['VoiceStart']")) == 'object' ){
				eval(FrameMainName +"document.all['VoiceStart']").alt="음성끄기 버튼";
				eval(FrameMainName +"document.all['VoiceStart']").title="음성끄기 버튼";
				eval(FrameMainName +"document.all['VoiceStart']").src = VoiceOnImg;
			}
		}else{
			if( typeof(document.all['VoiceStart']) == 'object' ){
				document.all['VoiceStart'].alt="음성끄기 버튼";
				document.all['VoiceStart'].title="음성끄기 버튼";
				document.all['VoiceStart'].src = VoiceOnImg;
			}
		}
	}
	//Stop
	else if(flag == "VoiceStop"){
		if( FrameLength == 2 ){
			if( typeof(eval(FrameMainName +"document.all['VoiceStart']")) == 'object' ){
				eval(FrameMainName +"document.all['VoiceStart']").alt="음성켜기 버튼";
				eval(FrameMainName +"document.all['VoiceStart']").title="음성켜기 버튼";
				eval(FrameMainName +"document.all['VoiceStart']").src = VoiceOffImg;
			}
		}else{
			if( typeof(document.all['VoiceStart']) == 'object' ){
				document.all['VoiceStart'].alt="음성켜기 버튼";
				document.all['VoiceStart'].title="음성켜기 버튼";
				document.all['VoiceStart'].src = VoiceOffImg;
			}
		}
	}


	//Not NetLightCOM
	else if( flag == "COM" ){
	}
}

/*********************************************************/
//글자크기 설정
/*********************************************************/
function f_setFace(){
	var objs_td		= new Array();
	var	objs_a		= new Array();
	var	ogjs_span	= new Array();
	var objs_p		= new Array();
	var objs_li		= new Array();
	var Space_FontColor = fontColorIndex;	//fontColor[fontColorIndex]; //
	var Space_BGColor   = bgColorIndex; 	//bgColor[bgColorIndex];

	objs_td		= document.getElementsByTagName("td");
	objs_a		= document.getElementsByTagName("a");
	ogjs_span	= document.getElementsByTagName("span");
	objs_p		= document.getElementsByTagName("P");
	objs_div	= document.getElementsByTagName("div");
	objs_li		= document.getElementsByTagName("li");
	
	
	objs_dl		= document.getElementsByTagName("dl"); 
	objs_dt		= document.getElementsByTagName("dt"); 
	objs_dd		= document.getElementsByTagName("dd"); 
	objs_pre	= document.getElementsByTagName("pre");
	objs_font	= document.getElementsByTagName("font");

    
	for (i=0;i<objs_dl.length;i++){
		if (Space_FontColor !="0") objs_dl[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_dl[i].style.backgroundColor=bgColor[bgColorIndex];
	} 
	for (i=0;i<objs_dt.length;i++){
		if (Space_FontColor !="0") objs_dt[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_dt[i].style.backgroundColor=bgColor[bgColorIndex];
	}  
	for (i=0;i<objs_dd.length;i++){
		if (Space_FontColor !="0") objs_dd[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_dd[i].style.backgroundColor=bgColor[bgColorIndex];
	} 
	for (i=0;i<objs_pre.length;i++){
		if (Space_FontColor !="0") objs_pre[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_pre[i].style.backgroundColor=bgColor[bgColorIndex];
	}
	for (i=0;i<objs_font.length;i++){
		//objs_td[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_font[i].style.color=fontColor[fontColorIndex];
		//objs_font[i].style.backgroundColor=bgColor[bgColorIndex];
	}
	

	for (i=0;i<objs_td.length;i++){
		//objs_td[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_td[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_td[i].style.backgroundColor=bgColor[bgColorIndex];
	}

	for (i=0;i<objs_a.length;i++){
		//objs_a[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_a[i].style.color=fontColor[fontColorIndex];
	}

	for (i=0;i<ogjs_span.length;i++){
		//ogjs_span[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") ogjs_span[i].style.color=fontColor[fontColorIndex];
	}

	for (i=0;i<objs_p.length;i++){
		//objs_p[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_p[i].style.color=fontColor[fontColorIndex];
	}

	for (i=0;i<objs_div.length;i++){
		//objs_div[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_div[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_div[i].style.backgroundColor=bgColor[bgColorIndex];
	}

	for (i=0;i<objs_li.length;i++){
		//objs_div[i].style.fontSize=fontSize+'px';
		if (Space_FontColor !="0") objs_li[i].style.color=fontColor[fontColorIndex];
		if (Space_BGColor !="0") objs_li[i].style.backgroundColor=bgColor[bgColorIndex];
	}
	if ( document.all['fontSelect'] == '[object]' && document.all['bgSelect'] == '[object]' ){
		document.all['fontSelect'].selectedIndex	= parseInt(fontColorIndex);
		document.all['bgSelect'].selectedIndex		= parseInt(bgColorIndex);
	}

	//space_setCookie("fontSize", fontSize, 1);					//폰트저장
	space_setCookie("fontColorIndex", fontColorIndex, 1);		//폰트색상저장	
	space_setCookie("bgColorIndex", bgColorIndex, 1);			//배경색저장
}


/*********************************************************/
//Object 유/무
/*********************************************************/
function NetlightObjectType(netlight){
	if(netlight.object){
		return true;
	}else{
		return false;
	}
}



