// JavaScript Document
/* Watermark solution */
(function($){
    function CreateDummyInput(jElement, options, tagName) {
      var watermarkText = (options.watermarkText) ? options.watermarkText : jElement.attr('title');
		  var dummyType = (tagName == 'INPUT') ? '<input type="text">' : '<textarea>';
      var dummyInput = $(dummyType)
          .attr('id', jElement.attr('id') + '_watermark')
          .addClass(options.watermarkCssClass)
          .addClass('watermarkPluginCustomClass') //workaround to fix some caching? problem in FF3. Used in window.unload hook to remove watermarks from the DOM
          .val(watermarkText)
          .css({overflowY: jElement.css('overflow-y'), overflowX: jElement.css('overflow-x')});

      dummyInput.hide();
      jElement.before(dummyInput);
      return dummyInput;
    }

    function MakeWatermark(element, options) {
      element.each(function(){
        var thisEl = jQuery(this);

        var dummyInput = CreateDummyInput(thisEl, options, thisEl.attr('tagName').toUpperCase());

        dummyInput.focus(function(e) {
          $(this).hide();
          thisEl.show().focus();
        });

        thisEl.blur(function(e) {
          if(this.value == '') {
            $(this).hide();
            dummyInput.show();
          }
        });

        thisEl.blur();
      });
      return element;
    }

    $(window).unload(function(){
    	$('.watermarkPluginCustomClass').remove();
    });

    $.fn.watermark = function(options){ return MakeWatermark(this, options);}
})(jQuery);

function validate(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}

$(document).ready(function(){
  	$('input#edit-mail').watermark({watermarkText: 'Mon adresse email (xx@xx.xx)', watermarkCssClass: 'input'});
	$(".rol-img").hover(
		function(){ $("img.rol", this).show(); },
		function(){ $("img.rol", this).hide(); }
	);
	
	$(".custom-form .in").hover(
		function(){ $(this).addClass("search-rol"); },
		function(){ $(this).removeClass("search-rol"); }
	);
	
	var comblock = $(".two-cols-block .left-block").height();
	var comblockmore = $(".two-cols-block .right-block-height").height();
	var heightblock = comblock - comblockmore - 301;
	if (heightblock <= 0)
	{
		heightblock = 0;
	}
	$(".com-block").css("height", heightblock);
	$('input#edit-submit').click(function(){
          $('div.error-custom-1').hide();
          $('div.success-message').hide();
          $('div.error-custom-2').hide();

          if ($('input#edit-agree').attr('checked')) {
            if (!validate($('input#edit-mail').val())) {
              $('div.error-custom-1').show('slow');
              return false;
            }
            $.post('sendmail_jeu_n2.php', {mail: $('input#edit-mail').val()}, function(response){
              if (parseInt(response, 10)) {
                $('div.error-custom-1').show('slow');
                return false;
              }
              $('div.success-message').show('slow');
              return false;
            });
          } else {
            $('div.error-custom-2').show('slow');
          }
          return false;
        });
});
