// JavaScript Document

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17925462-1']);
_gaq.push(['_setDomainName', 'smart-php.com']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

window.___gcfg = {lang: 'th'};

(function() {
	var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
	po.src = 'https://apis.google.com/js/plusone.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

$(function(){
	
	$("button").button();
	
	$(".tooltip").tipTip();
		
	$("#Msg-Dialog").dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			Ok : function(){
				$(this).dialog("close");
			}
		}
	});
	$("#Login-Form").dialog({
		autoOpen: false,
		modal: true,
		buttons: {
			"เข้าสู่ระบบ" : function(){
				var login_user = $("#login_username").val();
				var login_psswd = $("#login_passwd").val();
				var login_remember = $("#login_remember").val();
				$.ajax({
					type: "POST",
					url: "data/handle/login.php",
					data: "user="+login_user+"&passwd="+login_psswd+"&remember="+login_remember,
					success: function(data){
						$("#Login-Form").dialog("close");
						$("#Msg-Dialog-Text").html(data);
						$("#Msg-Dialog").dialog({
							autoOpen: true,
							close: function(event, ui) {
								location.reload();
							}
						});
					}
				});
			},
			"ยกเลิก" : function(){
				$(this).dialog("close");
			}
		}
	});
	$("#Login").click(function(){
		$("#Login-Form").dialog("open");
	});
	
	$("a#Logout").click(function(){
		$("#Msg-Dialog-Text").html('คุณออกจากระบบเรียบร้อยแล้ว');
		$("#Msg-Dialog").dialog({
			autoOpen: true,
			close: function(event, ui) {
				window.location='?op=logout';
			}
		});
	});
		
	ddsmoothmenu.init({
		mainmenuid: "Header-Navigator", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	});
});
