function validMail(email) {
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) result = true;
	}
	return result;
}

jQuery(function() {
	//jQuery('<input />').attr('id','focus-stealer').appendTo('<body>').focus();
	if (navigator.userAgent.match(/firefox/i)) document.getElementById('focus-stealer').focus();
  /*
  jQuery('.noclick').click(function() { 
  	jAlert(jQuery(this).attr('title'),messages[5]);	
  	return false;
  });
  */
  jQuery('.noclick').click(function() { 
  	jQuery('<div />').attr('id','popup_overlay').css({
  		'backgroundColor': '#fff',
  		'position': 'absolute',
  		'zIndex': 99998,
  		'top': '0px',
  		'left': '0px',
  		'width': '100%',
  		'height': jQuery(window).height()+'px',
  		'opacity': '0.5'
  	}).appendTo('body');
  	jQuery('<div />').attr('id','popup_alert').css({
			'left':((jQuery(window).width()-311)/2)+'px',
			'top':((jQuery(window).height()-97)/2)+'px',
			'margin':'0',
			'width':'311px',
			'height':'97px',
			'padding':'0',
			'position':'absolute',
			'zIndex':'99999',
			'background':'url(/images/'+lan+'/alert.gif)',
			'textAlign':'center'
  	}).html('<div style="height:56px;">&nbsp;</div><a id="close_alert" href="#"><img src="/images/ok.gif" /></a>').appendTo('body');
  	jQuery('#close_alert').click(function() { 
  		jQuery('#popup_alert').remove();
  		jQuery('#popup_overlay').remove();
  		return false;	
  	});
  	return false;
  });



  jQuery('.modal').click(function() {
  
  		var vpwidth = jQuery(window).width();
  		var vpheight = jQuery(window).height();
      jQuery('<div />').attr('id', 'popup_overlay').css({
          'backgroundColor': '#fff',
          'position': 'absolute',
          'zIndex': 8998,
          'top': '0px',
          'left': '0px',
          'width': '100%',
          'height': jQuery(window).height() + 'px',
          'opacity': '0.5'
      }).appendTo('body');
      jQuery('<div />').attr('id', 'modal_alert').css({
          'left': ((jQuery(window).width() - 311) / 2) + 'px',
          'top': ((jQuery(window).height() - 210) / 2) + 'px',
          'margin': '0',
          'width': '311px',
          'height': '210px',
          'padding': '0',
          'position': 'absolute',
          'zIndex': '8999',
          'background': 'url(/images/modal-bg.png)',
          'textAlign': 'left'
      }).html('<div style="height:152px;"><a style="margin-top:18px;display:block;margin-bottom:18px;margin-left:56px" href="/fichiers/pdf/catalogue_patiodrummond_version_4.pdf" title=""><img src="/images/' + lan + '/btn-download-catalog.png" alt=""></a><a id="patiodrum" rel="iframe" style="margin-left:56px;" href="/swf/patiodrum/Default.html" title=" :: :: height:'+vpheight+', width:' + vpwidth +'"><img src="/images/' + lan + '/btn-see-catalog.png" alt="" /></a></div><a style="margin-left:127px;" id="close_alert" href="#"><img src="/images/ok.gif" /></a>').appendTo('body');
      jQuery('#patiodrum').prettyPhoto();
      
      jQuery('#close_alert').click(function() {
          jQuery('#modal_alert').remove();
          jQuery('#popup_overlay').remove();
          return false;
      });
      return false;
  });
  
  jQuery('.external').attr('target','_blank');
  // FORMULAIRE CONTACT
  jQuery('#contactform').submit(function() {
  	if (jQuery('#txt-subject').val()=='') {
  		jAlert(messages[0],messages[5]);
  		return false;
  	}
  	if (jQuery('#txt-name').val()=='') {
  		jAlert(messages[1],messages[5]);
  		return false;
  	}
  	if (jQuery('#txt-email').val()=='') {
  		jAlert(messages[2],messages[5]);
  		return false;
  	}
  	if (!validMail(jQuery('#txt-email').val())) {
  		jAlert(messages[3],messages[5]);
  		return false;
  	}
  	if (jQuery('#txt-msg').val()=='') {
  		jAlert(messages[4],messages[5]);
  		return false;
  	}
  	jQuery.ajax({
  		url :	'/contact-form.php?lan='+lan,
  		type : 'POST',
  		data : jQuery('#contactform').serialize()
  	});
  	jQuery('#contact-form').html(htmlcontact);
  	return false;
  });
  jQuery('#gentrajet').click(function() {
  	window.open('http://maps.google.com/?hl='+lan+'&q=from:%20'+escape(jQuery('#txt-cp').val())+'%20to:%208435%20boul%20St-Joseph%20Saint-Nicephore');
  	
  });
  
});

jQuery.fn.makeAbs = function() {

    return this.each(function() {
        var el = jQuery(this);
        var pos = el.position();
        el.css({ 
        		position: "absolute",
            top: pos.top, 
            left: pos.left 
        });
    });

}

jQuery.fn.makeStatic = function() {

    return this.each(function() {
        var el = jQuery(this);
        //var pos = el.position();
        el.css({ 
        		position: "static",
            top: 'auto', 
            left: 'auto'
        });
    });

}
