// my work 아이템 삭제
function delMyWork(m) {
	if ( !fnRadioCheck('chk_idx') ) {
		alert(A0058);
	}
	else {
		var addMsg = '';
		if ( $("input[name=chk_idx][prize='1']:checked").length > 0 ) {
			$("input[name=chk_idx][prize='1']:checked").attr("checked", false);
			addMsg = A0069;
		}
		if (del_conf(addMsg)) {
			$("#f").attr("method","post");
			$("#f").attr("action","del_proc.rwp");
			$("#f").submit();
		}
	}
}

// 챌린지를 내아바타로 지정
function setAvatar_MyChallenge(strCate) {
	var checked_cnt = $("input[name='chk_idx']:checked").length;
	if ( checked_cnt == 0 ) {
	   alert(A0059);
	}
	else {
		if (checked_cnt == 1) {
			setProfileImage($("input[name='chk_idx']:checked").val(),strCate);
		}
		else {
			alert(A0060);
		}
	}
}

// My Saved Looks Setting
function showMSL_Setting() {
	$.get("ax_msl_settings.asp",
	function(data){
		var dlg_id = "SettingLayer";
		appendDialog(dlg_id, 'My Saved Looks Settings');
		$("#"+dlg_id).html(data).show();
		$("#"+dlg_id).dialog({
			autoOpen: false
			,bgiframe: true
			,width: 400
			,draggable:true
			,resizable:false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,buttons: {
				"CLOSE": function() {
					$(this).dialog("close");
				},
				"SAVE": function(event) {
					var chk_auth_msl = $("input[name='chk_auth_msl']:checked").val();
					$.get("ax_msl_settings_proc.asp?chk_auth_msl="+chk_auth_msl,
					function(data){
						$("#"+dlg_id).html(data);
						$(event.target).prev().text('OK');
						$(event.target).hide();
					});
				}
			}
			,close: function(event, ui) {
				$(this).dialog('destroy');
			}
		});
		$("#"+dlg_id).dialog('open');
	});
}

// Guestbook Setting
function showGB_Setting(){
	$.get("ax_gb_settings.rwp",
	function(data){
		var dlg_id = "SettingLayer";
		appendDialog(dlg_id, 'Guestbook Settings');
		$("#"+dlg_id).html(data).show();
		$("#"+dlg_id).dialog({
			autoOpen: false
			,bgiframe: true
			,width: 400
			,draggable:true
			,resizable:false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,buttons: {
				"CLOSE": function() {
					$(this).dialog("close");
				},
				"SAVE": function(event) {
					var iMpAuthGB = $("input[name='iMpAuthGB']:checked").val();
					$.get("ax_gb_settings_proc.rwp?MpAuthGB="+iMpAuthGB,
					function(data){
						$("#"+dlg_id).html(data);
						$(event.target).prev().text('OK');
						$(event.target).hide();
					});
				}
			}
			,close: function(event, ui) {
				$(this).dialog('destroy');
			}
		});
		$("#"+dlg_id).dialog('open');
	});
}
function GBWriteProc(strUserId){
	var obj = document.GuestBook;

	var strTmpMsg = $('textarea[name=Content]').val();
	var strBadContent = fnFilter($.trim(strTmpMsg).replace(/(^\s*)|(\s*$)/g,""));
	var strMsg1 = strUserId +", what are you up to today?";
	var strMsg2 = strUserId +", say something...";
	var strMsg3 = strUserId +", become a friend to leave message.";
	var strMsg4 = "Become a friend to leave messages.";

	if (strTmpMsg.indexOf(strMsg1) != '-1') {
		return false;
	}

	if (strBadContent != ""){
		CommMsg("'" + strBadContent + "' " + A0034);
		$('textarea[name=Content]').select();
		return false;
	}

	obj.Emoticon.value=$('#emoti_btn').attr('no');
	obj.action = '/profile/guestbook/gb_write_proc.rwp';
	obj.submit();
}

function GBDelProc(iGBIdx){
	var obj = document.GuestBook;
	obj.action = '/profile/guestbook/gb_del_proc.rwp';
	obj.GBDelIdx.value = iGBIdx;
	obj.submit();
}


function setProfileImage(iClickValue,strCate){
	if ($("#dialog_profileAvaImgEdit").length==0) {
		$("body").append("<div id='dialog_profileAvaImgEdit' class='dialog_profileAvaImgEdit' title='Edit Your Profile Image'></div>");
	}
	$("#dialog_profileAvaImgEdit").html('');
	$("#dialog_profileAvaImgEdit").dialog({
		autoOpen: false
		,bgiframe: true
		,resizable: false
		,width: 546
		,height:430
		,close: function(event, ui) {
			$(this).dialog('destroy');
		}
	});
	$.get("/profile/common/ax_editProfileImage.asp?iUniq="+iClickValue+"&strCate="+strCate,
	function(data){
		$('#dialog_profileAvaImgEdit').dialog('open');
		$("#dialog_profileAvaImgEdit").html(data);
	});
}

/******* Latest Activity ******************/
function getLatestAct_Top(pkey) {
	var reqUrl = '/profile/friends/latest-activity/ax_activity_top.asp?pkey='+pkey;
	$.get(reqUrl,
		function(strResult){
			$('#latestA_Data').html(strResult);
		}
	);
}
function LatestActList(pkey, cate, st, sw, page) {
	var reqUrl = 'ax_activity.asp?pkey='+pkey+'&cate='+cate+'&page='+page+'&sw='+sw;
	$.get(reqUrl,
		function(strResult){
			$('#dataWrap').html(strResult);
			$.ga(GA_ID[0]);
		}
	);
}
function deleteActivity(pkey, i, doContinue) {
	if (confirm(A0075)) {
		var reqUrl = '/profile/friends/latest-activity/ax_del_activity.asp?pkey='+pkey+'&idx='+i;
		$.get(reqUrl,
			function(strResult){
				if (strResult=='OK') {
					if (doContinue.substr(0,3)=='fn:') {
						eval(doContinue.substr(3));
					}
					else {
						var hash = location.hash;
						hash = hash.replace(/^.*#/, '');
						if (hash=='') { hash = 'page=1'; }
						$.historyLoad(hash);
					}
				}
				else {
					alert(A0081);
				}
			}
		);
	}
}
/******* // Latest Activity ******************/

/******* // avatar editor ******************/
//앨범 이미지 클릭시
function avatarAlbumImgShow(num, albumUniq, path, date){
	var abTitle, showTitle;
	$("#noteArea").css({display: 'none'});

	abTitle = unescape($("#albumTitle"+num).val()); //title
	if (abTitle != '') showTitle = abTitle;	//title 있을때 title 노출
	else showTitle = date;	//title 없으면 날짜 노출

	$(".editDate").html(showTitle);//date
	$("#albumBigImg").attr("src",path);//img
	$("#albumUniq").val(albumUniq);
	$("#avaAlbumPrintImg").val(path);//print img
	avaAlbumFlag(albumUniq, $("#pkey").val(), num);//flag
	avaImgSel(num);//border
	ax_mp_comm('1','MP-ALBUM',$("#pkey").val(),albumUniq,'');//댓글
}
function avaImgSel(num){
	var cnt = $("#listCnt").val();
	for (i=1; i<=cnt; i++){
		if (i==parseInt(num)) {
			$("#albumImg"+num).attr('className', "selectimgLine");
		} else $("#albumImg"+i).attr('className', "imgLine");
	}
}
//flag 노출
function avaAlbumFlag(uniq, pkey, num){
	var flagContent = unescape($("#flag"+num).val());
	$(".flaggedBtn").html(flagContent);
}
//각 아이콘 클릭시
function avaAlbumAction(type){
	var uid = $('#uid').val();
	if (type == 'capture'){
		var iClickValue = $('#albumUniq').val();
		setProfileImage(iClickValue,'avaAlbum');
	} else if (type == 'note'){
		$("#noteArea").html('');
		albumConceptNote('');
		$('#noteArea').toggle();
	} else {
		var imgpath = $('#avaAlbumPrintImg').val();
		fnPrint(uid,imgpath,'avaAlbum');
	}
}
//앨범삭제
function avaAlbumDel(uniq){
	if ( confirm(A0086) ) {
		buildIframe("ifrm_alb");
		$("#iAlbDelIdx").val(uniq);
		$("#f_alb").attr("action","http://imgs.roiworld.com/dataup/avatar/album/del_proc.rwp");
		$("#f_alb").attr("target","ifrm_alb");
		$("#f_alb").submit();
	}
}
//컨셉노트 수정
function albumConceptNote(cmd){
	var num = $('#albumUniq').val();
	var pkey = $('#pkey').val();
	var reqUrl = "/profile/avatar/look-book/conceptNote_edit.rwp";
	$.post(reqUrl, {uniq: num, cmd: cmd, pkey: pkey},
		function(data){
			$("#noteArea").html(data);
		});
}
//프로파일 상단 탭 클릭시
function fnAETabBtn(pkey, cmd){
	var strLink;
	if (cmd == 'profile'){
		strLink = '/profile/'+pkey;
	} else if (cmd == 'look-book'){
		strLink = '/profile/avatar/look-book/?pkey='+pkey;
	} else if (cmd == 'guide1'){
		strLink = '/site/avatar-editor-guide.rwp';
	} else if (cmd == 'guide2'){
		strLink = '/site/avatar-editor-guide2.rwp';
	} else if (cmd == 'guide3'){
		strLink = '/site/avatar-editor-guide3.rwp';
	} else if (cmd == 'guide4'){
		strLink = '/site/avatar-editor-guide4.rwp';
	}
	var url = document.location;
	var s = url.toString().indexOf('/editor/');
	if (s > 0 ){//에디터 페이지 일때
		if ($("#albumMsg").length==0) {$("body").append("<div id='albumMsg' class='albumMsg' title='Roiworld'></div>");}
		$("#albumMsg").html(A0080);
		$("#albumMsg").dialog({
			autoOpen: true
			,bgiframe: true
			,resizable: false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,width: 280
			,height: 150
			,buttons: {
				"No": function() {$(this).dialog("close");},
				"Yes": function() {document.location.href=strLink;}
			}
			,close: function(event, ui) {$(this).dialog('destroy');}
		});
	} else document.location.href = strLink;
}
/******* // avatar editor ******************/