/** GetTDAProgForm **/


window.addEvent('domready', initGTP);


function initGTP() {
	
	
	var formDiv = new Element('div', {
		id:'myFormBox',
		styles: {
			position: 'fixed',
			top: 0,
			left: 0,
			zIndex: 100,
			background: '#FFF',
			width: '350px',
			boxShadow: '0 5px 5px',
			display: 'none',
			fontSize: '11px'
		}
	}).inject(document.body);
	
	var Footer = $$('#tda-footers p')[0];	
	Footer.adopt(
		new Element('span', { 'class': 'footer-separtion', text: ''}),
		new Element('a', {
			href: '#gtplink', title:'Recevoir le programme', 'class': 'footer-link', text: 'Recevoir le programme chez vous !',
				styles: {
					padding: 5,
					color: '#C00',
					backgroundColor: '#FFF',
					fontWeight: 'bold',
					fontSize: '12px',
					margin: [0, 0, 0, 15],
					border: '1px solid #252525',
					borderWidth: '1px 1px 0'
				},
				events: { click: addForm }
			})
	);
	
}

function addForm(ev) {
	ev.stop();
	var b = $('myFormBox');
	if(b.getStyle('display')=='none') {
		b.setStyles({
			display: 'block',
			opacity: 0,
			top:  this.getCoordinates().bottom - (window.getScroll().y),
			left: this.getCoordinates().left
		});
		b.set('load', {
			onSuccess: function(t,e,h,j) {
				b.fade('in');
				var f= $('gtp_subForm');
				new Element('input', { type: 'hidden', name: 'register', value: 'ok'}).inject(f);
				f.addEvent('submit', sendForm);
			}
		});
		
		b.load('./xhr/getProgForm.html');
		
		
	} else {
		var fadeOUT = new Fx.Tween(b, { property: 'opacity'});		
		fadeOUT.start(1,0).chain(
			function() { b.setStyle('display', 'none'); b.empty()}
		);
	}
	
	
	
}

function sendForm(ev) {
	ev.stop();
//this = gtp_subForm
	this.set('send', {
		onSuccess: function(respT, respXML) {
			$('gtp_serRep').set('html', respT).highlight('#F00', '#999');
		},
		onFailure: function(xhr) {  alert('Une Erreur est survenue');}
	});
	this.send();
}
