// JavaScript Document 

///Function Swap image - Modele LINERS avec petite Navigation

		function swap(laquelle, message) {
			tmp		=	document.getElementById("lil"+message+laquelle).src;
			tmp2 	=	tmp.split("p.jpg");
			tmp 	=	tmp2[0] + '.jpg';
			tmp_gv 	=	tmp2[0] + 'g.jpg';
			document.getElementById("swaper"+message).src = tmp;
			if(document.getElementById("swaper_link"+message) != undefined)
			{
				document.getElementById("swaper_link"+message).href = tmp_gv;
			}
		}

///Function Menu a calques avec Jquery
$(document).ready(function(){
	$(".suckerdiv ul")
	.superfish({
		animation : {opacity:"show",height:"show"},
        autoArrows:  false,
        dropShadows: false
	})
	.find(">li[ul]")
		.mouseover(function(){
			$("ul", this).bgIframe({opacity:false});
		})
		.find("a")
			.focus(function(){
				$("ul", $(".suckerdiv>li[ul]")).bgIframe({opacity:false});
			});


    if($('li', $('#pictospiscines')).length > 0)
    {
        slideMenuPiscine();
    }
});

function slideMenuPiscine()
{
    var nbLi = $('li', $('#pictospiscines')).length;
    var containerWidth = $('.submenu').width();
    var contentWidth = 0;


    $('li', $('#pictospiscines')).each(function(i){
        contentWidth += $(this).width();
    });

    if($('.piscineSubMenu').length > 0)
    {
        $('#localisation').width(497);
    }

    $('#pictospiscines').width(contentWidth);

    // Le contenu est plus long que le conteneur
    if(contentWidth > containerWidth)
    {
        $('.slideLeft').hide();
        $('.slideRight').show();
        // Distance en pixel à parcourir
        var diff = contentWidth-containerWidth;

        // Position du sous menu par rapport à la page
        var offset = $('.submenu').offset();
        var offsetLeft = offset.left;
        var offsetRight = (offset.left + containerWidth);
        var midLimit = (offset.left + (containerWidth / 2));
        var dist = midLimit - offsetLeft;

        // Quand on bouge la souris au dessus du menu
        $('.submenu').mousemove(function(e){
            oLeft = e.pageX;
            oTop = e.pageY;

            //percentShow = Math.round((((offsetRight-oLeft)/dist)/2)*100)/100;

            // La souris est avant la moitié
            if(oLeft < midLimit)
            {
                move = -Math.round(((diff-((midLimit-oLeft)/(dist))*diff))/2);
                $('#pictospiscines').css('margin-left',move+'px');
                $('.slideLeft').hide();
                $('.slideRight').show();
            }
            else
            {
                move = -Math.round((diff/2)+((((oLeft-midLimit)/(dist))*diff)/2));
                $('#pictospiscines').css('margin-left',move+'px');
                $('.slideLeft').show();
                $('.slideRight').hide();
            }
        });
    }
}

/*==== Focus sur les fields ====*/
function GetFocus(field) {
	if (field.value==field.title) {field.value=''}
}
/*==== Blur sur les fields ====*/
function GetBlur(field) {
	if (field.value=='') {
		field.value=field.title;
	}
}

/*==== Ajax Photo Piscine ====*/
function ajaxPhotoPiscine(id, url)
{
	var Zone_a_charger = document.getElementById('photo-piscine-med');
	var data = "id="+id+"&url="+url;
	var url_post = url+"plugins/articles/ajax_photo_piscine.php";
	
	// Charge les caract�ristiques
	ajaxCaractPiscine(id, url);
	
	//Loader
	Zone_a_charger.innerHTML = '<div class="ajax-loader"><img src="'+url+'templates/default/images/ajax-loader.gif" alt="" /></div>';
	
	// Response
	Success = function(t)
	{
		Zone_a_charger.innerHTML = t;
		$(document).ready(TB_init);
	}
	$.ajax({
		type: "POST",
		url: url_post,
		data: data,
		success: Success
	});
}
/*==== Ajax Caract�ristiques Piscine ====*/
function ajaxCaractPiscine(id, url)
{
	var Zone_a_charger = document.getElementById('piscine-caract');
	var data = "id="+id+"&url="+url;
	var url_post = url+"plugins/articles/ajax_caract_piscine.php";
	
	//Loader
	Zone_a_charger.innerHTML = '<div class="ajax-loader"><img src="'+url+'templates/default/images/ajax-loader.gif" alt="" /></div>';
	
	// Response
	Success = function(t)
	{
		Zone_a_charger.innerHTML = t;
		$(document).ready(TB_init);
	}
	$.ajax({
		type: "POST",
		url: url_post,
		data: data,
		success: Success
	});
}

function affiche_cache(id_div, regle)
{
	var div = document.getElementById(id_div);
	if(regle==0)
	{
		div.style.display = "none";
	}
	else
	{
		div.style.display = "block";
	}
}

function load_affiche_cache(id_div,valeur)
{
	if( (valeur=="0") || (valeur=="") )
	{
		affiche_cache(id_div, 0);
	}
	else
	{
		affiche_cache(id_div, 1);
	}	

}

function hide(node)
{
	var tmp = node.parentNode.childNodes;
		for ( i = 0; i < tmp.length; i++ ) {
			if ( tmp[i].nodeName.toLowerCase() == 'div' ) 
			{
				tmp[i].style.display = 'none';
			}
		}
}
function pop(id)
{
	document.getElementById(id).style.display="block";
}


function hide_error () 
{
	div  = (document.layers) ? document.layers['errorPad'] : document.getElementById('errorPad');
	div2  = (document.layers) ? document.layers['erlogPad'] : document.getElementById('erlogPad');
	div.className = "error_hide";
	div2.className = "error_hide";
}

function validOne2one(choix)
{
	if(choix == 1)
	{
		var url = 'bo/_inc/managers/one2one/one2one.ajax.php';
		var pars = 'choix='+choix;
		
		// Response
		Success = function(t)
		{
			window.location.replace(t);
		}
		
		$.ajax({
			type: "POST",
			url: url,
			data: pars,
			success: Success
		});		
	}
	else
	{
		document.getElementById('calqueInfo').style.display = 'none';
	}
}

function displayListCountries()
{
	document.getElementById("bgdiv").style.display="block";
	document.getElementById("listpays").style.display="block";
}

function hideListCountries()
{
	document.getElementById("bgdiv").style.display="none";
	document.getElementById("listpays").style.display="none";
}

function listcountries()
{
	var url = 'listcountries.php';
	
	// Response
	Success = function(t)
	{

	    var bgdiv = document.createElement('div');	
		bgdiv.className = 'bgdiv';
		bgdiv.onclick = function() {document.body.removeChild(bgdiv);document.body.removeChild(listpays);};				
	    document.body.appendChild(bgdiv);

		var listpays = document.createElement('div');	
		listpays.className = 'listpays';

		var titre = document.createElement('div');
		titre.className = 'titrelistpays';
		listpays.appendChild(titre);

		var txttitre = document.createElement('div');
		txttitre.className = 'txttitre';
		txttitre.innerHTML = 'Select your country';
		
		var fermertitre = document.createElement('div');
		fermertitre.className = 'fermertitre';
		fermertitre.innerHTML = '<a id="fermertitre" href="#">close</a>';
		fermertitre.onclick = function() {document.body.removeChild(bgdiv);document.body.removeChild(listpays);};	
		
		titre.appendChild(txttitre);
		titre.appendChild(fermertitre);
		
	    var datalistpays = document.createElement('div');
		datalistpays.className = 'datalistpays';
		datalistpays.innerHTML = t;
		listpays.appendChild(datalistpays);
		
		document.body.appendChild(listpays);
	}
	
	$.ajax({
		type: "POST",
		url: url,
		success: Success
	});		
}

function swap_country(value)
{
	document.getElementById('inst_pays').value = value;
}

function copy_cp(value)
{
	document.getElementById('inst_code_postal').value = value;
}


function affiche_cache_auto(id_div)
{
	var div = document.getElementById(id_div);
	if(div.style.display=='block')
	{
		div.style.display = "none";
	}
	else
	{
		div.style.display = "block";
	}
}

