var C_ADD 			= "a" ;
var C_CHANGE 		= "c" ;
var C_DELETE 		= "d" ;
var C_EXPORT 		= "e" ;
var C_GET 			= "g";
var C_LIST 			= "l" ;
var C_NEW 			= "n";
var C_QUERY 		= "q" ;
var C_REPORT 		= "r" ;
var C_UPDATE 		= "u" ;
var C_VIEW 			= "v";
var C_REMOVE 		= "rm";

var	C_OK 			= "0";
var C_INFO 			= "6" ;
var C_INVALID 		= "7";
var C_CONFIRM 		= "8" ;
var C_ERROR 		= "9" ;
var C_DELETE_LOGO 	= "dl" ;

$(document).keypress(
	function(event){
	  if (event.which == '13') {
		event.preventDefault();
	  }
});

$(document).ready(function () {
	showDate('dte');
	setInterval("showDate('dte')", 5000);
	$("input:button").button() ;
	
	var accordopt = {
		active:false ,
		collapsible: true,
		heightStyle: "content"
	} ;

	$("#mainmenu div").bind({
		click: function() { 
			$(this).effect('bounce',{direction:'up',distance:20,mode:'effect',times:3},200);
		}
	}) ;
	
	$("#sidemenu div").bind({
		click: function() { 
			$(this).effect('bounce',{direction:'up',distance:20,mode:'effect',times:3},200);
		}
	}) ;
	$("#mainmenu div").hover(function() {
			$("#sbg-tips").text($(this).children('a').attr('title')) ;
			$("#sbg-tips").css("top", ($(this).offset().top-35) + "px") ;
			$("#sbg-tips").css("left", ($(this).offset().left) + "px");
			$("#sbg-tips").show() ;
		},function(){
		$("#sbg-tips").text('').hide() ;
	});
		
	$("#sidemenu div").hover(function() {
			$("#sbg-tips").text($(this).children('a').attr('title')) ;
			$("#sbg-tips").css("top", ($(this).offset().top-35) + "px") ;
			$("#sbg-tips").css("left", ($(this).offset().left) + "px");
			$("#sbg-tips").show() ;
		},function(){
			$("#sbg-tips").text('').hide() ;
	});

	(function($) {
		$.fn.blank=function() {
			return $.trim($(this).val()).length==0;
		}
		$.fn.validDate = function() {
			if ($(this).val().length != 10) return false ;
			
			var re_date = /^\s*(\d{1,2})\/(\d{1,2})\/(\d{2,4})\s*$/;
			if (!re_date.exec($(this).val())) {
				return false;
			}
			var n_day = Number(re_date.$1),
				n_month = Number(re_date.$2),
				n_year = Number(re_date.$3);
	
			if (n_year < 100)
				n_year += 2000;
			if (n_month < 1 || n_month > 12) {
				return false;
			}
			var d_numdays = new Date(n_year, n_month, 0);
			if (n_day > d_numdays.getDate()) {
				return false;
			}
			return true;
		}
	})(jQuery) ;
}); 

function showPage(page,desc) {
	showProgress("loading " + desc) ;
	var data = { "type": "v"} ;
	var url = "index.pzx?c=" + page + "&d=" + new Date().getTime() ;
	$("#sbg-center-panel").load(url,data,function() {hideProgress();}) ;
}
function onMainResponse(data) {
	hideProgress() ;
	$("#sbg-center-panel").html(data) ;
}
function onLogout() {
	var data = { "type": "o"} ;
	var url = "request.pzx?c=" + login_url  +"&d=" + new Date().getTime() ;		
	callServer(url,"json",data,onLogoutResponse) ;
}
function onLogoutResponse(data) {
	openSite("index.pzx");
}

async function showContent(html) {
	try {
		await $("#sbg-center-panel").html(html);
		return true;
	} catch (error) {
		console.error('Error showing content:', error);
		return false;
	}
}