$(document).ready(function () {
	$("<div id='overlay'/>").appendTo("body");

	//login click
	$("#login").click(function () {
		$("body").find("#overlay").show();
		$("body").find("#overlay").css({
			"position": "fixed",
			"width": "100%",
			"height": "100%",
			"top": "0",
			"left": "0",
			"background-color": "#000",
			"opacity": "0.5",
			"z-index": "200000000"
		});
		$("body").find(".secure-login").show().css({
			"position": "fixed",
			"top": "50%",
			"left": "50%",
			"margin-left": "-100px",
			"margin-top": "-75px",
			"z-index": "6000000000"
		});
		$("body").css("overflow", "hidden");
		return false;
	});

	//register click
	$("#register").click(function () {
		$("body").find("#overlay").show();
		$("body").find("#overlay").css({
			"position": "fixed",
			"width": "100%",
			"height": "100%",
			"top": "0",
			"left": "0",
			"background-color": "#000",
			"opacity": "0.5",
			"z-index": "200000000"
		});
		$("body").find(".secure-register").show().css({
			"position": "fixed",
			"top": "50%",
			"left": "50%",
			"margin-left": "-150px",
			"margin-top": "-240px",
			"z-index": "6000000000"
		});
		$("body").css("overflow", "hidden");
		return false;
	});


	//reigister json submit
	jQuery('#register-form').submit(function (e) {
		//alert('Handler for .submit()1 called.');
		e.preventDefault();
		jQuery.ajax({
			type: 'POST',
			url: jQuery(this).attr('action'),
			data: jQuery(this).serialize(),
			success: function (msg) {
				//alert("logged in");
				$('.secure-register').hide();
				$("#overlay").hide();

				window.location.reload();
			},
			//end success
			error: function (msg) {
				alert("error");
				// you can do something else
			},
			//end error
		}); //end ajax
	}); //end submit
	//login json submit
	jQuery('#login-form').submit(function (e) {
		//alert('Handler for .submit()1 called.');
		e.preventDefault();
		jQuery.ajax({
			type: 'POST',
			url: jQuery(this).attr('action'),
			data: jQuery(this).serialize(),
			success: function (msg) {
				//alert("logged in");
				$('.secure-login').hide();
				$("#overlay").hide();
				window.location.reload();

			},
			//end success
			error: function (msg) {
				alert("error");
				// you can do something else
			},
			//end error
		}); //end ajax
	}); //end submit
	//overlay click
	$("#overlay").click(function () {
		$(".webapp-confirmation").remove();
		$("body").find(".secure-register").hide();
		$("body").find(".secure-login").hide();
		$("#overlay").hide();
	});
}); // JavaScript Document
