var chat_cur=document.location.href;
var chat_lang="kor";
var chat_site="na";

if(chat_cur.indexOf("cn_")!=-1)
{
	chat_site="cn";
}
else if(chat_cur.indexOf("jp_")!=-1)
{
	chat_site="cn";
}


if (chat_cur.indexOf("_eng")!=-1)
{
		chat_lang="eng";
}
else if (chat_cur.indexOf("_kor")!=-1)
{
		chat_lang="kor";
}
else if (chat_cur.indexOf("_sch")!=-1)
{
		chat_lang="sch";
}
else if (chat_cur.indexOf("_jpn")!=-1)
{
		chat_lang="jpn";
}

var bNS = (document.layers) ? true : false;
var bIE = (document.all) ? true : false;

function checkCustomInfo()
{
	var szCustom = "";
	
	if (typeof LA_custom01 != 'undefined'){	szCustom += "&custom01=" + escape(LA_custom01)}
	if (typeof LA_custom02 != 'undefined'){	szCustom += "&custom02=" + escape(LA_custom02)}
	if (typeof LA_custom03 != 'undefined'){	szCustom += "&custom03=" + escape(LA_custom03)}
	if (typeof LA_custom04 != 'undefined'){	szCustom += "&custom04=" + escape(LA_custom04)}
	if (typeof LA_custom05 != 'undefined'){	szCustom += "&custom05=" + escape(LA_custom05)}
	if (typeof LA_custom06 != 'undefined'){	szCustom += "&custom06=" + escape(LA_custom06)}
	if (typeof LA_custom07 != 'undefined'){	szCustom += "&custom07=" + escape(LA_custom07)}
	if (typeof LA_custom08 != 'undefined'){	szCustom += "&custom08=" + escape(LA_custom08)}
	if (typeof LA_custom09 != 'undefined'){	szCustom += "&custom09=" + escape(LA_custom09)}
	if (typeof LA_custom10 != 'undefined'){	szCustom += "&custom10=" + escape(LA_custom10)}
	if (typeof LA_custom11 != 'undefined'){	szCustom += "&custom11=" + escape(LA_custom11)}
	if (typeof LA_custom12 != 'undefined'){	szCustom += "&custom12=" + escape(LA_custom12)}
	if (typeof LA_custom13 != 'undefined'){	szCustom += "&custom13=" + escape(LA_custom13)}
	if (typeof LA_custom14 != 'undefined'){	szCustom += "&custom14=" + escape(LA_custom14)}
	if (typeof LA_custom15 != 'undefined'){	szCustom += "&custom15=" + escape(LA_custom15)}
	if (typeof LA_custom16 != 'undefined'){	szCustom += "&custom16=" + escape(LA_custom16)}
	if (typeof LA_custom17 != 'undefined'){	szCustom += "&custom17=" + escape(LA_custom17)}
	if (typeof LA_custom18 != 'undefined'){	szCustom += "&custom18=" + escape(LA_custom18)}
	if (typeof LA_custom19 != 'undefined'){	szCustom += "&custom19=" + escape(LA_custom19)}
	if (typeof LA_custom20 != 'undefined'){	szCustom += "&custom20=" + escape(LA_custom20)}
	if (typeof LA_custom21 != 'undefined'){	szCustom += "&custom21=" + escape(LA_custom21)}
	if (typeof LA_custom22 != 'undefined'){	szCustom += "&custom22=" + escape(LA_custom22)}
	if (typeof LA_custom23 != 'undefined'){	szCustom += "&custom23=" + escape(LA_custom23)}
	if (typeof LA_custom24 != 'undefined'){	szCustom += "&custom24=" + escape(LA_custom24)}
	if (typeof LA_custom25 != 'undefined'){	szCustom += "&custom25=" + escape(LA_custom25)}
	if (typeof LA_custom26 != 'undefined'){	szCustom += "&custom26=" + escape(LA_custom26)}
	if (typeof LA_custom27 != 'undefined'){	szCustom += "&custom27=" + escape(LA_custom27)}
	if (typeof LA_custom28 != 'undefined'){	szCustom += "&custom28=" + escape(LA_custom28)}
	if (typeof LA_custom29 != 'undefined'){	szCustom += "&custom29=" + escape(LA_custom29)}
	if (typeof LA_custom30 != 'undefined'){	szCustom += "&custom30=" + escape(LA_custom30)}

  return szCustom;
}

function openChatWindow(theURL,winName,features) 
{ 
    var szCustomInfo = checkCustomInfo();
    var addinfo ="&platform=" + escape(navigator.platform)
						+ "&title=" + escape('Welcome to Korean Air')
						+ "&url=" + escape(document.URL)
						+ '&referrer=' + escape(document.referrer);
  if (bIE)	
	{
		addinfo += "&lang=" + escape(navigator.browserLanguage);
	}
    else
	{		
		addinfo += "&lang=" + escape(navigator.language);
	}
	addinfo += "&app=" + escape(navigator.appName);
	addinfo += szCustomInfo;
	addinfo += "&dmy=" + new Date().getTime();
	theURL += addinfo;
//	window.open(theURL,winName,features);
	//openErrorWindow()
   // IE아닌 경우
   if (window.navigator.appName.indexOf("Explorer") ==-1) {
		if(chat_lang=="kor")
		{
	        alert('지원하지 않는 브라우저입니다. 곧 지원할 예정입니다.') ;
		}
		else
		{
			alert("Sorry, this browser isn't currently supported.");
		}
   }else { //IE인경우

        window.open(theURL,winName,features);

   }
}
function  openErrorWindow(){
//  window.open('http://kr.koreanair.com/KALMain/liveChat/liveActError.html','','status = 1,width=395,height=520'); //장애 링크 URL
	if(chat_site=="jp")
	{
		if(chat_lang=="jpn")
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/jp/jpn/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
		else
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/jp/kor/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
	}
	else if(chat_site="cn")
	{
		if(chat_lang=="sch")
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/cn/sch/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
		else
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/cn/kor/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
	}
	else
	{
		if(chat_lang=="eng")
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/na_eng/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
		else
		{
			window.open('http://www.koreanair.com/lib/liveChat/error/kr_kor/not_avail.htm','','status = 1,width=395,height=520'); //장애 링크 URL
		}
	}
}

function checkLiveactServer()
{
	var liveactChatImg = (document.getElementById("liveactChatImg"));
	var newDate = new Date();
	var strH = newDate.getHours();
		
	if(liveactChatImg == null || liveactChatImg.readyState != "complete" ) 
	{    
	  //업무시간(05시~23시)에 따른 이미지 처리  
	  //업무시간(01시~09시)에 따른 이미지 처리  
	  //업무시간(09시~17시)에 따른 이미지 처리 (미주) 
		if(chat_site=="cn")
		{
			if(strH >= 9 && strH <=18 )
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/cn_chat_on.gif";  //ON 메인 이미지 URL
			}else
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/cn_chat_off.gif";  //OFF 메인 이미지 URL
			}
		}
		else if(chat_site=="jp")
		{
			if(strH >= 9 && strH <=18 )
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/jp_chat_on.gif";  //ON 메인 이미지 URL
			}else
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/jp_chat_off.gif";  //OFF 메인 이미지 URL
			}
		}
		else
		{
			if(strH >= 0 && strH <=8 )
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/na_eng_sub_on.gif";  //ON 메인 이미지 URL
			}else
			{
				liveactChatImg.src = "http://vip8.koreanair.com/KAL_edit/KAL/lib/liveChat/img/na_eng_sub_off.gif";  //OFF 메인 이미지 URL
			}
		}
		liveactChatImg.onclick = openErrorWindow ;
	}
}

if(chat_cur.indexOf("/index_na")==-1||chat_cur.indexOf("/index_jp_kor")==-1||chat_cur.indexOf("/index_jp_jpn")==-1||chat_cur.indexOf("/index_cn_chn")==-1||chat_cur.indexOf("/index_cn_kor")==-1)
{
	setTimeout('checkLiveactServer()', 5000);
}
