function search_check() {
  var form = document.searchform;
  if(!form.search.value) {
    alert('검색어를 입력해주세요.');
    form.search.focus();
    return false;
  }
}
function ZB_layerAction(num) {
  window.open('./view_info2.php?member_no='+num,'info','width=400,height=510,statusbar=no,scrollbars=yes,toolbar=no')
}

//물결 플래쉬용
// main function
function showTitle(srcUrl, srcFilename, width, height, titleStr, linkStr, hAlign, tColor)
{
	var str = "<embed id=\"viewTitle\" name=\"viewTitle\" type=\"application/x-shockwave-flash\" src=\"" +
				srcUrl + srcFilename + "\" width=\"" + width + "\" height=\"" + height + "\" wmode=\"transparent\"" + " allowScriptAccess=\"always\"" + "FlashVars=\"" +
				"articleTitle="+ pEncode(titleStr) +"&linkTo=" + linkStr + "&hAlign=" + hAlign + "&tColor="+ tColor + "\"/>";

//	window.alert(str);
	document.write(str);
}

// percent-encoding
function pEncode(str)
{
	str = str.replace(/&amp;/g, "%26");
	//str = str.replace(/[&]/g, "%26");
	str = str.replace(/[+]/g, "%2b");

	return str;
}

//게임정보 덧글 접이용
function showcom(aaa) {
  if($("commentdiv").style.display=='block') {
    $("commentdiv").style.display = 'none';
    $("commentframe").src = '../game/game_no_comment.php';
  } else {
    $("commentdiv").style.display = 'block';
    $("commentframe").src = '../game/game_comment.php?no=' + aaa;
  }
}

function resizeIfr(obj, minHeight) {
 minHeight = minHeight || 10;
 try {
  var getHeightByElement = function(body) {
   var last = body.lastChild;
   try {
    while (last && last.nodeType != 1 || !last.offsetTop) last = last.previousSibling;
    return last.offsetTop+last.offsetHeight;
   } catch(e) {
    return 0;
   }
  }

  var doc = obj.contentDocument || obj.contentWindow.document;
  if (doc.location.href == 'about:blank') {
   obj.style.height = minHeight+'px';
   return;
  }

  //var h = Math.max(doc.body.scrollHeight,getHeightByElement(doc.body));
  //var h = doc.body.scrollHeight;
  if (/MSIE/.test(navigator.userAgent)) {
   var h = doc.body.scrollHeight;
  } else {
   var s = doc.body.appendChild(document.createElement('DIV'))
   s.style.clear = 'both';

   var h = s.offsetTop;
   s.parentNode.removeChild(s);
  }

  //if (/MSIE/.test(navigator.userAgent)) h += doc.body.offsetHeight - doc.body.clientHeight;
  if (h < minHeight) h = minHeight;

  obj.style.height = h + 'px';
  if (typeof resizeIfr.check == 'undefined') resizeIfr.check = 0;
  if (typeof obj._check == 'undefined') obj._check = 0;

//  if (obj._check < 5) {
//   obj._check++;
   setTimeout(function(){ resizeIfr(obj,minHeight) }, 200); // check 5 times for IE bug
//  } else {
   //obj._check = 0;
//  }
 } catch (e) {
  //alert(e);
 }
}

function preview() {
  var form = document.icon_add;
  window.open("about:blank","preview", "");
  form.target = "preview";
  form.action = "http://www.coteaven.net/game/game_preview.php";
  form.submit();
}

//통합검색용
function main_search_check() {
  var form = document.search_form;

  if(form.keyword.value=='') {
    alert("검색어를 입력해주세요.");
    form.keyword.focus();
    return false;
  } else {
    form.action = '../search.php';
  }
}

//브라우져 버전 체크
var detect = navigator.userAgent.toLowerCase();
var isMsie = (detect.indexOf('msie') != -1 ? true : false);
var isFirefox = (detect.indexOf('firefox') != -1 ? true : false);
//var isSafari = (detect.indexOf('safari') != -1 ? true : false);
var isChrome = (detect.indexOf('chrome') != -1 ? true : false);
//var isOpera = (detect.indexOf('opera') != -1 ? true : false);

function checkbrowser() {
  var update_html = "";
  if(isMsie==true) {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );
    var iv = parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));

    if(iv < 7) {
      var update_msg = "on";
    }

  } else if(isFirefox==true) {
    var ua = window.navigator.userAgent;
    var ff = ua.indexOf ( "Firefox/" );

    var iv = ua.substring (ff+8,ff+11);
    var nv = 3.0;

    if(iv < nv) {
      update_msg = "on";
    }

  } else if(isChrome==true) {
    var ua = window.navigator.userAgent;
    var cr = ua.indexOf ( "Chrome/" );
    var iv = ua.substring (cr+7,cr+10);

    if(iv < 3.0) {
      update_msg = "on";
    }

  }

  if(update_msg=="on") {
    update_html += "<div style='border:1px solid #000000;width:990px;height:80px;padding:10px;'>";
    update_html += "<span style='color:#ff0000;font-weight:bold;'>동인천국은 IE7, IE8, 파이어폭스, 구글 크롬의 최신버전에 최적화되어 있습니다. 브라우저를 업데이트 해주세요.<\/span><br \/><br \/>";
    update_html += "<a href='http://www.microsoft.com/korea/windows/internet-explorer/ie7.aspx' target='_blank'>[인터넷 익스플로러 7 다운로드]<\/a> || <a href='http://www.microsoft.com/korea/windows/downloads/default.aspx' target='_blank'>[인터넷 익스플로러 8 다운로드]<\/a> || <a href='http://www.mozilla.or.kr/ko/' target='_blank'>[파이어폭스 3.5.3 다운로드]<\/a> || <a href='http://www.google.com/chrome/?hl=ko' target='_blank'>[구글 크롬 최신버전 다운로드]<\/a><br \/><br \/>";
    update_html += "<span style='color:#ff0000;font-weight:bold;'>※ 이 메세지는 익스플로러를 업데이트하기 전까지 계속 보입니다.<\/span><br \/><br \/>";
    update_html += "<\/div>";
    if(update_html) {
      $("div#check_browser").show().html(update_html);
    }
  }
}

//문자열 체크
// 영문
  function check_eng(val,ment,which,extra) {
    if (extra == 'id')
    {
      ex = /^[a-zA-Z]/;
      if (ex.test(val.substr(0,1))) {
      } else {
        alert(ment+'첫자리가 알파벳이어야 합니다.');
        return false;
      }
    }
    if (which == 'coterieid') {
      ex = /[a-z0-9_]/;
      attachment = '소문자 영문,숫자,언더바(_)만 가능합니다.';
    } else if (which == 'eng') {
      ex = /[a-zA-Z]/;
      attachment = '영문만 가능합니다.';
    } else if (which == 'engdig') {
      ex = /[a-zA-Z0-9]/;
      attachment = '영문,숫자만 가능합니다.';
    } else if (which == 'engdigbar') {
      ex = /[a-zA-Z0-9_]/;
      attachment = '영문,숫자,언더바만 가능합니다.';
    } else if (which == 'engdigminusdot') {
      ex = /[a-zA-Z0-9-.]/;
      attachment = '영문,숫자,하이픈,점만 가능합니다.';
    } else if (which == 'engdigminusbar') {
      ex = /[a-zA-Z0-9-_]/;
      attachment = '영문,숫자,하이픈,언더바만 가능합니다.';
    } else if (which == 'engdigblk') {
      ex = /[a-zA-Z0-9 ]/;
      attachment = '영문,숫자,빈칸만 가능합니다.';
    } else if (which == 'engdigblkcom') {
      ex = /[a-zA-Z0-9 ,]/;
      attachment = '영문,숫자,빈칸,콤마만 가능합니다.';
    } else if (which == 'engdigblkcomdot') {
      ex = /[a-zA-Z0-9 ,.]/;
      attachment = '영문,숫자,빈칸,콤마,점만 가능합니다.';
    } else if (which == 'engdigblkcomdotminus') {
      ex = /[a-zA-Z0-9 ,.-]/;
      attachment = '영문,숫자,빈칸,콤마,점,하이픈만 가능합니다.';
    } else if (which == 'engdigminusgol') {
      ex = /[a-zA-Z0-9-.@]/;
      attachment = '영문,숫자,하이픈,점,@만 가능합니다.';
    }
 for (i=0;i<val.length;i++) {
      str = '';
      str = val.substr(i,1);
      if (ex.test(str)) {
      } else {
        alert(ment+attachment);
        return false;
      }
    }
    return true;
  }
  // 한글
  function check_kor(val,ment,which) {
    if (which == 'kor') {
      ex = /[가-힣]/;
      attachment = '한글만 가능합니다.';
    } else if (which == 'kordig') {
      ex = /[가-힣0-9]/;
      attachment = '한글,숫자만 가능합니다.';
    } else if (which == 'kordigblk') {
      ex = /[가-힣0-9 ]/;
      attachment = '한글,숫자,빈칸만 가능합니다.';
    } else if (which == 'kordigblkcom') {
      ex = /[가-힣0-9 ,]/;
      attachment = '한글,숫자,빈칸,콤마만 가능합니다.';
    } else if (which == 'kordigblkcomdot') {
      ex = /[가-힣0-9 ,.]/;
      attachment = '한글,숫자,빈칸,콤마,점만 가능합니다.';
    } else if (which == 'kordigblkcomdotminus') {
      ex = /[가-힣0-9 ,.-]/;
      attachment = '한글,숫자,빈칸,콤마,점,하이픈만 가능합니다.';
    }
    for (i=0;i<val.length;i++) {
      str = '';
      str = val.substr(i,1);
      if (ex.test(str)) {
      } else {
        alert(ment+attachment);
        return false;
      }
    }
    return true;
  }
  // 한글,영문
  function check_koreng(val,ment,which) {
    if (which == 'koreng') {
      ex = /[가-힣a-zA-Z]/;
      attachment = '한글,영문만 가능합니다.';
    } else if (which == 'korengdigminus') {
      ex = /[가-힣a-zA-Z0-9-]/;
      attachment = '한글,영문,숫자,하이픈만 가능합니다.';
    } else if (which == 'korengdigblk') {
      ex = /[가-힣a-zA-Z0-9 ]/;
      attachment = '한글,영문,숫자,빈칸만 가능합니다.';
    } else if (which == 'korengdigblkminus') {
      ex = /[가-힣a-zA-Z0-9 -]/;
      attachment = '한글,영문,숫자,빈칸,하이픈만 가능합니다.';
    } else if (which == 'kordigblkcomdotminus') {
      ex = /[가-힣a-zA-Z0-9 ,.-_]/;
      attachment = '한글,영문,숫자,빈칸,하이픈,언더바만 가능합니다.';
    }
    for (i=0;i<val.length;i++) {
      str = '';
      str = val.substr(i,1);
      if (ex.test(str)) {
      } else {
        alert(ment+attachment);
        return false;
      }
    }
    return true;
  }
  // 숫자
  function check_digit(val,ment,which) {
    if (which == 'dig') {
      ex = /[0-9]/;
      attachment = '숫자만 가능합니다.';
    } else if (which == 'digcom') {
      ex = /[0-9,]/;
      attachment = '숫자,콤마만 가능합니다.';
    } else if (which == 'digminus') {
      ex = /[0-9-]/;
      attachment = '숫자,하이픈만 가능합니다.';
    }
    for (i=0;i<val.length;i++) {
      str = '';
      str = val.substr(i,1);
      if (ex.test(str)) {
      } else {
        alert(ment+attachment);
        return false;
      }
    }
    return true;
  }
  function fc_chk_byte(ele,maxlen) {
    var ls_str      =  ele;
    var li_str_len  =  ls_str.length;
    var li_max      =  maxlen;
    var li_byte     =  0;
    var li_len      =  0;
    var ls_one_char =  "";
    var ls_str2     =  "";
    for (i=0;i<li_str_len;i++) {
       ls_one_char =  ls_str.charAt(i);
       if (escape(ls_one_char).length > 4) {
          li_byte =  li_byte+2;
       } else {
          li_byte++;
       }
       if(li_byte <=  li_max) {
          li_len =  i + 1;
       }
    }
    if(li_byte > li_max) {
      alert("아이디는 "+li_max+"바이트를 초과 입력할수 없습니다.");
      return false;
    }
    return true;
  }


function now_conn() {
  $("#nowconn").load("/now_conn.php");
  window.setTimeout('now_conn()',60000);
}


function traffic() {
  $(".traffic").load("http://www.coteaven.net/cband-status-me?unit=M").hide(1,function(){
    var test = $(".traffic").text();
    var t = test.split("MBU/U/");
    var s = t[0].split("3000MB/3000MB/");
    var y = eval(3000 - Math.round(s[1],0));
    var n = eval(Math.round(s[1],0) / 3000);
    var x = 100 - Math.round(n * 100,0);
    $(".traffic").html('<div class="tra1" style="width:'+x+'%;background-color:#FFFF00;"></div>').show(1,function(){
      $(".traffic").attr("title","현재 트래픽은 "+y+"/3000 입니다.");
    });
  });
}

function toggle_mutter() {
  if($('#member_mutter').height()==100) {
    $('#member_mutter').css('height','');
    $('#mutter_image').attr('src','../image/close.gif').attr('title','접기');
  } else if($('#member_mutter').height()>100) {
    $('#member_mutter').css('height',100);
    $('#mutter_image').attr('src','../image/open.gif').attr('title','펼침');
  }
}

function content_edit(n) {
  $("div#clbox_load").fadeIn(500);
  $('.game_button').attr('disabled','disabled');
  $.post("content_edit.php", {
    no: n
  }, function(data){
    $('#game_content').html(data);
    $("div#clbox_load").fadeOut(500);
  });
}

function content_edit_ok(n) {
  $("div#clbox_load").fadeIn(500);
  $('.game_button').attr('disabled','disabled');
  $.post("content_edit_ok.php", {
    content: $('#content').val(),
    no: n
  }, function(data){
    $('#game_content').html(data);
    $('.game_button').removeAttr("disabled");
    $("div#clbox_load").fadeOut(500);
  });
}

//쿠키 플러그인
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


function __page_start() {
  $("div#clbox_back").css("opacity","0.6");
  $("div#clbox_load").fadeOut(500);
  $("div#wrapper").show();
  $(".mutter_image").each(function(i) {
    if(this.width<this.height) {
      if(this.height>700) {
        this.style.height = 700+'px';
      }
    } else {
      if(this.width>700) {
        this.style.width = 700+'px';
      }
    }
  });
  $("img.zb_target_resize").each(function(i) {
    if($(this).width()>740) {
      $(this).width(740+'px');
    }
  });
}

function __chrome_patch() {
  $("img.zb_target_resize").each(function(i) {
    if($(this).width()>740) {
      $(this).width(740+'px');
    }
  });
}

$(document).ready(function() {
  __page_start();
  if($.browser.safari==true || $.browser.opera==true) {
    window.setTimeout('__chrome_patch()',200);
  }
  $("#header > .main_logo").mouseenter(function(){
    $(this).css('background-image','url(/image/top_background2.png)');
  }).mouseleave(function(){
    $(this).css('background-image','url(/image/top_background1.png)');
  });
  $(".nowon").hover(function(){
    $("#nowconn").show();
  },function(){
    $("#nowconn").hide();
    $("#nowconn").hover(function(){
      $("#nowconn").show();
    },function(){
      $("#nowconn").hide();
    });
  });
});
