// window ¶ç¿ì±â
function open_win(URL, name, width, height) 
{
    // Å©±âÁöÁ¤ÇÏ±â => È£ÃâÇÑ Page¿¡¼­ °¡Áö°í ÀÖÀ½ pop_width, pop_height
    //if( width == '' ) width = screen.availWidth;
    if( height == '' ) height = screen.availHeight;

    // ÀüÃ¼ window size ±¸ÇÏ±â
    s_width = screen.availWidth;

    // ¿ì»ó´Ü¿¡ ¸ÂÃß±â
    t_left = s_width - width - 10;

    msgWindow = window.open(URL,name,'width='+width+',height='+height+',top=0,left='+t_left+',location=0,toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,border=0');
    msgWindow.focus();
}


function upload_file( fname, fsq, fpath, tg_img )
//function upload_file( fname, fsq, fpath )
{
    if( tg_img == "" ) tg_img = "0";
    
    url = "/pop_file_reg.html?q_fname=" + fname + "&q_fsq=" + fsq + "&q_path=" + fpath + "&q_tg_img=" + tg_img;
    open_win(url,'', 450, 230);
}


// ÀÌ¹ÌÁö Popup
//==================================================================================================== S
var imgObj = new Image();
var imageWin;
function showImgWin(imgName) {
  imgObj.src = imgName;
  setTimeout("createImgWin(imgObj)", 100);
}
function createImgWin(imgObj) {
  if (! imgObj.complete) {
    setTimeout("createImgWin(imgObj)", 100);
    return;
  }

  //imageWin = window.open("", "imageWin", "width=" + imgObj.width + ",height=" + imgObj.height);
  imageWin = window.open("", "", "width=" + imgObj.width + ",height=" + imgObj.height);
  imageWin.document.write("<html><head><title></title></head><body style='margin:0'>");
  imageWin.document.write("<a href=\"javascript:window.close();\" onmouseover=\"window.opener.alt( 'ÀÌ¹ÌÁö¸¦ Å¬¸¯ÇÏ¸é Ã¢ÀÌ ´ÝÈü´Ï´Ù.', '200', '25' )\" onmouseout=\"window.opener.alt()\" onmousemove='window.opener.get_xy()'><img src='" + imgObj.src + "' border='0'></a> ");

  imageWin.document.write(
    "<div id=alt_div style=\"" +
    "padding:7px 0px 0px 8px;" +
    "margin:3px 0px 0px -10px;" +
    "border:0px;" + // ¸»Ç³¼± Å×µÎ¸® ÄÃ·¯
    "background:url('/images/stars/bg_cursor.gif'); color:#9A9A9A;" + // ¸»Ç³¼± Å×ÀÌºí ¹é±×¶ó¿îµåÄÃ·¯ / ÆùÆ®ÄÃ·¯
    "position:absolute;" +
    "visibility:hidden;" +
    "overflow:hidden;" +
    "z-index:auto;" +
    "width:200px;" +
    "height:25px;" +
    "font-size:12px;" +
    "cursor:hand;" +
    "\"></div>"
  );
  
  imageWin.document.write("</body><html>");
}
function get_xy(){
    var _style = imageWin.document.getElementById("alt_div").style;
	
    var x = imageWin.event.x + imageWin.document.body.scrollLeft; 
    var y = imageWin.event.y + imageWin.document.body.scrollTop;
    _style.left = x + 10;
    _style.top = y + 10;

	window.status = "X=" + _style.left + "/Y=" + _style.top;
}
function alt( msg, _width, _height ){
	var alt_div = imageWin.document.getElementById("alt_div");
    var _style = alt_div.style;

	if( msg != null ){
		alt_div.innerHTML = msg;
        _style.visibility = "visible";
        if( _width != null ){
            if( alt_div.offsetWidth > _width ){
                _style.width = _width;
            }
        }
        if( _height != null ){
            if( alt_div.offsetHeight > _height ){
                _style.height = _height;
            }
        }
    }else{
        _style.visibility = "hidden";
    }
}
//==================================================================================================== E



// html Æ¯¼ö¹®ÀÚ Ã³¸®
var PERCENT = '%26'; // &
var QUESTION = '%3F'; // ?
var SHARP = '%23'; // #

// °ø¹é check(space Ã³¸®)
// null => true
function chk_null(toCheck) 
{
    for (var i = 0; i < toCheck.length; i++)
        if (toCheck.substring(i, i+1) != " ") return false;
        
    return true;
}

// °ø¹é check
// null => true
function chk_null2(toCheck)
{
    var chkstr = toCheck + "";
        
    if( (chkstr == "") || (chkstr == null) )
    {
        return true;
    }

    return false;
}

// ¼ýÀÚ check
function chk_num(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if ( (toCheck.substring(j,j+1) == ".") || (toCheck.substring(j,j+1) == ",") || (toCheck.substring(j,j+1) == "-") || (toCheck.substring(j,j+1) == "~") ) continue;
         return false;
      }
   }
   
   return true;
}

// ÇÑ±Û check
function chk_hangul(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`!@#$%^&*()-=_+~[]\{}|,.:/<>?";
    
    for( i=0 ; i< toCheck.length ; i++ )
    {
        idcheck = toCheck.charAt(i);
        
        for ( j=0 ;  j < str.length ; j++ )
        {
        
            if( idcheck == str.charAt(j) ) break;
                
            if( j+1 == str.length )
            {
                return false;
            }
        }
    }
    return true;
}


// ¿µ¹®,¼ýÀÚ check
function chk_engnum(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    var len = toCheck.length;
    var len2 = str.length;
    
    for( i=0 ; i<len ; i++ )
    {
        idcheck = toCheck.charAt(i);

        for( j=0 ; j<len2 ; j++ )
        {
            if( idcheck == str.charAt(j) ) break;
            
            if( j+1 == len2 )
                return false;
        }
    }
    return true;
}


// ¿µ¹®¼Ò¹®ÀÚ,¼ýÀÚ check
function chk_engnum2(toCheck) 
{
    var str = "abcdefghijklmnopqrstuvwxyz1234567890";
    var len = toCheck.length;
    var len2 = str.length;
    
    for( i=0 ; i<len ; i++ )
    {
        idcheck = toCheck.charAt(i);

        for( j=0 ; j<len2 ; j++ )
        {
            if( idcheck == str.charAt(j) ) break;
            
            if( j+1 == len2 )
                return false;
        }
    }
    return true;
}


// Email check
function chk_mail(toCheck) 
{
    // @Ç¥½Ã È®ÀÎ
    if(toCheck.indexOf('@') == -1 ) return false; 

    // .Ç¥½Ã È®ÀÎ
    if(toCheck.indexOf('.') == -1 ) return false; 
    
    // ÇÑ±Û È®ÀÎ
    if( chk_hangul(toCheck) == false ) return false; 
    
    return true;
}


// Check url
function chk_url(toCheck) 
{
    // .Ç¥½Ã È®ÀÎ
    if(toCheck.indexOf('.') == -1 ) return false;
    
    // ÇÑ±Û È®ÀÎ
    if( chk_hangul(toCheck) == false ) return false; 
    
    return true;
}



// ³¯ÀÚ check
function chk_date(toCheck) 
{
    var isDate = true;
   
    if (toCheck.length != 8) 
        return false;

    var year = toCheck.substring(0, 4);
    var month = toCheck.substring(4, 6);
    var day = toCheck.substring(6, 8);
    
    if (chk_yyyy(year) != true) 
    {
         isDate = false;
    }
    else if (chk_mm(month) != true) 
    {
         isDate = false;
    }
    else if (chk_dd(year, month, day) != true) 
    {
         isDate = false;
    }

    return isDate;
}


// ½Ã°£ check
function chk_time(toCheck) 
{
    var isTime = true;
   
    if (toCheck.length != 4) 
        return false;

    var hour = toCheck.substring(0, 2);
    var minute = toCheck.substring(2, 4);
    
    // ½Ã°£ check
    if( chk_num(hour) && hour >= 0 && hour < 24 ) isTime = true;
    else isTime = false;

    // ½Ã°£ check
    if( chk_num(minute) && minute >= 0 && minute < 60 ) isTime = true;
    else isTime = false;

    return isTime;
}


// ³â check
function chk_yyyy(toCheck) 
{
    return ( ( toCheck.length == 4 ) && ( chk_num(toCheck) ) && ( toCheck != "0000" ) );
}


// ¿ù check
function chk_mm(toCheck) 
{
    return ( ( toCheck.length > 0) && ( chk_num(toCheck) ) && ( 0 < eval(toCheck) ) && ( eval(toCheck) < 13) );
}


// ÀÏ check
function chk_dd(yyyy, mm, toCheck) 
{
    var isYMD = false;
    var monthDD = new montharr(31,28,31,30,31,30,31,31,30,31,30,31);
    var im = eval(mm) - 1;

    if ( toCheck.length == 0 )  return false;
    if ( !chk_num(toCheck)  )  return false;

    var dd = eval(toCheck);

    if ( ( (yyyy%4 == 0) && (yyyy%100 != 0) ) || (yyyy%400 == 0) ) 
    {
        monthDD[1] = 29;
    }

    if ( (0 < dd) && (dd <= monthDD[im]) ) 
        isYMD = true;

    return isYMD;
}


// ¿ùº°·Î ¸¶Áö¸· ³¯ÀÚ¸¦ Setting
// chk_dd¿¡¼­ »ç¿ëÇÔ
function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) 
{
    this[0] = m0;
    this[1] = m1;
    this[2] = m2;
    this[3] = m3;
    this[4] = m4;
    this[5] = m5;
    this[6] = m6;
    this[7] = m7;
    this[8] = m8;
    this[9] = m9;
    this[10] = m10;
    this[11] = m11;
}


// ¿ù,ÀÏÀÌ 1ÀÚ¸®¼öÀÏ°æ¿ì - ¾ÕÀÚ¸®¿¡ "0" setting. (°ªÀ» ºñ±³ÇÏ±â À§ÇØ)
function set_zero( num ) 
{
    if (num.length == 1)
        num = "0" + num;

    return num;
}

// ½ÃÀÛ³¯ÀÚ¿Í ¸¶Áö¸·³¯ÀÚ ¼ø¼­ check
function checkDate2( s_yy, s_mm, s_dd, e_yy, e_mm, e_dd ) 
{
    var isDate = true;

    s_mm = set_zero( s_mm );
    s_dd = set_zero( s_dd );
    e_mm = set_zero( e_mm );
    e_dd = set_zero( e_dd );

    var start_date  = s_yy + s_mm + s_dd;
    var end_date = e_yy + e_mm + e_dd;

    if ( start_date > end_date ) 
    {
         isDate = false;
    }  

    return isDate;
}


// ÁÖ¹Î¹øÈ£ check
function chk_juminno(toCheck) 
{
    var str_f_num = toCheck.substring(0, 6);
    var str_l_num = toCheck.substring(6, 13);

    var i3=0;
    for (var i=0;i<str_f_num.length;i++) 
    {
        var ch1 = str_f_num.substring(i,i+1);
        if (ch1<'0' || ch1>'9') { i3=i3+1 }
    }

    if ((str_f_num == '') || ( i3 != 0 )) 
    {
            return (false);
    }

    var i4=0;
    for (var i=0;i<str_l_num.length;i++) 
    {
        var ch1 = str_l_num.substring(i,i+1);
        if (ch1<'0' || ch1>'9') { i4=i4+1 }
    }

    if ((str_l_num == '') || ( i4 != 0 )) 
    {
       return (false);
    }

    // 20³â»ýÀÌÇÏ error
    if(str_f_num.substring(0,1) < 2)
    {
       return (false);
    }

    if( str_l_num.substring(0,1) != 1 && str_l_num.substring(0,1) != 2 && str_l_num.substring(0,1) != 3 && str_l_num.substring(0,1) != 4 )
    {
       return (false);
    }

    if((str_f_num.length > 7) || (str_l_num.length > 8)) 
    {
       return (false);
    }

    if ((str_f_num == '72') || ( str_l_num == '18')) 
    {
       return (false);
    }

    var f1=str_f_num.substring(0,1)
    var f2=str_f_num.substring(1,2)
    var f3=str_f_num.substring(2,3)
    var f4=str_f_num.substring(3,4)
    var f5=str_f_num.substring(4,5)
    var f6=str_f_num.substring(5,6)
    var hap=f1*2+f2*3+f3*4+f4*5+f5*6+f6*7
    var l1=str_l_num.substring(0,1)
    var l2=str_l_num.substring(1,2)
    var l3=str_l_num.substring(2,3)
    var l4=str_l_num.substring(3,4)
    var l5=str_l_num.substring(4,5)
    var l6=str_l_num.substring(5,6)
    var l7=str_l_num.substring(6,7)
    hap=hap+l1*8+l2*9+l3*2+l4*3+l5*4+l6*5
    hap=hap%11
    hap=11-hap
    hap=hap%10
    if (hap != l7) 
    {
        return false;
    }

    return true; 
}


function chk_comma(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( toCheck.substring(j,j+1) == "," )
      {
         return false;
      }
   }
   
   return true;
}

// form check
// <input> tag¿¡ ¾Æ·¡»çÇ×À» check
// text : ÇØ´ç column ÀÌ¸§
// notnull : null check
// check
// - number : ¼ýÀÚ check
// - date : ³¯ÀÚ check
// - mail : ¸ÞÀÏ check
// - juminno : ÁÖ¹Î¹øÈ£ check
function chk_form(form) 
{
    var inx = 0; // À§Ä¡

    for ( ; inx < form.length ; inx++)
    {
        //alert(inx);
        var column = form.elements[inx];
        
        var text = column.text;

        if ( (column.type == "text") || 
             (column.type == "password") || 
             (column.type == "select-one") || 
             (column.type == "file") || 
             (column.type == "textarea") )
        {
            //column.value = do_replace(column.value,"'","''");
          
            // ÇÊ¼öÇ×¸ñ check
            if( (column.notnull == "") && (chk_null(column.value)) ) 
            {
                alert (text + "Àº(´Â) ÇÊ¼öÇ×¸ñÀÔ´Ï´Ù");
                column.focus();
                return false;
            }
            
            // nullÀÌ ¾Æ´Ï¸é check
            if( !chk_null(column.value) )
            {
                // ÇüÅÂ check
                if ( (column.check == "number") && (!chk_num(column.value)) )
                {
                    alert (text + "À»(¸¦) ¼ýÀÚ·Î ÀÔ·ÂÇÏ¼¼¿ä");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "date") && (!chk_date(column.value)) )
                {
                    alert (text + "À»(¸¦) ³¯Â¥·Î ÀÔ·ÂÇÏ¼¼¿ä");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "time") && (!chk_time(column.value)) )
                {
                    alert (text + "À»(¸¦) ½Ã°£À¸·Î ÀÔ·ÂÇÏ¼¼¿ä (½Ã°£:0~23,ºÐ:0~59)");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "id") && (!chk_engnum2(column.value)) )
                {
                    alert (text + "À»(¸¦) ¿µ¹®¼Ò¹®ÀÚ,¼ýÀÚ·Î¸¸ ÀÔ·ÂÇÏ¼¼¿ä");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "mail") && (!chk_mail(column.value)) )
                {
                    alert ("¿Ã¹Ù¸¥ ¸ÞÀÏÁÖ¼Ò°¡ ¾Æ´Õ´Ï´Ù.");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "juminno") && (!chk_juminno(column.value)) )
                {
                    alert ("¿Ã¹Ù¸¥ ÁÖ¹Î¹øÈ£°¡ ¾Æ´Õ´Ï´Ù.");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "length") && ( get_length(column.value) > column.hlength ) )
                {
                    alert (text + "Àº(´Â) " + column.hlength + "ÀÚ±îÁö ÀÔ·Â°¡´ÉÇÕ´Ï´Ù.");
                    column.focus();
                    return false;
                }
                
                //english
                //----------------------------------------------------------------------------- S
                else if ( (column.check == "en_number") && (!chk_num(column.value)) )
                {
                    alert (text + "- Please, input number.   ");
                    column.focus();
                    return false;
                }
                //----------------------------------------------------------------------------- E
                
            }
        }
    }
  
    return true;
}

// object°¡ nullÀÎÁö check
function chk_null_obj(Obj) 
{
    var check = false;
    var Radio = Obj;

    if (!Radio) return check;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ ) 
        {
            if ( Radio[i].checked == 1 ) 
            {
                check = true;
                break;
            }
        }
    }
    else
    {
        if ( Radio.checked == 1 ) 
        {
            check = true;
        }
    }

    return check
}


// ¸ðµç object¸¦ checkÇÔ
function CheckAll(Obj) 
{
    var Radio = Obj.form.file;

    if (!Radio) return;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ )
            Obj.form.file[i].checked=1;
    }
    else 
    {
        Obj.form.file.checked=1;
    }
}


// ¸ðµç object¸¦ uncheckÇÔ 
function UnCheckAll(Obj) 
{
    var Radio = Obj.form.file;

    if (!Radio) return;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ )
            Obj.form.file[i].checked=0;
    }
    else 
    {
        Obj.form.file.checked=0;
    }
}

// window ¶ç¿ì±â
function open_win_left(URL, name, width, height) 
{
    // Å©±âÁöÁ¤ÇÏ±â => È£ÃâÇÑ Page¿¡¼­ °¡Áö°í ÀÖÀ½ pop_width, pop_height
    if( width == '' ) width = screen.availWidth;
    if( height == '' ) height = screen.availHeight;

    // ÀüÃ¼ window size ±¸ÇÏ±â
    s_width = screen.availWidth;

    // ÁÂ»ó´Ü¿¡ ¸ÂÃß±â
    t_left = 0;

    msgWindow = window.open(URL,name,'width='+width+',height='+height+',top=0,left='+t_left+',location=0,toolbar=no,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no,border=0');
    msgWindow.focus();
}

// ´Þ·Â ¶ç¿ì±â
function open_calendar(target) 
{
    msgWindow=window.open('/view_calender.html?q_target='+target,'calender','location=0,toolbar=no,width=160,height=160,directories=no,status=no,scrollbars=no,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}


// ´ë»ó checkbox¿¡ index°¡ ¾ø´Â °æ¿ì  
function check_all( source, target, form_name)
{
    var is_checked = true;
   
    q_check = form_name(target);

    if( q_check == null ) // ¾ø´Â °æ¿ì
    {
        alert('°Ë»öÈÄ ¼±ÅÃÇÏ¼¼¿ä.');
        return false;
    }

    if(source.checked)
        is_checked = false;
    
    // ¿©·¯°³ÀÏ °æ¿ì
    if( q_check.length > 0 )
    {    
        for(var i=0;i<q_check.length;i++)
        {
            if(is_checked)
                q_check[i].checked=false;
            else
                q_check[i].checked=true;
        }
    }
    else // ÇÑ°³ÀÏ°æ¿ì
    {
        if(is_checked)         
            q_check.checked=false;
        else
            q_check.checked=true;
    }
}

function get_length(str) 
{ 
    var char_cnt = 0;
    
    for(var i = 0; i < str.length; i++)
    {
        var chr = str.substr(i,1);
        //alert( chr +"//"+ char_cnt +"//"+ i );

        if( !chk_hangul(chr) )
        {
            char_cnt = char_cnt + 2;
        }
        else
        {
            char_cnt = char_cnt + 1;
        }
    }
    //alert( str +"//"+ char_cnt );
    return char_cnt;    
}

// ½ºÅ¸È¨ÇÇ
//-------------------------------------------------------------------------------------------------------------------- S
function go_star( obj )
{
    location.href = "/stars/pop_index.html?q_sc=" + obj.value;
}
//-------------------------------------------------------------------------------------------------------------------- E