 
function swapImage(name, img) 
{
	imgch = eval("document."+name);
	imgch.src = img ; 
}

function showLayers(index)  
{ 
	var layer_name = "sub"+ index; 
	document.all[layer_name].style.visibility = "visible"; 
} 
 
function mOver_swapImage(name, img) 
{ 
	if(on_click == "off")
		document.all[name].src = img ; 

}

function mOut_swapImage(name, img, num) 
{ 
	var out_menu=eval("document.all."+name); 
	if(out_menu.display != "block")
		if(on_click == "off")
			document.all[name].src = img ; 

}

function showhide(menu_name, num, cnt)
{
	for (i=1; i<=cnt; i++)   
	{ 
		menu=eval("document.all."+menu_name+i+".style"); 
		imgch=eval("document.menu"+i); 

		if (num==i)
		{ 
			  if (menu.display=="block")
			 { 
				  menu.display="block"; 
				  imgch.src = "/images/icon_main.gif"; 
			 }
			 else
			 { 
			   menu.display = "block"; 
			   imgch.src = "/images/icon_main_r.gif"; 
			 } 
		}
		  
		else 
		{ 
			menu.display="none"; 
		} 
	} 
}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


String.prototype.trim = function() {
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1"); 
}

function __jsCheckAll(checked,element)
{
    if (element) {
        for(i=0;i<element.length;i++)
        {
            element[i].checked = checked;
        }
    }
}    

function __jsCheckAllItem(theform)
{
    if(theform.p_check_all_fg.checked == true)
    {
        for(var i=0; i < theform.length; i++)
        {
            if(theform[i].name == "p_checkbox" && theform[i].checked == false)
            {
                theform[i].checked = true;
            }
        }
    }
    else
    {
        for(var i=0; i < theform.length; i++)
        {
            if(theform[i].name == "p_checkbox" && theform[i].checked == true)
            {
                theform[i].checked = false;
            }
        }
    }
}

function __jsIsChecked(element) {
    if (element) {
        if (element.checked) {
            return true;
        } else {
            for( var i=0; i < element.length; i++) {
                if (element[i].checked) {
                    return true;
                }
            }
        }
    }
    return false;
}

function __jsGetSelectedItemCount(theform)
{
    var item_count = 0;
    for(var i=0; i < theform.length; i++)
    {
        if(theform[i].name == "p_checkbox" &&  theform[i].checked == true)
        {
            item_count++;
        }
    }

    return item_count;
}

function __jsGetSelectedItemList(theform)
{
    var item_list = "";
    for(var i=0; i < theform.length; i++)
    {
        if(theform[i].name == "p_checkbox" &&  theform[i].checked == true)
        {
            item_list = item_list + theform[i].value + "";
        }
    }

    return item_list;
}

function __jsGetSelectedItemListByDeli(theform, deli)
{
    var item_list = "";
    for(var i=0; i < theform.length; i++)
    {
        if(theform[i].name == "p_checkbox" &&  theform[i].checked == true)
        {
            item_list = item_list + theform[i].value + deli;
        }
    }

    return item_list;
}

function _jsFixWindowSize()
{
	wid = document.body.scrollWidth+10;
	hei = document.body.scrollHeight+29;
	self.resizeTo(wid,hei);
}

function __jsGetTextByte(str)
{
    var wch, x, uch = "";
    var szLength = 0;

    for ( x = 0; x < str.length; x ++ )
    {
        wch = str.charCodeAt( x );
        if ( !( wch && 0xFF80 ) )
        {
            szLength ++;
        }
        else if ( !( wch & 0xF000 ) )
        {
            szLength ++;
        }
        else 
        {  
            szLength += 2;
        }
    }
    return szLength;
}

function __jsGetTimeStamp()
{
    var now = new Date();
    var hours = now.getHours();
    var minutes = now.getMinutes();
    var seconds = now.getSeconds();
    return stemp = hours+minutes+seconds;
}

function __jsPopUp(url, popupname,x,y,scroll,resize)
{
    window.open(url,popupname,"toolbar=no,width="+x+",height="+y+ ",top="+ (screen.availheight- y )/2+",left="+(screen.availwidth- x)/2 +",directories=no,status=no,scrollbars="+scroll+",resize="+resize+",menubar=no");
}

function __jsAdd10Zero(s)
{
	if( s.length > 1 )
    {
		return s;
	}
    else
    {
		return ("0"+s);
	}
}

function __jsRemove10Zero(s)
{
    if( s.charAt(0) == '0' )
    {
        return s.charAt(1);
    }
    else
    {
        return s;
    }
}

function __jsGetRandomNumber(min_num, max_num)
{         
    var nr=0;                                    
    while ((nr < min_num) || (nr > max_num))
    {   
        nr = Math.round( min_num*Math.random());  
    }

    return nr;                             
}

function __jsIsAlphaNumeric(s)
{
    var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for (i = 0;  i < s.length;  i++)
    {
        ch = s.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length)
        {
            return (false);
            break;
        }
    }
    return (true);
}

function __jsIsDotNumeric(s)
{
    var checkOK = "0123456789.";
    for (i = 0;  i < s.length;  i++)
    {
        ch = s.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
            if (ch == checkOK.charAt(j))
                break;
        if (j == checkOK.length)
        {
            return (false);
            break;
        }
    }
    return (true);
}

/*
* ???? ????
*/
function __jsIsNumeric(s)
{
    var ch;

    for ( k = 0; k < s.length; k++ )
    {
        ch = s.charAt(k);
        if ( ch < '0' || ch > '9' )
        {
            return (false);
        }
    }
    return (true);
}

/*
* ?????? ?????? ????
*/
function __jsIsAvailableId(s)
{
    var ch, ch2=1;

    for ( k = 0; k < s.length; k++ )
    {
        ch = s.charAt(k);
        if ( !(('0' <= ch && '9' >= ch ) ||
            ('A' <= ch && 'Z' >= ch ) ||
            ('a' <= ch && 'z' >= ch ) || ( ch == '_' )) )
        {
            if ( ch == ' ' )
                alert("?????? ?????????? ????????.");
            else
            {
                alert("????, ????, '_' ???? ?????? ???????? ?? ????????.");
            }
            return (false);
        }
    }
    return (true);
}

function __jsIsWhiteSpace(s)
{
    var ch;

    for ( k = 0; k < s.length; k++ )
    {
        ch = s.charAt(k);
        if ( ch == ' ' )
        {
            return (false);
        }
    }
    return (true);
}

function __jsIsBlankSpace(s)
{
  var es = escape(s);

  if( es.indexOf("%20") >= 0 )
	   return true;
 
  return false;
}

function __jsIsDateFormat(strDate)
{
      var strMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

      if ( strDate.length != 8 ) return false;

      var YYYY  = eval(strDate.substr(0,4));
      var MM    = eval(strDate.substr(4,2));
      var DD    = eval(strDate.substr(6,2));

      if ( !isNumeric(YYYY) || !isNumeric(MM) || !isNumeric(DD) )
           return false;

      var MonthDays = (MM != 2) ? strMonth[MM-1] : (( YYYY%4==0 && YYYY%100 !=0 || YYYY%400 ==0 ) ? 29:28 );

      if( ( MM <13 && MM >0 && DD >0 && DD <= MonthDays) == false )
         return false;

      return true;
}

function __jsCheckImageFile( szValue )
{
    var szExt = szValue.substr( szValue.length - 3, 3 ).toLowerCase();

    switch ( szExt ) {
    case "gif":
    case "bmp":
    case "jpg":
    case "png":
    case "jpeg":
    case "jpe":
        return true;
        break;
    default :
        if ( szValue.substr( 0, 4 ).toLowerCase() == 'http' ) return true;
        break;
    }

    return false;
}

function __jsCheckLength(objInput) 
{
  var strValue = objInput;
  var retCode = 0;
  var countChar = 0;

  if ( strValue.trim() == "" ) {
    return 0;
  }

  for (i=0; i<strValue.length; i++) {
    var retCode = strValue.charCodeAt(i);
    var retChar = strValue.substr(i,1).toUpperCase();
    retCode = parseInt(retCode);

    if ((retChar < "0" || retChar > "9") && (retChar < "A" || retChar > "Z") && ((retCode > 255) || (retCode < 0))) {
      countChar = countChar + 2;
    } else {
      countChar = countChar + 1;
    }
  }

  return countChar;
}

function __jsIsCivilNo(it)
{
	var idtot=0;
	var idadd="234567892345";

	for (var i=0; i<12; i++) {
		idtot = idtot+parseInt(it.substring(i,i+1))*parseInt(idadd.substring(i,i+1));
	}
	idtot=11-(idtot%11);
	if (idtot==10) {
		idtot=0;
	} else if(idtot==11) {
		idtot=1;
	}
	if (parseInt(it.substring(12,13))!=idtot) 
		return false;

	return true;
}

function formData2QueryString(docForm) {
	var submitContent = '';
	var formElem;
	var lastElemName = '';
	for (i = 0; i < docForm.elements.length; i++) {
	    formElem = docForm.elements[i];
	    switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'select-one':
	        	submitContent += formElem.name + '=' + formElem.value + '&'
	        	break;
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					submitContent += formElem.name + '=' + formElem.value + '&'
				}
	        	break;
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == lastElemName) {
						// Strip of end ampersand if there is one
						if (submitContent.lastIndexOf('&') == submitContent.length-1) {
							submitContent = submitContent.substr(0, submitContent.length - 1);
						}
						// Append value as comma-delimited string
						submitContent += ',' + formElem.value;
					}else {
						submitContent += formElem.name + '=' + formElem.value;
					}
					submitContent += '&';
					lastElemName = formElem.name;
				}
	        	break;
	    }
	}
	// Remove trailing separator
	submitContent = submitContent.substr(0, submitContent.length - 1);
	return submitContent;
}

// ie7 ???? ????
function ie7Check()
{
	var IE = document.all ? true:false;
	var msie_vs = navigator.appVersion.match(/MSIE \d+.\d+/)[0].split(" ")[1];

	if ( (IE && msie_vs) > "6.0"){
		return  true;
	}else {
		return false;
	}
}

/**
 *	vista ????
 */
function vistaCheck()
{
	var navi		= navigator.appVersion.split(";");
	var os_version	= navi[2]

	if ( os_version.indexOf("Windows NT 6.0") >= 0 ) 
		return true;
	else 
		return false;
}

/**
 *	vista?? ???? height ?? ????
 */
function vistaHeight(p_height)
{
	if ( vistaCheck() )
	{
		p_height	+= 10;
	}

	return p_height;
}

/**
 *	IE7 ?? ???? resizeTo ???? ?????? ?? height ????
 */
function resizeTo_ie7(p_width, p_height)
{
	var height_add	= "";	// IE7 ?? ???? +20

	if ( vistaCheck() )		// vista ????
	{
		height_add	= 30; 
	}	
	else
	{
		if ( ie7Check() )	// IE7 ????
		{
			height_add	= 20;
		}
	}
	
	window.resizeTo(p_width, p_height + height_add);	
}

/**
 *	IE7 ?? ???? resizeTo ???? ?????? ?? height ????
 */
function resizeTo_vista(p_width, p_height)
{
	var height_add	= 0;	
	var width_add	= 0;
	var isXp = navigator.userAgent.indexOf('Windows NT 5.1') > 0

    // XP (???????? ????) & vista ?? ??
    if ( isXp || vistaCheck() ) {
        height_add += 58;
		width_add	= 10;
    }

    // IE7 ?? ????
	if ( ie7Check() ) {
        height_add += 18;
		width_add	= 10;
    }

	window.resizeTo(parseInt(p_width) + width_add, parseInt(p_height) + height_add);	
}

function sizeCalculate(bytesize){
	var msize = 0;
	var ksize = parseFloat(bytesize / 1024);
	if ( ksize > 1024 ){
		msize = parseFloat(ksize /1024);
		msize = msize.toFixed(2);
		return msize+" Mbyte";
	}else{
		ksize = ksize.toFixed(2);
		return ksize + " Kbtye";
	}
}

function replace(str,sstr,rstr) { 
	return String(str).replace(new RegExp(sstr,"ig"),rstr);
}




