// JScript ÆÄÀÏ
var __webgear_library_loaded = true;

function na_restore_img_src(name, nsdoc)
{
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img && img.altsrc) {
    img.src    = img.altsrc;
    img.altsrc = null;
  } 
}

function na_preload_img()
{ 
  var img_list = na_preload_img.arguments;
  if (document.preloadlist == null) 
    document.preloadlist = new Array();
  var top = document.preloadlist.length;
  for (var i=0; i < img_list.length; i++) {
    document.preloadlist[top+i]     = new Image;
    document.preloadlist[top+i].src = img_list[i+1];
  } 
}

function na_change_img_src(name, nsdoc, rpath, preload)
{ 
  var img = eval((navigator.appName.indexOf('Netscape', 0) != -1) ? nsdoc+'.'+name : 'document.all.'+name);
  if (name == '')
    return;
  if (img) {
    img.altsrc = img.src;
    img.src    = rpath;
  } 
}

function recvPassword()
{
	var ap = "";
	if(arguments.length > 0)
		ap = String(arguments[0]);
	var pwd = window.prompt("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä", ap);
	if(pwd != null)
	{
		document.forms[0].comment_pw.value = pwd;
		return true;
	}
	else
		return false;
}

window.oprompt = window.prompt;

window.prompt = function(message, defaultValue, isText)
{
	var dArg = [message, defaultValue, isText];
	return window.showModalDialog("/webgear/lib/prompt.htm", dArg, "dialogWidth:330px;dialogHeight:220px;status=no;help=no;");
}

//Á¤±Ô½Ä ÆÐÅÏ¿¡ ºÎÇÕµÇ´ÂÁö ¿©ºÎ ¹ÝÈ¯
//ex) "abc123".validate(/[a-z0-9]+/gm), true ¹ÝÈ¯
String.prototype.validate = function(regEx)
{
	return (this.replace(regEx, "") == "");
}

//¾ÕµÚ °ø¹éÀ» »èÁ¦ ÈÄ ¹ÝÈ¯
//ex) " 123 123 ".trim(), "123 123" ¹ÝÈ¯
String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/, "");
}

//¹®ÀÚ¿­ÀÇ byte ±æÀÌ¸¦ ¹ÝÈ¯
//ex) "abc°¡³ª´Ù¶ó".bytelength(), 11 ¹ÝÈ¯
String.prototype.bytelength = function()
{
	var c = 0, i = 0, len = 0;
	while(!isNaN(c = this.charCodeAt(i++)))
		len += (c > 0xFF?2:1);
	return len;
}

//Æ÷¸Ë¿¡ ¸ÂÃç º¯È¯µÈ ¹®ÀÚ¿­ ¹ÝÈ¯
//ex) "{0} is less than {1} {2}".format(0, 1), "0 is less than 1 {2}" ¹ÝÈ¯
String.prototype.format = function()
{
	var args = arguments;
	return this.replace(/\{(\d+)\}/g, function(whole, match){
			var n = Number(match);
			if(n < args.length)
				return args[n].toString();
			else
				return whole;
		}
	);
}

//¿À¸¥ÂÊ¿¡ ÇØ´ç ¹®ÀÚ¸¦ ±æÀÌ¿¡ ¸Â°Ô µ¡ºÙÀÎ ÈÄ ¹ÝÈ¯
//ex) "a".padRight("b", 3), "abb" ¹ÝÈ¯
String.prototype.padRight = function(ch, len)
{
	return this + new Array(len - this.length + 1).join(ch);
}


//¿ÞÂÊ¿¡ ÇØ´ç ¹®ÀÚ¸¦ ±æÀÌ¿¡ ¸Â°Ô µ¡ºÙÀÎ ÈÄ ¹ÝÈ¯
//ex) "12".padLeft("0", 4), "0012" ¹ÝÈ¯
String.prototype.padLeft = function(ch, len)
{
	return new Array(len - this.length + 1).join(ch) + this;
}

//SELECT ELEMENT ÀÇ ÇØ´ç value¸¦ °®´Â OPTION ELEMENT ¸¦ ¹ÝÈ¯
//ex) findOption(document.forms[0].select1, "1")
function findOption(select, value)
{
	for(var i = 0; i < select.options.length; i++)
		if(select.options[i].value == value)
			return select.options[i];
	return new Object;
}

//ÇØ´ç ³âµµ¿Í ¿ùÀÇ ¸¶Áö¸· ÀÏÀ» ¹ÝÈ¯
//ex) getDaysInMonth(2001, 2), 28 ¹ÝÈ¯
function getDaysInMonth(year, month)
{
	return (new Date(year, month, 0)).getDate();
}

//Date°³Ã¼¸¦ ÁöÁ¤µÈ Æ÷¸Ë¹®ÀÚ¿­·Î º¯È¯ ÈÄ ¹ÝÈ¯
//ex) new Date().format("yyyy-MM-dd")
Date.prototype.format = function(strFormat)
{
	var d = this;
	return strFormat.replace(
		/[a-z]+/ig,
		function(pattern){
			switch(pattern){
			  case "yyyyMMdd":
			    return d.getFullYear() + (d.getMonth() + 1).toString().padLeft("0", 2) + d.getDate().toString().padLeft("0", 2);
			  case "yyyyMM":
			    return d.getFullYear() + (d.getMonth() + 1).toString().padLeft("0", 2);
				case "yyyy":
					return d.getFullYear();
				case "yy":
					return d.getYear();
				case "MM":
					return (d.getMonth() + 1).toString().padLeft("0", 2);
				case "M":
					return d.getMonth() + 1;
				case "dd":
					return d.getDate().toString().padLeft("0", 2);
				case "d":
					return d.getDate();
				case "hh":
					return d.getHours().toString().padLeft("0", 2);
				case "h":
					return d.getHours();
				case "mm":
					return d.getMiniutes().toString().padLeft("0", 2);
				case "m":
					return d.getMinutes();
				case "ss":
					return d.getSeconds().toString().padLeft("0", 2);
				case "s":
					return d.getSeconds();
				case "ms":
					return d.getMilliSeconds();
				default:
					return pattern;
				}
			}
		);
}

function NewsTicker(s, delay)
{
	var t;
	this.initiated = false;
	this.init = function()
	{
		var d = (delay == null?1000:delay);
		var mouseFlag = false;
		var i = 0;
		function adScroll()
		{
			if(mouseFlag)
				return;
			if(--i <= 0)
			{
				window.clearInterval(t);
				s.appendChild(s.childNodes[0]);
				s.scrollTop = 0;
				window.setTimeout(startScroll, d);
				return;
			}
			s.scrollTop++;
		}
		
		function startScroll()
		{
			i = s.childNodes[0].offsetHeight;
			t = window.setInterval(adScroll, 50);
		}
		
		if(s.childNodes.length > 0 && s.offsetHeight < s.scrollHeight)
		{
			s.onmouseover = function(){mouseFlag = true;}
			s.onmouseout = function(){mouseFlag = false;}
			window.setTimeout(startScroll, d);
		}
		this.initiated = true;
	}
	
	this.dispose = function()
	{
		window.clearInterval(t);
	}
}

function NewsTicker2(s, delay)
{
	var t;
	this.initiated = false;
	this.init = function()
	{
		var d = (delay == null?1000:delay);
		var mouseFlag = false;
		var i = 0;
		function adScroll()
		{
			if(mouseFlag)
				return;
			if((i -= 4) <= 0)
			{
				window.clearInterval(t);
				s.appendChild(s.childNodes[0]);
				s.scrollLeft = 0;
				window.setTimeout(startScroll, d);
				return;
			}
			s.scrollLeft += 4;
		}
		
		function startScroll()
		{
			i = s.childNodes[0].offsetWidth;
			t = window.setInterval(adScroll, 50);
		}
		
		if(s.childNodes.length > 0 && s.offsetWidth < s.scrollWidth)
		{
			s.onmouseover = function(){mouseFlag = true;}
			s.onmouseout = function(){mouseFlag = false;}
			window.setTimeout(startScroll, d);
		}
		this.initiated = true;
	}
	
	this.dispose = function()
	{
		window.clearInterval(t);
	}
}

function fwrapper(func, args)
{
	this.invoke = function(){
		func.apply(null, args);
	}
}

function isNumeric()
{
	for(var i = 0; i < arguments.length; i++)
		if(String(arguments[i]) == "" || String(arguments[i]).replace(/\d+/, "") != "")
			return false;
	return true;
}

function isSocialNo(str) {
	var str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, str13;
	var intsum, strchk;
	var rslt = false;

	if (str.length == 13) {
		rslt = true;
		str1 = str.charAt(0);
		str2 = str.charAt(1);
		str3 = str.charAt(2);
		str4 = str.charAt(3);
		str5 = str.charAt(4);
		str6 = str.charAt(5);
		str7 = str.charAt(6);
		str8 = str.charAt(7);
		str9 = str.charAt(8);
		str10 = str.charAt(9);
		str11 = str.charAt(10);
		str12 = str.charAt(11);
		str13 = str.charAt(12);

		intsum = (parseInt(str1) * 2) + (parseInt(str2) * 3) + (parseInt(str3) * 4) + (parseInt(str4) * 5);
		intsum = parseInt(intsum) + (parseInt(str5) * 6) + (parseInt(str6) * 7) + (parseInt(str7) * 8);
		intsum = parseInt(intsum) + (parseInt(str8) * 9) + (parseInt(str9) * 2) + (parseInt(str10) * 3);
		intsum = intsum + (parseInt(str11) * 4) + (parseInt(str12) * 5);

		strchk = intsum % 11;
		strchk = 11 - strchk;

		if (strchk == 11) {
			strchk = 1;
		} else if (strchk == 10) {
			strchk = 0;
		}

		if (str13 != strchk) {
			rslt = false;
		}

	} else {
		rslt = false; 
	}
	return rslt;
}

function SetCookie(sName, sValue, expireDate){
	if(expireDate)
		document.cookie = sName + "=" +sValue+ "; path=/; expires=" + expireDate.toUTCString() + ";";
	else
		document.cookie = sName + "=" +sValue+ "; path=/;";
}

function DelCookie(sName){
	document.cookie = sName + "='temp'; path=/; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function ReadCookie(CookieName){
	var name = CookieName;
	var Found = false;
	var start, end;
	var i = 0
	while(i < document.cookie.length){
		start = i
		end	= start + name.length;
		if(document.cookie.substring(start,end) == name){
			Found = true;
			break;
		}
		i++;
	}
	if(Found == true){
		start = end + 1;
		end	= document.cookie.indexOf(";",start);
		if(end < start){
			end	= document.cookie.length;
		}
		return document.cookie.substring(start, end);
	}
	else
	{
		return null;
	}
}

function openImage(imgPath, imgSrc)
{
	window.open("/webgear/lib/image.htm?" + imgPath + encodeURIComponent(imgSrc), "", "status=yes,resizable=yes,width=200px,height=100px").focus();
}

function previewFile(path, name)
{
  if(name == "")
    return;
  var ext = name.substr(name.lastIndexOf(".")).toLowerCase();
  switch(ext)
  {
    case ".jpg":
    case ".gif":
    case ".bmp":
    case ".png":
      document.write("<center><div align='center' style='width:500px;overflow:hidden;'><img src=\"", path, name, "\" style='display:none;' onload=\"this.style.display='block';resizeImg(this, 500);\" /></div></center><br/>");
    case ".swf":
    case ".asx":
    case ".asf":
    case ".wmv":
    case ".wma":
    case ".avi":
    case ".mp3":
      document.write("<div align='center'><embed src=\"", path, name, "\"></embed></div><br/>")
  }
}

function openFile(imgPath, imgSrc)
{
  try {
    if(imgSrc == "")
      return;
    if(imgSrc.match(/\.(jpg|jpeg|bmp|gif|png)$/i) != null)
    {
      openImage(imgPath, imgSrc);
    }
    else
    {
      window.open(imgPath + imgSrc, "", "");
    }
    return false;
  } catch(e) {
    return true;
  }
}

function getAvailSize(w, h, mw, mh)
{
	if(w > mw || h > mh)
	{
		//width ±âÁØ Ãà¼Ò
		if(h / w > mh / mw)
		{
			return [(mh * w) / h, mh];
		}
		//height ±âÁØ Ãà¼Ò
		else
		{
			return [mw, (mw * h) / w];
		}
	}
	else
		return [w, h];
}

function resizeImgEx(img, maxw, maxh)
{
	if(img.width)
	{
		var avail = getAvailSize(img.width, img.height, maxw, maxh);
		if(avail[0] != 0 && avail[1] != 0 && !isNaN(avail[0]) && !isNaN(avail[1]))
		{
			img.width = avail[0];
			img.height = avail[1];
		}
		else
		{
			img.width = maxw;
			img.height = maxh;
		}
	}
	else
	{
		window.setTimeout(new fwrapper(resizeImgEx, [img, maxw, maxh]).invoke, 10);
	}
}

function resizeImg(img, max)
{
	if(max){}
	else{max = 500;}
	if(img.width)
	{
		if(img.width > img.height)
		{
			if(img.width > max)
				img.width = max;
		}
		else
		{
			if(img.height > max)
				img.height = max;
		}
	}
	else
	{
		window.setTimeout(new fwrapper(resizeImg, [img, max]).invoke, 10);
	}
}

function openWndProgress(form, name)
{
  try {
    var strAppVersion = navigator.appVersion;
    var elem = form.elements[name];
    var uploadFlag = false;
    if(elem) {
      if(elem.length) {
        for(var i = 0; i < elem.length; i++)
          if(elem[i].value != "")
          {
            uploadFlag = true;
            break;
          }
      } else {
        uploadFlag = (elem.value != "")
      }
    }
    if(uploadFlag)
    {
      switch(form.multipart_form_type.value)
      {
        case "DEXT":
        {
          if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4) {
				    winstyle = "dialogWidth=385px; dialogHeight:150px; center:yes";
				    window.showModelessDialog("/webgear/lib/progress/show_progress.asp?nav=ie", null, winstyle);
			    } else {
				    winpos = "left=" + ((window.screen.width-380)/2) + ",top=" + ((window.screen.height-110)/2);
				    winstyle="width=380,height=110,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=no,copyhistory=no," + winpos;
				    window.open("/webgear/lib/progress/show_progress.asp?nav=ns",null,winstyle);
			    }
			    break;
			  }
			  case "TABS":
			  {
          var url = "/webgear/lib/progress/tabs_progress.asp?pid=" + form.progress_id.value;
	        window.open(url, "", "width=380px,height=100px,scrollbars=no,copyhistory=no,top=" + (screen.height-100)/2 + "px,left=" + (screen.width-380)/2 + "px");
			    break;
			  }
			}
    }
  } catch(e) {}
}

function openWndFindPW() {
  var w = 300, h = 150;
  var x = (window.screen.availWidth - w) / 2, y = (window.screen.availHeight - h) / 2;
  var wndFindPW = window.open("/webgear/member/findpw.asp", "wndFindPW", "width=" + w + "px,height=" + h + "px,left=" + x + "px,top=" + y + "px");
  if(wndFindPW){
    wndFindPW.focus();
    wndFindPW.moveTo(x, y);
  }
}