function gdSubscribeNewsletter() {
	var email = $('newsletter_email').value;
	
	if (email != '') {
		new Ajax.Request('/membres/subscribe.php', {
			method: 'post',
			parameters: 'email=' + email + '&nl[1]=1',
			onComplete: function(transport) {
				var response = transport.responseText;
				if (response == '[OK]') {
					alert('Inscription effectuée avec succès');
				} else {
					alert(response);
				}
			}
		});
	}
	else 
	alert('Veuillez renseigner une adresse email');
	return false;
}


function gdClearShopsSelect(firstText) {
	$('id_shop').options[0].selected = true;
	$('id_shop').options[0].text = firstText;
	for(i=$('id_shop').length; i > 0 ; i--){
		$('id_shop').options[i] = null;
	}
}

function gdGetShops(onlineShop, shopDepartment) {
	gdClearShopsSelect('Sélectionner un magasin');
	
	new Effect.Appear('loading', {
		duration : 0.5,
		afterFinish : function(){
			new Ajax.Request('/reduction/', {
				method: 'post',
				parameters: 'action=ajax_get_shops&online_shop=' + onlineShop + '&shop_department=' + shopDepartment,
				onComplete: function(transport) {
					var shops = transport.responseText.evalJSON();
					
					shops.each (function(shop){
						$('id_shop').options[$('id_shop').length] = new Option(shop.name, shop.id_shop);
					});
					
					new Effect.Fade('loading', {duration : 0.5});
				}
			});
		}
	});
}

function gdHandleOnlineShop(onlineShop) {
	if (onlineShop == 1) {
		new Effect.BlindUp('shopDept', 1);
		$('shop_department').options[0].selected = true;
		gdGetShops(onlineShop, '', '');
	} else {
		new Effect.BlindDown('shopDept', 1);
		gdClearShopsSelect('Veuillez sélectionner un département');
	}
	
	return true;
}

function gdHandleShopDepartment(department) {
	if (department) {
		gdGetShops(0, department, '');
	}
	
	return true;
}

function gdCheckGoodDealForm() {
	return true;
}

/*
function gdSubmitGoodDealForm() {
	$('goodDealForm').submit();
	return false;
}
*/


