function setCookie(name, value, expires)
{
	var today = new Date();
	today.setDate( today.getDate() + expires );
	document.cookie = name + '=' + escape( value ) + '; path=/; expires=' + today.toGMTString() + ';';
}

function setListCount(key, value)
{
	setCookie(key, value, 365);
	location.reload();
}

function close_layer_popup(obj)
{
	$('.layer_popup_style').has(obj).remove();
}

function strip_tags(input, allowed) {
	allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join('');
	var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
		 commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
	return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1){
		return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
	});
}

function sendMessage(id)
{
	showBox('/message/manager/write/send/' + id, 'iframe', 650);
}

// SNS에 글쓰기
(function($){
	$.fn.snspost = function(opts) {
		var loc = '';
		opts = $.extend({}, {type:'twitter', event:'click', content:'', url:'', summary:'', writer:''}, opts);
		opts.content = encodeURIComponent(opts.content);
    opts.url = encodeURIComponent(opts.url);
		switch(opts.type) {
			case 'me2day' :
				loc = 'http://me2day.net/posts/new?new_post[body]='+opts.content + ' ' + opts.url;
				if (opts.tag) loc += '&new_post[tags]='+encodeURIComponent(opts.tag);
				break;
			case 'facebook' :
				loc = 'http://www.facebook.com/share.php?t='+opts.content+'&u='+opts.url;
				break;
			case 'yozm' :
				loc = 'http://yozm.daum.net/api/popup/prePost?sourceid=54&link=' + opts.url + '&prefix=' + opts.content + '&parameter=' + opts.content;
				break;
			case 'clog' :
				loc = 'http://csp.cyworld.com/bi/bi_recommend_pop.php?url=' + opts.url + '&title_nobase64=' + opts.content + '&summary_nobase64=' + encodeURIComponent(opts.summary) + '&writer=' + encodeURIComponent(opts.writer);
				break;
			case 'delicious' :
				loc = 'http://www.delicious.com/save?v=5&noui&jump=close&url='+ opts.url +'&title='+opts.content;
				break;
			case 'twitter' :
			default:
				loc = 'http://twitter.com/home?status='+opts.content + ' ' + opts.url;
				break;
		}
		this.bind(opts.event, function(){
			window.open(loc);
			return false;
		});
	};
	$.snspost = function(selectors, action) {
		$.each(selectors, function(key,val) {
			$(val).snspost( $.extend({}, action, {type:key}) );
		});
	};
})(jQuery);

