
<!--
$(document).ready(function () {
	$("form#form-login").submit(function()
	{

		var ctr = "";

		if($('#username').val() == ""){
			ctr = ctr + "Please enter your username.\n";
		}
		
		if($('#password').val() == ""){
			ctr = ctr + "Please enter your password.\n";
		}
		
		if(ctr){
			alert("Following error/s occurred :\n\n"+ctr);
			return false;
		}
		else {
	        //remove all the class add the messagebox classes and start fading
	        $("#login-session").html('&nbsp;<p class="error-message"><img src=\"images/ajax-login-loader.gif\" border=\"0\">&nbsp;Validating...</p>').fadeIn(1000);
	        //check the username exists or not from ajax
	        $.post("jscalls/login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
	        {
	          
	          if(data=='200') //if correct login detail
	          {
	                $("#login-session").fadeTo(200,0.1,function()  //start fading the messagebox
	                {
	                  //add message and change the class of the box and start fading
	                  $(this).html('<p class="p1">Logging in.....</p>').fadeTo(900,1,
	                  function()
	                  {
	                     //redirect to secure page
	                     document.location='index.php';
	                  });
	                });
	          }
	          else if(data=='202' || data=='209'){
	          		$("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
	                {
	                  //add message and change the class of the box and start fading
	                  $(this).html('<p class="error-message">Invalid Username and/or Password...</p>').fadeTo(900,1);
	                });
	          }
	          else if(data=='217'){
	                $("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
	                {
	                  //add message and change the class of the box and start fading
	                  $(this).html('<p class="error-message">Logged in... Please prepare the activation code.</p>').fadeTo(1200,1,
	                  function()
	                  {
	                  	//redirect to secure page and notify for the activation code
	                     document.location='index.php';
	                  });
	          
	                });
	          }
	        });
	        return false;//not to post the  form physically
		}
	});
	
	$("#button-logout").click(function() {
	  $("#login-session").html('&nbsp;<p class="error-message"><img src=\"images/ajax-login-loader.gif\" border=\"0\">&nbsp;Logging out...</p>').fadeTo(1200,0.1,function()
	    {
	     document.location = 'index.php?logout';
	    });
	});
	
	/*$("#password").blur(function()	{
		$("#form-login").trigger('submit');
	});*/
	
	$("form#form-activate-code").submit(function() {
		var ctr = "";
		if($('#code').val() == ""){
			alert("Following error/s occurred :\n\nPlease enter your activation code.");
			return false;
		}
		else {
			//remove all the class add the messagebox classes and start fading
			$("#login-session").html('&nbsp;<p class="error-message"><img src=\"images/ajax-login-loader.gif\" border=\"0\">&nbsp;Validating...</p>').fadeIn(1000);
			
			//check the username exists or not from ajax
	        $.post("jscalls/activate.php",{ code:$('#code').val(),rand:Math.random() } ,function(data)
	        {

	         if(data == '216'){
	         	$("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
                {
					//add message and change the class of the box and start fading
					$(this).html('Code is already Active.').fadeTo(1200,1,
					function()
					{
						//redirect to secure page and notify for the activation code
					 document.location='index.php';
					});
				});
	         }
	         else if(data == '219'){
	         	$("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
                {
                  //add message and change the class of the box and start fading
                  $(this).html('<p class="error-message">Invalid Activation Code.</p>').fadeTo(900,1);
                });
	         }
	         else {
	         	$(this).html('You have successfully registered your Pulse account.').fadeTo(1200,1,
					function()
					{
	         			document.location='index.php';
					});
	         }
	        });
		}
		return false;
	});
	$("form#form-reset-password").submit(function(){
	 error = "";
	 $("#login-session").html('&nbsp;<p class="error-message"><img src=\"images/ajax-login-loader.gif\" border=\"0\">&nbsp;Validating...</p>').fadeIn(1000);
	 $.post("jscalls/reset-password.php",{ user_name:$('#username').val(),rand:Math.random() } ,function(data){
	  $("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
        {
          $(this).html('<p class="error-message">'+data+'</p>').fadeTo(1200,1);
        });
	 });
	 return false;
	});
	
	$("form#form-change-password").submit(function(){
	 error = "";
	 $("#login-session").html('&nbsp;<p class="error-message">&nbsp;Validating...</p>').fadeIn(1000);
	 $.post("jscalls/update-password.php",{ username:$("#username").val(),password:$('#password').val(),confirm_password:$("#password2").val(),rand:Math.random() } ,function(data){
      resData = data.split("|||",2);
      if(resData[0] == 1){
      	$("#login-session").fadeTo(200,0.1,function() //start fading the messagebox
        {
          $(this).html('<p class="p1">'+resData[1]+'</p>').fadeTo(1200,1);
        });
      }
      else {
      	alert(resData[1]);
        $("#login-session").html('');
      }
	 });
	 return false;
	});
});
//-->

