﻿//<!--
var form_loaded = false;
jQuery(document).ready(function($) {

	$('#dialogContent').dialog({
		autoOpen: false,
		modal: true,
		bgiframe: true,
		title: "MySql Membership Config Tool",
		width: 800,
		height: 600,
		buttons: {
			'Close': function() { $(this).dialog('close'); resetView(); }
		}
	});

	$('.launch_tool').click(function() {
		//open dialog. 
		$('#dialogContent').dialog('open');

		if (!form_loaded) {
			$.get('/tools/p448.html', function(data) {
				$('#dialogContent').html(data);
				form_loaded = true;

				$("#systemTypeWindows,#systemTypeMono").change(function() {
					checkSystemType($(this));
				});
				//rule for password retrieval and hashed passwords
				$("#passwordFormatHashed").change(function() {
					checkPasswordFormat($(this));
				});
				$("#passwordFormatEncrypted").change(function() {
					checkPasswordFormatEncrypted($(this));
				});
				//rule for password retrieval and hashed passwords
				$("#enablePasswordRetrieval").change(function() {
					if ($(this).attr('checked') && $("#passwordFormatHashed").attr('checked'))
						$(this).attr('checked', false);
				});
				$("#back").click(function() {
					resetView();
				});

				//defaults
				$("#generatedConfig").hide(); //hide result pane
				$("#generatedResultError").hide(); //hide the error message.
				checkSystemType($("#systemTypeMono")); //system type check.
				checkPasswordFormat($("#passwordFormatHashed")); //password format check
			});
		}
		return false;
	});
});

function generatedResultCallback(context) {
	var resp = context.get_response();
	var data = resp.get_object();

	//if it worked, then show it.
	if (data.Success) {
		$("#generatedResult").val(data.Result);
	}
	else {
		$("#generatedResult").hide();
		$("#generatedResultError").fadeIn();
	}
	$("#formView").slideUp();
	$("#generatedConfig").slideDown();
}
function resetView() {
	$("#generatedConfig").hide();
	$("#formView").show();
	$("#generatedResult").show();
	$("#generatedResultError").hide();
}
function checkPasswordFormat(control) {
	if (control.val() == "Hashed")
		$("#enablePasswordRetrieval").attr("checked", false);
}
function checkPasswordFormatEncrypted(control) {
	if (control.attr('checked')) {
		//set the protection to all.
		$("#protection > option:contains('All')").attr('selected', true);
	}
}
function checkSystemType(control) {
	if (control.val() == 'Windows' && control.attr('checked')) {
		//show the hashed encryption option.
		$("#passwordFormatHashed").parent().slideDown();
	}
	else if (control.val() == 'Mono' && control.attr('checked')) {
		//hide the hashed encryption option
		$("#passwordFormatHashed").parent().slideUp();
		if ($("#passwordFormatHashed").attr('checked')) //if hashed checked, changed to clear. 
			$("#passwordFormatClear").attr('checked', true);
	}
}

//-->