// JavaScript Document


//
function setPopupPosition() {
	// get screen dimensions
	var sw = $(window).width();
	var sh = $(window).height();
	//
	var w = $("#modal").width();
	var h = $("#modal").height();
	//
	var x = (sw * .5) - (w * .5);
	var y = (sh * .5) - (h * .5);
	//
	$("#modal").css('left',x);
	$("#modal").css('top',y);	
}
//

//
function screenContent() {
	
	// set vars
	var popScreen = $("#homemade-popup-screen");
	var popUp = $("#modal");
	
	// get screen dimensions
	var sw = $(window).width();
	var sh = $(document).height();
	
	//set height, width, and default visibility
	popScreen.width(sw);
	popScreen.height(sh);
	popScreen.css('display','block');
	popScreen.show();
	
	// close screen and pop up if screen is clicked
	$("#homemade-popup-screen").click(function(){
		$("#modal").hide();
		$("#homemade-popup-screen").hide()
	});
	
}
//

///////////////////////
//forgot password stuff
$(document).ready(function(){
	
	$("#homemade-popup-screen").hide();
	$("#modal").hide();
	
	$(".forgot").click(function(){
		screenContent();
		$("#modal").css('display','block');
		$("#modal").show();
		setPopupPosition();
		
		
		
		$("#fireEmail").click(function(){
			var button = $(this);
			button.attr("disabled","disabled");
			var emailString = $("#fe").val();						   
			$.ajax({
					type : 'POST',
					url : "script_forgotpwd.php",
					data : {email : emailString},
					success : function(text) {
						console.log(text);
						//invalid email
						if(text == 0){
							$("#ferror").html("<p>Please enter a valid email</p>");
							button.removeAttr("disabled");
						}
						if(text == 1){
							$("#ferror").html("<p>This email is not recognized in our data base.</p>");
							button.removeAttr("disabled");
							// console.log(jsonError.email);
						}
						if(text == 2){
							$("#modal").html("<p>Thank You</p><p>A temporary password will be e-mailed to you shortly.</p><p style='text-align:center'><a href='index.php'>Done<a></p>");
						}
					}	   
			});
			
		});
	
	
	});

});
//end forgot password
/////////////////////



