/*
** Evonux 2005-2008
** Evonux JavaScript Tools (EJST) - local version
**
** tested: IE 6.0/7.0, Firefox 2.0, Safari 2.0/3.0, Konqueror
**         Mac OS X, Windows XP/Vista, Linux
**
** All rights reserved
*/

if (Evonux && Evonux.IncludeRegister('THIS'))
  Evonux.Exit();

if (!Evonux) Evonux = {};

Evonux.Page = new Class({
    categories_menu_height: 342, // px
    cat_menu_slide_lg: 72,
    ptab_id: new Array('product-description', 'product-use-advice', 'product-precaution-for-use',
		       'product-composition', 'product-guides-and-files', 'product-lilian-opinion',
		       'product-users-opinions', 'product-give-opinion', 'product-tell-a-friend'),
    pmenu_id: new Array('menu-product-description', 'menu-product-use-advice', 'menu-product-precaution-for-use',
			'menu-product-composition', 'menu-product-guides-and-files', 'menu-product-users-opinions',
			'menu-product-lilian-opinion', 'menu-product-give-opinion', 'menu-product-tell-a-friend'),
    banner: null,
    banner_rank: 0,
    banner_duration: 7500, // 4500
    area: null,

    /*
    ** Inits complex display
    */
    initialize: function()
    {
	//Evonux.Text.HeadersToImg({node:$('content')});

	/*
	// Area switcher
	this.AreasInit();
	*/
	// Country switcher
	this.CountriesInit();

	// Categories menu
	if ($('cat_list'))
	{
	  var up = $('cat_list_up'),
	      down = $('cat_list_down');
	  up.addEvent('click', this.CatBrowseUp.bind(this));
	  down.addEvent('click', this.CatBrowseDown.bind(this));
	  //  - if a category is opened, scrolls to this category
	  var op_cat = $('categories').getElement('ul.list li.open');
	  if (op_cat)
	  {
	      var ul = $('categories').getElement('ul.list'),
		  ul_top = ul.getPosition().y,
		  li_top = op_cat.getPosition().y,
		  anim_ul = new Fx.Styles(ul, {wait:false, duration: 300});
	      anim_ul.start({
		  'margin-top': - li_top + ul_top + 20
	      });
	  }
	}
	// Top menu
	//  - centers menu (here we give <ul> a width so that centering is effective)
	var m = $('top_menu'), li = m.getElements('li'), w = 0;
	for (var k = 0; k < li.length; k++)
	  w += parseInt(li[k].getStyle('width'));
	m.setStyle('width', w);
	// Product
	this.Init();
	// Banners
	this.BannersInit();
	// Category
	this.CategoryInit();
	// Search
	this.SearchInit();
	// Cart
	if ($('cart-end-content')) this.CartInit();
	// User
	if ($('user-data')) this.UserDataInit();

	// Cart step #4
	if ($('human-post')) this.CartStep4Init();
	// Cart step #5
	if ($('cart-last')) this.CartStep5Init();
    },

    /*
    ** Modifies some styles for bad reacting browsers
    */
    /*
    BrowserAdjust: function()
    {
	if (window.webkit) // WebKit
	{
	  new Asset.css(Evonux.CSS_DIR +'/webkit.css');
	}
    },
    */
    /*
    ** Adjusts size of elements that are contained inside main HTML skeleton
    */
    Resize: function()
    {
	//this.AreaFirst();
    },
    /*
    ** Builds objects' interactivity for standard page
    */
    Init: function()
    {
	/*
	if ($('catalog-menu')) Evonux.Text.ToImg({node:$('catalog-menu').getElements('strong'), font:0});
	if ($('catalog')) this.CatalogInit();
	*/
	this.ProductInit();
	// Login (if not logged in)
	if ($('login_button') && $('login-box'))
	{
	  var a = $('login_button').getElement('a');
	  a.addEvent('click', this.ShowLoginBox.bind(this));
	}
    },

    /*
    ** Builds objects' interactivity for catalog page
    */
    CartInit: function()
    {
	Evonux.cart = new Evonux.Cart();
    },
    /*
    ** Makes search input interactive
    */
    SearchInit: function()
    {
	var s = $('q');
	if (!s) return false;
	s.addEvent('click', this.SearchContent.bind(this));
	s.addEvent('blur', this.SearchReset.bind(this));
    },
    SearchContent: function(e)
    {
	document.title += ' - '+ $tc1('to_search');
	var s = $('q');
	if (s.getAttribute('value') == $tc1('to_search'))
	{
	  s.setAttribute('value', '');
	  s.removeClass('out');
	}
    },
    SearchReset: function(e)
    {
	var s = $('q');
	if (s.getAttribute('value') == '')
	{
	  s.setAttribute('value', $tc1('to_search'));
	  s.addClass('out');
	}
    },

    /*
    ** Makes countries switching possible
    */
    CountriesInit: function()
    {
	var country_current = $('area-this-country'),
	    countries = $('area-countries');
	country_current.addEvent('click', this.CountriesSwitch.bind(this));
	countries.addEvent('mouseleave', this.CountriesSwitch.bind(this));
    },
    CountriesSwitch: function()
    {
	var country_current = $('area-this-country'),
	    countries = $('area-countries'),
	    show = country_current.getStyle('display') != 'none' ? false : true;
	country_current.setStyle('display', show ? 'block' : 'none');
	countries.setStyle('display', show ? 'none' : 'block');
    },

    /*
    ** Makes areas switching possible
    */
    /*
    AreasInit: function()
    {
	if ($('first-area'))
	  this.AreaFirst();
	this.area = $('lang').getElements('li');
	for (var k = 0; k < this.area.length; k++)
	  this.area[k].getElement('img').addEvent('click', this.AreaSwitch.bind(this));
    },
    AreaSwitch: function(e)
    {
	var e = new Event(e),
	    li = e.target;
	while (li.getTag() != 'li') li = li.getParent();
	var d = li.getElement('div.area-choice'),
	    d_on = d.evx_disp;
	this.HideAreasSwitches();
	if (!d_on) {d.setStyle('display', 'block'); d.evx_disp = true;}
	else {d.setStyle('display', 'none'); d.evx_disp = false;}
    },
    HideAreasSwitches: function(e)
    {
	for (var k = 0; k < this.area.length; k++)
	  this.area[k].getElement('div.area-choice').setStyle('display', 'none').evx_disp = false;
    },
    */
    /*
    ** Asks user to choose area
    ** Here this method will mask content to force area selection
    */
    /*
    AreaFirst: function()
    {
	if (!$('first-area')) return false;
	var bg = $('first-area').getElement('div.bg'),
	    text = $('first-area').getElement('div.text'),
	    w = window.getSize();
	bg.setStyles({'display': 'block',
		      'width': w.scrollSize.x - 1,
		      'height': w.scrollSize.y - 1,
		      'opacity': 0.85});
	text.setStyles({'display': 'block',
		        'margin-left': Math.floor((w.size.x - parseInt(text.getStyle('width'))) / 2),
		        'margin-top': Math.floor((w.size.y - parseInt(text.getStyle('height'))) / 3)
		       });
    },
    */

    /*
    ** Launches banners cycle
    */
    BannersInit: function()
    {
	this.banner = $('banner').getChildren();
	for (var k = 0; k < this.banner.length; k++)
	  this.banner[k].setStyles({
	      'position': 'absolute',
	      'width': 475,
	      'height': 91,
	      'margin-top': (k > 0 ? 91 : 0)
	  });
	if (this.banner.length <= 1) return false;
	this.banner_rank = 0;
	setTimeout(this.NextBanner.bind(this), this.banner_duration);
    },
    /*
    ** Displays next banner
    */
    NextBanner: function()
    {
	var next_rank = (this.banner_rank < this.banner.length - 1 ? this.banner_rank + 1 : 0),
	    cur_ban = this.banner[this.banner_rank],
	    next_ban = this.banner[next_rank],
	    anim_cur = new Fx.Styles(cur_ban, {wait:false, duration: 500}),
	    anim_next = new Fx.Styles(next_ban, {wait:false, duration: 500});
	anim_cur.start({
	    'margin-top': [0,-91]
	});
	anim_next.start({
	    'margin-top': [91,0]
	});

	this.banner_rank = next_rank;
	setTimeout(this.NextBanner.bind(this), this.banner_duration);
    },

    /*
    ** Makes categories menu slide up
    */
    CatBrowseUp: function(e)
    {
	var ul = $('categories').getElement('ul.list'),
	    ul_size = ul.getSize(),
	    ul_margintop = parseInt(ul.getStyle('margin-top'));

	if (ul_size.size.y < this.categories_menu_height) return false;
	if (ul_margintop >= 0) return false;
	var anim_ul = new Fx.Styles(ul, {wait:false, duration: 300});
	anim_ul.start({
	    'margin-top': (-ul_margintop < this.cat_menu_slide_lg ? 0 : ul_margintop + this.cat_menu_slide_lg)
	});
    },
    /*
    ** Makes categories menu slide down
    */
    CatBrowseDown: function(e)
    {
	var ul = $('categories').getElement('ul.list'),
	    ul_size = ul.getSize(),
	    ul_margintop = parseInt(ul.getStyle('margin-top'));

	if (ul_size.size.y < this.categories_menu_height) return false;
	if (this.categories_menu_height - ul_margintop >= ul_size.size.y) return false;
	var anim_ul = new Fx.Styles(ul, {wait:false, duration: 300});
	anim_ul.start({
	    'margin-top': ul_margintop - this.cat_menu_slide_lg
	});
    },


    /*
    ** Show/Hide login box
    */
    ShowLoginBox: function()
    {
	var box = $('login-box'),
	    anim_box = new Fx.Styles(box, {wait:false, duration: 500});
	if (!box) return false;
	// Show
	if (parseInt(box.getStyle('height')) < 54)
	{
	  box.setStyle('padding', 6);
	  anim_box.start({
	      'height': 54,
	      'margin-top': [59, 5]
	  });
	}
	// Hide
	else
	{
	  box.setStyles.delay(550, box, {'padding': 0});
	  anim_box.start({
	      'height': 0,
	      'margin-top': [5, 59]
	  });
	}
    },

    /*
    ** Builds product's interactivity
    */
    ProductInit: function()
    {
	var prod = $('product_panel');
	if (!prod) return false;

	// MENU
	var li_menu = prod.getElements('div.center div.infos ul.contents li');
	//  - Description
	$('menu-product-description').addEvent('click', this.ShowProductDescription.bind(this));
	//$('product-description').setStyle('display', 'none'); // Not done because it is default display
	//  - Use advice
	$('menu-product-use-advice').addEvent('click', this.ShowProductUseAdvice.bind(this));
	$('product-use-advice').setStyle('display', 'none');
	//  - Precaution for use
	$('menu-product-precaution-for-use').addEvent('click', this.ShowProductPrecautionForUse.bind(this));
	$('product-precaution-for-use').setStyle('display', 'none');
	//  - Composition
	$('menu-product-composition').addEvent('click', this.ShowProductComposition.bind(this));
	$('product-composition').setStyle('display', 'none');
	//  - About brand
	// done
	//  - Guides and files
	if ($('menu-product-guides-and-files'))
	{
	  $('menu-product-guides-and-files').addEvent('click', this.ShowProductGuidesAndFiles.bind(this));
	  $('product-guides-and-files').setStyle('display', 'none');
	}
	//  - Lilian opinion
	if ($('menu-product-lilian-opinion'))
	{
	  $('menu-product-lilian-opinion').addEvent('click', this.ShowProductLilianOpinion.bind(this));
	  $('product-lilian-opinion').setStyle('display', 'none');
	}
	//  - Give your opinion
	$('menu-product-give-opinion').addEvent('click', this.ShowProductGiveOpinion.bind(this));
	$('product-give-opinion').setStyle('display', 'none');
	//  - Users opinion
	$('menu-product-users-opinions').addEvent('click', this.ShowProductUsersOpinions.bind(this));
	$('product-users-opinions').setStyle('display', 'none');
	//  - Tell a friend
	$('menu-product-tell-a-friend').addEvent('click', this.ShowTellFriend.bind(this));
	$('product-tell-a-friend').setStyle('display', 'none');

	// OPINION NOTE INTERACTIVE
	var pgo = $('product-give-opinion'),
	    td = pgo.getElements('td'),
	    note = td[0].getElements('input');
	this.pgo_td = td;
	for (var k = 0; k < note.length; k++)
	  note[k].addEvent('click', this.SwitchNoteStars.bind(this));

	// IMAGE ZOOM
	var zoom_menu = prod.getElement('div.left div.product_pic a.zoom'),
	    zoom_img = $('zoomed-img');
	if (zoom_menu && zoom_img.getElement('img.big'))
	{
	  zoom_menu.addEvent('click', this.ProductZoomImage.bind(this));
	  zoom_img.addEvent('click', this.ProductCloseZoomImage.bind(this));
	  zoom_img.setStyle('display', 'none');
	}

	// CART QUANTITY
	var plus = prod.getElement('div.center div.qty div.plus'),
	    minus = prod.getElement('div.center div.qty div.minus');
	plus.addEvent('click', this.QtyPlus1.bind(this));
	minus.addEvent('click', this.QtyMinus1.bind(this));
    },

    /*
    ** Updates visual note according to pressed star
    */
    SwitchNoteStars: function(e)
    {
	var e = new Event(e),
	    i = e.target,
	    note = this.pgo_td[0].getElements('input');
	for (var k = 0; k < note.length; k++)
	{
	  if (i == note[k])
	  {
	    this.pgo_td[0].className = 'notes n'+ (k+1);
	    break;
	  }
	}
    },
    /*
    ** Sends user's opinion to server
    */
    SendOpinion: function(e)
    {
	// Checks that note > 0
	var note = $('product-give-opinion').getElement('form').note,
	    note_value = 0;
	for (var k = 0; k < note.length; k++)
	  if (note[k].checked) note_value = note[k].value;
	if (note_value <= 0)
	{
	  alert($t('note_is_empty'));
	  return false;
	}
	// Checks that msg is not empty
	if (!$('product-give-opinion').getElement('textarea').value)
	{
	  alert($t('msg_is_empty'));
	  return false;
	}
	$('product-give-opinion').getElement('form').send({onComplete: this.SendOpinion_do.bind(this)});
    },
    SendOpinion_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	alert(xml['msg'][0]);
    },
    /*
    ** Sends an email to given email (tell a friend)
    */
    TellFriend: function(e)
    {
	// Checks that note > 0
	var form = $('product-tell-a-friend').getElement('form');
	// Checks that fields are not empty
	if (!form.sender_name.value.trim() ||
	    !form.friend_email.value.trim())
	{
	  alert($t('please_fill_all_fields'));
	  return false;
	}
	form.send({onComplete: this.TellFriend_do.bind(this)});
    },
    TellFriend_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	alert(xml['msg'][0]);
    },

    /*
    ** Sends user's message board message
    */
    SendMB: function(e)
    {
	// Checks that msg is not empty
	if (!$('messageboard_form').getElement('textarea').value)
	{
	  alert($t('msg_is_empty'));
	  return false;
	}
	$('messageboard_form').send({onComplete: this.SendMB_do.bind(this)});
    },
    SendMB_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	alert(xml['msg'][0]);
    },
    DeleteMB: function(oid)
    {
	if (!confirm($tc1('are_you_sure_delete'))) return false;
	var ajax_option = {
	    method: 'get',
	    onSuccess: this.DeleteMB_do.bind(this),
	    onFailure: this.Error
	};
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&a=mboard_delete&oid='+ oid +'', ajax_option).request();
    },
    DeleteMB_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	alert(xml['msg'][0]);
    },

    /*
    ** Displays "description" tab and hides other ones
    */
    ShowProductDescription: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-description').setStyle('display', 'block');
	$('menu-product-description').addClass('on');
    },
    /*
    ** Displays "use-advice" tab and hides other ones
    */
    ShowProductUseAdvice: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-use-advice').setStyle('display', 'block');
	$('menu-product-use-advice').addClass('on');
    },
    /*
    ** Displays "precaution-for-use" tab and hides other ones
    */
    ShowProductPrecautionForUse: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-precaution-for-use').setStyle('display', 'block');
	$('menu-product-precaution-for-use').addClass('on');
    },
    /*
    ** Displays "composition" tab and hides other ones
    */
    ShowProductComposition: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-composition').setStyle('display', 'block');
	$('menu-product-composition').addClass('on');
    },
    /*
    ** Displays "composition" tab and hides other ones
    */
    ShowProductGuidesAndFiles: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-guides-and-files').setStyle('display', 'block');
	$('menu-product-guides-and-files').addClass('on');
    },
    /*
    ** Displays "lilian-opinion" tab and hides other ones
    */
    ShowProductLilianOpinion: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-lilian-opinion').setStyle('display', 'block');
	$('menu-product-lilian-opinion').addClass('on');
    },
    /*
    ** Displays "users-opinions" tab and hides other ones
    */
    ShowProductUsersOpinions: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-users-opinions').setStyle('display', 'block');
	$('menu-product-users-opinions').addClass('on');
    },
    /*
    ** Displays "give-opinion" tab and hides other ones
    */
    ShowProductGiveOpinion: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-give-opinion').setStyle('display', 'block');
	$('menu-product-give-opinion').addClass('on');
    },
    /*
    ** Displays "tell-a-friend" tab and hides other ones
    */
    ShowTellFriend: function(e)
    {
	var e = new Event(e);
	e.stop();
	this.HideProductTabs(e);
	$('product-tell-a-friend').setStyle('display', 'block');
	$('menu-product-tell-a-friend').addClass('on');
    },
    /*
    ** Hides all tabs
    */
    HideProductTabs: function(e)
    {
	for (var k = 0; k < this.ptab_id.length; k++)
	{
	  if ($(this.ptab_id[k]))
	    $(this.ptab_id[k]).setStyle('display', 'none');
	}
	for (var k = 0; k < this.pmenu_id.length; k++)
	{
	  if ($(this.pmenu_id[k]))
	    $(this.pmenu_id[k]).removeClass('on');
	}
	// pmenu_id
    },

    /*
    ** Shows larger image for product
    */
    ProductZoomImage: function(e)
    {
	var img_wrap = $('zoomed-img'),
	    img = img_wrap.getElement('img.big'),
	    img_wrap_bg = $('zoomed-img-bg'),
	    w = window.getSize(),
	    anim_iwbg = new Fx.Styles(img_wrap_bg, {wait:false, duration: 500}),
	    anim_img = new Fx.Styles(img, {wait:false, duration: 300});
	img_wrap_bg.setStyles({'display': 'block',
			       'width': w.scrollSize.x - 1,
			       'height': w.scrollSize.y - 1,
			       'opacity': 0});
	img_wrap.setStyles({'display': 'block',
			    'opacity': 0});
	img.setStyles({
	    'width': 'auto',
	    'height': 'auto'
	});

	var i = {'width': img.offsetWidth, 'height': img.offsetHeight};
	img.setStyles({
	    'opacity': 1,
	    'width': i.width,
	    'height': 0
	});
	img_wrap.setStyles({'opacity': 1,
			    'top': Math.floor((w.scrollSize.y - i.height) / 2),
		            'left': Math.floor((w.scrollSize.x - i.width) / 2)});
	anim_iwbg.start({
	    'opacity': 0.85
	});
	anim_img.start.delay(500, anim_img, {
	    'height': i.height,
	    'margin-top': [Math.floor(i.height / 2), 0]
	});
    },
    ProductCloseZoomImage: function(e)
    {
	var img_wrap = $('zoomed-img'),
	    img = img_wrap.getElement('img.big'),
	    img_wrap_bg = $('zoomed-img-bg'),
	    i = {'width': img.offsetWidth, 'height': img.offsetHeight};
	    anim_iwbg = new Fx.Styles(img_wrap_bg, {wait:false, duration: 500}),
	    anim_img = new Fx.Styles(img, {wait:false, duration: 300});
	img_wrap.setStyles.delay(300, img_wrap, {'display': 'none'});
	anim_img.start({
	    'height': [i.height, 0],
	    'margin-top': [0, Math.floor(i.height / 2)]
	});
	anim_iwbg.start.delay(300, anim_img, {
	    'opacity': 0
	});
	setTimeout(function() {img_wrap_bg.setStyle('display', 'none')}, 500);
    },

    /*
    ** Enables category local interactivity
    */
    CategoryInit: function(e)
    {
	var cat = $('category_panel');
	if (!cat) return false;

	var bs_button = cat.getElement('div.category a.bestof'),
	    bs_h1 = $('category_best_sellers').getElement('h1');
	bs_button.addEvent('click', this.CategoryBestSellersShow.bind(this));
	bs_h1.addEvent('click', this.CategoryBestSellersHide.bind(this));

	// Checks if best sellers have to be displayed first
	if (window.location.hash == '#best-sellers')
	  this.CategoryBestSellersShow();
    },
    /*
    ** Shows best sellers and hide category presentation
    */
    CategoryBestSellersShow: function(e)
    {
	var cat = $('category_panel'),
	    cat_bs = $('category_best_sellers');
	cat.setStyle('display', 'none');
	cat_bs.setStyle('display', 'block');
	// Sort form
	$('catsort').setAttribute('action', $('catsort').getAttribute('action') +'#best-sellers');
    },
    /*
    ** Shows best sellers and hide category presentation
    */
    CategoryBestSellersHide: function(e)
    {
	var cat = $('category_panel'),
	    cat_bs = $('category_best_sellers');
	cat.setStyle('display', 'block');
	cat_bs.setStyle('display', 'none');
    },

    /*
    ** Builds objects' interactivity for catalog page
    */
    CatalogInit: function()
    {
	Evonux.catalog = new Evonux.Catalog();
    },
    /*
    ** Builds objects' interactivity for catalog page
    */
    CartInit: function()
    {
	Evonux.cart = new Evonux.Cart();
    },

    /*
    ** Asks server for content
    ** option:
    **  - oid
    **  - a
    */
    Open: function(option)
    {
	if (!option) return false;
	// Checks options
	//  - get
	var query_string = {};
	if (option.a) query_string.a = option.a;
	if (option.oid) query_string.oid = option.oid;
	var ajax_option = {
	    method: 'get',
	    onSuccess: option.onSuccess || this.Open_do,
	    onFailure: this.Error
	};
	//  - post
	if (option.post)
	{
	  ajax_option.method = 'post';
	  // Adds post parameters
	  ajax_option.data = option.post;
	}
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&'+ Object.toQueryString(query_string), ajax_option).request();
    },

    /*
    ** Executes from server's answer
    */
    Open_do: function(text, xml)
    {
	alert('regular Open_do: '+ text);
    },

    /*
    ** Sends contact form
    */
    ContactFormSend: function()
    {
	var form = $('contactform');
	form.send({
	    onSuccess: this.ContactFormSend_do.bind(this)
	});
	return false;
    },
    ContactFormSend_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	alert(xml['msg'][0]);
    },

    /*
    ** Increments cart quantity by 1
    */
    QtyPlus1: function(e)
    {
	var qty = $('product_panel').getElement('div.center div.qty div.value');
	qty.setText(parseInt(qty.getText()) + 1);
    },
    /*
    ** Decrements cart quantity by 1
    */
    QtyMinus1: function(e)
    {
	var qty = $('product_panel').getElement('div.center div.qty div.value');
	qty.setText(parseInt(qty.getText()) > 1 ? parseInt(qty.getText()) - 1  : 1);
    },
    /*
    ** Adds product with oid to cart
    */
    AddToCart: function(oid, qty_input, empty)
    {
	// Asks server to add current element to cart
	var qty = ($('product_panel') && !qty_input ? $('product_panel').getElement('div.center div.qty div.value') : (qty_input ? qty_input : 1)),
	    query_string = {
	      'a': 'cart',
	      'do': 'add',
	      'oid': oid,
	      'quantity': qty_input ? qty_input : (qty ? qty.getText() : 1),
	      'empty': (empty ? 1 : 0)
	    },
	    ajax_option = {
	      method: 'get',
	      onSuccess: this.AddToCart_do.bind(this),
	      onFailure: evx_page.Error
	    };
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&lang='+ Evonux.LANG +'&'+ Object.toQueryString(query_string), ajax_option).request();
	return false;
    },
    AddToCart_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	    
	// Checks that adding is accepted by server
	if (xml['state'][0] == '0')
	{
	  alert(xml['msg'][0]);
	  return false;
	}
	// Cart is heterogeneous
	else if (xml['state'][0] == '-1')
	{
	  if (confirm($tc1('heterogeneous_cart_ask_empty')))
	    this.AddToCart(xml['oid'][0], xml['qty'][0], true);
	  return false;
	}

	var cart_content = $('cart_content'),
	    cart_details = cart_content.getElement('div.details');
	// Updates cart's content
	cart_details.setHTML(xml['cart_html'][0]);
	alert($tc1('product_added_into_cart_successfully'));
	return true;
    },

    /*
    ** Adds product with oid to subscription cart
    */
    AddToSubscription: function(oid, qty_input, empty)
    {
	// Asks server to add current element to cart
	var qty = ($('product_panel') && !qty_input ? $('product_panel').getElement('div.center div.qty div.value') : (qty_input ? qty_input : 1)),
	    query_string = {
	      'a': 'cart_sub',
	      'do': 'add',
	      'oid': oid,
	      'quantity': qty_input ? qty_input : (qty ? qty.getText() : 1),
	      'empty': (empty ? 1 : 0)
	    },
	    ajax_option = {
	      method: 'get',
	      onSuccess: this.AddToSubscription_do.bind(this),
	      onFailure: evx_page.Error
	    };
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&'+ Object.toQueryString(query_string), ajax_option).request();
	return false;
    },
    AddToSubscription_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	    
	// Checks that adding is accepted by server
	if (xml['state'][0] == '0')
	{
	  alert(xml['msg'][0]);
	  return false;
	}
	// Cart is heterogeneous
	else if (xml['state'][0] == '-1')
	{
	  if (confirm($tc1('heterogeneous_cart_ask_empty')))
	    this.AddToSubscription(xml['oid'][0], xml['qty'][0], true);
	  return false;
	}

	var cart_content = $('cart_content'),
	    cart_details = cart_content.getElement('div.details');
	// Updates cart's content
	cart_details.setHTML(xml['cart_html'][0]);
	alert($tc1('product_added_into_subscription_successfully'));
	return true;
    },

    /*
    ** Adds product with oid to lightbox
    */
    AddProductToLightbox: function(product_oid)
    {
	if (!product_oid) return false;

	// Asks server to add current element into lightbox
	var query_string = {
	      'a': 'userlightboxaddproduct',
	      'oid': product_oid
	    },
	    ajax_option = {
	      method: 'get',
	      onSuccess: this.AddProductToLightbox_do.bind(this),
	      onFailure: evx_page.Error
	    };
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&'+ Object.toQueryString(query_string), ajax_option).request();
	return false;
    },
    AddProductToLightbox_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	    
	// Checks that adding is accepted by server
	if (xml['state'][0] == '0')
	{
	  if (xml['msg']) alert(xml['msg'][0]);
	  return false;
	}
	else
	  alert($tc1('product_added_into_lightbox_ok'));
    },
    /*
    ** Removes product with oid from lightbox
    */
    DeleteProductFromLightbox: function(product_oid)
    {
	if (!product_oid) return false;

	// Asks server to add current element into lightbox
	var query_string = {
	      'a': 'userlightboxdeleteproduct',
	      'oid': product_oid
	    },
	    ajax_option = {
	      method: 'get',
	      onSuccess: this.DeleteProductFromLightbox_do.bind(this),
	      onFailure: evx_page.Error
	    };
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&'+ Object.toQueryString(query_string), ajax_option).request();
	return false;
    },
    DeleteProductFromLightbox_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	    
	// Checks that adding is accepted by server
	if (xml['state'][0] == '0')
	{
	  if (xml['msg']) alert(xml['msg'][0]);
	  return false;
	}
	else if (xml['product_oid'])
	{
	  var lb_pr = $('lightbox_sel'+ xml['product_oid'][0]);
	  if (lb_pr) lb_pr.remove();
	}
    },

    /*
    ** Submits Cart's step 4 telling server that a refresh has
    ** to occur and prevent step 5 from being loaded
    */
    SubmitStep4: function()
    {
	$('cart-recap').setAttribute('action', $('cart-recap').getAttribute('action') + '?re=1');
	$('cart-recap').submit();
    },

    /*
    ** Launch a timer to prevent user from paying a deleted invoice
    ** When this timer has finished, recap is replaced with a 'session ended' warning
    */
    CartStep5Init: function()
    {
	setTimeout(this.CartStep5SessionEnd.bind(this), Evonux.CART_LENGTH * 1000);
    },
    CartStep5SessionEnd: function()
    {
	$('cart-last').setHTML($t('cart_step5_session_end_speech'));
    },

    /*
    ** Makes addresses fields listen to copy invoice data to delivery data (if fields empty)
    */
    CartStep4Init: function()
    {
	var form = $('cart-recap'),
	    i1 = form.getElements('div.cart-address-invoice table input'),
	    i2 = form.getElements('div.cart-address-delivery table input');
	for (var k = 0; k < i1.length; k++)
	{
	  i1[k].evonux_same_input = i2[k]; // records associated field
	  i1[k].addEvent('click', this.CartStep4CopyField.bind(this));
	  i1[k].addEvent('keyup', this.CartStep4CopyField.bind(this));
	  // Checks if can replace content
	  i2[k].evonux_accept_replace = i2[k].value ? false : true;
	  i2[k].addEvent('click', this.CartStep4CheckEmpty.bind(this));
	  i2[k].addEvent('keyup', this.CartStep4CheckEmpty.bind(this));
	}
    },
    CartStep4CopyField: function(e)
    {
	var e  = new Event(e),
	    i = e.target;
	if (i.evonux_same_input.evonux_accept_replace)
	  i.evonux_same_input.value = i.value;
    },
    CartStep4CheckEmpty: function(e)
    {
	var e  = new Event(e),
	    i = e.target;
	i.evonux_accept_replace = i.value ? false : true;
    },

    /*
    ** Inits user data special page tabs/content interactivity
    */
    UserDataInit: function()
    {
	// TABS
	var tab = $('user-data').getElements('ul.menu li'),
	    item = $('user-data').getElements('div.item');
	for (var k = 0; k < tab.length; k++)
	{
	  tab[k].evonux = {rank: k, item: item[k]};
	  tab[k].addEvent('click', this.UserDataSwitchTab.bind(this));
	}

	// ADDRESSES
	var form = $('user-addresses').getElements('form'),
	    del;
	for (var k = 0; k < form.length; k++)
	{
	  form[k].addEvent('submit', this.UserDataAddressUpdate.bind(this));
	  del = form[k].getElement('button');
	  del.addEvent('click', this.UserDataAddressDelete.bind(this));
	}
	
	// SPONSORING
	form = $('user-sponsor');
	form.addEvent('submit', this.UserDataSponsor.bind(this));

	// USER EVENTS
	form = $('user-event-add');
	form.addEvent('submit', this.UserDataEvent.bind(this));
	//  - list of events
	this.UserDataEventLoad();
    },
    UserDataSwitchTab: function(e)
    {
	// Removes all items
	var item = $('user-data').getElements('div.item');
	for (var k = 0; k < item.length; k++)
	  item[k].addClass('off');
	// Desactivates all tabs
	var tab = $('user-data').getElements('ul.menu li');
	for (var k = 0; k < tab.length; k++)
	  tab[k].removeClass('on');

	// Activates asked tab/content
	var e = new Event(e),
	    li = e.target;
	li.addClass('on');
	li.evonux.item.removeClass('off');
    },
    UserDataPersonnalDataSend: function(e)
    {
	$('form-personnal-data').send({onComplete: this.UserDataPersonnalDataSend_do.bind(this)});
    },
    UserDataPersonnalDataSend_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (xml['msg'])
	  alert(xml['msg'][0]);
	else
	  alert($tc1('data_updated_successfully'));
    },
    UserDataAddressUpdate: function(e)
    {
	var e = new Event(e),
	    f = e.target;
	while (f.getTag() != 'form') f = f.getParent();
	f.send({onComplete: this.UserDataAddressUpdate_do.bind(this)});
    },
    UserDataAddressUpdate_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (xml['msg'])
	  alert(xml['msg'][0]);
	else
	  alert($tc1('data_updated_successfully'));
    },
    UserDataAddressDelete: function(e)
    {
	if (!confirm($tc1('are_you_sure_delete'))) return false;

	var e = new Event(e),
	    f = e.target;
	e.stop();
	// Looks for form and its rank (to extract label_rank)
	while (f.getTag() != 'form') f = f.getParent();
	var form = $('user-addresses').getElements('form');
	var label_rank = 0;
	for (; label_rank < form.length; label_rank++)
	  if (form[label_rank] == f) break;
	// Looks for uid
	var input = f.getElements('input'), uid = 0;
	for (var k = 0; k < input.length; k++)
	{
	  if (input[k].getAttribute('name') == 'uid')
	    uid = input[k].getAttribute('value');
	}
	if (!uid) return false;

	var ajax_option = {
	    method: 'get',
	    onSuccess: this.UserDataAddressDelete_do.bind(this)
	};
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?__cn='+ Evonux.GetNb() +'&a=useraddressdelete&lr='+ label_rank +'&uid='+ uid, ajax_option).request();
    },
    UserDataAddressDelete_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (xml['msg'])
	  alert(xml['msg'][0]);
	else if (xml['label_rank'])
	{
	  // Delete address
	  li = $('user-addresses').getElements('li');
	  li[parseInt(xml['label_rank'][0])].remove();
	}
    },
    UserDataSponsor: function(e)
    {
	var e = new Event(e),
	    f = e.target;
	e.stop();
	
	$('user-sponsor').send({onSuccess: this.UserDataSponsor_do.bind(this)});
    },
    UserDataSponsor_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (xml['state'][0] == '0')
	  alert(xml['msg'][0]);
	else
	{
	  // User alert confirmation
	  alert($tc1('email_sent_to_sponsored'));
	  // Empties form
	  var i = $('user-sponsor').getElements('input');
	  for (var k = 0; k < i.length; k++)
	    i[k].setAttribute('value', '');
	}
    },

    UserDataEventLoad: function(e)
    {
	var ajax_option = {
	    method: 'get',
	    onSuccess: this.UserDataEventLoad_do.bind(this),
	    onFailure: this.Error
	};
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?a=usereventlist', ajax_option).request();
    },
    UserDataEventLoad_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray(),
	    i = xml['i'], li,
	    ul = $('events-list'), d, _d, y;
	ul.empty();
	if (i)
	for (var k = 0; k < i.length; k++)
	{
	  d = i[k]['date'][0];
	  y = parseInt(d.substr(0,4));
	  _d = d.substr(6,2) +'/'+ d.substr(4,2) + (y ? '/'+ y : ', '+ $tc1('every_year'));
	  
	  li = new Element('li');
	  li.evonux_oid = i[k]['oid'][0];
	  li.innerHTML = '<h1>'+ i[k]['title'][0] +'</h1><h2>'+ _d +'</h2><pre>'+ i[k]['content'][0] +'</pre><p><a href="#" onclick="evx_page.UserDataEventUpdate('+ k +'); return false;">'+ $tc1('edit') +'</a> - <a href="#" onclick="evx_page.UserDataEventDelete('+ k +'); return false;">'+ $tc1('delete') +'</a></p>';
	  ul.adopt(li);
	}
    },
    UserDataEvent: function(e)
    {
	var e = new Event(e),
	    f = e.target;
	e.stop();
	
	$('user-event-add').send({onSuccess: this.UserDataEvent_do.bind(this)});
    },
    UserDataEvent_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (xml['state'][0] == '0')
	  alert(xml['msg'][0]);
	else
	{
	    this.UserDataEventLoad();
	    alert($tc1('user-event-added-successfully'));
	    $('user-event-add').reset();
	}
    },
    UserDataEventDelete: function(rank)
    {
	if (!confirm($tc1('are_you_sure_delete'))) return false;

	var ul = $('events-list').getElements('li'),
	    li = ul[rank],
	    ajax_option = {
	      method: 'get',
	      onSuccess: this.UserDataEventDelete_do.bind(this),
	      onFailure: this.Error
	    };
	// Asks for server answer according to those options
	new Ajax(Evonux.SITE_ROOT +'/dyn.php?a=usereventdelete&oid='+ li.evonux_oid +'&rank='+ rank, ajax_option).request();
    },
    UserDataEventDelete_do: function(txt, xml)
    {
	var xml = new Evonux.XML(xml).GetArray(),
	    rank = parseInt(xml['rank'][0]),
	    ul = $('events-list').getElements('li'),
	    li = ul[rank];
	if (xml['state'][0] == '1')
	{
	  li.remove();
	  this.UserDataEventLoad();
	}
	else
	  alert(xml['msg'][0]);
    },
    UserDataEventUpdate: function(rank)
    {
	var ul = $('events-list').getElements('li'),
	    li = ul[rank],
	    form = $('user-event-add'),
	    oid = form.getElement('input.oid')
	    title = form.getElement('input.title'),
	    content = form.getElement('textarea.content'),
	    _date = form.getElements('td.date select'),
	    day = _date[0], month = _date[1], year = _date[2];
	oid.setAttribute('value', li.evonux_oid);
	title.setAttribute('value', li.getElement('h1').innerHTML);
	content.innerHTML = li.getElement('pre').innerHTML;
	// Date
	var re_d = /([0-9]{2})\/([0-9]{2})(, (.*)|\/([0-9]{4}))/;
	re_d.exec(li.getElement('h2').innerHTML);
	var d = parseInt(RegExp.$1, 10),
	    m = parseInt(RegExp.$2, 10),
	    y = parseInt(RegExp.$4 +''+ RegExp.$5, 10); if (isNaN(y)) y = '0000';

	for (var k = 0; k < day.length; k++)
	  if (day[k].value == d) day[k].selected = true;
	for (var k = 0; k < month.length; k++)
	  if (month[k].value == m) month[k].selected = true;
	for (var k = 0; k < year.length; k++)
	  if (year[k].value == y) year[k].selected = y;
    }
});

var evx_page;

window.addEvent('domready', function () {evx_page = new Evonux.Page();});
window.addEvent('resize', function () {evx_page.Resize();});

// ------------------------------------------------

Evonux.Cart = new Class({

    initialize: function(e)
    {
	this.Init();
    },

    /*
    ** Makes all entries dynamic for user comfort.
    ** Then he will be able to remove entries and update number of
    ** units for each product
    */
    Init: function ()
    {
	this.PackageInit();
	this.CartQtyInit();
	this.SubscriptionInit();
	// Blocks next step if user has not checked terms of use's box
	var a_next = $('cart-recap').getElement('.next-step-button');
	if (a_next)
	a_next.addEvent('click', function (e) {
	    var e = new Event(e),
		tof = $('accept-tof');
	    if (!$('accept-tof').checked)
	    {
	      alert($tc1('please_accept_term_of_use'));
	      e.stop();
	      return false;
	    }
	    return true;
	});
    },

    /*
    ** Activates packagings selection refresh requirement
    */
    PackageInit: function()
    {
	var sel = $('cart-end-content').getElements('select.package-select');
	for (var k = 0; k < sel.length; k++)
	  sel[k].addEvent('change', this.ForceCompute.bind(this));
    },

    /*
    ** Activates quantity active buttons
    */
    CartQtyInit: function()
    {
	var tr = $('cart-end-content').getElements('tr'),
	    del, box, m, p, i;
	for (var k = 1; k < tr.length - 1; k++)
	{
	  // + / -
	  box = tr[k].getElement('div.qty-wrap');
	  m = box.getElement('div.minus');
	  p = box.getElement('div.plus');
	  i = box.getElement('input');
	  m.addEvent('click', this.CartQtyMinus1.bind(this));
	  p.addEvent('click', this.CartQtyPlus1.bind(this));
	  i.addEvents({
	      'click': this.ForceCompute.bind(this),
	      'keyup': this.ForceCompute.bind(this),
	      'blur': this.ForceCompute.bind(this)
	  });
	  // Delete (hide and set to 0)
	  del = tr[k].getElement('td.remove a');
	  del.addEvents({
	      'click': this.CartRemove.bind(this)
	  });
	}
    },
    CartQtyMinus1: function(e)
    {
	var e = new Event(e),
	    b = e.target;
	while (!b.hasClass('qty-wrap')) b = b.getParent();
	var i = b.getElement('input'),
	    v = parseInt(i.getAttribute('value'));
	v = isNaN(v) ? 0 : (v > 0 ? v - 1 : 0);
	i.value = v;
	i.setAttribute('value', v);
	this.ForceCompute();
	return true;
    },
    CartQtyPlus1: function(e)
    {
	var e = new Event(e),
	    b = e.target;
	while (!b.hasClass('qty-wrap')) b = b.getParent();
	var i = b.getElement('input'),
	    v = parseInt(i.getAttribute('value'));
	i.value = isNaN(v) ? 0 : v + 1;
	i.setAttribute('value', isNaN(v) ? 0 : v + 1);
	this.ForceCompute();
	return true;
    },
    CartRemove: function(e)
    {
	var e = new Event(e),
	    tr = e.target;
	while (tr.tagName.toLowerCase() != 'tr') tr = tr.parentNode;
	// Sets quantity to 0
	var qty = tr.getElement('div.qty-wrap input');
	qty.setAttribute('value', 0);
	// Removes <tr>
	var anim_tr = new Fx.Styles(tr, {wait:false, duration: 500});
	anim_tr.start({
	    'opacity': 0
	});
	tr.addClass('deleted');
	tr.setStyles.delay(500, tr, {'display': 'none'});
	setTimeout(this.CartRemove_do.bind(this), 500);

	// Disallows next step
	this.ForceCompute();
	return true;
    },
    CartRemove_do: function(e)
    {
	// Sets classes
	var tr = $('cart-end-content').getElements('tr');
	for (var k = 1, i = 0; k < tr.length - 1; k++)
	{
	  if (!tr[k].hasClass('deleted'))
	  {
	    tr[k].className = 'line'+ (i % 2);
	    i++;
	  }
	}
    },

    /*
    ** Will help use choose correct combination of frequency and number
    ** of sendings
    */
    SubscriptionInit: function ()
    {
	var subbox = $('cart-recap').getElement('.subscription-choice');
	if (subbox)
	{
	    $('subscription-frequency').addEvent('change', this.SubscriptionCheckNbSendings.bind(this));
	    $('subscription-nb').addEvent('change', this.SubscriptionCheckFrequency.bind(this));
	}
    },
    /*
    ** Updates number of sending: makes unavailable numbers of sendings that are
    ** too high
    ** NB. total time have to be < 1 year
    */
    SubscriptionCheckFrequency: function ()
    {
	/* UPDATE WITH SAME METHOD THAN NEXT FUNCTION IS USED :
	var sel_freq = $('subscription-frequency'),
	    sel_nb_s = $('subscription-nb'),
	    nb_sendings = sel_nb_s.value;
	for (var k = 1; k <= 3; k++)
	{
	  if ((k-1) * nb_sendings > 12)
	    sel_freq.options[k].setAttribute('disabled', 'disabled');
	  else
	    sel_freq.options[k].removeAttribute('disabled');
	}
	*/
	this.SubscriptionTotalExplicite();
    },
    /*
    ** Updates available frequencies: make unavailable frequencies that are too high
    ** NB. total time have to be < 1 year
    */
    SubscriptionCheckNbSendings: function ()
    {
	var sel_freq = $('subscription-frequency'),
	    sel_nb_s = $('subscription-nb'),
	    freq = sel_freq.value;
	var opt;
	sel_nb_s.empty();
	// Empty choice :
	opt = new Element('option');
	opt.setAttribute('value', 0);
	opt.setHTML($tc1('choose_number_of_sendings'));
	sel_nb_s.adopt(opt);
	// Other choices :
	for (var k = parseInt($('subscription_min_nb').value); k <= 12; k++)
	{
	  if (k * freq > 12)
	    break;
	  opt = new Element('option');
	  opt.setAttribute('value', k);
	  opt.setHTML(', '+ k +' '+ $t('times'));
	  sel_nb_s.adopt(opt);
	}
	this.SubscriptionTotalExplicite();
    },
    /*
    ** Copies number of sendings in a readable way so user understands perfectly
    ** what he has choosen
    */
    SubscriptionTotalExplicite: function ()
    {
	preloadTranslation('so_you_will_receive', 'sendings', 'subscription_one_now');

	var sel_nb_s = $('subscription-nb');
	if (sel_nb_s.value > 0)
	  $('subscription-total-sendings').setHTML($tc1('so_you_will_receive') +' '+ sel_nb_s.value +' '+ $t('sendings') +' '+ $t('subscription_one_now'));
	else
	  $('subscription-total-sendings').setHTML('');
    },

    /*
    ** Prevents user from going forward by replacing "Go forward" link with
    ** "Compute again" submit button
    */
    ForceCompute: function (e)
    {
	if (e)
	{
	  var e = new Event(e)
	  e.stop();
	}

	// Updates total prices with ? since they are now uncorrect
	$('cart-end-content').getElement('td.total-price').setHTML('???');
	// Switches "Go forward" to "Compute totals"
	var a_validate = $('cart-recap').getElement('.next-step-button');
	if (a_validate)
	{
	  // Replaces "Go forward" link by submit button
	  var submit = new Element('input', {
	      'type': 'image',
	      'src': Evonux.PIC_DIR +'/cart-compute-again.'+ Evonux.LANG +'.png',
	      'alt': $tc1('compute_again')
	  });
	  submit.injectAfter(a_validate);
	  a_validate.remove();
	}
	return false;
    },

    /*
    ** Allows user to signgin not to have to fill his address form
    */
    AllowSignin: function (e)
    {
	if (e)
	{
	  var e = new Event(e)
	  e.stop();
	}

	var usersignin_desc = $('usersignin_desc'),
	    usersignin_passwd = new Element('tr', {
		'id': 'usersignin_passwd'
	    }),
	    usersignin_passwd_th = new Element('th', {
		'styles': {
		    'vertical-align': 'top',
		    'padding-top': '4px'
		}
	    }),
	    usersignin_passwd_td = new Element('td');
	/*
	usersignin_passwd.setHTML('<th style="vertical-align:top; padding-top:4px;">'+ $tc1('password') +'</th><td><input class="text" name="pass" type="password" value="" /><div style="width:255px;">'+ $tc1('cart_connect_speech2') +'</div><div style="text-align:right; width:255px; margin-bottom:10px;"><input type="submit" value="OK" /></div></td>');
	*/
	usersignin_passwd.adopt(usersignin_passwd_th);
	usersignin_passwd.adopt(usersignin_passwd_td);
	usersignin_passwd_th.setHTML($tc1('password'));
	usersignin_passwd_td.setHTML('<input class="text" name="pass" type="password" value="" /><div style="width:255px;">'+ $tc1('cart_connect_speech2') +'</div><div style="text-align:right; width:255px; margin-bottom:10px;"><input type="submit" value="OK" /></div>');
	usersignin_passwd.injectAfter(usersignin_desc);
	usersignin_passwd.getElement('input').value = '';
	usersignin_desc.remove();
    },

    /*
    ** User is asking form to be deleted. This methods does it.
    */
    UpdateContactContent: function (e)
    {
	$('update').value = '';
	if ($('recorded_address_choice').value == -1)
	  this.ResetContactForm();
	$('cart-recap').submit();
	return true;
    },
    /*
    ** User is asking form to be deleted. This methods does it.
    */
    ResetContactForm: function (e)
    {
	$('name').value = '';
	$('firstname').value = '';
	$('street').value = '';
	$('address_info').value = '';
	$('zip').value = '';
	$('city').value = '';
    }
});
