/*
 InUC Web Client IM Window v6.1.0 by NEC Platforms,Ltd.
*/
var myId=-1,dlgBtnList=[],D_BTN_SAVE_IM=0,D_BTN_CNFIM=1,debuglog=0,l={log:function(a){0<debuglog&&console.log(a)},dir:function(a){1<debuglog&&console.dir(a)},warn:function(a){console.warn(a)},error:function(a){0<=debuglog&&console.error(a)}};
$(document).ready(function(){var a=null;a=GetQueryString();null!==a&&(void 0!==a.id&&(myId=parseInt(a.id,10)),a=null);$("#im_window").css("right","0");$("#im_wrap").css("display","block");koInitialize();window.opener.memberList[myId].imSubWin?window.close():(window.opener.memberList[myId].imSubWin=window,viewModel.targetUsr(window.opener.memberList[myId]),viewModel.stObj(viewModel.targetUsr().stObj()),viewModel.chatLogArr(window.opener.getChatArrByUser(window.opener.memberList[myId]).slice()),updtDocTitle(),
setImEnterMode(window.opener.entKeyOp),scrollToNewMessage(),$(".cancelTab").on("keydown",function(a){}).on("keydown keyup keypress change input",function(){var a=$(this);text=a.val();new_text=text.replace(/\t/g," ");new_text!=text&&a.val(new_text)}),$(window).focus(function(){if(0<=myId){var a=window.opener.memberList[myId];window.opener.deleteImAlert(a);window.opener.deleteDsktpNotification(window.opener.NOTIF_TYPE_IM,a)}$("#im_ta_1").focus()}),$(window).blur(function(){0<=myId&&clearImNew()}),$("#im_ta_1").on("keydown keyup keypress change input",
function(){if(0<=myId){var a=window.opener.memberList[myId];window.opener.deleteImAlert(a);window.opener.deleteDsktpNotification(window.opener.NOTIF_TYPE_IM,a);clearImNew()}}),$(window).on("unload",function(){try{window.opener.memberList[myId].imSubWin=null,clearImNew()}catch(b){}}),$("#im_ta_1").focus())});
var null_user=new window.opener.usrObj,null_status=window.opener.null_status,kovm=function(){this.targetUsr=ko.observable(null_user);this.stObj=ko.observable(null_status);this.isStandAlone=ko.observable(!1);this.chatLogArr=ko.observableArray([]);this.dialogMsg=ko.observable("");this.dialogBtns=ko.observableArray([])},viewModel=new kovm;function koInitialize(){ko.applyBindings(viewModel);initDialog()}
function GetQueryString(){if(1>=document.location.search.length)return null;var a=document.location.search.substring(1).split("&"),b={};if(null===b)return null;for(var c=0;c<a.length;c++){var d=a[c].split("="),e=decodeURIComponent(d[0]);d=decodeURIComponent(d[1]);b[e]=decodeURIComponent(d)}return b}function updtDocTitle(){document.title=viewModel.targetUsr().name()}function dispSelEmoji(){$(".im_input_normal").css("display","none");$(".im_input_emoji").css("display","block")}
function closeSelEmoji(){$(".im_input_emoji").css("display","none");$(".im_input_normal").css("display","block")}function setEmoji(a,b){var c=a.val();c=c+"(_"+window.opener.emojiArr[b]+"_)";c.length<=window.opener.CHAT_INPUT_MAX&&a.val(c);closeSelEmoji();clearImNew()}function setCallBack(a){if(window.opener.viewModel.myExt()){var b=a.val();b=b+"<t"+window.opener.viewModel.myExt()+"/>";b.length<=window.opener.CHAT_INPUT_MAX&&a.val(b);clearImNew()}}
function sendChat(a,b){window.opener.sendChat(a,b);$("#im_ta_1").val("")}function dispDiagSaveLog(){-1!==viewModel.targetUsr().imLastIdx()&&openDialog(langTbl.d_pre_9,dlgBtnList[D_BTN_SAVE_IM])}
function initDialog(){destroyDialog();btns=[];label=langTbl.d_yes;btn=new window.opener.dBtnObj(label,function(){closeDialog();window.opener.saveLogAsText(window.opener.memberList[myId])});btns.push(btn);label=langTbl.d_no;btn=new window.opener.dBtnObj(label,function(){closeDialog()});btns.push(btn);dlgBtnList.push(btns);btns=[];label=langTbl.d_ok;btn=new window.opener.dBtnObj(label,function(){closeDialog()});btns.push(btn);dlgBtnList.push(btns)}
function destroyDialog(){for(var a=0,b=dlgBtnList.length;a<b;a++)delete dlgBtnList[a];dlgBtnList.length=0}function scrollToNewMessage(){var a=document.getElementsByClassName("newmes_block"),b=null,c=a.length;if(c)for(i=0;i<c;i++)if("none"!=$(a[i]).css("display")){b=a[i];break}b?document.getElementById("im_msgline").scrollTop=b.offsetTop-5:document.getElementById("im_msgline").scrollTop=document.getElementById("im_msgline").scrollHeight}
function openDialog(a,b){var c=0;closeDialog();viewModel.dialogMsg(a);a=0;for(var d=b.length;a<d;a++)viewModel.dialogBtns.push(b[a]),c++;$("#dialg_mask").css("display","block");$(".dialog_btn").css("display","none");$(".dialog_btn_"+c).css("display","block")}function closeDialog(){$("#dialg_mask").css("display","none");$(".dialog_btn").css("display","none");viewModel.dialogMsg("");viewModel.dialogBtns.removeAll()}
function setImEnterMode(a){l.log("enterKeyOperation apply:"+a);$(".im_ta").off("keydown.enter");$(".im_ta").on("keydown.enter",function(b){if(13==b.which){if(b.ctrlKey&&0==a||!b.ctrlKey&&1==a)return sendChat(viewModel.targetUsr(),$(this).val()),!1;if(b.ctrlKey&&1==a){b=$(this).val();var c=(b.match(/\n/g)||[]).length;if(512<b.length+c+2)return!1;c=this.selectionStart;var d=c+1;this.value=b.substr(0,c)+"\n"+b.substr(c);this.setSelectionRange(d,d);return!1}}})}
function clearImNew(){viewModel.targetUsr()&&(window.opener.deleteImAlert(viewModel.targetUsr()),window.opener.deleteDsktpNotification(window.opener.NOTIF_TYPE_IM,viewModel.targetUsr()),window.opener.imOpened(viewModel.targetUsr()))}function openDialer(a){window.opener.focus();window.opener.openDialer(a)}function sendMail(a){window.opener.sendMail(a)}function openConfURL(a){window.opener.openConfURL(a)};
