$(document).ready(function() {

/* actu defilente */
$('#slideshownews')
.cycle({ 
    fx:     'scrollUp',
    speed:  1500, 
    timeout: 6000,
});

/* mini form contact */
//if submit button is clicked
    $('#submit').click(function () {
								 
		//test email
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var cpReg = /^\d{5}$/;
         
        //Get the data from all the fields
        var nomprenom = $('input[name=nomprenom]');
        var email 	  = $('input[name=email]');
        var tel 	  = $('input[name=tel]');
        var cp 		  = $('input[name=cp]');
		var sujet 	  = $('input[name=sujet]');
 
        //Simple validation to make sure user entered something
        //If error found, add hightlight class to the text field
        if (nomprenom.val()=='' || nomprenom.val()=='votre nom et prénom *') {
            nomprenom.addClass('hightlight');
            return false;
        } else nomprenom.removeClass('hightlight');
         
        if (email.val()=='' || email.val()=='votre email *' || !emailReg.test(email.val())) {
            email.addClass('hightlight');
            return false;
        } else email.removeClass('hightlight');
         
        if (tel.val()=='' || tel.val()=='votre numéro de téléphone *') {
            tel.addClass('hightlight');
            return false;
        } else tel.removeClass('hightlight');
		
		if (cp.val()=='' || cp.val()=='votre code postal *' || !cpReg.test(cp.val())) {
            cp.addClass('hightlight');
            return false;
        } else cp.removeClass('hightlight');
		
		if (sujet.val()=='' || sujet.val()=='sujet *') {
            sujet.addClass('hightlight');
            return false;
        } else sujet.removeClass('hightlight');
		
         
        //organize the data properly
        var data = 'nomprenom=' + nomprenom.val() + '&email=' + email.val() + '&tel='
        + tel.val() + '&cp='  + cp.val() + '&sujet='  + sujet.val();
         
        //disabled all the text fields
        $('.text').attr('disabled','true');
         
        //show the loading sign
        $('.loading').show();
         
        //start the ajax
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "/contact/formcontactright.php",
             
            //GET method is used
            type: "GET",
 
            //pass the data         
            data: data,     
             
            //Do not cache the page
            cache: false,
             
            //success
            success: function (html) {              
                //if process.php returned 1/true (send mail success)
                if (html==1) {
                    //hide the form
                    $('.form').fadeOut('slow');                 
                     
                    //show the success message
                    $('.done').fadeIn('slow');
                     
                //if process.php returned 0/false (send mail failed)
                } else alert('Un problème est survenu');               
            }       
        });
         
        //cancel the submit button default behaviours
        return false;
    });


});

