//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use

$(document).ready(function(){
	$("#signup_form").submit(function(){
		
		//remove all the class add the messagebox classes and start fading
		//$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		
		//check the username exists or not from ajax
		$.post("http://nycmugged.com/mug/ajax_signup.php",{
			user_name:$('#signupusername').val(),
			password1:$('#password1').val(),
			password2:$('#password2').val(),
			email:$('#signupemail').val()
		} ,function(data) {
			  if(data=='true'){

		 		$("#signup_form .formcontent").html('<div class="response">Your account has been created! You can now log in to NYC Mugged using the fields above. A confirmation has been sent to the email address provided. Good times!</div>')
			  }else{
				if(data == "username taken"){
					$("#signupusername").addClass("invalid");
				}
	          }				
			$("#loginmodal #formresponse").html(data);
	
        });
 		return false; //not to post the  form physically
	});
	
	$("#forgot_form").submit(function(){
		$.post("http://nycmugged.com/mug/ajax_signup.php",{
			reminder:true,
			email:$('#forgotemail').val()
		} ,function(data) {
			  if(data=='true'){
		 		$("#forgotpassword .formcontent").html('<div class="response">A new password has been sent to your email address.</div>').hide().fadeIn();
			  }else{
				$("#forgotpassword .formcontent").html('<div class="response">Something broke. Try again?</div>').hide().fadeIn();
	          }				
        });
 		return false; //not to post the  form physically
	})
});
