
var IS_NAV = (navigator.appName == "Netscape");
var IS_IE = (navigator.appName == "Microsoft Internet Explorer");

var IS_WIN = (navigator.userAgent.indexOf("Win") != -1);
var IS_MAC = (navigator.userAgent.indexOf("Mac") != -1);
var IS_UNIX = (navigator.userAgent.indexOf("X11") != -1);

/**
 * ÄíÅ°°ª ±¸ÇÏ±â
 * @param name ÄíÅ° ÀÌ¸§
 * @return ÄíÅ°°ªÀÌ ÀÖÀ¸¸é ÄíÅ°°ª ¸®ÅÏ, ¾øÀ¸¸é "" ¸®ÅÏ.
 */
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return "";
}


/**
 * ÄíÅ°°ª ¼³Á¤
 * @param name ÀúÀåÇÒ ÄíÅ°ÀÌ¸§
 * @param value ÄíÅ° °ª
 * @param expires ÄíÅ° ¸¸·áÀÏÀÚ
 * @param path
 * @param domain
 * @param secure
 */
function setCookie(name, value, expires, path, domain, secure) {
    if (!path) {
        path = "/";
    }
    document.cookie = name + "=" + value +
                    ((expires) ? "; expires=" + expires : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
}


/**
 * ÄíÅ° »èÁ¦
 * @param name »èÁ¦ÇÒ ÄíÅ° ÀÌ¸§
 * @param path
 * @param domain
 */
function deleteCookie(name, path, domain) {
    if (!path) {
        path = "/";
    }
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + 
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}


/**
 * ÀÔ·ÂÇÑ ½Ã°£ ÀÌÈÄÀÇ ³¯Â¥
 * @days ÀÏ
 * @hours ½Ã°£
 * @minutes ºÐ
 */
function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" &&
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) +
        parseInt(minutes));
        return expDate.toGMTString( );
    }
}


/**
 * ±¸ºÐÀÚ(";") ÀÌÀüÀÇ ¹®ÀÚ¿­ ¸®ÅÏ
 */
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

/**
 * filter°ª¿¡ ÇØ´çÇÏ´Â ¹®ÀÚ·Î¸¸ ±¸¼ºµÆ´ÂÁö È®ÀÎ
 * ex : <input type="text" ..... onkeypress="filterKey('[0-9]')"> ; ¼ýÀÚ·Î¸¸ ±¸¼ºµÈ text filed
 * ex : <input type="text" ..... onkeypress="filterKey('[0-9a-zA-Z]')"> ; ¼ýÀÚ, ¾ËÆÄºªÀ¸·Î¸¸ ±¸¼ºµÈ text filed
 * @param filter :    ex) '[0-9]':  , '[a-zA-Z]':
 * @return 
 */
function filterInputData(filter) {
    if (filter) {
        var sKey = String.fromCharCode(event.keyCode);
        var re = new RegExp(filter);
        if (!re.test(sKey)) {
            event.returnValue = false;
        }
    }
}


/**
 * ?????? ??????(source)?? ???? ????(query)?? ???????? ?????? ????????.
 * @param source ?????? ???? ??????
 * @param query ?????????? ??????
 * @return ?????? ???????? ???? ?????? ???????? ????
 */
function countInstances(source, query) {
    var re = new RegExp(query, "g");
    var result = source.match(re);
    return (result) ? result.length : 0;
}

/**
 * <div> ?????? ???? ?? ???? ??????(before)?? ???? ??????(after)?? ????????.
 * @param id <div> ?????? id ???? ??
 * @param before ???? ?? ??????
 * @param after ???? ?? ??????
 */
function replaceTextInDiv(id, before, after) {
    var element = document.getElementById(id).firstChild;
    var re = new RegExp(before, "g");
    element.nodeValue = element.nodeValue.replace(re, after);
    return false;
}

function writeTextInElement(id, text) {
    var element = document.getElementById(id);
    if (element.firstChild) {
        element.firstChild.nodeValue = text;
    } else {
        var child = document.createTextNode(text);
        element.appendChild(child);
    }
    return false;
}

/**
 * ???? ?????? 3 ???????? ????(,)?? ???? ????????.
 * @param field ?????? ???? ??
 */
function formatCommas(numString) {
    var re = /,|\s+/g;
    numString = numString.replace(re, "");

    re = /(-?\d+)(\d{3})/;
    while (re.test(numString)) {
        numString = numString.replace(re, "$1,$2");
    }
    return numString;
}

function stripCommas(numString) {
    var re = /,/g;
    return numString.replace(re, "");
}

/**
 * ?????? ?????? ?????? ???? 3???????? ????(,)?? ??????.
 * ?????? ?????? ?????? ????????. onkeyup="toMoney(this)"
 * @param field ?????? ????
 */
function toMoney(field) {
    var value = field.value;
    var indexOfPoint = value.indexOf(".");
    if (indexOfPoint == -1) {
        field.value = formatCommas(value);
    } else {
        field.value = formatCommas(value.substring(0, indexOfPoint)) +
                        value.substring(indexOfPoint, value.length);
    }
}


/**
 * ?? ???? ?????? ?????? ???????? ????????.
 * @param date1 ?????? ???????? '20041012' ????
 * @param date2 ?????? ???????? '20041012' ????
 */
function daysBetween(date1, date2) {
    date1 = new Date(date1.substring(0, 4), date1.substring(4, 6)-1, date1.substring(6,8));
    date2 = new Date(date2.substring(0, 4), date2.substring(4, 6)-1, date2.substring(6,8));
    var DSTAdjust = 0;
    oneMinute = 1000 * 60;
    var oneDay = oneMinute * 60 * 24;
    date1.setHours(0);
    date1.setMinutes(0);
    date1.setSeconds(0);
    date2.setHours(0);
    date2.setMinutes(0);
    date2.setSeconds(0);
    DSTAdjust = (date2.getTimezoneOffset( ) - 
                     date1.getTimezoneOffset( )) * oneMinute;
    var diff = date2.getTime( ) - date1.getTime() - DSTAdjust;
    return Math.ceil(diff/oneDay);
}


/**
 * ???? ?????? ?????? ???? ???? ?????? TEXTAREA?? ????????. ???? ?????? ??????
 * ???????? ????????.
 * @param obj ???? ???? ?????? ???? ????
 */
function listProperties(obj) {
    var objName;

    if (obj.nodeName) {
        objName = obj.nodeName;
    } else {
        objName = "navigator";
    }

    var result = "";
    for (var i in obj) {
        result += objName + "." + i + "=" + obj[i] + "\n";
    }

    var area = document.createElement("textarea");
    area.rows = 20;
    area.cols = 50;
    var body = document.getElementsByTagName("BODY");
    if (body) {
        body[0].appendChild(area);
    } else {
        alert("body ?????? ?????? ??????.");
        return false;
    }
    area.value = result;
    return false;
}

function getQueryString() {
    var result = "";
    var queryTags = document.getElementsByTagName("input");
    for (var i = 0; i < queryTags.length; i++) {
        var name = queryTags[i].name;
		if (name && name.substring(0, 2) == "q_" || name == "pageNo") {
		    result += "&" + name + "=" + queryTags[i].value;
		}
    }

    queryTags = document.getElementsByTagName("select");
    for (var i = 0; i < queryTags.length; i++) {
        var name = queryTags[i].name;
		if (name && name.substring(0, 2) == "q_" || name == "pageNo") {
		    result += "&" + name + "=" + queryTags[i].value;
		}
    }
    return result;
}

/*
 * Focus Move
 * @param len		int
 * @param preObj	Object
 * @param nextObj	Object
 */
function chgFocus(len, preObj, nextObj) {
	if(preObj.value.length == len) {
    	nextObj.focus();
    }
}

/**
  * ?????? ???????? ?????? ???? ???????????? ????
  * @param month   ??????
  * @return true : ?????? ????
 */
function IsMonth(month) {
    if (month.length > 2) return false;
    month = ParseInt(month);
    if ((month <= 0) || (month > 12)) return false;
    return true;
}

/**
  * ?????? ???????? ?????? ???? ???????????? ???? (???? ????????)
  * @param day ??????
  * @return true : ?????? ????
 */
function IsDay(day) {
    if (day.length > 2) return false;
    day = ParseInt(day, 10);
    if ((day <= 0) || (day > 31)) return false;
    return true;
}
        
/**
  * ???? ??, ???? ?????? ?????? ????????
  * @param year   ??
  * @param month  ??
  * @return ?????? ????
 */
function GetEndDay(year,month){
	if ((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month==12))
  		return 31;
	else {
  		if(month==2) {
  			if ((year%4==0) && ((year/4)%200!=0))	return 29;
  			else	return 28;
		} else {
  			return 30;
  		}
	}
}        

/**
  * ???????? ?????? ???????? ????
  * @param str   ??????
  * @return ????
 */
function ParseInt(str) {
    return parseInt(str, 10);
}
    
/**
  * ???????? ?????? ???????????????? ???????? ????
  * @param obj   String
  * @return true : ???? ?????????????? ????
 */
function IsValidJumin(sResNo)
{
	if(sResNo == ""){
		return false;
	}

	if(sResNo.length != 13) {
		return false;
    }
    
	var a = new Array(6)
	var b = new Array(7)
	var tot=0
	var c=0

	var sJumin0 = sResNo.substring(0,6);
	if (!IsMonth(sJumin0.substring(2,4))) {
		return false;
	}
	else if (!IsDay(sJumin0.substring(4,6))) {
		return false;
	}
	    
	var sJumin1 = sResNo.substring(6,13);

	for(var i=1;i<7;i++)
	{
		a[i]=sJumin0.substring(i-1,i);
		b[i]=sJumin1.substring(i-1,i);

		if(i<3)
			c=Number(b[i])*(i+7);
		else
			c=Number(b[i])*((i+9)%10);

		tot = tot + Number(a[i])*(i+1) + c;
	}

	b[7]=sJumin1.substring(6,7);

	if(Number(b[7]) != ((11-(tot%11))%10)) {
		return false;
	}
	else {
		return true;
	}
}

/**
 * ¹®ÀÚ¿­ Ä¡È¯
 */
function replaceStr(str,str1,str2) {

	if (str == "" || str == null) return str;

	while (str.indexOf(str1) != -1) {
		str = str.replace(str1,str2);
	}
	return str;

}    

/**
 * ¹®ÀÚ¿­ ¹ÙÀÌÆ® check
 */
function calByte(name, num) {
    var tmpStr;
    var temp=0;
    var onechar;
    var tcount;
    tcount = 0;

    tmpStr = new String(name);
    temp = tmpStr.length;

    for (k=0;k<temp;k++) {
        onechar = tmpStr.charAt(k);
        if (escape(onechar) =='%0D') {
        }
        else if (escape(onechar).length > 4) {
            tcount += 2;
        }
        else {
            tcount++;
        }
    }

    if(tcount>num) {
        return false;
    } else {
        return true;
    }
}

function onlyNumber() {
    if ((window.event.keyCode == 8) || (window.event.keyCode == 46) || (window.event.keyCode == 9) || (window.event.keyCode == 13)) { //?????????????? del??, Enter???? ????????.
        window.event.returnValue=true;
    } else if( (window.event.keyCode<48) || (window.event.keyCode>57) ) {
        window.event.returnValue=false;
    }
}

function changeDateldh(sdate, edate, i)
{
    var dminus = 0;
    var mminus = 0;

    var from;
    var date=new Date();
    var toDate=new Date();
    var yy, mm, dd;
    var t_yy, t_mm, t_dd;
    
    switch(i){
        case 'd3':
                dminus = 3;
                from=date.getDate() - dminus;
                date.setDate(from);
                break;
        case 'd7':
                dminus = 7;
                from=date.getDate()- dminus;
                date.setDate(from);
                break;
        case 'd10':
                dminus = 10;
                from=date.getDate()- dminus;
                date.setDate(from);
                break;                
        case 'm1':
                mminus = 1;
                from=date.getMonth()-mminus;
                date.setMonth(from);
                break;
        case 'm3':
                mminus = 3;
                from=date.getMonth()-mminus;
                date.setMonth(from);
                break;
        case 'm6':
                mminus = 6;
                from=date.getMonth()-mminus;
                date.setMonth(from);
                break;
    }
    
    yy = date.getYear();
    t_yy = toDate.getYear();
    
    if(date.getMonth()+1 < 10) 
	    mm = "0" + (date.getMonth()+1);
	else 
		mm = date.getMonth()+1;
	if(date.getDate() < 10)
	    dd = "0" + date.getDate();
    else 
	    dd = date.getDate();
	    
    if(toDate.getMonth()+1 < 10) 
	    t_mm = "0" + (toDate.getMonth()+1);
	else 
		t_mm = toDate.getMonth()+1;
	if(toDate.getDate() < 10)
	    t_dd = "0" + toDate.getDate();
    else 
	    t_dd = toDate.getDate();
	
	if(sdate.value == "") 
	    sdate.value = yy + "-" + mm + "-" + dd;
	if(edate.value == "")
	    edate.value = t_yy + "-" + t_mm + "-" + t_dd;
    
}

function trimmed(value) {
    value = value.replace(/^\s+/, "");  /* remove leading white spaces */
    value = value.replace(/\s+$/g, ""); /* remove trailing while spaces */
    return value;
}


/** ÀÌ¹ÌÁö ¸®»çÀÌÂ¡
 * onLoad='adjustImage(this);'
**/
function adjustImage(target_img, maxWidth, maxHeight)
{
	var newX, newY;
	var newHeight, newWidth;
	var newImg;

    if(!maxWidth) {
	    maxWidth = 500;
	}
	if(!maxHeight) {
	    maxHeight = 500;
	}

	newImg = new Image();
	newImg.src = target_img.src;
	imgw = newImg.width;
	imgh = newImg.height;

	//if (imgw*1.2 >= imgh) {
	//	return false;
	//}

	if (imgw > maxWidth || imgh > maxHeight) {
		if(imgw > imgh) {
			if(imgw > maxWidth)
				newWidth = maxWidth;
			else
				newWidth = imgw;
			newHeight = Math.round((imgh*newWidth)/imgw);
		} else {
			if(imgh > maxHeight)
				newHeight = maxHeight;
			else
				newHeight = imgh;
			newWidth = Math.round((imgw*newHeight)/imgh);
		}
	} else {
		newWidth = imgw;
		newHeight = imgh;
	}

	newX = maxWidth/2 - newWidth/2;
	newY = maxHeight/2 - newHeight/2;

	target_img.onload = null;
	target_img.src = newImg.src;
	target_img.width = newWidth;
	target_img.height = newHeight;
}
        
//SelectBox Option »èÁ¦
function removeOption(obj) {
		while(obj.options.length > 0) {
				obj.options[0] = null;
		}
}
