// JavaScript Document
 

	   


var $ = jQuery.noConflict();

$(document).ready(function() {
    initjQuery();	   
	
	
//	    $("li a#lang").click(function(){
//			  alert('Soon!');
//			  return false
//		 })

//
//	$("ul.level-1").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
//	
//	$("ul#cssmw li.parent").hover(function() { //When trigger is clicked...
//		
//		//Following events are applied to the subnav itself (moving subnav up and down)
//		$(this).find("ul.level-1").show('fast').show(); //Drop down the subnav on click
//
//		$(this).hover(function() {
//		}, function(){	
//			$(this).find("ul.level-1").hide('fast'); //When the mouse hovers out of the subnav, move it back up
//		});
//
//		//Following events are applied to the trigger (Hover events for the trigger)
//		}).hover(function() { 
//			$(this).addClass("subhover"); //On hover over, add class "subhover"
//		}, function(){	//On Hover Out
//			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
//	});


	$("ul#cssmw li").hoverIntent(function () {
			$(this).addClass("hovering").css("z-index", 200000);
			if ( $(this).hasClass("hovering") ){
				$(this).find(".level-1").queue("fx",[]);
				$(this).find(".level-1").slideDown("fast");
			}
		},
		function () {
			 $(this).find(".level-1").slideUp("fast");
			 $(this).removeClass("hovering");
		}
	);


		 
		 $('#teaser').nivoSlider({
			 effect:'fold',
			 controlNav:true,
			 pauseOnHover:false,
			 directionNav:false,
			 pauseTime:5000 

		});	  

    // Init Function
    function initjQuery() {
        var defaultSearchString = "Search";
        $().createSubNavigation();
   //     $().createRoundedCorners('.rc .rc');
  //      $().createRoundedCorners('.rc'); // Round 1, of creating RCs
  //      $().initTabs();
  //      $().initSliders();
  //      $().initQuickLinks();
  //      $().initTicker();
 //       $().createEqualHeight();
 //       $().createRoundedCorners('.btn');
        //$().moreResults("Show all", "Hide");
        //$().createRoundedCorners();	// Call this again to do RC inside RC
     //   $().createButtonRollOver(); // Make the roll overs, now that all the rounded corners have been made

        var completed = new Array();

 //       $('a[rel*=language]').lightBox({});

        $('#dd_search input[type="text"], .searchBox input[type="text"]').each(function() {
            $(this).attr('value') === '' ? $(this).attr('resetvalue', defaultSearchString) : $(this).attr('resetvalue', $(this).attr('value'));
            $(this).focus(function() {
                ($(this).attr('value') == $(this).attr('resetvalue')) ? $(this).attr('value', '') : $(this).select();
            }).blur(function() {
                if ($(this).attr('value') == '') { $(this).attr('value', $(this).attr('resetvalue')); }
            });
        });
       // $('.shortenable').applyShowHide();
	   
	   
    }
 
//    function contains(array, item) {
//        for (var i = 0; i < array.length; i++) {
//            if (array[i] == item) {
//                return true;
//            }
//        }
//        return false;
//    }

    $("a#dologin").click(function(){
		  $("#clientarea").stop().animate({ top: '0px'}, 'slow')
	  });

    $("div#clientarea").bind('mouseleave',function(){
	     $('#clientarea').animate({ top: '-61px'}, 'slow');
	  });
	  
	  
	  
	  var $ui = $('#header');
	  
	  $ui.find('#menurecherche').bind('focus click',function(){
		  $ui.find('#menurecherche, #menurecherche a')
			 .addClass('changeSearch')
			 .andSelf()
			 .find('#searchbox')
			 .slideDown();
	  });
	  

	  $ui.bind('mouseleave',function(){
		  $ui.find('.changeSearch, #menurecherche a')
			 .andSelf()
			 .find('#searchbox')
			 .slideUp( function(){ $('.changeSearch').removeClass('changeSearch') } );
	  });
				
	  
	  
	  
	//  $(".w1, .w2").height($(document).height());
	  $(".w1, .w2").height( $("#outerWrapper").height() );
	  //$(".w2").css("background-color","red");
	 

	  
 
      
 
 	  
		// Preload all rollovers
		$("#menuaccueilxxx img").each(function() {
			// Set the original src
			rollsrc = $(this).attr("src");
			rollON = rollsrc.replace(/.jpg$/ig,"_on.jpg");
			$("<img>").attr("src", rollON);
		});
		
		// Navigation rollovers
		$("#menuaccueilxxx a").mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			
  		if (imgsrc) {
				matches = imgsrc.match(/_on.jpg/);
				// don't do the rollover if state is already ON
				if (!matches) {
				imgsrcON = imgsrc.replace(/.jpg$/ig,"_on.jpg"); // strip off extension
				$(this).children("img").attr("src", imgsrcON);
				}

			}
			
		});
		$("#menuaccueilxxx a").mouseout(function(){
			$(this).children("img").attr("src", imgsrc);
		});
		
	  
//$('#menuaccueil a img').hover(function() {
//  $(this).animate({
//    opacity: 0.50,
//  }, 300, function() {
//    
//	  $//(this).animate({opacity: 1},300) 
//	  $(this).fadeTo(250,1);
//	
//	
//  });
//});
	  
	  
    var opacity = 1, toOpacity = 0.75, duration = 250;
    $('#menuaccueil a img').hover(function() {
            $(this).fadeTo(duration,toOpacity);
        }, function() {
            $(this).fadeTo(duration,opacity);
        }
    );
	  
	  
	  
	 $("form#formlogin").submit(function(){
		  alert('Erreur d\'authentification \n\nVeuillez essayer a nouveau!');
		  return false;
	  });
	  
	  
	$(".dynamicform").submit(function(){

		//$('form#formquickcontact input[type=submit]').attr("disabled", "disabled"); 	
		$("#formresult").html('');
		

		
		
							 var theForm = $(this) 
							 var theFormID = $(this).attr('id') 
							 var theName = $("#" + theFormID + " input#NOM").val();
							// var theDate = $("#" + theFormID + " input#date").val();
							 var theTelephone = $("#" + theFormID + " input#TELEPHONE").val();
							 var theEmail = $("#" + theFormID + " input#EMAIL").val();
							 var themessage = 'S.v.p verifier le(s) champ(s) suivant: \n'
							 
							 var hasError = false;
		                     var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/ ;
							//$("#" + theFormID + " .error").remove(); 
							 $("#" + theFormID + " .bordererror").removeClass("bordererror");
							 
							 
							if(theName == 'nom') {
								//$("#" + theFormID + " input#NOM").before('<span class="error">*Erreur</span>');
								$("#" + theFormID + " input#NOM").addClass("bordererror");
								themessage = themessage + "\n- NOM";
								hasError = true;
							}
							

							if(theEmail == '') {
								$("#" + theFormID + " input#EMAIL").before('<span class="error">*Erreur</span>');
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							} else if(!emailReg.test(theEmail)) {
								//$("#" + theFormID + " input#EMAIL").before('<span class="error">*Erreur</span>');
								$("#" + theFormID + " input#EMAIL").addClass("bordererror");
								themessage = themessage + "\n- EMAIL";
								hasError = true;
							}
					
							if(theTelephone == 'numéro de téléphone') {
								//$("#" + theFormID + " input#TELEPHONE").before('<span class="error">*Erreur</span>');
								$("#" + theFormID + " input#TELEPHONE").addClass("bordererror");
								themessage = themessage + "\n- TELEPHONE";
								hasError = true;
							}
							
							
						  if(hasError == false) {
							  
							  
		
											  $.ajax({
												  type: "POST",
												  url: 'functions.asp',
												  cache: false,
												  data: $("form.dynamicform").serialize(),
												  success: function(msg){
									  //				if(msg.indexOf("client") > -1 ){
									  //					document.location = './client_P' + idpageclient + '.html';
									  //				} else if (msg.indexOf("pro") > -1 ){
									  //					document.location = '/?pro=secure';
									  //				} else {
									  //					alertMes(msg);
									  //					setTimeout('$("#formresult").html("Courriel:"); $("form#loginform input[type=submit]").attr("disabled", "");', 2000);
									  //				}	
													 alert('Votre message a ete envoye avec succes!');
													
													//$('form#formquickcontact input[type=submit]').before('<span class="error" style="display:block ; text-align:left;">Merci, nous vous contacterons sous peu!</span>');
													$('form.dynamicform input[type=submit]').hide("slow");
													  
												  }
											  });				   
											  return false;
							  
							  
							  
							  
							  
							    
						  }	else {
							  
							// alert(themessage);
							 return false;
						 }						
						  
						 
		 
		
		
		
	})
	  
	  
	  
	  
});
