if(typeof window != 'undefined' && typeof window.j$ === 'undefined'){
	if(!!window.jQuery){
		window.j$ = jQuery.noConflict();
	};
};
//querystring¿¡¼­ ÇØ´ç °ªÀ» º¯°æ
function setQuery(key, value, query){
	if(typeof query === "undefined"){
		query = location.search.substr(1);
	};
	if(typeof key === "object"){
		for(var l_key in key){
			query = setQuery(l_key, key[l_key], query);
		};
	}else if(typeof key === "string" && typeof value !== "undefined"){
		var l_reg = new RegExp("(" + key + "=)[^$&]*");
		if(query && l_reg.test(query)){
			query = query.replace(l_reg, "$1" + value);
		}else{
			query += ("&" + key + "=" + value);
		};
	};
	return (query.indexOf("&") === 0 ? query.substr(1) : query);
};


function getCookie(name){
	var l_cookie = document.cookie;
	var l_value = "";
	if(new RegExp(name + "=([^;&]*)").test(l_cookie)){
		l_value = RegExp.$1;
	};

	return (typeof l_value === "undefined" ? "" : l_value);
};

function setCookie(name, value, expires){
	document.cookie = name + "=" + escape (value) + "; path=/; expires=" + (typeof expires === "undefined" ? "" : expires.toGMTString());
}


String.prototype.comma = function() {
	return this.replace(/,/g, '').replace(
		/^([-+]?\d+)(\d{3})($|\..*$)/g
		, function(Original_String, Match_String_1, Match_String_2, Match_String_3) {
			return Match_String_1.comma() +(',' + Match_String_2 + Match_String_3);
		}
	);
};

String.prototype.money=function(){
	return this.replace(/,/g, "")
		.replace(/[^\d\-]+/g, "")
		.comma();
};

String.prototype.truncateByte=function(length, truncation){
	length = length || 30;
	truncation = Object.isUndefined(truncation) ? '..' : truncation;

	var l_tempString = "";
	var l_tempLength = 0;
	for(var l_idx = 0; l_idx < this.length; ++l_idx){
		l_tempLength += (this.charCodeAt(l_idx) > 128 ? 2 : 1);
		if(l_tempLength <= length){
			l_tempString += this.substr(l_idx, 1);
		}else{
			l_tempString += truncation;
			break;
		};
	};
	return l_tempString;
};




Date.prototype.lastDay = function() {

	var l_firstDayOfNextMonth = new Date(
		this.getFullYear(),
		this.getMonth() + 1,
		1
	);
	
	return l_firstDayOfNextMonth.add('d', -1).getDate();
};
Date.prototype.firstDate = function()
{
	var l_firstDayOfNextMonth = new Date(
		this.getFullYear(),
		this.getMonth(),
		1
	);
	return l_firstDayOfNextMonth;
};
Date.prototype.add = function(p_part, p_interval) {
	var l_thisYear = this.getFullYear();
	var l_thisMonth = this.getMonth();
	var l_thisDay = this.getDate();

	var l_addedDate = null;

	switch (p_part.toUpperCase()) {
		case 'D': {
			l_addedDate = new Date(l_thisYear, l_thisMonth, l_thisDay + p_interval);
			break;
		};
		case 'M': {
			l_addedDate = new Date(l_thisYear, l_thisMonth + p_interval, 1);
			if(l_thisDay > l_addedDate.lastDay())
				l_thisDay = l_addedDate.lastDay();
			l_addedDate = new Date(
				l_addedDate.getFullYear()
				, l_addedDate.getMonth()
				, l_thisDay
				);
			break;
		};
		case 'Y': {
			l_addedDate = new Date(l_thisYear + p_interval, l_thisMonth, 1);
			if(l_thisDay > l_addedDate.lastDay())
				l_thisDay = l_addedDate.lastDay();
			l_addedDate = new Date(
				l_addedDate.getFullYear()
				, l_addedDate.getMonth()
				, l_thisDay
				);
			break;
		}
	
	}

	return l_addedDate;
};
Date.prototype.format = function(p_format) {
	var l_string = this;
	var l_year = this.getFullYear();
	var l_month = this.getMonth() + 1;
	var l_day = this.getDate();
	switch(p_format.toUpperCase()) {
		case "Y": {
			return l_year.toString().substring(2);
			break;
		};
		case 'YY': {
			return l_year.toString().substring(2);
			break;
		};
		case 'YYYY': {
			return l_year.toPaddedString(4);
			break;
		};
		case 'M': {
			return l_month.toString();
			break;
		};
		case 'MM': {
			return l_month.toPaddedString(2);
			break;
		};
		case 'D': {
			return l_day.toString();
			break;
		};
		case 'DD': {
			return l_day.toPaddedString(2);
			break;
		};
		default: {
			p_format = p_format.replace(/(Y{1,4}|[MD]{1,2})([\-\/\.³â¿ùÀÏ\d ])?/g,
				function(matching, p1, p2){
					return (l_string.format(p1) + (!!p2 ? p2 : ""));
			});
			return p_format;
		};
	};
};
Date.prototype.formatTime = function(p_format){
	var l_string = this;
	var l_hour = this.getHours();
	var l_minute = this.getMinutes();
	var l_second = this.getSeconds();

	switch(p_format.toUpperCase()){
		case "H": {
			return l_hour.toString();
			break;
		};
		case "HH": {
			return l_hour.toPaddedString(2);
			break;
		};
		case "M": {
			return l_minute.toString();
			break;
		};
		case "MM": {
			return l_minute.toPaddedString(2);
			break;
		};
		case "S": {
			return l_second.toString();
			break;
		};
		case "SS": {
			return l_second.toPaddedString(2);
			break;
		};
		default: {
			p_format = p_format.replace(/([HMS]{1,2})([\:\-\/\.½ÃºÐÃÊ\d ])?/g,
				function(matching, p1, p2){
					return (l_string.formatTime(p1) + (!!p2 ? p2 : ""));
				});
			return p_format;
		};
	};
};