/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) 
{
	var contact = 
	{
		message: null,
		init: function () 
		{
			$('#contact-form input.contact, #contact-form a.contact').click(function (e) {
				e.preventDefault();

				// load the contact form using ajax
				var urlget_etape = 'questionnaire/page1.php';
				if (document.body)
				{ var haut = (document.body.clientHeight); }
				else{ var haut = (window.innerHeight); }
				var hautbis = haut-550;
				hautbis=hautbis/2;
				
					$.get(urlget_etape, function(data){
					// create a modal dialog with the data
					$(data).modal({
						closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
						position: [""+hautbis+"px",],
						overlayId: 'contact-overlay',
						containerId: 'contact-container',
						onOpen: contact.open,
						//onShow: contact.show,
						onClose: contact.close
					});
				});
			});
		},
		open: function (dialog) 
		{
			var h = 520;
			
			// add padding to the buttons in firefox/mozilla
			if ($.browser.mozilla) {
				$('#contact-container .contact-button').css({
					'padding-bottom': '2px'
				});
			}
			// input field font size
			if ($.browser.safari) {
				$('#contact-container .contact-input').css({
					'font-size': '.9em'
				});
			}

			// dynamically determine height
			if ($.browser.msie){		// --> tester le navigateur IE ou non :: code jquery
				var h = 520;
			}

			if ($('#contact-subject').length) {
				h += 26;
			}
			if ($('#contact-cc').length) {
				h += 22;
			}

			var title = $('#contact-container .contact-title').html();
			$('#contact-container .contact-title').html('Loading...');
			dialog.overlay.fadeIn(200, function () {
				dialog.container.fadeIn(200, function () {
					dialog.data.fadeIn(200, function () {
						$('#contact-container .contact-content').animate({
							height: h
						}, function () {
							$('#contact-container .contact-title').html(title);
							$('#contact-container form').fadeIn(200, function () {
								$('#contact-container #contact-name').focus();

								$('#contact-container .contact-cc').click(function () {
									var cc = $('#contact-container #contact-cc');
									cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
								});

								// fix png's for IE 6
								if ($.browser.msie && $.browser.version < 9) {
									$('#contact-container .contact-button').each(function () {
										if ($(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+$/i)) {
											var src = RegExp.$1;
											$(this).css({
												backgroundImage: 'none',
												filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
											});
										}
									});
								}
							});
						});
					});
				});
			});
		},
		close: function (dialog)
		{
			$('#contact-container .contact-message').fadeOut();
			$('#contact-container .contact-title').html('A bientôt...');
			$('#contact-container form').fadeOut(200);
			$('#contact-container .contact-content').animate({
				height: 40
			}, function () {
				dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(200, function () {
						dialog.overlay.fadeOut(200, function () {
							$.modal.close();
						});
					});
				});
			});
		},
		error: function (xhr) {
			alert(xhr.statusText);
		},
		showError: function () {
			$('#contact-container .contact-message')
				.html($('<div class="contact-error"></div>').append(contact.message))
				.fadeIn(200);
		}
	};

	contact.init();
});

/* ---------------- FONCTION POUR ETAPE 2 ---------------- */

function goForm() 
{
	$('#div_form').animate({ opacity: 0 }, 300, function() {
		var budgettest=$("#budget").val();
		if (budgettest=="")
		{
			$('#div_form').load('questionnaire/page1.php', {
				erreur: 'yes', type: $('input[type=radio][name=type]:checked').attr('value'), proprio: $('input[type=radio][name=proprio]:checked').attr('value'), cadre: $('input[type=radio][name=cadre]:checked').attr('value'), serviceasso1: $('#serviceasso1').is(':checked'), serviceasso2: $('#serviceasso2').is(':checked'), debut: $('input[type=radio][name=debut]:checked').attr('value'), budget: $("#budget").val(), infoge: $('#info_general').attr('value'), 
				style: $('input[type=radio][name=style]:checked').attr('value'), aspect: $('input[type=radio][name=aspect]:checked').attr('value'), couleurfacade: $("#couleurfacade").val(), plantravail: $('input[type=radio][name=plantravail]:checked').attr('value'), couleurplan: $("#couleurplan").val(), info_cuisine: $('#info_cuisine').attr('value'), 
				concept1: $('#concept1').is(':checked'), concept2: $('#concept2').is(':checked'), concept3: $('#concept3').is(':checked'), nombre: $("#nombre").val(), info_agencement: $('#info_agencement').attr('value'), 
				implantation1: $('#implantation1').is(':checked'), implantation2: $('#implantation2').is(':checked'), implantation3: $('#implantation3').is(':checked'), implantation4: $('#implantation4').is(':checked'), implantation5: $('#implantation5').is(':checked'), implantation6: $('#implantation6').is(':checked'), implantation7: $('#implantation7').is(':checked'), implantation8: $('#implantation8').is(':checked'), implantation9: $('#implantation9').is(':checked')
				},
				function() { $('#div_form').animate({ opacity: 1 }, 300); }
			);
		}
		else
		{
			$('#div_form').load('questionnaire/page2.php', {
				type: $('input[type=radio][name=type]:checked').attr('value'), proprio: $('input[type=radio][name=proprio]:checked').attr('value'), cadre: $('input[type=radio][name=cadre]:checked').attr('value'), serviceasso1: $('#serviceasso1').is(':checked'), serviceasso2: $('#serviceasso2').is(':checked'), debut: $('input[type=radio][name=debut]:checked').attr('value'), budget: $("#budget").val(), infoge: $('#info_general').attr('value'), 
				style: $('input[type=radio][name=style]:checked').attr('value'), aspect: $('input[type=radio][name=aspect]:checked').attr('value'), couleurfacade: $("#couleurfacade").val(), plantravail: $('input[type=radio][name=plantravail]:checked').attr('value'), couleurplan: $("#couleurplan").val(), info_cuisine: $('#info_cuisine').attr('value'), 
				concept1: $('#concept1').is(':checked'), concept2: $('#concept2').is(':checked'), concept3: $('#concept3').is(':checked'), nombre: $("#nombre").val(), info_agencement: $('#info_agencement').attr('value'), 
				implantation1: $('#implantation1').is(':checked'), implantation2: $('#implantation2').is(':checked'), implantation3: $('#implantation3').is(':checked'), implantation4: $('#implantation4').is(':checked'), implantation5: $('#implantation5').is(':checked'), implantation6: $('#implantation6').is(':checked'), implantation7: $('#implantation7').is(':checked'), implantation8: $('#implantation8').is(':checked'), implantation9: $('#implantation9').is(':checked')
				},
				function() { $('#div_form').animate({ opacity: 1 }, 300); }
			);
		}
	});
}

function goForm2() 
{
	$('#div_form').animate({ opacity: 0 }, 300, function() {
		$('#div_form').load('questionnaire/page3.php', {
			bas1: $('#bas1').is(':checked'), bas2: $('#bas2').is(':checked'), bas3: $('#bas3').is(':checked'), bas4: $('#bas4').is(':checked'), bas5: $('#bas5').is(':checked'), bas6: $('#bas6').is(':checked'), info_bas: $('#info_bas').attr('value'), 
			haut1: $('#haut1').is(':checked'), haut2: $('#haut2').is(':checked'), haut3: $('#haut3').is(':checked'), haut4: $('#haut4').is(':checked'), info_haut: $('#info_haut').attr('value'), 
			armoires1: $('#armoires1').is(':checked'), armoires2: $('#armoires2').is(':checked'), armoires3: $('#armoires3').is(':checked'), armoires4: $('#armoires4').is(':checked'), armoires5: $('#armoires5').is(':checked'), armoires6: $('#armoires6').is(':checked'), armoires7: $('#armoires7').is(':checked'), info_armoire: $('#info_armoire').attr('value'), 
			evier: $('input[type=radio][name=evier]:checked').attr('value'), info_evier: $('#info_evier').attr('value'), 
			electro1: $('#electro1').is(':checked'), electro2: $('#electro2').is(':checked'), electro3: $('#electro3').is(':checked'), electro4: $('#electro4').is(':checked'), electro5: $('#electro5').is(':checked'), electro6: $('#electro6').is(':checked'), electro7: $('#electro7').is(':checked'), electro8: $('#electro8').is(':checked'), electro9: $('#electro9').is(':checked'), info_electro: $('#info_electro').attr('value'),
			idquest: $("#idquest").val()
			},
			function() { $('#div_form').animate({ opacity: 1 }, 300); }
		);
	});
}

function goForm3() 
{
	$('#div_form').animate({ opacity: 0 }, 300, function() {
		$('#div_form').load('questionnaire/page4.php', function() { $('#div_form').animate({ opacity: 1 }, 300); });
	});
}
function goForm4() 
{
	$('#div_form').animate({ opacity: 0 }, 300, function() {
		$('#div_form').load('questionnaire/page5.php', {
			nom: $("#nom").val(), prenom: $("#prenom").val(), email: $("#email").val(), tel: $("#tel").val(), adresse: $("#adresse").val(), ville: $("#ville").val(), adresse: $("#adresse").val(), cp: $("#cp").val(), cgv: $('#cgv').is(':checked')
			},
			function() { $('#div_form').animate({ opacity: 1 }, 300); }
		);
	});
}

