
// ÀÔ·Â°ªÀÌ NULLÀÎÁö Ã¼Å© 
function is_null(input) { return (input.value == null || input.value == ""); }


// ÀÔ·Â°ª¿¡ ½ºÆäÀÌ½º ÀÌ¿ÜÀÇ ÀÇ¹ÌÀÖ´Â °ªÀÌ ÀÖ´ÂÁö Ã¼Å© 
function is_empty(input) { return (input.value == null || input.value.replace(/ /gi,"") == ""); }


// ÀÔ·Â°ª¿¡ Æ¯Á¤ ¹®ÀÚ(chars)°¡ ÀÖ´ÂÁö Ã¼Å© (Æ¯Á¤ ¹®ÀÚ¸¦ Çã¿ëÇÏÁö ¾ÊÀ¸·Á ÇÒ ¶§ »ç¿ë)
function contains_chars(input, chars) { 
	for (var inx = 0; inx < input.value.length; inx++) { 
		if (chars.indexOf(input.value.charAt(inx)) != -1) return true; 
	} 
	return false; 
} 


// ÀÔ·Â°ªÀÌ Æ¯Á¤ ¹®ÀÚ(chars)¸¸À¸·Î µÇ¾îÀÖ´ÂÁö Ã¼Å© (Æ¯Á¤ ¹®ÀÚ¸¸ Çã¿ëÇÏ·Á ÇÒ ¶§ »ç¿ë)
function contains_chars_only(input, chars) { 
	for (var inx = 0; inx < input.value.length; inx++) { 
		if (chars.indexOf(input.value.charAt(inx)) == -1) return false; 
	} 
	return true; 
} 


// ÀÔ·Â°ªÀÌ ¾ËÆÄºª
function is_alphabet(input) { 
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 
	return contains_chars_only(input, chars); 
} 


//ÀÔ·Â°ªÀÌ ¾ËÆÄºª ´ë¹®ÀÚÀÎÁö Ã¼Å© 
function is_upper_case(input) { 
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
	return contains_chars_only(input, chars); 
} 


// ÀÔ·Â°ªÀÌ ¾ËÆÄºª ¼Ò¹®ÀÚÀÎÁö Ã¼Å© 
function is_lower_case(input) { 
	var chars = "abcdefghijklmnopqrstuvwxyz"; 
	return contains_chars_only(input, chars);  
} 


// ÀÔ·Â°ª¿¡ ¼ýÀÚ¸¸ ÀÖ´ÂÁö Ã¼Å© 
function is_number(input) { 
	var chars = "0123456789"; 
	return contains_chars_only(input, chars);  
} 


// ÀÔ·Â°ªÀÌ ¾ËÆÄºª,¼ýÀÚ·Î µÇ¾îÀÖ´ÂÁö Ã¼Å© 
function is_alpha_num(input) { 
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 
	return contains_chars_only(input, chars); 
} 


// ÀÔ·Â°ªÀÌ ¼ýÀÚ,´ë½Ã(-)·Î µÇ¾îÀÖ´ÂÁö Ã¼Å© 
function is_num_dash(input) { 
	var chars = "-0123456789"; 
	return contains_chars_only(input, chars); 
} 


// ÀÔ·Â°ªÀÌ ¼ýÀÚ,ÄÞ¸¶(,)·Î µÇ¾îÀÖ´ÂÁö Ã¼Å© 
function is_num_comma(input) { 
	var chars = ",0123456789"; 
	return contains_chars_only(input, chars); 
} 


// ÀÔ·Â°ªÀÌ »ç¿ëÀÚ°¡ Á¤ÀÇÇÑ Æ÷¸Ë Çü½ÄÀÎÁö Ã¼Å© 
function is_valid_format(input,format) { return (input.value.search(format) != -1); } 


// ÀÔ·Â°ªÀÌ ÀÌ¸ÞÀÏ Çü½ÄÀÎÁö Ã¼Å© 
function is_email_format(input) { 
	var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/; 
	return is_valid_format(input, format); 
} 


// ÀÔ·Â°ªÀÌ ÀüÈ­¹øÈ£ Çü½ÄÀÎÁö Ã¼Å©
function is_phone_num_format(input) { 
	var format = /^(\d+)-(\d+)-(\d+)$/; 
	return is_valid_format(input, format); 
} 

// ¹ÙÀÌÆ® ±æÀÌ¸¦ ¸®ÅÏ
function get_byte_length(input) { 
	var byte_length = 0; 
	for (var i = 0; i < input.value.length; i++) { 
		var one_char = escape(input.value.charAt(i)); 
		if (one_char.length == 1) byte_length ++; 
		else if (one_char.indexOf("%u") != -1) byte_length += 2; 
		else if (one_char.indexOf("%") != -1) byte_length += one_char.length / 3; 
	}
	return byte_length; 
} 

// ÀÔ·Â°ª¿¡¼­ ÄÞ¸¶¸¦ ¾ø¾Ø´Ù. 
function remove_comma(input) { 
	return input.value.replace(/,/gi,""); 
} 

function input_keycode_number(keycode) {
	// 48 ~ 57 : keyboard À§¿¡ ÀÖ´Â ¼ýÀÚ ÄÚµå
	// 96 ~ 105 : keyboard ¿ìÃøÀÇ ¼ýÀÚÆÇ¿¡ ÀÖ´Â ÄÚµå
	// 8 : back space, 13 : enter key
	if( (keycode >= 48 && keycode <= 57) ||
		(keycode == 8) || (keycode == 13) ){
		return true;
	}else{
		return false;
	}
}

// ÄÁÆ®·Ñ¿¡ ÀÔ·ÂµÈ °ªÀÇ ±æÀÌ¸¦ Ã¼Å©ÇÑ´ÙÀ½ ´ÙÀ½ ÄÁÆ®·Ñ·Î ÀÌµ¿
function move_focus(current_obj, next_obj, length) {
	if (next_obj == "undefined" || next_obj == null) return;
	if (get_byte_length(current_obj) >= length) next_obj.focus();
}

// »õÃ¢ ¶ç¿ì±âÀÇ ³ôÀÌ º¸Á¤
function get_size_by_version(height){

	var height_size;
	if(height == null){
		height_size = 0;
	}else{
		height_size = height
	}

	// IE 7.0 º¸Á¤
	if (window.navigator.appVersion.indexOf("MSIE 7.0") > 0){
		height_size = height_size + 30;
	}

	return height_size;
}


// ÄíÅ°°ªÀ» °¡Á®¿Â´Ù
function get_cookies(name) { 

	var cookies_name = name + "="; 
	var x = 0; 

	while ( x <= document.cookie.length ) { 
		var y = (x + cookies_name.length); 
		if (document.cookie.substring(x, y) == cookies_name) { 			
			if ((end_of_cookies = document.cookie.indexOf(";", y)) == -1) end_of_cookies = document.cookie.length; 
				return unescape(document.cookie.substring( y, end_of_cookies)); 
        } 

		x = document.cookie.indexOf(" ", x) + 1; 
		if (x == 0) break; 
    } 
	return ""; 
} 

 
// ÄíÅ°°ªÀ» ÀúÀåÇÑ´Ù
function set_cookies(name, value, expire_days) { 

	if (expire_days != null) {
		var todayDate = new Date(); 
		todayDate.setDate( todayDate.getDate() + expire_days); 
	    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
	} else {
	    document.cookie = name + "=" + escape( value ) + "; path=/;" 
	}
} 


// ·¹ÀÌ¾îÀÇ Ãâ·Â¿©ºÎ¸¦ Åä±Û½ÃÅ²´Ù
function toggle_layer_visibility(obj) {
	if (obj.style.visibility != 'visible') obj.style.visibility ='visible';
	else obj.style.visibility = 'hidden';
}


function controlImage(_image)
{
	controlImageReSize(_image, 500, 500);
}

function controlImageReSize(_image, nWidth, nHeight)
{
	var newX;
	var newY;
	var newHeight;
	var newWidth;
	var maxWidth = nWidth;
	var maxHeight = nHeight;
	var newImg = new Image();
	newImg.src = _image.src;
	imgw = newImg.width;
	imgh = newImg.height;
	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;
	_image.onload = null;
	_image.src = newImg.src;
	_image.width = newWidth;
	_image.height = newHeight;
}


// ÀÔ·Â°ªÀÌ Æ¯Á¤ ¹®ÀÚ(chars)¸¸À¸·Î µÇ¾îÀÖ´ÂÁö Ã¼Å© (Æ¯Á¤ ¹®ÀÚ¸¸ Çã¿ëÇÏ·Á ÇÒ ¶§ »ç¿ë)
function check_charactor(string, chars) { 
	for (var inx = 0; inx < string.length; inx++) { 
		if (chars.indexOf(string.charAt(inx)) == -1) return false; 
	} 
	return true; 
} 


function xssFilter(string)
{
	var pattern = new Array(2);
	pattern[0] = /\@@variable|\@variable|\--/gi
	pattern[1] = /[<>|\'\"@;+%#()$\\&]/gi

	for(cnt=0; cnt < 2; cnt++){
		string = string.replace(pattern[cnt],"");
	}
	
	return string;
}

function scriptFilter(string)
{
	var pattern = new Array(2);
	pattern[0] = /\.location|location\.|onload=|\.cookie|\alert/gi
	pattern[1] = /\window|\.open|(onmouse|onkey|onclick|view|-source)/gi

	for(cnt=0; cnt < 2; cnt++){
		string = string.replace(pattern[cnt],"");
	}
	
	return string;
}

function filterparam(string, isnumber, mincount, maxcount)
{
	var buf = string;
	if(buf == null){
		buf = '';
	}
	
	if(mincount > buf.length){
		return -1;
	}else if(maxcount > 0 && maxcount < buf.length){
		return -2;
	}else if(isnumber){
		var chars = "-0123456789"; 
		if(!check_charactor(buf, chars)){
			return -3;
		}
	}else{
		buf = xssFilter(buf);
		buf = scriptFilter(buf);
	}
	
	return buf;
}

function getPageUrl()
{
	var pageUrl = location.href;
	if(pageUrl.indexOf('?') < 0)
		return pageUrl;

	var queryString = pageUrl.substring(pageUrl.indexOf('?')+1, pageUrl.length);
	var args = queryString.split('#')[0].split('&');
	var hostUrl = pageUrl.substring(0, pageUrl.indexOf('?')+1);
	var buf = '';
	var cnt = 0;

	for(cnt = 0; cnt < args.length; cnt++)
	{
		if(cnt > 0)		buf += '&';
		buf += filterparam(args[cnt], false, 0, 0);
	}

	return hostUrl + encodeURL(buf);
}

function get_scrollTop() 
{
	if (typeof(window.pageYOffset) == "number") {
		return window.pageYOffset;
	} else if (typeof(document.body.scrollTop) == "number") {
		return document.body.scrollTop;
	} else {
		return 0;
	}
}

function init_frame(frame_name) {

	var objFrame	=	document.all[frame_name];

	if (objFrame != null) {
		var objBody	    =	eval(frame_name).document.body;
		objFrame.style.height = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);
		objFrame.style.width = '100%';
	}

}

/* ¸¶¿ì½º ÀÌº¥Æ® ¸·±â */
function disabled_click() {
	if (navigator.appName == "Netscape") {
		document.captureEvents(Event.MOUSEDOWN)
		document.onmousedown = checkClick

		function checkClick(ev) {
        	if (ev.which != 1) {
        	        return false
        	}
		}
	}else{
		//if ((event.button==2) || (event.button==3)) {
        	return false
		//}
	}
}

	
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;

} 

