
function confirmDelete() {
	return confirm("정말 삭제하겠습니까?\n\n삭제된 자료는 다시 회복할수 없습니다.");
}
function isAvailable(obj) {
	if( typeof(obj) != "undefined" && obj != null ) {
		return true;
	}
	return false;
}
function formatInt(str){
	if (typeof str == 'string') {
		if (/^\d+$/.test(str)) {
			//truncate 0 for number less than 10
			while (str.charAt(0)=="0") {
				str = str.substring(1, str.length);
			}
			if ( str == "" ) str = "0";
		} else {
			str = "0";
		}
	}
	return str;
}
function getNodeValueByTagName(node, sTagName) {
	if (node == null) return "";
	if (node.getElementsByTagName(sTagName).length == 0) return "";
	if (node.getElementsByTagName(sTagName)[0].childNodes.length == 0) return "";
	if (node.getElementsByTagName(sTagName)[0].firstChild.nodeType != 3) return "";
	return node.getElementsByTagName(sTagName)[0].firstChild.nodeValue;
}
function ajaxError() {
	alertMessage(TYPE_DANGER, "<p>봉사기에 문제가 발생하였습니다.</p>");
}
function onSubmit4Ajax(frm, fnSuccess, fnError){
	var enctype = $(frm).attr("enctype")?$(frm).attr("enctype"):"application/x-www-form-urlencoded";
	$.ajax({
		type: "POST",
		url: frm.action,
		contentType: enctype,
		data: $(frm).serialize(),
		dataType: "xml",
		success: function(result){
			alertMessageFromXML(result);
			if( fnSuccess ) fnSuccess();
		},
		error: function(err){
			console.log(err);
			ajaxError();
			if( fnError ) fnError();
		}
	});
	return false;
}
function sendData(options) {
	$.ajax({
		type: "POST",
		url: options.url,
		data: options.data,
		dataType: "xml",
		success: function(result){
			alertMessageFromXML(result);
			if( fnSuccess ) fnSuccess();
		},
		error: function(){
			ajaxError();
			if( fnError ) fnError();
		}
	});
}
function openWindow(url, width, height) {
	var nRealWidth, nRealHeight, left=50, top=50;
	if (typeof(width) == "undefined" || width == null) {
		nRealWidth = window.screen.availWidth-100;
	} else {
		nRealWidth = width;
		left = (window.screen.availWidth - width) / 2;
	}
	if (typeof(height) == "undefined" || height == null) {
		nRealHeight = window.screen.availHeight-150;
	} else {
		nRealHeight = height;
		top = (window.screen.availHeight - height) / 2;
	}
	var style_str = "left=" + left + ",top=" + top + ",width="+(nRealWidth)+",height="+(nRealHeight)+",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=1,location=0";
	window.open(url, Math.round(Math.random()*10000), style_str).focus();
}

$().ready(function() {
	$(".navbar-toggle").click(function() {
		var target = "#" + $(this).data("target");
		$(target).toggleClass("in");
	});
	
	subTitle_show();
	$(window).resize(subTitle_show);
	
	$('a.iframe').fancybox({
		type: 'iframe',
		padding: 10
	});

	$('a.iframe.rmenjoy').fancybox({
		type: 'iframe',
		padding: 3
	});
	
	$('a.image').fancybox({
		type: 'image',
		padding: 10
	});
	
});
function subTitle_show() {
	if($(window).outerWidth() <= 767){
		$("span.subTitle").text(" > " + $("ul.catalogue-navi > li.active").text());
		$("span.subTitle").show(); }
	else {
		$("span.subTitle").hide(); }
}

//var punct = /(\~|\!|\@|\#|\^|\&|\*|\(|\)|\_|\-|\+|\'|\"|\:|\;|\<|\>|\.|\,|\\|\||\{|\}|\[|\]|\?|\=|\/|\$)/g;
var ptnProhibitionalChars=/(\"|\'|\<|\>|\/|\(|\)|\\|\+|\$|\%|\:|\;|\?|\@|\,)/g;
var msgProhibitionalChars="[ \" \' < / \\ > ( ) + $ % : ; ? @ , ]";
function validateSearchText(oid, errmsg) {
	var searchText = $(oid).val();
	searchText = $.trim(searchText.replace(ptnProhibitionalChars, ""));
	$(oid).val(searchText);
	$(oid).focus();
	//if (searchText == "") {
		//alert($(errmsg).html());
		//return false;
	//}
	return true;
}
function checkProhibitionalChars(oid, errmsg) {
	var searchText = $(oid).val();
	if (ptnProhibitionalChars.test(searchText)) {
		alert($(errmsg).html() + "\n " + msgProhibitionalChars);
		$(oid).val(searchText.replace(ptnProhibitionalChars, ""));
	}
	$(oid).focus();
	return true;
}

var ptnUnDigitalChars=/[^0-9]/g;
function checkDigitalChars(oMe, errmsg) {
	var recordsperpage = $(oMe).val();
	if (ptnUnDigitalChars.test(recordsperpage)) {
		alert(errmsg);
		$(oMe).val(recordsperpage.replace(ptnUnDigitalChars, ""));
	}
	$(oMe).focus();
	return true;
	
}
function inputRPP(oMe) {
	var label = $(oMe);
	var input =  $("input.RecordsPerPage"); 
	input.attr("type", "text");
	input.position({
		of: label, my: "left middle", at: "left middle", within: label, collision: "none none"
	});
}
function iframe_width_resize(riW) {
	$("div.fancybox-inner").width(riW+5);
	$("div.fancybox-outer").width(riW+5);
	$("div.fancybox-skin").width(riW+5);
	$("div.fancybox-wrap").width(riW+5);
	$("div.fancybox-wrap").position({
		of: $("div.fancybox-overlay"), my: "middle middle", at: "middle middle", 
		within: $("div.fancybox-overlay"), collision: "none none"
	});
}