$(document).ready(function(){

	// LINK (url)
	$("[class*=btn_link],button[type=button]").bind("click", function(e){

		if ($(this).attr("url")) {
			var v_url = $(this).attr("url");
			if ($(this).attr("target") == "_blank") {
				window.open(v_url);
			}
			else {
				window.location.href = v_url;
			}
		}
		else if ($(this).attr("js")) {
			var v_js = $(this).attr("js");
			eval(v_js);
		}
		else  {
			return;
		}
	});

	// ÅëÇÕ°Ë»ö
	$("#f_sch_tot input[name=sch_tot_k]").bind("keydown", function(e) {
		if (e.keyCode == 13) {
			var v_cate = $("#f_sch_tot input[name=sch_tot_c]").val();
			var v_sort = $("#f_sch_tot input[name=sch_sort_k]").val();
			submit_sch(v_cate, v_sort);
		}
		return;
	});
});

function submit_sch(cate,sort_k) {
	$("#f_sch_tot").attr("method","get");
	$("#f_sch_tot input[name=sch_tot_c]").val(cate);
	$("#f_sch_tot input[name=sch_sort_k]").val(sort_k);
	$("#f_sch_tot").attr("action","/search/search_main.php");
	$("#f_sch_tot").submit();
}

function setPng24(obj)
{
		obj.width = obj.height = 1;
		obj.className = obj.className.replace(/\bpng24\b/i,'');
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
		obj.src = '';
		return '';
}

function putComma(input) {
	var num = input;

	if (num < 0) {
		num *= -1;
		var minus = true
	}else{
		var minus = false
	}

	var dotPos = (num+"").split(".")
	var dotU = dotPos[0]
	var dotD = dotPos[1]
	var commaFlag = dotU.length%3

	if(commaFlag) {
		var out = dotU.substring(0, commaFlag)
		if (dotU.length > 3) out += ","
	}
	else var out = ""

	for (var i=commaFlag; i < dotU.length; i+=3) {
		out += dotU.substring(i, i+3)
		if( i < dotU.length-3) out += ","
	}

	if(minus) out = "-" + out
	if(dotD) return out + "." + dotD
	else return out
}

function getTimeStamp() {
	var d = new Date();

	var s =	leadingZeros(d.getFullYear(), 4) + '-' + leadingZeros(d.getMonth() + 1, 2) + '-' + leadingZeros(d.getDate(), 2) + ' ' + leadingZeros(d.getHours(), 2) + ':' + leadingZeros(d.getMinutes(), 2) + ':' + leadingZeros(d.getSeconds(), 2);

	return s;
}

function leadingZeros(n, digits) {
	var zero = '';
	n = n.toString();

	if (n.length < digits) {
	for (i = 0; i < digits - n.length; i++)
		zero += '0';
	}
	return zero + n;
}

