$(function() {
//LOGIN SCRIPT
		$( "#dialog-confirm" ).dialog({
			modal: true,
			resizable: false,
			autoOpen:false,
			width:350,
			buttons: {
				Login: function() {
					$.post('processLogin.php',  {txtusername:$("input[name$='txtusername']").val(),txtpass:$("input[name$='txtpass']").val()}, function (data) {
						var array = $.parseJSON(data);
						switch (array.result) {
							case 'err1': case 'err2':
							$('#loginResult-confirm').html('<p style="color:red">' + array.text + '</p>');
							break;
							case 'errActivate': case 'err2':
							$('#loginResult-confirm').html('<p style="color:red">' + array.text + '</p>');
							break;
							case 'ok':
							window.location.reload();
							$( "#dialog-confirm" ).dialog( "close" );
							break;
						}
					});
				},
				Cancel: function(){
					$( "#dialog-confirm" ).dialog( "close" );
				},
				"Create Account": function(){
					location.href="registration.php";
					$( "#dialog-confirm" ).dialog( "close" );
				}
			}
	});
		// Dialog Link
				$('.popuplink').click(function(){
					$('#dialog-confirm').dialog('open');
					return false;
				});
	//POST
		$( "#dialog-post" ).dialog({
					modal: true,
					resizable: false,
					autoOpen:false,
					width:500,
					buttons: {
						Login: function() {
							$.post('processLogin.php',  {txtusername:$("input[name$='txtpost']").val()}, function (data) {
								var array = $.parseJSON(data);
								switch (array.result) {
									case 'err1': case 'err2':
									$('#loginResult').html('<p style="color:red">' + array.text + '</p>');
									break;
									case 'errActivate': case 'err2':
									$('#loginResult').html('<p style="color:red">' + array.text + '</p>');
									break;
									case 'ok':
									window.location.reload();
									$( "#dialog-confirm" ).dialog( "close" );
									break;
								}
							});
						},
						Cancel: function(){
							$( "#dialog-post" ).dialog( "close" );
						},
						Register: function(){
							location.href="registration.php";
							$( "#dialog-post" ).dialog( "close" );
						}
					}
			});
// Dialog Post Comment
				$('#dialog_post').click(function(){
					$('#dialog-post').dialog('open');
					return false;
				});
// LOGOFF DIALOG
			$( "#dialog-logoff" ).dialog({
			modal: true,
			resizable: false,
			autoOpen:false,
			width:350,
			buttons: {
				OK: function(){
					location.href="./";
					$( "#dialog-logoff" ).dialog( "close" );
				}
			}
	});
// LOGOFF Trigger on click
$('#dialog-logoff').dialog('open');	
				//$('#dialog_logoff').click(function(){
				//	$('#dialog-logoff').dialog('open');
				//	return false;
				//});
				
// STATUS DIALOG
			$( "#dialog-status" ).dialog({
			modal: true,
			resizable: false,
			autoOpen:false,
			width:400,
			buttons: {
				
			}
	});
// LOGOFF Trigger on click
$('#dialog-status').dialog('open');	

// Maintenance DIALOG
	$( "#dialog-maintenance" ).dialog({
		modal: true,
		resizable: false,
		autoOpen:false,
		width:400,
		buttons: {
			OK: function(){
				$( "#dialog-maintenance" ).dialog( "close" );
			}
		}
	});
// LOGOFF Trigger on click
	$('#dialog-maintenance').dialog('open');	

//CEU notification
			$( "#dialog-ceu" ).dialog({
			modal: true,
			resizable: false,
			autoOpen:false,
			width:400,
			buttons: {
				OK: function(){
					$( "#dialog-ceu" ).dialog( "close" );
				}
			}
	});
// LOGOFF Trigger on click
$('#dialog-ceu').dialog('open');	

				
// REPLY DIALOG
		$( "#dialog-reply" ).dialog({
		modal: true,
		resizable: false,
		autoOpen:false,
		width:400,
		buttons: {
			Submit: function() {
						$.post('processReply.php',  {txtreply:$("textarea#txtreply").val(),sectionID:$("input[name$='sectionID']").val()}, function (data) {
							var array = $.parseJSON(data);
							switch (array.result) {
								case 'err1':
								$('#submitResult').html('<p style="color:red">' + array.text + '</p>');
								break;
								case 'ok':
								window.location.reload();
								$( "#dialog-reply" ).dialog( "close" );
								break;
							}
						});
			
			},
			Cancel: function(){
				$( "#dialog-reply" ).dialog( "close" );
			}
		}
		});
// Reply Trigger on click
		$('.popupReply').click(function(){
			$('#dialog-reply').dialog('open');
			return false;
		});
});
