// ÇÃ·¡½Ã ½ºÅ©¸³Æ®
function printFlashObject(flash_src,name,width,height,option_param_tag){
  obj_html = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' width='"+width+"' height='"+height+"' id='"+name+"' align='middle'>\
  <param name='allowScriptAccess' value='always' />\
  <param name='movie' value='"+flash_src+"' />\
  <param name='quality' value='high' />\
  <param name='bgcolor' value='#ffffff' />\
  <param name='wmode' value='transparent'>\
  <param name='menu' value='false'>";
  obj_html = obj_html + option_param_tag;
  obj_html = obj_html + "<embed src='"+flash_src+"' quality='high' bgcolor='#ffffff' width='"+width+"' height='"+height+"' name='"+name+"' align='middle' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />\
  </object>";
  document.write(obj_html);
}

// ¹Ìµð¾îÇÃ·¹ÀÌ¾î ½ºÅ©¸³Æ®
function printPlayerObject(file_src,name,width,height,file_start,option_param_tag){
  obj_html = "<object CLASSID=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width='"+width+"' height='"+height+"' id='"+name+"' />\
  <param name='URL' value='"+file_src+"' />\
  <param name='AutoStart' value='"+file_start+"'>";
  obj_html = obj_html + option_param_tag;
  obj_html = obj_html + "</object>";
  document.write(obj_html);
}

// PNG»ç¿ë
function setPng24(obj) {  
    obj.width=obj.height=1;  
    obj.className=obj.className.replace(/\bpng24\b/i,'');  
    obj.style.filter =  
    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"  
    obj.src='http://file.pmang.kr/images/pmang/tenvi/ob/img/common/blank.gif';   
    return '';  
}

//Æ÷Ä¿½º Blur ÇÔ¼ö
function bluring(){ 
  if(event.srcElement.tagName == "A" || event.srcElement.tagName == "IMG")
  document.body.focus(); 
} 
document.onfocusin=bluring;

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if ( pattern.test(els[i].className) ) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function addEvent( obj, type, fn ) {
  if (obj.addEventListener) {
    obj.addEventListener( type, fn, false );
    EventCache.add(obj, type, fn);
  }
  else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
    obj.attachEvent( "on"+type, obj[type+fn] );
    EventCache.add(obj, type, fn);
  }
  else {
    obj["on"+type] = obj["e"+type+fn];
  }
}

var EventCache = function(){
  var listEvents = [];
  return {
    listEvents : listEvents,
    add : function(node, sEventName, fHandler){
      listEvents.push(arguments);
    },
    flush : function(){
      var i, item;
      for(i = listEvents.length - 1; i >= 0; i = i - 1){
        item = listEvents[i];
        if(item[0].removeEventListener){
          item[0].removeEventListener(item[1], item[2], item[3]);
        };
        if(item[1].substring(0, 2) != "on"){
          item[1] = "on" + item[1];
        };
        if(item[0].detachEvent){
          item[0].detachEvent(item[1], item[2]);
        };
        item[0][item[1]] = null;
      };
    }
  };
}();

// ÇÃ·ÎÆÃ ½ºÅ©¸³Æ®
function Floating(FloatingObj,MarginY,Percentage,setTime) {
  this.FloatingObj = FloatingObj;
  this.FloatingObj.style.position = "absolute";
  this.MarginY = (MarginY) ? MarginY : 0;
  this.Percentage = (Percentage) ? Percentage : 20;
  this.setTime = (setTime) ? setTime : 10;
  this.Run();
}
Floating.prototype.Run = function () {
  var This = this;
  var FloatingObjTop = (this.FloatingObj.style.top) ? parseInt(this.FloatingObj.style.top,10) : this.FloatingObj.offsetTop;
  var DocTop = document.body.scrollTop + this.MarginY;
  var MoveY = Math.abs(FloatingObjTop - DocTop);
//  var maxTop = document.body.scrollHeight - dv_float_on.scrollHeight;
  MoveY = Math.ceil(MoveY / this.Percentage);
  if (FloatingObjTop < DocTop) {
//    if(FloatingObjTop < maxTop){
      this.FloatingObj.style.top = FloatingObjTop + MoveY + "px";   
//    }
  } else {
    this.FloatingObj.style.top = FloatingObjTop - MoveY + "px";
  }
  setTimeout(function () { This.Run(); },This.setTime);
}

//ÇÃ·ÎÆÃ ¹è³Ê
function floatMenuOpen(){
  document.getElementById('dv_float_off').style.display="none";
  document.getElementById('dv_float_on').style.display="block";
  return;
}
function floatMenuClose(){
  document.getElementById('dv_float_on').style.display="none";
  document.getElementById('dv_float_off').style.display="block";
  return;
}

function floatMenuMove(){
    if(document.body.clientWidth > 1145 ){
      floatMenuOpen();
    }
    else { 
      floatMenuClose();       
    }   
  }

// ´ë¿îµ¿È¸ ·Ñ¸µ Start
var healtyPREV = -1;
var healtyNEXT = 1;
var healtyNum = null;
var healtyRun = true;
var healtyCount = 0;
var healtytimer;

healtyRolling = function(){
	if(!document.getElementById('dv_main')) return;
	var maxNum = getElementsByClass('rank',document.getElementById('dv_center')).length;
	if(!healtyCount || healtyCount>=maxNum) healtyCount = 1;
	else {
		healtyCount++;
	}
	for(i=1;i<=maxNum;i++){
		randomId = document.getElementById('tv_weekrank_'+i);
		if(i==healtyCount){
			healtyNum = i;
			randomId.style.display='block';
			clearInterval(healtytimer);
			setTimeout("healtyStart(healtyNum);", 1000);
		}
		else {
			randomId.style.display='none';
		}
	}

	if(healtyRun){
		var time = 9000;
		setTimeout("healtyRolling();", time);
	}
}

function healtyStart(healtyNum){
	healtytimer = setInterval("healtyServerChg(healtyNum, healtyNEXT)", 3000);
}

function healtyServerChg(healtyNum, offset) {
	var current = 0;
	var node = document.getElementById('tv_weekrank_'+healtyNum);
	var list = getElementsByClass('healty_rank', node);
	if (list.length <= 1) return;
	for ( var i=0; i<list.length; i++ ) {
		if ( list[i].style.display != 'none') current = i;
		list[i].style.display = 'none';
	}
	if (offset < 0) {
		if ( current == 0) current = list.length-1;
		else current--;
	}
	else if (offset > 0) {
		if ( current == (list.length-1)) current = 0;
		else current++;
	}
	list[current].style.display = 'block';
}
// ´ë¿îµ¿È¸ ·Ñ¸µ End

function game_start()
{
  run_pubgame();
}

function go_home()
{
  top.location = "tenvi_home.nwz?ssn=326&intro=done";
}

function go_menu(param1,param2)
{
  document.location.href = "tenvi_frame.nwz?mKey="+param1+"&sKey="+param2;
}

function ingEventPage(page, max_page)
{  
  for ( var i = 1; i <= max_page; i++ )
  {
  if ( i == page )
    eval("document.all.ing_page_" + i + ".style.display = ''");
  else
    eval("document.all.ing_page_" + i + ".style.display = 'none'");
  }
  
  p_resizeiframe('INFO_DOC');
}

function endEventPage(page, max_page)
{
  for ( var i = 1; i <= max_page; i++ )
  {
  if ( i == page )
    eval("document.all.end_page_" + i + ".style.display = ''");
  else
    eval("document.all.end_page_" + i + ".style.display = 'none'");
  }
  
  p_resizeiframe('INFO_DOC');
}

function ingEvent()
{
  document.all.ing_Event.style.display = "";
  document.all.end_Event.style.display = "none";
  p_resizeiframe('INFO_DOC');
}
function endEvent()
{
  document.all.ing_Event.style.display = "none";
  document.all.end_Event.style.display = "";
  p_resizeiframe('INFO_DOC');
}

function user_info_pop(usn)
{  
  window.open('/tenvi_user_pop.nwz?usn='+usn, 'policy', 'resizable=no,width=400,height=350');
}

function pop_user_info(usn,tsn,world,csn)
{  
  window.open('/tenvi_user_pop.nwz?type=rank&usn='+usn+'&tsn='+tsn+'&world='+world+'&csn='+csn, 'policy', 'resizable=no,width=400,height=350');
}

function tester_pop()
{
  //window.open('/poll_326_1.nwz', 'tester', 'resizable=no,width=640,height=800,scrollbars=yes'); 
  window.open('http://file.pmang.com/images/pmang/tenvi/ob/img/popup/event_20071120_pop.html','_event', 'width=355, height=309,fullscreen=no,menubar=no,status=no,toolbar=no,titlebar=no,location=no,scrollbar=no');
}

function pop_policy()
{
  switch ( document.domain )
  {
	  case "tooniland.com" :
	    window.open('http://tenvifile.tooniland.com/images/pmang/gamepub/police/tenvi_tooniland.html#12', 'policy', 'resizable=no,width=670,height=550,scrollbars=no');
	    break;
	  case "buddybuddy.co.kr":
	    window.open('http://tenvifile.buddybuddy.co.kr/images/pmang/gamepub/police/tenvi_buddy.html#12', 'policy', 'resizable=no,width=670,height=550,scrollbars=no');
	    break;
	  default:
	    window.open('http://file.pmang.kr/images/pmang/gamepub/police/tenvi.html#12', 'policy', 'resizable=no,width=670,height=550,scrollbars=no');
	}
}

function go_policy()
{ 
//  go_menu(1,98);
  window.open('http://file.pmang.kr/images/pmang/gamepub/police/tenvi.html', 'policy', 'resizable=no,width=670,height=550,scrollbars=no');
}

function pop_alarm()
{
  window.open('/event/email/cb_alarm.nwz', 'alarm', 'resizable=no,width=400,height=390,scrollbars=yes');
}

function tenvi_begin_game()
{
  document.location.href ="/gamepub/game_running.nwz?ssn=326";
}

function tenvi_finish_game()
{
  document.location.href ="/gamepub/game_end_proc.nwz?ssn=326";
}

function pop_friend() 
{
  window.open('/event/20071112/tenvi_friend.nwz', 'friend', 'resizable=no,width=344,height=280,scrollbars=no');
}

function giftTicket()
{
  var saleinfo_id = document.all.giftticket.value;
  open_win('http://www.pmang.com/gamepub_gift_ticket.nwz?saleinfo_id='+saleinfo_id+'&ssn=326','',420,600);
}

function go_menu_url(param1,param2,url)
{
  document.location.href = "/tenvi_frame.nwz?mKey="+param1+"&sKey="+param2+"&url="+urlencode(url);
}

function open_event_popup()
{
  var cookie= getCookie("tv_open_event");

  if ( cookie == "" )
  {
    window.open('/event/20071218/game_end_popup.nwz', '_event', 'width=390,height=530,resizable=no,scrollbars=no,scrolling=no' );
  }
}

function open_pcbang() 
{
  window.open('/gamepub/pcbang.nwz?ssn=326', 'pcbang', 'resizable=no,width=560,height=690');
}

function poll_081218()
{
  window.open('/tenvi_board.nwz?act=read&ssn=326&bserial=15&lbserial=15&ano=16945663&no=1', 'tester', 'resizable=no,width=500,height=550,scrollbars=no');
}

function poll_081202()
{
  window.open('/tenvi_board.nwz?act=read&ssn=326&bserial=15&lbserial=15&ano=16770930&no=1', 'tester', 'resizable=no,width=500,height=550,scrollbars=no');
}

//home ÇÐ±³´ëÇ×Àü ÇÐ±³ Ç¥½Ã
function openBalloon(text)
{
	document.getElementById('dv_rank_balloon').innerText=text; 
	document.getElementById('dv_rank_balloon').style.display="block";
	document.getElementById('dv_rank_balloon').style.pixelTop=event.y+document.body.scrollTop+10; 
	document.getElementById('dv_rank_balloon').style.pixelLeft=event.x+document.body.scrollLeft;
}
function closeBalloon()
{
	document.getElementById('dv_rank_balloon').style.display="none";
}

function school_popup()
{
	window.open("/event/20080221/rank.nwz?event=ok&type=1&min=0&max=10", "_prize", "resizable=no,width=495,height=640,scrollbars=no" );
}

function tenvi_guide()
{
  document.location.href ="/tenvi_beginner_guide.nwz";
}

function tenvi_guide_pop()
{
  window.open("/tenvi_guide_basic.nwz", "_guide", "resizable=no,width=964,height=610,scrollbars=no" );
}

function pop_user_skill(usn,tsn,world,csn)
{  
  window.open('/tenvi_skill_popup.nwz?usn='+usn+'&tsn='+tsn+'&world='+world+'&csn='+csn, 'skill_pop', 'resizable=no,width=820,height=610');
}

function hide_update_pop()
{
	if (document.all.no_pop.checked)
		setCookie("tv_20080626","close", 1);

	document.getElementById('dv_update_counter').style.display = "none";
}

function displaySkill(id){
	if(document.getElementById(id).style.display=="block"){
		document.getElementById(id).style.display='none'
	}
	else {document.getElementById(id).style.display='block'}
}

function tenvi_buddy_login()
{
  var form = document.getElementsByName("gc_login")[0];

  var gc_id = form.id;
  var gc_pwd = form.pwd;
  if (gc_id.value == "")
  {
    alert(" ¾ÆÀÌµð¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä ");
    gc_id.focus();
    return;
  }
  if (gc_pwd.value == "")
  {
    alert(" ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä ");
    gc_pwd.focus();
    return;
  }
  var obj = document.createElement("<INPUT TYPE='HIDDEN' NAME='url'>");
  form.appendChild( obj );
  form.url.value = document.location;
  form.action = ((form.secchk.checked) ? "https" : "http") + "://user.buddybuddy.co.kr/Login/Login.asp";
  document.charset = "ks_c_5601-1987";
  form.submit();
}

function tenvi_buddy_charge()
{
  var form = document.getElementById("gc_charge");

  window.open( 'about:blank', form.target, 'width=400,height=300' );
  form.submit();
}

 function talk_tenvi()
  {
    if ( document.all.ask.value.length < 2 )
    {
      alert("2ÀÚ ÀÌ»óÀ¸·Î ¹°¾îº¸¼¼¿ä.");
      return;
    }
    //var url = "/gamepub/gamepub_faq.nwz?ssn=326&bserial=0&keyword=";
    if ( document.location.hostname == "tenvi.tooniland.com" )
     	var url = "http://tenvihelp.tooniland.com/Publishing/TenviTooni/FMLB_FaqSearch.aspx?hidKeyword=";
    else if (document.location.hostname == "tenvi.buddybuddy.co.kr" )
    	var url = "http://tenvihelp.buddybuddy.co.kr/Publishing/TenviBuddy/FMLB_FaqSearch.aspx?hidKeyword=";
    else
    	var url = "http://help.pmang.com/Publishing/Tenvi/FMLB_FaqSearch.aspx?hidKeyword=";
    document.location.href = "/tenvi_frame.nwz?mKey=7&sKey=1&url="+urlencode(url)+document.all.ask.value;
  }
  function talk_tenvi_msg(msg)
  {
    var url = "/gamepub/gamepub_faq.nwz?ssn=326&bserial=0&keyword=";
    document.location.href = "/tenvi_frame.nwz?mKey=7&sKey=1&url="+urlencode(url)+msg;
  }
  function write_tenvi()
  {
    document.all.ask.value = "";
  }
