function announce() {
	var o = this;
	this.datesonline = []; this.datespaper = []; this.cat = 0;

	o.add = function (type,date) {
		if (type == 'online') {
			if (this.datesonline.indexOf(date) == -1) {
				this.datesonline.push(date);
				var c = document.createElement('div');
				c.setAttribute('id','chosenonline-'+date);
				c.innerHTML = this.getHTML(type,date);
				document.getElementById('chosendates-online').appendChild(c);
				show('chosendates-online');
			}
		} else {
			if (this.datespaper.indexOf(date) == -1) {
				this.datespaper.push(date);
				var c = document.createElement('div');
				c.setAttribute('id','chosenpaper-'+date);
				c.innerHTML = this.getHTML(type,date);
				document.getElementById('chosendates-paper').appendChild(c);
				show('chosendates-paper');
			}
		}
	}
	
	o.showDateSelection = function () {
		if ($('both').checked === true) {
			show('chooseDates-online');
			show('chooseDates-paper');
		} else if ($('online').checked === true) {
			show('chooseDates-online'); hide('chooseDates-paper');
		} else {
			show('chooseDates-paper'); hide('chooseDates-online');
		}
		Effect.Grow('chooseDatesLeft');
	}
	
	o.refreshDateSelection = function () {
		if ($('both').checked === true) {
			show('chooseDates-online');
			show('chooseDates-paper');
		} else if ($('online').checked === true) {
			show('chooseDates-online'); hide('chooseDates-paper');
		} else {
			show('chooseDates-paper'); hide('chooseDates-online');
		}
	}	
	o.remove = function (type,date) {
		if (type == 'online') var myIndex = this.datesonline.indexOf(date);
		else var myIndex = this.datespaper.indexOf(date);
		if (myIndex > -1) {
			document.getElementById('chosendates-'+type).removeChild(document.getElementById('chosen'+type+'-'+date));
			if (type == 'online') {
				this.datesonline.splice(myIndex,1);
				if (this.datesonline.length == 0) {
					hide('chosendates-online');
				}
			} else {
				this.datespaper.splice(myIndex,1);
				if (this.datespaper.length == 0) {
					hide('chosendates-paper');
				}
			}
		}
	}
	
	o.getHTML = function (type,date) {
		return '<a href="javascript:void(0)" onclick="announce.remove(\''+type+'\',\''+date+'\')">'+date+'</a>';
	}

	o.startPay = function () {
		if ($('message').value.length < 15) {
			alert('S\'il vous plaît, ecrivez un message plus long.');
			return;
		}
		var type = false;
		if ($('both').checked === true) type = 'both';
		else if ($('online').checked === true) type = 'online';
		else if ($('paper').checked === true) type = 'paper';
		else {
			alert('S\'il vous plaît choisir le type de message');
			return;
		}
		
		if (type == 'online' && this.datesonline.length == 0) { alert('S\'il vous plaît choisir au moins 1 jour.'); return; }
		if (type == 'paper' && this.datespaper.length == 0) { alert('S\'il vous plaît choisir au moins 1 jour.'); return; }
		if (type == 'both' && (this.datesonline.length == 0 || this.datespaper.length == 0)) { alert('S\'il vous plaît choisir au moins 1 jour.'); return; }
		
		if (this.cat == 0) { alert('S\'il vous plaît choisir une catÃ©gorie.'); return; }
		if ($('name').value.length < 1 || $('firstname').value.length < 1 || $('emailannonces').value.length < 1 || $('phone').value.length < 1 || $('country').value.length < 1) {
			alert('S\'il vous plaît entrer vos coordonnÃ©es.'); return;
		}
		Effect.Shrink('requestForm');
		Effect.Shrink('chooseDatesLeft');
		Effect.Grow('loadingForm');

		var status = AjaxRequest.post(
				    {
				      'url':'/annonces/getPaymentForm.php',
				      'timeout':35000,
				      'mode':type,
				      'catid':o.cat,
				      'message':$('message').value, 'name':$('name').value, 'firstname':$('firstname').value,
				      'email':$('emailannonces').value, 'phone':$('phone').value, 'country':$('country').value,
				      'datesonline':o.datesonline.toString(),
				      'datespaper':o.datespaper.toString(),
				      'onTimeout':o.restartPayTimeout,
				      'onSuccess':function(req) { 
				      		Effect.Shrink('loadingForm');
		if (document.getElementById('payForm')) document.getElementById('payForm').parentNode.removeChild(document.getElementById('payForm'));
		var payForm = document.createElement('div'); payForm.setAttribute('id','payForm');
		payForm.style.margin = '5px';
		payForm.innerHTML = req.responseText; payForm.style.display = 'none';
		$('requestForm').parentNode.appendChild(payForm);
		Effect.Grow('payForm');
				      
				      },
				      'onError':o.restartPayError
				    }
				  );
		return true;
	}
	
	o.processPayReply = function (req) {
	}

}

var announce = new announce();