/*
 ****************************************************************************************************
 *
 * COPYRIGHT NOTICE:
 *   (C) Copyright 2009 DealerTitan, Inc. All rights reserved.
 *
 * FILE NAME:
 *   login.js
 *
 * PURPOSE:
 *   Login Javascript functions
 *
 * NOTES:
 *
 * ABBREVIATIONS/ACRONYMS:
 *
 ****************************************************************************************************
*/

//***************************************************************************************************
//Author: Chris Ayers
//Date: 5/7/09
//Function: Process the login attempt
//***************************************************************************************************
function Login_User()
{
  // Get the login data
  var Username = jQuery("#Login_Content #Username").val();
  var Password = jQuery("#Login_Content #Password").val();
  
  if (Username == "")
  {
    jAlert("Please enter your Username");
  }
  else if (Password == "")
  {
    jAlert("Please enter your Password");
  }
  else
  {
    // Toggle the busy notifier
    Toggle_Busy_Notifier();
    
    // Perform the ajax call
    jQuery.post("index.php",
                {
                  Function_Name:"Login_User",
                  Username:Username,
                  Password:Password
                },
                function(data)
                {
                  // Toggle the busy notifier
                  Toggle_Busy_Notifier();
    
                  if (data != Username)
                  {
                    jAlert(data, "Error logging in");
                  }
                  else
                  {
                    window.location.reload();
                  }
                });
  }
}

//***************************************************************************************************
//Author: Chris Ayers
//Date: 5/7/09
//Function: Email the users forgotten password to them
//***************************************************************************************************
function Email_Forgot_Password()
{
  // Get the login data
  var Username = jQuery("#Modal_Content #Username").val();
  
  if (Username == "")
  {
    jAlert("Please enter your Username");
  }
  else
  {
    // Toggle the busy notifier
    Toggle_Busy_Notifier();
    
    // Perform the ajax call
    jQuery.post("index.php",
                {
                  Function_Name:"Email_Forgot_Password",
                  Username:Username
                },
                function(data)
                {
                  // Toggle the busy notifier
                  Toggle_Busy_Notifier();
    
                  if (data != "")
                  {
                    jAlert(data, "Error Emailing Password");
                  }
                  else
                  {
                    jAlert("Your password has been sent to your email.","Password Sent",
                           function()
                           {
                            jQuery.modal.close();
                           });
                  }
                });
  }
}
