// Menu déroulant avec hoverintent
$(document).ready(function() 
{
	// hide the submenus
	$(".submenu").hide();
	// setup the drop downs
	$('#navbar ul > li').hoverIntent(
		// mouseover so show the drop down
		function()
		{
			// make the nav item have the over state
			$('> .submenu', this).toggle("fast");
		},
		// mouseout so hide the drop down
		function()
		{
			// remove the over state on the nav item
			$('> .submenu', this).toggle();
		}
	);
});


// Menu déroulant avec hoverintent
$(document).ready(function() 
{
	// hide the submenus
	$(".submenu").hide();
	// setup the drop downs
	$('#navbarb ul > li').hoverIntent(
		// mouseover so show the drop down
		function()
		{
			// make the nav item have the over state
			$('> .submenu', this).show();
		},
		// mouseout so hide the drop down
		function()
		{
			// remove the over state on the nav item
			$('> .submenu', this).toggle();
		}
	);
});


// Commentaire des interactions qui s'affichent au survol
$(document).ready(function() 
{
	// hide the submenus
	$(".intercomment").hide();
	// setup the drop downs
	$('.cstinter-list').hoverIntent(
		// mouseover so show the drop down
		function()
		{
			// make the nav item have the over state
			$('> .intercomment', this).toggle("fast");
		},
		// mouseout so hide the drop down
		function()
		{
			// remove the over state on the nav item
			$('> .intercomment', this).toggle();
		}
	);
});


// Commentaire des interactions qui s'affichent au survol ainsi que sur la page gestion interactions
$(document).ready(function() 
{
	// hide the submenus
	$(".clientinterlist").hide();
	$(".intercommentB").hide();
	// setup the drop downs
	$('.content-list ').hoverIntent(
		// mouseover so show the drop down
		function()
		{
			// make the nav item have the over state
			$('> .clientinterlist', this).toggle("fast");
			// make the nav item have the over state
			$('> .intercommentB', this).toggle("fast");
		},
		// mouseout so hide the drop down
		function()
		{
			// remove the over state on the nav item
			$('> .clientinterlist', this).toggle();
			// make the nav item have the over state
			$('> .intercommentB', this).toggle();
		}
	);
});



/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
// Image preview
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});

// Prompt a text to be sure to delete content
function deletechecked(message)
{
    var answer = confirm(message)
    if (answer){
        document.messages.submit();
        return false; // This line added
    }
	return false;  
}  

/**
* Jump to page
*/
function jumpto()
{
	var page = prompt(jump_page, on_page);

	if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0)
	{		
		$("#jumpto").attr("href", "index.php?p=ClientListe&n="+page)
		reload;
	}
}

/**
* Availability status
*/
$(document).ready(function()//When the dom is ready 
{
$("#username").change(function() 
{ //if theres a change in the username textbox

var username = $("#username").val();//Get the value in the username textbox
if(username.length > 3)//if the lenght greater than 3 characters
{
$("#availability_status").html('&nbsp;V&eacute;rification du nom de client...');
//Add a loading image in the span id="availability_status"

$.ajax({  //Make the Ajax Request
    type: "POST",  
	id: "name_check",
    url: "ajax/ajax_check_username.php",  //file name
    data: "username="+ username,  //data
    success: function(server_response){  
   
   $("#availability_status").ajaxComplete(function(event, request){ 

	if(server_response == '0')//if ajax_check_username.php return value "0"
	{ 
	$("#availability_status").html('Nom du client disponible.');
	$("#availability_status").css('color','green');
	//add this image to the span with id "availability_status"
	}  
	else  if(server_response == '1')//if it returns "1"
	{  
	 $("#availability_status").html('Nom du client non disponible.');
	 $("#availability_status").css('color','red');
	}  
   
   });
   } 
   
  }); 

}
else
{

$("#availability_status").html('Nom du client trop court.');
$("#availability_status").css('color','#cc0000');
//if in case the username is less than or equal 3 characters only 
}



return false;
});

});



// Smooth scrolling

$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');

  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });

  // use the first element that is "scrollable"
  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop()> 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop()> 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }

});
