
function getBrowserAgent(){
	var suserAgent = navigator.userAgent;
	/*
	* �������� ���� �˾ƺ��� ���� ���� ����
	* isIE  �ͽ��÷���(6.7.8���� ����)
	* isIE7 �ͽ��÷ξ� 7�����ΰ� ����
	* isFF ���̾���
	* isSF  ���ĸ�
	* isOP  �����
	*
	* ����
	* //������ �ͽ��÷ξ����� ����
	* if(isIE){
	*  alert('�ͽ��÷ξ��Դϴ�.');
	* }
	*isIE = (suserAgent.indexOf('MSIE') != -1) true; false
	isIE7 = (suserAgent.indexOf('MSIE 7') != -1) true; false
	isFF = (suserAgent.indexOf('Firefox') != -1) true; false
	isSF = (suserAgent.indexOf('Safari') != -1) true; false
	isOP = (suserAgent.indexOf('Opera') != -1) true; false
	*/
	return suserAgent;
}

function getMSIEversion() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf ( "MSIE " );

    if ( msie > 0 ) {     // If Internet Explorer, return version number
       bVer = parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
    } else {                // If another browser, return 0
       bVer = 0;
    }
    return bVer;
}

function getScrollXY() {
	var scrollX = 0;
	var scrollY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrollY = window.pageYOffset;
		scrollX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrollY = document.body.scrollTop;
		scrollX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrollY = document.documentElement.scrollTop;
		scrollX = document.documentElement.scrollLeft;
	}
	var scrollXY = ({X:scrollX, Y:scrollY});
	return scrollXY
}

var getNowScroll = function(){

	var de = document.documentElement;
	var b = document.body;
	var now = {};

	now.X = document.all ? (!de.scrollLeft ? b.scrollLeft : de.scrollLeft) : (window.pageXOffset ? window.pageXOffset : window.scrollX);
	now.Y = document.all ? (!de.scrollTop ? b.scrollTop : de.scrollTop) : (window.pageYOffset ? window.pageYOffset : window.scrollY);

	return now;


}



function numberFormat(input){
    var input = String(input);
    var reg = /(\-?\d+)(\d{3})($|\.\d+)/;
    if(reg.test(input)){
        return input.replace(reg, function(str, p1,p2,p3){
                return numberFormat(p1) + "," + p2 + "" + p3;
            }    
        );
    }else{
        return input;
    }
}

/*
* ������ ���� ���̿� ���� ���� ���ϱ�
* @return json (key= width, height)
*/
function getBrowserSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {width:myWidth, height:myHeight};
}

function getBrowserInfo(){
    var browser;
    var version;
    if(navigator.appName==""){
        browser="Unknown";
    } else {
        browser=navigator.appName;
    }

    version = parseFloat(navigator.appVersion);
    if ((Math.round(parseFloat(navigator.appVersion)*100)) - (parseInt(navigator.appVersion) * 100) == 0) {
        version = version + ".0";
    }

    if (navigator.appName.substring(0,9) == "Microsoft") {
        var msiestart = (navigator.appVersion.indexOf('(') + 1);
        var msieend = navigator.appVersion.indexOf(')');
        var msiestring = navigator.appVersion.substring(msiestart, msieend);
        var msiearray = msiestring.split(";");
        var platform = msiearray[2];
        var msieversion = msiearray[1].split(" ");
        version = msieversion[2];
    }
    return [browser,version];
};

//
//	���� ���ڿ� �ð��� 'YYYYMMDDHHMMSSsss' ������� ��ȯ�Ѵ�.
//
function getYYYYMMDDHHMMSSsss()
{
	var today = new Date();
	var strDateTime = (today.getFullYear() * 100 + today.getMonth() + 1) * 100;
	strDateTime = ( strDateTime + today.getDate() ) * 100;
	strDateTime = ( strDateTime + today.getHours() ) * 100;
	strDateTime = ( strDateTime + today.getMinutes() ) * 100;
	strDateTime = ( strDateTime + today.getSeconds() ) * 1000;
	strDateTime = strDateTime + today.getMilliseconds();

	return strDateTime;
}

//
//	���� ���ڿ� �ð��� 'YYYYMMDDHHMMSS' ������� ��ȯ�Ѵ�.
//
function getYYYYMMDDHHMMSS()
{
	var today = new Date();
	var strDateTime = (today.getFullYear() * 100 + today.getMonth() + 1) * 100;
	strDateTime = ( strDateTime + today.getDate() ) * 100;
	strDateTime = ( strDateTime + today.getHours() ) * 100;
	strDateTime = ( strDateTime + today.getMinutes() ) * 100;
	strDateTime = strDateTime + today.getSeconds();

	return strDateTime;
}

//
//	���� ���ڸ� 'YYYYMMDD' ������� ��ȯ�Ѵ�.
//
function getYYYYMMDD()
{
	var today = new Date();
	var strDate = (today.getFullYear() * 100 + today.getMonth() + 1) * 100;
	strDate = strDate + today.getDate();

	return strDate;
}

//
//	���� �ð��� 'HHMMSSsss' ������� ��ȯ�Ѵ�.
//
function getHHMMSSsss()
{
	var today = new Date();
	var strTime = today.getHours() * 100;
	strTime = ( strTime + today.getMinutes() ) * 100;
	strTime = ( strTime + today.getSeconds() ) * 1000;
	strTime = strTime + today.getMilliseconds();

	return strTime;
}

//
//	���� �ð��� 'HHMMSS' ������� ��ȯ�Ѵ�.
//
function getHHMMSS()
{
	var today = new Date();
	var strTime = today.getHours() * 100;
	strTime = ( strTime + today.getMinutes() ) * 100;
	strTime = strTime + today.getSeconds();

	return strTime;
}

function isIE7(){
    var verInfo = getBrowserInfo();
    if( verInfo[0].indexOf("Microsoft") != -1 && verInfo[1].indexOf("7.0") != -1 ){
        return true;
    }
    return false;
}

function isIE(){
    var info = getBrowserInfo();
    if( info[0].indexOf("Microsoft") != -1 ){
        return true;
    }
    return false;
}

function getIE7PlusFix(fix){
    if( isIE7() ){
        return fix;
    }
    return 0;
}


/**
* ����� �����Ѵ�.
**/
function trim(str){
	str = str.replace(/^\s*/,'').replace(/\s*$/, '');
	return str;
}

/**
* �̸��� ����� �´����� ���θ� �Ǵ��Ѵ�.
**/
function isEmail(mail) {
	if(!/^[\w_-]+(\.[\w_-]+)*@[\w_-]+(\.[\w_-]+)*\.\w{2,3}$/.test(mail)) {
		return false;
	}

	return true;
}


/**
* �������� ���θ� �Ǵ��Ѵ�.
**/
function isNumber(num) {
	var numLen = num.length;
	for( var i = 0 ; i < numLen ; i++ ) {
		var chr = num.charAt(i);
		if( '0' > chr || '9' < chr ) {
			return false;
		}
	}

	return true;
}

/**
* �Է°��� �������� �Ǵ��Ѵ�.
**/
/*
function validateNumberInput() {

    if((window.event.keyCode < 48) || (window.event.keyCode > 57)){
		alert("���ڸ� �Է��Ͽ� �ֽʽÿ�.");
        event.returnValue = false;
    }
}
*/
/**
* ���̼��� üũ�Ѵ�.
**/
function isLimitByteStr(str, maxByte) {
	return(str.length+(escape(str)+"%u").match(/%u/g).length-1) <= maxByte;
}


// �ܱ��� �ֹι�ȣ üũ
function isRegNo_fgnno(fgnno) {
	var sum=0;
	var odd=0;
	buf = new Array(13);
	for(i=0; i<13; i++) { buf[i]=parseInt(fgnno.charAt(i)); }
	odd = buf[7]*10 + buf[8];
	if(odd%2 != 0) { return false; }
	if( (buf[11]!=6) && (buf[11]!=7) && (buf[11]!=8) && (buf[11]!=9) ) {
	        return false;
	}
	multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
	for(i=0, sum=0; i<12; i++) { sum += (buf[i] *= multipliers[i]); }
	sum = 11 - (sum%11);
	if(sum >= 10) { sum -= 10; }
	sum += 2;
	if(sum >= 10) { sum -= 10; }
	if(sum != buf[12]) { return false }
	return true;
}

function isJumin(f_usernum1,f_usernum2){
  check_jumin = false;

  b_Year = (f_usernum2.charAt(0) <= "2") ? "19" : "20"

  b_Year += f_usernum1.substr(0, 2)

  b_Month = f_usernum1.substr(2, 2) - 1

  b_Date = f_usernum1.substr(4, 2)
  b_sum = new Date(b_Year, b_Month, b_Date)
  if ( b_sum.getYear() % 100 != f_usernum1.substr(0,2) || b_sum.getMonth() != b_Month || b_sum.getDate() != b_Date) {
  return check_jumin

  }
  total = 0
  temp = new Array(13)
  for(i=1; i<=6; i++) temp[i] = f_usernum1.charAt(i-1)
  for(i=7; i<=13; i++) temp[i] = f_usernum2.charAt(i-7)
  for(i=1; i<=12; i++) {
  k = i + 1
  if(k >= 10) k = k % 10 + 2


  total = total + (temp[i] * k)

  }

  last_num = (11- (total % 11)) % 10

  if(last_num == temp[13]) check_jumin = true

  else check_jumin = false
  return check_jumin
}


function checkboxAllSelect(itemType1, itemType2){
	var obj = document.getElementsByName(itemType1);
	var objView = document.getElementsByName(itemType2);
	for(var i = 0, len = obj.length ; i < len; i++){
		obj[i].checked = objView[0].checked;
	}
}

function isListChecked(itemType1, itemType2) {
	var obj = document.getElementsByName(itemType1);
	var objView = document.getElementsByName(itemType2);
	for(var i = 0, len = obj.length ; i < len; i++){
		if( obj[i].checked ) {
			return true;
		}
	}

	return false;
}

function callMovie(src) {
	var g = "";
	g += "<object classid='clsid:05589FA1-C356-11CE-BF01-00AA0055595A' id='player' width='320' height='240'>";
	g += "<param name='Filename' value='" + src + "'/>";
	g += "<param name='Showcontrols' value='false'/>";
	g += "<param name='EnableContextMenu' value='false'/>";
	g += "</object>";
	document.write(g);
}

function callMovieFlash(urlPath){
	var sb = new StringBuffer();
	sb.append("<div id='player'>");
	sb.append("<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 ");
	sb.append("codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0 ");
	sb.append("width=512px height=418px id=player align=middle>");
	sb.append("<param name=allowScriptAccess value=always>");
	sb.append("<param name=movie value=/kor/common/swf/player.swf?movieUrl=/upload/dog_etn/school/"+ urlPath +">");
	sb.append("<param name=quality value=high>");
	sb.append("<param name=wmode value=transparent>");
	sb.append("<embed src='/kor/common/swf/player.swf' quality=high pluginspage=http://www.macromedia.com/go/getflashplayer ");
	sb.append("type=application/x-shockwave-flash wmode=transparent width=512px height=418px></embed>");
	sb.append("</object>");
	sb.append("</div>");
	document.write(sb.toString());
}

function callFlash(src, width, height) {
	document.write("�÷��� ���ȴϴ�!~");
}
/** �ߺ�
function drawImage(src, limitWidth, className, limitHeight) {
	var tag = "";
	var img = new Image();
	img.src = src;

	if( limitWidth != null ) {
		if( img.width > parseInt(limitWidth) ) {
			tag = "<img src='" + img.src + "' width='" + limitWidth + "'";
		} else {
			tag = "<img src='" + img.src + "' widht='" + img.width + "'";
		}
	} else {
		tag = "<img src='" + img.src + "' width='" + img.width + "'";
	}

	if( limitHeight != null ) {
		if( img.height > parseInt(limitHeight) ) {
			tag += " height='" + limitHeight + "' ";
		}
	}

	if( className != null ) {
		tag += " class='" + className + "' >";
	} else {
		tag += " > ";
	}

	document.write(tag);
}
**/
function jalert(msg) {
	var rv = window.showModalDialog( "/common/jsp/popupInfo.jsp?msg=" + encodeURI(msg) + "&act=ALERT" , window, "dialogWidth:350px;"
            +"dialogHeight:"+ (270 - getIE7PlusFix(20)) + "px;"
            +"status:0;center:1;help:0;"
            +"dialogHide:0")

}


function jconfirm(msg) {
	var rv = window.showModalDialog( "/common/jsp/popupInfo.jsp?msg=" + encodeURI(msg) + "&act=CONFIRM" , window, "dialogWidth:350px;"
            +"dialogHeight:"+ (270 - getIE7PlusFix(20)) + "px;"
            +"status:0;center:1;help:0;"
            +"dialogHide:0");

	return rv;
}

function jAuthority(msg) {
	var rv = window.showModalDialog( "/common/jsp/popupInfo.jsp?msg=" + encodeURI(msg) + "&act=AUTHORITY" , window, "dialogWidth:350px;"
            +"dialogHeight:"+ (270 - getIE7PlusFix(20)) + "px;"
            +"status:0;center:1;help:0;"
            +"dialogHide:0");

	if( rv ) {
		window.open("http://www.naver.com","pay","width=300, height=400");
	}
}

function returnImageSize(imageFileUrl){

	if(imageFileUrl == null || imageFileUrl ==""){
		return null;
	}

	var imagePath = imageFileUrl;
	var imageInfo = new Image();
	var ImageInfoArray = new Array(2);

	imageInfo.src = imagePath;
	ImageInfoArray[0] = imageInfo.width;
	ImageInfoArray[1] = imageInfo.height;

	return ImageInfoArray;
}

function isWhiteSpace(str){
	var pattern = /\s+/;
	if(str.length == 0 ){
		return true;
	}
	return (pattern.test(str) && str.length == RegExp.lastIndex) ? true : false;
}


function isChecked(value){
	obj = document.getElementsByName(value);
	return obj[0].checked;
}

function replaceWhitespace(str) {
	while(str.indexOf(" ") != -1 || str.indexOf("\n") != -1 || str.indexOf("\r") != -1 ) {
		str = str.replace(" ","");
		str = str.replace("\n","");
		str = str.replace("\r","");
	}
	return str;
}

function replaceValue(contents, b, v) {
	while(contents.indexOf(b) != -1) {
		contents = contents.replace(b, v);
	}
	return contents;
}

function passTypeCheck(value) {
	var a = value;
	var num = false;
	var chars = false;
	var fchars = false;

	if( a.charAt(0) >= 'a' && a.charAt(0) <= 'z' ) {
		fchars = true;
	}

	if( !fchars ) {
		return false;
	}

	for(var i = 0; i < a.length ; i++ ) {
		var ch = a.charAt(i);

		if( ch >= '0' && ch <= '9' ) {
			num = true;
		} else if( (ch >= 'a' && ch <= 'z')
			|| (ch >= 'A' && ch <= 'Z') ) {
			chars = true;
		} else {
			num = false;
			chars = false;
		}
	}

	if( chars ) {
		return true;
	} else if( num && chars ) {
		return true;
	} else {
		return false;
	}
}

function nfpassTypeCheck(value) {
	var a = value;
	var num = false;
	var chars = false;

	for(var i = 0; i < a.length ; i++ ) {
		var ch = a.charAt(i);

		if( ch >= '0' && ch <= '9' ) {
			num = true;
		} else if( (ch >= 'a' && ch <= 'z')
			|| (ch >= 'A' && ch <= 'Z') ) {
			chars = true;
		} else {
			num = false;
			chars = false;
		}
	}

	if( chars ) {
		return true;
	} else if( num && chars ) {
		return true;
	} else {
		return false;
	}
}

function nextFocus(obj,num) {
	if(num == obj.value.length){
		var aForm = obj.form;
	    var len = aForm.elements.length;
		for (var i = 0; i <len; i++) {
			var eachElement = aForm.elements[i];
			if (eachElement == obj) {
				//aForm.elements[i+1].focus();
				for (var j=i+1; j< len; j++) {
					var eachComp = aForm.elements[j];
					try {
						eachComp.focus();
						return;
					}catch(ex) {
						continue;
					}
				}
			}
		}
	}
}

// ����ڵ�Ϲ�ȣüũ
function chkWorkNumb(strNumb) {
    strNumb = strNumb.replaceAll("-","");
   	if (!isNumber(strNumb)) {
        alert("����ڵ�Ϲ�ȣ�� �߸�Ǿ���ϴ�.");
        return false;
   	}
    if (strNumb.length != 10) {
        alert("����ڵ�Ϲ�ȣ�� �߸�Ǿ���ϴ�.");
        return false;
    }
    sumMod = 0;
    sumMod += parseInt(strNumb.substring(0,1));
    sumMod += parseInt(strNumb.substring(1,2)) * 3 % 10;
    sumMod += parseInt(strNumb.substring(2,3)) * 7 % 10;
    sumMod += parseInt(strNumb.substring(3,4)) * 1 % 10;
    sumMod += parseInt(strNumb.substring(4,5)) * 3 % 10;
    sumMod += parseInt(strNumb.substring(5,6)) * 7 % 10;
    sumMod += parseInt(strNumb.substring(6,7)) * 1 % 10;
    sumMod += parseInt(strNumb.substring(7,8)) * 3 % 10;
    sumMod += Math.floor(parseInt(strNumb.substring(8,9)) * 5 / 10);
    sumMod += parseInt(strNumb.substring(8,9)) * 5 % 10;
    sumMod += parseInt(strNumb.substring(9,10));

    if (sumMod % 10 != 0) {
        alert("����ڵ�Ϲ�ȣ�� �߸�Ǿ���ϴ�.");
        return false;
    }
    return true;
}

String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2){
	var temp_str = "";

	if (this.trim() != "" && str1 != str2){
		temp_str = this.trim();
		while (temp_str.indexOf(str1) > -1){
			temp_str = temp_str.replace(str1, str2);
		}
	}
	return temp_str;
}


function isImgFile(str){
	var ext = str.split(".");
	var imgchk = ext[ext.length-1].toUpperCase();

	if(imgchk == "JPG" || imgchk == "GIF" || imgchk == "BMP" || imgchk == "PNG"){
		return true;
	}else{
		return false;
	}
}

function isEng(str) {
	for(var i=0;i<str.length;i++){
		achar = str.charCodeAt(i);
		if( achar > 255 ){
			return false;
		}
	}
	return true;
}

function isKorean(str) {
	var i;
	var ch;

	for (i=0;i<str.length;i++) {
		ch = escape(str.charAt(i));        //ISO-Latin-1 ���ڼ����� ����

		if (strCharByte(ch) != 2) { //�ѱ��� �ƴ� ���
			return false;
		}
	}

	return true;
}

function strCharByte(chStr) {
	if (chStr.substring(0, 2) == '%u') {
		if (chStr.substring(2,4) == '00')
			return 1;
		else
			return 2;        //�ѱ�
	} else if (chStr.substring(0,1) == '%') {
		if (parseInt(chStr.substring(1,3), 16) > 127)
			return 2;        //�ѱ�
		else
			return 1;
	} else {
			return 1;
	}
}

/**
* ���̵� ���̵� üũ�ϱ� ���� �Լ�
* ����,����, _ ���ڸ� ��� üũ
**/
function isMydogIdType(str) {
	var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9_]/;
	return pattern.test(str);
}
/**
* �ѱ� ���� ���ڸ� �ִ����� üũ�Ѵ�
**/
function isNumHanAlpa(text) {
	var regexp = /[^\u0030-\u0039\u0041-\u005a\u0061-\u007a\uac00-\ud7af]/;
	return !regexp.test(text);
}

/**
* ���̵� ���̵� ���̸� ���� üũ �Լ�
* ����,����, _ ���ڸ� ��� üũ �� 6�ڸ� �̻� 15�ڸ� ����
**/
function isMydogIdTypeLenCheck(str) {
	var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9]{5,15}$/;
	return pattern.test(str);
}


function isRegexp(pettern, str){
	//var pettern = /[0-9a-zA-Z��-�ड-��&#\/]/g;
	//var str = document.all.str.value;
	var i = 0;
	while( pettern.exec(str)!=null ){
		i++;
	}

	if( str.length == i ){
		return true;
	}else{
		return false;
	}
}

/**
* ��й�ȣ �Է½� ���̵𰪿� Ư�� ���̸�ŭ
* ���� ���� �ִ����� ���θ� �Ǵ��ؼ� �ѷ��ش�.
* Ư�� ���� ������쿡 true �ƴϸ� false�� �����Ѵ�.
* @param id ���̵�
* @param pw ��й�ȣ
* @param len ����(��Ī�Ǵ� ����)
* @return true or false
**/
function idInPasswordCheck(id, pw, len){
	if(len == null) len = 3;
	return (pw.search("["+ id +"]{"+ parseInt(len) +"}") != -1);
}

//
//	���� �Է��� �����Ѵ�.
//
function checkNumeric( srcNumeric )
{
	if ( srcNumeric.Number == NaN ) return false;
//	var tmpChar;
//
//	for( nIndex = 0; nIndex < srcNumeric.length; nIndex++ )
//	{
//		tmpChar = srcNumeric.charAt( nIndex );
//
//		if ( tmpChar < '0' || tmpChar > '9' ) { return false; }
//	}

	return true;
}

//
//	�ֹε�Ϲ�ȣ ����� �����Ѵ�.
//
function checkResIdNo( srcNumeric )
{
	var sum = 0;

	if ( srcNumeric.length < 13 ) return false;

	for( nIndex = 0; nIndex < 8; nIndex++ ) { sum += srcNumeric.substring( nIndex, nIndex + 1 ) * ( nIndex + 2 ); }
	for( nIndex = 8; nIndex < 12; nIndex++ ) { sum += srcNumeric.substring( nIndex, nIndex + 1 ) * ( nIndex - 6 ); }

	sum = 11 - ( sum % 11 );

	if ( sum >= 10 ) { sum -= 10; }
	if ( srcNumeric.substring( 12, 13 ) != sum || ( srcNumeric.substring( 6, 7 ) != 1 && srcNumeric.substring( 6, 7 ) != 2 ) ) { return false; }

	return true;
}

//
//	�ܱ��� ������ �����Ѵ�.
//
function checkForeignNm( srcNm )
{
	var chr = srcNm.split( "\\" );
	var strChar = chr[chr.length - 1];

	//	��� ����
	if ( (/[\s]/).test( strChar ) )
	{
		return false;
	}

	for( nIndex = 0; nIndex < strChar.length; nIndex++ )
	{
		chr = strChar.substr( nIndex, 1 );

		if ( chr >= 'a' && chr <= 'z' )
			return false;
	}

	return true;
}

/**
* textarea �ڽ��� byte���� üũ�Ѵ�.
* ����
* <form method='post' name='form'>
* <textarea name='sms_msg' value='' onkeyup="length_count(this, 80)" onchange="length_count(this, 80)" onfocus="length_count(this, 80)"  cols=16 rows=5></textarea><br>
* <span id='sms_msg_count'>0</span> Byte (80����Ʈ���� �Է°����մϴ�.)
* </form>
* ǥ�õ� ���ڼ���  name (sapn�� name)�� textarea name + '_count' ��
**/
/*
function length_count(filed, max_count){
	var str;
	var str_count = 0;
	var cut_count = 0;
	var str_length = filed.value.length;

	for(k=0; k < str_length; k++){
		str = filed.value.charAt(k);
	    if(escape(str).length > 4){
	    	str_count += 2;
	    }else{
	    // (\r\n�� 1byte ó��)
	        if(escape(str)=='%0A') {
	        }else{
	        	str_count++;
	        }
	    }
	    if(max_count < str_count){
	    	alert("���ڼ��� "+ max_count +" byte �̻��� ���Ұ����մϴ�");
		    if(escape(str).length > 4){
		    	str_count -= 2;
		    }else{
		    	str_count--;
		    }
		    filed.value = filed.value.substring(0,k);
		    break;
	    }
	}
	try{
		document.getElementById(filed.name+"_count").innerHTML = str_count;
		//eval("document.all."+ filed.name+"_count.innerHTML = str_count;");
	}catch(e){}
}
*/

/**
* textarea �ڽ��� ���ڼ��� üũ�Ѵ�.
* ����
* <form method='post' name='form'>
* <textarea name='smsMsg' value='' onkeyup="lengthWordCount(this, 80)" onchange="lengthWordCount(this, 80)" onfocus="lengthWordCount(this, 80)"  cols=16 rows=5></textarea><br>
* <span id='smsMsgCount'>0</span> �� (80�ڱ��� �Է°����մϴ�.)
* </form>
* ǥ�õ� ���ڼ���  name (sapn�� name)�� textarea name + 'Count' ��
*
**/
/*
function lengthWordCount(filed, max_count){
	//var str;
	var str_count = 0;
	var cut_count = 0;
	var str_length = filed.value.length;

	for(k=0; k < str_length; k++){
		//str = filed.value.charAt(k);
	    str_count++;

	    if(max_count < str_count){
	    	alert("���ڼ��� "+ max_count +"�� �̻��� ���Ұ����մϴ�");
	    	str_count--;
		    filed.value = filed.value.substring(0,k);
		    break;
	    }
	}
	try{
		document.getElementById(filed.name+"Count").innerHTML = str_count;
	}catch(e){}
}
*/
/**
* �̹��� Ȯ��� üũ�� �Ѵ�.
**/
function checkExt(fileName) {
 	var tar = fileName;
 	var fname=tar.toLowerCase();
    var s=fname.lastIndexOf("\\");
    var m=fname.lastIndexOf(".");
    var e=fname.length;
    var filename=fname.substring(s+1,m);
    var extname=fname.substring(m+1,e);
    if (extname=="gif" || extname=="jpg"
    	//|| extname=="bmp"
    	|| extname=="png"
    	|| extname=="jpeg"
    	|| tar.value == ""){
  		return true;
    }else{
  		alert("�̹��� ���ϸ� ÷�� �����մϴ�.");
  		return false;
 	}
 }



/**
* �ʵ尪�� �ʱ�ȭ �ϰ� ��Ŀ���� �̵���Ų��.
**/
function fieldEmptyFocus(msg, fieldName){
	alert(msg);
	$(fieldName).value = "";
	$(fieldName).focus();
}

/**
* str -> byte change
**/
String.prototype.bytes = function(){
	var str = this;
	var l = 0;
	for (var i=0; i<str.length; i++) l += (str.charCodeAt(i) > 128) ? 2 : 1;
	return l;
}

function isCheckboxed(value){
	var obj = value;
	for(var i=0; i<obj.length;i++){
		if( obj[i].checked ) return true;
	}
	return false;
}


/**
* ���̾ ȭ�� �߾����� ���� ���� �Լ�
* ����
* <body onLoad="centerWindow('layer1')">
* <div id="layer1" style="float:right; position: absolute; right:10px; bottom:10px;z-index:10; text-align:center;background-color: transparent;" >
* <table border="1" cellpadding="0" cellspacing="0">
*  <tr>
*   <td>123</td>
*  </tr>
*</table>
*</div>
*</body>
**/
function centerWindow(value) {
	var layer =  document.getElementById(value);
    var bodyWidth   = document.body.clientWidth;
    var bodyHeight  = document.body.clientHeight;
    var divWidth    = layer.offsetWidth;
    var divHeight   = layer.offsetHeight;
    var divLeft = 0, divTop = 0;
    if(bodyWidth > divWidth) {        // left �� ���ϱ�
        divLeft = Math.ceil((bodyWidth - divWidth) / 2);
    }
    if(bodyHeight > divHeight) {    // top �� ���ϱ�
        divTop = Math.ceil((bodyHeight - divHeight) / 2);
    }
    layer.style.left = divLeft;
    layer.style.top = divTop;
}

/* Ư�̻���  */
function centerLayer(value) {
	var layer =  document.getElementById(value);
    var bodyWidth   = document.body.clientWidth;
    var bodyHeight  = document.body.clientHeight;
    var divWidth    = layer.offsetWidth;
    var divHeight   = layer.offsetHeight;
    var divLeft = 0, divTop = 0;
    if(bodyWidth > divWidth) {        // left �� ���ϱ�
        divLeft = Math.ceil((bodyWidth - divWidth) / 2);
    }
    if(bodyHeight > divHeight) {    // top �� ���ϱ�
        divTop = Math.ceil((bodyHeight - divHeight) / 2);
    }
    layer.style.left = divLeft;
    layer.style.top = divTop;
}

function centerWindow2(value1, value2) {
	var layer =  document.getElementById(value1);
    var bodyWidth    = document.body.clientWidth;
    var bodyHeight    = document.body.clientHeight;
    var divWidth    = layer.offsetWidth;
    var divHeight    = layer.offsetHeight;
    var divLeft = 0, divTop = 0;
    if(bodyWidth > divWidth) {        // left �� ���ϱ�
        divLeft = Math.ceil((bodyWidth - divWidth) / 2);
    }

    if(bodyHeight > divHeight) {    // top �� ���ϱ�
        divTop = Math.ceil((bodyHeight - divHeight) / 2);
    }

    layer.style.left = divLeft - 100;
    layer.style.top = divTop - 100;

    var layer2 = document.getElementById(value2);
    layer2.style.height = bodyHeight - 100;
}


/*  Function Equivalent to URLEncoder.encode(String, "UTF-8")

    Copyright (C) 2002 Cresc Corp.

    Version: 1.0

*/

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){
        	s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){     // check for escape
                s0 = s0 + s;           // don't escape
            }else {                      // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}



/*  Function Equivalent to URLDecoder.decode(String, "UTF-8")

    Copyright (C) 2002 Cresc Corp.

    Version: 1.0

*/

function decodeURL(str){
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";    // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters to parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;          // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}    // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}             // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }
    return s0;
}

/**
* �̹��� ����� ������¡�Ѵ�.
*
**/
function drawImage(src, limitWidth, className, limitHeight) {
	var tag = "";
	var img = new Image();
	img.src = src;

	if( limitWidth != null ) {
		if( img.width > parseInt(limitWidth) ) {
			tag = "<img src='" + img.src + "' width='" + limitWidth + "'";
		} else {
			tag = "<img src='" + img.src + "' widht='" + img.width + "'";
		}
	} else {
		tag = "<img src='" + img.src + "' width='" + img.width + "'";
	}

	if( limitHeight != null ) {
		if( img.height > parseInt(limitHeight) ) {
			tag += " height='" + limitHeight + "' ";
		}
	}

	if( className != null ) {
		tag += " class='" + className + "' >";
	} else {
		tag += " > ";
	}

	document.write(tag);
}

/**
* ���ӵ� �ڸ����� �ֳ��� üũ�ϱ� ���� �Լ�
* ���̵�, ��й�ȣ�� �������ε� ���� üũ�� ���
* @param str �Է°�
* @param len ���ӵ� ���ڰ�
* @return ���ӵ� ���ڰ� ������� true �׷��� ������� false
**/
function isContinuityChar(str, len){
	if(str == null || str == "") return false;
	if(len == null || len == "") len = 4;
	var result = false;
	for( var i = 0; i < str.length; ++i){
		var pattern = "/"+ str.charAt(i) +"{"+ len +",}/";
		if(eval(pattern).test(str)){
			result = true;
			break;
		}
	 }
	 return result;
}

/**
* �̹��� ũ�⸦ limitWidth ũ��� �����մϴ�.
* @param imgObj �̹��� ��ü
* @param limitWidth ũ��
*/
function imageSize(imgObj, limitWidth){
	var imageWidth = imgObj.width;
	if( limitWidth != null ) {
		if( imageWidth > parseInt(limitWidth) ) {
			imgObj.width = limitWidth;
		}
	}
}

/**
* StringBuffer
**/
function StringBuffer(){this.buffer=[];}
StringBuffer.prototype.append = function(String){
	this.buffer.push(String);
	return this;
}
StringBuffer.prototype.toString = function(){
   return this.buffer.join("");
}

function remaindTime(id, date) {
	var nowdate = new Date();
	nowdate.setMonth( (nowdate.getMonth()+1) );
	var year = parseInt(date.substring(0,4));
	var month = parseInt(date.substring(4, 6));
	var day = parseInt(date.substring(6, 8));
	var hour = parseInt(date.substring(8,10));
	var minute = parseInt(date.substring(10, 12));
	var second = parseInt(date.substring(12, 14));
	var enddate = new Date(year, month, day, hour, minute, second);
	
	var nowmille = nowdate.getTime();
	var endmille = enddate.getTime();

	var dsecond = parseInt( endmille - nowmille ) / 1000;
	var dday = parseInt(dsecond/ (60*60*24));
	dsecond = (dsecond - (dday * 60 * 60 * 24));
	var dhour = parseInt( dsecond /(60*60) );
	dsecond = (dsecond - (dhour*60*60));
	var dminute = parseInt(dsecond/60);
	dsecond = parseInt(dsecond-(dminute*60));
}

function getRemaindTime(dseccond) {
	if (dseccond <= 0) return "0초";
	var remaindTime = "";
	var day = parseInt( dseccond / ( 60 * 60 * 24));
	dseccond = dseccond - ( day * 60 * 60 * 24);
	if (day > 0) remaindTime += day + "일 ";
	
	var hour = parseInt( dseccond / ( 60 * 60));
	dseccond = dseccond - ( hour * 60 * 60 );
	if (hour > 0) remaindTime += hour + "시간 ";

	var minute = parseInt( dseccond / (60) );
	dseccond = dseccond - ( minute * 60 );
	if (minute > 0) remaindTime += minute + "분 ";
	
	var second = parseInt(dseccond);
	remaindTime += second + "초 전";
	
	return remaindTime;
}
