function addCommas(nStr)
{
	
	if (nStr == undefined ) return 0;
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
	
}






function staticDrawTable(identification, listBon, info, afterDraw) {
	// alert( $(identification + ":first-child ").html() );	
	var str =""; $(identification).html( "" ); 
    if (!info )  {	
    	//alert( $(identification +" tr:first td" ) );
    	return false;        	}	
    				
	for(var i=0; i< info.length;i++ ) {
		var strhtmllocal = listBon;
		str += strhtmllocal.replace(/##(\d+)#/g, function (m,key) { return info[i][key];  } ); 	  
	}
	$(identification).html(str);
	if (  typeof afterDraw == 'function'  )   afterDraw.call(this);      
	
}


function getCookie(name) {
	var Found = false
	var start, end;
	var i = 0;
	 
	while(i <= document.cookie.length) {
		start = i;
		end = start + name.length;
		 
		if(document.cookie.substring(start, end) == name) {
			Found = true;
			break;
			}
		i++;
	}
	 
	if(Found == true) {
		start = end + 1;
		end = document.cookie.indexOf(";", start);
		if(end < start)
		 end = document.cookie.length
		return document.cookie.substring(start, end)
	}
	
	return "";
}

function setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function closeWin( bpopup ,CookieName )  {
	
	if ($('input[type=checkbox]', bpopup).attr('checked') )  // 폼네임 cnjform 은 동일해야 합니다.
		setCookie(CookieName, "no" , 1);   // 부모창에서 지정한 쿠키네임과 일치 해야 합니다.
		
	bpopup.fadeOut();	
}

function explode(delimiter,string,limit){
	var emptyArray = { 0: '' };
	if(arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined'){
		return null;
	}
	if(delimiter === '' || delimiter === false || delimiter === null){
		return false;
	}
	if(typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object'){
		return emptyArray;
	}
	if(delimiter === true){
		delimiter = '1';
	}
	if(!limit){
		return string.toString().split(delimiter.toString());
	}else{
		var splitted = string.toString().split(delimiter.toString());
		var partA = splitted.splice(0, limit - 1);
		var partB = splitted.join(delimiter.toString());
		partA.push(partB);
		return partA;
	}
}

function number_format(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 number_format(p1) + "," + p2 + "" + p3;
            }
        );
    }else{
        return input;
    }
}


//문자열을 길이 만큼 자른다.
//* param - str: 자를 문자열
//* param - limit: 자를 바이트 수
//*/
function cutStr(str,limit){
	var tmpStr = str;
	var byte_count = 0;
	var len = str.length;
	var dot = "";

	for(i=0; i<len; i++){
		byte_count += chr_byte(str.charAt(i)); 
		if(byte_count == limit-1){
			if(chr_byte(str.charAt(i+1)) == 2){
				tmpStr = str.substring(0,i+1);
				dot = "...";
			}else {
				if(i+2 != len) dot = "...";
				tmpStr = str.substring(0,i+2);
			}
			break;
		}else if(byte_count == limit){
			if(i+1 != len) dot = "...";
			tmpStr = str.substring(0,i+1);
			break;
		}
	}
	return tmpStr+dot;
}

function chr_byte(chr){
	if(escape(chr).length > 4)
		return 2;
	else
		return 1;
}


function trim(str) {
	
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	
}
	

	
String.prototype.trim = function() {
	
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');

	}




;(function ($) {
	$.addImageButton = $.addImageButton || {};
	$.fn.addImageButton = function( customoptions ) {
	 	
		var options = $.extend( {
			imgsrc :  false
		}, customoptions);
		
		return this.each(function() {
			
			var thisobj = $(this);  
		 	
		 	var imgsrc = thisobj.attr('src');
		 	
		 	
		 	
		 	if (options.imgsrc)  imgsrc = options.imgsrc ;
		 	
		 	var imgwidth = thisobj.attr('width') == 0 ? thisobj.attr('_width')  : thisobj.attr('width') ;
		 	var imgheight = thisobj.attr('height') > 100 ? thisobj.attr('_height')  : thisobj.attr('height') ;

		 	thisobj.css('border','none');
			thisobj.css('display','inline-block');
			thisobj.css('width',imgwidth + "px");
			thisobj.css('height',imgheight + "px");
			thisobj.css("background", "url("+ imgsrc +") 0 0 no-repeat");  
			
			
			thisobj.hover(
				function(){  thisobj.css('background-position','0 -'+ imgheight +'px');  },
				function(){  thisobj.css('background-position','0 0'); }
			);
			
			
			thisobj.mousedown( function(){ thisobj.css('background-position','0 -'+ imgheight*2 +'px'); }  );
			
			//thisobj.attr('src','');
			 
		}); // end of return
	}; // end of function tableList  
	
 
})(jQuery);  

