function getByteLen(s) {
	var l = 0 
	for(var i=0;i<s.length;i++) { 
		if(escape(s.charAt(i)).length>3) l += 2; else l++;
	}
	return l;
}


function MoveSelectOrder(movetype, obj)
{
    var sel = obj.selectedIndex;
    if (movetype == "U") {
        if(sel > 0) {
			/*
			var dobj = obj.options[sel-1];
			var cobj = obj.options[sel];

			var darr = new Array();
			var carr = new Array();

			var j = 0;
			for(var i=0;i<obj.options[sel-1].attributes.length;i++){
				if(obj.options[sel-1].attributes[i].specified){
					darr[j] = new Array(obj.options[sel-1].attributes[i].nodeName, obj.options[sel-1].attributes[i].nodeValue);
					j++;
				}
			}


			j = 0;
			for(var i=0;i<obj.options[sel].attributes.length;i++){
				if(obj.options[sel].attributes[i].specified)
				{
					carr[j] = new Array(obj.options[sel].attributes[i].nodeName, obj.options[sel].attributes[i].nodeValue);
					j++;
				}
			}

	
			var j = 0;
			var k = 0;
			for(var i=0;i<obj.options[sel-1].attributes.length;i++){
				if(obj.options[sel-1].attributes[i].specified){
					for (var j =0;j<carr.length;j++)
					{

					}
				}
			}


			j = 0;
			for(var i=0;i<obj.options[sel].attributes.length;i++){
				if(obj.options[sel].attributes[i].specified)
				{

				}
			}
			*/
	

            var onetext = obj.options[sel-1].text;
            var onevalue = obj.options[sel-1].value;

			var prevstyle = obj.options[sel-1].style?obj.options[sel-1].style.color:null;
			var curstyle = obj.options[sel].style?obj.options[sel].style.color:null;
			
			var prevbgcolor = obj.options[sel-1].style?obj.options[sel-1].style.backgroundColor:null;
			var curbgcolor = obj.options[sel].style?obj.options[sel].style.backgroundColor:null;

            
			obj.options[sel-1].text  = obj.options[sel].text;
            obj.options[sel-1].value = obj.options[sel].value;

            obj.options[sel].text = onetext;
            obj.options[sel].value = onevalue;

			obj.options[sel].style.color = prevstyle;
			obj.options[sel-1].style.color  = curstyle; 

			obj.options[sel].style.backgroundColor = prevbgcolor;
			obj.options[sel-1].style.backgroundColor  = curbgcolor; 

            obj.selectedIndex = sel-1;
      }
    }
    else if (movetype == "D") {
        if(sel >= 0 && sel < obj.options.length-1) {
            var onetext = obj.options[sel+1].text;
            var onevalue = obj.options[sel+1].value;

			var prevstyle = obj.options[sel+1].style?obj.options[sel+1].style.color:null;
			var curstyle = obj.options[sel].style?obj.options[sel].style.color:null;
			
			var prevbgcolor = obj.options[sel+1].style?obj.options[sel+1].style.backgroundColor:null;
			var curbgcolor = obj.options[sel].style?obj.options[sel].style.backgroundColor:null;
			
            obj.options[sel+1].text  = obj.options[sel].text;
            obj.options[sel+1].value = obj.options[sel].value;

            obj.options[sel].text = onetext;
            obj.options[sel].value = onevalue;
	
			obj.options[sel].style.color = prevstyle;
			obj.options[sel+1].style.color  = curstyle;
			
			obj.options[sel].style.backgroundColor = prevbgcolor;
			obj.options[sel+1].style.backgroundColor  = curbgcolor; 

			obj.selectedIndex = sel+1;
        }
    }
}

function DeleteOrder(obj) {
    var sel = obj.selectedIndex;
    if (sel >= 0) {
        var i=sel;
        for (;i<obj.length-1;i++) {
            var onetext = obj.options[i+1].text;
            var onevalue = obj.options[i+1].value;

			var prevstyle = obj.options[i+1].style?obj.options[i+1].style.color:null;
			var curstyle = obj.options[i].style?obj.options[i].style.color:null;

            obj.options[i].text = onetext;
            obj.options[i].value = onevalue;

            obj.options[i+1].text  = '';
            obj.options[i+1].value = '';

			obj.options[i].style.color = prevstyle;
			obj.options[i+1].style.color  = curstyle;
        }
        obj.length = i;
    }
}

//----------------------------------------------------------------
function getByteLength(str){
	var len = 0;
	if ( str == null ) return 0;
	for(var i=0;i<str.length;i++){
		var c = escape(str.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 ltrim(str){
	var s = new String(str);
	if (s.substr(0,1) == " ") return ltrim(s.substr(1));
	else return s;
}

function rtrim(str){
	var s = new String(str);
	if(s.substr(s.length-1,1) == " ") return rtrim(s.substring(0, s.length-1))
	else return s;
}

function trim(str){
	return ltrim(rtrim(str));
}

function CutString(str,len,more) {
 var l = 0;
 for (var i=0; i<str.length; i++) {
  l += (str.charCodeAt(i) > 128) ? 2 : 1;
  if (l > len) return str.substring(0,i) + (more?more:"");
 }
 return str;
}

function FormMail(vpath, papercode, name, mailto, etc)
{
	var url = vpath + "/mail/mailwin.php?papercode=" + papercode + "&rcvname=" + name + "&mailto=" + mailto + (etc!=null?etc:"");
	var name= "FORMMAIL";
	var opt = "width=400,height=300";
	window.open(url,name,opt);
}

function OpenModal(url,obj,width,height,status,scroll,etc) {
	if ((typeof(width)).toLowerCase() == 'number') width+="px";
	if ((typeof(height)).toLowerCase() == 'number') height+="px";
	var dialogOpt = "dialogWidth:" + width 
				  + ";dialogHeight:" + height 
				  + ";status:" + (status==null?"0":status) 
				  + ";scroll:" + (scroll==null?"1":scroll) 
				  + ";help:0;edge:sunken;" + etc;
    return window.showModalDialog(url,obj,dialogOpt);
}

function SetCookie(sName, sValue, expireDate)
{
	var expire = "";
	if (expireDate != null && expireDate != "")
	{
		expire = "; expires=" + expireDate.toUTCString() + " ;";
		//date.setDate(5);
		
	}
	

	document.cookie = sName + "=" + escape(sValue) + expire;//+ "; expires=" + date.toGMTString();
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function DelCookie(sName)
{
  document.cookie = sName + "=" + escape('2') + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


function uf_GetLastDay(y,m,b) 
{
	var date = new Date(y, m, 1, 12);
	date.setMonth(date.getMonth() + (b?1:0));
	date.setDate(date.getDate()-1);
	return date.getDate();	
}

function addEvent(obj,evt,fnc)
{
	if(document.all)
	{
		obj.attachEvent(evt , fnc);
	} 
	else 
	{
		evt=evt.replace('on','');
		obj.addEventListener(evt , fnc, true)
	}
}

function removeEvent(obj,evt,fnc)
{
	if(document.all)
	{
		obj.detachEvent(evt , fnc);
	}
	else
	{
		evt=evt.replace('on','');
		obj.removeEventListener(evt , fnc, false)
	}
}

function NewsMoviePlay(filename,w,h,s,sc,v)
{
	document.write("<OBJECT classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" ");
	document.write(" CODEBASE=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"");
	document.write(" standby=\"Àá½Ã¸¸ ±â´Ù·ÁÁÖ½Ã±â ¹Ù¶ø´Ï´Ù....\"");
	document.write(" type=\"application/x-oleobject\"");
	document.write(" id=\"IDMovie\"");
	document.write(" width=\"" + (w?w:320) + "\"");
	document.write(" height=\"" + (h?h:320) + "\">");
	document.write("<PARAM NAME=\"FileName\" VALUE=\""+ filename +  "\">");
	document.write("<PARAM NAME=\"AnimationatStart\" VALUE=\"false\">");
	document.write("<PARAM NAME=\"TransparentatStart\" VALUE=\"true\">");
	document.write("<PARAM NAME=\"AutoStart\" VALUE=\"true\">");
	//document.write("<PARAM NAME=\"DisplayMode\" VALUE=\"4\">");
	document.write("<PARAM NAME=\"Volume\" VALUE=\"" + (v?v:"0") + "\">");
	//document.write("<PARAM NAME=\"AllowScan\" VALUE=\"false\">");
	document.write("<PARAM NAME=\"ShowControls\" VALUE=\"" + (s?s:"true") + "\">");
	document.write("<PARAM NAME=\"ShowStatusBar\" VALUE=\"" + (sc?sc:"true") + "\">");
	//document.write("<param name=\"DisplaySize\" value=\"true\">");
	document.write("</OBJECT>");
}


function IndexMoviePlay(filename,w,h,idx)
{
	document.write("<OBJECT classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" ");
	document.write(" CODEBASE=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"");
	document.write(" standby=\"Àá½Ã¸¸ ±â´Ù·ÁÁÖ½Ã±â ¹Ù¶ø´Ï´Ù....\"");
	document.write(" type=\"application/x-oleobject\"");
	document.write(" id=\"" +  (idx?idx:"IDMovieIndex") + "\"");
	document.write(" width=\"" + (w?w:320) +"\"");
	document.write(" height=\"" + (h?h:320) +" \">");
	document.write("<PARAM NAME=\"FileName\" VALUE=\""+ filename +  "\">");
	document.write("<PARAM NAME=\"AnimationatStart\" VALUE=\"false\">");
	document.write("<PARAM NAME=\"TransparentatStart\" VALUE=\"true\">");
	document.write("<PARAM NAME=\"AutoStart\" VALUE=\"true\">");
	document.write("<PARAM NAME=\"AutoSize\" VALUE=\"true\">");
	document.write("<PARAM NAME=\"ShowControls\" VALUE=\"true\">");
	document.write("<PARAM NAME=\"ShowStatusBar\" VALUE=\"false\">");
	document.write("<param name=\"DisplaySize\" value=\"true\">");
	document.write("</OBJECT>");
}

function FlashWrite(path, w, h, name, id, params)
{
	var fname = name?' name="' + name + '" ':'';
	var fid = name?' id="' + id + '" ':'';

	w = w?w:'100%';
	h = h?h:'100%';

	var paramtext = "";
	var embedtext = "";
	if (params)
	{
		for (var i=0;i<params.length;i++)
		{
			paramtext += '<param name="' + params[i][0] + '" value="' + params[i][1] + '" />';
			embedtext += ' ' + params[i][0] + '="' + params[i][1] + '" ';
		}
	}

	document.write('<object ' + fid + ' ' + fname + ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=9,0,28,0" ');
	document.write('width="' + w +'" height="' + h + '">');
	document.write('<param name="movie" value="' + path + '" />');
	document.write('<param name="quality" value="high" /> ');
	document.write('<param name="wmode" value="transparent" />');
	document.write(paramtext);
	document.write('<embed  ' + fid + ' ' + fname + '  type="application/x-shockwave-flash" ');
	document.write('src="' + path + '" quality="high" width="' + w +'" height="' + h +'" ' + embedtext);
	document.write('pluginspage="http://www.macromedia.com/go/getflashplayer_kr"></embed>');
	document.write('</object>');
}

function SwapNodes(item1,item2) 
{  
	var itemtmp = item1.cloneNode(true); 
	var parent = item1.parentNode; 
	item2 = parent.replaceChild(itemtmp,item2); 
	parent.replaceChild(item2,item1);  
	parent.replaceChild(item1,itemtmp); 
	itemtmp = null;
}


function ShowToolTip(e, obj, width, height)
{

	try
	{
		
		//var e = (evt?evt:event);
		var srcEle = e.target?e.target:e.srcElement;
	 
		var text = "";
		if (typeof obj == 'string')
		{
			text = obj;
		}
		else
		{
			try
			{ 
				if (obj && obj.innerHTML) text = obj.innerHTML; 
				else if (obj && obj.value) text = obj.value; 
			}
			catch (e) { }
		}

		if (text == "")
		{
			return;
		}

		var div = document.getElementById("IDToolTip");//?document.getElementById("IDToolTip"):document.createElement("DIV");
		//var div = document.createElement("DIV"); 

		var bIE = document.all?true:false;

		var x = e.x?e.x + document.body.scrollLeft:e.pageX;
		var y = e.y?e.y + document.body.scrollTop:e.pageY; 

		var w = document.body.offsetWidth;
	 
		div.id = "IDToolTip"
		div.style.position = "absolute";
		div.style.backgroundColor = "#f6f6f6";

		if (bIE) div.style.height = height?height:"20px";
		else div.style.minheight = height?height:"20px";
		
		div.style.width = width?width:(bIE?"200px":"190px");
		div.style.border = "2px gray inset";
		div.style.padding = "5px";
		div.style.zIndex = 1000000;

		if (x + parseInt(div.style.width,10) + 20> w) x = w - parseInt(div.style.width,10) -20;
		if (x < 0) x = 0;

		div.style.top = y + 10; 
		div.style.left = x;
	 

		/*
		var parentTag = div.parentNode;
		if (!parentTag || parentTag == "undefined" || (parentTag && parentTag.tagName != "BODY")) 
		{  
			//document.body.focus();
			//if (document.body && document.body.readyState == "complete" && document.body.appendChild)
				document.body.appendChild(div);
		} 
		*/
	 
		div.innerHTML = text;
		div.style.display = "";
	}
	catch (e)
	{
		//alert(e);
	}
}

function HideToolTip() 
{ 
	var div = document.getElementById("IDToolTip");

	if (div)
	{
		try
		{			
			div.innerHTML = "";
			div.style.display = "none"; 	
		}
		catch (e) {	}
	}
}