var Enquiry = Class.create(Validate,{

	initialize: function($super)
	{
		$super();
		var options = {
			'presence_of': {
				name_field: {message: 'Merci de renseigner votre nom'}
			},
			'format_of': {
				email: {use: 'email', message: 'Le format de votre adresse e-mail n&#39;est pas correct'}
			}
		};
		this.reqire_fields = options;

		this.brawser = navigator.appName;
		this.target = $('enquiry_holder');
		this.open_link = $('open_enquiry');
		this.close_link = $$('#enquiry_holder a.close')[0];

		if(this.close_link) {
			this.close_link.observe('click', this.hide_img.bindAsEventListener(this));
		}
		if(this.open_link) {
			this.open_link.observe('click', this.show_dialog.bindAsEventListener(this));
		}

		this.flag = false;
		this.count = 0;
	},


	show_dialog: function ()
	{
		if(this.flag === true) return;
		this.flag = true;
		$$('div.lightbox2_fog').first().style.height = this.get_page_size()+'px';
		this.target.setStyle({display: 'block'});
		// FIXME EHM modification du montage permettant de recharger le contenu de la popin
		load_newsletter_form();
	},


	hide_img: function (){
		if(this.flag){
			this.target.hide();
			this.flag = false;
		}
	},

	get_page_size: function(){

		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			yScroll = document.body.offsetHeight;
		}

		var windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowHeight = document.body.clientHeight;
		}

		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		return pageHeight;
	},
	
	submit_form: function()
	{
	   $('form_successful', 'form_for_submit', 'scrollable_text').invoke('toggle');
    }

});

 Event.observe(window,'load', function(){
 	Enq = new Enquiry();
 });


