/***
 * main.js
 * lastModified 2006/10/27
 * 
 * 2006/04/21 : check_extension(String fullname, String match_extension, boolean allowDeny) funtion Ãß°¡
 * 				- allowDeny false : match_extension ¿¡ µî·ÏµÈ È®ÀåÀÚ Çã¿ë
 * 				- allowDeny true : match_extension ¿¡ µî·ÏµÈ È®ÀåÀÚ Á¦ÇÑ
 * 2006/05/03 : check_fileSize(Object formElement, Object input, int limitSize) funtion Ãß°¡
 * 2006/07/14 : fillString(String str, int len) function Ãß°¡
 * 2006/07/14 : optionSelected(Object obj, String checkValue) function Ãß°¡
 * 2006/07/14 : radioChecked(Object obj, String checkValue) function Ãß°¡
 * 2006/07/18 : arrayQueryString(String str) function Ãß°¡ 
 * 				- GET URL QueryString ¹è¿­·Î ÀúÀå (this.addURL)
 * 2006/07/18 : getParameter(String name) function Ãß°¡
 *      		- GET URL QueryString "name" Parameter value return
 * 2006/10/11 : checkBoxChecked(Object obj, String checkValue) function Ãß°¡
 * 2006/10/26 : nvObject(String Name, String Value) function Ãß°¡
 * 				- Object => Name, Value ·Î ÀúÀå
 * 2006/10/26 : nvObjectIndex(Array array, String Name) function Ãß°¡
 * 				- nvObject ¸¦ ÀÌ¿ë ¹è¿­·Î ÀúÀåÇÒ °æ¿ì Name °ªÀ» Á¶È¸ ¹è¿­ÀÎµ¦½º¸¦ ¸®ÅÏ
 * 2006/10/26 : arrayQueryString() function ¼öÁ¤
 * 				- GET URL QueryString => nvObject ¸¦ ÀÌ¿ë ¹è¿­·Î ÀúÀå
 * 2006/10/26 : addQs() function Ãß°¡
 * 				- n°³ÀÇ Ãß°¡ Parameter ¸¦ GET URL QueryString ¿¡ Ãß°¡
 * 2006/10/26 : chgQs(Name, Value) function Ãß°¡
 * 				- Name Paramter °ªÀ» º¯°æ
 * 2006/10/26 : delQs() function Ãß°¡
 * 				- n°³ÀÇ Name Parameter ¸¦ GET URL QueryString ¿¡¼­ Á¦°Å
 * 2006/10/26 : getQsValue() funciton Ãß°¡
 * 				- Name Paramter °ª ¸®ÅÏ
 * 2006/10/26 : getQs() function Ãß°¡
 * 				- GET URL QueryString ¹®ÀÚ¿­·Î ¸®ÅÏ, getQs(1) : Null Parameter Á¦°ÅÇØ¼­ ¸®ÅÏ
 */

/************************* COMMON *************************/
function makeArray(n)
{
	this.length = n;
	for (var i = 1; i <= n; i++) this[i] = null;
	return this;
}
function getObjectID(id)
{
	return document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : null;
}
function showHideLine(id)
{
	var obj = getObjectID(id);
	if (obj) obj.style.display = (obj.style.display == "none") ? "inline" : "none";
}
function showLayer(element, visible)
{
	var layers;
	if ((navigator.appName == "Netscape") && (navigator.appVersion.charAt(0) < "5")) {
		if (visible == "show")
			element.visibility = "show";
		else
      		element.visibility = "hide";
		return;
	}
	if (navigator.appVersion.charAt(0) < "5") {
		layers = document.all.tags("div");
	} else {
		layers = document.getElementsByTagName("div");
	}
	if (visible == "show")
		layers[0].style.visibility = "visible";
	else
    	layers[0].style.visibility = "hidden";
	return;
}
function popWin(url, name, x, y)
{
	var top, left, sc, re;
	var arg = popWin.arguments;
	var aLen = popWin.arguments.length;

	left = (aLen > 4 && arg[4] != 0)	? arg[4] : (screen.width - x) / 2;
	top = (aLen > 5 && arg[5] != 0)	? arg[5] : (screen.height - y) / 2;
	sc = (aLen > 6) ? arg[6] : 0;
	re = (aLen > 7) ? arg[7] : 0;

	var settings  = 'height=' + y + ', width=' + x + ', ';
		settings += 'top=' + top + ', left=' + left + ', ';
		settings += 'scrollbars=' + sc + ', ';
		settings += 'resizable=' + re;

	winObj = window.open(url, name, settings);

	return winObj;
}
function nvObject(Name, Value)
{
	this.Name = Name;
	this.Value = Value;
}
function nvObjectIndex(array, Name)
{
	for (var i = 0; i < array.length; i++)
		if (array[i].Name == Name)
    		return i;
	return -1;
}
/************************* COMMON : END *************************/

/************************* COOKIE *************************/
function getCookie(name)
{
	var name = name + "=";
	var nLen = name.length;
	var cLen = document.cookie.length;
	var i = 0;

	while ( i < cLen )
	{
      var j = i + nLen;
		if (document.cookie.substring(i, j) == name) {
			var end = document.cookie.indexOf(";", j);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(j, end)); //ÄíÅ°°ª ¹ÝÈ¯
      }
		i = document.cookie.indexOf(" ", i) + 1;
		if ( i == 0) {
			break;
		}
	}
}
function setCookie(name, value)
{
	var expires = new Date();
	var path, domain, secure;
	var arg = setCookie.arguments;
	var aLen = setCookie.arguments.length;

	if (aLen > 2) {
		expires.setTime(expires.getTime() + (1000*60*arg[2]));	// arg[2] : ºÐ´ÜÀ§·Î È£Ãâ
	} else {
		expires = null;
	}
	path = (aLen > 3)	? arg[3] : null;
	domain = (aLen > 4)	? arg[4] : null;
	secure = (aLen > 5)	? arg[5] : false;

	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : (";expires=" + expires.toGMTString())) +
		((path == null) ? "" : (";path=" + path)) +
		((domain == null) ? "" : (";domain=" + domain)) +
		((secure == true) ? " ;secure" : "" );
}
function delCookie(name)
{
	var value = getCookie(name);
	var expires = new Date();
	expires.setDate(expires.getDate() - 1);

	if (value != null) {
		document.cookie = name + "=" + escape(value) + ("; expires=" + now.toGMTString());
		return 1;
	} else {
		return -1;
	}
}
/************************* COOKIE : END *************************/

/************************* DATE *************************/
function valid_Date(month, day, year)
{
	var chk_date = Math.abs(month) + "/" + Math.abs(day) + "/" + Math.abs(year);
	var obj_date = new Date(Date.parse(chk_date));
	var cmp_date = (obj_date.getMonth()+1) + "/" + obj_date.getDate() + "/" + obj_date.getFullYear();

	if (cmp_date == "NaN/NaN/NaN")   return 0;
	else if (chk_date == cmp_date)   return 1;
	else  return -1;
}
function last_Date(month, day, year)
{
	var chk_date = month + "/" + day + "/" + year;
	var today = new Date();
	var today = (today.getMonth()+1) + "/" + today.getDate() + "/" + today.getYear();
	var today = new Date(Date.parse(today));
	var end_day = new Date(Date.parse(chk_date));

	if (today.getTime() > end_day.getTime())  return -1;
	else  return 1;
}
function getSearchDate(scope)
{
	var sDate = new Date();
	var eDate = new Date();

	switch (scope) {
		case "TODAY" : break;
		case "YESTERDAY" :
			sDate.setDate(sDate.getDate() - 1);
			eDate.setDate(eDate.getDate() - 1);
			break;
		case "THIS_WEEK" :
			sDate.setDate(sDate.getDate() - sDate.getDay());
			break;
		case "LAST_WEEK" :
			sDate.setDate(sDate.getDate() - (7 + sDate.getDay()));
			eDate.setDate(eDate.getDate() - (eDate.getDay()+1));
			break;
		case "THIS_MONTH" :
			sDate.setMonth(sDate.getMonth(), 1);
			break;
		case "LAST_MONTH" :
			sDate.setMonth(sDate.getMonth() - 1, 1);
			eDate.setMonth(eDate.getMonth(), 0);
			break;
	}
	
	var seDate = new Array(2);
	seDate[0] = sDate.getFullYear() + "" + fillString(sDate.getMonth() + 1, 2) + fillString(sDate.getDate(), 2);
	seDate[1] = eDate.getFullYear() + "" + fillString(eDate.getMonth() + 1, 2) + fillString(eDate.getDate(), 2);
	
	return seDate;
}
/************************* DATE : END *************************/

/************************* CHECK VALUE *************************/
function chech_ASCII(check_string)
{
	var char_ASCII = check_string.charCodeAt(check_string.length-1);
	
	//¼ýÀÚ, ¿µ¾î, Æ¯¼ö¹®ÀÚ, ÇÑ±Û
	if (char_ASCII >= 48 && char_ASCII <= 57 ) return 1;
	else if ((char_ASCII>=65 && char_ASCII<=90) || (char_ASCII>=97 && char_ASCII<=122)) return 2;
	else if ((char_ASCII>=33 && char_ASCII<=47) || (char_ASCII>=58 && char_ASCII<=64) ||
			 (char_ASCII>=91 && char_ASCII<=96) || (char_ASCII>=123 && char_ASCII<=126)) return 4;
	else if ((char_ASCII >= 12592) || (char_ASCII <= 12687)) return 3;
	else  return 0;
}
function isMatchSpecial_ASCII(str)
{
	var i, ch;
	for (i = 0; i < str.length; i++) {
		ch = str.charCodeAt(i);
		if ((ch>=33 && ch<=47) || (ch>=58 && ch<=64) || (ch>=91 && ch<=96) || (ch>=123 && ch<=126)) return false;
	}

	return true;
}
function isMatchNotHangul_ASCII(str)
{
	if (str.length > 0 ) {
		for (var i = 0; i < str.length; i++)
			if (str.charCodeAt(i) < 128 )
				return false;
	}

	return true;
}
function isMatchNotAlphaNumeric(str)
{
	var regExp = /[^a-z0-9]/i;
	if (regExp.test(str)) return false;
	else return true;
}
function isMatchNotNumeric(str)
{
	var regExp = /\D/i;
	if (regExp.test(str)) return false;
	else return true;
}
function isMatchNotBlank(str)
{
	var regExp = /\S/i;
	if (regExp.test(str)) return true;
	else return false;
}
function isMatchBlank(str)
{
	var regExp = /\s/i;
	if (regExp.test(str)) return false;
	else return true;
}
function check_Email(str)
{
	var regExp = /^[a-z0-9]{2,}@([a-z0-9-]+){2,}(\.[a-z]{2,}){1,}$/i;
	if (regExp.test(str)) return true;
	else return false;
}
function chkHttpHost(str) 
{
    var regExp = /^(http\:\/\/)?((\w+)[.])+(asia|biz|cc|cn|com|de|eu|in|info|jobs|jp|kr|mobi|mx|name|net|nz|org|travel|tv|tw|uk|us)(\/(\w*))*$/i;
    return regExp.test(str);
}
function chkIp(str) 
{
	var regExp = /^(1|2)?\d?\d([.](1|2)?\d?\d){3}$/;
    return regExp.test(str);
}
function check_Byte(input)
{
	var i, j = 0;
	for (i = 0; i < input.length; i++) {
		val = escape(input.charAt(i)).length;
		if (val ==  6) j++;
		j++;
	}

	return j;
}
function check_radio(input, msg)
{
	var len = input.length;
	for (var i = 0; i < len; i++)
		if (input[i].checked == true && input[i].value)
			return true;
	alert(msg);

	return false;
}
function check_select(input, msg)
{
	if (input[0].selected == true) {
		alert(msg);
		return false;
	}

	return true;
}
function onlyNumber() {
	if ((event.keyCode < 48) || (event.keyCode > 57)) event.returnValue = false;
}
function tab_order(input, next, len)
{
	if (input.value.length == len) {
		next.focus();
		return;
	}
}
/************************* CHECK VALUE : END *************************/

/************************* FORM ELEMENT *************************/
function optionSelected(obj, checkValue)
{
	for (var i = 0;i < obj.length; i++)
		if (obj.options[i].value == checkValue) {
			obj.selectedIndex = i;
			break;
		}
}
function radioChecked(obj, checkValue)
{
	for (var i = 0; i < obj.length; i++)
		if (obj[i].value == checkValue)
			obj[i].checked = true;
}
function checkBoxChecked(obj, checkValue)
{
	if (obj.value == checkValue) obj.checked = true;
}
function chkboxAllChecked(f, checker, startWith)
{
	if (checker.checked) {
		for (var i = 0; i < f.length; i++)
			if (f.elements[i].type == "checkbox") {
				if (f.elements[i].name.substring(0, startWith.length) != startWith) continue;
				f.elements[i].checked = true;
			}
	} else {
		for (var i = 0; i < f.length ; i++)
			if (f.elements[i].type == "checkbox") {
				if (f.elements[i].name.substring(0, startWith.length) != startWith) continue;
				f.elements[i].checked = false;
			}
	}
}
function chkboxAllCheckedChange(f, checker, startWith)
{
	var isChecked = true;
	for (var i = 0; i < f.length; i++) 
		if (f.elements[i].type == "checkbox") {
			if (f.elements[i].name.substring(0, startWith.length) != startWith) continue;
			if (f.elements[i].checked == false) {
				isChecked = false;
				break;
			}
		}

	checker = eval("f." + checker);
	if (isChecked) checker.checked = true;
	else checker.checked = false;
}
/************************* FORM ELEMENT : END *************************/

/************************* FILE *************************/
function check_extension(fullname, match_extension, allowDeny)
{
	var extension = "";
	var isMatches = allowDeny;
	var index = fullname.lastIndexOf('.');
	var arr_extension = match_extension.split("|");

	if (index != -1)
		extension = fullname.substring(index + 1, fullname.len);
	if (extension.lastIndexOf('\\') != -1)
		extension = "";

	if (extension != "" ) {
		for (i = 0; i < arr_extension.length; i++)
			if (extension.toLowerCase() == arr_extension[i]) {
				isMatches = !isMatches;
				break;
			}
	} else {
		return false;
	}

	return isMatches;
}
// ÀÌ¹ÌÁö ÆÄÀÏ¸¸
function check_fileSize(formElement, input, limitSize)
{
	formElement.dynsrc = input.value;
	if (formElement.fileSize > limitSize)
		return false;
	else
		return true;
}
/************************* FILE : END *************************/

/************************* IMAGE *************************/
function resizeImage(imageSrc, resizeWidth, resizeHeight)
{
	var sourceWidth = imageSrc.width;
	var sourceHeight = imageSrc.height;
	var size = new Array;

	if (sourceWidth <= resizeWidth && sourceHeight <= resizeHeight) {
		size[0] = sourceWidth;
		size[1] = sourceHeight;
	} else {
		if (sourceWidth > sourceHeight) {
			size[0] = resizeWidth;
			size[1] = Math.ceil(sourceHeight * resizeWidth / sourceWidth);
		} else if(sourceWidth < sourceHeight) {
			size[0] = Math.ceil(sourceWidth * resizeHeight / sourceHeight);
			size[1] = resizeHeight;
		} else {
			size[0] = resizeWidth;
			size[1] = resizeHeight;
		}

		if (size[0] > resizeWidth) {
			size[0] = resizeWidth;
			size[1] = Math.ceil(sourceHeight * resizeWidth / sourceWidth);
		}
		if (size[1] > resizeHeight) {
			size[0] = Math.ceil(sourceWidth * resizeHeight / sourceHeight);
			size[1] = resizeHeight;
		}
	}

	size[2] = sourceWidth;
	size[3] = sourceHeight;

	return size;
}
function vi(imageSrc, resizeWidth, resizeHeight, isLink)
{
	var size = resizeImage(imageSrc, resizeWidth, resizeHeight);
	imageSrc.width = size[0];
	imageSrc.height = size[1];
   
	if (isLink) {
		imageSrc.onclick = function() {
			locT = Math.ceil((screen.width - size[2])/2);
			locL = Math.ceil((screen.height - size[3])/2);
			obj = window.open("", 'imageViewer', 'width=' + size[2] + ',height=' + size[3] + ',top=' + locT + ',left=' + locL);

			var doc = obj.document;
			doc.body.style.margin = 0;
			doc.body.style.cursor = "hand";

			var createTag = doc.createElement("img");
			createTag.src = imageSrc.src;
			doc.body.appendChild(createTag);
			doc.body.onmousedown = function(){ obj.close();}
			doc.title = "¿øº» ÀÌ¹ÌÁö";
		}

		imageSrc.style.cursor = "hand";
	}
}
/************************* IMAGE : END *************************/

/************************* GET URL QUERYSTRING *************************/
function arrayQueryString()
{
	var nv;
	var arrayQuery = new Array();
	var params = location.search.substring(1).split("&");

    for (var i = 0; i < params.length; i++)
	{
		if (params[i].indexOf('=') == -1) continue;
		nv = params[i].split('=');
        arrayQuery[i] = new nvObject(nv[0], nv[1]);
    }

    return arrayQuery;
}
function addQs()
{
    var nv;
    var arg = addQs.arguments;
	var argCount = addQs.arguments.length;

    for (var i = 0; i < argCount; i++) {
        nv = arg[i].split('=');
        this.addURL.push(new nvObject(nv[0], nv[1]));
    }

    return true;		
}
function chgQs(Name, Value)
{
	var index = nvObjectIndex(this.addURL, Name);
	if (index == -1) addQs(Name + '=' + Value);
	else this.addURL.splice(nvObjectIndex(this.addURL, Name), 1, new nvObject(Name, Value));
}
function delQs()
{
	var index;
    var arg = delQs.arguments;
    var argCount = delQs.arguments.length;

    for (var i = 0; i < argCount; i++) {
		if (nvObjectIndex(this.addURL, arg[i]) == -1) continue;
        this.addURL.splice(nvObjectIndex(this.addURL, arg[i]), 1);
    }
}
function getQsValue(Name)
{
	var index = nvObjectIndex(this.addURL, Name);
	return (index == -1) ? "" : this.addURL[index].Value;
}
function getQs()
{
    var qs = new Array();
    var __null = (getQs.arguments.length > 0) ? true : false;

    for (var i = 0; i < this.addURL.length; i++)
    {
        if (__null && this.addURL[i].Value == "") continue;
        qs.push(this.addURL[i].Name + '=' + this.addURL[i].Value);
    }

    return (qs.length == 0) ? "" : '?' + qs.join("&");
}
/************************* GET URL QUERYSTRING : END *************************/

/************************* ETC *************************/
function base64_encode(str)
{
	var InStr = str;
	var ttb = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var len_1 = InStr.length;
	var len_res = InStr.length % 3;
	var len_div = len_1 - len_res;
	var ra = new makeArray(4);
	var i = 0;
	var Stat = "";
	var str = "";

	while (1) 
	{
		if (i >= len_1) break; 
		if (i >= len_div) Stat = "End";

		A = eval(InStr.charCodeAt(i++));
		B = eval(InStr.charCodeAt(i++));
		C = eval(InStr.charCodeAt(i++));

		if (i > len_div) {
			Stat = "End";
			if(len_res >= 1) C = 0;
			if(len_res == 1) B = 0;
		}

		ra[1] = A >> 2;
		ra[2] = ( (A & 3) << 4 ) + (B >> 4);
		ra[3] = ( ( B & 15 ) << 2 ) + ( C >> 6);
		ra[4] = C & 63;

		if (Stat == "End" && len_res >= 1) ra[4] = 64;
		if (Stat == "End" && len_res == 1) ra[3] = 64;

		for (k = 1; k <= 4; k++) str = str + ttb.substr(ra[k],1); 
	}

	return str;   
}
function inner_form(form, name, val, action)
{
	document.body.insertAdjacentHTML("beforeEnd", "<form id=" + form + "></form>");
	var obj = document.getElementById(form);
	var arr = name.split(":");
	var arr_val = val.split(":");

	for (i = 0; i < arr.length; i++)
		obj.innerHTML += "<input type=hidden name='" + arr[i] + "' value='" + arr_val[i] + "' />";

	obj.action = action;
	obj.method = "POST";
	obj.submit();
}
function fillString(str, len)
{
	var addStr = "";
	var count = len - ("" + str).length;
	if (count > 0) {
		var fillStr = (fillString.arguments.length > 2) ? fillString.arguments[2] : "0";
		for (var i = 0; i < count; i++)
			addStr += fillStr;
	}

	return addStr.concat(str);
}
function eolasObj(obj)
{
   document.write(obj);
}