﻿//****************************************************//
//		  ax common function
//****************************************************//

/*********** user info in Login box ***********/
function getUInfo(req_type) {
	var url = "/common/getUInfo.rwp";
	if (req_type) url += "?req_type=" + req_type;
	$.getJSON(url, getMyInfo);
}
function getMyInfo(uinfo) {
	displayMyInfo("#uinfo_emote", uinfo.emote);
	displayMyInfo("#uinfo_fr_req", uinfo.fr_req);
	displayMyInfo("#uinfo_point", uinfo.point);
	displayMyInfo("#uinfo_point_earn", uinfo.point_earn);
	displayMyInfo("#uinfo_mypoint", uinfo.point);
	displayMyInfo("#uinfo_nowmem", uinfo.nowmem);
}
function displayMyInfo(em_id, val) {
	try {
		if ($(em_id).length > 0) {
			$(em_id).html(val);
		}
	} catch (e) {}
}
/*********** user info in Login box// ***********/

// Latest member news
function getLatestMemberNews() {
	$.getJSON("/common/get_lm_news_cc.rwp",
	function(data){
		$(".LatestList").html(data.result_data);
		$(".LatestList").scroller({ speed: "6000", fontSize: "11px", addHeight: 11 });
	});
}


// popular game in Left box
function getMostGame(req_type, cate, ducate) {
	$.getJSON("/game/common/get_most_game_cc.rwp?cate="+cate+"&ducate="+ducate+"&req_type="+req_type,
	function(data){
		$("#mpArea").html(data.mostdata);
		$("#mpArea").css("background","url("+data.mostimg+") no-repeat");
	});
}

/*********** find pass ***********/
function preRecoveryPW() {
	$("#btn_Submit").hide();
	$("#areaSubmitBtn").css({ color: "#2121FF", fontSize: "15px", fontStyle: "normal", fontFamily: "Tahoma" });
	$("#areaSubmitBtn").html(A0031);
	if ($("#areaEmail").length>0) $.MyMessage({ msg: "", afterObj: "#areaEmail" });
}
function doRecoveryPW(f){
	var email = $.trim(f.email.value);
	if (email == "") {
		f.email.focus();
		$.MyMessage({ msg: A0005, afterObj: "#areaEmail" });
		return false;
	}
	doRecoveryPW_Proc(email);
	return false;
}
function doRecoveryPW_Proc(email) {
	preRecoveryPW();
	$.getJSON("/user/password_proc.rwp?email="+email,
	function(data){
		$("#areaSubmitBtn").html(" ");
		$("#btn_Submit").show();

		if (data.status == "1") {
			var result_msg = data.messages.error[0];
			var email_link = makeEmailConfirm(email, "16px");
			if (email_link != "") result_msg += '<p>&nbsp;</p>' + email_link;
			$("#areaEmail").css({ align: 'center', textAlign: 'center', padding: '2px', fontSize: '16px', fontWeight: 'bold' });
			$("#areaEmail").html(result_msg);
			$("#dpMsgArea").hide();
		}
		else {
			$.MyMessage({ msg: A0024, afterObj: "#areaEmail" });
		}
	});
}
/*********** find pass// ***********/
// give rating
function goRating(obj) {
	if($("#uid").val()=="") {
		alert(A0019);
	}
	else {
		/*
		var strConfirm='<div id="confirmMsg" align="center"><div>'+A0001+'</div><div><a id="confirmMsg_y">[Yes]</a></div></div>';
		var jbRating = jBox.open("Rating", "inline", strConfirm, "평점 주기", "width=250,height=60,center=true,draggable=true");
		$("#confirmMsg_y,#confirmMsg_n").css({ color: "blue" });
		$("#confirmMsg > div").css({ height: "25px" });

		$("#confirmMsg_y").click(function(){
			doRating("DR", $("#gcode").val(), obj.value, "dpRating");
			jBox.dispose(jbRating);
		});
		*/
		if ( confirm(A0001) ) {
			doRating("DR", $("#gcode").val(), obj.value, "dpRating");
		}
	}
}

// process rating
function doRating(req_type, chk_idx, give_point, rtn_obj) {
	var url = "/game/common/rating.rwp?type="+req_type+"&chk_idx="+chk_idx+"&give_point="+give_point;
	$.getJSON(url,
	function(data){
		if (data.result == "1") {
			$("#"+rtn_obj).html(data.resultdata);
		}
		alert(data.resultmsg);
	});
}

/*********** flagging processing ***********/
/*
function blockClgList(strList) {
	if (strList != "" && strList != ",") {
		var arrList = strList.split(",");
		for (var i=0; i<arrList.length; i++) {
			if (arrList[i] != "") {
				var block_div='<div id="coverArea'+arrList[i]+'" no="'+arrList[i]+'" class="coverArea"><img src="http://roi.ltcdn.com/dsgn/en/sub_img/cover_flag.png" class="png24" /></div>';
				$("#GLline"+arrList[i]).append(block_div);
				//$(".coverArea").click(function(){ location.href=$("#url"+arrList[i]).attr("href"); });

			}
		}
		$(".coverArea").click(function(){ location.href = $("#url"+$(this).attr("no")).attr("href"); });
	}
}
*/

function doFlagging(flagcnt_id, t, idx, uk, ui, from_uk) {
	if (!from_uk || from_uk=='') {
		alert(A0051);	//Please log in.
	}
	else {
		var dlg_id = 'dialog_flagging';
		appendDialog(dlg_id, 'Roiworld Flagging System')
		$('#'+dlg_id).html(A0050).show();
		$('#'+dlg_id).dialog({
			autoOpen: true
			,bgiframe: true
			,width: 350
			,modal: true
			,resizable: false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,buttons: {
				"NO": function() {
					$(this).dialog("close");
				},
				"YES": function(event) {
					var url = "/common/flag/flag_proc.rwp?t="+t+"&idx="+idx+"&uk="+uk+"&ui="+ui;
					$.getJSON(url,
					function(data){
						switch (data.result) {
							case 'OK' :
								$("#"+dlg_id).html(A0044);
								$("#"+flagcnt_id).text(parseInt($("#"+flagcnt_id).text())+1);
								break;
							case 'ALREADY_FLAGGED' :
								$("#"+dlg_id).html(A0042);
								break;
							case 'DENIED' :
								$(this).dialog('close');
								var msg;
								if (data.deny_term == 'P') msg = A0043_2.replace('{R1}', data.deny_enddate);
								else msg = A0043.replace('{R1}', data.deny_enddate);
								showSuspendMsg("F", msg, false);
								break;
							case 'LIMIT_TIMES' :
								$("#"+dlg_id).html(A0045);
								break;
							case 'NOT_MEMBER' :
								$("#"+dlg_id).html(A0046);
								break;
							case 'NOT_ENOUGH_PARAMETER' :
								$("#"+dlg_id).html(A0047);
								break;
							case 'NOT_LOGIN' :
								$("#"+dlg_id).html(A0051);
								break;
							case 'MINE' :
								$("#"+dlg_id).html(A0048);
								break;
							case 'RESUMED' :
								$("#"+dlg_id).html(A0052);
								break;
						}
						$(event.target).prev().text('OK');
						$(event.target).hide();
					});
				}
			}
			,close: function(event, ui) {
				$(this).dialog('destroy');
			}
		});
	}
}
function showSuspendMsg(vDenyType, vMsg, isBack) {
	var dlg_id = 'dialog_suspend';
	appendDialog(dlg_id, 'Roiworld')
	$('#'+dlg_id).html(vMsg).show();

	$('#'+dlg_id).dialog({
		autoOpen: true
		,bgiframe: true
		,width: 350
		,modal: true
		,resizable: false
		,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
		,buttons: {
			"CLOSE": function() {
				if ($('#dialog_flagging').length > 0) {
					$('#dialog_flagging').dialog("close");
				}
				$(this).dialog("close");
			}
		}
		,close: function(event, ui) {
			$(this).dialog('destroy');
			if (isBack) history.back();
		}
	});
}

//linkModify(신고상태값, '수정페이지 링크', '메세지', history back 여부)
function linkModify(vPatrolStat, vLink, vMsg, isBack) {
	if (vPatrolStat == '2') {
		var dlg_id = 'dialog_resume';
		appendDialog(dlg_id, 'Roiworld')
		$('#'+dlg_id).html(vMsg).show();

		$('#'+dlg_id).dialog({
			autoOpen: true
			,bgiframe: true
			,width: 350
			,modal: true
			,resizable: false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,buttons: {
				"No": function() {
					$(this).dialog("close");
				},
				"Yes": function() {
					if (vLink) location.href = vLink;
					else $(this).dialog("close");
				}
			}
			,close: function(event, ui) {
				$(this).dialog('destroy');

				if (isBack) history.back();

			}
		});
	}
	else {
		location.href = vLink;
	}

}
/*********** //flagging processing ***********/

/************ Emoticon Layer ****************/
function showEmotiDlg(cate, icon_id) {
	var url = "/common/ax_emoti.asp?cate="+cate+"&icon_id="+icon_id;
	$.get(url,
	function(data){
		var dlg_id = "dlg_emoti";
		if ($("#"+dlg_id).length==0) $("body").append("<div id='"+dlg_id+"' style='display:none;'></div>");
		var offset = $("#"+icon_id).offset();

		var strSpeed = '';
		if ($("#"+dlg_id).css('display') == 'none') strSpeed = 'fast'
		$("#"+dlg_id).css({ position: 'absolute', 'left': offset.left, 'top': offset.top+$('#'+icon_id).innerHeight() }).html(data).show(strSpeed);
	});
}

/************ Usermenu Layer ****************/
function showUserMenu(obj, fr_ukey, fr_uid, ukey){
	if (fr_ukey != '3783288'){//[romi,romiroiword] Layer close...
		var um = '';
		um+='<div class="umenu" style="width:100px; background:#fff; border:1px solid #000; padding:0 5px 0 0;">';
		um+='  <ul class="umenu" style="padding-top:0px; color:#666; font-size:11px;">';
		um+='	<li style="padding-top:4px; height:18px; border-bottom:1px dotted #EFDAF8;">';
		um+='		<img src="http://roi.ltcdn.com/dsgn/en/profile/left_dot2.gif" width="12" height="2" /><a onClick="goProfile(\''+fr_ukey+'\');">View Profile</a>';
		um+='	</li>';
		um+='	<li style="padding-top:4px; height:18px; border-bottom:1px dotted #EFDAF8;">';
		um+='		<img src="http://roi.ltcdn.com/dsgn/en/profile/left_dot2.gif" width="12" height="2" /><a onClick="fnAddFriend(\''+fr_ukey+'\', \''+fr_uid+'\', \''+ukey+'\');">Become a Friend</a></li>';
		um+='	<li style="padding-top:4px; height:18px; border-bottom:1px dotted #EFDAF8;"><img src="http://roi.ltcdn.com/dsgn/en/profile/left_dot2.gif" /><a href="/profile/my-work/my-challenge-looks/?pkey='+fr_ukey+'" target="_blank">View Challenges</a></li>';
		um+='  </ul>';
		um+='</div>';

		var dlg_id = 'UserMenu';
		if ($('#'+dlg_id).length==0) $('body').append('<div id="'+dlg_id+'"></div>');
		var offset = $(obj).offset();

		$('#'+dlg_id).css({position: 'absolute', zIndex:9999, left: parseInt(offset.left), top: offset.top+$(obj).height()}).html(um).show();

		$(document).click(function(event){
			//firelog("is", $(event.target).parent().is(".umenu") )
			if (!$(event.target).parent().is('.umenu')) {
				$('#UserMenu').remove();
			}
		});
	}
}
$(document).ready(function(){
	$('.umenu').bind('click', function(e){
		if ($(this).attr('pos')=='cursor') {
			$('#UserMenu').css({ left:e.pageX, top:e.pageY });
		}
	});
});

/************ my info Layer ****************/
function showMyInfo(obj,ukey){
	var url = '/profile/common/ax_my_info.asp?ukey='+ukey;
	$.get(url,
	function(data){
		var dlg_id = 'myinfoLayer';
		if ($('#'+dlg_id).length==0) $('body').append('<div id="'+dlg_id+'" style="display:none"></div>');
		var offset = $(obj).offset();
		$('#'+dlg_id).css({position: 'absolute', zIndex:9999, 'left': offset.left, 'top': offset.top+$(obj).height()+2}).html(data);
		$('#'+dlg_id).toggle();
	});
}

/************ friends list Layer ****************/
function showFrList(obj,ukey){
	var url = '/profile/common/ax_fr_list.asp?ukey='+ukey;
	$.get(url,
	function(data){
		var dlg_id = 'frListLayer';
		if ($('#'+dlg_id).length==0) $('body').append('<div id="'+dlg_id+'" style="display:none"></div>');
		var offset = $(obj).offset();
		$('#'+dlg_id).css({position: 'absolute', zIndex:9000, 'left': offset.left, 'top': offset.top+$(obj).height()+2}).html(data);
		if ($('#'+dlg_id).css('display')=='none') {
			$('#'+dlg_id).slideDown('fast');
		}
		else {
			$('#'+dlg_id).slideUp('fast');
		}
	});
}


/************ friends Add Layer ****************/
function fnAddFriend(strToUkey, strToUname, strUkey){
	if (strToUkey == strUkey) {
		fnShowAlert('You cannot add yourself as a friend.');
	}
	else {
		if (strUkey == "") {
			fnShowAlert('You need to log in to become friends with others!');
		}else if(strToUkey=="3783288"){//romiroiworld 친구요청 안되게
			return false;
		}else {
			if (strToUkey != strUkey && strUkey != "") {
				if ($("#addFriendLayer").length==0) {$('body').append('<div id="addFriendLayer"></div>'); }

				$.get("/profile/friends/ax_add_Friend.asp?tokey="+strToUkey,
				function(strResult){
					$("#addFriendLayer").html(strResult).attr("title", "Wanna Become "+strToUname+"'s Friend?");
					$("#addFriendLayer").dialog({
						autoOpen:  false
						,bgiframe: true
						,width:    475
						,height:   400
						,draggable:true
						,resizable:false
						,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
						,buttons: {
							"CANCEL": function() {
								$(this).dialog("close");
							},
							"SEND": function() {
								addFriendSendMsg(strToUkey,strToUname);
							}
						}
						,close: function(event, ui) {
							$(this).dialog('destroy');
						}
					});
					$("#addFriendLayer").dialog('open');
				});

			}
		}
	}
}

/************ friends add Send ****************/
function addFriendSendMsg(strToUkey,strToUname) {
	var obj    = document.addFriend;
	var strMsg = $('textarea[name=addMsg]').val();
	var strGrp = $('select[name=grpList]>option:selected').val();

	var strBadMsg = fnFilter($.trim(strMsg).replace(/(^\s*)|(\s*$)/g,""));
	if (strBadMsg != ""){
		CommMsg("'" + strBadMsg + "' " + A0034);
		$('textarea[name=addMsg]').select();
		return false;
	}else {
		fnShowAlert('<center>Friend Request has been sent to <u>'+ strToUname +'</u> for approval.<br /><a href="/profile/">My Profile</a> > <a href="/profile/friends/">Friends</a> > <a href="/profile/friends/friend-requests.rwp">Friend Requests</a></center>');
		reqUrl = "/profile/friends/ax_add_Friend_proc.asp?tokey="+strToUkey+"&toname="+strToUname+"&saveGrp="+strGrp+"&sendMsg="+strMsg;
		$.get(reqUrl,
			function(strResult){eval(strResult);}
		);
		$('#addFriendLayer').dialog('close');
	}
}

/************ friends Become Layer ****************/
function fnBefriend(strToUkey,strToUname,strUkey,strUname,strMsg) {
	$("#altBefriend").remove();
	if ($("#altBefriend").length==0) { $("body").append("<div id='altBefriend' title='Roiworld'></div>");}

	switch(strMsg) {
	case "Guestbook":
		strMsg = "Become a friend to leave messages.<br><br><center><a onClick=\"fnAddFriend('"+strToUkey+"', '"+strToUname+"', '"+strUkey+"');$(\'#altBefriend\').dialog(\'close\');\">Befriend</a></center>";
		break;
	case "FriendsList":
		strMsg = "Share th List of Friends after becoming a friend with <u>"+ strToUname +"</u>.<br><br><center><a onClick=\"fnAddFriend('"+strToUkey+"', '"+strToUname+"', '"+strUkey+"');$(\'#altBefriend\').dialog(\'close\');\">Befriend</a></center>";
		break;
	default:
		strMsg = "Share th List of Friends after becoming a friend with <u>"+ strToUname +"</u>.<br><br><center><a onClick=\"fnAddFriend('"+strToUkey+"', '"+strToUname+"', '"+strUkey+"');$(\'#altBefriend\').dialog(\'close\');\">Befriend</a></center>";
		break;
	}
	$("#altBefriend").append(strMsg).show();
	$("#altBefriend").dialog({
		autoOpen: true
		,bgiframe: true
		,width: 350
		,modal: true
		,resizable: false
		,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
		,buttons: {
			"OK": function() {
				$(this).dialog("close");
			}
		}
		,close: function(event, ui) {
			$(this).dialog('destroy');
		}
	});
}

/************ calc byte length ****************/
function getByteLen(strVal) {
    var byteLen = 0;
	try {
		for (var inx = 0; inx < strVal.length; inx++) {
			var oneChar = escape(strVal.charAt(inx));
			if ( oneChar.length == 1 ) {
				byteLen ++;
			} else if (oneChar.indexOf("%u") != -1) {
				byteLen += 2;
			} else if (oneChar.indexOf("%") != -1) {
				byteLen += oneChar.length/3;
			}
		}
		return byteLen;
	}
	catch (e) {return 0;}
}

/************ text chk ****************/
function CheckStrLen(obj,maxLen){
	if ( getByteLen(obj.value) > maxLen ) {
		obj.value=obj.value.substring(0,maxLen);
		obj.focus();
	}
	if ( typeof(document.getElementById('byteview')) != 'undefined' ) {
		$("#byteview").html( getByteLen(obj.value).toString() );
	}
}

/************ fnSowAlert ****************/
function fnShowAlert(strMsg) {
	if ($("#show_alert").length==0) {
		$("body").append("<div id='show_alert' class='show_alert' title='Roiworld'></div>");
	}
	$("#show_alert").html(strMsg).show();
	$("#show_alert").dialog({
		autoOpen: true
		,bgiframe: true
		,width: 350
		,modal: true
		,resizable: false
		,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
		,buttons: {
			"OK": function() {
				$(this).dialog("close");
			}
		}
		,close: function(event, ui) {
			$(this).dialog('destroy');
		}
	});
}

/************ Friend Request Dialog ****************/
function ax_FrRequestList(tmp,iPage) {
	if ($("#FrReqLayer").length==0) {$('body').append('<div id="FrReqLayer"></div>'); }

	$.get("/profile/friends/ax_req_Layer.asp?page="+iPage,
	function(strResult){
		$("#FrReqLayer").html(strResult).attr("title", "Friend Requests");
		$("#FrReqLayer").dialog({
			autoOpen:  false
			,bgiframe: true
			,width:    325
			,height:   360
			,draggable:true
			,resizable:false
			,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
			,buttons: {
				"Cancel": function() {
					$(this).dialog("close");
				},
				"View all": function() {
					location.href='/profile/friends/friend-requests.rwp';$(this).dialog("close");
				}
			}
			,close: function(event, ui) { $(this).dialog('destroy');}
		});
		$("#FrReqLayer").dialog('open');
	});
}

/************ Click Add(+1) ****************/
//(링크 걸릴는곳, idx값,테이블명,링크필드,증가시킬필드)
function ax_AddClick(iIdx,strTname,strLink,strAdd){
	var reqUrl = '/common/ax_addClick.rwp?i='+iIdx+'&t='+strTname+'&l='+strLink+'&a='+strAdd;
	$.get(reqUrl,
		function(strResult){
//			$('#'+a).attr('href',strResult).attr('target','_blank');
//			MM_openBrWindow(strResult,'','');
		}
	);
}

// common dialog msg
function showCommonDlg(vMsg, w, bModal, bBack) {
	var dlg_id = 'dialog_common';
	appendDialog(dlg_id, 'Roiworld')
	$('#'+dlg_id).html(vMsg).show();

	$('#'+dlg_id).dialog({
		autoOpen: true
		,bgiframe: true
		,width: w
		,modal: bModal
		,resizable: false
		,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
		,buttons: {
			"CLOSE": function() {
				$(this).dialog("close");
			}
		}
		,close: function(event, ui) {
			$(this).dialog('destroy');
			if (bBack) history.back();
		}
	});
}
//project-runway chk winner
function goRunwayWinner(){
	var reqUrl = '/project-runway/common/ax_chk_winner.asp';
	$.get(reqUrl,
		function(strResult){
			if(strResult=='1'){
				document.location.href='/project-runway/challenge/winner.rwp';
			}else{prwayWinnerLayer();}
		}
	);
}
function prwayWinnerLayer(){
	var reqUrl = '/project-runway/common/ax_winnerLayer.asp';
	$.get(reqUrl,
		function(strResult){
			var LPos =(screen.availWidth-605)/2;
			var Tpos =(screen.availHeight-455)/2;
			if ($("#tempprwarlayer").length==0) {
				$("body").append("<div id='tempprwarlayer'></div>");
			}
			$('#tempprwarlayer').css({ position: 'absolute', zIndex:9000, 'width': 605, 'height': 455, 'left': LPos, 'top': Tpos });
			$("#tempprwarlayer").html(strResult);
		}
	);
}
//bg change
function fnGetTime(div) {
	var divid;
	var path;
	if (div=='main'){
		divid = '#skinBg';
		path = 'http://roi.ltcdn.com/dsgn/en/090713_main/skin_3_11.jpg';
	} else {
		divid = '#topBg';
		path = 'http://roi.ltcdn.com/dsgn/en/runway/main/top_bg_11.jpg';
	}
	var reqUrl = '/common/ax_get_time.asp';
	$.get(reqUrl,
		function(strResult){
			if (strResult=='1'){
				fnChangeNKBG();
			}
		}
	);
}
function fnChangeBG(div,path){
	$(div).css("background","url("+path+") no-repeat");
}
//노마까말리 메인스킨 변경
function fnChangeNKBG(){
	$("#bg_left").css("background","url(http://roi.ltcdn.com/DSGN/en/090713_main/nk_bg.jpg) repeat-x");
	$("#bg_left div").css("background","url(http://roi.ltcdn.com/DSGN/en/090713_main/nk_left_bg.jpg) no-repeat right top");
	$("#bg_right").css("background","url(http://roi.ltcdn.com/DSGN/en/090713_main/nk_bg.jpg) repeat-x");
	$("#bg_right div").css("background","url(http://roi.ltcdn.com/DSGN/en/090713_main/nk_right_bg.jpg) no-repeat 495px top");
	$("#skinBg").css("background","url(http://roi.ltcdn.com/DSGN/en/090713_main/nk_skin.jpg) no-repeat");
	$("#nkLink").attr("href", "/event/norma-kamali/collection.rwp");
}

//Global Alert
var timerGA = null;
function global_alert(p) {
	var url = '/main/global-alert/ax_global_alert.asp?p='+p;
	$.get(url,
	function(data){
		if (p == 'home') {
			if ( $.cookie('gashow') != 'n' ) {
				if (data != 'NONE') {
					$("#skinBg").prepend(data);
				}
				timerGA = setTimeout("$('#global_alert').slideUp();", 30000);
			}
		}
		else {
			if (data != 'NONE') {
				$("#ProfileWrap").prepend(data);

				// 디폴트레이어 높이 조절
				var offset1, offset2, add_h;
				if ($('#dialog_defautmsg_interests').length > 0) {
					offset1 = $('#dialog_defautmsg_interests').position();
					add_h = $('#global_alert').height();
					$('#dialog_defautmsg_interests').css('top', offset1.top+add_h);
				}
				if ($('#dialog_defautmsg_inspiration').length > 0) {
					offset2 = $('#dialog_defautmsg_inspiration').position();
					add_h = $('#global_alert').height();
					$('#dialog_defautmsg_inspiration').css('top', offset2.top+add_h);
				}
			}
		}
		$("#global_alert").show();
	});
}
