
function valider(form)
{
	var i = 0;
	var msg = "";
	var dateArrivee = form.elements['dateArrivee'].value;
	var dateDepart = form.elements['dateDepart'].value;
	var nbrpersonne = form.elements['inputNbrPersonneFormResa'].value;

	if (dateArrivee.length<2)
		{msg += "Merci de saisir une date d\'arriv\351e. \n";i++;}

	if (dateDepart.length<2)
		{msg += "Merci de saisir une date de d\351part. \n";i++;}

	if (nbrpersonne.length==0 || nbrpersonne==0)
		{msg += "Merci de saisir le nombre de personnes. \n";i++;}


	if (i>=1)
		{alert(msg);return false;}
	return true;
}

function validerHotel(form)
{
	var i = 0;
	var msg = "";
	var dateDebut = form.elements['dateDebut'].value;
	var dateFin = form.elements['dateFin'].value;
	var nbPers = form.elements['nbPers'].value;

	if (dateDebut.length<2)
		{msg += "Merci de saisir une date d\'arriv\351e. \n";i++;}

	if (dateFin.length<2)
		{msg += "Merci de saisir une date de d\351part. \n";i++;}

         
	if (nbPers.length==0 || nbPers==0)
		{msg += "Merci de saisir le nombre de personnes. \n";i++;}


	if (i>=1)
		{alert(msg);return false;}
	return true;
}




function dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }

    alert(out);

    // or, if you wanted to avoid alerts...

    var pre = document.createElement('pre');
    pre.innerHTML = out;
    document.body.appendChild(pre)
}

var debut =0;
var test='';
var current='';
$(window).load(function() {

    


    if($("#slider").length){
        $('#slider').nivoSlider({
            effect:'random', //Specify sets like: 'fold,fade,sliceDown'
            animSpeed:500, //Slide transition speed
            pauseTime:9000,
            startSlide:0, //Set starting Slide (0 index)
            directionNav:true, //Next & Prev
            directionNavHide:false, //Only show on hover
            controlNav:false, //1,2,3...
            controlNavThumbs:true, //Use thumbnails for Control Nav
            controlNavThumbsFromRel:false, //Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', //Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
            keyboardNav:true, //Use left & right arrows
            pauseOnHover:true, //Stop animation while hovering
            manualAdvance:false, //Force manual transitions
            captionOpacity:0.7, //Universal caption opacity
            beforeChange: function(){
            },
            afterChange: function(){
            },
            slideshowEnd: function(){
            }, //Triggers after all slides have been shown
            lastSlide: function(){}, //Triggers when last slide is shown
            afterLoad: function(){
            } //Triggers when slider has loaded
        });
    }
}); 

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });

}


function mycarousel_initCallback_thematiques(carousel) {


    $('.jcarousel-control a').bind('click', function() {

        $('#liste_thematiques li a').css('color','#4088B8');
        $('#liste_thematiques li a img').css('border','none');
        
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        $('#liste_thematiques li:eq('+eval(jQuery(this).text()-1)+') a').css('color','orange');
        $('#liste_thematiques li:eq('+eval(jQuery(this).text()-1)+') a img').css('border','2px solid orange');
        return false;
    });
}


/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int} page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
function pageselectCallback(page_index, jq){
	// Get number of elements per pagionation page from form
	var members = jQuery('#hiddenresult li');
	var items_per_page = 6;
	var max_elem = Math.min((page_index+1) * items_per_page, members.length);
	var newcontent = '';
	
	$('#Searchresult').empty();
	// Iterate through a selection of the content and build an HTML string
	for(var i=page_index*items_per_page;i<max_elem;i++)
	{
		newcontent = jQuery('#hiddenresult li:eq('+i+')').clone();
		$('#Searchresult').append(newcontent);
	
	}
	// Prevent click eventpropagation
	return false;
}

/**
 * Initialisation function for pagination
 */
function initPagination() {
    // count entries inside the hidden content
    var num_entries = jQuery('#hiddenresult li').length;
	/*alert(num_entries);*/
    // Create content inside pagination element
	 $("#Pagination").pagination(num_entries, {
        callback: pageselectCallback,
        items_per_page:6,
        prev_text:" < ",
        next_text:" > ",
        num_display_entries:0,
        num_edge_entries:0
    });
    /*$("#Pagination").pagination(num_entries, {
        callback: pageselectCallback,
        items_per_page:4,
        prev_text:" < ",
        next_text:" > ",
        num_display_entries:4,
        num_edge_entries:2
    });*/
   /* $("#Pagination2").pagination(num_entries, {
        callback: pageselectCallback,
        items_per_page:4,
        prev_text:" < ",
        next_text:" > ",
        num_display_entries:4,
        num_edge_entries:2
    });*/
 }



function hilightSecteur(obj){

    var data = obj.data('maphilight') || {};
    data.alwaysOn = !data.alwaysOn;
    obj.data('maphilight', data).trigger('alwaysOn.maphilight');

    $('#cb_'+obj.id).attr('checked', true);

}

function cocheCase2(e){
    e.preventDefault();
    var data = $(this).data('maphilight') || {};
    data.alwaysOn = !data.alwaysOn;
    $(this).data('maphilight', data).trigger('alwaysOn.maphilight');

    if($('#cb_'+this.id).is(':checked'))
        $('#cb_'+this.id).attr('checked', false);
    else
        $('#cb_'+this.id).attr('checked', true);

}


$(document).ready(function(){
	
	$('#link1').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});
	$('#link2').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});
	$('#link3').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});
	$('#link4').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});
	$('#link5').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});
	$('#link6').click(function() {
	  $('#form_dispo_hotel').show('slow');
	});

	if($("#Register").length>0)
	 {
		$("#ezcoa-1883_user_account_password").val("");
		$("#ezcoa-1883_user_account_login").val("");
     }
    
    if($("#ezcoa-1883_user_account_email").length){
        $("#PublishButton").click(function(){
			if($("#Register").length>0)
			{
				$("#ezcoa-1883_user_account_password").val("");
				$("#ezcoa-1883_user_account_login").val("");
			}	
            var value_mail =$("#ezcoa-1883_user_account_email").val();
           $("#ezcoa-1883_user_account_login").val(value_mail);
        });
    }


    if( $('.quantiteProd select').length){
        $('.quantiteProd select').each(function(){
            $(this).get(0).selectedIndex = 0;
        });
    }

    if( $('.quantiteProd select').length){
        $('.quantiteProd select').each(function(){
            $(this).get(0).selectedIndex = 0;
        });
    }

    
   if( $('#dateArrivee').length){
        $('#dateArrivee').val("");
        $('#dateDepart').val("");
        $('#inputNbrPersonneFormResa').get(0).selectedIndex = 0;
   }

   if( $('#liste_secteur').length){

       
       $('.map_corse_img').maphilight({fillColor:'859BC4',fillOpacity:0.7,strokeWidth:2,strokeColor:'FCDE06'});

       //map clicks
       $(".tabs_map area").bind("click",{test:1},cocheCase2);



        $(".test").each(function (index, domEle) {
         // domEle == this
             if($(domEle).is(':checked')){
                 var tab = $(domEle).attr('id').split('_');
                 hilightSecteur($('#'+tab[1]));
             }

       });

   }



    
    //$('#menu_haut').corner();
    //$('#liste_accueil ul li').corner();
    //$('.hotels_actu_ul').corner();
    //$('.hotels_them_ul').corner();
    //$('.allActualites').corner();
    //$('.AllHotels ul').corner();
    //$('#search_results ul').corner();

    //moteur de recgherche accueil
    //$('input[placeholder]').placeholder();
	
	var isPlaceholderSupported = function () { 
		var o = document.createElement('input'); 
		return "placeholder" in o; 
	};
	if (!isPlaceholderSupported()) {
		var togglePlaceholderText = function (el) {	
			var color = '#000';
			var v = $.trim(el.val());
			var p = el.attr('placeholder'); 
			if (v == '') { 
				el.val(p); 
				el.css({'color':color}); 
			} else if (v == p) {
				el.val(''); 
				el.css({'color':''});
			} 
		};
		$('input[placeholder]')
			.each(function(){togglePlaceholderText($(this));})
			.click(function(){togglePlaceholderText($(this));})
			.blur(function(){togglePlaceholderText($(this));})
			.closest('form').submit(function(){$(this).find('input[placeholder]').each(function(){togglePlaceholderText($(this));})});
	}
	//alert pour montrer que cela fonctionne
	/*$('form').submit(function(){
		alert($(this).serialize());
	});*/

    //slider liste h�tels accueil
    /*$("#liste_accueil").easySlider({
		auto: true,
		continuous: true
    });*/

    if( $('#Pagination').length)
        initPagination();


    //coups de corur accueil
    if( $('#liste_coups_coeur').length){
        jQuery('#liste_coups_coeur').jcarousel({
            visible: 4,
            auto: 10,
            scroll:1,
            wrap: 'last',
            initCallback: mycarousel_initCallback          
        });
    }

    //slider th�matiques accueil
    if( $('#liste_thematiques').length){
        jQuery('#liste_thematiques').jcarousel({
            visible: 5,
            auto: 10,
            scroll:1,
            wrap: 'last',
            initCallback: mycarousel_initCallback_thematiques,
            buttonNextHTML: null,
            buttonPrevHTML: null
            //itemFirstInCallback:carouselAnim

        });
    }

    //slider actualites accueil
    $("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 1000000, true);



});

function carouselAnim(carousel,li,i,state){
    $('.jcarousel-control a').removeClass('current_pag_car');
    $('.jcarousel-control a:eq('+eval(i-1)+')').addClass('current_pag_car');
}
