var clickId='';
var clickX=0;
var clickY=0;
var clickLayer='';
var numLoginUsersMember=0;
var numLoginUsersGuest=0;
var numLoginUsersTotal=0;
var myDeskWidth;
var myDeskAlign;

/*객체얻기*/
function getId(id)
{
	return document.getElementById(id);
}
/*현재url*/
function getNowUrl()
{
	var urlx = location.href.split(ko_thisfile);
	return urlx[0];
}
/*킴스큐설치url*/
function getKimsqUrl()
{
	var i;
	var urlx = location.href.split(ko_thisfile);
	var urlc = urlx[0].split('/');
	var urln = ko_path_core.split('../');
	var urlg = urlc.length - urln.length;
	var url = "";

	for (i = 0; i < urlg; i++)
	{
		url += urlc[i] + '/';
	}
	return url;
}
/*쿠키세팅*/
function setCookie(name,value,expiredays) 
{ 
	var todayDate = new Date(); 
	todayDate.setDate( todayDate.getDate() + expiredays ); 
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
}
/*쿠키추출*/
function getCookie( name )
{
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length )
        {
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;
                        return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                        break;
        }
		return "";
}
/*이벤트좌표값*/
function getEventXY(e)
{
	var obj = new Object(); 
	obj.x = (e.pageX) ? e.pageX : event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - (document.documentElement.clientLeft || document.body.clientLeft);
	obj.y = (e.pageY) ? e.pageY : event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)  - (document.documentElement.clientTop || document.body.clientTop);
	//obj.x =window.event.x;
	//obj.y =event.clientY;
	//alert(event.clientX + ' : ' + event.clientY + ' / ' + window.event.x + ' : ' + window.event.y);

	return obj;
}
/*파일확장자*/
function getFileExt(file)
{
	var arr = file.split('.');
	return arr[arr.length-1];
}
/*로그인체크*/
function isLogin()
{
	if(ko_myid == '')
	{
		alert(msg_lang_1+'        ');
		return false;
	}
	return true;
}
/*권한체크*/
function isPerm()
{
	alert(msg_lang_2 + '        ');
	return false;
}
/*팝업체크*/
function getPopUpFlag(win)
{
	try{ win.focus(); return win; }
	catch(e)
	{
		alert(msg_lang_3+'               ');
	}
}
/*회원레이어보이기*/
function getMemberLayer(id,e)
{
	var xy = getEventXY(e);
	clickX = myagent == 'ie' ? xy.x - 25 : xy.x + 15;
	clickY = myagent == 'ie' ? xy.y : xy.y - 10;
	clickX = clickX -300;
	clickY = clickY -30 ;
	clickLayer = '_member_layer_';
	clickId = id;
	frames._action_frame_.location.href = ko_path_home + 'index.php?action=member&a=mbr_layer&id=' + id;
}
/*회원정보윈도우*/
function getMemberWin(module,id,que)
{
	getPopUpFlag(window.open(ko_path_module+module+'/index.php?xsite='+ko_account+'&id=' + id + '&q=' + que,'','left=0,top=0,width=1000px,height=670px,status=yes,scrollbars=no,resizeable=no'));
}
/*쪽지창*/
function getPaperWin(module,type,to)
{
	getPopUpFlag(window.open(ko_path_module+module+'/paper_'+type+'.php?xsite='+ko_account + '&to=' + to,'','left='+(type=='send'?400:0)+',top=0,width=300px,height=250px,status=yes,scrollbars=no,resizable=yes'));
}
/*채팅창*/
function reqChat(module,from,to)
{
	if (from == '') isLogin();
	getPopUpFlag(window.open(ko_path_module+module+'/chat.php?xsite='+ko_account+'&a=mkroom&callid='+to,'','left=0,top=0,width=500px,height=480px,scrollbars=no,status=yes,resizeable=no'));
}
/*설문창*/
function getSurveyWin(module,q)
{
	getPopUpFlag(window.open(ko_path_module+module+'/survey.php?xsite='+ko_account+'&q='+q,'','left=0,top=0,width=700px,height=500px,scrollbars=no,status=yes,resizeable=no'));
}
/*이동복사*/
function getMoveCopyWin(uid,flag,site)
{
	getPopUpFlag(window.open(ko_path_syscore+'root/action/a.siteselect.php?site='+site+'&referer='+escape('../kimsq.contents.movecopy.php?posts='+uid+',&flag='+flag),'','top=0,left=0,width=950px,height=600px,resizable=yes,status=yes,scrollbars=yes'));
}
/*칼라픽커*/
function getColor(module,q)
{
	getPopUpFlag(window.open(ko_path_module+module+'/color.php?xsite='+ko_account+'&'+q,'','left=0,top=0,width=400px,height=300px,scrollbars=no,status=yes,resizeable=no'));
}
/*히든액션*/
function getHiddenAction(value)
{
	frames._action_frame_.location.href = ko_path_home + 'index.php?'+value;
}
/*이메일조합*/
function getEmailWin(domain,id)
{
	location.href = 'mailto:' + id + '@' + domain;
}
/*우편번호윈도우*/
function OpenZipcode(module,z1,z2,ad,ad1) 
{
	var url = ko_path_module+module+'/zipcode.php?zip1='+z1+'&zip2='+z2+'&address='+ad+'&address1='+ad1;
	getPopUpFlag(window.open(url,'zip_win','width=440px,height=550px,statusbar=no,scrollbars=no,toolbar=no'));
}
/*원본이미지뷰어*/
function imgOrignWin(url)
{
	getPopUpFlag(window.open(ko_path_global+'connect/img.view.php?img=' + url,'','width=10px,height=10px,status=yes,resizable=yes,scrollbars=yes'));
}
/*요청윈도우*/
function sendWindow(url,width,height,scroll)
{
	var top = 0;
	var left= 0;

	if (scroll != 'no' && scroll != 'yes')
	{
		var xy = getEventXY(scroll);

		top = 100;/*top  = parseInt(xy.y) + parseInt(height);*/
		left = parseInt(xy.x) - parseInt(width/2);
		height = 150;
		scroll = 'no';
	}

	getPopUpFlag(window.open(url , '' , 'top='+top+'px,left='+left+'px,width='+width+'px,height='+height+'px,scrollbars='+scroll+',status=yes,resizeable=no'));
}
/*url이동*/
function goUrl(url,opt)
{
	if (opt == '')
	location.href = url;
	else
	window.open(url , '' , opt);
}
/*첨부파일윈도우*/
function getUpfileWin(tmpcode,cbox,q)
{
	setCookie('downuids',tmpcode,1);
	getPopUpFlag(window.open(ko_path_module+cbox+'/viewer.php?xsite='+ ko_account +'&q='+q,'','left=0,top=0,width=750px,height=650px,status=yes,scrollbars=no,resizeable=no'));
}
/*개별파일다운로드*/
function getSingleDown(uid,cbox)
{
	getId('clickLayer').innerHTML = getId('clickLayer').innerHTML + "<iframe name=\"downIframe_"+uid+"\" width=\"0\" height=\"0\" frameborder=\"0\" scroll=\"no\" scrolling=\"no\"></iframe>";
	eval("frames.downIframe_"+uid).location.href = ko_path_module + cbox + '/down.php?xsite='+ko_account+'&uid=' + uid;
}
/*파일(컨텐츠)박스오픈*/
function getFilebox(cbox,q)
{
	if(isLogin()) getPopUpFlag(window.open(ko_path_module+cbox+'/index.php?xsite='+ko_account+'&q='+q,'','top=0,left=0,width=950px,height=670px,status=yes,resizable=yes,scrollbars=no'));
}
/*객체의위치/크기*/
function getOfs(id) 
{ 
    var obj = new Object(); 
    if(document.all) 
	{ 
        var cr = id.getBoundingClientRect(); 
        obj.left = cr.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
        obj.top = cr.top + (document.documentElement.scrollTop || document.body.scrollTop); 
		obj.width = cr.right - cr.left; 
        obj.height = cr.bottom - cr.top; 
    }
	else 
	{ 
        var box = document.getBoxObjectFor(id); 
        obj.left = box.x; 
        obj.top = box.y; 
		obj.width = box.width; 
        obj.height = box.height; 
    } 
    return obj; 
} 
/*본문삽입이미지 가로사이즈조정*/
function getDivWidth(width,div)
{
	var maxsize = parseInt(width);
    var content = getId(div); 
    var img = content.getElementsByTagName('img'); 
    for(i=0; i<img.length; i++) 
    {
        if ( eval('img[' + i + '].width > maxsize') ) 
        { 
            var heightSize = ( eval('img[' + i + '].height')*maxsize )/eval('img[' + i + '].width') ; 
            eval('img[' + i + '].width = maxsize') ; 
            eval('img[' + i + '].height = heightSize') ; 
        } 
    }
	content.innerHTML = content.innerHTML.replace(/<img /ig,"<img onclick='imgOrignWin(this.src);' ");
}
/*레이어show/hide전환*/
function LayerShowHide(obj,layer)
{
	if (obj.checked == true) getId(layer).style.display = '';
	else getId(layer).style.display = 'none';
}
/*클릭오픈된레이어감추기*/
function getClickLayerHide()
{
	if (clickLayer)
	{
		var layer = getId(clickLayer);
		layer.style.top = clickY + 'px';
		layer.style.left = clickX + 'px';
		layer.style.zIndex = 10000;
		layer.style.display = 'block';
		
		clickX = -1000;
		clickY = -1000;
	}
}
/*포커스체크*/
function focusCheck(obj)
{
	if (obj.value == obj.defaultValue)
	{
		obj.value = '';
	}
}
/*블러체크*/
function blurCheck(obj)
{
	if (obj.value == obj.defaultValue)
	{
		obj.value = '';
	}
	else {
		if(obj.value == '') obj.value = obj.defaultValue;
	}
}
/*버튼오버/아웃*/
function TbtnOver(obj,f,bg)
{
	obj.style.background = bg;
	obj.style.color='#FF691F';
}
function TbtnOut(obj,f,bg)
{
	obj.style.background = bg;
	obj.style.color = f;
}
/*인용레이어*/
function quotShow(d,sopen,sclose,obj)
{
	var p = getId('xpreview_'+d);
	var h = getId('hidden_'+d);
	var htags = "";

	if (p.className == 'sys_dis_none')
	{
		p.className = 'sys_dis_block';
		htags += "<span style=\"cursor:pointer;color:"+obj.style.color+";font-weight:"+obj.style.fontWeight+";text-decoration:"+obj.style.textDecoration+";\" onclick=\"quotShow('"+d+"','"+sopen+"','"+sclose+"',this);\">" + sclose + "</span>";
	}
	else {
		p.className = 'sys_dis_none';
		htags += "<span style=\"cursor:pointer;color:"+obj.style.color+";font-weight:"+obj.style.fontWeight+";text-decoration:"+obj.style.textDecoration+";\" onclick=\"quotShow('"+d+"','"+sopen+"','"+sclose+"',this);\">" + sopen + "</span>";
	}
	h.innerHTML = htags;
}
/*조사처리*/
/*은,는,이,가 - getJosa(str,"은는")*/
function getJosa(str, tail) 
{ 
    strTemp = str.substr(str.length - 1); 
    return ((strTemp.charCodeAt(0) - 16) % 28 != 0) ? str + tail.substr(0, 1) : str + tail.substr(1, 1); 
}
/*타입비교 (비교문자 , 비교형식 ; ex: getTypeCheck(string , "1234567890") ) */
function getTypeCheck (s, spc)
{
	var i;

	for(i=0; i< s.length; i++) 
	{
		if (spc.indexOf(s.substring(i, i+1)) < 0) 
		{
			return false;
		}
	}        
	return true;
}

/*콤마삽입 (number_format)*/
function commaSplit(srcNumber) 
{ 
	var txtNumber = '' + srcNumber; 

	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])'); 
	var arrNumber = txtNumber.split('.'); 
	arrNumber[0] += '.'; 
	do { 
		arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2'); 
	} 
	while (rxSplit.test(arrNumber[0])); 
	if (arrNumber.length > 1) { 
		return arrNumber.join(''); 
	} 
	else { 
		return arrNumber[0].split('.')[0]; 
	} 
}

/*콤마제거*/
function filterNum(str) 
{ 
	return str.replace(/^\$|,/g, ""); 
}
/*숫자체크*/
function commaInsert(field)
{
	if (!getTypeCheck(field.value , "0123456789,"))
	{
		alert('숫자만 입력해 주세요.       ');
		field.value = '';
		field.focus();
		return false;
	}
	field.value = commaSplit(filterNum(field.value));
}
/*이메일체크*/
function chkEmailAddr(email)
{
	if (email == '') return false;
	if (email.indexOf('\@') == -1) return false;
	return true;
}
/*아이디체크*/
function chkIdValue(id)
{
	if (!getTypeCheck(id,"abcdefghijklmnopqrstuvwxyz1234567890_")) return false;
	return true;
}
/*문자열카피*/
function copyStr(id) 
{
	var tempval=getId(id);
	tempval.focus();
	tempval.select();
	therange=tempval.createTextRange();
	therange.execCommand("copy");
}
/*페이징처리*/
function getPageLink(lnum,p,tpage,img)
{
	var g_hi = img.split('|');
	var imgpath = g_hi[0];
	var wp = g_hi[1] ? g_hi[1] : '';
	var g_p1 = '<img src="'+imgpath+'/p1.gif" align="absmiddle" style="margin:0 3px 0 3px;" /> ';
	var g_p2 = '<img src="'+imgpath+'/p2.gif" align="absmiddle" style="margin:0 3px 0 3px;" /> ';
	var g_n1 = ' <img src="'+imgpath+'/n1.gif" align="absmiddle" style="margin:0 3px 0 3px;" />';
	var g_n2 = ' <img src="'+imgpath+'/n2.gif" align="absmiddle" style="margin:0 3px 0 3px;" />';
	var g_cn = '<img src="'+imgpath+'/l.gif" align="absmiddle" style="margin:0 8px 0 8px;" />';
	var g_q  = p > 1 ? '<a href="'+getPageGo(1,wp)+'"><img src="'+imgpath+'/fp.gif" align="absmiddle" style="margin:0 3px 0 3px;" /></a> ' : '<img src="'+imgpath+'/fp1.gif" align="absmiddle" style="margin:0 3px 0 3px;" /> ';

	if(p < lnum+1) { g_q += g_p1; }
	else{ var pp = parseInt((p-1)/lnum)*lnum; g_q += '<a href="'+getPageGo(pp,wp)+'" style="color:#666666;">'+g_p2+'</a>';} g_q += g_cn;

	var st1 = parseInt((p-1)/lnum)*lnum + 1;
	var st2 = st1 + lnum;

	for(var jn = st1; jn < st2; jn++)
	if ( jn <= tpage)
	(jn == p)? g_q += '<b style="font-size:14px;font-family:Arial">'+jn+'</b>'+g_cn : g_q += '<a href="'+getPageGo(jn,wp)+'" style="color:#666666;font-family:Arial;">'+jn+'</a>'+g_cn;

	if(tpage < lnum || tpage < jn) { g_q += g_n1; }
	else{var np = jn; g_q += '<a href="'+getPageGo(np,wp)+'">'+g_n2+'</a>'; }
	g_q  += tpage > p ? ' <a href="'+getPageGo(tpage,wp)+'"><img src="'+imgpath+'/lp.gif" align="absmiddle" style="margin:0 3px 0 3px;" /></a>' : ' <img src="'+imgpath+'/lp1.gif" align="absmiddle" style="margin:0 3px 0 3px;" />';
	document.write(g_q);
}
/*페이지클릭*/
function getPageGo(n,wp)
{ 
	var v   = wp != '' ? wp : 'p';
	var p   = getUriString(v);
	var que = location.href.replace('&'+v+'='+p,'');
		que = que.indexOf('?') != -1 ? que : que + '?';
		que = que.replace('&'+v+'=view&uid=' + getUriString('uid') , '');
	var xurl = que.split('#');
	return xurl[0].indexOf('?') != -1 ?  xurl[0] + '&'+v+'=' + n : xurl[0] + '?'+v+'=' + n; 
}
/*파라미터값*/
function getUriString(param)
{
	var QuerySplit = location.href.split('?');
	var ResultQuer = QuerySplit[1] ? QuerySplit[1].split('&') : '';

	for (var i = 0; i < ResultQuer.length; i++)
	{
		var keyval = ResultQuer[i].split('=');
		if (param == keyval[0]) return keyval[1];
	}
	return '';
}
/* 날짜출력포맷 */
/* getDateFormat('yyyymmddhhiiss','xxxx.xx.xx xx:xx:xx')*/
var dateFormat = 0;
function getDateFormat(date , type)
{
	var ck;
	var rtstr = "";
	var j = 0;
	for(var i = 0; i < type.length; i++) 
	{
		if(type.substring(i,i+1) == 'x')
		{
			rtstr += date.substring(j,j+1);
		}
		else {
			j--;
			rtstr += type.substring(i,i+1);
		}
		j++;
	}
	if(dateFormat == 0)
	{
		document.write(rtstr);
	}
	else {
		dateFormat = 0;
		return rtstr;
	}
}
function getHttprequest_FALSE(URL) 
{ 
	var xmlhttp = null;

	if(window.XMLHttpRequest) 
	{ 
		xmlhttp = new XMLHttpRequest(); 
	} 
	else 
	{ 
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
		catch (e1) 
		{ 
			try 
			{ 
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch (e2) { 
				return false;
			} 
		} 
	}
	if (xmlhttp)
	{
		xmlhttp.open("GET", URL, false); 
		xmlhttp.send(null);
		if (xmlhttp.readyState==4 && xmlhttp.status == 200 && xmlhttp.statusText=='OK') 
		{
			return xmlhttp.responseText.replace(/\n/g , '<br>');
		}
		xmlhttp = '';
	}
} 
function getHttprequest_TRUE(URL) 
{ 
	var xmlhttp = null;

	if(window.XMLHttpRequest) 
	{ 
		xmlhttp = new XMLHttpRequest(); 
	} else 
	{ 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	}

	xmlhttp.open("GET", URL, true);
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) 
		{
			if (xmlhttp.status == 200) 
			{
				getId('_ajax_layer_').innerHTML = xmlhttp.responseText;
			} 
		} 
	}
	xmlhttp.send(null); 
}

function getMyCheck(URL,flag)
{	
	var i;

	if (flag == false)
	{
		var checkvalue = getHttprequest_FALSE(URL).replace(/<BR\/>/g,'<br>');
	}
	else {
		getHttprequest_TRUE(URL);
		var checkvalue = getId('_ajax_layer_').innerHTML.replace(/<BR\/>/g,'<br>');
	}
	if (!checkvalue) return false;

	var checkarray = checkvalue.split('<br>');
	var checksize = checkarray.length;
	var arr;

	for (i = 0; i < checksize; i++)
	{
		if (checkarray[i] != '')
		{
			arr = checkarray[i].split('|');
			if (arr[0] == 'paper')
			{
				getPaperWin(mdl_minibox,'rcv',arr[1]);
			}
			if (arr[0] == 'friendin' || arr[0] == 'friendout')
			{
				FriendSlideOpen(checkarray[i]);
			}
			if (arr[0] == 'memberin' || arr[0] == 'memberout')
			{
				if(arr[1] != ko_myuid) MemberSlideOpen(checkarray[i]);
			}
			if (arr[0] == 'chat' || arr[0] == 'visit')
			{
				window.open(ko_path_module+mdl_chat+'/chat.php?xsite='+ko_account+'&room='+arr[1]+'&who='+arr[2]+'&que=rcv/'+arr[0] , '', 'left=0,top=0,width=435px,height=250px,scrollbars=no,status=yes');
			}
			if (arr[0] == 'session')
			{
				numLoginUsersGuest = arr[1];
				numLoginUsersMember = arr[2];
				numLoginUsersTotal = parseInt(arr[1]) + parseInt(arr[2]);
			}
			if (arr[0] == 'members')
			{
				getId('strLoginUsersMember').innerHTML = arr[1];
			}
			if (arr[0] == 'guest')
			{
				getId('strLoginUsersGuest').innerHTML = arr[1];
			}
		}
	}
	setTimeout("getMyCheck('"+URL+"',"+flag+")",15000);
}
function getSessCheck()
{
	getMyCheck('./index.php?action=message&a=mycheck&sess_location='+getId('_ajax_layer_').innerHTML,false);
}

document.onclick  = getClickLayerHide;
