function validate_email(field,alerttxt)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}


function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}


function validate_form(thisform)
{
with (thisform)

  {
  if (validate_required(nom,"Veuillez indiquer votre nom.")==false)
  {nom.focus();return false;}
  
  if (validate_required(sujet,"Veuillez indiquer votre sujet.")==false)
  {sujet.focus();return false;}  
 
  if (validate_required(message,"Votre message semble vide.")==false)
  {message.focus();return false;} 
  if (validate_email(courriel,"Votre courriel ne semble pas valide.")==false)
    {courriel.focus();return false;}  
  
  }    
  

  
}


/* Mouse Over */

$(document).ready( function()
{
   PEPS.rollover.init();
   
   $("#contacteux").click(function(){
  	 $("#formulaireContact").show('slow');
 	});


 	$("#contactFromMenu").click(function(){
  	 $("#formulaireContact").show('slow');
 	});


   $("#fermerContact").click(function(){
  	 $("#formulaireContact").hide('slow');
 	});   
   
   
});

PEPS = {};

PEPS.rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_o' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_o\./, '.');
   }
};



$(function(){
	$('a.map').teste({
		bgColor: '#000',
		bgOpacity: 0.8,
		mapWidth: 600,
		mapHeight: 450,
		mapText: 'Les Constructions Claude Levesque inc.',
		mapUrl: 'http://maps.google.ca/maps?f=q&source=s_q&hl=fr&geocode=&q=2699,+boulevard+Perrot,+Notre-Dame-de-l\'%C3%8Ele-Perrot+(Qu%C3%A9bec),+J7V+8P4&sll=45.403731,-71.868499&sspn=0.011254,0.027895&ie=UTF8&z=14&iwloc=A&ll=45.363604,-73.937988&output=embed'
	});
});


/**
 * Google Maps Modal
 * This jQuery plugin was inspired on jQuery.lightBox
 *
 * @name jquery.google-maps-modal.js
 * @author Igor Frias Vieira - http://igorvieira.com
 * @version 0.1
 * @date Feb 10, 2009
 * @copyright (c) 2008 Igor Frias Vieira
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://igorvieira.com/blog/google-maps-modal/
 */

(function($)
{
	
	$.fn.teste = function(settings) {
		
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			
			//The overlay background
			bgColor: '#000', 		// Background color
			bgOpacity: 0.8,			// Background opacity
			
			//The map size
			mapWidth: 600,		// The map Width
			mapHeight: 350,		// The map Height
			
			//About the Map
			mapText: '',			// A little text
			mapUrl: ''				// You can find it on Google Maps iframe <iframe src="HERE"></iframe>
			
			/*
			 * ============================================================== You Should look for this src URL  \/ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \/
			 * <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"	src="http://www.google.com/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Parque+ibirapuera&amp;sll=-23.623704,-46.561111&amp;sspn=0.092006,0.181961&amp;ie=UTF8&amp;s=AARTsJoZOnljttHb6BAp9fGn-ngks2fbFg&amp;ll=-23.588138,-46.657734&amp;spn=0.027531,0.036478&amp;z=14&amp;output=embed"></iframe>
			 */
			
		},settings);
	
	
		/*
		 * Initializing the plugin
		 * @return boolean false
		 */
		function _initialize(){			
			
			//Create the modal Interface
			_createInterface();
			
			return false;
		}
		
		
		
		/*
		 * Creating the Modal Interface
		 * @return boolean false
		 */
		function _createInterface(){			
			
			$('body').append("<div id='gMapModal-overlay'></div><div id='gMapModal-text'></div><div id='gMapModal-box'></div>");
			$('#gMapModal-box').append('<iframe width="' + settings.mapWidth + '" height="' + settings.mapHeight + '" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + settings.mapUrl + '"></iframe>');
			$('#gMapModal-text').append('<p>' + settings.mapText + '</p><a id="gMapModal-closeButton"></a>');
			
			objHidden = $('embed, object, select').css({ 'visibility' : 'hidden' });
			
			
			//Hidding the elements
			$('#gMapModal-overlay, #gMapModal-box, #gMapModal-text').hide();
			
			
			// The Background CSS
			$('#gMapModal-overlay').css({
				'position' 	: 'absolute',
				'top' 		: 0,
				'left' 		: 0,
				'width' 	: '100%',
				'height' 	: $('body').outerHeight(),
				
				'background-color' : settings.bgColor,
				'opacity' 			: settings.bgOpacity
			});
			
			
			
			mgLeft = ((settings.mapWidth/2) * -1);
			mgTop = $(window).scrollTop() + 50;
			
						
			// The Map Box CSS
			$('#gMapModal-box').css({
				'position'		: 'absolute',
				'left'			: '50%',
				'width'			: settings.mapWidth + "px",
				'height'		: settings.mapHeight + "px",
				'margin-left'	: mgLeft + "px",
				'top'			: mgTop + "px"
			});
			
			
			mgTop = mgTop + settings.mapHeight;
			
			// The text CSS
			$('#gMapModal-text').css({
				'position'		: 'absolute',
				'left'			: '50%',
				'width'			: settings.mapWidth + "px",
				'margin-left'	: mgLeft + "px",
				'top'			: mgTop + "px"	 
			});
			
			
			//Calling the setActions Function
			_setActions();
			
			
			$('#gMapModal-overlay, #gMapModal-box').show();
			setTimeout(function(){
				$('#gMapModal-text').slideDown();
			}, 500);
			
			return false;
		}
		
		
		
		/*
		 * Set the buttons actions
		 * @return boolean false
		 */
		function _setActions(){
			
			$('#gMapModal-overlay').bind('click', closeModal);
			$('#gMapModal-closeButton').bind('click', closeModal);
			
			return false;
		}
		
		
		
		
		/*
		 * Closing the Modal
		 * @return boolean false
		 */
		closeModal = function(){
			$('#gMapModal-overlay').remove();
			$('#gMapModal-box').remove();
			$('#gMapModal-text').remove();
			
			
			$(objHidden).css({ 'visibility' : 'visible' });
			
			return false;
		}
		
		var objHidden = [];
		return this.unbind('click').click(_initialize);
	}
		
})(jQuery);



/*
 * jquery.watermark.js
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 */
(function($) {

	$.extend($,{
		clearwatermarks : function() {
			$("[wmwrap='true']").find("input,textarea").watermark({remove:true});
		},
		addwatermarks : function() {
			$("[watermark]").each(function(num,el) {
				$(el).watermark($(el).attr("watermark"));
			});
		},
		watermark : function(o) {
			o.el = $(o.el);
			if(o.remove) {
				if(o.el.parent().attr("wmwrap") == 'true') {
					o.el.parent().replaceWith(o.el);
				}
			} else {
				if(o.el.parent().attr("wmwrap") != 'true') {
					o.el = o.el.wrap("<span wmwrap='true' style='position:relative;'/>");
					var l = $("<label/>");
					
					if(o.html) { l.html(o.html); }
					if(o.cls) { l.addClass(o.cls); }
					if(o.css) { l.css(o.css); }
					
					l.css({
						position:"absolute",
						left:"3px",
						top : parseInt(o.el.css("paddingTop")),
						display:"inline",
						cursor:"text"
					});
					
					if(o.el.is("TEXTAREA")) {
						if($.browser.msie) {
							l.css("width",o.el.width());
						}
						if($.browser.mozilla || $.browser.safari) {
							l.css("top","");
						}
					}
					
					if(!o.cls && !o.css) {
						l.css("color","#ccc");
					}
					
					var focus = function() {
						l.hide();
					};
					
					var blur = function() {
						if(!o.el.val()) {
							l.show();
						} else {
							l.hide();
						}
					};
					
					var click = function() {
						o.el.focus();
					};
					
					if(o.inherit) {
						if(typeof o.inherit == "string") {
							l.css(o.inherit,o.el.css(o.inherit));
						} else {							
							for(var x=0;x<o.inherit.length;x++) {
								l.css(o.inherit[x],o.el.css(o.inherit[x]));
							}							
						}
					}
					
					o.el.focus(focus).blur(blur);
					l.click(click);
					o.el.before(l);
					if(o.el.val()) { l.hide(); }
				}
			}
			return o.el;
		}
	});
	
	$.fn.watermark = function(o) {
		return this.each(function() {
			if(typeof(o) == "string") {
				try {o = eval("(" + o + ")");} catch(ex) {o = {html:o};}
			}
			o.el = this;
			return $.watermark(o);
		});
	};
})(jQuery);

$().ready(function(){
	$.addwatermarks();
});

