// 미래톡 키로 치환
if(mi_chat_adkey != mi_cfg.load.mi_adkey){
	mi_chat_adkey = mi_cfg.load.mi_adkey;
}

/* 전역 함수 */
// ie 대응코드 
if (!('remove' in Element.prototype)) {
  Element.prototype['remove'] = function () {
    if (this.parentNode) {
      this.parentNode.removeChild(this);
    }
  }
}

/* 객체 갯수 및 문자열 길이 체크 */
function mi_object_cnt(obj){
	var flag = false;
	for(var prop in obj){
		if(obj.hasOwnProperty(prop)){ 
			flag = true;
			break;
		}
	}
	return flag;
}

function param_to_query(obj){
	var prefix = '';
	if(typeof this.prefix !== 'undefined'){ 
		prefix = this.prefix;
	}
	var str = prefix+Object.keys(obj).reduce(function(a,k){
		a.push(k+'='+encodeURIComponent(obj[k]));
	return a;
	}, []).join('&');
	return str;
}
/* 전역 함수 */

/* 전역 변수 */
var mi_wd = window.document;
var mi_res_qstr = null;
var mi_uk = { uk:'', un:'', ue:'', up:'' };
/* 전역 변수 */

if(typeof mi_cookie_data == "undefined"){
	mi_cookie_data = {};
	mi_cookie_data.setCookie = function(name, value, expires, path, domain, secure){
		var today = new Date();
		var expires_date = new Date(today.setDate( today.getDate() + expires)  );

		var s_name = name + '=';
		var cookie_val = document.cookie;
		var search_cookie = cookie_val.indexOf(s_name);
		var cookie_time = "";

		if(secure == "Safari"){
			var date = new Date();
			var hours = 1;
			date.setTime(date.getTime()+(hours*60*60*1000));

			cookie_time = ";expires=" + date.toGMTString() + "";
		}else{
			if( search_cookie != -1 ){
				today.setDate( today.getDate() - 1 );
				document.cookie = name + "= " + "; expires=" + today.toGMTString() + "" +
				";path=/" ;
			}
			if( name != "mi_chat_vc" && expires != "" ) cookie_time = ";expires=" + expires_date.toGMTString() + "";
		}
		document.cookie = name + "=" +escape( value ) +
		 cookie_time +
		";path=/" ;
	}

	mi_cookie_data.getCookie = function(check_name){
		var a_all_cookies	= document.cookie.split(';');
		var a_temp_cookie	= '';
		var cookie_name		= '';  //cookie name
		var cookie_value	= '';  //cookie value
		var b_cookie_found	= false; // set boolean t/f default f
		for (var i = 0; i < a_all_cookies.length; i++ ){  //get all cookie and loop
			a_temp_cookie = a_all_cookies[i].split( '=' );  //div cookie name , value 
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');  //[=] before cookie name set
			if (cookie_name == check_name){
				b_cookie_found = true;
				if (a_temp_cookie.length > 1){
					cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));  //[=] after cookie value set
				}
				return cookie_value;  //cookie value return
				break;
			}
			a_temp_cookie = null; //temp cookie set null
			cookie_name = ''; //cookie name set null
		}
		if (!b_cookie_found) {
			return "";
		}
	}
	mi_cookie_data.setCookieOneTime = function(name, value, domain){
		document.cookie = name+"="+escape(value)+";expires=;path=/" ;
	}
}

if(typeof mi_chat_msg == "undefined"){
	mi_chat_msg = {};
	mi_chat_msg.week_flag		= false;
	mi_chat_msg.time_flag		= false;
	mi_chat_msg.sms_time_flag	= false;
	mi_chat_msg.week			= {};
	mi_chat_msg.week[0]			= '일';
	mi_chat_msg.week[1]			= '월';
	mi_chat_msg.week[2]			= '화';
	mi_chat_msg.week[3]			= '수';
	mi_chat_msg.week[4]			= '목';
	mi_chat_msg.week[5]			= '금';
	mi_chat_msg.week[6]			= '토';
	mi_chat_msg.week['all']		= '00:00am ~ 23:59pm';

	mi_chat_msg.use				= {};
	mi_chat_msg.use.Y			= "안녕하세요. 상담원 연결까지 시간이 걸릴 수 있습니다.";
	mi_chat_msg.use.N			= "죄송합니다. 지금은 상담 운영시간이 아닙니다.";
	mi_chat_msg.chat_time		= "채팅상담 운영시간<br>[week] : [time]";

	mi_chat_msg.getTitle = function(){
		var flag = 'N';
		if(mi_chat_msg.time_flag || mi_chat_return.counsel.absent_msg != "") flag = 'Y';
		if(mi_object_cnt(mi_chat_return.counsel.msg.title[flag]) && mi_chat_return.counsel.msg.title[flag]!= '' && mi_chat_return.counsel.msg.title[flag]!='undefined') {
			mi_chat_msg.use[flag] = mi_chat_return.counsel.msg.title[flag].replace(/\\n/gi,"");
		}
		return mi_chat_msg.use[flag];
	}

	mi_chat_msg.getChatTitle = function(){
		// 운영
		var temp_msg = '';
		if(mi_object_cnt(mi_chat_return.counsel)){
			time_chk = mi_chat_return.counsel.week;
			var cs = [];
			var d =new Date() ;
			var t_s=new Date() ;
			var t_e=new Date() ;
			week = d.getDay() , h = d.getHours() , m = d.getMinutes() , d.setSeconds(0) ;
			mi_chat_msg.time_flag = false;
			var str_start , str_end , str_week , str_time;
			//운영시간 체크
			now_day_week = d.getDay();
			time_chk = time_chk[now_day_week];
			time_chk = time_chk.replace(/:/gi,"");
			time_chk = time_chk.split('~');
			now_hours = String(d.getHours());
			now_minut = String(d.getMinutes());
			if(now_hours.length == 1){ 
			  now_hours = "0" + now_hours;
			} 
			if(now_minut.length == 1){ 
			  now_minut = "0" + now_minut;
			}
			now_time = now_hours +""+ now_minut;

			if(now_time >= time_chk[0] && now_time <= time_chk[1]){
				mi_chat_msg.time_flag = true;
				mi_chat_msg.sms_time_flag = true;
			}
			//휴계시간 체크
			resttime = mi_chat_return.counsel.resttime;
			resttime = resttime.replace(/:/gi,"");
			resttime = resttime.split('~');
			if(now_time >= resttime[0] && now_time <= resttime[1]){
				mi_chat_msg.time_flag = false;
			}

			
			//공휴일 휴무 체크
			if(mi_chat_return.counsel.hollyday == "Y"){
				var solarHolidays = ["0101", "0301", "0505","1225"]; //양력휴일
				var month = new String(d.getMonth()+1); 
				var day = new String(d.getDate());
				if(month.length == 1){ 
				  month = "0" + month; 
				} 
				if(day.length == 1){ 
				  day = "0" + day; 
				}
				hollyday = month + day;
				if(solarHolidays.indexOf(hollyday)>= 0){
					mi_chat_msg.time_flag = false;
					mi_chat_msg.sms_time_flag = false;
				};
			}
			
			var str_week = cs.join(","+(cs.length<7?" ":""));
			if(typeof str_week!=='undefined' && typeof str_time!=='undefined'){
				temp_msg = mi_chat_msg.chat_time;
				temp_msg = temp_msg.replace("[week]" + (str_week!=''?'':' : '),str_week);
				temp_msg = temp_msg.replace("[time]",str_time);
			}
		}
		return temp_msg;
	}
}

if(typeof mi_chat_handledre == "undefined"){
	mi_chat_handledre = {};
	mi_chat_handledre.talk_start	= null;
	mi_chat_handledre.sms_start		= null;
	mi_chat_handledre.device		= '';
	mi_chat_handledre.org_meta		= [];
	mi_chat_handledre.childwindow	= "";
	mi_chat_handledre.receiveData	= '';
	mi_chat_handledre.beforeMitalkBoardStatue = '';

	mi_chat_handledre.click = function(){
		if(document.getElementById('mi-push-iframe-box')){
			//document.getElementById('mi-push-iframe-box').remove();
		}
		if(document.getElementById(miIconActivity.iconActivityMsgID)){
			document.getElementById(miIconActivity.iconActivityMsgID).style.display = 'none';
		}
		if(document.getElementById(miIconActivity.iconActivityCntID)){
			document.getElementById(miIconActivity.iconActivityCntID).style.display = 'none';
		}		
		if(mi_chat_handledre.device == 'M'){
			mi_chat_handledre.childwindow = window.open("https://www.miraetalk.com/chatClient_v2?newwindow");
			return;
		}
		icon = document.getElementById("mi-chat-icon-box");
		var mi_nudge_el_box = document.getElementById("mi-push-iframe-box");
		var mi_nudge_el = document.getElementById("mi-push-script-iframe");
		var chat_mobile_class = "mi-chat-mobile";
		if(icon.style.display == 'none'){
			if(typeof(mi_nudge_el) != 'undefined' && mi_nudge_el != null){
				if(mi_nudge_el.style.display =='none'){
					mi_nudge_el.style.display = 'block';
					mi_nudge_el_box.style.opacity = "1";
				}
			}
			if(mi_chat_handledre.device == 'M'){
				document.body.className = document.body.className.replace(/(?:^|\s)mi-chat-mobile(?!\S)/g , '');
				if(document.getElementById("mirae_defender_layer")) document.getElementById("mirae_defender_layer").style.display = 'block';
				var n = mi_wd;
				n.getElementById("mi-chat-viewport").parentNode.removeChild(n.getElementById("mi-chat-viewport"));
				if (mi_chat_handledre.org_meta.length){
					for(var i in mi_chat_handledre.org_meta ){
						var regex = /^[0-9]$/g;
						// 배열에 숫자가 아닌 문자로 key 가 잡히는경우가 생김
						if(regex.test(i)){
							var meta = mi_chat_handledre.org_meta[i];
							n.getElementsByTagName("head")[0].appendChild(meta);
						}
					}
					mi_chat_handledre.org_meta = [];
				}
			}
			mi_chat_handledre.setMitalkBoardStatueCookie(0);
			if(typeof mi_chat_handledre.receiveData !== 'undefined' && typeof mi_chat_handledre.receiveData.param !== 'undefined'){
				mi_chat_handledre.beforeMitalkBoardStatue = mi_chat_handledre.receiveData.param;
			}
			mi_btn_fade.act('icon','chat');
		}else{
			if(typeof(mi_nudge_el) != 'undefined' && mi_nudge_el != null){
				if(mi_nudge_el.style.display =='block'){
					mi_nudge_el.style.display = 'none';
				}
			}
			if(mi_chat_handledre.device == 'M'){
				document.body.className += " " + chat_mobile_class ;
				if(document.getElementById("mirae_defender_layer")) document.getElementById("mirae_defender_layer").style.display = 'none';
				var n = mi_wd;
				var metaTag = n.getElementsByTagName("head")[0].getElementsByTagName("meta");
				for(var i in metaTag){
					var e = metaTag[i];
					if(e.name === 'viewport' && e.id !== "mi-chat-viewport"){
						mi_chat_handledre.org_meta.push(e);
						e.parentNode.removeChild(e);
					}
				}
				var r = n.createElement("meta");
				r.id = "mi-chat-viewport", r.name = "viewport", r.content = "user-scalable=no,target-densitydpi=medium-dpi, width=720,";
				n.getElementsByTagName("head")[0].appendChild(r);
			}
			mi_chat_handledre.setMitalkBoardStatueCookie(mi_chat_handledre.beforeMitalkBoardStatue != '' ? mi_chat_handledre.beforeMitalkBoardStatue : 1);
			mi_btn_fade.act('chat','icon');
		}
	}
	mi_chat_handledre.click_naver = function(){
		window.open('http://talk.naver.com/' + mi_chat_return.btn_list.naver.key , 'naver_talktalk', 'scrollbars=1, resizable=1, width=486, height=745');
	}
	mi_chat_handledre.click_kakao = function(){
		window.open(mi_chat_return.btn_list.kakao.key , 'kakao_talktalk', 'scrollbars=1, resizable=1, width=486, height=745');
	}
	mi_chat_handledre.iframeInfo = function(type){
		if(mi_object_cnt(mi_chat_return.counsel.default_msg.week)) mi_chat_msg.week = mi_chat_return.counsel.default_msg.week;
		if(mi_object_cnt(mi_chat_return.counsel.default_msg.use)) mi_chat_msg.use = mi_chat_return.counsel.default_msg.use;
		if(mi_object_cnt(mi_chat_return.counsel.default_msg.chat_time)) mi_chat_msg.chat_time = mi_chat_return.counsel.default_msg.chat_time;

		var result = {};
		result.title = '';
		result.counsel = '';
		result.mi_chat_return = mi_chat_return;
		result.btn = mi_chat_return.btn_list;
		result.counsel = mi_chat_msg.getChatTitle();
		result.title = mi_chat_msg.getTitle();
		result.visit_id = mi_chat_return.visit_id;
		result.adkey = mi_chat_adkey;
		result.log = mi_chat_return.log_data;
		result.mi_chat_return.chat_act = mi_chat_msg.time_flag;
		result.mi_chat_return.sms_act = mi_chat_msg.sms_time_flag;
		var sendData = JSON.stringify({fn:'returnIframeInfo' , 'data' :result});
		if(type == "new"){
			mi_chat_handledre.childwindow.postMessage(sendData,"https://www.miraetalk.com");
		}else{
			document.getElementById('mi-chat-script-iframe').contentWindow.postMessage(sendData, '*');
		}
		return result;
	}
	mi_chat_handledre.smsQuickClose = function(){
		try{
			mi_wd.getElementById("mi_sms_box").parentNode.removeChild(mi_wd.getElementById("mi_sms_box"));
		}catch(e){
			window.document.getElementById("mi_sms_box").parentNode.removeChild(window.document.getElementById("mi_sms_box"));
		}
	}
	mi_chat_handledre.smsIsLive = function(){
		if (typeof mi_chat_handledre.sms_start === 'function') mi_chat_handledre.sms_start();
		sendData = mi_chat_return.log_data;
		document.getElementById('mi-sms-script-iframe').contentWindow.postMessage(sendData, '*');
	}
	
	mi_chat_handledre.setMitalkBoardStatueCookie = function(statue){
		/* 0 : close , 1:open , 2:chat , 3:sms */
		if(typeof statue === 'undefined'){
			if(typeof mi_chat_handledre.receiveData !== 'undefined' && typeof mi_chat_handledre.receiveData.param !== 'undefined'){
				statue = mi_chat_handledre.receiveData.param;
			}
		}
		var mi_domain = unescape(document.location.href);
		mi_cookie_data.setCookieOneTime ("_mi_board_statue", statue, mi_domain);
	}

	// 미톡 로드 되었을시 리턴 함수
	mi_chat_handledre.onLoad = function(){
		if (typeof mi_chat_handledre.talk_start === 'function'){
			mi_chat_handledre.talk_start();
			//미톡 활성화 상태값 체크
			var _mi_board_statue = mi_cookie_data.getCookie('_mi_board_statue');
			if(mi_object_cnt(mi_chat_return.autoOpen)){
				var temp_flag = false;

				if(typeof mi_chat_return.autoOpen.auto !== 'undefined' && mi_chat_return.autoOpen.auto == 'Y' && _mi_board_statue == 2){
					temp_flag = true;
				}
				if(typeof mi_chat_return.autoOpen.direct !== 'undefined' && mi_chat_return.autoOpen.direct == 'Y' && mi_chat_return.autoOpen.statue != ''){
					_mi_board_statue = mi_chat_return.autoOpen.statue;
					temp_flag = true;
				}
				if(temp_flag){
					mi_chat_handledre.click();
					setTimeout(function() {
						var sendData = JSON.stringify({fn:'returnAutoBoardChange' , 'data' :_mi_board_statue});
						if (mi_chat_handledre.device == 'M'){
							mi_chat_handledre.childwindow.postMessage(sendData,"*");
						}else{
							document.getElementById('mi-chat-script-iframe').contentWindow.postMessage(sendData, '*');
						}
					},1000);
				}else{
					// 아이콘 자동 클릭
					if (typeof mi_chat_return.autoOpen.icon !== 'undefined' && mi_chat_return.autoOpen.icon == 'Y'){
						document.getElementById('mi-chat-icon-box').style.visibility = 'hidden';
						mi_chat_handledre.click();
					}
				}
			}
			mi_chat_handledre.talk_start = null;
		}
	}
	
	// 티커
	mi_chat_handledre.ticker= function(){
		if(typeof document.getElementById('mi-ticker-script-iframe') === 'null' || document.getElementById('mi-ticker-script-iframe') == null) return;
		
		document.getElementById('mi-ticker-script-iframe').height= 80;
		document.getElementById('mi-ticker-script-iframe').style.display = "block";
		document.getElementById('mi-ticker-iframe-box').style.setProperty("z-index", "1000000000", "important");
		document.getElementById('mi-ticker-iframe-box').style.opacity = "1";

		if(mi_object_cnt(mi_chat_handledre.receiveData.param)){
			mi_chat_handledre.receiveData.param['device'] = mi_chat_return.log_data.device;
			mi_chat_handledre.receiveData.param['icon_p'] = mi_chat_return.icon.p;
			mi_ticker_data.send(mi_chat_handledre.receiveData);
		}
	}
	mi_chat_handledre.ticker_close= function(){
		document.getElementById('mi-ticker-iframe-box').style.setProperty("z-index", "-1", "important")
		document.getElementById('mi-ticker-script-iframe').style.display	= "none";
	}

	window.addEventListener('message', function(e) {
		mirae_confirm = '\"fn\":\"mi'
		if(typeof e.data !== 'undefined'){
			var receiveData = '';
			if(typeof e.data === 'string' && e.data.indexOf(mirae_confirm)>-1){ 
				receiveData = JSON.parse(e.data);
			}else if(typeof e.data === 'object' && typeof e.data.fn !== 'undefined'){
				receiveData = e.data;
			}
			mi_chat_handledre.receiveData = receiveData;
			if(typeof receiveData === 'object' && typeof eval(receiveData.fn) === 'function'){
				if(receiveData.fn == 'mi_ticker.row_add'){
					mi_ticker.row_add(e.data);
				}else if(receiveData.fn == 'mi_ticker.row_remove'){
					mi_ticker.row_remove(e.data);
				}else{
					eval(receiveData.fn + "();");
				}
			}
		}
	});
}

/* 로그분석 티커 */
if(typeof mi_ticker == "undefined"){
	var mi_ticker = {}
	mi_ticker.doc = {}
	mi_ticker.iframe_url = mi_cfg.url.mitalk+'/ticker/append';
	mi_ticker.init_cnt = {
		'hit':[],
		'cart':[],
		'order':[],
		'view_order':[],
		'view_together':[],
		'view_hit':[],
		'topselling':[],
		'soldout':[]
	}
	mi_ticker.ticker_max_show_cnt = null;
	mi_ticker.ticker_wait_sec = null;

	mi_ticker.uuid = (prefix = "", random = false)=>{
		const sec = Date.now() * 1000 + Math.random() * 1000;
		const id = sec.toString(16).replace(/\./g, "").padEnd(14, "0");
		return `${prefix}_${id}${random ? `.${Math.trunc(Math.random() * 100000000)}`:""}`;
	}
	
	if(mi_cookie_data.getCookie("mi_ticker_id")){
		mi_ticker.id = mi_cookie_data.getCookie("mi_ticker_id");
	}else{
		mi_ticker.id = mi_ticker.uuid(mi_chat_adkey,false);
		mi_cookie_data.setCookie('mi_ticker_id',mi_ticker.id, 1,'',unescape(document.location.href),'');
	}
	
	mi_ticker.doc.getid=(el)=>{
		return document.getElementById(el);
	}

	mi_ticker.doc.getcs=(el)=>{
		return document.getElementsByClassName(el);
	}

	mi_ticker.data_call=()=>{
		var data = {}
		data.cfg = mi_ticker_return; // response data
		data.cfg.is_mobile = false;
		if(window.innerWidth<=768){
			data.cfg.is_mobile = true;
		}
		mi_ticker.is_mobile = data.cfg.is_mobile;
		mi_ticker.ticker_max_show_cnt = data.cfg.ticker_max_show_cnt;
		mi_ticker.ticker_wait_sec = (data.cfg.ticker_wait_sec*1000);

		data.adkey	= mi_chat_adkey; // 애드키 채널키 
		if(typeof mi_conv!=='undefined'){ 
			data.mi_conv = mi_conv; // 전환값
		}

		//mi_ticker.id = _mi_log_vi;
		if(typeof mi_ticker.id!=='undefined'){
			data.ticker_id = mi_ticker.id;
			var send_data = JSON.stringify({'fn':'data_back','data':data});
			mi_ticker.doc.getid('mi_ticker_iframe').contentWindow.postMessage(send_data, '*');
		}
	}

	mi_ticker.fadeout=(uid,iframe_pos)=>{
		var fadeTarget = mi_ticker.doc.getid('mi_ticker_iframe_'+uid);
		var fadeEffect = setInterval(function () {
			if (!fadeTarget.style.opacity) {
				fadeTarget.style.opacity = 1;
			}
			if (fadeTarget.style.opacity > 0) {
				fadeTarget.style.opacity -= 0.1;
			} else {
				if(mi_ticker.is_mobile){
					iframe_pos = 'bottom_center';
				}
				mi_ticker.doc.getid('mi_ticker_pos_'+iframe_pos).style.zIndex = '-1';
				if(mi_ticker.doc.getid('mi_ticker_iframe_wrap_'+uid)!==null){
					mi_ticker.doc.getid('mi_ticker_iframe_wrap_'+uid).remove();
				}
				clearInterval(fadeEffect);
			}
		}, 50);
	}

	mi_ticker.row_remove=(data)=>{
		var res =JSON.parse(data);
		res = res.data;
		mi_ticker.fadeout(res.uid,res.cfg.position);
		setTimeout(()=>{ mi_ticker.init_cnt[res.cfg.source] = []; },mi_ticker.ticker_wait_sec);
	}

	var row_cnt = 0;
	mi_ticker.row_add=(data)=>{
		var molen = mi_ticker.doc.getcs('mi_ticker_pos_bottom_center').length;
		if(molen > 0 && mi_ticker.is_mobile && mi_ticker.ticker_wait_sec < 1){
			setTimeout(()=>{ mi_ticker.row_add(data); },500);
			return;
		}

		if(mi_ticker.is_mobile && mi_ticker.ticker_wait_sec > 0){
			mi_ticker.ticker_max_show_cnt = 1;
		}

		var res =JSON.parse(data);
		res = res.data;

		if(mi_ticker.ticker_wait_sec > 0){
			var pos_count = 0;		
			for(const v in mi_ticker.init_cnt){
				if(mi_ticker.init_cnt[v].length>=1){
					pos_count = pos_count+1;
				}
				if(pos_count >= mi_ticker.ticker_max_show_cnt){
					return;
				}
			}
			if(mi_ticker.init_cnt[res.cfg.source].length >=1){
				return;
			}
			mi_ticker.init_cnt[res.cfg.source].push(1);
		}

		if(mi_ticker.is_mobile && !res.cfg.mobile_init){
		//	console.log(res);
		//	return;
		}

		const url = mi_ticker.iframe_url;  
		const max_zindex = '2147483647';

		var ticker_iframe_wrap_id = 'mi_ticker_iframe_wrap_'+res.uid; // 아이프레임 박스 
		var ticker_iframe_id = 'mi_ticker_iframe_'+res.uid; // 아이프레임 

		var ticker_wrap = null; 
		var class_name = null; 
		var pos_top = false; 

		res.cfg.ticker_iframe_wrap_id = ticker_iframe_wrap_id; // 콜백에서 실행될 
		res.cfg.ticker_iframe_id = ticker_iframe_id; // 콜백에서 실행될

		var div_arr = [
						'mi_ticker_pos_bottom_left','mi_ticker_pos_bottom_center','mi_ticker_pos_bottom_right',
						'mi_ticker_pos_middle_left','mi_ticker_pos_middle_center','mi_ticker_pos_middle_right',
						'mi_ticker_pos_top_left','mi_ticker_pos_top_center','mi_ticker_pos_top_right'
					  ]			

		var pos_arr = [
						'top_left','top_center','top_right',
						'middle_left','middle_center','middle_right',
						'bottom_left','bottom_center','bottom_right'
					  ]	

		for(var x=0;x<div_arr.length;x++){
		//	ticker_wrap = mi_ticker.doc.getid(div_arr[x]);
		//	ticker_wrap.style.zIndex = '-1';
		}

		//res.cfg.position = pos_arr[Math.floor(Math.random() * pos_arr.length)];
		//res.cfg.position = 'bottom_center';
		switch(res.cfg.position){
			case 'top_left':
				pos_top		= true;
				class_name	= 'mi_ticker_pos_top_left';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'top_center': 
				pos_top		= true;
				class_name	= 'mi_ticker_pos_top_center';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'top_right': 
				pos_top		= true;
				class_name	= 'mi_ticker_pos_top_right';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'middle_left': 
				class_name	= 'mi_ticker_pos_middle_left';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'middle_center': 
				class_name	= 'mi_ticker_pos_middle_center';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'middle_right': 
				class_name	= 'mi_ticker_pos_middle_right';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'bottom_left': 
				class_name	= 'mi_ticker_pos_bottom_left';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'bottom_center': 
				class_name	= 'mi_ticker_pos_bottom_center';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
			case 'bottom_right': 
				class_name	= 'mi_ticker_pos_bottom_right';
				ticker_wrap = mi_ticker.doc.getid(class_name); 
			break;
		}

		var item_cnt = mi_ticker.doc.getcs(class_name).length;
		if(item_cnt>=3){
			return;
		}
		
		if(mi_ticker.is_mobile){
			class_name	= 'mi_ticker_pos_bottom_center'; 
			ticker_wrap = mi_ticker.doc.getid(class_name);
			ticker_wrap.style.maxWidth = null;
			ticker_wrap.style.top = null;
			ticker_wrap.style.left = null;
			ticker_wrap.style.bottom = null;
			ticker_wrap.style.marginTop = null;
			ticker_wrap.style.marginBottom = null;

			ticker_wrap.style.position = 'absolute';
			ticker_wrap.style.width = '90%';
			ticker_wrap.style.left = '50%';
			ticker_wrap.style.height = (res.cfg.item_height+10)+'px';

			if(res.cfg.mobile_position == 'top'){
				ticker_wrap.style.transform = 'translate(-50%,0%)';
				ticker_wrap.style.top = '0%';
				ticker_wrap.style.marginTop = res.cfg.mobile_position_move_pixel+'px';
			}else if(res.cfg.mobile_position == 'middle'){
				ticker_wrap.style.transform = 'translate(-50%,-50%)';
				ticker_wrap.style.top = '50%';
				ticker_wrap.style.marginTop = res.cfg.mobile_position_move_pixel+'px';
			}else if(res.cfg.mobile_position == 'bottom'){
				ticker_wrap.style.transform = 'translate(-50%,0%)';
				ticker_wrap.style.bottom = '0%';
				ticker_wrap.style.marginBottom = res.cfg.mobile_position_move_pixel+'px';
			}

			for(var i=0;i<pos_arr.length;i++){
				if(pos_arr[i]!='bottom_center'){
					if(mi_ticker.doc.getid('mi_ticker_pos_'+pos_arr[i])!==null){
						mi_ticker.doc.getid('mi_ticker_pos_'+pos_arr[i]).remove();
					}
				}
			}
		}

		if(ticker_wrap !== null){
			ticker_wrap.style.zIndex = max_zindex;
	
			var ticker_iframe_wrap = document.createElement('div');
			ticker_iframe_wrap.id = ticker_iframe_wrap_id;
			ticker_iframe_wrap.style.height = res.cfg.item_height+'px';
			ticker_iframe_wrap.className  = class_name;

			var ticker_iframe = document.createElement('iframe');
			ticker_iframe.id = ticker_iframe_id;
			ticker_iframe.src = url;
			ticker_iframe.scrolling = 'no'; 
			ticker_iframe.style.border = '0';
			ticker_iframe.style.width = '100%';
			ticker_iframe.style.height = '100%';

			ticker_iframe_wrap.append(ticker_iframe);

			if(pos_top === true) ticker_wrap.append(ticker_iframe_wrap);
			else ticker_wrap.prepend(ticker_iframe_wrap);

			if(res.my === false){
				row_cnt = 0;
			}

			row_cnt = row_cnt+1;
			setTimeout(()=>{
				var send_data = JSON.stringify({'fn':'draw','data':{'html':res.html,'uid':res.uid,'cfg':res.cfg,'log':res.log,'is_mobile':mi_ticker.is_mobile}});
				document.getElementById(ticker_iframe_id).contentWindow.postMessage(send_data, '*');
			},row_cnt*500);
			
		}
	}
}

/* 전환처리 함수 START */
if(typeof mi_chat_conv == 'undefined'){
	mi_chat_conv = {}
	mi_chat_conv.mi_type_before = [];
	mi_chat_conv.in_array = function(arr,val){
		for(i=0; i<arr.length; i++){
			if(arr[i] == val){
				return i;
			}
		}
		return -1;
	}
	mi_chat_conv.send = function(o){
		if(mi_cfg.load.log_use_yn=='N' || mi_cfg.load.flag =='N' || !mi_cfg.use.analysis){
			return;
		}
		if((typeof o.mi_type!='undefined' && typeof o.mi_val!='undefined') && (o.mi_type!='' && o.mi_val!='')){
			if(this.in_array(this.mi_type_before,o.mi_type)==-1){
				if(typeof window.jQuery=='undefined'){
					function runWithJQuery(jQueryCode){
						if(window.jQuery)  jQueryCode();
						else{   
							var script = document.createElement('script'); 
							document.head.appendChild(script);  
							script.type	  = 'text/javascript';
							script.src	  = "https://code.jquery.com/jquery-3.6.0.js";
							script.onload = jQueryCode;
						}
					}
					runWithJQuery(function jQueryCode(){
						mi_chat_conv.act(o);	
					})
				}else{
					mi_chat_conv.act(o);
				}
			}else{
				console.log(o.mi_type,'already processed');
			}
		}else{
			console.log(o,'typeof undefined');
		}
	}
	mi_chat_conv.act = function(o){
		if(mi_res_qstr != null){
			var qstr = mi_res_qstr.split('?')[1].split('&');
			var conv_arr = [];
			//for(var i in qstr){
			for(var i = 0; i < qstr.length; i++){
				var s = qstr[i].split('=');
				if(this.in_array(['mi_type','mi_val','mi_order_num'],s[0])==-1){
					var ss = s[0]+':\''+s[1]+'\'';
					conv_arr.push(ss);
				}
			}
			conv_arr.push('mi_type:\''+o.mi_type+'\'');
			conv_arr.push('mi_val:\''+o.mi_val+'\'');
			if(typeof o.mi_order_num != 'undefined' && o.mi_order_num!=''){
				conv_arr.push('mi_order_num:\''+o.mi_order_num+'\'');
			}	
			conv_arr = '{'+conv_arr.join(',')+'}';
			eval('var conv_data='+conv_arr);
			if(typeof window.jQuery!='undefined'){
				$.post("//log1.toup.net/mirae_response_conv.php",conv_data,function(result){
					console.log(result);	
				}); 
			}else{
				console.log('jquery load failed');
			}
			this.mi_type_before.push(o.mi_type);
		}
	}

	mi_chat_conv.send2 = function(o){
		if(mi_cfg.load.log_use_yn=='N' || mi_cfg.load.flag =='N' || !mi_cfg.use.analysis){
			return;
		}
		if((typeof o.mi_type!='undefined' && typeof o.mi_val!='undefined') && (o.mi_type!='' && o.mi_val!='')){
			if(this.in_array(this.mi_type_before,o.mi_type)==-1){
				if(typeof window.jQuery=='undefined'){
					function runWithJQuery(jQueryCode){
						if(window.jQuery)  jQueryCode();
						else{   
							var script = document.createElement('script'); 
							document.head.appendChild(script);  
							script.type	  = 'text/javascript';
							script.src	  = "https://code.jquery.com/jquery-3.6.0.js";
							script.onload = jQueryCode;
						}
					}
					runWithJQuery(function jQueryCode(){
						mi_chat_conv.act2(o);	
					})
				}else{
					mi_chat_conv.act2(o);
				}
			}else{
				console.log(o.mi_type,'already processed');
			}
		}else{
			console.log(o,'typeof undefined');
		}
	}
	mi_chat_conv.act2 = function(o){
		if(mi_res_qstr != null){
			var qstr = mi_res_qstr.split('?')[1].split('&');
			var conv_arr = [];
			for(var i in qstr){
				var s = qstr[i].split('=');
				if(this.in_array(['mi_type','mi_val','mi_order_num'],s[0])==-1){
					var ss = s[0]+':\''+s[1]+'\'';
					conv_arr.push(ss);
				}
			}
			conv_arr.push('mi_type:\''+o.mi_type+'\'');
			conv_arr.push('mi_val:\''+o.mi_val+'\'');
			if(typeof o.mi_order_num != 'undefined' && o.mi_order_num!=''){
				conv_arr.push('mi_order_num:\''+o.mi_order_num+'\'');
			}	
			conv_arr = '{'+conv_arr.join(',')+'}';
			eval('var conv_data='+conv_arr);
			if(typeof window.jQuery!='undefined'){
				window.jQuery.post("//log1.toup.net/mirae_response_conv.php",conv_data,function(result){
					console.log(result);	
				}); 
			}else{
				console.log('jquery load failed');
			}
			this.mi_type_before.push(o.mi_type);
		}
	}

}
/* 전환처리 함수 END */

if(typeof mi_ticker_data == "undefined"){
	mi_ticker_data = {};
	mi_ticker_data.send = function(data){
		var sendData = JSON.stringify({fn:'addTicker' , 'data' :data});
		mi_ticker_data.postMessage(sendData);
	}
	mi_ticker_data.postMessage = function(data){
		document.getElementById('mi-ticker-script-iframe').contentWindow.postMessage(data, '*');
	}
}

if(typeof mi_btn_fade == "undefined"){
	mi_btn_fade				= {};
	mi_btn_fade.icon		= {};
	mi_btn_fade.icon.inInt	= '';
	mi_btn_fade.icon.outInt	= ''; 
	mi_btn_fade.chat		= {};
	mi_btn_fade.chat.inInt	= '';
	mi_btn_fade.chat.outInt	= '';
	mi_btn_fade.act = function(fade_in,fade_out) {
		icon = document.getElementById("mi-chat-icon-box");
		chat = document.getElementById("mi-chat-iframe-box");
		if (fade_in == 'icon'){
			mi_btn_fade.in(icon,5,fade_in);
			mi_btn_fade.out(chat,5,fade_out);
		}else{
			mi_btn_fade.in(chat,5,fade_in);
			mi_btn_fade.out(icon,5,fade_out);
		}
	}

	mi_btn_fade.in = function(obj,cnt,type) {
		clearInterval(mi_btn_fade[type].inInt);
		clearInterval(mi_btn_fade[type].outInt);
		var newValue = 0;
		obj.style.display = 'block';
		obj.style.opacity = 0;
		mi_btn_fade[type].inInt = setInterval(function(){ 
			if(newValue < 1){
				newValue += 0.01;
			} else if (newValue === 1) {
				clearInterval(mi_btn_fade[type].inInt);   
			}
			obj.style.opacity = newValue;
		}, cnt);
	}
	mi_btn_fade.out = function(obj , cnt , type) {
		clearInterval(mi_btn_fade[type].inInt);
		clearInterval(mi_btn_fade[type].outInt);
		var newValue = 1;
		obj.style.opacity = 1;
		mi_btn_fade[type].outInt = setInterval(function(){ 
			if (newValue > 0) {
				newValue -= 0.01;
			} else if (newValue < 0) {
				obj.style.opacity = 0;
				obj.style.display = 'none';
				clearInterval(mi_btn_fade[type].outInt);
			}
			obj.style.opacity = newValue;
		}, cnt);
	}
}

if(typeof mi_push_data == "undefined"){
	mi_push_data = {};
	mi_push_data.set = function(template_suid){
		if(typeof template_suid == "undefined"){
			template_suid = "";
		}
		var sendData = {}
		sendData.fn = 'init';
		sendData.mi_chat_return = mi_chat_return;
		sendData.mi_chat_return.adkey = mi_chat_adkey;
		sendData.mi_chat_return.template_suid = template_suid;
		if(document.getElementById('mi-push-iframe-box')){
			document.getElementById('mi-push-script-iframe').contentWindow.postMessage(JSON.stringify(sendData), '*' );	
		}
	}

	mi_push_data.display = function(contentHeight,type,position){
		if(type == "tbbar"){
			document.getElementById('mi-push-iframe-box').style.setProperty("height", "50px");
			document.getElementById('mi-push-iframe-box').style.setProperty("width", "100%", "important");
			document.getElementById('mi-push-iframe-box').style.setProperty("max-width", "100%");
			document.getElementById('mi-push-iframe-box').style.setProperty("right", "0px", "important");
			document.getElementById('mi-push-iframe-box').style.setProperty("max-width", "unset", "important")
			if(position == "top"){
				document.getElementById('mi-push-iframe-box').style.setProperty("left", "0px", "important");
				document.getElementById('mi-push-iframe-box').style.setProperty("transform", "unset", "important");
				document.getElementById('mi-push-iframe-box').style.setProperty("margin-top", "-50px");
				document.getElementById('mi-push-iframe-box').style.setProperty("top", "0px", "important")
				document.getElementById('mi-push-iframe-box').style.setProperty("bottom", "unset", "important")
				document.getElementById('mi-push-iframe-box').style.setProperty('position','static','important');
				setTimeout(function(){
					document.getElementById('mi-push-iframe-box').style.setProperty("margin-top", "0px");
					document.getElementById('mi-push-iframe-box').style.setProperty("transition", "0.5s");
				}, 100);
			}else{
				document.getElementById('mi-push-iframe-box').style.setProperty("bottom", "0px", "important")
				document.getElementById('mi-push-iframe-box').style.setProperty("top", "unset", "important")
			}
		}else if(type == "round"){
			if(position == "top"){
				document.getElementById('mi-push-iframe-box').style.setProperty("top", "20px", "important")
				document.getElementById('mi-push-iframe-box').style.setProperty("bottom", "unset", "important")
			}
		}else if(type == "alert"){
			document.getElementById('mi-push-iframe-box').style.setProperty("left", "50%", "important");
			document.getElementById('mi-push-iframe-box').style.setProperty("top", "50%", "important");
			document.getElementById('mi-push-iframe-box').style.setProperty("bottom", "unset", "important");
			document.getElementById('mi-push-iframe-box').style.setProperty("right", "unset", "important");
			if(window.innerWidth >= 480){
				document.getElementById('mi-push-iframe-box').style.setProperty("transform", "translate(-50%,-50%)", "important");
			}else{
				document.getElementById('mi-push-iframe-box').style.setProperty("transform", "translate(-50%, -50%) scale(0.8)", "important");
			}
		}else if(type == "halfmoon"){
			document.getElementById('mi-push-iframe-box').style.setProperty("bottom", "0px", "important")
			document.getElementById('mi-push-iframe-box').style.setProperty("top", "auto", "important")
		}
		document.getElementById('mi-push-script-iframe').style.setProperty("height",contentHeight+"px")
		document.getElementById('mi-push-script-iframe').style.display	= "block";
		document.getElementById('mi-push-iframe-box').style.setProperty("z-index", "1000000000", "important")
		document.getElementById('mi-push-iframe-box').style.opacity = "1";
	}
	
	mi_push_data.display_height = function(contentHeight){
		document.getElementById('mi-push-script-iframe').style.setProperty("height",contentHeight+"px");
	}

	mi_push_data.close = function(){
		document.getElementById('mi-push-iframe-box').style.setProperty("z-index", "-1", "important");
		document.getElementById('mi-push-script-iframe').style.display	= "none";
		document.getElementById('mi-push-iframe-box').remove();

	}
	mi_push_data.fadein = function(el, time) {
		el.style.opacity = 0;
		var last = +new Date();
		var tick = function() {
			el.style.opacity = +el.style.opacity + (new Date() - last) / time;
			last = +new Date();
			if (+el.style.opacity < 1) {
				(window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16);
			}
		}
		tick();
	}
}

if(typeof miIconActivity == "undefined"){
	var miIconActivity = {};
	miIconActivity.messageCount = 0;
	miIconActivity.iconActivityCntID = 'miActivityCnt_';
	miIconActivity.iconActivityMsgID = 'miActivityMsg_';
	miIconActivity.device	= 'P';
	miIconActivity.agent = navigator.userAgent;
	miIconActivity.domain = "";
	miIconActivity.icon_size = "";

	if (miIconActivity.agent.match(/iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson/i) != null || miIconActivity.agent.match(/LG|SAMSUNG|Samsung/) != null){
		miIconActivity.device = 'M';
	}
	miIconActivity.init = function(){
		miIconActivity.domain = unescape(document.location.href);
		var mi_talk_returnd = mi_cookie_data.getCookie('mi_talk_returnd'+mi_chat_return.visit_id);
		if(mi_talk_returnd == ""){
			mi_talk_returnd = "0"
		}else{
			mi_talk_returnd = mi_talk_returnd;
		}
		miIconActivity.messageCount = Number(mi_talk_returnd);

		if(miIconActivity.device == "P"){
			miIconActivity.icon_size = mi_chat_return.counsel.design.icon_size_pc;
		}else{
			miIconActivity.icon_size = mi_chat_return.counsel.design.icon_size_m;
		}
		
		if(miIconActivity.messageCount > 0){
			miIconActivity.iconActivityCnt();
		}

		var data = { visit_id:mi_chat_return.visit_id,user:'user' };
		var sendData = JSON.stringify({fn:'iconConnect' , 'data' :data});
		document.getElementById('mi-chat-script-iframe').contentWindow.postMessage(sendData, '*');
	}
	miIconActivity.returnd = function(visit_id,say,user,account_name,writer_nick,writer_pic){
		if(say=='') return;
		miIconActivity.messageCount = Number(miIconActivity.messageCount + 1); 
		mi_cookie_data.setCookie("mi_talk_returnd"+visit_id, miIconActivity.messageCount, 365,"",miIconActivity.domain, "");
		if(document.getElementById("mi-chat-iframe-box").style.display=='block'){
			return;
		}

		$("#"+miIconActivity.iconActivityMsgID).hide();		
		miIconActivity.iconActivityCnt();

		var today	= new Date();   
		var year	= today.getFullYear();		// 년도
		var month	= today.getMonth() + 1;		// 월
		var date	= today.getDate();			// 날짜
		var day		= today.getDay();			// 요일
		var hours	= today.getHours();			// 시
		var minutes = today.getMinutes();		// 분
		var seconds = today.getSeconds();		// 초
		var writeDate = year+'.'+month+'.'+date+' '+hours+':'+minutes;

		var messageBox = '<div style="display:inline-block; width:30px; height:30px; vertical-align:middle; border-radius:50% !important;"><img style="width:100%" src="'+mi_url.mitalk+writer_pic+'" onerror=\'this.src="'+mi_url.mitalk+'/assets/img/user/user-13.jpg"\'></div>';
		messageBox+='<div style="font-size:13px; font-weight:bold; display:inline-block; vertical-align:middle; margin-left:10px;">'+writer_nick+'</div>';
		messageBox+='<div style="margin-top:10px;font-size: 13px; line-height: 16px; max-height: 16px; overflow: hidden; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">'+say+'</div>';
		messageBox+='<div style="font-size:13px;float:right;margin-top:10px;">'+writeDate+'</div>';
		
		if(miIconActivity.device=='P'){
			document.getElementById(miIconActivity.iconActivityMsgID).innerHTML = messageBox;		
		}
		
		$("#"+miIconActivity.iconActivityMsgID).fadeIn('slow');
	}

	miIconActivity.iconActivityCnt = function(){
		var michatEl = document.getElementById('mi-chat-icon-box');
		miIconActivity.iconActivityCntEl = document.createElement('div');
		miIconActivity.iconActivityCntEl.setAttribute('id',miIconActivity.iconActivityCntID); 
		if(miIconActivity.device=='P'){
			if(mi_chat_return.icon.p == "3"){
				miIconActivity.iconActivityCntEl.setAttribute('style',"left: "+mi_chat_return.icon.x+"px; line-height:20px; height:20px;width:20px; bottom: "+(Number(mi_chat_return.icon.y) + Number(miIconActivity.icon_size) - 15)+"px; background-color: rgb(244, 67, 54); color: white; font-weight:bold; position: fixed !important ;display:block; border-radius:20px !important;z-index:99999999999 !important;text-align:center"); 
			}else{
				miIconActivity.iconActivityCntEl.setAttribute('style',"right: "+mi_chat_return.icon.x+"px; line-height:20px; height:20px;width:20px; bottom: "+(Number(mi_chat_return.icon.y) + Number(miIconActivity.icon_size) - 15)+"px; background-color: rgb(244, 67, 54); color: white; font-weight:bold; position: fixed !important ;display:block; border-radius:20px !important;z-index:99999999999 !important;text-align:center"); 
			}
		}else{
			if(mi_chat_return.icon.p == "3"){
				miIconActivity.iconActivityCntEl.setAttribute('style',"left: "+mi_chat_return.icon.x+"px; height:20px; line-height:20px; width:20px; bottom: 7.5%; padding: 3px; background-color: rgb(244, 67, 54); color: white; font-weight:bold; margin-bottom: 15px; position: fixed !important ;display:block; border-radius:20px !important;z-index:99999999999 !important;text-align:center");
			}else{
				miIconActivity.iconActivityCntEl.setAttribute('style',"right: "+mi_chat_return.icon.x+"px; height:20px; line-height:20px; width:20px; bottom: 7.5%; padding: 3px; background-color: rgb(244, 67, 54); color: white; font-weight:bold; margin-bottom: 15px; position: fixed !important ;display:block; border-radius:20px !important;z-index:99999999999 !important;text-align:center"); 
			} 
		}
		if(!document.getElementById(miIconActivity.iconActivityCntID)) michatEl.parentNode.insertBefore(miIconActivity.iconActivityCntEl,michatEl);
		
		if(miIconActivity.device=='P'){
			miIconActivity.iconActivityMsgEl = document.createElement('div');
			miIconActivity.iconActivityMsgEl.setAttribute('id',miIconActivity.iconActivityMsgID); 

			if(mi_chat_return.icon.p == "3"){
				miIconActivity.iconActivityMsgEl.setAttribute('style',"left: "+mi_chat_return.icon.x+"px; bottom: "+ (Number(mi_chat_return.icon.y) + Number(miIconActivity.icon_size)) +"px; padding: 12px; background-color: #ffffff;color: black; margin-bottom: 15px; position: fixed !important; min-width:200px;max-width:200px; word-break:break-all; display:none; border-radius:10px;height:auto; box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -webkit-box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -moz-box-shadow : 0 0px 10px 0 rgba(0,0,0,.8); cursor:pointer;");
			}else{
				miIconActivity.iconActivityMsgEl.setAttribute('style',"right: "+mi_chat_return.icon.x+"px; bottom: "+ (Number(mi_chat_return.icon.y) + Number(miIconActivity.icon_size)) +"px; padding: 12px; background-color: #ffffff;color: black; margin-bottom: 15px; position: fixed !important; min-width:200px;max-width:200px; word-break:break-all; display:none; border-radius:10px;height:auto; box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -webkit-box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -moz-box-shadow : 0 0px 10px 0 rgba(0,0,0,.8); cursor:pointer;");
			} 

			miIconActivity.iconActivityMsgEl.setAttribute('onclick','miIconActivity.chatOpen()');		
			if(!document.getElementById(miIconActivity.iconActivityMsgID)) michatEl.parentNode.insertBefore(miIconActivity.iconActivityMsgEl,michatEl);
		}
		document.getElementById(miIconActivity.iconActivityCntID).innerHTML = miIconActivity.messageCount;
		if(document.getElementById(miIconActivity.iconActivityCntID)){
			document.getElementById(miIconActivity.iconActivityCntID).style.display = 'block';
		}
	}
	miIconActivity.chatOpen = function(){
		mi_chat_handledre.click();
		var sendData = JSON.stringify({fn:'btn_mirae' , 'data' :{}});
		document.getElementById('mi-chat-script-iframe').contentWindow.postMessage(sendData, '*');
	}
	miIconActivity.chatRead = function(isRead){
		if(isRead){
			miIconActivity.messageCount = 0;
			mi_cookie_data.setCookie("mi_talk_returnd"+mi_chat_return.visit_id, 0, 365,"",miIconActivity.domain, "");
			if(document.getElementById(miIconActivity.iconActivityCntID)){
				document.getElementById(miIconActivity.iconActivityCntID).style.display = 'none';
			}
			if(document.getElementById(miIconActivity.iconActivityMsgID)){
				document.getElementById(miIconActivity.iconActivityMsgID).style.display = 'none';
			}
		}else{
			if(document.getElementById(miIconActivity.iconActivityCntID)){
				document.getElementById(miIconActivity.iconActivityCntID).style.display = 'block';
			}
		}
	}
}

(function(){
	var mi_domain = unescape(document.location.href);

	var mi_chat_vi = mi_cookie_data.getCookie('mi_chat_vi');
	var mi_chat_vc = mi_cookie_data.getCookie('mi_chat_vc');

	// 봇 유입 체크
	var bot_type = mi_cookie_data.getCookie('_mi_bot_type');
	var bot_id = mi_cookie_data.getCookie('_mi_bot_id');
	var bot_click = 0;

	if(typeof getParameters('_mi_bot_type') !== 'undefined'){
		if(getParameters('_mi_bot_type') != ''){
			bot_type = getParameters('_mi_bot_type');
			mi_cookie_data.setCookieOneTime ("_mi_bot_type", bot_type, mi_domain);
			bot_click = 1;
		}
	}

	if(typeof getParameters('_mi_bot_id') !== 'undefined'){
		if(getParameters('_mi_bot_id') != ''){
			bot_id = getParameters('_mi_bot_id');
			mi_cookie_data.setCookieOneTime ("_mi_bot_id", bot_id, mi_domain);
		}
	}


	// 미톡 활성화 상태 값 
	if (mi_cookie_data.getCookie('_mi_board_statue') == '' ) mi_cookie_data.setCookieOneTime ("_mi_board_statue", 0 , mi_domain);

	// 미톡 다이렉트 유입 체크
	var _mi_dt_vi = typeof getParameters('_mi_dt_vi') !== 'undefined' ? getParameters('_mi_dt_vi') : '';

	var config = {};
	var mi_url  = {};
	mi_url.icon = {};
	mi_url.l4				= mi_cfg.url.l4;
	mi_url.mitalk			= mi_cfg.url.mitalk;
	mi_url.log				= mi_cfg.url.mitalk_log;
	mi_url.sms				= mi_cfg.url.map+"/sms/sms_bot/new_sms_[type]_v2.php?bi=[bi]&bip=[bip]&bl=[bl]&adkey=[adkey]&agent=[agent]&place_text=[place_text]";
	mi_url.response			= "//log1.toup.net/"+mi_cfg.url.response;
	mi_url.icon.default		= mi_url.mitalk+"/mir_mt/img/ico_talk01.png";
	mi_url.chat				= mi_url.mitalk+"/chatClient_v2";
	mi_url.push				= mi_url.mitalk+"/miraepushWindow";
	mi_url.ticker			= mi_url.mitalk+"/miraeTicker";
	mi_url.ticker_			= mi_url.mitalk+"/ticker";

	var icon  = {};
	var divs  = {};
	divs.chat = "mi_chat_box";
	divs.sms  = "mi_sms_box";

	function mi_init_chat(){
		config = mi_chat_return;
		operation_chk = mi_chat_msg.getChatTitle();
		if((config.counsel.real_sms_operation == "B" && !mi_chat_msg.sms_time_flag) || (config.counsel.real_sms_operation == "C" && mi_chat_msg.sms_time_flag)){
			delete config.btn_list.sms;
		}
		if(mi_object_cnt(config.log_data)){ 
			ctL();
		}
		if(mi_object_cnt(config.btn_list)){
			ctC(); // cookie
			ctS(); // style
			ctI(); // miraetalk
			ctT(); // ticker
			ctN(); // nudge
		}
		if ( typeof config.sms === "object" && mi_object_cnt(config.sms)){
			//sms 운영시간 체크
			if(config.counsel.real_sms_operation == "A"){
				ctSms();
			}else{
				if(config.counsel.real_sms_operation == "B" && mi_chat_msg.sms_time_flag){
					ctSms();
				}else if(config.counsel.real_sms_operation == "C" && !mi_chat_msg.sms_time_flag){
					ctSms();
				}
			}
		}
	}

	// 카페24 수집로그
	function set_cafe24_track(){
		if(typeof CAFE24API!=='undefined' && typeof CAFE24API.init == "function"){
			CAFE24API.init('aVyHsP06IpeSfB7DtOSqfA'); //App Key
			let url = [];
			let mall_id = CAFE24API.MALL_ID;
			let shop_no = CAFE24API.SHOP_NO;
			let order_data = '';
			let cafe24_api = {
				'save':function(){
					$.get('https://log1.toup.net/mirae_response_cafe24_app_check.php?url=https://'+mall_id+'.cafe24api.com/api/v2/products?cafe24_app_key=aVyHsP06IpeSfB7DtOSqfA',function(res){
						let app_check = JSON.parse(res);
						//console.log(app_check);
						if(typeof app_check.error == 'undefined'){ // 에러가 없을경우 내부 앱설치건으로 간주함
							
							function cookie_set_minutes(name,value,minutes){
								if (minutes) {
									var date = new Date();
									date.setTime(date.getTime()+(minutes*60*1000));
									var expires = "; expires="+date.toGMTString();
								} else {
									var expires = "";
								}
								document.cookie = name+"="+value+expires+"; path=/";
							}
							
							function cookie_get_minutes(name){
								var cookieValue=null;
								if(document.cookie){
									var array=document.cookie.split((escape(name)+'='));
									if(array.length >= 2){
										var arraySub=array[1].split(';');
										cookieValue=unescape(arraySub[0]);
									}
								}
								return cookieValue;
							}

							// 태그 제거
							function cafe24_tag_remove(str){
								str = str.replace(/(<([^>]+)>)/ig,"");
								//str = str.replace("#","");
								str = str.replace(/\"/gi, "");
								str = str.replace(/\'/gi, "");
								return str;
							}

							if(typeof CAFE24.FRONT_EXTERNAL_SCRIPT_VARIABLE_DATA!=='undefined'){
								order_data = CAFE24.FRONT_EXTERNAL_SCRIPT_VARIABLE_DATA;
							}
							
							let ck_cart = cookie_get_minutes('ck_cart');
							let ck_view = cookie_get_minutes('ck_view');
							let ck_product = cookie_get_minutes('ck_product');
							let ck_order = cookie_get_minutes('ck_order');
							
							// 장바구니 리스트
							//if(ck_cart == null){ // 분단위 유효쿠키 텀을줌 지속 호출 방지하기 위함
							if( 1 ){ // 매 페이지 이동시 장바구니 리스트 호출
								CAFE24API.getCartList(function(err, res) {
									if(err){
										//console.log('set_cafe24_track cart_list err ',err);
									}else{
										//console.log('set_cafe24_track cart_list res ',res);
										url = [];
										for(var i=0;i<res.carts.length;i++){
											url.push('cart[]='+JSON.stringify({
																				'adkey':mi_chat_adkey,
																				'mall_id':mall_id,
																				'shop_no':shop_no,
																				'additional_option':res.carts[i].additional_option,
																				'attached_file_option':res.carts[i].attached_file_option,
																				'basket_product_no':res.carts[i].basket_product_no,
																				'delvtype':res.carts[i].delvtype,
																				'is_set_product':res.carts[i].is_set_product,
																				'option_id':res.carts[i].option_id,
																				'product_no':res.carts[i].product_no,
																				'product_price':Math.floor(res.carts[i].product_price),
																				'quantity':res.carts[i].quantity,
																				'selected_product':res.carts[i].selected_product,
																				'set_product_no':res.carts[i].set_product_no,
																				'variant_code':res.carts[i].variant_code,
																				'type':'cart'
																			}));
					
										}
										if(url.length){
											url.push('type=cart');
											$.get('//log1.toup.net/mirae_response_cafe24.php?'+url.join('&'));			
										}
									}
									//cookie_set_minutes('ck_cart','1',1);
								});
							}
							
							// 상품 조회수 
							//if(ck_view == null){ // 분단위 유효쿠키 텀을줌 지속 호출 방지하기 위함
							if( 1 ){ // 뷰 페이지 오면 무조건 호출
								if(typeof iProductNo!=='undefined'){
									CAFE24API.get('/api/v2/products/'+iProductNo+'/hits/count', function (err, res) {
										if(err){
											//console.log('set_cafe24_track product_count err ',err);
										}else{
											//console.log('set_cafe24_track product_count res ',res);
											$.get('//log1.toup.net/mirae_response_cafe24.php?view='+JSON.stringify({'adkey':mi_chat_adkey,'mall_id':mall_id,'shop_no':shop_no,'product_no':iProductNo,'hit':res.count,'type':'view'})+'&type=view');			
										}
										//cookie_set_minutes('ck_view','1',5);
										// 상품정보 수집
										getProducts(iProductNo);
									});
								}
							}

							// 상품 리스트 
							if(ck_product == null){ // 분단위 유효쿠키 텀을줌 지속 호출 방지하기 위함 
								// 상품 리스트 수집 미실행 처리 
								//getProducts();
								//cookie_set_minutes('ck_product','1',1440);
							}

							// 주문완료
							if(ck_order == null){ // 분단위 유효쿠키 텀을줌 지속 호출 방지하기 위함
								if(typeof order_data.order_id!=='undefined'){
									//console.log('set_cafe24_track order res ',order_data);
									url = [];
									for(var i=0;i<order_data.order_product.length;i++){
										url.push('order[]='+JSON.stringify({
											'adkey':mi_chat_adkey,
											'mall_id':mall_id,
											'shop_no':shop_no,
											'category_name_1':order_data.order_product[i].category_name_1,
											'category_no_1':order_data.order_product[i].category_no_1,
											'product_code':order_data.order_product[i].product_code,
											'product_name':encodeURIComponent(cafe24_tag_remove(order_data.order_product[i].product_name)),
											'product_no':order_data.order_product[i].product_no,
											'product_price':order_data.order_product[i].product_price,
											'quantity':order_data.order_product[i].quantity,
											'sub_total_price':order_data.order_product[i].sub_total_price,
											'sum_total_opt_price':order_data.order_product[i].sum_total_opt_price,
											'order_id':order_data.order_id,
											'type':'order'
										}));
									}
									if(url.length){
										url.push('type=order');
										$.get('//log1.toup.net/mirae_response_cafe24.php?'+url.join('&'));			
										//cookie_set_minutes('ck_order','1',1);
									}
								}
							}

							function getProducts(productNo){
								var u = '/api/v2/products';
								var is_product = false;
								if( typeof productNo !== 'undefined' ){
									is_product = true;
									u += '/' + productNo;
								}

								CAFE24API.get(u,function(err,res){
									if(err){
										//console.log('set_cafe24_track product_list err ',err);
									}else{
										//console.log('set_cafe24_track product_list res ',res);
										var response = {};
										if ( is_product ){
											var temp_res = res;
											res = {};
											res.products = [];
											res.products[0] =temp_res.product;
										}


										url = [];
										for(var i=0;i<res.products.length;i++){
											// get 배열에 json 문자열로 담는다
											var img_src = "";
											if( res.products[i].list_image != "null" && res.products[i].list_image != null ){
												img_src = res.products[i].list_image ;
											} else if( res.products[i].tiny_image != "null" && res.products[i].tiny_image != null ){
												img_src = res.products[i].tiny_image ;
											} else if( res.products[i].small_image != "null" && res.products[i].small_image != null ){
												img_src = res.products[i].small_image ;
											} else if( res.products[i].detail_image != "null" && res.products[i].detail_image != null ){
												img_src = res.products[i].detail_image ;
											} else {
												img_src = "//img.echosting.cafe24.com/thumb/img_product_big.gif";
											}

											url.push('products[]='+JSON.stringify({
												'adkey':mi_chat_adkey,
												'mall_id':mall_id,
												'shop_no':shop_no,
												'product_no':res.products[i].product_no,
												'name':encodeURIComponent(cafe24_tag_remove(res.products[i].product_name)),
												'price':Math.floor(res.products[i].price),
												'img_src':img_src , 
												'img_link':encodeURIComponent('https://'+mall_id+'.cafe24.com/product/detail.html?product_no='+res.products[i].product_no),
												'type':'product'
											}));

											$.get('//log1.toup.net/mirae_response_cafe24.php?'+url.join('&'));			
											url = [];
										}
									}
									return 1;
								});
							}
						} // app_check
					}); // ajax app_check 
				} // save
			} // cafe24_api
			cafe24_api.save();
		} // CAFE24API undefined 
	} // set_cafe24_track

	function mi_init_act(){
		set_cafe24_user();
		set_cafe24_track();
		mi_dt=new Date(),mi_y=mi_dt.getFullYear(),mi_m=mi_dt.getMonth()+1,mi_d=mi_dt.getDate(),mi_h=mi_dt.getHours();
		mi_date=""+mi_y+(mi_m<=9?"0":"")+mi_m+(mi_d<=9?"0":"")+mi_d+(mi_h<=9?"0":"")+mi_h;
		if(mi_cfg.load.log_use_yn == 'Y' && mi_cfg.use.analysis){
			insert_before({src:mi_url.l4+'/_mirae_log.js?t='+mi_date,callback:mi_init_script});
		}else{
			mi_init_script();
		}
	}

	function mi_init_script(){
		var conv = {
			mi_type			: typeof mi_type		!='undefined' ? mi_type			:'',
			mi_val			: typeof mi_val			!='undefined' ? mi_val			:'',
			mi_order_num	: typeof mi_order_num	!='undefined' ? mi_order_num	:'',
			mi_p			: typeof mi_p			!='undefined' ? mi_p			:''
		};
		var arr					= [];
		var conv_data			= null;
		var url					= null;
		arr.push("?k="			+ mi_chat_adkey);
		arr.push("&url="		+ getLocation());
		arr.push("&mi_wm="		+ getDevice());
		arr.push("&mi_chat_vi="	+ mi_chat_vi);
		arr.push("&mi_chat_vc="	+ mi_chat_vc);
		arr.push("&agent="		+ fn_mi_brtype());
		arr.push("&bot_type="	+ bot_type);
		arr.push("&bot_id="		+ bot_id);
		arr.push("&bot_click="	+ bot_click);
		arr.push('&ticker_id='	+ mi_ticker.id);
		arr.push("&dt_vi="		+ _mi_dt_vi);
		if(typeof mi_get_param == 'function'){
			conv_data = mi_get_param.apply(conv);
			arr.push(param_to_query.apply({prefix:'&'},[conv_data]));
		}
		arr.push(getUserInfo());
		arr.push(getConvString());
		arr.push(getSmsPageView());
		url = arr.join("");
		mi_res_qstr = url;
		insert_before({src:mi_url.response+url,callback:function(){ 
			// 티커 사용여부 체크 
			if(typeof mi_ticker_return !=='undefined' && mi_ticker_return.use_yn == 'Y' && mi_cfg.use.analysis && typeof mi_log_return !=='undefined'){
				var pos_arr = [
								'mi_ticker_pos_bottom_left','mi_ticker_pos_bottom_center','mi_ticker_pos_bottom_right',
								'mi_ticker_pos_middle_left','mi_ticker_pos_middle_center','mi_ticker_pos_middle_right',
								'mi_ticker_pos_top_left','mi_ticker_pos_top_center','mi_ticker_pos_top_right',
								'mi_ticker_wrap'
							  ];
				
				var ticker_wrap = null;
				for(var i=0 ;i<pos_arr.length;i++){
					var div = document.createElement('div');
					div.id = pos_arr[i];
					document.body.appendChild(div);
					ticker_wrap = document.getElementById(pos_arr[i]);
					ticker_wrap.style.position	= 'fixed';
					ticker_wrap.style.zIndex	= '-1';
					ticker_wrap.style.maxWidth	= '400px';
					ticker_wrap.style.width		= '100%';
					ticker_wrap.style.height	= 'auto';

					switch(pos_arr[i]){
						case 'mi_ticker_pos_bottom_right':
							ticker_wrap.style.right = '1%';
							ticker_wrap.style.bottom = '10px';

						break;
						case 'mi_ticker_pos_bottom_left':
							ticker_wrap.style.left = '1%';
							ticker_wrap.style.bottom = '10px';
						break;
						case 'mi_ticker_pos_bottom_center':
							ticker_wrap.style.left = '40%';
							ticker_wrap.style.bottom = '10px';
						break;
						case 'mi_ticker_pos_middle_left':
							ticker_wrap.style.left = '1%';
							ticker_wrap.style.top = '45%';
						break;
						case 'mi_ticker_pos_middle_center':
							ticker_wrap.style.left = '40%';
							ticker_wrap.style.top = '45%';
						break;
						case 'mi_ticker_pos_middle_right':
							ticker_wrap.style.right = '1%';
							ticker_wrap.style.top = '45%';
						break;
						case 'mi_ticker_pos_top_left':
							ticker_wrap.style.left = '1%';
							ticker_wrap.style.top = '1%';
						break;
						case 'mi_ticker_pos_top_center':
							ticker_wrap.style.left = '40%';
							ticker_wrap.style.top = '1%';
						break;
						case 'mi_ticker_pos_top_right':
							ticker_wrap.style.right = '1%';
							ticker_wrap.style.top = '1%';
						break;
						case 'mi_ticker_wrap':
							ticker_wrap.style.height = '0px';
							ticker_wrap.style.width = '0px';
							ticker_wrap.style.maxWidth = null;
						break;
					}
				}

				var mi_ticker_wrap = document.getElementById('mi_ticker_wrap');
				var mi_ticker_iframe_wrap = document.createElement('div');
				mi_ticker_iframe_wrap.id = 'mi_ticker_iframe_wrap';
				
				var mi_ticker_iframe = document.createElement('iframe');
				mi_ticker_iframe.id = 'mi_ticker_iframe';
				mi_ticker_iframe.src = mi_url.ticker_+"?adkey="+mi_chat_adkey;
				mi_ticker_iframe.scrolling = 'no';
				mi_ticker_iframe.style.border = '0';
				mi_ticker_iframe.style.width = '0px';
				
				mi_ticker_iframe_wrap.append(mi_ticker_iframe);
				mi_ticker_wrap.append(mi_ticker_iframe_wrap);
			}

			if(mi_cfg.use.analysis && typeof mi_log_return !=='undefined'){
                var makeData = [];
				makeData = mi_log_return.makeData.split('\t');
				if(makeData[2] == "1"){
					_mi_cookie_val = JSON.stringify({m_type:makeData[15],m_detail:makeData[16],keyword:makeData[17],keyword_type:makeData[18]});
					var mi_domain = unescape(document.location.href);
					mi_cookie_data.setCookie("mi_flow_data", _mi_cookie_val, 1,"",mi_domain, "");
				}
				Object.assign(mi_log_return, { 
					mi_adkey	: typeof mi_chat_adkey				!= 'undefined'? mi_chat_adkey			: '',
					mi_p_res	: typeof conv_data.mi_p_res			!= 'undefined'? conv_data.mi_p_res		: '',
					mi_type_res : typeof conv_data.mi_type			!= 'undefined'? conv_data.mi_type		: '',
					mi_order_num: typeof conv_data.mi_order_num		!= 'undefined'? conv_data.mi_order_num	: '',
					o_mi_vc		: typeof conv_data.mi_log_vc		!= 'undefined'? conv_data.mi_log_vc		: '',
					o_mi_vi		: typeof conv_data.mi_log_vi		!= 'undefined'? conv_data.mi_log_vi		: '',
					d_mi_vi		: mi_log_return.mi_log_vi,
					d_mi_vc		: mi_log_return.mi_log_vc
				});
				mi_set_conv(mi_log_return);
				if(mi_cfg.use.click && mi_log_return.defender_popup_use == 'Y'){
					var defender_popup_flag = true;
					if(typeof mi_log_return.except_popup_ip !='undefined' && mi_log_return.except_popup_ip !=''){
						var except_ips = mi_log_return.except_popup_ip.split(',');
						if(except_ips.includes(mi_log_return.mi_ip)){
							defender_popup_flag = false;
						}
					}

					if(typeof mi_log_return.except_popup_keyword !='undefined' && mi_log_return.except_popup_keyword !=''){
						var except_keywords = mi_log_return.except_popup_keyword.split(',');
						if(except_keywords.includes(mi_log_return.keyword)){
							defender_popup_flag = false;
						}
					}
					
					if(defender_popup_flag == true){
						mi_click_popup.popchk(
							  makeData
							, mi_log_return.defender_popup_count
							, mi_log_return.defender_popup_type
							, mi_log_return.defender_custom_type
							, mi_log_return.defender_bg_color
							, mi_log_return.defender_strong_text
							, mi_log_return.defender_basic_text
							, mi_log_return.defender_strong_color
							, mi_log_return.defender_basic_color
							, mi_log_return.defender_ud_position
							, mi_log_return.defender_lr_position
						);
					}
				}
			}
			if(typeof mi_chat_return !=='undefined'){
				var client_page = null;
				var hidden_page = null;
				var check_page = false;
				if(typeof mi_chat_return.hidden_page!=='undefined' && mi_chat_return.hidden_page!=''){
					hidden_page = mi_chat_return.hidden_page.split(',');
					client_page = document.location.href;
					for(var i in hidden_page){
						if(client_page.indexOf(hidden_page[i]) !==-1){
							check_page =true;
							break;
						}
					}
				}
				if(!check_page){
					mi_init_chat();
				}
			}
			return;		
		}});
	}

	function ctIS(){
		var temp = [];
		temp.push("\n" + "#mi_chat_box { " );
		temp.push("\n" + "	display: block;" );
		temp.push("\n" + "}" );
		temp.push("\n" + "@media print { " );
		temp.push("\n" + "	#mi_chat_box { display: none; }" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-iframe-box {" );
		temp.push("\n" + "	display:none ; " );
		temp.push("\n" + "	width: 360px !important; " );
		temp.push("\n" + "	min-height: 660px !important;" );
		temp.push("\n" + "	max-height: 660px !important;" );
		temp.push("\n" + "	height: 80% !important;" );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	background-color: transparent !important;" );
		temp.push("\n" + "	z-index: 10000000000 !important;" );
		temp.push("\n" + "	overflow: hidden !important; " );
		temp.push("\n" + "	font-family: !important; " );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-iframe-box-mobile { " );
		temp.push("\n" + "	display: none;" );
		temp.push("\n" + "	width: 100% !important; " );
		temp.push("\n" + "	height: 100% !important; " );
		temp.push("\n" + "	position: fixed !important; " );
		temp.push("\n" + "	top: 0 !important; " );
		temp.push("\n" + "	left: 0 !important; " );
		temp.push("\n" + "	bottom: 0 !important; " );
		temp.push("\n" + "	right: 0 !important; " );
		temp.push("\n" + "	z-index: 10000000000 !important; " );
		temp.push("\n" + "	-webkit-overflow-scrolling: touch !important; " );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-mobile { " );
		temp.push("\n" + "	width: 100% !important; " );
		temp.push("\n" + "	height: 100% !important; " );
		temp.push("\n" + "	position: fixed !important; " );
		temp.push("\n" + "	overflow: hidden !important" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-icon-box {" );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	display: none ; " );
		temp.push("\n" + "	overflow: initial !important;" );
		temp.push("\n" + "	z-index: 999999999 !important;" );
		temp.push("\n" + "	flex-wrap: nowrap !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi_icon_text_box_1234 .emoji {" );
		temp.push("\n" + "	width:16px;" );
		temp.push("\n" + "	vertical-align:middle;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-icon-pixel-box {" );
		temp.push("\n" + "	position: static !important;" );
		temp.push("\n" + "	display:none ;" );
		temp.push("\n" + "	z-index:9999999999;" );
		temp.push("\n" + "	clear:both !important;" );
		temp.push("\n" + "	line-height : unset !important;" );
		temp.push("\n" + "	letter-spacing : unset !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-chat-icon-pixel-print {" );
		temp.push("\n" + "	position: absolute !important;" );
		temp.push("\n" + "	top:-15px !important;" );
		temp.push("\n" + "	width: 100px !important;" );
		temp.push("\n" + "	text-align:center !important;" );
		temp.push("\n" + "	background-color:gray !important;" );
		temp.push("\n" + "	color:white !important;" );
		temp.push("\n" + "	font: 0.75em \"돋움\",Dotum,AppleGothic,sans-serif!important; " );
		temp.push("\n" + "	font-size:13px !important;" );
		temp.push("\n" + "	line-height : normal !important;" );
		temp.push("\n" + "	letter-spacing : unset !important;" );
		temp.push("\n" + "	clear:both !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".rightBottomPosition {" );
		temp.push("\n" + "	right:30px !important;" );
		temp.push("\n" + "	bottom:30px !important;" );
		temp.push("\n" + "}" );

		temp.push("\n" + ".rightTopPosition {" );
		temp.push("\n" + "	right:30px !important;" );
		temp.push("\n" + "	top:30px !important;" );
		temp.push("\n" + "}" );

		temp.push("\n" + ".leftTopPosition {" );
		temp.push("\n" + "	left:30px !important;" );
		temp.push("\n" + "	top:30px !important;" );
		temp.push("\n" + "}" );

		temp.push("\n" + ".leftBottomPosition {" );
		temp.push("\n" + "	right:30px !important;" );
		temp.push("\n" + "	bottom:30px !important;" );
		temp.push("\n" + "}" );


		//pushWindow 
		if ( getDevice() != 'M' ) {
		temp.push("\n" + ".mi-push-iframe-box {" );
		temp.push("\n" + "	display:block; " );
		temp.push("\n" + "	width: 100% !important; " );
		temp.push("\n" + "	max-width: 400px; " );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	background-color: transparent !important;" );
		temp.push("\n" + "	z-index: -1 !important;" );
		temp.push("\n" + "	overflow: hidden !important; " );
		temp.push("\n" + "	font-family: !important;" );
		temp.push("\n" + "	opacity: 0;" );
		temp.push("\n" + "}" );
		}
		if ( getDevice() == 'M' ) {
		temp.push("\n" + ".mi-push-iframe-box {" );
		temp.push("\n" + "	display:block; " );
		temp.push("\n" + "	width: 100% !important; " );
		temp.push("\n" + "	max-width: 400px; " );
		temp.push("\n" + "	position: fixed !important;");
		temp.push("\n" + "	background-color: transparent !important;" );
		temp.push("\n" + "	z-index: -1 !important;" );
		temp.push("\n" + "	overflow: hidden !important; " );
		temp.push("\n" + "	font-family: !important;" );
		temp.push("\n" + "	opacity: 0;" );
		temp.push("\n" + "}" );
		}

		if(config.icon.use == "Y"){
			if(window.innerWidth >= 480){
				icon_bottom = Number(config.icon.y) + Number(config.counsel.design.icon_size_pc) + 12;
			}else{
				icon_bottom = Number(config.icon.y) + Number(config.counsel.design.icon_size_m) + 12;
			}
		}else{
			icon_bottom = 40;
		}

		if(window.innerWidth >= 480){
			temp.push("\n" + ".push-position {" );
			if ( mi_chat_return.icon.p == "3" ){
				temp.push("\n" + "	left: 20px ; " );
			}else{
				temp.push("\n" + "	right: 20px ; " );
			}
			temp.push("\n" + "	bottom: "+icon_bottom+"px ;" );
			temp.push("\n" + "}" );
		}else{
			temp.push("\n" + ".push-position {" );
			temp.push("\n" + "	left: 50% ; " );
			temp.push("\n" + "	transform: translateX(-50%); " );
			temp.push("\n" + "	bottom: "+icon_bottom+"px ;" );
			temp.push("\n" + "}" );
		}

		//ticker
		if ( getDevice() != 'M' ) {
			temp.push("\n" + ".mi-ticker-iframe-box {" );
			temp.push("\n" + "	display:block; " );
			temp.push("\n" + "	width: 100% !important; " );
			temp.push("\n" + "	max-width: 370px; " );
			temp.push("\n" + "	position: fixed !important;" );
			temp.push("\n" + "	background-color: transparent !important;" );
			temp.push("\n" + "	z-index: -1 !important;" );
			temp.push("\n" + "	overflow: hidden !important; " );
			temp.push("\n" + "	font-family: !important;" );
			temp.push("\n" + "	opacity: 0;" );
			temp.push("\n" + "}" );
			temp.push("\n" + ".ticker-position {" );

			if ( mi_chat_return.icon.p == "3" ){
				temp.push("\n" + "	right: 30px ; " );
			}else{
				temp.push("\n" + "	left: 30px ; " );
			}
			temp.push("\n" + "	bottom: 30px ;" );
			temp.push("\n" + "}" );
		}else{
			temp.push("\n" + ".mi-ticker-iframe-box {" );
			temp.push("\n" + "	display:block; " );
			temp.push("\n" + "	width: 100% !important; " );
			temp.push("\n" + "	max-width: 400px; " );
			temp.push("\n" + "	position: fixed !important;");
			temp.push("\n" + "	background-color: transparent !important;" );
			temp.push("\n" + "	z-index: -1 !important;" );
			temp.push("\n" + "	overflow: hidden !important; " );
			temp.push("\n" + "	font-family: !important;" );
			temp.push("\n" + "	opacity: 0;" );
			temp.push("\n" + "}" );
			if(window.innerWidth >= 480){
				temp.push("\n" + ".ticker-position {" );
				if ( mi_chat_return.icon.p == "3" ){
					temp.push("\n" + "	right: 20px ; " );
				}else{
					temp.push("\n" + "	left: 20px ; " );
				}
				temp.push("\n" + "	top: 20px ;" );
				temp.push("\n" + "}" );
			}else{
				temp.push("\n" + ".ticker-position {" );
				temp.push("\n" + "	left: 50% ; " );
				temp.push("\n" + "	transform: translateX(-50%); " );
				temp.push("\n" + "	top: 20px ;" );
				temp.push("\n" + "}" );
			}
		}

		temp.push(getIconStyle());
		temp.push("\n" + " " );
		return temp;
	}

	function ctS (){
		var r = document.createElement("style");
		r.type = "text/css";
		r.setAttribute("private", "true");
		r.innerHTML = ctIS().join("");
		window.document.getElementsByTagName("head")[0].appendChild(r);
	}

	function ctI(){
		if (!document.getElementById(divs.chat)) {
			var node = document.createElement('div');
			node.id = divs.chat;
			document.body.appendChild(node);
		}
		var root = document.getElementById(divs.chat);


		var iframe_box = 'mi-chat-iframe-box mi-position';
		if ( getDevice() == 'M' ) {
			iframe_box = 'mi-chat-iframe-box-mobile';
		}

		mi_chat_handledre.device = getDevice();

		root.innerHTML = "<div id='mi-chat-iframe-box' class='"+iframe_box+" '><iframe id='mi-chat-script-iframe' src='"+mi_url.chat+"' style='position:relative!important;height:100%!important;width:100%!important;border:none!important;'></iframe></div>";
		var iframe = document.getElementById('mi-chat-script-iframe');
		mi_chat_handledre.talk_start = CtIcon;
	}

	function ctN(){
		var iframe_box = 'mi-push-iframe-box push-position';
		var html = "<div id='mi-push-iframe-box' class='"+iframe_box+" '><iframe id='mi-push-script-iframe' src='"+mi_url.push+"' style=' position:relative !important;width:100% !important;border:none !important;'></iframe></div>";
		appendHtml(document.getElementById(divs.chat), html);
		var mi_body_ele = document.querySelector('body');
		if(mi_body_ele == null){
			mi_body_ele = document.querySelector('head');
		}
		var mi_push_iframe_box = document.getElementById('mi-push-iframe-box');
		mi_body_ele.insertBefore(mi_push_iframe_box,mi_body_ele.childNodes[0]);
	}

	function ctT(){
		var iframe_box = 'mi-ticker-iframe-box ticker-position';
		var html = "<div id='mi-ticker-iframe-box' class='"+iframe_box+" '><iframe id='mi-ticker-script-iframe' src='"+mi_url.ticker+"' style=' position:relative !important;width:100% !important;border:none !important;'></iframe></div>";
		appendHtml(document.getElementById(divs.chat), html);
	}

	
	function appendHtml(el, str){
		var div = document.createElement('div');
		div.innerHTML = str;
		while (div.children.length > 0) {
			el.appendChild(div.children[0]);
		}
	}

	function ctL(){
		var ae = [];
		var l = config.log_data;
		for(var i in l){
			if ( typeof l[i] == 'object'){
				ae.push(i + "=" + encodeURIComponent(JSON.stringify(l[i])));
			}else{
				ae.push(i + "=" + encodeURIComponent(l[i]));
			}
		}
		var url = "?" + ae.join("&");
		insert_before({src:mi_url.log+url});
	}


	function CtIcon(){
		var mi_icon_box = "mi-chat-icon-box";
		if (!document.getElementById(mi_icon_box)) {
			var node = document.createElement('div');
			node.id = mi_icon_box;
			node.className = mi_icon_box + " mi-position ";
			document.getElementById(divs.chat).appendChild(node);
		}

		var ib = document.getElementById(mi_icon_box);
		var ib_pixel_box  = 'mi-chat-icon-pixel-box' , ib_pixel_print  = 'mi-chat-icon-pixel-print' ,ib_drag_box  = 'mi-chat-icon-drag-box' ;
		if (!document.getElementById(ib_pixel_box)) {
			var node = document.createElement('div');
			node.id = ib_pixel_box , node.className  = ib_pixel_box ;
			ib.appendChild(node);

			if (!document.getElementById(ib_pixel_print)) {
				var nodec = document.createElement('div');
				nodec.id = ib_pixel_print , nodec.className  = ib_pixel_print ;
				node.appendChild(nodec);
			}
			if (!document.getElementById(ib_drag_box)) {
				var nodec = document.createElement('div');
				nodec.id = ib_drag_box , nodec.className  = ib_drag_box + " mi-chat-icon-drag-box-p " ;
				node.appendChild(nodec);
			}
		}

		if(getDevice() == 'M'){
			icon.size = mi_chat_return.counsel.design.icon_size_m;
		}else{
			icon.size = mi_chat_return.counsel.design.icon_size_pc;
		}
		
		icon.fontsize = 14;
		icon.dw = 500;
		icon.sw = window.innerWidth;
		icon.rate = 1;
		icon.addHeight = 0;
		if ( getDevice() == 'M' && icon.dw < icon.sw ){
			icon.rate = (icon.sw / icon.dw).toFixed(2);
			icon.size = (icon.size * icon.rate).toFixed(2);
			icon.fontsize = (icon.fontsize * icon.rate).toFixed(2);
		}

		var anchor = document.createElement("div");
		
		anchor.setAttribute('onclick',"mi_chat_handledre.click()");
		anchor.setAttribute('href',"javascript:;");
		anchor.setAttribute('style',"position:relative;display:inline-block; cursor:pointer");
		anchor.setAttribute('id',mi_chat_return.visit_id);

		var icon_html = '<span id = "mouse_over_ictx" style="board:1px solid red;">';

		if(mi_chat_return.counsel.design.widget_icon != "direct"){
			if(mi_chat_return.icon.p == "4"){
				icon_html += '<div id = "mi_icon_over" style="z-index:9999; position:absolute; right:0px; top:0px; background:'+((mi_chat_return.counsel.design.theme_select == "direct") ? mi_chat_return.counsel.design.theme_color+";" : 'linear-gradient(0deg, rgb(110, 74, 197) 0%, rgb(222, 90, 215) 100%);')+' width:'+icon.size+'px; height:'+icon.size+'px; border-radius:50% !important; overflow:hidden;"><img style="width:100%" src="https://www.miraetalk.com/mir_mt/img/ico_talk0'+((mi_chat_return.counsel.design.widget_icon) ? mi_chat_return.counsel.design.widget_icon : "1")+'.png"></div>'
			}else{
				icon_html += '<div id = "mi_icon_over" style="z-index:9999; position:absolute; left:0px; top:0px; background:'+((mi_chat_return.counsel.design.theme_select == "direct") ? mi_chat_return.counsel.design.theme_color+";" : 'linear-gradient(0deg, rgb(110, 74, 197) 0%, rgb(222, 90, 215) 100%);')+' width:'+icon.size+'px; height:'+icon.size+'px; border-radius:50% !important; overflow:hidden;"><img style="width:100%" src="https://www.miraetalk.com/mir_mt/img/ico_talk0'+((mi_chat_return.counsel.design.widget_icon) ? mi_chat_return.counsel.design.widget_icon : "1")+'.png"></div>'
			}
		}else{
			if(mi_chat_return.icon.p == "4"){
				icon_html += '<div id = "mi_icon_over" style="z-index:9999; position:absolute; right:0px; top:0px; background:'+((mi_chat_return.counsel.design.theme_select == "direct") ? mi_chat_return.counsel.design.theme_color+";" : 'linear-gradient(0deg, rgb(110, 74, 197) 0%, rgb(222, 90, 215) 100%);')+' width:'+icon.size+'px; height:'+icon.size+'px; border-radius:50% !important; overflow:hidden;"><img style="width:100%" src="https://www.miraetalk.com'+((mi_chat_return.counsel.design.widget_icon_img) ? mi_chat_return.counsel.design.widget_icon_img : "mir_mt/img/ico_talk01.png")+'"></div>'
			}else{
				icon_html += '<div id = "mi_icon_over" style="z-index:9999; position:absolute; left:0px; top:0px; background:'+((mi_chat_return.counsel.design.theme_select == "direct") ? mi_chat_return.counsel.design.theme_color+";" : 'linear-gradient(0deg, rgb(110, 74, 197) 0%, rgb(222, 90, 215) 100%);')+' width:'+icon.size+'px; height:'+icon.size+'px; border-radius:50% !important; overflow:hidden;"><img style="width:100%" src="https://www.miraetalk.com'+((mi_chat_return.counsel.design.widget_icon_img) ? mi_chat_return.counsel.design.widget_icon_img : "mir_mt/img/ico_talk01.png")+'"></div>'
			}
		}

		if(mi_chat_return.counsel.design.widget_icon_text != "" && mi_chat_return.counsel.design.widget_icon_text != null){
			if(mi_chat_return.icon.p == "4"){
				icon_html += '<div id = "mouse_over_text" class="mi_icon_text_box_1234" style="color:#111; padding: 0px '+icon.size*1.3+'px 0px '+icon.size*0.7+'px; background:#fff; font-size:'+icon.fontsize+'px; height:'+icon.size+'px;line-height:'+icon.size+'px; border-radius:'+icon.size*0.5+'px !important; font-weight:bold; width:auto; box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -webkit-box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -moz-box-shadow : 0 0px 10px 0 rgba(0,0,0,.8);"><span id="icon_txt" style="line-height:'+icon.size+'px;">'+mi_chat_return.counsel.design.widget_icon_text+'</span></div>'
			}else{
				icon_html += '<div id = "mouse_over_text" class="mi_icon_text_box_1234" style="color:#111; padding: 0px '+icon.size*0.7+'px 0px '+icon.size*1.3+'px; background:#fff; font-size:'+icon.fontsize+'px; height:'+icon.size+'px;line-height:'+icon.size+'px; border-radius:'+icon.size*0.5+'px !important; font-weight:bold; width:auto; box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -webkit-box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -moz-box-shadow : 0 0 10px 0 rgba(0,0,0,.8);"><span id="icon_txt" style="line-height:'+icon.size+'px;">'+mi_chat_return.counsel.design.widget_icon_text+'</span></div>'
			}
		}else{
			icon_html += '<div style="color:#111; height:'+icon.size+'px; width:'+icon.size+'px;line-height:'+icon.size+'px; border-radius: 50% !important; font-weight:bold; box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -webkit-box-shadow : 0 0 10px 0 rgba(0,0,0,.8); -moz-box-shadow : 0 0 10px 0 rgba(0,0,0,.8);"></div>'
		}
		icon_html += '</span>'

		anchor.insertAdjacentHTML('beforeend', icon_html);
		ib.appendChild(anchor);


		//마우스오버
		var icon_mouse_ev = document.getElementById('mouse_over_ictx');
		var text_box_ic = document.getElementById('mouse_over_text');
		var icon_text_ic = document.getElementById('icon_txt');
		var intervalID = 0;
		var opacity = 0;
		if(mi_chat_return.counsel.design.mouse_over_show == "Y" && 	getDevice() != 'M' && mi_chat_return.counsel.design.widget_icon_text != "" && mi_chat_return.counsel.design.widget_icon_text != null) {
			text_box_ic.style.opacity = "0";
			text_box_ic.style.width = "1px";
			text_box_ic.style.padding = "1px";
			icon_text_ic.style.display = "none";
			icon_mouse_ev.addEventListener("mouseover", function() {intervalID = setInterval(function(){mouse_ov(icon_mouse_ev)},100)});
		}


		function mouse_ov(t){
			opacity = Number(window.getComputedStyle(text_box_ic).getPropertyValue("opacity"));
			t.style.offsetWidth = parseInt(document.getElementById('mi_icon_over').clientWidth )  +  parseInt(text_box_ic.clientWidth ) ;
			if(opacity<1){
				if(mi_chat_return.icon.p == "4"){
					text_box_ic.style.padding = "0px "+icon.size*1.3+"px 0px "+icon.size*0.7+"px";
				}else{
					text_box_ic.style.padding = "0px "+icon.size*0.7+"px 0px "+icon.size*1.3+"px";
				}
				opacity = opacity+0.1;
				text_box_ic.style.opacity=opacity;
				text_box_ic.style.width = "auto";
				icon_text_ic.style.display = "";
			}else{
				t.clientWidth -= text_box_ic.clientWidth  ;
				clearInterval(intervalID);
			}

		}

		// 아이콘 사용시 작동
		if (mi_chat_return.icon.use == 'Y' && mi_chat_return.btn_list.no != "")
			mi_btn_fade.in(ib , 5, 'icon');

		config.icon.name = mi_icon_box;
		config.icon.pixelBoxNodeId = ib_pixel_box;
		config.icon.pixelPrintNodeId = ib_pixel_print;
		config.icon.dragNodeId = ib_drag_box;
		config.icon.x = config.icon.x;
		config.icon.y = config.icon.y;
		config.icon.p = config.icon.p;
		config.icon.pv = config.icon.pv;
		if ( config.icon.pv == 'Y' ) mi_i_drag.setConfig(config.icon);
		miIconActivity.init();
		return true;
	}

	function getIconStyle(){
		var c ="";
		c = c + "\n" + ".mi-position { ";
		c = c + "\n" + "	right: 30px !important;";
		c = c + "\n" + "	bottom: 30px !important; ";
		c = c + "\n" + "}";
		c = c + "\n" + ".mi-chat-icon-drag-box {" ;            
		c = c + "\n" + "	right: 0px ;";
		c = c + "\n" + "	bottom: 0px ; ";
		c = c + "\n" + "	position: absolute !important;" ;       
		c = c + "\n" + "	width: 5px !important;" ;            
		c = c + "\n" + "	height: 5px !important;" ;           
		c = c + "\n" + "	overflow: initial !important;" ;     
		c = c + "\n" + "	z-index: 9999999999 !important;" ;   
		c = c + "\n" + "	cursor: move !important;" ;          
		c = c + "\n" + "	clear:both !important;" ;            
		c = c + "\n" + "	background-color:red !important;" ;  
		c = c + "\n" + "}" ;

		var x = config.icon.x;
		var y = config.icon.y;
		var p = config.icon.p;

		switch(p) {
			case "1" : 
				c ="";
				c = c + "\n" + ".mi-position { ";
				c = c + "\n" + "	top: " + y + "px ;";
				c = c + "\n" + "	left: " + x + "px ; ";
				c = c + "\n" + "}";

				c = c + "\n" + ".mi-chat-icon-drag-box-p {" ;
				c = c + "\n" + "	top: 0px ;";
				c = c + "\n" + "	left: 0px ; ";
				c = c + "\n" + "}" ;

				break;
			case "2" : 
				c ="";
				c = c + "\n" + ".mi-position { ";
				c = c + "\n" + "	top: " + y + "px ;";
				c = c + "\n" + "	right: " + x + "px ;";
				c = c + "\n" + "}";

				c = c + "\n" + ".mi-chat-icon-drag-box-p {" ;
				c = c + "\n" + "	top: 0px ;";
				c = c + "\n" + "	right: 0px ; ";
				c = c + "\n" + "}" ;
				break;
			case "3" : 
				c ="";
				c = c + "\n" + ".mi-position {";
				c = c + "\n" + "	left: " + x + "px ; " ;
				c = c + "\n" + "	bottom: " + y + "px ; " ;
				c = c + "\n" + "}" ;

				c = c + "\n" + ".mi-chat-icon-drag-box-p {" ;
				c = c + "\n" + "	bottom: 0px ; ";
				c = c + "\n" + "	left: 0px ;";
				c = c + "\n" + "}" ;
				break;
			case "4" : 
				c ="";
				c = c + "\n" + ".mi-position { ";
				c = c + "\n" + "	right: " + x + "px ;";
				c = c + "\n" + "	bottom: " + y + "px ; ";
				c = c + "\n" + "}";

				c = c + "\n" + ".mi-chat-icon-drag-box-p {" ;
				c = c + "\n" + "	right: 0px ;";
				c = c + "\n" + "	bottom: 0px ; ";
				c = c + "\n" + "}" ;
				break;
		}

		c = c + "\n" + ".mi-chat-icon-drag-box {" ;            
		c = c + "\n" + "	position: absolute !important;" ;       
		c = c + "\n" + "	width: 10px !important;" ;            
		c = c + "\n" + "	height: 10px !important;" ;           
		c = c + "\n" + "	overflow: initial !important;" ;     
		c = c + "\n" + "	z-index: 9999999999 !important;" ;   
		c = c + "\n" + "	cursor: move !important;" ;          
		c = c + "\n" + "	clear:both !important;" ;            
		c = c + "\n" + "	background-color:red !important;" ;  
		c = c + "\n" + "}" ;
		return c;
	}

	function ctC(){
		if(mi_chat_vi != config.visit_id){
			var mi_domain = unescape(document.location.href);
			mi_cookie_data.setCookie("mi_chat_vi", config.visit_id, 365,"",mi_domain, ""); // visit 
		}

		if(mi_chat_vc != config.vc || mi_chat_vc == '' ){
			var mi_domain = unescape(document.location.href);
			mi_cookie_data.setCookie("mi_chat_vc", config.vc, 1,"",mi_domain, ""); // vc
		}
	}

	function ctSms(){
		getSmsIframeCss();
		setSmsIframe();
	}

	function set_cafe24_user(){
		// cafe24 
		if (typeof EC_ROOT_DOMAIN !== 'undefined') {
			// sessionStorage 체크
			var ssg = sessionStorage;
			if(typeof ssg.member_1 !== 'undefined'){
				try{
					var m = JSON.parse(ssg.member_1);
					if (typeof m.data !== 'undefined') {
						if(typeof m.data.member_id !== 'undefined') mi_uk.uk = m.data.member_id;
						if(typeof m.data.member_id !== 'undefined') mi_uk.un = m.data.name;
						if(typeof m.data.member_id !== 'undefined') mi_uk.ue = m.data.email;
						if(typeof m.data.member_id !== 'undefined') mi_uk.up = m.data.cellphone.replace(/[^0-9]/g,'');
					}
				}catch(e){
					console.log(e);
				}
			}
		// 미톡 로그인 계정 변수
		} else {
			mi_uk = lowercase_key(mi_uk);
			mi_uk.uk = typeof mi_uk.uk !== 'undefined' ? mi_uk.uk : '' ;
			mi_uk.un = typeof mi_uk.un !== 'undefined' ? mi_uk.un : '' ;
			mi_uk.ue = typeof mi_uk.ue !== 'undefined' ? mi_uk.ue : '' ;
			mi_uk.up = typeof mi_uk.up !== 'undefined' ? mi_uk.up.replace(/[^0-9]/g,'') : '' ;
		}
	}


	function getConv(){
		var c = window.mi_conv;
		c = JSON.stringify(c);
		return c ;
	}

	function getConvString(){
		var text = '';
		//주문완료 중복으로 쌓이는 문제 삭제
		if(typeof window.mi_conv != 'undefined' && typeof window.mi_conv.type != 'undefined'){
			if(window.mi_conv.type == "order" && window.mi_conv.order_num != '' ){
				var mi_cookie_order_chk = mi_cookie_data.getCookie("mi_order_flag");
				if(mi_cookie_order_chk == window.mi_conv.order_num ){
					window.mi_conv = {};
				}else{
					mi_cookie_data.setCookie("mi_order_flag", window.mi_conv.order_num, 1,"",mi_domain, ""); // visit 
				}
			}
		}
		if ( mi_object_cnt(window.mi_conv)) text = "&mi_conv=" + encodeURIComponent(getConv());
		return text ;
	}


	function getUser(){
		var c = window.mi_uk;
		c = JSON.stringify(c);
		return c ;
	}

	function getUserInfo(){
		var text = '';
		if ( mi_object_cnt(window.mi_uk)) text = "&ui=" + encodeURIComponent(getUser());
		return text ;
	}

	function lowercase_key(obj){
		if ( mi_object_cnt(obj) ){
			var result = {};
			for ( var i in obj ){
				result[i.toLowerCase()] = obj[i];
			}
			return result;
		}
		return obj;
	}

	var mi_i_drag =  {
		target : null
		, layerName : null
		, dragNodeId : null
		, pixelBoxNodeId : null
		, pixelPrintNodeId : null
		, preview : ''
		, x : 30
		, y : 30
		, p : 4
		, setConfig : function(c){
			mi_i_drag.x  = c.x;
			mi_i_drag.y  = c.y;
			mi_i_drag.p  = c.p;
			mi_i_drag.layerName  = c.name;
			mi_i_drag.pixelBoxNodeId  = c.pixelBoxNodeId;
			mi_i_drag.pixelPrintNodeId  = c.pixelPrintNodeId;
			mi_i_drag.dragNodeId  = c.dragNodeId;
			mi_i_drag.preview  = c.pv
			mi_i_drag.act();
			if ( mi_i_drag.preview == 'Y' ) document.getElementById(mi_i_drag.pixelBoxNodeId).style.display= "block";

		}
		, act : function(){
			mi_i_drag.target = document.getElementById(mi_i_drag.layerName);
			mi_i_drag.setIconPosition(mi_i_drag.target);
			var icon = document.getElementById(mi_i_drag.dragNodeId);
			mi_i_drag.showPosition(mi_i_drag.x, mi_i_drag.y);
			if(icon.addEventListener) {
				icon.addEventListener("mousedown", mi_i_drag.start, false); 
			}else if(window.attachEvent) {
				icon.attachEvent("onmousedown", mi_i_drag.start);
			}
		}
		, start : function (e) {	
			var e_obj = window.event? window.event : e;
			mi_i_drag.x = mi_i_drag.getX() ;
			mi_i_drag.y = mi_i_drag.getY() ;
			document.onmousemove = mi_i_drag.move;
			document.onmouseup = mi_i_drag.stop;
			if(e_obj.preventDefault)e_obj.preventDefault(); 
		}
		, move : function(e){
			var e_obj = window.event? window.event : e;
			if ( mi_i_drag.p == "1" ){
				mi_i_drag.x = parseInt(e_obj.clientX );
				mi_i_drag.y = parseInt(e_obj.clientY );
			} else if ( mi_i_drag.p == "2" ){
				mi_i_drag.x = parseInt(window.innerWidth - e_obj.clientX  - 24);
				mi_i_drag.y = parseInt(e_obj.clientY );
			} else if ( mi_i_drag.p == "3" ){
				mi_i_drag.x = parseInt(e_obj.clientX );
				mi_i_drag.y = parseInt(window.innerHeight - e_obj.clientY );
			} else if ( mi_i_drag.p == "4" ){
				mi_i_drag.x = parseInt(window.innerWidth - e_obj.clientX - 24);
				mi_i_drag.y = parseInt(window.innerHeight - e_obj.clientY );
			}
			if ( mi_i_drag.x < 0 ) mi_i_drag.x = 0
			if ( mi_i_drag.y < 0 ) mi_i_drag.y = 0
			mi_i_drag.showPosition(mi_i_drag.x , mi_i_drag.y);
			mi_i_drag.setIconPosition(mi_i_drag.target);
			return false;
		}
		, stop : function(){
			document.onmousemove = null;
			document.onmouseup = null;
			// 미톡 iframe 위치 적용
			mi_i_drag.setIconPosition(document.getElementById("mi-chat-iframe-box"));
		}
		, getX : function(){
			return mi_i_drag.getStylePosition(mi_i_drag.p , 'x');
		}
		, getY : function(){
			return mi_i_drag.getStylePosition(mi_i_drag.p , 'y');
		}
		, showPosition : function(x,y){
			if ( mi_i_drag.preview == 'Y' ){
				var t = "x : " + x + " , y : " + y;
				document.getElementById(mi_i_drag.pixelPrintNodeId).innerHTML = t;
			}
		}
		, setIconPosition : function(t){
			if (mi_i_drag.p == '1' ){
				t.style.top = mi_i_drag.y + "px";
				t.style.left = mi_i_drag.x + "px";
			} else if (mi_i_drag.p == '2' ){
				t.style.top = mi_i_drag.y + "px";
				t.style.right = mi_i_drag.x + "px";
			} else if (mi_i_drag.p == '3' ){
				t.style.left = mi_i_drag.x + "px";
				t.style.bottom = mi_i_drag.y + "px";
			} else if (mi_i_drag.p == '4' ){
				t.style.right = mi_i_drag.x + "px";
				t.style.bottom = mi_i_drag.y + "px";
			}
		}
		, getStylePosition : function (p,t){
			if (p == '1' ){
				if (t == 'x') return parseInt( (mi_i_drag.target.style.top == '' ? '0' : mi_i_drag.target.style.top ).replace('px', '')); 
				else if(t == 'y') return parseInt( (mi_i_drag.target.style.left == '' ? '0' : mi_i_drag.target.style.left ).replace('px', '')); 
			} else if (p == '2' ){
				if (t == 'x') return parseInt( (mi_i_drag.target.style.right == '' ? '0' : mi_i_drag.target.style.right ).replace('px', '')); 
				else if (t == 'y') return parseInt( (mi_i_drag.target.style.top == '' ? '0' : mi_i_drag.target.style.top ).replace('px', '')); 
			} else if (p == '3' ){
				if (t == 'x') return parseInt( (mi_i_drag.target.style.left == '' ? '0' : mi_i_drag.target.style.left ).replace('px', '')); 
				else if (t == 'y') return parseInt( (mi_i_drag.target.style.bottom == '' ? '0' : mi_i_drag.target.style.bottom ).replace('px', '')); 
			} else if (p == '4' ){
				if (t == 'x') return parseInt( (mi_i_drag.target.style.right == '' ? '0' : mi_i_drag.target.style.right ).replace('px', '')); 
				else if (t == 'y') return parseInt( (mi_i_drag.target.style.bottom == '' ? '0' : mi_i_drag.target.style.bottom ).replace('px', '')); 
			}
			return 0;
		}
	};

	var mi_drag =  {
		target : null
		, layerName : null
		, dragNodeId : null
		, pixelBoxNodeId : null
		, pixelPrintNodeId : null
		, preview : ''
		, x : 0
		, y : 0
		, setConfig : function(c){
			mi_drag.x  = c.pl;
			mi_drag.y  = c.pt;
			mi_drag.layerName  = c.name;
			mi_drag.pixelBoxNodeId  = c.pixelBoxNodeId;
			mi_drag.pixelPrintNodeId  = c.pixelPrintNodeId;
			mi_drag.dragNodeId  = c.dragNodeId;
			mi_drag.preview  = c.pv
			mi_drag.posi  = c.posi
			mi_drag.act();

			if ( c.pv == 'Y' ) document.getElementById(mi_drag.pixelBoxNodeId).style.display= "block";
		}
		, act : function(){
			mi_drag.target = document.getElementById(mi_drag.layerName);
			var sms = document.getElementById(mi_drag.dragNodeId);
			mi_drag.showPosition(mi_drag.x, mi_drag.y);
			if(sms.addEventListener) {
				sms.addEventListener("mousedown", mi_drag.start, false); 
			}else if(window.attachEvent) {
				sms.attachEvent("onmousedown", mi_drag.start);
			}
		}
		, start : function (e) {	
			var e_obj = window.event? window.event : e;
			mi_drag.x = mi_drag.getX(mi_drag.posi) - e_obj.clientX;
			mi_drag.y = mi_drag.getY(mi_drag.posi) - e_obj.clientY;
			document.onmousemove = mi_drag.move;
			document.onmouseup = mi_drag.stop;
			if(e_obj.preventDefault)e_obj.preventDefault(); 
		}
		, move : function(e){
			var e_obj = window.event? window.event : e;
			var element_box = document.getElementById("mi-sms-iframe-box");
			var h = element_box.clientHeight;
			var w = element_box.clientWidth/2;
			switch(mi_drag.posi) {
				case "1": 
						var dmvx = parseInt(e_obj.clientX + mi_drag.x);
						var dmvy = parseInt(e_obj.clientY + mi_drag.y);
						mi_drag.target.style.left = dmvx +"px";
						mi_drag.target.style.top = dmvy +"px";
					 break;
				case "2": 
						var dmvx = parseInt(e_obj.clientX + mi_drag.x);
						var dmvy = parseInt((window.innerHeight-e_obj.clientY - h));
						mi_drag.target.style.left = dmvx +"px";
						mi_drag.target.style.bottom = dmvy +"px";
					 break;
				case "3": 
						var dmvx = parseInt((window.innerWidth-e_obj.clientX - w));
						var dmvy = parseInt(e_obj.clientY + mi_drag.y);
						mi_drag.target.style.right = dmvx +"px";
						mi_drag.target.style.top = dmvy +"px";
					break;
				case "4":
						var dmvx = parseInt((window.innerWidth-e_obj.clientX - w));
						var dmvy = parseInt((window.innerHeight-e_obj.clientY - h));
						mi_drag.target.style.right = dmvx +"px";
						mi_drag.target.style.bottom = dmvy +"px";
					break;
				default: 
						mi_drag.target.style.left = dmvx +"px";
						mi_drag.target.style.top = dmvy +"px";
					 break;
			}
			mi_drag.showPosition(dmvx , dmvy);
			return false;
		}
		, stop : function(){
			document.onmousemove = null;
			document.onmouseup = null;
		}
		, getX : function(posi){
			switch(posi) {
				case "1": 
						return parseInt((mi_drag.target.style.left == '' ? '0' : mi_drag.target.style.left ).replace('px', ''));
					 break;
				case "2": 
						return parseInt((mi_drag.target.style.left == '' ? '0' : mi_drag.target.style.left ).replace('px', ''));
					 break;
				case "3": 
						return parseInt((mi_drag.target.style.right == '' ? '0' : mi_drag.target.style.right ).replace('px', ''));
					break;
				case "4": 
						return parseInt((mi_drag.target.style.right == '' ? '0' : mi_drag.target.style.right ).replace('px', ''));
					break;
				default: 
						return parseInt((mi_drag.target.style.left == '' ? '0' : mi_drag.target.style.left ).replace('px', ''));
					break;
			}

		}
		, getY : function(posi){
			switch(posi) {
				case "1": 
						return parseInt((mi_drag.target.style.top == '' ? '0' : mi_drag.target.style.top ).replace('px', ''));
					 break;
				case "2": 
						return parseInt((mi_drag.target.style.bottom == '' ? '0' : mi_drag.target.style.bottom ).replace('px', ''));
					 break;
				case "3": 
						return parseInt((mi_drag.target.style.top == '' ? '0' : mi_drag.target.style.top ).replace('px', ''));
					break;
				case "4": 
						return parseInt((mi_drag.target.style.bottom == '' ? '0' : mi_drag.target.style.bottom ).replace('px', ''));
					break;
				default: 
						return parseInt((mi_drag.target.style.top == '' ? '0' : mi_drag.target.style.top ).replace('px', ''));
					break;
			}
			

			
		}
		, showPosition : function(x,y){
			if(mi_drag.preview == 'Y'){
				var t = "x : " + x + " , y : " + y;
				document.getElementById(mi_drag.pixelPrintNodeId).innerHTML = t;
			}
		}
	};


	function getSmsIframeCss(){
		var temp = [];
		temp.push("\n" + ".mi-sms-iframe-box {" );
		temp.push("\n" + "	display:none ; " );
		temp.push("\n" + "	width: 165px !important; " );
		temp.push("\n" + "	min-height: 214px !important;" );
		temp.push("\n" + "	max-height: 290px !important;" );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	background-color: transparent !important;" );
		//temp.push("\n" + "	box-shadow: 0 6px 60px 0 rgba(81, 99, 120, 0.3) !important;" );
		temp.push("\n" + "	z-index: 10000000000 !important;" );
		temp.push("\n" + "	overflow: hidden !important; " );
		temp.push("\n" + "	font-family: !important; " );
		temp.push("\n" + "}" );

		temp.push("\n" + ".mi-sms-iframe-box-B {" );
		temp.push("\n" + "	height: 290px !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-sms-iframe-box-S-FH {" );
		temp.push("\n" + "	height: 220px !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-sms-iframe-box-S-E {" );
		temp.push("\n" + "	height: 260px !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-sms-iframe-box-S-N {" );
		temp.push("\n" + "	height: 250px !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-sms-iframe-box-S-G {" );
		temp.push("\n" + "	height: 214px !important;" );
		temp.push("\n" + "}" );

		temp.push("\n" + ".mi-sms-drag-box {" );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	width: 130px !important;" );
		temp.push("\n" + "	height: 30px !important;" );
		temp.push("\n" + "	overflow: initial !important;" );
		temp.push("\n" + "	z-index: 9999999999 !important;" );
		temp.push("\n" + "	flex-wrap: nowrap !important;" );
		temp.push("\n" + "	cursor: move !important;" );
		temp.push("\n" + "	clear:both !important;" );
		temp.push("\n" + "}" );

		temp.push("\n" + ".mi-sms-pixel-box {" );
		temp.push("\n" + "	position: fixed !important;" );
		temp.push("\n" + "	display:none ;" );
		temp.push("\n" + "	z-index:9999999999;" );
		temp.push("\n" + "	clear:both !important;" );
		temp.push("\n" + "	line-height : unset !important;" );
		temp.push("\n" + "	letter-spacing : unset !important;" );
		temp.push("\n" + "}" );
		temp.push("\n" + ".mi-sms-pixel-print {" );
		temp.push("\n" + "	position: absolute !important;" );
		temp.push("\n" + "	top:-15px !important;" );
		temp.push("\n" + "	width: 165px !important;" );
		temp.push("\n" + "	text-align:center !important;" );
		temp.push("\n" + "	background-color:gray !important;" );
		temp.push("\n" + "	color:white !important;" );
		temp.push("\n" + "	font: 0.75em \"돋움\",Dotum,AppleGothic,sans-serif!important; " );
		temp.push("\n" + "	font-size:13px !important;" );
		temp.push("\n" + "	line-height : normal !important;" );
		temp.push("\n" + "	letter-spacing : unset !important;" );
		temp.push("\n" + "	clear:both !important;" );
		temp.push("\n" + "}" );

		var r = document.createElement("style");
		r.type = "text/css";
		r.setAttribute("private", "true");
		r.innerHTML = temp.join("");
		window.document.getElementsByTagName("head")[0].appendChild(r);
	}

	function getSmsHeightBox(dt){
		var r = '';
		if ( dt == 'A' || dt == 'B' || dt == 'C' || dt == 'D' || dt == 'I' || dt == 'J' || dt == 'K' || dt == 'L' || dt == 'M' || dt == 'N' || dt == 'O' ) r = 'B';
		else if ( dt == 'F' || dt == 'H' || dt == 'P' || dt == 'R' || dt == 'S') r = 'S-FH';
		else if ( dt == 'E'  ) r = 'S-E';
		else if ( dt == 'T' || dt == 'U' || dt == 'X' ) r = 'S-N';
		else if ( dt == 'G' || dt == 'Q' ) r = 'S-G';
		return r;
	}

	function setSmsIframe(){
		if (!document.getElementById('mi_sms_box')) {
			var node = document.createElement('div');
			node.id = 'mi_sms_box';
			document.body.appendChild(node);
		}
		var root = document.getElementById("mi_sms_box");
		var sms_iframe_node = "mi-sms-iframe-box";
		var sms_pixel_box = "mi-sms-pixel-box";
		var sms_pixel_print = "mi-sms-pixel-print";
		var sms_drag_box = "mi-sms-drag-box";
		var iframe_box = sms_iframe_node;

		iframe_box = iframe_box + " mi-sms-iframe-box-" + getSmsHeightBox(config.sms.dt) ;

		var sms_url = mi_url.sms.replace("[type]",config.sms.dt).replace("[bi]",encodeURIComponent(config.sms.bi)).replace("[bip]",config.sms.bip).replace("[bl]",encodeURIComponent(config.sms.bl)).replace("[adkey]",encodeURIComponent(mi_chat_adkey)).replace("[agent]",getDevice()).replace("[place_text]",encodeURIComponent(config.sms.st));
		root.innerHTML = "<div id='mi-sms-iframe-box' class='"+iframe_box+" '><div id='"+sms_pixel_box+"' class='"+sms_pixel_box+"'><div id='"+sms_pixel_print+"' class='"+sms_pixel_print+"'></div></div><div id='"+sms_drag_box+"' class='"+sms_drag_box+"'></div><iframe id='mi-sms-script-iframe' src='"+sms_url+"' style='position:relative!important;height:100%!important;width:100%!important;border:none!important;'></iframe></div>";
		var iframe = document.getElementById('mi-sms-script-iframe');
		mi_chat_handledre.sms_start = smsStart;
	}

	function smsStart(){
		var sms_iframe_node = "mi-sms-iframe-box";
		var sms_pixel_box = "mi-sms-pixel-box";
		var sms_pixel_print = "mi-sms-pixel-print";
		var sms_drag_box = "mi-sms-drag-box";

		switch(config.sms.posi) {
			case "1": 
					document.getElementById(sms_iframe_node).style.top = config.sms.pt + "px";
					document.getElementById(sms_iframe_node).style.left = config.sms.pl + "px";
				 break;
			case "2": 
					document.getElementById(sms_iframe_node).style.bottom = config.sms.pt + "px";
					document.getElementById(sms_iframe_node).style.left = config.sms.pl + "px";
				 break;
			case "3": 
					document.getElementById(sms_iframe_node).style.top = config.sms.pt + "px";
					document.getElementById(sms_iframe_node).style.right = config.sms.pl + "px";
				break;
			case "4": 
					document.getElementById(sms_iframe_node).style.bottom = config.sms.pt + "px";
					document.getElementById(sms_iframe_node).style.right = config.sms.pl + "px";
				break;
			default: 
					document.getElementById(sms_iframe_node).style.top = config.sms.pt + "px";
					document.getElementById(sms_iframe_node).style.left = config.sms.pl + "px";
				 break;
		}

		document.getElementById(sms_iframe_node).style.display = 'block';
		config.sms.name = sms_iframe_node;
		config.sms.pixelBoxNodeId = sms_pixel_box;
		config.sms.pixelPrintNodeId = sms_pixel_print;
		config.sms.dragNodeId = sms_drag_box;
		mi_drag.setConfig(config.sms);
	}

	function getSmsPageView(){
		var tg = ['rt','rw','rh','rl','ri','roi','qv','ra','icp','icx','icy' ];
		var r = [];
		for(var i in tg ) {
			if ( typeof tg[i]  == 'string' ){
				var v = getParameters(tg[i]);
				if ( v != '' ){
					r.push("&" + tg[i] + "=" + getParameters(tg[i]));
				}
			}
		}
		return r.join("");
	}

	function getDevice(){
		var UserAgent = navigator.userAgent;
		if(UserAgent.match(/iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson/i)!= null || UserAgent.match(/LG|SAMSUNG|Samsung/)!=null){
			var device = 'M';
		}else{
			var device = 'P';
			// 반응형 viewport 체크 있으면 
			if(getResponsive()) device = 'M';
		}
		return device;
	}

	function getResponsive(){
		var is_viewPort = false;
		var n = mi_wd;
		var metaTag = n.getElementsByTagName("head")[0].getElementsByTagName("meta");
		//viewport 체크
		for ( var i in metaTag ){
			var e = metaTag[i];
			if ( e.name === 'viewport' && e.id !== "mi-chat-viewport" ){
				is_viewPort = true;
			}
		}
		// 접근 agent width 체크 테블릿 ( 768 px 까지 pc 로 )
		if ( is_viewPort && screen.width < 768) is_viewPort = true;
		else is_viewPort = false;
		return is_viewPort;
	}

	function getAgent(){
		return encodeURIComponent(navigator.userAgent);
	}

	function getReferrer(){
		return document.referrer ? encodeURIComponent(document.referrer) : "";
	}

	function getLocation(){
		return encodeURIComponent(document.location.href);
	}

	function getParameters(paramName) {
		var returnValue;
		var url = location.href;
		//var parameters = (url.slice(url.indexOf('?') + 1, url.length)).split('&');
		var parameters = (url.slice(url.lastIndexOf('?') + 1, url.length)).split('&');
		for (var i = 0; i < parameters.length; i++) {
			var varName = parameters[i].split('=')[0];
			if (varName.toUpperCase() == paramName.toUpperCase()) {
				returnValue = parameters[i].split('=')[1];
				return decodeURIComponent(returnValue);
			}
		}
		return '';
	};

	function fn_mi_brtype(){
		var _ua = navigator.userAgent;
		var rv = -1;
		//IE 11,10,9,8
		var trident = _ua.match(/Trident\/(\d.\d)/i);
		if( trident != null )
		{
			if( trident[1] == "7.0" ) return rv = "IE" + 11;
			if( trident[1] == "6.0" ) return rv = "IE" + 10;
			if( trident[1] == "5.0" ) return rv = "IE" + 9;
			if( trident[1] == "4.0" ) return rv = "IE" + 8;
		}

		//IE 7...
		if( navigator.appName == 'Microsoft Internet Explorer' ) return rv = "IE" + 7;

		//other
		var agt = _ua.toLowerCase();		
		if(agt.indexOf("whale") != -1) return 'Whale';
		else if (agt.indexOf("edg") != -1) return 'Edge';
		else if (agt.indexOf("chrome") != -1) return 'Chrome';
		else if (agt.indexOf("opera") != -1) return 'Opera';
		else if (agt.indexOf("staroffice") != -1) return 'Star Office';
		else if (agt.indexOf("webtv") != -1) return 'WebTV';
		else if (agt.indexOf("beonex") != -1) return 'Beonex';
		else if (agt.indexOf("chimera") != -1) return 'Chimera';
		else if (agt.indexOf("netpositive") != -1) return 'NetPositive';
		else if (agt.indexOf("phoenix") != -1) return 'Phoenix';
		else if (agt.indexOf("firefox") != -1) return 'Firefox';
		else if (agt.indexOf("safari") != -1) return 'Safari';
		else if (agt.indexOf("skipstone") != -1) return 'SkipStone';
		else if (agt.indexOf("netscape") != -1) return 'Netscape';
		else if (agt.indexOf("NAVER(inapp") != -1) return 'NAVER App';
		else if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla5.0';
		else if (agt.indexOf("mozilla/4.0") != -1) return 'Mozilla4.0';
	}
	document.readyState==="complete"?mi_init_act():window.attachEvent?window.attachEvent("onload",mi_init_act):(window.addEventListener("load",mi_init_act,!1));
}) ();
