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 ""; } function setCookie( name, value, expiredays ) { var today = new Date(); today.setDate( today.getDate() + expiredays ); document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";"; } function getDateValue() { var today = new Date(); var hour = (today.getHours()% 12 == 0) ? 12 : (today.getHours()% 12).datelength(); var hour_vaule = (today.getHours() > 11) ? "오후 "+hour : "오전 "+hour; var res = hour_vaule+":"+ today.getMinutes().datelength(); return res; } Number.prototype.datelength = function() { if(this < 10) res = "0"+this; else res = ""+this; return res; } function getFileSize(obj) { var size = 0; if(typeof(obj.files) == 'undefined') { size = 1; } else size = obj.files[0].size; return size; } function html2text(val){ var res = val.replace(/"/g, '"'); res = res.replace(//g, '>'); res = res.replace(/\r\n|\n/g,'
'); return res; } function removenl(val){ var res = val.replace(/\r\n|\n/g,''); return res; } function autolink(val) { var res = ""; var regURL1 = new RegExp("(http|https|ftp|telnet|news|irc)://([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi"); var regURL2 = new RegExp("(www.)([-/.a-zA-Z0-9_~#%$?&=:200-377()]+)","gi"); if(regURL1.test(val)) { res = val.replace(regURL1,"$1://$2"); } else { res = val.replace(regURL2,"$1$2"); } return res; } function checkFileForm(obj) { var maxFileSize = 2*1024*1024; if($(obj).val() != "") { if(clientCode && agentCode ) { var c = confirm("이 파일을 전송하시겠습니까?"); if(c == true) { var filesize = getFileSize(obj); if(maxFileSize < filesize) { alert("2메가 이상 업로드 할 수 없습니다."); return; } $(".progress").css('display','block'); var input1 = $("").attr("type", "hidden").attr("name", "clientCode").val(clientCode); var input2 = $("").attr("type", "hidden").attr("name", "agentCode").val(agentCode); var input3 = $("").attr("type", "hidden").attr("name", "mainCode").val(mainCode); $('#fileuploadform').append($(input1)); $('#fileuploadform').append($(input2)); $('#fileuploadform').append($(input3)); $('#fileuploadform').submit(); } } else { alert("대화중이지 않습니다."); $(obj).val(""); return; } } $(obj).val(""); } function getStringToUnicode(str){ var res = escape(str); while(1){ if( res.indexOf("%") != -1 ) res = res.replace("%", "\\"); else break; } return res; } function popRemote(uid,acode) { var cf = confirm("상담원에게 PC원격을 요청하시겠습니까?"); if(cf == true) window.open('http://helppc.net/'+uid+'/'+acode, '_remote','width=530,height=600,resizeable=yes'); } function setChatContent(display) { $('.chaticon_content').css('display',display); $('.chatclose').css('display',display); } function checkNick() { if(!((event.keyCode >= 45032 && event.keyCode <= 55203) || (event.keyCode >= 12593 && event.keyCode <= 12622) || (event.keyCode >= 12623 && event.keyCode <= 12643) || (event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)) ) { if(event.preventDefault) event.preventDefault(); else event.returnValue = false; } } $(function(){ var bar = $('.bar'); var percent = $('.percent'); var status = $('#status'); $(document).on("change","#chatfile, #imgfile",function(e) {checkFileForm(this)}); $('#fileuploadform').ajaxForm({ beforeSend: function() { status.empty(); var percentVal = '0%'; bar.width(percentVal) percent.html(percentVal); }, uploadProgress: function(event, position, total, percentComplete) { var percentVal = percentComplete + '%'; bar.width(percentVal) percent.html(percentVal); }, success: function() { var percentVal = '100%'; bar.width(percentVal); percent.html(percentVal); }, complete: function(xhr) { var res = jQuery.parseJSON(xhr.responseText); if(res.code == 200) { if(chattype != 2) { //var ourl = decodeURIComponent((res.url)+getStringToUnicode(res.filename)+"").replace(/'/gi,"\'"); //res.url = res.url+res.filename+""; $('input[name=action]').val('{"mode":"file","mainCode":"'+mainCode+'","agentCode":"'+agentCode+'","clientCode":"'+clientCode+'","agentName":"'+getStringToUnicode(agentName)+'","clientIP":"'+clientIP+'","msg":"'+res.url+'","type":"'+res.type+'"}'); //$.post('/runchat/sendchat.php','mode=file&mainCode='+mainCode+'&agentCode='+agentCode+'&clientCode='+clientCode+'&agentName='+agentName+'&clientIP='+clientIP+'&msg='+res.url+'&type='+res.type,function(data){}) } res.url = decodeURIComponent(res.url); var chatfile = $("input[name=chatfile]"), chatfile_clone = chatfile.clone(true); chatfile.replaceWith(chatfile_clone); var imgfile = $("input[name=imgfile]"), imgfile_clone = imgfile.clone(true); imgfile.replaceWith(imgfile_clone); sendFile(res); } else { alert(res.msg); } //$('#msgbox').val(res.url); //$('.send .sendbtn').click(); $(".progress").css('display','none'); } }); $(document).on('click','.chatlist_container .chatlistmore_content', function() { chatlistpage = chatlistpage+1; $.post('/runchat/history.php','lmode='+lmode+'&maincode='+mainCode+'&agentcode='+agentCode+'&page='+chatlistpage+'&scale=7', function(data) { $('.chatlist_content').append(data); }) }); $(document).on('click','.chatlist_container .chatlist_title li', function() { chatlistpage = 1; var listmode = $(this).attr('lmode'); lmode = listmode; $('.chatlist_container .chatlist_title li').removeClass('active'); $(this).addClass('active'); $.post('/runchat/history.php','lmode='+lmode+'&maincode='+mainCode+'&agentcode='+agentCode+'&page='+chatlistpage+'&scale=7', function(data) { $('.chatlist_content').html(data); }) }); })