function go_home() {
  top.location.href = "/crossfire_home.nwz?intro=done";
}

function go_menu(mKey,sKey,addr) {
  top.location.href = "/crossfire_frame.nwz?mKey="+ mKey +"&sKey="+ (addr ? sKey +"&url="+ encodeURIComponent(addr) : sKey);
}

function goClan(guildid) {
  window.open("http://www.pmang.com/guild/index.nwz?ssn=318&guildid="+ guildid);
}

function cf_begin_game() {
  top.location.href = "/gamepub/game_running.nwz?ssn=318";
}

function cf_finish_game() {
  execGameEndProc(318);
}

function openWindow(fn,w,h) {
  window.open(fn,"CF_POPUP","width="+ (w ? w : 100) +",height="+ (h ? h : 100));
}

function openUserProfile(usn,call_name) {
  openWindow("/crossfire_user_info.nwz?usn="+ usn +"&call_name="+ (call_name ? call_name : "profileGameInfo"));
}

function openPolicy() {
  openWindow("http://file.pmang.kr/images/pmang/gamepub/police/crossfire.html#12",670,550);
}

function tabLogin(no) {
  var idx = no-1;
  var call_func = ['','loginCashItem','loginFriendMemo'];

  if(!$(".myinfo").eq(idx).html()) {
    $.get("/crossfire_ajax.nwz",{call_name:call_func[idx]},function(txt) {
      $(".myinfo").eq(idx).html(txt);
      
      if(no == 3) {
        document.getElementById("my_memo_newcount").innerHTML = ( ('object'==typeof(AppletSession) || 'function'==typeof(AppletSession) ) && AppletSession.getvalue("memo_cnt_new")) ? AppletSession.getvalue("memo_cnt_new") : 0;
      }
      
      $(".myinfo").selectTab(no);
    });
  } else {
    $(".myinfo").selectTab(no);  
  }
}

function tabMainRanking(no) {
  if(no == 2 && !$("#rank_personal_weekly").html()) {
    $.get("/crossfire_ajax.nwz",{call_name:"getDocument",doc:"main_ranking_user"},function(txt) {
      $("#rank_personal_weekly").html(txt);
      $(".ranklist").selectTab(no);
    });
  } else {
    $(".ranklist").selectTab(no);
  }
}

function tabProfile(usn,no) {
  var idx = no-1;
  var call_func = ($(".profile").length == 6) ? ['profileGameInfo','profileClanInfo','profileMyItem','profileMyFriend','profileCapsuleWeapon','profileGuestBook'] : ['profileGameInfo','profileClanInfo','profileGuestBook'];

  if(!$(".profile").eq(idx).html()) {
    $.get("/crossfire_ajax.nwz",{call_name:call_func[idx],usn:usn},function(txt) {
      $(".profile").eq(idx).html(txt);
      $(".profile").selectTab(no);
    });
  } else {
    $(".profile").selectTab(no);
  }
}

function tabGuideStrategy(no) {
  if(no == 2 && !$(".footer_menu").eq(1).html()) {
    $.get("/crossfire_ajax.nwz",{call_name:"getGuideStrategy",keyword:document.getElementsByTagName("h3")[2].innerHTML},function(txt) {
      $(".footer_menu").eq(1).html(txt);
      $(".footer_menu").selectTab(no);
      parent.resize_frame(window.name);
    });
  } else {
    $(".footer_menu").selectTab(no);
    parent.resize_frame(window.name);
  }
}

function tabProfileMyItem(type,page) {
  $.get("/crossfire_ajax.nwz",{call_name:"profileMyItem",type:type,page:page},function(txt) {
    $(".profile").eq(2).html(txt);
  });
}

function tabProfileMyFriend(type,page) {
  $.get("/crossfire_ajax.nwz",{call_name:"profileMyFriend",type:type,page:page},function(txt) {
    $(".profile").eq(3).html(txt);
  });
}

function tabProfileCapsuleWeapon(type,page) {
  var usn = $("input[name=usn]").val();
  
  $.get("/crossfire_ajax.nwz",{call_name:"profileCapsuleWeapon",usn:usn,type:type,page:page},function(txt) {
    $(".profile").eq(4).html(txt);
  });
}

function buyItem(obj, isPoint) {
  if(typeof obj == "number") {
    var saleinfo_id = obj;
  } else {
    var tag = obj.parentNode.parentNode.getElementsByTagName('select');
    var saleinfo_id = tag.length ? tag[0].value : obj.parentNode.parentNode.getElementsByTagName('input')[0].value;
  }
  isPoint ? pub_shop.point_buy(318, saleinfo_id) : pub_shop.buy(318, saleinfo_id);
//  gamepub_check_login() ? (isPoint ? pub_shop.point_buy(318, saleinfo_id) : pub_shop.buy(318, saleinfo_id)) : pub_shop.showdetail(318, saleinfo_id);
}

function giftItem(obj) {
  if(typeof obj == "number") {
    var saleinfo_id = obj;
  } else {
    var tag = obj.parentNode.parentNode.getElementsByTagName('select');
    var saleinfo_id = tag.length ? tag[0].value : obj.parentNode.parentNode.getElementsByTagName('input')[0].value;
  }

  gamepub_check_login() ? pub_shop.gift(318, saleinfo_id) : pub_shop.showdetail(318, saleinfo_id);
}

function itemDetail(item_code) {
  var addr = "/crossfire_item_view.nwz?item_code="+ item_code;
  var ln = "/crossfire_frame.nwz?mKey=3&sKey=1&url="+ encodeURIComponent(addr);
  
  if(window.name == "INFO_DOC") {
    location.href = addr;
  } else if(opener) {
    opener.top.location.href = ln;
    opener.focus();
  } else {
    top.location.href = ln;
  }
}

function itemUse(saleinfo_id,item_code) {
  window.open("/crossfire_item_use_temp.nwz?saleinfo_id="+ saleinfo_id +"&item_code="+ item_code +"&type=use","_CF_ITEM_USE","width=480,height=270");
}

function itemBuy(obj) {
  if(typeof obj == "number") {
    var saleinfo_id = obj;
  } else {
    var tag = obj.parentNode.parentNode.getElementsByTagName('select');
    var saleinfo_id = tag.length ? tag[0].value : obj.parentNode.parentNode.getElementsByTagName('input')[0].value;
  }

  open_win("http://www.pmang.com/gamepub_purchase.nwz?ssn=318&saleinfo_id="+saleinfo_id,"_buy",430,700);
}

function itemGift(obj) {
  if(typeof obj == "number") {
    var saleinfo_id = obj;
  } else {
    var tag = obj.parentNode.parentNode.getElementsByTagName('select');
    var saleinfo_id = tag.length ? tag[0].value : obj.parentNode.parentNode.getElementsByTagName('input')[0].value;
  }

  open_win("http://www.pmang.com/gamepub_gift.nwz?ssn=318&saleinfo_id="+saleinfo_id,"_buy",430,700);
}

function sendMemo(usrid) {
  window.open("http://memo.pmang.com/memosend.nwz?divtype=clan&ssn=209&toid="+ usrid,"memosend","width=440,height=303,toolbar=no,location=no,resizable=yes");  
}

function profileGuestBookAuth(val) {
  var usn = $("input[name=usn]").val();

  $.get("/crossfire_ajax.nwz",{call_name:"profileGuestBookAuth",auth:val},function() {
    //location.href = "?usn="+ usn +"&call_name=profileGuestBook";
  });
}

function profileGuestBookWrite() {
  var usn = $("input[name=usn]").val();
  var comment = $.trim($("input[name=profile_comment]").val());

  if(!comment) {
    alert("³²±â°í ½ÍÀº ¸»À» ÀÔ·ÂÇÏ¿© ÁÖ¼¼¿ä.");
    return;
  }
  
  $.post("/crossfire_ajax.nwz",{call_name:"profileGuestBookWrite",usn:usn,comment:comment},function() {
    profileGuestBookPage(1);
  });
}

function profileGuestBookDelete(srl) {
  var usn = $("input[name=usn]").val();
  
  $.get("/crossfire_ajax.nwz",{call_name:"profileGuestBookDelete",usn:usn,article_srl:srl},function() {
    profileGuestBookPage(1);
  });
}

function profileGuestBookPage(page) {
  var usn = $("input[name=usn]").val();

  $.get("/crossfire_ajax.nwz",{call_name:"profileGuestBook",usn:usn,page:page},function(txt) {
    $(".profile").eq($(".profile").length-1).html(txt);
  });
}

function profileMyFriendAdd(obj) {
  var f = document.fo;
  
  if(typeof obj == "object") {
    $("input[name=input_str]").val($("input[name=str]").val());
    
    if(!$.trim($("input[name=input_str]").val())) {
      pub_alert("´Ð³×ÀÓ(¾ÆÀÌµð)¸¦ ÀÔ·ÂÇÏ¿© ÁÖ½Ê½Ã¿ä.");
      f.input_str.focus();
      return;
    }
    
    f.s_usn.value = "";
  } else {
    $("input[name=s_usn]").val(obj);
  }
  
  f.action = "/gamepub/gamepub_friend_add_proc.nwz"
  f.target = "virtual_fr";
  f.submit();
}

function mediaAction(addr) {
  addr = 'http://crossfire.pmang.com/gamepub/mm_show.nwz?ssn=318&gameid=crossfire&no='+ addr;
  
  if($.browser.msie) {
    clipboardData.setData('Text', addr);
    pub_alert("ÀÌ µ¿¿µ»óÀÇ ÁÖ¼Ò°¡ º¹»çµÇ¾ú½À´Ï´Ù.<br />°Ô½ÃÆÇÀÌ³ª ¸Þ½ÅÀú Ã¢¿¡¼­ Ctrl+V¸¦ ´©¸£½Ã¸é<br />ÇØ´ç µ¿¿µ»óÀÇ ÁÖ¼Ò¸¦ ½±°Ô ¿Å±æ ¼ö ÀÖ½À´Ï´Ù.");
  } else {
    prompt("ÀÌ µ¿¿µ»óÀÇ ÁÖ¼ÒÀÔ´Ï´Ù.\nCtrl+C¸¦ ´©¸£½Ã¸é º¹»çÇÒ ¼ö ÀÖ½À´Ï´Ù.",addr);
  }
}

function guideSearch(obj) {
  var txt = $("input[name=keywords]");

  if(obj.innerHTML.toUpperCase().substr(0,4) != "<IMG" && obj.name != "keywords" && document.body.className != "main") {
    txt.val(obj.innerHTML);
  }

  if(txt.val().length < 2) {
    pub_alert("2ÀÚ ÀÌ»óÀÇ °Ë»ö¾î¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
    return;
  }
  
  var addr = "/crossfire_board.nwz?act=list&ssn=318&bserial=201&lbserial=3&isgroup=Y&page=1&findtype=0&keyword="+ txt.val();

  if(window.name == "INFO_DOC") {
    location.href = addr;
  } else {
    go_menu(2,1,addr);
  }
}
