// SYSTEM

var select_obj = null;
var select_over = false;

document.onclick = on_mouse_click;

function on_mouse_click() {
  if (select_obj && !select_over) {
    select_obj.style.visibility = "hidden";
    select_obj = null;
  }
  
  select_over = false;
}

function show_menu(name,status) {
  var obj = document.all[name];
  var x, y, width, height;
  
  x = event.clientX + parseInt(obj.offsetWidth);
  y = event.clientY + parseInt(obj.offsetHeight);
  
  marginx = document.body.clientWidth - x;
  marginy = document.body.clientHeight - y;
  
  if (marginx < 0)
    x = event.clientX + document.body.scrollLeft + marginx;
  else
    x = event.clientX + document.body.scrollLeft;
  if (marginy < 0)
    y = event.clientY + document.body.scrollTop + marginy;
  else
    y = event.clientY + document.body.scrollTop;
  
  obj.style.posLeft = x;
  obj.style.posTop = y;
  
  if (status == "visible") {
    if (select_obj) {
      select_obj.style.visibility = "hidden";
      select_obj = null;
    }
    select_obj = obj;
    select_over = true;
  } else {
    select_obj = null;
  }
  
  obj.style.visibility = status;
}

function show_info(name,status) {
  var obj = document.all[name];
  var x, y;
  
  if (document.body.clientWidth / 2 > event.clientX) {
    x = event.clientX + document.body.scrollLeft + 10;
    if (x + parseInt(obj.offsetWidth) - document.body.scrollLeft > document.body.clientWidth)
      x = x - (x + parseInt(obj.offsetWidth) - document.body.scrollLeft - document.body.clientWidth);
  } else {
    x = event.clientX + document.body.scrollLeft - parseInt(obj.offsetWidth) - 10;
    if (x < document.body.scrollLeft)
      x = document.body.scrollLeft;
  }
  
  if (document.body.clientHeight / 2 > event.clientY) {
    y = event.clientY + document.body.scrollTop + 10;
    if (y + parseInt(obj.offsetHeight) - document.body.scrollTop > document.body.clientHeight) {
      y = y - (y + parseInt(obj.offsetHeight) - document.body.scrollTop - document.body.clientHeight);
    }
  } else {
    y = event.clientY + document.body.scrollTop - parseInt(obj.offsetHeight) - 10;
    if (y < document.body.scrollTop) {
      y = document.body.scrollTop;
    }
  }
  
  obj.style.posLeft = x;
  obj.style.posTop = y;
  
  if (status == "visible") {
    if (select_obj) {
      select_obj.style.visibility = "hidden";
      select_obj = null;
    }
    select_obj = obj;
    select_over = true;
  } else {
    select_obj = null;
  }
  
  obj.style.visibility = status;
}

function do_blink() {
  var blink = document.all.tags("BLINK");
  for (var i = 0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
}

function start_onload() {
  if (document.all) {
    setInterval("do_blink()", 1000);
  }
}

window.onload=start_onload;



// PAGE

function popup_noacq_emailadd() {
  window.open("../member/popup_noacq_emailadd.php","popup_noacq_emailadd","width=300,height=220");
}

function popup_forget_id() {
  window.open("../member/popup_forget_id.php","popup_forget_id","width=300,height=225");
}

function popup_forget_password() {
  window.open("../member/popup_forget_password.php","popup_forget_password","width=300,height=435");
}

function popup_img(img_file, img_width, img_height) {
  window.open("../mid/popup_img.php?img_file="+img_file,"popup_img","width="+(img_width+10)+",height="+(img_height+48)+",resizable=yes");
}

function popup_mov(mid_id) {
  window.open("../mid/popup_mov.php?mid_id="+mid_id,"popup_mov","width="+(425+10)+",height="+(344+48)+",resizable=yes");
}

// MEMBER

function popup_profile(mbr_id) {
  window.open("../member/popup_profile.php?mbr_id="+mbr_id,"popup_profile","width=634,height=480,scrollbars=yes,resizable=yes");
}

function popup_homepage(homepage) {
  window.open(homepage);
}

function popup_memo(receiver_id) {
  window.open("../member/popup_memo.php?receiver_id="+receiver_id,"popup_memo","width=300,height=280");
}

// GET

function get_bytes_length(str) {
  var str_len = 0;
  
  for (var i = 0; i < str.length; i++) {
    if (escape(str.charAt(i)).length >= 4)
      str_len += 2;
    else
      str_len++;
  }
  
  return str_len;
}

function get_radio_checked(radio) {
  if (radio == null) {
    return false;
  } else if (radio.length == null) {
    return radio.checked;
  } else {
    for (var i = 0; i < radio.length; i++) {
      if (radio[i].checked) return true;
    }
    return false;
  }
}

function get_checkbox_count(checkbox) {
  if (checkbox == null) {
    return 0;
  } else if (checkbox.length == null) { // ¼±ÅÃ Ç×¸ñÀÌ ÇÏ³ª»Ó
    return (checkbox.checked) ? 1 : 0;
  } else {
    var checked_cnt = 0;
    for (var i = 0; i < checkbox.length; i++) {
      if (checkbox[i].checked) checked_cnt++;
    }
    return checked_cnt;
  }
}

// FUNCTION

function ltrim(a) {
  var i = 0;
  while (a.substring(i, i+1) == " " || a.substring(i, i+1) == "¡¡") i = i + 1;
  return a.substring(i);
}

function rtrim(a) {
  var b;
  var i = a.length - 1;
  while (i >= 0 && (a.substring(i, i+1) == " " || a.substring(i, i+1) == "¡¡")) i = i - 1;
  return a.substring(0, i+1);
}

function trim(a) {
  return(ltrim(rtrim(a)));
}

function rpad(str, len, ch) {
  if (typeof(str) != "string")
    str = str.toString();
  
  var strlen = trim(str).length;
  var ret = "";
  var alen = len - strlen;
  var astr = "";
  
  //ºÎÁ·ÇÑ ¼ýÀÚ¸¸Å­ len Å©±â·Î ch ¹®ÀÚ·Î Ã¤¿ì±â
  for (var i = 0; i < alen; ++i) {
    astr = astr + ch;
  }
  
  ret = trim(str) + astr; //µÚ¿¡¼­ Ã¤¿ì±â
  
  return ret;
}

function lpad(str, len, ch) {
  if (typeof(str) != "string")
    str = str.toString();
  
  var strlen = trim(str).length;
  var ret = "";
  var alen = len - strlen;
  var astr = "";
  
  //ºÎÁ·ÇÑ ¼ýÀÚ¸¸Å­ len Å©±â·Î ch ¹®ÀÚ·Î Ã¤¿ì±â
  for (var i = 0; i < alen; ++i) {
    astr = astr + ch;
  }
  
  ret = astr + trim(str); //¾Õ¿¡¼­ Ã¤¿ì±â
  
  return ret;
}

// CHECK

function is_hangul(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i, 1).toUpperCase();
    if (one_char < "°¡" || one_char > "ÆR") return false;
  }
  return true;
}

function is_alphabet(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i,1).toUpperCase();
    if (one_char < "A" || one_char > "Z") return false;
  }
  return true;
}

function is_number(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i,1).toUpperCase();
    if (one_char < "0" || one_char > "9") return false;
  }
  return true;
}

function is_alphabet_or_number(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i, 1).toUpperCase();
    if ((one_char < "A" || one_char > "Z") && (one_char < "0" || one_char > "9")) return false;
  }
  return true;
}

function is_hangul_or_number(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i, 1).toUpperCase();
    if ((one_char < "°¡" || one_char > "ÆR") && (one_char < "0" || one_char > "9")) return false;
  }
  return true;
}

function is_hangul_or_alphabet_or_number(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i, 1).toUpperCase();
    if ((one_char < "°¡" || one_char > "ÆR") && (one_char < "A" || one_char > "Z") && (one_char < "0" || one_char > "9")) return false;
  }
  return true;
}

function is_all_space(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i,1);
    if (one_char != " ") return false;
  }
  return true;
}

function is_valid_email(str) {
  for (var i = 0; i < str.length; i++) {
    var one_char = str.substr(i,1).toUpperCase();
    if ((one_char < "0" || one_char > "9") && (one_char < "A" || one_char > "Z") && one_char != "." && one_char != "-" && one_char != "_") return false;
  }
  return true;
}
