/*
 * This file is part of the w3studioCMS package library and it is distributed 
 * under the LGPL LICENSE Version 2.1. To use this library you must leave 
 * intact this copyright notice.
 *  
 * (c) Since 2007 Giansimon Diblas <giansimon.diblas@w3studiocms.com>
 *  
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

var language; 
var page;
var loginWindow;

// Shows the login form. Retrieve the login form from sfGuard/signinSuccess
function showLoginForm(sActionPath, l, p)
{    
  //W3sWindow = new w3sWindow();
  page = (p != undefined) ? p : 0;
  language = (l != undefined) ? l : 0;
  sAjaxOptions = {asynchronous:true,
                  evalScripts:false, 
                  method:'post',
                  onComplete:function()
                    {
                      $('username').focus();
                    },
                  parameters:'page=' + page +
                             '&lang=' + language};

  W3sWindow = new w3sWindow();
  loginWindow = W3sWindow.openModal(270, 160);
  loginWindow.setAjaxContent(sActionPath, sAjaxOptions);
  /*
  curWindow = W3sWindow.openModal(270, 160);
  curWindow.setAjaxContent(sActionPath, sAjaxOptions);
  W3sWindow = null;*/
  
  return false;
}

// Validates the login data from the executeSignin action of sfGuard module.
function doLogin(sActionPath, sPageUrl)
{
 
  var bHasSigned = true;
  sAjaxOptions = {asynchronous:true,
                  evalScripts:false, 
                  method:'post',
                  onFailure:function()
                    { 
                      bHasSigned = false;
                    },
                  onComplete:function(request, json)
                    {
                     
                      if (bHasSigned){
                        loginWindow.setHTMLContent('<br /><br /><br /><h1>W3StudioCMS IS LOADING<br />Please Wait</h1>');
                        location.href = sPageUrl;
                      }
                    }, 
                  parameters:'lang=' + language +
                             '&page=' + page +
                             '&signin[lang]=' + language +
                             '&signin[page]=' + page +
                             '&signin[username]=' + encodeURIComponent($('signin_username').value) +
                             '&signin[password]=' + encodeURIComponent($('signin_password').value)};
  loginWindow.setAjaxContent(sActionPath, sAjaxOptions);
  
  return false;
}