﻿/* **************************************************************
	Wiz Javascript - AJAX Utility Library
	Version : 2.0
	Developer : wiz (wizys@yahoo.co.kr / http://wiz.pe.kr/)
	Last Updated : 2007.03.13 - Ver. 2.0 Upgrade (AJAX.NET Base)
		2007.02.22 - Ver. 1.2 Upgrade
		2006.05.04 - Ver. 1.1 Upgrade
		2005.04.25 - First Version By wiz
************************************************************** */

/** START:BROWSER DETECTION ********************/
_nv=navigator.appVersion.toLowerCase();
ie4 =(!document.getElementById&&document.all)?true:false;
ie5 =(_nv.indexOf('msie 5.0')!=-1)?true:false;
ie55=(_nv.indexOf('msie 5.5')!=-1)?true:false;
ie6 =(_nv.indexOf('msie 6')!=-1)?true:false;
ie7 =(_nv.indexOf('msie 7')!=-1)?true:false;
ie8 =(_nv.indexOf('msie 8')!=-1)?true:false;
isIE=(_nv.indexOf('msie')!=-1) ?true:false;
/** END:BROWSER DETECTION ********************/

/* **************************************************************
	Object Functions
************************************************************** */
/* AJAX.NET으로 변경 function $get() { }*/
function $(tg) { if(typeof(tg)=='string') { return $get(tg); } else { return tg; } }
/* Object Append tg에 ctlID의 ctl을 추가 */
function $Add(tg, ctlID, ctl)	{ var otg = $(tg); if(otg) { ctl.setAttribute('id', ctlID); otg.appendChild(ctl); return ctlID; }else { return '';} }
/* Object Remove */
function $Del(ctlID)	{ var ctl = $(ctlID); if(ctl) { if(ctl && ctl.style) { ctl.style.display='none'; } GetPNode(ctl).removeChild(ctl); }}

function GetOuterHTML(obj)
{
	if(obj.outerHTML) { return obj.outerHTML; }
	else
	{
		var tbox = document.createElement('div');
		tbox.appendChild(obj);
		return tbox.innerHTML;
	}
}

/* **************************************************************
	String Functions
************************************************************** */
function V() { return; }
function IsEmpty(str) { if(str&&str.length>0&&str.replace(/ /g,'')!='') { return false; } else { return true; } }

/* Mail validator (http://wiz.pe.kr/blog2/128) */
function CheckMail(strMail) 
{
	var check1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	var check2 = /^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4})$/; 
	if(!IsEmpty(strMail)) 
	{
		if ( !check1.test(strMail) && check2.test(strMail) ) { return true; } 
		else { return false;} 
	} 
}

/* Copy To Clipboard */
function CopyToClip(tgTxt) { window.clipboardData.setData('Text',tgTxt); }

/* Get Parent Node Object */
function GetPPNode(tg) { return GetPNode(GetPNode(tg)); }
function GetPNode(tg) { var otg = $(tg); if(otg.parentNode) { return otg.parentNode; } else { return otg; } }

/* Set Focus */
function SetFocus(tg) { $(tg).focus(); }


/* **************************************************************
	Window Functions
************************************************************** */
function NW(lk) { return NW(lk, null); }
function NW(lk,tg) { window.open(lk.href, tg);return false; }
function ShowPopup(url, name, w, h) { ShowPopup(url, name, w, h, false, true); }
function ShowPopup(url, name, w, h, s, r) { ShowPopup(url, name, w, h, s, r, false); }
function ShowPopup(url, name, w, h, s, r, b)
{
	var tgwin = window.open(url,name,'toolbar=no,location=no,directories=no,status='+(b?'yes':'no')+',menubar=no,scrollbars='+(s?'yes':'no')+',resizable='+(r?'yes':'no')+',width='+w+',height='+h+'');
	tgwin.focus();
	return tgwin;
}

/* Image PopupWindow */
function ShowImage(tg)
{
	var tgwin = ShowPopup('about:blank','imgWin', 200, 200, false, true, false);
	tgwin.document.write('<img src="'+tg+'" name="thisImg" alt="클릭하면 창이 닫힙니다." onclick="self.close();" style="cursor:pointer;" /'+'>');
	tgwin.document.write('<scr'+'ipt type="text/javascr'+'ipt">');
	tgwin.document.write('function fileresize(){'
		+'var imgWidth = document.all.thisImg.width+35;'
		+'var imgHeight = document.all.thisImg.height+35;'
		+'if(document.all.thisImg.complete == true)'
		+'{'
		+'if( imgWidth > screen.availWidth ) imgWidth = screen.availWidth;'
		+'if( imgHeight > screen.availHeight ) imgHeight = screen.availHeight;'
		+'window.self.resizeTo(imgWidth,imgHeight);'
		+'}'
		+'}'
		+'');
	tgwin.document.write('</'+'scr'+'ipt>');
	if (isIE) { tgwin.document.body.onload	= function() { return fileresize(); }; }
	else { tgwin.document.body.addEventListener('onload', function() { return fileresize(); }, true); }
	tgwin.focus();
}

/* **************************************************************
	Display Functions
************************************************************** */
/* Get Windows Width */
function GetBodyWidth()
{
	var rtn = 0;
	if(isIE) { rtn = document.body.offsetWidth; } else { rtn = window.innerWidth; }
	if(rtn<document.body.scrollWidth) { rtn = document.body.scrollWidth; }
	return rtn;
}	
function GetControlWidth(otg) { if(isIE) { return otg.offsetWidth; } else { return otg.innerWidth; } }
/* Get Windows Height */
function GetBodyHeight()
{
	var rtn = 0;
	if(isIE) { rtn = document.body.offsetHeight; } else { rtn = window.innerHeight; }
	if(rtn<document.body.scrollHeight) { rtn = document.body.scrollHeight; }
	return rtn;
}
function GetControlHeight(otg) { if(isIE) { return otg.offsetHeight; } else { return otg.innerHeight; } }

/* Display Option Change */
function DisplayCh(tg) { var otg = $(tg); if(otg) { otg.style.display= ((otg.style.display=='none')?'':'none'); } }
/* Display Option Change */
function DisplaySet(tg, val) { var otg = $(tg); if(otg) { otg.style.display = (val)?'':'none'; } }
/* Display Message */
function ShowWorkMsg(tg, msg, ev) { tg.text = msg; tg.enable = ev; }
/* Object Opecity Setting */
function SetOpecity(tg, val)
{
	if(val<0) { val = 0; } else if(val>=100) { val = 100; }

	var otg = $(tg);
	if(otg)
	{
		otg.style.opacity = otg.style.MozOpacity = otg.style.KhtmlOpacity = (val / 100);
		otg.style.filter = "alpha(opacity="+val+")";
	}
}

/* Progress Background Image Setting */
function SetPBBG(tg, cn, val)
{
	var otg = $(tg);
	if(otg)
	{
		otg.className = ('PB_'+val);
		if(cn&&cn.length>0) { otg.className = (' '+cn +m); }
	}
}

/* Select Box Util */
function GetSelectedValue(tg) { if(!tg || tg.selectedIndex<0) { return; } return tg.options[tg.selectedIndex].value; }
function SetSelectedValue(tg, val)
{
	if(!tg) { return; }
	var opts = tg.options;
	if(opts) { for(tmpi=0;tmpi<opts.length;tmpi++) { if(opts[tmpi].value==val) { tg.selectedIndex = tmpi; break; } }	}
}

/* **************************************************************
	Wiz Javascript - Cookie Utility
	Version : 1.1
	Developer : wiz (wizys@yahoo.co.kr / http://wiz.pe.kr/)
	Last Updated : 2007.03.13 - ver. 1.1 Upgrade
		2004.02.26 - Ver. 1.0 First Version By wiz
************************************************************** */
function DelCookie (name, path, domain) { if(GetCookie(name)) { document.cookie = name+"="+((path) ? "; path="+path : "")+((domain) ? "; domain="+domain : "")+"; expires=Thu, 01-Jan-70 00:00:01 GMT"; } }
function SetCookie (name, value, expires, path, domain, secure) { document.cookie = (name+"="+escape(value)+((expires) ? "; expires="+expires.toGMTString() : "")+((path) ? "; path="+path : "")+((domain) ? "; domain="+domain : "")+((secure) ? "; secure" : "")); }
function GetCookie (name) {
	var cp = name+'='; var cpl = cp.length;
	var c = document.cookie;
	var csi = c.indexOf(cp);
	if (csi<0) { return ''; }
	else
	{
		var cci = c.indexOf(";", csi+cpl);
		if (cci == -1) { cci = c.length; }
		return unescape(c.substring(csi+cpl, cci));
	}
}

function GetCOption(key) { return GetCookie(key); }
function SetCOption(key, val)
{
	var ex = new Date();
	ex.setTime(ex.getTime() + 31536000000);
	SetCookie(key, val, ex, '/', '', '');
}

/* **************************************************************
	Flash Tag Insert Script : IE Patch
************************************************************** */
function InsertFlash(path, w, h) { InsertFlash(path, w, h, 'transparent'); }
function InsertFlash(path, w, h, bgcolor)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+w+'" height="'+h+'" id="egg" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="'+path+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="'+bgcolor+'" />'); 
	document.write('<param name="bgcolor" value="'+bgcolor+'" />');
	document.write('<embed src="'+path+'" quality="high" bgcolor="'+bgcolor+'" width="'+w+'" height="'+h+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

/* 자리수 표시 함수 */
function SetComma(v)
{
	var rtn = '';
	var cnt = v.length-1;
	if(cnt<3) { return v; }
	for(var tmpi=cnt, cck = 1;tmpi>=0;tmpi--, cck++)
	{
		rtn=(v.substr(tmpi,1)+rtn);
		if(cck==3 && tmpi>0) { rtn=(',' + rtn);cck=0; }
	}
	return rtn;
}