﻿function echeck(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
var error_mail_invalide = "L'adresse email que vous avez entre est incorrecte, corrigez puis reessayez.";

if (str.indexOf(at)==-1){
alert(error_mail_invalide);
return false;
 }

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert(error_mail_invalide);
return false;
 }

if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert(error_mail_invalide);
return false;
 }

if (str.indexOf(at,(lat+1))!=-1){
alert(error_mail_invalide);
return false;
 }

if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert(error_mail_invalide);
return false;
 }

if (str.indexOf(dot,(lat+2))==-1){
alert(error_mail_invalide);
return false;
 }

if (str.indexOf(" ")!=-1){
alert(error_mail_invalide);
return false;
 }

return true;
 }

function ValidateForm(){
var emailID=document.fcdm_email.address;

if ((emailID.value==null)||(emailID.value=="")){
alert("Merci de rentre votre adresse email.");
emailID.focus();
return false;
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus();
return false;
}

 return true;
}


jQuery.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }

  return this.each(function () {
    // get jQuery version of 'this'
    var $input = jQuery(this),

    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title

      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

$(document).ready(function() {
	$('input[id=address]').focus(function() {
		value = $(this).val();
		if(value == 'Entrez ici votre adresse email') {
			$(this).val('');
			$(this).attr('style', 'color:inherit;');
		}
	});
	$('input[id=address]').blur(function() {
		value = $(this).val();
		if(value == '') {
			$(this).val('Entrez ici votre adresse email');
			$(this).attr('style', 'color:#CCC;');
		}
	});
	if($('input[id=address]').val() == '') {
		$('input[id=address]').val('Entrez ici votre adresse email');
		$('input[id=address]').attr('style', 'color:#CCC;');
	}
	
	});
