/*
** 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({
    w: null, // window dimensions (mootools' window.getSize();)
    wrap_height: -1, // px
    wrap_width: 960, // px
    // Objects that need position to be updated on resize (msie)
    resize_objects: new Array(),
    content_id: 'content',
    home_img_timer_duration: 4000,

    /*
    ** Inits complex display
    */
    initialize: function()
    {
	this.BrowserAdjust();
	this.Resize();
	this.WelcomeInit() || this.Init();
	Evonux.Text.HeadersToImg({node:$('content')});

	// Categories images rotation
	if ($('welcome-catalog'))
	  setTimeout(this.HomeCategoryImageSwitch.bind(this),
		     this.home_img_timer_duration);
    },

    /*
    ** 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()
    {
	
    },
    /*
    ** 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();
	if ($('cart-recap')) this.CartInit();
    },
    /*
    ** Builds objects' interactivity for welcome page
    */
    WelcomeInit: function()
    {
	if (!$('welcome-catalog')) return false;
	// Catalog main panel (with images)
	var catalog_li = $('welcome-catalog').getElements('li'),
	    l, a, img;
	for (var k = 0; k < catalog_li.length; k++)
	{
	  li = catalog_li[k];
	  a = li.getElement('a');
	  img = li.getElement('img');
	  if (a) // Last element if for graphism only
	  {
	    a.style.visibility = 'hidden';
	    li.addEvent('mouseenter', this.ShowHomeCatalogTitle.bind(this));
	    li.addEvent('mouseleave', this.HideHomeCatalogTitle.bind(this));
	  }
	}
	// Makes an animation on slogan
	var slogan = $('slogan').getElement('img');
	anim_slogan = new Fx.Styles(slogan, {wait:false, duration: 1500});
	anim_slogan.start.delay(1500, anim_slogan, {
	    'opacity': [0, 1],
	    'width': [0, 235],
	    'height': [0, 243],
	    'margin-top': [243, 0],
	    'margin-left': [235, 0]
	});
	return true;
    },

    /*
    ** Hover for home page catalog entry
    */
    ShowHomeCatalogTitle: function (e)
    {
	var e = new Event(e),
            li = e.target;
	for (var tag = li.getTag(); tag != 'li'; li = li.parentNode, tag = li.getTag())
	  if (tag == 'body') return false;
	var a = li.getElement('a'), other = li.getParent().getElements('li'), o;
	// Hides others
	for (var k = 0; k < other.length - 1; k++)
	{
	  o = other[k];
	  if (o == li) continue;
	  this.HideHomeCatalogTitle(false, o);
	}
	// Show this one
	anim_a = new Fx.Styles(a, {wait:false, duration: 300});
	anim_a.start({
	    'opacity': 1
	});
    },
    /*
    ** De-hover for home page catalog entry
    */
    HideHomeCatalogTitle: function (e, li)
    {
	var e = (e ? new Event(e) : false), li = li;
	if (arguments.length == 1)
	{
          li = e.target;
	  for (var tag = li.getTag(); tag != 'li'; li = li.parentNode, tag = li.getTag())
	    if (tag == 'body') return false;
	}
	var a = li.getElement('a');
	if (a.getStyle('visibility') == 'hidden') return;
	anim_a = new Fx.Styles(a, {wait:false, duration: 300});
	anim_a.start({
	    'opacity': 0
        });
    },

    /*
    ** 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);
    },

    /*
    ** Loads new images for home catalog categories
    */
    HomeCategoryImageSwitch: function()
    {
	var li = $('welcome-catalog').getElements('li'),
	    img, img_url,
	    anim_img, anim_img_opacity,
	    rankge, range_neg = new Array(-50, -60, -50, -40, -50, -60, -60, -44);
	for (var k = 0; k < Evonux.home_image.length; k++)
	{
	  img_url = Evonux.home_image[k][Evonux.home_image_rank[k]++];
	  img = li[k].getElement('img');
	  img.setAttribute('src', img_url);
	  anim_img_opacity = new Fx.Styles(img, {wait:false, duration:500});
	  anim_img_opacity.start({
	      'opacity': [0,1]
	  });
	  range = (Math.random() > 0.5 ? [range_neg[Math.floor(Math.random() * 8)],0] : [0,range_neg[Math.floor(Math.random() * 8)]]);
	  anim_img = new Fx.Styles(img, {wait:false, duration:this.home_img_timer_duration});
	  anim_img.start({
	      'margin-left': range
	  });

	  if (Evonux.home_image_rank[k] >= Evonux.home_image[k].length)
	    Evonux.home_image_rank[k] = 0;
	}

	setTimeout(this.HomeCategoryImageSwitch.bind(this),
		   this.home_img_timer_duration);
    },

    /*
    ** 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]);
    }
});

var evx_page;

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

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

Evonux.Catalog = new Class({
    cur_oid: 0,
    cat_list_scroll: null, // List of other products' scroll object
    nb_products: 0, // number of displayable products
    cur_rank: 0, // current displayed product's rank
    cur_img_rank: 1, // current displayed product's image rank
    img_id1: 'cat-image', // 
    img_id2: 'cat-image2', // 
    img_timer: null, // timer to automatically display different images for product
    img_timer2: null, // timer to load an image from switching program
    img_timer_duration: 2000, // milliseconds
    img: null, // pictures to display for product

    initialize: function(e)
    {
	// Adds interactivity for list of other products (inside right list)
	var li = $('cat-list').getElements('li'),
	    img, a,
	    re_oid = /\/([0-9]+)\//;
	Evonux.Catalog.nb_products = li.length;
	for (var k = 0; k < li.length; k++)
	{
	  //  - mouseover/out opacity effect
	  li[k].addEvent('mouseenter', this.ShowListItem.bind(this));
	  li[k].addEvent('mouseleave', this.HideListItem.bind(this));
	  img = li[k].getElement('img');
	  img.setOpacity(0.25);
	  //  - web 2.0 links overloading
	  a = li[k].getElement('a');
	  re_oid.exec(a.getAttribute('href'));
	  a.evonux = {rank:k, oid:RegExp.$1};
	  a.addEvent('click', function(e) {
	      var e = new Event(e),
		  target = e.target;
	      e.stop();
	      if (target.getTag() != 'a') target = target.getParent();
	      Evonux.catalog.Open(target.evonux.rank, target.evonux.oid);
	      return false;
	  });
	}
	// Makes add-to-cart / prev / next / zoom : web 2.0 buttons
	$('cat-add-to-cart').addEvent('click', this.AddToCart.bind(this));
	//ZOOM IS DEACTIVATED: $('cat-zoom').addEvent('click', this.Zoom.bind(this));
	var cat_nav = $('cat-nav').getElements('a');
	cat_nav[0].addEvent('click', this.OpenPrev.bind(this)); // prev
	cat_nav[1].addEvent('click', this.OpenNext.bind(this)); // next
	// Adds scroll on mousemove to list
	this.cat_list_scroll = new Scroller('cat-list', {area: 100, velocity: 1});
	$('cat-list').addEvent('mouseover', this.cat_list_scroll.start.bind(this.cat_list_scroll));
	$('cat-list').addEvent('mouseout', this.cat_list_scroll.stop.bind(this.cat_list_scroll));
	// Tries to find pictures for this product
	if (Evonux.catalog_img)
	{
	  this.img = Evonux.catalog_img;
	  this.LaunchSwitchImage();
	}
	// Sets current oid
	re_oid.exec(window.location);
	this.cur_oid = parseInt(RegExp.$1);
    },

    /*
    ** Loads a product's file
    */
    Open: function(caller_rank, oid)
    {
	this.cur_rank = caller_rank;
	this.HideProduct();
	evx_page.Open.delay(650, evx_page, {
	    a: 'page',
	    oid: oid,
	    onSuccess: this.Open_do.bind(this)
	});
	this.StopSwitchImage();
    },
    /*
    ** Loads previous product's file
    */
    OpenPrev: function(e)
    {
	new Event(e).stop();
	var a = $('cat-list').getElements('a');
	// Checks that we can go further
	if (this.cur_rank <= 0) return false;
	// Asks for next product
	var re_oid = /\/([0-9]+)\//;
	re_oid.exec(a[this.cur_rank - 1].getAttribute('href'));
	this.Open(this.cur_rank - 1, RegExp.$1);
	return false;
    },
    /*
    ** Loads next product's file
    */
    OpenNext: function(e)
    {
	new Event(e).stop();
	var a = $('cat-list').getElements('a');
	// Checks that we can go further
	if (this.cur_rank >= a.length - 1) return false;
	// Asks for next product
	var re_oid = /\/([0-9]+)\//;
	re_oid.exec(a[this.cur_rank + 1].getAttribute('href'));
	this.Open(this.cur_rank + 1, RegExp.$1);
	return false;
    },
    /*
    ** Treats server's answer from this.Open call
    */
    Open_do: function(text, xml)
    {
	var xml = new Evonux.XML(xml).GetArray();
	if (!xml['product']) return false;

	this.cur_oid = parseInt(xml['oid'][0]);
	this.LoadTitle(xml['title'][0]);
	this.LoadContent(xml['content'][0]);
	this.LoadReference(xml['product'][0]['ref'][0]);
	this.LoadPrice(xml['product'][0]['price'][0]);
	if (xml['product'][0]['img_src'].length > 0)
	  this.img = xml['product'][0]['img_src'];
	this.LoadImage(xml['product'][0]['img_src'][0], xml['title'][0]);
    },

    /*
    ** Creates DOM objects for animations
    */
    GetHider: function()
    {
	var hider = $('cat-hide');
	if (hider) return hider;
	hider = new Element('div', {
	    'id': 'cat-hide',
	    'styles': {
		'width': 0,
		'height': 204,
		'padding-top': 150
	    }
	});
	hider.setHTML('<img src="'+ Evonux.PIC_DIR +'/loading.gif" alt="loading..." />').injectAfter('cat-ref');
	return hider;
    },
    /*
    ** Hides product for loading
    */
    HideProduct: function()
    {
	var h = this.GetHider();
	anim_h = new Fx.Styles(h, {wait:false, duration: 500, transition:Fx.Transitions.Quint.easeIn});
	anim_h.start({
	    'width': [0, 335],
	    'margin-left': [335, 0],
	    'opacity': [0, 1]
        });
    },
    /*
    ** Shows product after loading time
    */
    ShowProduct: function()
    {
	var h = this.GetHider();
	if (h.getStyle('opacity') < 0.1) return false;
	anim_h = new Fx.Styles(h, {wait:false, duration: 500, transition:Fx.Transitions.Quint.easeIn});
	anim_h.start({
	    'width': 0,
	    'margin-left': 635,
	    'opacity': [1, 0]
        });
    },

    /*
    ** Updates product's title
    */
    LoadTitle: function(str)
    {
	$('catalog').getElement('h1').setHTML(str);
    },
    /*
    ** Updates product's content
    */
    LoadContent: function(str)
    {
	$('catalog').getElement('div.content').setHTML(str);
    },
    /*
    ** Updates product's reference
    */
    LoadReference: function(str)
    {
	$('cat-ref').setHTML($tc1('reference') +' '+ str);
    },
    /*
    ** Updates product's price
    */
    LoadPrice: function(str)
    {
	$('cat-price').setHTML(str +' &euro;');
    },
    /*
    ** Updates product's image
    */
    LoadImage: function(src, title)
    {
	if (!$(this.img_id2)) this.ImagesMotionInit();
	var img = $(this.img_id2).getElement('img');
	img.addEvent('load', this.ShowProduct.bind(this));
	img.setAttribute('src', src);
	img.setAttribute('alt', title ? title : '');

	this.LaunchSwitchImage();
    },

    /*
    ** Displays next image for current product
    */
    LaunchSwitchImage: function()
    {
	this.img_timer = setTimeout(this.SwitchImage.bind(this),
				    this.img_timer_duration);
    },
    /*
    ** Displays next image for current product
    */
    StopSwitchImage: function()
    {
	clearInterval(this.img_timer);
	this.img_timer = null;
	this.img = null;
	this.cur_img_rank = 1;
    },
    /*
    ** Inits JS animations for images
    */
    ImagesMotionInit: function()
    {
	var img1_w = $('cat-image'),
	    img2_w = $('cat-image2'),
	    img1 = img1_w.getElement('img'),
	    img2;
	// Creates second image
	img2_w = new Element('div', {
	    id: 'cat-image2',
	    styles: {
		'visibility': 'hidden',
		'opacity': 0
	    }
	});
	img2 = new Element('img');
	img2_w.injectAfter(img1_w);
	img2.injectInside(img2_w);
	// Adds events
	img1.addEvent('load', this.SwitchImage_do.bind(this));
	img2.addEvent('load', this.SwitchImage_do.bind(this));
    },
    /*
    ** Displays next image for current product
    */
    SwitchImage: function()
    {
	// Inits img tags if first time
	if (!$('cat-image2'))
	  this.ImagesMotionInit();

	var i1 = $(this.img_id1).getElement('img'),
	    i2 = $(this.img_id2).getElement('img');
	i2.setAttribute('src', this.img[this.cur_img_rank++]);
	if (this.cur_img_rank >= this.img.length) this.cur_img_rank = 0;

	this.img_timer = setTimeout(this.SwitchImage.bind(this),
				    this.img_timer_duration);
    },
    /*
    ** Does display loaded image
    */
    SwitchImage_do: function(e)
    {
	var i1 = $(this.img_id1),
	    i2 = $(this.img_id2),
	    anim_i1 = new Fx.Styles(i1, {wait:false, duration: 500}),
	    anim_i2 = new Fx.Styles(i2, {wait:false, duration: 500});
	// Animates
	anim_i1.start({
	    'opacity': [1,0]
        });
	anim_i2.start({
	    'opacity': [0,1]
        });

	var tmp_id = this.img_id1;
	this.img_id1 = this.img_id2;
	this.img_id2 = tmp_id;
    },

    /*
    ** Adds current product to cart
    */
    AddToCart: function(e)
    {
	new Event(e).stop();
	// Asks server to add current element to cart
	var query_string = {
	      'a': 'cart',
	      'do': 'add',
	      'oid': this.cur_oid
	    },
	    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() +'&'+ Object.toQueryString(query_string), ajax_option).request();

	//this.AddToCart_do();

	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;
	}

	var cart = $('cart'),
	    cart_bg = $('cart-bg'),
	    cart_desc = cart.getElement('strong'),
	    anim_cart = new Fx.Styles(cart, {wait:false, duration: 550}),
	    anim_cart_back = new Fx.Styles(cart, {wait:false, duration: 1000, transition:Fx.Transitions.Bounce.easeOut}),
	    anim_cart_bg = new Fx.Styles(cart_bg, {wait:false, duration: 550}),
	    anim_cart_bg_back = new Fx.Styles(cart_bg, {wait:false, duration: 1000, transition:Fx.Transitions.Bounce.easeOut});
	// Checks that cart is visible
	if ($('cart').getStyle('display') == 'none')
	{
	  $('cart').setStyles({
	      'display': 'block',
	      'margin-top': -164
	  });
	  $('cart-bg').setStyles({
	      'display': 'block',
	      'margin-top': -188
	  });
	}
	// Updates cart's content
	cart_desc.setHTML(xml['cart_html'][0]);
	// Animates
	anim_cart.start({
	    'margin-top': 164
        });
	anim_cart_bg.start({
	    'margin-top': 140
        });
	anim_cart_back.start.delay(550, anim_cart_back, {
	    'margin-top': -64
        });
	anim_cart_bg_back.start.delay(550, anim_cart_bg_back, {
	    'margin-top': -88
        });
	return true;
    },

    /*
    ** Displays bigger image for current product
    */
    Zoom: function(e)
    {
	new Event(e).stop();
	alert('have to display bigger image');

	return false;
    },

    /*
    ** Hover for product list item
    */
    ShowListItem: function(e)
    {
	var e = new Event(e),
	    li = e.target;
	for (var tag = li.getTag(); tag != 'li'; li = li.getParent(), tag = li.getTag())
	  if (tag == 'body') return false;
	var ul = li.getParent(), other = ul.getElements('li'), o;
	// Hides others
	for (var k = 0; k < other.length; k++)
	{
	  o = other[k];
	  if (o == li) continue;
	  this.HideListItem(false, o);
	}
	// Show this one
	var img = li.getElement('img');
	anim_img = new Fx.Styles(img, {wait:false, duration: 300});
	anim_img.start({
	    'opacity': 1
	});
    },
    /*
    ** De-hover for product list item
    */
    HideListItem: function(e, li)
    {
	var e = (e ? new Event(e) : false), li = li;
	if (arguments.length == 1)
	{
	  li = e.target;
	  for (var tag = li.getTag(); tag != 'li'; li = li.getParent(), tag = li.getTag())
	    if (tag == 'body') return false;
	}
	var img = li.getElement('img');
	anim_img = new Fx.Styles(img, {wait:false, duration: 150});
	anim_img.start({
	    'opacity': 0.25
        });
    }
});

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

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 ()
    {
	var li = $('cart-recap').getElements('div.middle ul.cart-items li'),
	    a_remove,
	    input_qty;
	// Cart items
	for (var k = 0; k < li.length; k++)
	{
	  a_remove = li[k].getElement('a.remove');
	  if (!a_remove) continue;
	  a_remove.addEvent('click', this.RemoveEntry.bind(this));
	  
	  input_qty = li[k].getElement('input.quantity');
	  input_qty.addEvents({
	      'click': this.ForceCompute.bind(this),
	      'keyup': this.ForceCompute.bind(this),
	      'blur': this.ForceCompute.bind(this)
	  });
	}
	// Coupons
	var newcoupon = $('newcoupon');
	if (newcoupon)
	{
	  newcoupon.addEvent('keyup', this.ForceCompute.bind(this));
	  newcoupon.addEvent('mouseup', this.ForceCompute.bind(this));
	}
	// Blocks next step if user has not checked terms of use's box
	var a_next = $('cart-recap').getElement('div.bottom td.validate a');
	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;
	});
	// Multi addresses select
	//recorded_address_choice
    },

    /*
    ** Removes entry
    */
    RemoveEntry: function (e)
    {
	var e = new Event(e),
	    li = e.target;
	e.stop();
	// Looks for <li>
	while (li.getTag() != 'li' && li.getTag() != 'body') li = li.getParent();
	// Removes <li>
	anim_li = new Fx.Styles(li, {wait:false, duration: 700});
	anim_li.start({
	    'height': 0
        });
	li.remove.delay(700, li, {});
	this.ForceCompute();
	// If there is no entry left, opens empty page
	if ($('cart-recap').getElements('div.middle ul li').length <= 1)
	  setTimeout(function () {$('cart-recap').submit()}, 800);

	return false;
    },

    /*
    ** 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-recap').getElement('div.bottom td.total-price').setHTML('<p>'+ $tc1('shipping_cost') +' : ???</p><h1>'+ $tc1('total') +' : ???</h1><p>('+ $tc1('where_taxes_equal') +' : ???)</p>');
	// Switches "Go forward" to "Compute totals"
	var a_validate = $('cart-recap').getElement('div.bottom td.validate a');
	if (a_validate)
	{
	  // Replaces "Go forward" link by submit button
	  var submit = new Element('input', {
	      'type': 'submit',
	      'value': $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 = '';
    }
});

