// JavaScript Document
var shortly;

jQuery(document).ready(function() {

	jQuery("#login_form").submit(function() {
		//remove all the class add the messageBox classes and start fading
		jQuery("#msgBox").removeClass().addClass('messageBox').text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
		jQuery.post("/fulfillingthevision/investors/ajax_login.php",{ user_name:jQuery('#username').val(),password:jQuery('#password').val(),rand:Math.random() } ,function(data) {
			if(data=='yes') { //if correct login detail
				jQuery("#msgBox").fadeTo(200,0.1,function() { //start fading the messageBox
					//add message and change the class of the box and start fading
					jQuery(this).html('Logging in.....').addClass('messageBoxOk').fadeTo(900,1,function() {
						//redirect to secure page
						document.location='/fulfillingthevision/investors/secure.php';
					});
				});
			} else {
				jQuery("#msgBox").fadeTo(200,0.1,function() { //start fading the messageBox
					//add message and change the class of the box and start fading
					jQuery(this).html('Wrong Username or Password!').addClass('messageBoxError').fadeTo(900,1);
				});
			}
		});

		shortly = new Date(); 
		shortly.setSeconds(shortly.getSeconds() + 4.5); 
		jQuery('#msgHide').countdown('change', {until: shortly}); 

		return false;//not to post the form physically
	});

	jQuery('#msgHide').countdown({until: shortly, onExpiry: hideMsgBox}); 

	function hideMsgBox() {
		 jQuery("#msgBox").removeClass().addClass('messageBoxHide').fadeOut("slow");
	}

});
