<!--
//===================================================================================================
// FILE : js/common.js
// DESC : 공통 javascript
//===================================================================================================

//OpenCy namespace
var OpenCy = {};
OpenCy.appstore_domain = "http://appstore.nate.com";
OpenCy.devsquare_domain = "http://devsquare.nate.com";
OpenCy.fs_domain = "http://fsds.nate.com";

function logout(strRedirect) {
	location.href="http://xo.nate.com/rlogout.jsp?redirect="+strRedirect;
}



//---------------------------------------------------------------------------------------------------
// 도메인 값 가져오기
//---------------------------------------------------------------------------------------------------
function getDomain() {
	var domain = document.domain;
	var pattern = /([a-zA-Z]*)\.com$/;
	if ( (result = pattern.exec(domain)) != null ) {
		return result[0];
	}
}

//---------------------------------------------------------------------------------------------------
// 팝업
//---------------------------------------------------------------------------------------------------
function OpenPopup(url, width, height, target, option) {
	if (width == null)
		width = 500;
	if (height == null)
		height = 500;
	if (option == "") {
		var option = "left=0, top=0, toolbar=0,menubar=0,scrollbars=yes,resizable=no";
	}

//    var viewpage = window.open(url, target, option+',width='+width+',height='+height);
//    if (viewpage != null)
//		viewpage.focus();
	try {
		viewpage = window.open(url, target, option+',width='+width+',height='+height);
	
		if (viewpage != null)
			viewpage.focus();
	} catch(e)
	{
		target.location = url;
		if (viewpage != null)
			viewpage.focus();
	}
}
 
//---------------------------------------------------------------------------------------------------
// 페이지 이동
//---------------------------------------------------------------------------------------------------
function movePage(url) {
	var intArgs = arguments.length;
	if (intArgs == 2) {statClick(arguments[1]);}
	window.location.href = url;
}


//---------------------------------------------------------------------------------------------------
// 특정시간 이후 함수 호출
//---------------------------------------------------------------------------------------------------
function countTime(url,second) {
	setTimeout("movePage(\""+url+"\")", second);
}

//---------------------------------------------------------------------------------------------------
// 문자열 byte수
//---------------------------------------------------------------------------------------------------
function StringSize (s) {
	var i;
	var len = 0;
	for ( i=0 ; i<s.length; i++) {
		if ( s.charCodeAt(i) > 255 ) {
			//len ++;
			len += 2;
		} else {
			len ++;
		}
	}
	return len;
}

//---------------------------------------------------------------------------------------------------
// 쿠키값 가져 오기
//---------------------------------------------------------------------------------------------------
function GetCookie(name,escape){ 
    var cname = name + "=";               
    var dc = document.cookie;             
 
    if (dc.length > 0) {              
     begin = dc.indexOf(cname);       
        
        if (begin != -1) {           
         begin += cname.length;       
         end = dc.indexOf(";", begin);
 
         if (end == -1) end = dc.length;
			if ( escape != null ) {
				return dc.substring(begin, end);
			} else {
				return unescape(dc.substring(begin, end));
			}
        } 
    }
    return "";
} 

//---------------------------------------------------------------------------------------------------
// 쿠키생성
//---------------------------------------------------------------------------------------------------
function setCookie(name,value,expires,path,domain,secure)
{
   var argv = setCookie.arguments;
   var argc = setCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;

   document.cookie = name + "=" + value +
     ((expires == null) ? "" : ("; expires="+expires.toGMTString())) +
     ((path == null) ? "" : ("; path=" + path)) +
     ((domain == null) ? "" : ("; domain=" + domain)) +
     ((secure == true) ? "; secure" : "");
}

//---------------------------------------------------------------------------------------------------
// 쿠키 삭제
//---------------------------------------------------------------------------------------------------
function DelCookie( name, path, domain ) {
	var value = GetCookie(name);
	var	domain = getDomain();
	if ( value != '' && value.length > 0 ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function email_chk(strEmail){
	re=/^[0-9a-zA-Z-_\.]*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i; 
 
	if(re.test(strEmail)) { 
		return true; 
	} else {
		return false; 
	} 

}


//---------------------------------------------------------------------------------------------------
// 네이트 로그인
//---------------------------------------------------------------------------------------------------
function loginNate(strRedirect)
{
	if (strRedirect == '' || strRedirect == null)
		strRedirect = location.href;

		strRedirect =  strRedirect.split("http://appstore.nate.com/")[1];

	location.href = 'https://xo.nate.com/login.jsp?redirect=http://appstore.nate.com/main/loginRedirect?r_url='+strRedirect;
	
}



//---------------------------------------------------------------------------------------------------
// 레이어 센터 정렬
//---------------------------------------------------------------------------------------------------

function centerLayer(strLayerId) {
	obj_centerLayer = document.getElementById(strLayerId);
	obj_centerLayer.style.display='';
	centerLayerMove(strLayerId);
}
function centerLayerMove(strLayerId) {
	obj_centerLayer = document.getElementById(strLayerId);
	
    var bodyWidth    = document.documentElement.clientWidth; 
	var bodyHeight    = document.documentElement.clientHeight;
	
    var divWidth    = obj_centerLayer.offsetWidth; 
    var divHeight    = obj_centerLayer.offsetHeight; 
	
	if (typeof document.body.style.maxHeight != "undefined") {
		bodyWidth    = document.body.clientWidth; 
		bodyHeight    = document.body.clientHeight; 
		if (!!(window.attachEvent && !window.opera)) { //IE 7 ~
			pageLeft = document.documentElement.scrollLeft;
			pageTop = document.documentElement.scrollTop;
		} else { //FF
			pageLeft = window.pageXOffset;
			pageTop = window.pageYOffset;
		}
	} else {// IE 6
		pageLeft = document.documentElement.scrollLeft;
	    pageTop = document.documentElement.scrollTop;
	}


    
                /*
    if (window.innerWidth) { // All browsers but IE
    	bodyWidth    = document.body.clientWidth; 
    	bodyHeight    = document.body.clientHeight; 
	    pageLeft = window.pageXOffset;
	    pageTop = window.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.clientWidth) {
		bodyWidth    = document.body.clientWidth; 
    	bodyHeight    = document.body.clientHeight;
	    pageLeft = document.documentElement.scrollLeft;
	    pageTop = document.documentElement.scrollTop;
	}
	else if (document.body.clientWidth) {
	    pageLeft = document.body.scrollLeft;
	    pageTop = document.body.scrollTop;
	}
	*/

    var divLeft = pageLeft, divTop = pageTop; 

    if(bodyWidth > divWidth) { 
        divLeft = pageLeft + Math.ceil((bodyWidth - divWidth) / 2); 
    }
    
    if(bodyHeight > divHeight) {
        divTop = pageTop + Math.ceil((bodyHeight - divHeight) / 2); 
    } 

	obj_centerLayer.style.left = divLeft+"px";
	obj_centerLayer.style.top = divTop+"px";
    if (obj_centerLayer.style.display == '') {
    	setTimeout(function() { centerLayerMove(strLayerId);}, 100);
    }
}

//---------------------------------------------------------------------------------------------------
// 레이어 닫기
//---------------------------------------------------------------------------------------------------

function closeLayer(strLayerId) {
	document.getElementById(strLayerId).style.display='none';
}

//---------------------------------------------------------------------------------------------------
// 레이어 하나만 열기
//---------------------------------------------------------------------------------------------------
g_str_openLayerName = '';
function onlyOpenLayer(strLayerId) {
	if (g_str_openLayerName !='') closeLayer(g_str_openLayerName);
	centerLayer(strLayerId);
	g_str_openLayerName = strLayerId;
}


//---------------------------------------------------------------------------------------------------
// 미니 홈피로 가기
//---------------------------------------------------------------------------------------------------

function goMiniHomePage(cy_id) {
	OpenPopup("https://xo.nate.com/cysso/cysso.jsp?from=na&r_url=http://minihp.cyworld.com/pims/main/pims_main.asp?tid="+cy_id, 930, 550, cy_id, "");
}

function goMiniHomePageMyApps(cy_id) {
	OpenPopup("https://xo.nate.com/cysso/cysso.jsp?from=na&r_url=http://minihp.cyworld.com/pims/main/pims_myapps.asp?tid="+cy_id+"", 930, 550, cy_id, "");
}

function goMiniHomePageNewCookie(cy_id) {
	OpenPopup("https://xo.nate.com/cysso/cysso.jsp?from=na&r_url=http://minihp.cyworld.com/pims/main/pims_main.asp?nc_refresh=1&tid="+cy_id, 930, 550, "", "");
}

//---------------------------------------------------------------------------------------------------
// URL 형태 확인
//---------------------------------------------------------------------------------------------------
function checkDetailUrl(strUrl) {
    //var expUrl = /^(http\:\/\/)?([0-9a-zA-Z-_]*)+(.)+(asia|biz|cc|cn|com|de|eu|in|info|jobs|jp|kr|mobi|mx|name|net|nz|org|travel|tv|tw|uk|us)(\/(\w*))*$/i;
    //return expUrl.test(strUrl);
	var expUrl = /^([a-z]+):\/\/((?:[a-z가-힣\d\-]{2,}\.)+[a-z]{2,})(:\d{1,5})?(\/[^\?]*)?(\?.+)?$/i;
	return expUrl.test(strUrl);
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
//---------------------------------------------------------------------------------------------------
// 네이트 싸이월드 연동 팝업
//---------------------------------------------------------------------------------------------------

function registCySSO(strUrl) {
	var intArgs = arguments.length;
	var isPopUp = 'Y';
	if (intArgs == 2) { isPopUp = arguments[1]; }
	OpenPopup('https://member.nate.com/sso/regist/registCySSO.jsp?r_url='+strUrl+'&isPopUp='+isPopUp,300,300,'CySSO','scrollbars=auto');
}

//
function nateMemberInfo() {
	window.open('http://helpdesk.nate.com/faq/exMemberInfo.asp?height=1500&r_url=http://xso.nate.com/login.jsp?redirect=https://member.nate.com/sccustomer/join/nate/modify/CheckPassword_index.jsp?height=1400');

}


function registNateSSO(strUrl) {
	var intArgs = arguments.length;
	var isPopUp = 'Y';
	if (intArgs == 2) { isPopUp = arguments[1]; }
	OpenPopup('https://cymember.cyworld.com/member/sso/registNateSSO.jsp?r_url='+strUrl+'&isPopUp='+isPopUp,300,300,'','scrollbars=auto');
}

//---------------------------------------------------------------------------------------------------
// 문자열 자르기(한글처리 포함)
//---------------------------------------------------------------------------------------------------

function cutString(str, len, tail) {
    var l = 0;
    if (str == null) return str;
    
    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;
}


//---------------------------------------------------------------------------------------------------
// 팝업창 이미지
//---------------------------------------------------------------------------------------------------
/*
function popup_ImgView(img_src) {
	var img_view = img_src; 
	var x = x + 20 ;  //var x = x + 20 ;
	var y = y + 30 ;  //var y = y + 30 ;
	var shight = screen.height-100; //전체화면에서 창여백주기
	var swidth = screen.width-50; //전체화면에서 창여백주기
	htmlz = "<html><head><title>이미지크게보기</title><style>body{margin:0;cursor:hand;}</style></head><body scroll=auto onload='width1=document.all.Timage.width;if(width1>"+swidth+")width1="+swidth+";height1=document.all.Timage.height;if(height1>"+shight+")height1="+shight+";top.window.resizeTo(width1+30,height1+54);' onclick='top.window.close();'><img src='"+img_view+"'  title='클릭하시면 닫힙니다.' name='Timage' id='Timage'></body></html>" 
	imagez = window.open('', "image", "width="+ 100 +", height="+ 100 +", top=0,left=0,scrollbars=auto,resizable=1,toolbar=0,menubar=0,location=0,directories=0,status=1"); 
	imagez.document.open(); 
	imagez.document.write(htmlz)
	imagez.document.close(); 
}
*/
/*
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ";path=/"+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
*/
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function goForum() {
	statPage("cyworld_ndretc.com/devsquare/forum/");
	window.open('http://club.cyworld.com/devsquare');
}

/*
function goForum() {
	strLang = getCookie('lang');
	if(strLang == "en_US") fnShowModalLayer('divForumEng');
	else fnShowModalLayer('divForumKor');
}
*/
	
function moveForum() {
	window.open('http://club.cyworld.com/devsquare');
	strLang = getCookie('lang');
	if(strLang == "en_US") fnCloseModalLayer('divForumEng');
	else fnCloseModalLayer('divForumKor');

}

//ModalLayerShow
function fnShowModalLayer(strLayerId){
	$('#message').modal({
			close:false,
			position: ["30%","32%"],
			overlayId:'viewModalOverlay',
			containerId:'viewModalContainer', 
			onShow: function (dialog) {
				var html = document.getElementById(strLayerId).innerHTML;
				dialog.data.find('.message').html(html);
			}
		});
}
//ModalLayerClose
function fnCloseModalLayer(){
		$.modal.close();
}



function imageResize(maxSize)
{
	var imgs = document.getElementsByTagName('img');
    var max = maxSize; // fixed size
    for (var i = 0; i < imgs.length; i++) {
     try {
      var img = imgs[i];
      if (img.width > max) {
       var ratio = parseFloat(max / img.width);
       var h = parseInt(img.height * ratio);
       var w = max;
       
       img.height = h;
       img.width = w;
       img.style.height = h;
       img.style.width = w;
       img.setAttribute('espresso:resized', '1');
      }
     }
     catch(e) {}
    } 
}


//---------------------------------------------------------------------------------------------------
// 문자열 공백 제거
//---------------------------------------------------------------------------------------------------
function strTrim(str){
	return str.replace(/(^\s*)|(\s*$)/g, "");
}


//---------------------------------------------------------------------------------------------------
// 팝업 리사이즈
// 사용법 window.onload = function() {autoResizePopup(1000,600);}
//---------------------------------------------------------------------------------------------------
function autoResizePopup(int_max_width, int_max_height) {
	var winW, winH, sizeToW, sizeToH;
	bodyWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
	bodyHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
	
	if (window.innerWidth) {
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else {
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}

	sizeToW = 0; sizeToH = 0;
	sizeToW = (winW - bodyWidth) * -1;
	sizeToH = (winH - bodyHeight) * -1;
	
	if (sizeToH+winH > int_max_width)
		sizeToW = int_max_width - winW;
	
	if (sizeToH+winH > int_max_height)
		sizeToH = int_max_height - winH;

	if ( sizeToW != 0 || sizeToH != 0 )
		window.resizeBy(sizeToW, sizeToH);
}

//-->

//popup resize
function fnResizePopup(idPopupSize) {
    var nWidth = 0;
    var nHeight = 0;
    var objParent = document.getElementById(idPopupSize);
    if(document.all && document.getElementById)
    {
        var x = document.body.offsetWidth;
        var y = document.body.offsetHeight;
        window.resizeTo(500, 500);
        nWidth = 500 - document.body.offsetWidth + x;
        nHeight = 500 - document.body.offsetHeight + y;
        window.resizeTo(nWidth, nHeight);
    }
    else
    {
        nWidth = window.outerWidth;
        nHeight = window.outerHeight;
    }
        
    nWidth -= document.body.clientWidth;
    nHeight -= document.body.clientHeight;
        
    if(objParent)
    {
        window.resizeTo(objParent.offsetWidth + nWidth, objParent.offsetHeight + nHeight);
    }
}

function cyProfileImage_swf(str_id, str_path, int_width, int_height) {
	var retStr;
		var isNotIE;
		if(navigator.appName != 'Microsoft Internet Explorer') isNotIE = true; else isNotIE = false;
		if (isNotIE)
		retStr = "<object id=\"" + str_id + "\" height=\"" + int_height + "\" align=\"middle\" width=\"" + int_width + "\" allowscriptaccess=\"always\" allowfullscreen=\"false\" menu=\"true\" bgcolor=\"#ffffff\" devicefont=\"false\" scale=\"noscale\" loop=\"true\" play=\"true\" quality=\"high\" flashvars=\"\" wmode=\"transparent\" data=\"" + str_path + "\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" style=\"outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;\"><h1>Alternative content</h1><p><a href=\"http://www.adobe.com/go/getflashplayer\"><img alt=\"Get Adobe Flash player\" src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\"/></a></p></object>";
	else
		retStr = "<object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" id=\"" + str_id + "\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"" + int_width + "\" height=\"" + int_height + "\" align=\"middle\" ><param name=\"movie\" value=\"" + str_path + "\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"flashvars\" value=\"\" /><param name=\"quality\" value=\"high\" /><param name=\"play\" value=\"true\" /><param name=\"loop\" value=\"true\" /><param name=\"scale\" value=\"noscale\" /><param name=\"devicefont\" value=\"false\" /><param name=\"bgcolor\" value=\"#ffffff\" /><param name=\"menu\" value=\"true\" /><param name=\"allowFullScreen\" value=\"false\" /><param name=\"allowScriptAccess\" value=\"always\" /><h1>Alternative content</h1><p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></p></object>";
	retStr += "<noscript><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" width=\"970\" height=\"355\" id=\"" + str_id + "\" style=\"outline:none;\" ><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowFullScreen\" value=\"false\" /><param name=\"movie\" value=\"" + str_path + "\" /><param name=\"wmode\" value=\"transparent\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\""+ str_path + "\" width=\"" + int_width + "\" height=\"" + int_height + "\"><!--<![endif]--><param name=\"wmode\" value=\"transparent\" /><h1>Require flash player</h1><p><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></p><!--[if !IE]>--></object><!--<![endif]--></object></noscript>";
	return retStr;
}

function htmlDecode(strValue) {
	strValue = strValue.replace(/\\\\/g, "\\");
	strValue = strValue.replace(/\\&quot;/g, "\"");
	strValue = strValue.replace(/\\&#039;/g, "'");
	//strValue = strValue.replace('&lt;', '<');
	//strValue = strValue.replace('&gt;', '>');
	//strValue = strValue.replace(/&amp;/g, '&');
	return strValue;
}

function moveLocation(LocName) {
	var objs = document.getElementsByName(LocName);
	if (LocName == "" || LocName == "top") document.body.scrollTop = 0;
	if (objs == null || objs.length==0) return false;
	if (typeof moveLocation.obj == "undefined") {
	moveLocation.obj = document.createElement("A");
	moveLocation.obj.href="#";
	document.body.appendChild(moveLocation.obj);
	}

	//focus on the bottom of the page
	moveLocation.obj.style.display = "";
	moveLocation.obj.focus();
	moveLocation.obj.style.display = "none";

	if (objs[0].tagName.toLowerCase() == "a") {
	var ref = objs[0].href;
	objs[0].href = "#";
	objs[0].focus();
	if (ref=="") objs[0].removeAttribute("href");
	else objs[0].href = ref;
	} else {
	objs[0].focus();
	}

	objs[0].blur();

	return false;
} 

