function pop_win(script,width,height,win_title,opt) // new version of pop_it_up()
{
	width = (width>250 ? width : 250);
	height = (height>100 ? height : 100);
	var scrollopt = (opt==1 ? 'yes' : 'no')
    var vleft =Math.floor((screen.width - (width+20))/2);
    var vtop = Math.floor((screen.height - (height+97))/2);
    var winprops = 'resizable=yes, scrollbars='+scrollopt+', location=yes, ' +
    	'status=yes, width=' + width + ', height=' + 
    	height + ', left=' + vleft + ', top=' + vtop;
    return window.open(script,win_title,winprops);
}

function win_resizeTo(vwidth,vheight) // new version of my_resizeTo()
{
    vwidth += 20;
    vheight += 97;
    var vleft =(screen.width - vwidth)/2;
    var vtop = (screen.height - vheight)/2;
    self.resizeTo(vwidth,vheight);
    self.moveTo(vleft,vtop);
}

function show_obj(x,opt) // opt == 1/0 iff all/nonempty
{
    var i,count=0;
    var str = '';
    var myArray = new Array();
    for(i in x) if(opt || x[i]) myArray[count++] = i; // eliminates null and ''
    myArray.sort();
    for(j=0; j<count; j++){
        str += myArray[j]+' = ' + x[myArray[j]] + '\t'; 
    }
    str = '# of items = ' + count + '\n\n'+ str;
    alert(str);
}

function changeImage(obj,img_url)
{
	obj.src = img_url;
}

function backgroundColor(x,y){
    x.style.backgroundColor = y;
}
function mybutton(theaction,thestr){ // anchor
    var retstr = "<TABLE height=21 border=1 style='padding-top:3; padding-left:4; padding-right:4;' bgcolor=#f3f3ff\n";
    retstr += "bordercolor=steelblue bordercolordark=white cellpadding=0 cellspacing=0>\n";
    retstr += "<TR align=center><TD nowrap style='font-size:9pt;'";
    retstr += " onmouseover=\"javascript:backgroundColor(this,'#ffffcc')\"";
    retstr += " onmouseout=\"javascript:backgroundColor(this,'#f3f3ff')\"><A class=mybutton hre";
    retstr += "f=\"javascript:"+theaction+"\" onfocus=this.blur();>\n";
    retstr += thestr+"</A></TD></TR></TABLE>\n";
    document.write(retstr);
}
function mybutton2(theaction,thestr){ // anchor
    var retstr = "<TABLE height=21 border=1 style='padding-top:3; padding-left:4; padding-right:4;' bgcolor=white\n";
    retstr += "bordercolor=palegoldenrod bordercolordark=white cellpadding=0 cellspacing=0>\n";
    retstr += "<TR align=center><TD nowrap style='font-size:9pt;'>";
    retstr += "<A class=mybutton2 hre";
    retstr += "f=\"javascript:"+theaction+"\" onfocus=this.blur();>\n";
    retstr += thestr+"</A></TD></TR></TABLE>\n";
    document.write(retstr);
}
function pop_it_up0(src,wintitle) // pop-up invisible window
{
    var vwidth=150,vheight=50,vleft=screen.width,vtop=screen.height;
    var winprops = 'resizable=yes width=' + vwidth + ' height=' + vheight + 
                    ' left=' + vleft + ' top=' + vtop;
    return window.open(src,wintitle,winprops);
}
function pop_it_up(src,wintitle,vwidth,vheight,opt) 
// vwidth, vheight´Â ÃÖ¼Ò 100ÀÌ¹Ç·Î ´õ ÀÛ°Ô ÇÏ·Á¸é resizeTo()¸¦ »ç¿ë.
{
    var vleft =(screen.width - vwidth)/2;
    var vtop,winprops;
    switch(opt){
        case 0: vtop = (screen.height - (vheight+36))/2;
                winprops = 'resizable=yes width=' + vwidth + ' height=' + vheight + 
                    ' left=' + vleft + ' top=' + vtop;
        break;
        case 1: vtop = (screen.height - (vheight+36))/2;
                winprops = 'resizable=yes scrollbars=yes width=' + vwidth + ' height=' 
                    + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 2: vtop = (screen.height - (vheight+59))/2;
                winprops = 'resizable=yes scrollbars=yes location=yes width=' + vwidth + 
                    ' height=' + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 3: vtop = (screen.height - vheight)/2 - 52;
                winprops = 'resizable=yes menubar=yes scrollbars=yes location=yes width=' + 
                    vwidth + ' height=' + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 4: vtop = (screen.height - vheight)/2 - 70;
                winprops = 'resizable=yes menubar=yes location=yes toolbar=yes' +
                    ' scrollbars=yes width=' + vwidth + ' height=' + vheight + 
                    ' left=' + vleft + ' top=' + vtop;
        break;
        default: alert('Impossible case'); return;
    }
    return window.open(src,wintitle,winprops);
}

function pop_up_1024(src,wintitle,opt) 
// vwidth, vheight´Â ÃÖ¼Ò 100ÀÌ¹Ç·Î ´õ ÀÛ°Ô ÇÏ·Á¸é resizeTo()¸¦ »ç¿ë.
{
    var vwidth = 1012;
    var vheight = 700;
    var vleft = 0;
    var vtop=0,winprops;
    switch(opt){
        case 0: winprops = 'resizable=yes width=' + vwidth + ' height=' + vheight + 
                    ' left=' + vleft + ' top=' + vtop;
        break;
        case 1: winprops = 'resizable=yes scrollbars=yes width=' + vwidth + ' height=' 
                    + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 2: vheight = 650;
            winprops = 'resizable=yes scrollbars=yes location=yes width=' + vwidth + 
                    ' height=' + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 3: vheight = 606;
            winprops = 'resizable=yes menubar=yes scrollbars=yes location=yes width=' + 
                    vwidth + ' height=' + vheight + ' left=' + vleft + ' top=' + vtop;
        break;
        case 4: vheight = 568;
            winprops = 'resizable=yes menubar=yes location=yes toolbar=yes' +
                    ' scrollbars=yes width=' + vwidth + ' height=' + vheight + 
                    ' left=' + vleft + ' top=' + vtop;
        break;
        default: alert('Impossible case'); return;
    }
    return window.open(src,wintitle,winprops);
}
function my_resizeTo(vwidth,vheight) // for pop_it_up(,,,,0)
{
    vwidth += 12;
    vheight += 38;
    var vleft =(screen.width - vwidth)/2 + 6;
    var vtop = (screen.height - vheight)/2 + 1;
    self.moveTo(vleft,vtop);
    self.resizeTo(vwidth,vheight);
}
function my_resizeTo4(vwidth,vheight) // for pop_it_up(,,,,4)
{
    vwidth += 12;
    vheight += 142;
    var vleft =(screen.width - vwidth)/2;
    var vtop = (screen.height - vheight)/2;
    self.moveTo(vleft,vtop);
    self.resizeTo(vwidth,vheight);
}
function trim(str){
    mypattern1 = /^\s+/;
    mypattern2 = /\s+$/;
    str = str.replace(mypattern1,'');
    str = str.replace(mypattern2,'');
    return str;
}
function digit_str(str){
    var len = str.length;
    var i,icode,retstr='';
    for(i=0;i<len;i++){
        icode = str.charCodeAt(i) - 48;
        if(icode>=0 && icode<=9) retstr += icode;
    }
    return retstr;
}
function email_check(email_str)
{ // empty stringÀº ºÒÇÕ°Ý
    var len = email_str.length;
    var i,icode,status=0;
    for(i=0;i<len;i++){
        icode = email_str.charCodeAt(i);  // a-z A-Z 0-9 + - _  AND @ . 
        if((icode>=97 && icode<=122) || (icode>=65 && icode<=90) || 
                (icode>=48 && icode<=57) || icode==43 || icode==45 || icode==95){
            if(status==1) status=2;
            continue;
        }
        if(i==0) return false;
        if(status==0){ // @ Àü¿¡´Â status 0
            if(icode==64){
                status=1; // @ ¿¡¼­ status 1À¸·Î ¹Ù²ñ
                continue;
            }
            else if(icode==46) continue;  // userid¿¡¼­ . Çã¿ë
            else return false;
        }
        else if(status==1) return false;
        else{
            if(icode==46){
                status++;
                continue;
            }
            else return false;
        }
    }
    if(icode==46 || status<3) return false;
    return true;
}
function win_close()
{
    self.close();
}
function emph_txt(x,opt,color)
{
    if(opt==1) {
        if(!color) color = 'tomato';  //  µðÆúÆ® °­Á¶»ö
        x.style.color = color; // °­Á¶»ö
    }
    else {
        if(!color) color = '#90a4be';  // µðÆúÆ® Æò»ó»ö
        x.style.color = color; // Æò»ó»ö
    }
}
function nbytes(str) 
{ // korean chars count as two bytes, others count as one. 
    var i,sum=0; 
    for(i=0;i<str.length;i++) sum += (str.charCodeAt(i) > 255 ? 2 : 1); 
    return sum; 
} 

