/*

	[ site.js ]

*/

var Site = {

	start: function(){

		if ( jQuery('form').length ) Site.formValidation();

		/* Open external links in new windows */
		jQuery('a[rel="external"]').attr({
			target: "_blank",
			title: "Lien s'ouvrant dans une nouvelle fenêtre"
		});

	},

/* ############################################# */

	formValidation: function(){

		jQuery.getScript('ui/js/jquery.validate.js', function(){

			jQuery.validator.setDefaults({
				submitHandler: function(form) {
					jQuery.post('common/contact.php', jQuery(form).serialize(), function(data){
						jQuery('#right-content').html(data);
					});
				},
				onfocusout: false
			});

			if (jQuery('form input#lang').val() == 1) {
				err1 = "This field is required.";
				err2 = "You must enter a valid email address.";
			} else {
				err1 = "Ce champ est obligatoire.";
				err2 = "S'il vous pla&icirc;t entrer un courriel valide.";
			}

			jQuery('form').validate({
				rules: {
					name: 'required',
					email: {
						required: true,
						email: true
					},
					subject: 'required',
					message: 'required'
				},
				messages: {
					name: err1,
					email: {
						required: err1,
						email: err2
					},
					subject: err1,
					message: err1
				}
			});

		});

	}

/* ############################################# */

}

/* ############################################# */

   /* 1.0. Google Analytics ################### */

	function googleAnalytics() {
		var gaJsHost = (('https:' == document.location.protocol) ? 'https://ssl.' : 'http://www.');
		jQuery.getScript(gaJsHost + 'google-analytics.com/ga.js', function(){
			var pageTracker = _gat._getTracker(''); // Insert GA Code
				pageTracker._initData();
				pageTracker._trackPageview();			
		});
	}

   /* 1.1. Spamless Email ##################### */

	function noSpam(user) {
		var mail = 'mailto:' + user + '@bectrol.com';
		window.location.href = mail;
	}

/* ############################################# */

jQuery.noConflict();

jQuery(document).ready(function(){
	//googleAnalytics();

	Site.start();
});

/* Code is poetry */