/*============================================================
 * Spec      : ¸ð´Þ À©µµ¿ì ÇÔ¼ö
 * Parameter : vWidth >> À©µµ¿ì³Êºñ
 * Parameter : vHeight >> À©µµ¿ì³ôÀÌ
 * Parameter : vUrl >> ¸µÅ© ÁÖ¼Ò
 * Return  : void
 * example   : modalWindow(300, 500, 'http://www.opop.com/popup/');
 ============================================================*/
function modalWindow(vWidth, vHeight, vUrl) {
  var mdWindow=null;
  //var kiho = (vUrl.indexOf("?")<0)?"?":"&";
  var x=(screen.width-vWidth)/2;
  var y=(screen.height - vHeight)/2;
  opt="status:no; help:no; edge:raised;";
  opt=opt+"dialogWidth:"+vWidth+"px; dialogHeight:"+vHeight+"px; dialogLeft:"+x+";scroll:no; dialogTop:"+y+";";
  var mdWindow=showModalDialog(vUrl, window, opt);
}

/*============================================================
 * Spec    : ÆË¾÷À©µµ¿ì ÇÔ¼ö(¿øÇÏ´Â Å©±â·Î Åø¹Ù¾øÀÌ È­¸é °¡¿îµ¥ ¶ç¿ì±â)
 * Parameter : vWidth >> À©µµ¿ì³Êºñ
 * Parameter : vHeight >> À©µµ¿ì³ôÀÌ
 * Parameter : vUrl >> ¸µÅ© ÁÖ¼Ò
 * Parameter : vOpt >> ½ºÅ©·Ñ À¯¹«(0:¾øÀ½, 1:ÀÖÀ½, ±âº»°ªÀº 0)
 * Return  : void
 * example   : openWindow(300, 500, 'http://www.opop.com/popup/',0);
 ============================================================*/
function openWindow(vWidth, vHeight, vUrl, vOpt) {
  var mdWindow = null;
  var x = (screen.width - vWidth)/2;
  var y = (screen.height - vHeight)/2;
  var opt;
  if (vOpt == "" || vOpt == null) vOpt = 0;
  opt =     "width=" + vWidth + ",height=" + vHeight;
  opt = opt + ",scrollbars=" + vOpt + ",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0";
  opt = opt + ",outerWidth=" + vWidth + ",outerHeight=" + vHeight + ",resizable=0";
  opt = opt + ",left=" + x + ",top=" + y;
  opt = opt + ",channelmode=no, titlebar=no";
  var mdWindow = window.open(vUrl, "", opt, false);
}

function openNameWindow(vWidth, vHeight, vUrl, vName, vOpt) {//ÀÎ½ºÅÏ½ºÀÌ¸§ ÀÖ´Â Ã¢ ¿­±â.
  var mdWindow = null;
  var x = (screen.width - vWidth)/2;
  var y = (screen.height - vHeight)/2;
  var opt;
  if (vOpt == "" || vOpt == null) vOpt = 0;
  opt =     "width=" + vWidth + ",height=" + vHeight;
  opt = opt + ",scrollbars=" + vOpt + ",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0";
  opt = opt + ",outerWidth=" + vWidth + ",outerHeight=" + vHeight + ",resizable=0";
  opt = opt + ",left=" + x + ",top=" + y;
  opt = opt + ",channelmode=no, titlebar=no";
  var mdWindow = window.open(vUrl, vName, opt, false);
  if(!mdWindow){
    alert("ÆË¾÷Â÷´ÜÀ» ÇØÁ¦ÇØÁÖ¼¼¿ä.");
    return false;
  }
  mdWindow.focus();
  return mdWindow;
}

function openNameWindowNoAlert(vWidth, vHeight, vUrl, vName, vOpt) {//ÀÎ½ºÅÏ½ºÀÌ¸§ ÀÖ´Â Ã¢ ¿­±â.
  var mdWindow = null;
  var x = (screen.width - vWidth)/2;
  var y = (screen.height - vHeight)/2;
  var opt;
  if (vOpt == "" || vOpt == null) vOpt = 0;
  opt =     "width=" + vWidth + ",height=" + vHeight;
  opt = opt + ",scrollbars=" + vOpt + ",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0";
  opt = opt + ",outerWidth=" + vWidth + ",outerHeight=" + vHeight + ",resizable=0";
  opt = opt + ",left=" + x + ",top=" + y;
  opt = opt + ",channelmode=no, titlebar=no";
  var mdWindow = window.open(vUrl, vName, opt, false);
  return mdWindow;
}


function checkPattern(sType, str) //Çü½Ä Ã¼Å©
{
  var pattern = new String() ;
  switch (sType){
    case "NUM" :  // ¼ýÀÚ¸¸
      pattern =/^[0-9]+$/;
      break;
    case "PHONE" :
      pattern =/^[0-9]{2,4}-[0-9]{3,4}-[0-9]{4}$/;                     //ÀüÈ­¹øÈ£ Çü½Ä : 033-1234-5678
      break;
    case "EMAIL" :
      pattern =/^[_a-zA-Z\d\-\.]+@([_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+)/;           //¸ÞÀÏ
      break;
    case "DOMAIN" :
      pattern =/^[.a-zA-Z0-9-]+.[a-zA-Z]+$/; ///¿µÀÚ ¼ýÀÚ¿Í . ´ÙÀ½µµ ¿µÀÚ
      break;
    case "ENG" : //¿µÀÚ¸¸
      pattern =/^[a-zA-Z]+$/;
      break;
    case "ENGNUM" : //¿µÀÚ¿Í ¼ýÀÚ
      pattern =/^[a-zA-Z0-9]+$/;
      break;
    case "HAN" : // ÇÑ±Û¸¸
      pattern =/^[°¡-ÆR]*$/;
      break;
    case "USERID" : //Ã¹±ÛÀÚ´Â ¿µÀÚ ±×µÚ¿£ ¿µ¾î¼ýÀÚ 4ÀÌ»ó 15ÀÚ¸® ÀÌÇÏ
      pattern =/^[a-zA-Z]{1}[a-zA-Z0-9_-]{4,15}$/;
      break;
    case "DATE" : // ³¯Â¥ : 2002-08-15
      pattern =/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
      break;
    case "PASS" : // ³¯Â¥ : 2002-08-15
      pattern =/^[;:`~!@#$%\^&*\(\)_a-zA-Z0-9-]{4,15}$/;
      break;
  }

  //alert(str + "|" + pattern);

  if(!pattern.test(str)){
      return false;
  }
  return true;
}

function isValidType(type, field, msg) // chkpattern·Î Çü½ÄÃ¼Å© ÈÄ ¸Þ¼¼Áö Ãâ·Â
{
  if(!checkPattern(type, field.value))
  {
    if(msg != "") alert(msg);
    field.focus();
    return false;
  }
  return true;

}


function strReplace(str){ // \º¯È¯
  str = str.replace("'", "\'");
//  str = str.replace(chr(13), "\n");
  str = str.replace("\\", "/");
  return str
}



function no_msg(){ //»óÅÂÃ¢ ÁÖ¼Ò ¾È¶ß°Ô
  window.status="";
  return true;
}

var CheckBoxAll
CheckBoxAll = false

function CheckAll(InputName)//¸ðµÎ ¼±ÅÃÇÏ±â
{
  if (CheckBoxAll == true) CheckBoxAll = false;
  else  CheckBoxAll = true;

  var i;
  for (i=0;i<document.forms[0].elements.length;i++){
    var e = document.forms[0].elements[i];

      if(e.name == InputName)
        e.checked = CheckBoxAll;
  }
}

function onlynum() {//¼ýÀÚ¸¸ ´­¸®°Ô ÇÏ±â , ¹æÇâÅ° + Delele + BackSpace
  var iCode = event.keyCode;
  if(!( ((iCode >= 48) && (iCode <= 57)) || ((iCode >= 37) && (iCode <= 40)) || ((iCode >= 96) && (iCode <= 105)) || (iCode == 8 ) || (iCode == 46 )|| (iCode == 9 )) ) event.returnValue = false;
}


function trim(val){
  if (val != null)
    val = val.replace(/ /g,'');
  return val;
}

function F_CheckEnter(frm)
{
  if(event.keyCode==13)
    frm.submit();
}


function goPage(formNm, PageNo) {
  f=eval("document."+formNm);
  f.page.value=PageNo;
  f.submit();
}

function goPageMove(url){
  document.location.href = url;
}

function checkJumin(formname1,formname2){
        var chk=0
        var yy=formname1.value.substring(0,2)
        var mm=formname1.value.substring(2,4)
        var dd=formname1.value.substring(4,6)
        var sex=formname2.value.substring(0,1)
        if((formname1.value.length!=6)||(yy<25||mm<1||mm>12||dd<1)){
                formname1.select();
                return false;
        }
        if((sex!=1&&sex!=2)||(formname2.value.length!=7)){
                formname2.select();
                return false;
        }
        for(var i=0;i<=5;i++){
                chk=chk+((i%8+2)*parseInt(formname1.value.substring(i,i+1)))
        }
        for(var i=6;i<=11;i++){
                chk=chk+((i%8+2)*parseInt(formname2.value.substring(i-6,i-5)))
        }
        chk=11-(chk %11)
        chk=chk%10
        if(chk!=formname2.value.substring(6,7)){
                formname2.select();
                return false;
        }
        return true;
}

function CheckValid(String, space)
{
   var retvalue = false;
   for (var i=0; i<String.length; i++)
   {    //StringÀÌ 0("" ÀÌ³ª null)ÀÌ¸é ¹«Á¶°Ç false
      if (space == true)
      {
         if (String.charAt(i) == ' ')
         {      //StringÀÌ 0ÀÌ ¾Æ´Ò¶§ space°¡ ÀÖ¾î¾ß¸¸ true(valid)
            retvalue = true;
            break;
         }
      } else {
         if (String.charAt(i) != ' ')
         {      //stringÀÌ 0ÀÌ ¾Æ´Ò¶§ space°¡ ¾Æ´Ñ ±ÛÀÚ°¡ ÀÖ¾î¾ß¸¸ true(valid)
            retvalue = true;
            break;
         }
      }
   }
   return retvalue;
}

function isEmpty(field, error_msg)//Ç×¸ñÀÌ ºñ¾îÀÖ´ÂÁö Ã¼Å©
{
  // error_msg°¡ ""ÀÌ¸é alert¿Í focusingÀ» ÇÏÁö ¾Ê´Â´Ù
  if(error_msg == "") {
    if(!CheckValid(field.value, false))   {
      return true;
    } else {
      return false;
    }
  } else {
    if(!CheckValid(field.value, false)) {
      alert(error_msg);
      field.focus() ;
      return true;
    } else {
      return false;
    }
  }
}

function isOutOfRange(field, min, max, error_msg)//¹®ÀÚ¿­ ±æÀÌ Á¦ÇÑ
{
  if(strLength(field) < min || strLength(field) > max)
  {
    alert(error_msg);
    field.focus();
    field.select();
    return true;
  }
  return false;
}

function strLength(field)//¹®ÀÚ¿­±æÀÌ ¹ÝÈ¯
{
   var Length = 0;
   var Nav = navigator.appName;
   var Ver = navigator.appVersion;
   var IsExplorer = false;
   var ch;
   if ( (Nav == 'Microsoft Internet Explorer') && (Ver.charAt(0) >= 4) )
   {
      IsExplorer = true;
   }
   if(IsExplorer)
   {
      for(var i = 0 ; i < field.value.length; i++)
      {
         ch = field.value.charAt(i);
         if ((ch == "\n") || ((ch >= "¤¿") && (ch <= "È÷")) ||
             ((ch >="¤¡") && (ch <="¤¾")))
    {
        Length += 2;
    } else
    {
        Length += 1;
        }
    }
   }else {
      Length = field.value.length ;
   }
   return Length;
}

function isCheckedBox(frm,msg)//Ã¼Å©¹Ú½º(¹è¿­Æ÷ÇÔ)¿¡ Ã¼Å©µÇ¾îÀÖ´ÂÁö È®ÀÎ
{
  var check_length = frm.length;
  var check_ = false;

  if(typeof(check_length)=="undefined"){
    if(frm.checked == false){
      alert(msg);
      return false;
    }
  } else {
    for(i=0;i<check_length;i++){
      if(frm[i].checked){
        check_ = true;
      }
    }
    if(check_ == false)
    {
      alert(msg);
      return false;
    }
  }
  return true;
}

function isNotCheckedRadio(field, error_msg) {//Radio Button Check
  if ( field == null ) {
    alert(error_msg);
    return true;
  }

  if ( field.length == null ) {
    if ( field.checked == true ) {
      return false;
    } else {
      alert(error_msg);
      return true;
    }
  }

  for(i = 0; i < field.length; i++) {
    if(field[i].checked == true) {
      return false;
    }
  }
  alert(error_msg);
  return true;
}

function getRadioVal(field) {
  for(i = 0; i < field.length; i++) {
    if(field[i].checked == true)
      return field[i].value;
  }
  return "";
}

//¼ýÀÚ¸¦ ±Ý¾×´ÜÀ§·Î º¯È¯(ÄÞ¸¶Âï±â)
function formatNumber(num) {
//  num = num.replace(/,/g, "")
  var num_str = num.toString()
  var result = ''

  for(var i=0; i<num_str.length; i++) {
    var tmp = num_str.length-(i+1)
    if(i%3==0 && i!=0) result = ',' + result
    result = num_str.charAt(tmp) + result
  }
  return result;
}

function skip_length(this_obj, next_obj, length){
  if(this_obj.value.length==length){
    next_obj.focus();
  }
}


/*============================================================*/

function getByteLength(s) {
  var len = 0;
  if (s == null) {
    return 0;
  }
  for(var i=0; i < s.length; i++) {
    var c = escape(s.charAt(i));
    if (c.length == 1) len ++;
    else if (c.indexOf("%u") != -1) len += 2;
    else if (c.indexOf("%") != -1) len += c.length / 3;
  }
  return len;
}

function cutRightString(memo, limitSize) {
  var tmpStr;
  var temp=0;
  var onechar;
  var tcount;
  tcount = 0;
  tmpStr = new String(memo);
  temp = tmpStr.length;
  for(k=0;k<temp;k++)
  {
    onechar = tmpStr.charAt(k);
    if(escape(onechar).length > 4) {
      tcount += 2;
    } else {
      if(escape(onechar)!='%0A') {
        tcount++;
      }
    }
    if(tcount>limitSize) {
      tmpStr = tmpStr.substring(0,k);
      break;
    }
  }
  return tmpStr;
}

function __ShowEmbedObject(__ELEMENT_ID) {
       document.write( __ELEMENT_ID.innerHTML );
       __ELEMENT_ID.id = "";
} 

// ·¹ÀÌ¾î º¸ÀÌ°í °¨Ãß±â
var curLayerName = new String();
function showLayer(val)
{
  if(typeof(eval(val))=="undefined")
  {
    alert("'"+val+"' Layer not found");
    return;
  }

  if(curLayerName == val){
    eval(curLayerName).style.display = "none";
    curLayerName = "";
    return;
  }

  if(curLayerName!="") {
    eval(curLayerName).style.display = "none";
  }

  eval(val).style.display = "";
  curLayerName = val;
}


//ÂÊÁöÇÔ ¿­±â
function openMessageBox()
{
  openNameWindow(450, 400, "/application/popup/message_list.asp", "message", "1");
}

//»õÃµ³â´ë°­´ç »ç¿ë½ÅÃ»
function openHallApplication()
{
  openNameWindow(610, 400, "/etc/pop_renthall.asp", "hall", "1");
}

//±¹¿Ü ½ÅÃ»ÀÚ
function openApplication()
{
  openNameWindow(800, 600, "/application/application.asp", "eng_apply", "1");
}


//±¹³» ½ÅÃ»ÀÚ
function openApplicationKor()
{
  openNameWindow(800, 600, "/application/kor/application_kor.asp", "kor_apply", "1");
}

//¿Â¶óÀÎ ºê·Î¼Å ½ÅÃ»
function openBrochureRequest()
{
  openNameWindow(620, 600, "/etc/pop_brochure_request.asp", "brochure", "1");
}

// ÇÏ´Ü ¸µÅ©
function goURL(code)
{
  var strURL = new String();
  var strType = new String();
  switch(code)
  {
    case "1" : // WEBZine
      strURL = "/webzine/02/main.html";
      strType = "NEW";
      break;

    case "2" : // ALUMNI
      strURL = "/html/alumni.asp";
      strType = "NEW";
      break;

    case "3" : // CAREER SERVICE
      strURL = "/html/career.asp";
      strType = "NEW";
      break;

    case "4" : // STUDENT ASSOCIATION
      strURL = "http://gsa.yonsei.ac.kr/index.php?option=com_content&task=blogcategory&id=14&Itemid=33";
      strType = "NEW";
      break;

    case "5" : // LIBRARY
      strURL = "/html/library.asp";
      strType = "NEW";
      break;

    case "6" : // AFFIATED
      strURL = "/html/afflitiated.asp";
      strType = "NEW";
      break;

    case "7" : // Áß±¹ÃÖ°íÀ§°úÁ¤
      strURL = "";
      alert("ÁØºñÁßÀÔ´Ï´Ù.");
      break;

    case "8" : // Korean Student network
      strURL = "http://web.yonsei.ac.kr/ks";
      strType = "NEW";
      break;
  }
  if (strURL!="") {
    if(strType==""){
      location.href = strURL;
    } else if (strType == "NEW"){
      window.open(strURL);
    }
  }
}

