//----------------------------------------------------------------------------------------

// Authors : Guillaume Quimper & Nadia HADJI, Influenza marketing http://www.influenza.ca
// Version 1.0
// Created: April 2011

//----------------------------------------------------------------------------------------


//------------------------------------------------------------------------
// Customer's Feedbacks Form
//------------------------------------------------------------------------

function displayMessage() {
	//Get the screen height and width  
    var maskHeight = $(document).height();  
    var maskWidth = $(window).width();  
       
    //Set height and width to mask to fill up the whole screen  
    $('#mask').css({'width':maskWidth,'height':maskHeight});  
           
    //transition effect      
    $('#mask').fadeTo("fast", 0.8);    
       
    //Get the window height and width  
    var winH = $(window).height();  
    var winW = $(window).width();  
                 
    //Set the popup window to center  
    $('#message').css('top',  winH/3-$('#message').height()/3);  
    $('#message').css('left', winW/2-$('#message').width()/2); 
    
    //transition effect
    $('#message').fadeIn(700);
}

function resetForm() {
	// Use a whitelist of fields to minimize unintended side effects.
	$(':text, :password, :file', 'form').val('');  
	// De-select any checkboxes, radios and drop-down menus
	$(':input,select option', 'form').removeAttr('checked').removeAttr('selected');
	//this is for selecting the first entry of the select
	$('select option:first', 'form').attr('selected',true);
}

$(function() {
	
	// Custom Regex for Phone Number Validation
	$.validator.addMethod("phone", function (value, el, params) {
    	return this.optional(el) || /^[01]?[- .]?\(?[2-9]\d{2}\)?[- .]?\d{3}[- .]?\d{4}$/.test(value);
    }, "Numéro invalide");
    
    // Custom Regex for Canadian Postal Code Validation
	$.validator.addMethod("codepostal", function (value, el, params) {
		return this.optional(el) || /^([ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]\d[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstvwxyz])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZabceghjklmnprstwvxyz]\d)$/.test(value);
	}, 'Veuillez entrer un code postal valide.');

	var validator = $("#feedbackForm").bind("invalid-form.validate", function() {	
	}).validate({
		rules: {
			courriel: {
				email: true
			},
			telephone : {
				phone : true
			},
			codepostal:{
				codepostal : true
			}			
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
                success: function() {
                	$("#displayNotice").append("<h3>Merci d'avoir répondu à ce questionnaire</h3><p>Nous vous remercions de choisir Valentine. Votre demande sera traitéé et une personne responsable communiquera avec vous sous peu.</p>");
                	displayMessage();
                	resetForm();
              	}
			});
		}
	});


//------------------------------------------------------------------------
// Job Application Form
//------------------------------------------------------------------------

	
	var validator = $("#applyForm").bind("invalid-form.validate", function() {	
	}).validate({
		rules: {
			codepostal: {
				codepostal: true
			},
			teldom : {
				phone : true
			},
			teltra : {
				phone : true
			},
			telaut : {
				phone : true
			},
			tel : {
				phone : true
			},
			cellulaire : {
				phone : true
			},
			courriel : {
				email : true
			}			
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: function() {
					var currentForm = $('#applyForm').attr("class");
					if(currentForm == 'postulant') {
						$("#displayNotice").append("<h3>Candidature envoyée avec succès !</h3><p>Nous vous remercions de choisir Valentine. Votre demande d'emploi sera traitée et une personne responsable de l'embauche communiquera avec vous sous peu.</p>");
					}
                	if(currentForm == 'concours') {
                		$("#displayNotice").append("<h3>Merci de votre participation !</h3><p>Nous vous remercions de choisir Valentine. Votre réponse au concours sera traitée et une personne responsable communiquera avec vous sous peu.</p>");
                	}
                	if(currentForm == 'franchise') {
                		$("#displayNotice").append("<h3>Demande d'information envoyée avec succès !</h3><p>Nous vous remercions de choisir Valentine. Votre demande d'information sera traitée et une personne responsable communiquera avec vous sous peu.</p>");
                	}
                	displayMessage();
                	resetForm();
				}
           });
		}	
	});
	
	

//------------------------------------------------------------------------
// Carte Cadeau Form
//------------------------------------------------------------------------

	
	var validator = $("#pickupForm").bind("invalid-form.validate", function() {	
	}).validate({
		rules: {
			codepostal: {
				codepostal: true
			},
			teldom : {
				phone : true
			},
			teltra : {
				phone : true
			},
			telaut : {
				phone : true
			},
			tel : {
				phone : true
			},
			cellulaire : {
				phone : true
			},
			courriel : {
				email : true
			},
			restaurant: {
				required:true
			}			
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				success: function() {
					var currentForm = $('#pickupForm').attr("class");
                		$("#displayNotice").append("<h3>Commande envoyée avec succès !</h3><p>Nous vous remercions de choisir Valentine. Votre commande de cartes-cadeaux sera traitée et une personne responsable communiquera avec vous sous peu.</p>");
                	displayMessage();
                	resetForm();
				}
           });
		}	
	});
	
	
		
	var validator = $("#paypalForm").bind("invalid-form.validate", function() {	
	}).validate();

});
