﻿// JScript 파일

/************ 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() );
    }
}

/************ 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;}
}



function fFriendList( obj, userkey)
{
    // 강제세팅.
    var offset = $(obj).offset();
    var layerleft =  parseInt( offset.left-65 );
    var layertop  =  offset.top+$(obj).height();

    if ($("#selectFriendLayer").length == 0 ){
        $('body').append('<div id="selectFriendLayer"></div>'); 
    }
    
    $('#selectFriendLayer').css({position: 'absolute', zIndex:999999, left: layerleft, top: layertop})
      
    var listURL =  fWWWDomain() + "/profile/common/ax_fr_list_groups.rwp?ukey=" +  userkey
     
      $.get("/AjaxProxy.aspx?url="+escape(listURL),
      function(data)
      {
            $('#selectFriendLayer').html(data).show();
      });
}


function frmAllcheck(DivID) {
	if($(DivID).is(":checked") == true){
			$("#layer_list > input:checkbox").attr("checked","checked");
			$(".layer_btn > input:checkbox").attr("checked","checked");
		}else{
			$("#layer_list > input:checkbox").attr("checked","");
			$(".layer_btn > input:checkbox").attr("checked","");
		}
}


function frmCheckConfirm() {
	var chked_list = $("#layer_list > input:checked");
	if (chked_list.length > 0) {
		frmCheckInsert(chked_list);
	}
	else {
		alert("")
	}
}

function frmCheckInsert(A_chked_list) {
	var chked , chkFrUid
	chked = "";
	chkFrUid = "";
	
	if( A_chked_list.length > 3 )
	{
	    alert("Please select no more than 3 users at a time. ");
	    return;
	}
		
	
	for (var i=0; i< A_chked_list.length; i++) {
		if (i == 0 ){
			chkFrUid += A_chked_list[i].value;
		}else {
			chkFrUid += "¶" + A_chked_list[i].value;
		}
	}
	fFriendListCallback(chkFrUid);
        	
}



function frmFriendsHide () {

	$("#selectFriendLayer").remove();
	
}

function fFriendListCallback( arruid)
{

    var arUid = arruid.split( "¶");
    var i;
    var item;
    
    var strUid = $('#msgTo').val( );
    for( item in arUid )
    {
        if( strUid != "")
        {
            strUid += ", ";
        }
        strUid += arUid[item]
    }
    
    var arrUid = strUid.split(",");
    if( arrUid.length > 3 )
    {
	    alert("Please select no more than 3 users at a time. ");
	    return;
    }
    
    $('#msgTo').val( strUid);
    $('#selectFriendLayer').remove();
   
}


var RoiFriendAdd = {

    fWWWDomain : function()
    {
        var domain = document.location.href;
        if( domain.indexOf("devgroups.roiworld.com")  > 0 )
        {
            return "http://devwww.roiworld.com";
        }
        else if( domain.indexOf("qagroups.roiworld.com") > 0 )
        {
            return "http://qawww.roiworld.com";
        }
        else
        {
            return "http://www.roiworld.com";
        }
    },


    /************ friends Add Layer ****************/
    fnAddFriendGroup : function(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>'); }

				    var toUrl=  escape( this.fWWWDomain() + "/profile/friends/ax_add_Friend.asp?tokey="  + strToUkey );
				    $.get("/AjaxProxy.aspx?url=" + toUrl, 
				    function(strResult){
					    $("#addFriendLayer").html(strResult).attr("title", "Wanna Become "+strToUname+"'s Friend?");
					    
					    $("#addFriendLayer").dialog({
						    autoOpen:  false
						    ,bgiframe: true
						    ,width:    480
						    //,height:   405
						    ,draggable:true
						    ,resizable:false
						    ,open: function() { $(this).parents('.ui-dialog').attr('tabindex', -1)[0].focus(); }
						    ,buttons: {
							    "CANCEL": function() {
								    $(this).dialog("close");
							    },
							    "SEND": function() {
								    RoiFriendAdd.fnAddFriendSendMsgGroup(strToUkey,strToUname);
							    }
						    }
						    ,close: function(event, ui) {
							    $(this).dialog('destroy');
						    }
					    });
					    $("#addFriendLayer").dialog('open');
				    });

			    }
		    }
	    }
    },

    /************ friends add Send ****************/
    fnAddFriendSendMsgGroup : function(strToUkey,strToUname) {

	    var strMsg = $('textarea[name=addMsg]').val();
	    var strGrp = $('select[name=grpList]>option:selected').val();

	    var strBadMsg = this.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="' + this.fWWWDomain() +'/profile/friends/friend-requests.rwp">Friend Requests</a></center>');
		    var reqUrl=  escape( this.fWWWDomain() + "/profile/friends/ax_add_Friend_proc.asp?tokey="+strToUkey+"&toname="+strToUname+"&saveGrp="+strGrp+"&sendMsg="+strMsg );
		    $.get( "/AjaxProxy.aspx?url=" + reqUrl , function(strResult){alert(strResult);});
		    $('#addFriendLayer').dialog('close');
	    }
    },

    
    fnFilter : function(words){
    
	    var strResult = "";
	    var re = /(\.)?\bass\b|a.ss.hole|asskisser|asswipe|bastard|beastial|beastiality|beastility|beaver|bestial|bestiality|bitch|blowjob|bonehead|boner|browntown|(\.)?\bbum(\.)?\b|butch|butt|fuck|fck|f.u.c.k|fu.c.k|fu.ck|chink(\.)?\b|\bchhriist|clam(\.)?\b|clit(\.)?\b|cobia(\.)?\b|cock(\.)?\b|cocks|cooter|\bcrap(\.)?\b|cum(\.)?\b|cummer|cumming|cums|cunilingus|cunillingus|cunnilingus|cunt|cyberfuc|damn|dick|dike|dildo|dink|\bdong(\.)?\b|dumbass|dyke|ejaculat|fag(\.)?\b|fagg|fagot|fags|fart|fatas|fatso|felatio|fellatio|fingerfuc|fuk|furburger|gangbang|gaysex|gazongers|goddamn|gonads|gook|guinne|hardcoresex|hell(\.)?\b|homo(\.)?\b|hooker|horniest|horny|hotsex|hussy|jackass|jackoff|\bjap\b|\bjerk\b|\bjesus\b|\bjew(\.)?\b|jism(\.)?\b|\bjiz|kike|knob|kock|kondum|kraut|kum(\.)?\b|kunilingus|lesbian|lesbo|loser|lust(\.)?\b|merde|mick(\.)?\b|mound(\.)?\b|muff(\.)?\b|nerd(\.)?\b|nigger|orgasim|orgasm|pecker|penis|phonesex|phuk|phuq|pimp|(\.)?\bpiss|porn|prick|prostitute|pussi|pussy|queer|retard|schlong|screw(\.)?\b|sheister|slag|sleaze|slut|smut|snatch|spunk|twat|wetback|whore|wop(\.)?\b|biatche|bicccch|fukk|shyt|b.tch|belly.whacker|blow.job|bung.hole|douche.bag|hard.on|hardcore.sex|jacking.off|jack.off|copy.this.on|press.f.|press.f..|c.py this .n|b.u.l.l.s.h.i.t|shit|(\.)?\bsh(.)?it|sh(.)?!t|d.ck|a\$\$|s.l.u.t|(\.)?\bc.ins\?|(\.)?\bc.in\?/i;
	    arr = re.exec(words);
	    if (arr != null) {
		    strResult = arr[0];
	    }
	    return strResult;
    }
}

//alert메세지(id[show_alert] 변경하지마세요.) - JINO(Roiworld)
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');
	    }
    });
}
