/**
* @version		$Id: modal.js 5263 2006-10-02 01:25:24Z webImagery $
* @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/

/**
 * JOpenID javascript behavior
 *
 * Used for switching between normal and openid login forms
 *
 * @package		Joomla
 * @since		1.5
 * @version     1.0
 */
var JOpenID = new Class({

	state    : false,
	link     : null,
	switcher : null,

	initialize: function()
	{
		//Create dynamic elements
		var switcher = new Element('a', { 'styles': {'cursor': 'pointer','padding-left':'15px','margin-bottom':'15px','display':'block','width':'119px','color':'#07BBC9','float':'left'},'id': 'openid-link'});
		switcher.inject($('open_id'));

		var link = new Element('a', { 'styles': {'cursor': 'pointer','text-align' : 'left', 'font-size' : 'xx-small','padding-right':'10px','padding-top':'5px','color':'#07BBC9','width':'50px','float':'left'},'class' : ''});
		
		link.inject($('open_home'));

		//Initialise members
		this.switcher = switcher;
		this.link     = link;
		this.state    = Cookie.get('login-openid');
		this.length   = $('form-login-password').getSize().size.y;

		this.switchID(this.state, 0);

		this.switcher.addEvent('click', (function(event) {
			this.state = this.state ^ 1;
			
			this.switchID(this.state, 300);
			$('modlgn_username').value="";
			$('modlgn_passwd').value="";							
			//Cookie.set('login-openid', this.state);
		}).bind(this));
		
		this.link.addEvent('click', (function(event) {
			
			this.state = this.state ^ 0;
			this.switchID(0, 300);
			this.state=0;
			//Cookie.set('login-openid', this.state);
			
			
			
		
			//clearing the information
			$('modlgn_username').addEvent('focus', (function(event) {
					$('modlgn_username').value="";										 
			}).bind(this));
			$('modlgn_passwd').addEvent('focus', (function(event) {
					$('modlgn_passwd').value="";										 
			}).bind(this));
			
			
			
		}).bind(this));
	},

	switchID : function(state, time)
	{
		
		var password = $('form-login-password');
		var username = $('modlgn_username1');

		if(state == 0)
		{
			
			
			username.removeClass('system-openid');
			var text = "<span class='clsopenid' id='nor'> Openid</a>";
			password.effect('height',  {duration: time}).start(0, this.length);
			$('id_normal').style.display="block";
			$('id_open').style.display="none";
			$('modlgn_username1').value="";
			//$('modlgn_username').value="";
			//$('modlgn_passwd').value="";
			$('stat').value=0;
		
			//change the gmail status form and to normal login
			if(this.link.className=="gmail" && this.switcher.innerHTML!='<span class="clsNormal" id="nor">Back to Login</span>')
			{
				
			this.link.setHTML='Back to Login';
			this.link.className='clsNormal';
			this.link.innerHTML='Back to Login';
			$('modlgn_username').value="Enter gmail id";
			$('modlgn_passwd').value="Enter gmail id";
			}
			else
			{
				
			this.link.className='gmail';
			this.link.innerHTML='Login';
			//$('modlgn_username').value="";
			//$('modlgn_passwd').value="";
			}
			
			
		}
		else
		{
			
			$('stat').value=1;
			$('id_normal').style.display="none";
			$('id_open').style.display="block";
			//$('__idselector_button').style.display="block";
			username.addClass('system-openid');
			var text = '<span class="clsNormal" id="nor">Back to Login</span>';
			password.effect('height',  {duration: time}).start(this.length, 0);
			this.link.className='gmail';
			this.link.innerHTML='Login';
			
			
		}

		password.effect('opacity', {duration: time}).start(state,1-state);

		this.switcher.setHTML(text);
		
	}
});

var JOpenID_com = new Class({

	state    : false,
	link     : null,
	switcher : null,

	initialize: function()
	{
		//Create dynamic elements
		var switcher = new Element('a', { 'styles': {'cursor': 'pointer'},'id': 'com-openid-link'});
		switcher.inject($('com-form-login'));

		var link = new Element('a', { 'styles': {'text-align' : 'right','padding-top':'5px', 'display' : 'block', 'font-size' : 'xx-small'}, 'href' : 'http://openid.net'});
		link.inject($('form-login'));

		//Initialise members
		this.switcher = switcher;
		this.link     = link;
		this.state    = Cookie.get('login-openid');
		this.length   = $('com-form-login-password').getSize().size.y;

		this.switchID(this.state, 0);

		this.switcher.addEvent('click', (function(event) {
			this.state = this.state ^ 1;
			this.switchID(this.state, 300);
			Cookie.set('login-openid', this.state);
		}).bind(this));
	},

	switchID : function(state, time)
	{
		var password = $('com-form-login-password');
		var username = $('username');

		if(state == 0)
		{
			username.removeClass('system-openid');
			var text = JLanguage.LOGIN_WITH_OPENID;
			password.effect('height',  {duration: time}).start(0, this.length);
		}
		else
		{
			username.addClass('system-openid');
			var text = JLanguage.NORMAL_LOGIN;
			password.effect('height',  {duration: time}).start(this.length, 0);
		}

		password.effect('opacity', {duration: time}).start(state,1-state);

		this.switcher.setHTML(text);
		this.link.innerHTML(JLanguage.WHAT_IS_OPENID);
	}
});


document.openid = null
document.com_openid = null
window.addEvent('domready', function(){
  if (typeof modlogin != 'undefined' && modlogin == 1) {
  	var openid = new JOpenID();
  	document.openid = openid;
  };
  if (typeof comlogin != 'undefined' && comlogin == 1) {
  	var com_openid = new JOpenID_com();
  	document.com_openid = openid;
  };
});
