// JavaScript Document

<!-- menu top -->
$(document).ready(function(){

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.topnav li a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //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"
	});
	
});

function subnav_hover (id) {
		//alert (id);
		$("#"+id).css("background-color","#493420").css("color","#FFF");
};

function mouseleave (id) {
		//alert("Hello");
		//$("#"+id).css("background-color","#f2f3e2").css("color","#493420");
		if(id==2){
			$("#"+id).css("background-color","#f2f3e2").css("color","#d26d36");
		}else{
			$("#"+id).css("background-color","#f2f3e2").css("color","#493420");
		}
		
}
// Function for the menu of le domaine. keep the orange color
function text_color (id){
	//alert (id);
	$("#menu1").css("color","#515151");
	$("#menu2").css("color","#515151");
	$("#menu3").css("color","#515151");
	$("#menu4").css("color","#515151");
	$("#menu5").css("color","#515151");
	$("#menu6").css("color","#515151");
	
	$("#"+id).css("color","#d26d36");

}

function topnav_hover (id) {
		$("#"+id).css("background-color","#493420").css("color","#FFF");
}

function topnav_mouseleave(id) {
		//$("#"+id).css("background-color","#f2f3e2").css("color","#493420");
		if(id==2){
			$("#"+id).css("background-color","#f2f3e2").css("color","#d26d36");
		}else{
			$("#"+id).css("background-color","#f2f3e2").css("color","#493420");
		}
}
<!-- EOF menu top -->

function menu_hover(id){
	var para = $("#hidden_var").val();
	//alert(para);
	if (para!= ''){
		$("#"+para).hide("fade", 400);
	}
	
	$("#hidden_var").val(id);
	$("#"+id).show("slide", { direction: "left" }, 1000);
	
}

function menu_out(id){
	$("#"+id).hide("fade", 400);
	$("#hidden_var").val('');
}


$(document).ready(function(){
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset}, 1000);
	   return false;
	  }
	}
  });
});




/* ##################################### */

function ajax_change_display_Function(div_name,content_name){
    var ajaxRequest;  // The variable that makes Ajax possible!
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser is not supported!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if (ajaxRequest.readyState==1 || ajaxRequest.readyState=="loading")
        //if AJAX state is loading (loading)
        {
            document.getElementById(div_name).innerHTML="<table width=\"100\" border=\"0\" cellspacing=\"15\"><tr><td align=\"left\"><img src=\"/images/preloader.gif\"/></td></tr></table>" ;
            //get element where the id is “Result”, in this case it goes to the <div> tag
            //send the loading image (loading.gif) that show us the data is being prepared
        }
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById(div_name);
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }
    ajaxRequest.open("GET", content_name, true);
    ajaxRequest.send(null);
    //set_swf_var(content_name);
    return false;
}

//Browser Support Code
function ajax_submit_form(div_name, page_name, query_string){
    var ajaxRequest;  // The variable that makes Ajax possible!
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser is not supported!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if (ajaxRequest.readyState==1 || ajaxRequest.readyState=="loading")
        //if AJAX state is loading (loading)
        {
            document.getElementById(div_name).innerHTML="<table width=\"100\" border=\"0\" cellspacing=\"15\"><tr><td align=\"left\"><img src=\"/images/preloader.gif\"/></td></tr></table>" ;
        }
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById(div_name);
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }
    var queryString = "?"+ query_string +"&";
    ajaxRequest.open("GET", page_name + queryString, true);
    ajaxRequest.send(null);
    return false;
}

//text filed validation function 
function validate_required(field,alerttxt){
    with (field){
        if (value==null||value==""){
            alert(alerttxt);
            return false;
        }
        else{
            return true
        }
    }
}

//email validation function
function validate_email(field,alerttxt){
    with (field){
        apos=value.indexOf("@")
        dotpos=value.lastIndexOf(".")
        if (apos<1||dotpos-apos<2){
            alert(alerttxt);
            return false
        }else{
            return true
        }
    }
}


//get all the elenments of a form
function get_form_elements_detail(form_name){    
    var detailed_url = "";
    var form_value = "";
    for (i=0; i<form_name.elements.length; i++){
        if(form_name.elements[i].name.substring(0,3)=="chk" ){
            if(form_name.elements[i].checked){
                detailed_url =  detailed_url + "&" + form_name.elements[i].name + "=yes";
            }else{
                detailed_url =  detailed_url + "&" + form_name.elements[i].name + "=no";
            }
        }else{
            form_name.elements[i].value = form_name.elements[i].value.replace("'"," ");
            detailed_url =  detailed_url + "&" + form_name.elements[i].name + "=" + form_name.elements[i].value.replace(/\n/gi, "<br/>\n");
        }
    }
    return detailed_url;
}


//Validation of fields with error messages 
function validate_form(thisform){
    for (i=0; i<thisform.elements.length; i++){
        if(thisform.elements[i].name=="txt_email"){
            if (validate_email(thisform.elements[i],email_err)==false)
            {thisform.elements[i].focus();return false;}
        }                
        if(thisform.elements[i].name=="txt_lastname"){
            if (validate_required(thisform.elements[i],family_name_err)==false)
            {thisform.elements[i].focus();return false;}
        }
        if(thisform.elements[i].name=="txt_firstname"){
            if (validate_required(thisform.elements[i],first_name_err)==false)
            {thisform.elements[i].focus();return false;}
        }
		if(thisform.elements[i].name=="txt_add"){
            if (validate_required(thisform.elements[i],address_err)==false)
            {thisform.elements[i].focus();return false;}
        }
		if(thisform.elements[i].name=="txt_ville"){
            if (validate_required(thisform.elements[i],city_err)==false)
            {thisform.elements[i].focus();return false;}
        }
    }
    return true;
}

//function for form submits 
function submit_form_function(form_name, call_page, div_name){  
    if(validate_form(form_name)==true){
        ajax_submit_form(div_name, call_page, get_form_elements_detail(form_name))
    }
    return false;    
}

//function for form submits 
function link_ajax_function(call_page, div_name){  
        ajax_submit_form(div_name, call_page,'');
        return false;    
}

function link_galleria_ajax_function(call_page, div_name){  
        ajax_submit_form(div_name, call_page,'');
        return false;    
}
// initializing colorbox
function select_init(page_name){
    if(page_name=="ledomaine"){
		//alert(page_name);
        $(".map").colorbox({iframe:true, width:"975", height:"700"});
		$(".visite").colorbox({iframe:true, width:"800", height:"550"});
		$(".contact").colorbox({iframe:true, width:"650", height:"550"});     
    }
    return false;
}

function pollC(id, load, page_name){
    if (!load&&document.getElementById(id)){
        document.getElementById(id).id='';
        return;
    }else if (load&&document.getElementById(id)){
        if (id=='unique_1')
        select_init(page_name);
        return;	
    }else if (load&&!document.getElementById(id)){
        setTimeout("pollC('"+id+"', 'load', '"+page_name+"')", 60);
    }	
}
