///////////////////////////////////////////////////////////
// 사이트 기능관련
// 로그아웃
function logout() {
	document.location = "../member/login_post.html?MD=LOGOUT";
}
// 팝업
function popup(url,ww,hh,scr){
	if (!scr) scr=0;
	var pop = window.open(url,'','width='+ww+',height='+hh+',resizable=0,scrollbars='+scr);
	return pop;
}
// 충전하기
function chargePoint() {
	document.location = '../pay/acount2.html';
//	window.open("../pay/acount.html","pay","width=500,height=520,toolbar=no")
}
function memberInfo(id)
{
	popup("../profile/?id="+id,800,580)
}
document.write("<div id='DivCapsuleKey' style='position:absolute;z-index:99'></div>");
function capsuleOpenKey()
{
	available_width = document.body.clientWidth;
	available_height = document.body.clientHeight;
	scroll_width = document.body.scrollLeft
	scroll_top = document.body.scrollTop;

	window.newAjax = new Ajax;
	newAjax.Method	='POST';
	newAjax.Action	=	'../capsule/key.html';
	newAjax.onComplete		= function(strText){
		if(strText.indexOf("Error:") == 0){alert(strText.replace(/Error:/, ''));}
		else{
			document.getElementById('DivCapsuleKey').style.top = scroll_top + (available_height - 400)/2;
			document.getElementById('DivCapsuleKey').style.left = (available_width - 400)/2;
			document.getElementById('DivCapsuleKey').innerHTML = strText;
		}
	}
	newAjax.submit();


}
function capsuleCloseKey()
{
	document.getElementById('DivCapsuleKey').innerHTML = '';
}
///////////////////////////////////////////////////////////
// 공통 라이브러리 관련

function Ltrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(0)==' '){
           strValue=strValue.substring(1,strValue.length);
   }
       else
          return strValue;
    }
return strValue;
}
function Rtrim(strValue){
    while (strValue.length>0){
       if(strValue.charAt(strValue.length-1)==' '){
           strValue=strValue.substring(0,strValue.length-1);
   }
       else
           return strValue;
   }
   return strValue;
}
function Trim(strValue){
   strValue = Ltrim(strValue);
   strValue = Rtrim(strValue);
   return strValue;
}

function str_replace(szFind, szReplace, szAll) {
	var i;
	var length;

	length = szReplace.length - szFind.length;

	for (i=0; i < szAll.length; i++) {
		if (szAll.substr(i,szFind.length) == szFind) {
			if ( i > 0 ) {
				if (szFind == "\n") {
					szAll = szAll.substr(0, i-1) + szReplace + szAll.substr(i+szFind.length,szAll.length - (i+szFind.length));
				} else {
					szAll = szAll.substr(0, i) + szReplace + szAll.substr(i+szFind.length,szAll.length - (i+szFind.length));
				}
			} else {
				szAll = szReplace + szAll.substr(i+szFind.length,szAll.length - (i+szFind.length));
			}
			i = i + length;
		}
	}
	return szAll;
}

function number_format(num)
{
	var str=''+num;
	var len=str.length;
	var no =len/3;
	var remain=len%3;
	var rv='';
	var str1='';
	var blank=0;
	var Bstr='                                   ';

	for (var i=1;i<=no;i++)
	{
		rv=str.substring(len-i*3,len-(i*3)+3)+rv;
		if (i!=no ) rv=','+rv;
	}
	if (remain) rv=str.substring(0,remain)+rv;


	if (navigator.appName=="Microsoft Internet Explorer")
	{
		rv=Bstr.substring(0,14-rv.length)+rv;
	}
	else
	{
		rv=Bstr.substring(0,14-rv.length)+rv;
	}
	return rv;
}
///////////////////////////////////////////////////////////
// 자바스크립트 쿠키 남기기

function setCookieToday(name,value,expiredays)
{
  var todayDate = new Date();
  todayDate.setDate( todayDate.getDate() + expiredays );
  document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
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 bluring(){
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
}
document.onfocusin=bluring;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

//////////////////////////////////////////////////////////////////////////////////////
var mytop=200;  //처음메뉴의상단위치
function mymenuscroll() {  //스크롤시수행

    //메뉴의상단위치를스크롤의상단위치와비교하여정함
    var m_menu=document.all.mymenu;
    var s_top=document.body.scrollTop
    m_menu.style.top = s_top > mytop ? s_top:mytop;
    m_menu.style.left = (document.body.clientWidth + -980)/2+2;
	if (m_menu.style.display == 'none')
	m_menu.style.display = 'block'

}

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

////////////////////////////////////////////////////////////////////////////////
function login_href_replce(url){
	alert("로그인이 필요합니다!");
	//url = str_replace("?", "%3F", url);
	url = str_replace("&", "%26", url);
	//url = str_replace("=", "%3D", url);
	var re_url = "/member/member_login.html?RETURL=" + url;
	//alert(re_url);
	location.href = re_url;
}


///////////////////////////////////////////////////////////
// 문자열 관련
String.prototype.cut = function(len, tail)
{
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++)
    {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0,i) + tail;
    }
    return str;
}
String.prototype.bytes = function()
{
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++)
        l += (str.charCodeAt(i) > 128) ? 2 : 1;

    return l;
}
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//String.prototype.trim1 = function(){
//    return this.replace(/\s/g, "");
//}

function replaceBackslash(paramStr)
{
    var str = paramStr;
    if (str.indexOf("\\") >= 0) str = str.replace(/\\/g, "\\\\");
    if (str.indexOf("\"") >= 0) str = str.replace(/\"/g, "\\\"");
    return str;
}
