//document.domain = "fanpy.net";

var myGlobalHandlers = {
		onCreate : function () {
				Element.show('systemWorking');
		},

		onComplete : function () {
				if(Ajax.activeRequestCount == 0) {
						Element.hide('systemWorking');
				}
		}
};


// 문자열 관련 함수
var SF = {};
SF.Main = function () {
	return {
		eregi: function (exp, str, min, max) {
			var regExpr;
			var regExprMust;

			regExpr = new RegExp(exp, "gi");

			if ( (min != undefined && max != undefined) || (min != "" && max != "")) {
				regExprMust = new RegExp( ".{" + min + "," + max + "}" );
				if ( str.match(regExprMust) == null ) // check : length
					return false;
			}

			if ( exp != undefined && exp != "") {
				if ( str.match(exp) != null )
					return false;
			}

			return true;
		},
		eregi_replace: function (ereg, dest, str) {
			ereg = eval("/"+ereg+"/gim");
			return str.replace(ereg, dest);
		}
	};
}();



// 게시물 리스트 checkbox 전체선택/취소 하기
function checkall(formname,checkname,thestate){
	var el_collection=eval("document.forms."+formname+"."+checkname)

	if(el_collection != null)
	{
		if(el_collection.length){
			for (c=0;c<el_collection.length;c++)
				el_collection[c].checked=thestate
		}
		else{
			el_collection.checked=thestate;
		}
	}
}

// ====================================================================
// 이미지 ReSize 처리 - 이봉구(08.08.06)
// ====================================================================
function SetImgResize(sName, iWidth) {
	var objImages = document.getElementsByName(sName);

	for (i=0; i < objImages.length; i++) {
		imgWidth	= objImages[i].width;
		imgHeight	= objImages[i].height;

		if (parseInt(imgWidth) > parseInt(iWidth)) {
			calc_height = parseInt(GetCalImageSize(parseInt(imgWidth), parseInt(imgHeight), iWidth, "Y"));
			calc_height = ( calc_height > 160 ) ? 160 : calc_height;

			objImages[i].setAttribute("width", iWidth);
			objImages[i].setAttribute("height", calc_height);
		}
	}
}

function GetCalImageSize (width, height, newsize, gubun) {
	var size = 0;

	if (gubun == "X")
		size = (width * newsize) / height;
	else
		size = (height * newsize) / width;
	
	size = parseInt(size);
	if ( size < 0 )
		size = 0;

	return size;
}
// ====================================================================

// error
function reportError(request) {
	alert(request);
}


// 팝업 관련 2008-08-11 이현우 

function fncOpenWin(strUrl, strName, intW, intH, blnPos, blnScroll) 
{
	var Win;
	var strScroll;

	if (blnPos == 0)
	{
		var strLeft = 0	// 새창을 화면 왼쪽으로 위치하게(가로위치)
		var strTop = 0	// 새창을 화면 위쪽으로 위치하게(세로위치)		
	}
	else
	{
		var strLeft = (window.screen.width / 2) - (intW / 2)	// 새창을 화면 가운데로 위치하게(가로위치)
		var strTop = (window.screen.height / 2) - (intH / 2)	// 새창을 화면 가운데로 위치하게(세로위치)
	}
	if(blnScroll == 0)
	{
		strScroll = 'no';
	}
	else
	{
		strScroll = 'yes';
	}

	Win = window.open(strUrl, strName, "width=" + intW + ", height=" + intH + ", top="+ strTop +", left="+ strLeft +", scrollbars="+ strScroll);
	Win.focus();
}


// 컨펌문을 통해 윈도우 오픈
function fncOpenWinWithConfirm(strMsg,strName,strUrl, intW, intH, blnPos, blnScroll)
{
	if(confirm(strMsg))
	{
		fncOpenWin(strUrl,strName ,intW, intH, blnPos, blnScroll);
	}
}



// lightbox 사용 =======================================================================
function HideAllDiv() {
	if(  $("divMemJoinEnd")  ) {  Element.hide('divMemJoinEnd'); }
	if(  $("divFindPwd")  ) {  Element.hide('divFindPwd'); }
	if(  $("divConfirmPwd")  ) {  Element.hide('divConfirmPwd'); }
	if(  $("divFindId")  ) {  Element.hide('divFindId'); }
	if(  $("divFindIdResult")  ) {  Element.hide('divFindIdResult'); }
	if(  $("divModifyId")  ) {  Element.hide('divModifyId'); }
	if(  $("divModifyIdResult")  ) {  Element.hide('divModifyIdResult'); }
}

function ShowDiv(objID) 
{
	var arrayPageSize = getPageSize();	// pageWidth,pageHeight,windowWidth,windowHeight
	// stretch overlay to fill page and fade in
	Element.setWidth("overlay", arrayPageSize[0]);
	Element.setHeight("overlay", arrayPageSize[1]);


//	new Effect.Appear("overlay", { duration: overlayDuration, from: 0.0, to: overlayOpacity });

	iWidth = 295;
	iHeight = 10;

	// calculate top and left offset for the lightbox
	tMargin = (arrayPageSize[1] / 2) - 300;
	lMargin = (arrayPageSize[0] / 2) - (iWidth / 2);

	var lightboxTop		= 150;	//tMargin;
	var lightboxLeft	= lMargin;

	Element.setTop(objID, lightboxTop);
	Element.setLeft(objID, lightboxLeft);

	HideAllDiv();
	Element.show(objID);
//	new Effect.Appear(objID, { duration: resizeDuration, queue: 'end', afterFinish: function(){ } });
}

function HideDiv(objID) {
	showSelectBoxes();
	showFlash();

//	new Effect.Fade('overlay', { duration: overlayDuration});
	Element.hide(objID);
}
// lightbox 사용 =======================================================================



function cal_byte(str) {
			var tmpStr;
			var temp=0;
			var onechar;
			var tcount;
			tcount = 0;

			str = str.replace(/cR_/g,''); //엔터문자 제거
			tmpStr = new String(str);
			temp = tmpStr.length;

			for (k=0;k<temp;k++) {
				onechar = tmpStr.charAt(k);
				if(escape(onechar).length > 4) {
					tcount += 2;
				}else if (onechar!='\r') {
					 tcount++;
				}
			}

			return tcount ;
		}

// 앞뒤 공백제거 
function trim(str){
 var i,j = 0;
 var objstr;
 for(i=0; i< str.length; i++){
  if(str.charAt(i) == ' ')
   j=j + 1;
  else 
   break;
 }
 str = str.substring(j, str.length - j + 1);
 
 i,j = 0;
 for(i = str.length-1;i>=0; i--){
  if(str.charAt(i) == ' ')
   j=j + 1;
  else 
   break;
 }
 return str.substring(0, str.length - j);
} 



//쪽지
function message_send(mem_id, mem_nname, targetURL) 
{
	window.open("http://www.fanpy.net/fanpy/message/msg_send.fpy?to_mb_code="+mem_id+"&to_nickname="+escape(mem_nname)+"&targetUrl="+targetURL,"msgs", "width=502,height=573,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=150,top=0");
}
// 선택 쪽지 보내기 ( input_name : mb_code 정의된 체크박스 name , input_nick : nickname 정의된 hidden 체크박스 name )
function multi_message_send(input_name, input_nick)
{
	var iname	= document.getElementsByName(input_name);
	var inick	= document.getElementsByName(input_nick);
	if(  iname	)
	{
		var from_mb_code	= "";
		var from_nickname	= "";
		for(var idx=0; idx < iname.length; idx++)
		{
			if(  iname[idx].checked == true  ){
				from_mb_code  += (  from_mb_code !=""  )? ","+iname[idx].value  :  iname[idx].value;
				from_nickname += (  from_nickname!=""  )? ","+inick[idx].value  :  inick[idx].value;
			}
		}
		if(  from_mb_code == ""  )
		{
			alert("메시지 발송할 회원을 선택해주세요!");
			return;
		}
		message_send(from_mb_code,from_nickname,'');
	}
}

//뻐꾸기
function cuckoo_send(mem_id,mem_nname,pi_file, home_id) 
{ 
	 window.open("http://fanpy.pullbbang.com/message/cuckoo_send.pull?to_mb_code="+mem_id+"&to_nickname="+mem_nname+"","cuck", "width=799,height=470,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=150,top=0");
}

function change_all()
{
	if(document.form1.checkbox.value == "N") {
		document.form1.checkbox.value="Y";
		checkall('form1','to_nickname',true);
	}
	else {
		document.form1.checkbox.value="Y";
		document.form1.checkbox.value="N";
		checkall('form1','to_nickname',false);
	}
}

var strAllchk = false;
function checkall(formname,checkname,thestate){
	if(  strAllchk	== false ){
		if (thestate == strAllchk) thestate = true;
	}else if( strAllchk	== true ){
		if (thestate == strAllchk) thestate = false;
	}
	strAllchk	= thestate;


	var el_collection=eval("document.forms."+formname+"."+checkname)

	if(el_collection != null)
	{
		if(el_collection.length){
			for (c=0;c<el_collection.length;c++)
				el_collection[c].checked=thestate
		}
		else{
			el_collection.checked=thestate;
		}
	}
}

function message_send_multi()
{
	
  var check_nums = document.form1.elements.length;

	alert(check_nums);
   
   for(var i = 0; i < check_nums; i++) {
      var checkbox_obj = eval("document.form1.elements[" + i + "]");
      if(checkbox_obj.checked == true) {
         break;
      }
   }
   if(i == check_nums) {
      alert("쪽지 보내실 분을 선택하세요");
      return;  
   }
	
	window.open("", "winName", "width=522, height=573,resizable=0,scrollbars=no");
	document.form1.method="post";
	document.form1.target="winName";
	document.form1.action="/fanpy/message/msg_send.fpy";
	document.form1.submit(); 

}//쪽지 끝

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
선택회원 선물하기 => 2008.03.26 임경재
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function gift_target_list(mb_code) {
	if (mb_code.length > 0 || mb_code > 0)
	{
//		hideProcFrame.location.href="http://www.pullbbang.com/mall/gift_target_list.pull?mb_code="+mb_code;
		fncOpenWin("/fanpy/message/pop_gift.fpy?select_mb_code="+mb_code, "fgift", "410", "575", 100, 0);
	}
}

///////////////////////////////////////////////////////
//	내팬피로 초대 시작
///////////////////////////////////////////////////////
function invite_request(mb_code) 
{
	if (confirm("내팬피로 초대를 하시면 단팥 5개가 차감됩니다.")) {
		var url = '/fanpy/message/invite_ok.fpy';
		var pars;
		pars = "mbc="+mb_code;
		var loader = new Ajax.Request(
			url,
			{
				method : 'get',
				parameters: pars,
				onComplete: function (r) {
					objJSON = eval('(' + r.responseText + ')');
					alert(objJSON[0].msg);
				}
			}
		);
	}
}
// 선택 초대하기 ( input_name : mb_code 정의된 체크박스 input name)
function setMultiInvite(input_name)
{
	var iname	= document.getElementsByName(input_name);
	if(  iname	)
	{
		var from_mb_code	= "";
		for(var idx=0; idx < iname.length; idx++)
		{
			if(  iname[idx].checked == true  ){
				from_mb_code += (  from_mb_code!=""  )? ","+iname[idx].value  :  iname[idx].value;
			}
		}
		if(  from_mb_code == ""  )
		{
			alert("내팬피에 초대할 회원을 선택해주세요!!!");
			return;
		}
		invite_request(from_mb_code);
	}
}
///////////////////////////////////////////////////////
//	내팬피로 초대 끝
///////////////////////////////////////////////////////


/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
2008.02.25 임경재 추가
몰래찜하기 시작
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function zzim_ok(mbc) {
	if (!confirm(" 몰래찜하기 하시겠습니까? ")) {
		return;
	}

	Ajax.Responders.register(myGlobalHandlers);
	var url = '/fanpy/zzim/write.fpy';
	var pars;
	pars = "mbc="+mbc;
	var loader = new Ajax.Request(
		url,
		{
			method : 'get',
			parameters: pars,
			onComplete: zzim_ok_Ajax,
			onFailure: getErrorDataView
		}
	);
}

function zzim_ok_Ajax(loader){
	var getReplyList = loader.responseText;
	alert(getReplyList);
}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
몰래찜하기 끝
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/


/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
Active Flash script
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// flashWrite(파일경로, 가로, 세로, 아이디, 배경색, 변수, 윈도우모드)
function flashWrite(url,w,h,id,bg,vars,win){

	// 플래시 코드 정의
	var flashStr=
	"<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"'>"+
	"<param name='movie' value='"+url+"' />"+
	"<param name='FlashVars' value='"+vars+"' />"+
	"<param name='quality' value='high' />"+
	"<param name='bgcolor' value='"+bg+"' />"+
	"<param name='allowScriptAccess' value='always' />"+
	"<param name='wmode' value='"+win+"' />"+
	"<param name='menu' value='false' />"+
	"<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' id='"+id+"' align='middle' play='true' loop='false' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>";

	// 플래시 코드 출력
	document.write(flashStr);

}
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/



/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
2008.11.10 남원일 추가
이벤트 페이지 팬등록하기 시작
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function FanRegister2(mbc, act) {

	var pars = "mbc="+mbc+"&act="+act+"&r=" + Math.floor(Math.random()*99999);

	var objAjax = new Ajax.Request(
		"http://event.fanpy.net/Bmw/fan_reg.pull",
		{
			method : 'get',
			parameters: pars,
			onComplete: GetValFanReg,
			onFailure: getErrorDataView
		}
	);
}
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
2008.08.23 임경재 추가
팬등록하기 시작
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function FanRegister(mbc, act) {

	var pars = "mbc="+mbc+"&act="+act+"&r=" + Math.floor(Math.random()*99999);
	var objAjax = new Ajax.Request(
		"/common/asp/fan_reg.fpy",
		{
			method : 'get',
			parameters: pars,
			onComplete: GetValFanReg,
			onFailure: getErrorDataView
		}
	);
}
// 선택 팬등록하기 ( input_name : mb_code 정의된 체크박스 input name)
function MultiFanRegister(input_name)
{
	var iname	= document.getElementsByName(input_name);
	if(  iname	)
	{
		var mb_code	= "";
		for(var idx=0; idx < iname.length; idx++)
		{
			if(  iname[idx].checked == true  ){
				mb_code += (  mb_code!=""  )? ","+iname[idx].value  :  iname[idx].value;
			}
		}
		if(  mb_code == ""  )
		{
			alert("팬등록 하려는 회원을 선택해주세요!!!");
			return;
		}
		FanRegister(mb_code,"");
	}
}
function GetValFanReg(rst) {
	try
	{	
		//alert(rst.responseText);
		objJSON = eval('(' + rst.responseText + ')');

		pageAction(objJSON.msg, objJSON.act);
	}
	catch (err) {
			alert(err);
	}
}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
팬등록하기 끝
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/


function getErrorDataView(oriMsg) {
//	alert(oriMsg);
}



function goLogin(refURL) {
	if (refURL == undefined) refURL = '';
	top.location.href = "http://www.fanpy.net/login/refURL="+refURL;
}

function strTrim(str)	// 문자열 공백 제거함수
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

function emailValidation(email) {
//	emailMatch = new RegExp(/^[A-Za-z0-9]{1,12}@[A-Za-z0-9]{2,12}\.[A-Za-z0-9]{2,12}/g);	// email --->   (1자~12자) @ (2자~12자) . (2자~12자)
	emailMatch = new RegExp(/^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[A-Za-z0-9]{2,12}\.[A-Za-z0-9]{2,12}/g);	// email --->   (1자~12자) @ (2자~12자) . (2자~12자)
	emailValue = strTrim(email);
	return emailMatch.test(emailValue);
}


/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
2008.09.01 임경재 추가
그룹등록 시작
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function groupMemReg(grc, act) {

	var pars = "grc="+grc+"&act="+act;
	
	var objAjax = new Ajax.Request(
		"/common/asp/group_mem_reg.fpy",
		{
			method : 'get',
			parameters: pars,
			onComplete: GetValFanReg,
			onFailure: getErrorDataView
		}
	);
}
/* 남원일 추가 2008-09-25 */
function groupJoinChk(grc)
{
	var nflag = confirm("그룹에 가입을 하시면 게시물을 열람 할 수 있습니다.\r\n지금 가입하시겠습니까?");
	if( nflag == true )
	{
		groupMemReg(grc, "NR");
	}
	return;
}
// 그룹 탈퇴
function groupMemDel(grc, act) {

	var pars = "grc="+grc+"&act="+act;

	var objAjax = new Ajax.Request(
		"/common/asp/group_mem_del.fpy",
		{
			method : 'get',
			parameters: pars,
			onComplete: GetValFanReg,
			onFailure: getErrorDataView
		}
	);
}
function groupRegConfirm(gcode, act, classNm, gname)
{
	if(  classNm == "J"  ) {
		nf = confirm("\""+gname+"\" 그룹에 가입하시겠습니까?");
	} else if(  classNm == "D"  ) {
		nf = confirm("\""+gname+"\" 그룹에서 탈퇴하시겠습니까?");
	}

	if(  nf  )
	{
		if(  classNm == "J"  ) {
			groupMemReg(gcode, act);
		} else if(  classNm == "D"  ) {
			groupMemDel(gcode, act);
		}
	}
}

function GetValFanReg(rst) {
	try
	{	
//		alert(rst.responseText);
		objJSON = eval('(' + rst.responseText + ')');
		pageAction(objJSON.msg, objJSON.act);
	}
	catch (err) {
//			alert(originalRequest);
//			alert(err.number);
//			alert(err.description);
	}

}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
그룹등록 끝
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
2008.09.01 임경재 추가
메세지 출력후 페이지 엑션
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function pageAction(msg, act) {
	alert(msg);
	if (act == "PR") { //리로드
		parent.location.reload();
	} else if (act == "WC") { //새창일 경우 닫기
		window.close();
	} else if (act == "PW") { //부모창 리로드, 새창 닫기
		opener.location.reload();
		window.close();
	} else if (act == "NR") { //현재창 리로드
		document.location.reload();
	}
}



/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
Member Tags Click Search
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function goTagFriend(strTag, intTagCode)
{
	top.location.href = "http://www.fanpy.net/tag_match/" + strTag;
}

function goTagFanpy(strTag, intTagCode) {
	location.href = "/fanpy/profile/tag_search.fpy?tag=" + strTag;
}


/* 남원일 추가 */
function listenMusic(mp_code) {
	var bgmPlayerWin = fncOpenWin("/common/asp/muisc_player.fpy?mp_codes="+mp_code, "bgmPlayerWin", 362, 330, 1, 0);
}
function MusicSelect(formname,checkname,act) {
	var el_collection=eval("document.forms."+formname+"."+checkname)
	
	var mpCode = "";
	if(el_collection != null)
	{
		if(el_collection.length){
			for (c=0;c<el_collection.length;c++)
			{
				if(  el_collection[c].checked == true )
				{
					mpCode += ( mpCode != "" )? "," + el_collection[c].value : el_collection[c].value
				}
			}
		}
		else{
			if(	  el_collection.checked == true )
				mpCode = el_collection.value
		}
	}
	if(  mpCode!= "" ) 
	{
		if(  act == "listen"  ) // 듣기 
		{	
			listenMusic(mpCode);
		}
		else if (act == "cart") // 담기
		{
			cartMusic(mpCode);
		}
		else if (act == "gift") // 선물
		{
			giftBGM(mpCode);
		}
		else if (act == "cartpop") // 담기 팝업
		{
			setMusic('',mpCode,'');
		}

			
	}
	else
	{
		alert("음악을 선택하여 주세요");
	}
}

function cartMusic(mp_code)
{
	var bgmPlayerWin = fncOpenWin("/shop/popup_MusicCart.fpy?mp_codes="+mp_code, "bgmPlayerWin", 380, 420, 1, 0);
}


// 음악 담기
function setMusic(mm_code, mp3_code, SelIndex)
{	

	
	if (window.confirm('택하신 곡을 팬피 배경음악 리스트에 담으시겠습니까? \n확인하시면 단팥 100개가 차감됩니다.'))
	{
	
	var url = '/common/asp/bgm_scrap_ok.fpy';
	var pars;
	if(  SelIndex != "" ) 
		pars = "SelIndex="+SelIndex;
	else
		pars = "mm_code="+mm_code+"&mp3_code="+mp3_code;

	//window.open(url+"?"+pars);
	var loader = new Ajax.Request(
		url,
		{
			method : 'get',
			parameters: pars,
			onComplete: getMusic,
			onFailure: reportError
		}
	);
	}
	
}
function getMusic(getRequest)
{
	var objJSON	= eval("(" + getRequest.responseText + ")");

	var ErrNo	= objJSON.ERROR_CODE;
	var ErrMsg	= objJSON.ERROR_MSG;

	if(  ErrNo != -2  )
	{
		alert(ErrMsg);
		document.location.reload();
	}
}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// 숫자 세자리 마다 "," 찍기
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function js_formatnumber(strNo) {
  var reg = /(^[+-]?\d+)(\d{3})/;   // 정규식
  strNo += '';                      // 숫자를 문자열로 변환

  while (reg.test(strNo))
    strNo = strNo.replace(reg, '$1' + ',' + '$2');

  return strNo;
}


/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// 닉네임 레이어
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
var tarobj;
var tarkind = "";
var tltop = 0;
var tlleft = 50;
function nick_layer(mb_code, obj, kind, ltop, lleft) {
	top.document.location.href = "/fwd/"+mb_code+"/";
	return;

	if ($("NickName_Layers2")) {
		$("NickName_Layers2").parentNode.removeChild($("NickName_Layers2"));
	}
	tarobj = obj;
	tarkind = kind;
	if (ltop == undefined || ltop == "") ltop = 0;
	if (lleft == undefined || lleft == "") lleft = 50;
	tltop = ltop;
	tlleft = lleft;
	var url = '/common/asp/nick_layer.fpy';
	var pars;
	pars = "mb_code="+mb_code+"&kind="+kind;
	var loader = new Ajax.Request(
			url,
			{
				method : 'get',

				parameters: pars,
				onComplete: nick_layer_result,
				onFailure: nick_layer_error
			}
	);
}


function nick_layer2(mb_code, obj, kind, ltop, lleft) {
	if ($("NickName_Layers2")) {
		$("NickName_Layers2").parentNode.removeChild($("NickName_Layers2"));
	}
	tarobj = obj;
	tarkind = kind;
	if (ltop == undefined || ltop == "") ltop = 0;
	if (lleft == undefined || lleft == "") lleft = 50;
	tltop = ltop;
	tlleft = lleft;
	var url = 'http://event.fanpy.net/event/bathory/nick_layer.pull';
	var pars;
	pars = "mb_code="+mb_code+"&kind="+kind;
	var loader = new Ajax.Request(
			url,
			{
				method : 'get',

				parameters: pars,
				onComplete: nick_layer_result,
				onFailure: nick_layer_error
			}
	);
}

function nick_layer_result(loader){
	try
	{
		var getReplyList = loader.responseText;
		//alert(getReplyList);
		$("NickName_Layers").innerHTML = getReplyList;
		setLyr($("nl_"+tarkind+tarobj), "NickName_Layers", tltop, tlleft);
		$("NickName_Layers").style.display = "";
	}
	catch (e)
	{
//		alert($("nl_"+tarkind+tarobj));
//		alert(e.discription);
	}
}

function nick_layer_error(oriMsg) {
//	alert(oriMsg);
}



function nick_layer_hidden(kind) {
	if (window.$("NickName_Layers") != null)
	{
		$("NickName_Layers").style.display = "none";
	}
	if ($("NickName_Layers2")) {
		$("NickName_Layers2").parentNode.removeChild($("NickName_Layers2"));
	};
}

function GetNickLayer(mb_code, objEle, lStyle) {
	if (lStyle == undefined || lStyle == "") lStyle = {"margin":"15px 0 0 0"};

	if ($("NickName_Layers2")) {
		$("NickName_Layers2").parentNode.removeChild($("NickName_Layers2"));
	}
	var divNickLayer = $("divNickNameLayer").cloneNode(true);
	divNickLayer.setAttribute('id','NickName_Layers2');
	divNickLayer.setAttribute('name','NickName_Layers2');
	divNickLayer.setStyle(lStyle);
	objEle.parentNode.insertBefore(divNickLayer, objEle);

	var url = '/common/asp/nick_layer.fpy';
	pars = "mb_code="+mb_code;
	var myAjax = new Ajax.Request(
			url,
			{
				method : 'get',
				parameters: pars,
				onComplete: function (rst) {
					if (window.$("NickName_Layers") != null)
					{
						$("NickName_Layers").style.display = "none";
					}
					divNickLayer.style.display = "block";
					divNickLayer.innerHTML = rst.responseText;
				}
			}
	);
}

/*======================================================
Find position
======================================================*/
function setLyr(obj,lyr, ltop, lleft){
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if (ltop != 0) newY += ltop;
	if (lleft != 0) newX += lleft;
	var x = $(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';
}

function findPosX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if(obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if(obj.offsetParent){
		while(obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}else if(obj.y) curtop += obj.y;

	return curtop;
}
/*======================================================
Find position
======================================================*/

// 아이템 선물하기
function itemgift(argCode, gtype, gmi_code, gidate, gidan){
		var dOption = ",top=150,left=350,scrollbars=yes";
		if (gtype == "C")
			window.open("/shop/item_gift.fpy?gd_code="+argCode+"&cat_type="+gtype+"&select_type=G&kind=shop","divgift","width=387,height=420"+dOption);
		else
			window.open("/shop/item_gift.fpy?gd_code="+argCode+"&cat_type="+gtype+"&select_type=G&gmi_code="+gmi_code+"&gidate="+gidate+"&gidan="+gidan,"divgift","width=387,height=420"+dOption);
	}

	// 아이템 구입하기
function fnccouponBuy(argCode,gtype){
		window.open("/shop/pop_itemmall_fanpybuying.fpy?gd_code="+argCode+"&cat_type="+gtype,"divgift","width=466,height=300");
	}

// 풀콘 아이콘 팝업 띄우기
function getPullconList(){
	//새창의 크기
	cw=400;
	ch=320;

	//스크린의 크기
	sw=screen.availWidth;
	sh=screen.availHeight;

	//열 창의 포지션
	px=(sw-cw)/2;
	py=(sh-ch)/2;

	op  = "left="+px+",top=50,width="+cw+",height="+ch;
	op += ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";

	var pcon = window.open("about:blank","pcon", op);

	pcon.document.write ('<body leftmargin=0 topmargin=0>');
	pcon.document.write ('<img src="http://image2.pullbbang.com/pull30/bbs/pop_pullcon.gif" onClick="self.close();" style="cursor:hand;">');
	pcon.document.write ('</body>');
}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function urlencode (q) { return escape(q).replace(/\+/g, "%2B") ; }


/*
	Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }

    return s0;

}

 

/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/

function decodeURL(str){
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }

    return s0;

}


/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// 숫자 체크
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function CheckNumber(instr)
{
	str = instr.value;
	for(var i = 0 ; i <str.length; i++){
		var ch =str.substring(i, i+1)
		if(ch < "0" || "9" <ch) {
			return false;
		}
	}	
}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// 바토리 이벤트
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function openBathoryPopup() {
	var cw=657;
	var ch=550;

	var sw=screen.availWidth;
	var sh=screen.availHeight;

	px=(sw-cw)/2;
	py=(sh-ch)/2;

	op  = "left="+px+",top=50,width="+cw+",height="+ch
	op += ",toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no";

	window.open("http://www.fanpy.net/event/pop_bathory.fpy?type=R","cEvent",op);

//	if (opener.document)
//		self.close();
}

/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
// 바토리 이벤트
/*〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓*/
function openBathoryPopup2() {
	var cw=657;
	var ch=550;

	var sw=screen.availWidth;
	var sh=screen.availHeight;

	px=(sw-cw)/2;
	py=(sh-ch)/2;

	op  = "left="+px+",top=50,width="+cw+",height="+ch
	op += ",toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no";

	window.open("http://www.fanpy.net/event/pop_bathory3.fpy?type=R","cEvent",op);

//	if (opener.document)
//		self.close();
}




/* ========================================= */
// 쿠키관련
/* ========================================= */
function setJsCookie( name, value, expiredays )
{
	var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + '=' + escape( value ) + '; path=/; expires=' + todayDate.toGMTString() + ';'
	return;
}
function getJsCookie( 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 setAuthorRss(bc2_code, ac3_code)
{
	var pars = "bc2_code="+bc2_code+"&ac3_code="+ac3_code;

	var objAjax = new Ajax.Request(
		"/board/AuthorRss_subscription.fpy",
		{
			method : 'get',
			parameters: pars,
			onComplete: function (rst) {
				objJSON = eval('(' + rst.responseText + ')');
				alert(objJSON[0].msg);
			}
		}
	);
}

// 시작페이지 설정하기
document.write ('<img src="http://image2.pullbbang.com/pull30/menu/bull_event_lm.gif" ID="oHomePage" onclick="setStartPage(this, \'http://www.fanpy.net/main/\');" width="0" height="0" style="display:none;" />');
function onSetStartPage()
{
    document.getElementById("oHomePage").onclick();
}
function setStartPage(obj, homeUrl)
{
	try
	{
		obj.style.behavior='url(#default#homepage)';
		obj.setHomePage(homeUrl);		
		document.hideProcFrame.location.href = "http://www.pullbbang.com/log/click_log.pull?page=WWW2&pos=START_SUCC";
	}
	catch (e) {  
		document.hideProcFrame.location.href = "http://www.pullbbang.com/log/click_log.pull?page=WWW2&pos=START_FAIL";
	}
}

function onGoFnapyClick()
{
	window.open("http://www.fanpy.net/fanpy/fanpyinfocaton.fpy");
}

///////////////////////////////////////////////////////
// 쿠키
///////////////////////////////////////////////////////
function getCookie(name) {
	var Found = false
	var start, end
	var i = 0

	while(i <= document.cookie.length) {
		start = i
		end = start + name.length

		if(document.cookie.substring(start, end) == name) {
			Found = true
			break
		}
		i++
	}

	if(Found == true) {
		start = end + 1
		end = document.cookie.indexOf(";", start)
		if(end < start)
			end = document.cookie.length

		return document.cookie.substring(start, end)
	}
	return ""
}

function setCookie( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

///////////////////////////////////////////////////////
// 오늘은 그만보기
///////////////////////////////////////////////////////
function ClosePopup(argStr, popName, objID, popType, period){
	if(  argStr == true  ){
		setCookie(popName, "no" , period);
	}
	if (popType == "div") {
		$(objID).style.display = "none";
	} else if (popType == "pop") {
		window.close();
	} else {
		$(objID).close();
	}
}
///////////////////////////////////////////////////////
// 오늘은 그만보기
///////////////////////////////////////////////////////


///////////////////////////////////////////////////////
// Mouse Over Layer location search
///////////////////////////////////////////////////////
function GetObjectTopLocation(obj)
{
	if (obj.offsetParent == document.body)
		return obj.offsetTop;
	else
		return obj.offsetTop + GetObjectTopLocation(obj.offsetParent);
}

function GetObjectLeftLocation(obj)
{
	if (obj.offsetParent == document.body)
		return obj.offsetLeft;
	else
		return obj.offsetLeft + GetObjectLeftLocation(obj.offsetParent);
}

// nate connection
function fnNateConnectionScrap(bdcode) {
	fncOpenWin("/common/asp/cyopenscrap.fpy?bd_code="+ bdcode, "cyopenscrap", 450, 410, 0, 0);
}